Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/cmdline/maven/target/
48 changes: 20 additions & 28 deletions cmdline/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.apache.netbeans</groupId>
<artifactId>netbeans-parent</artifactId>
<version>2</version>
<version>5</version>
</parent>
<url>https://netbeans.apache.org</url>
<scm>
Expand All @@ -41,39 +41,38 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.executable>${env.M2_HOME}/bin/mvn</maven.executable>
<maven.version>3.9.16</maven.version>
<maven.plugin.version>3.15.2</maven.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-toolchain</artifactId>
<version>2.1.0</version>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.1.0</version>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>tool</artifactId>
<version>${version}</version>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0</version>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${maven.plugin.version}</version>
<type>jar</type>
</dependency>
</dependencies>
Expand All @@ -83,36 +82,29 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<version>3.6.0</version>
<configuration>
<systemProperties>
<property>
<name>basedir</name>
<value>${basedir}</value>
</property>
<property>
<name>maven.executable</name>
<value>${maven.executable}</value>
</property>
</systemProperties>
<systemPropertyVariables>
<basedir>${basedir}</basedir>
<maven.executable>${maven.executable}</maven.executable>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>3.16.0</version>
<configuration>
<compilerArgs>
<arg>-AdisableJackpotProcessor=true</arg>
</compilerArgs>
<source>1.8</source>
<target>1.8</target>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.10.2</version>
<version>${maven.plugin.version}</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* @goal analyze
* @requiresDependencyResolution compile
* @author Jan Lahoda
*/
@Mojo(name = "analyze", requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
public class RunAnalyze extends RunJackpot30 {

/**
* @parameter property="project"
* @required
* @readonly
*/
private MavenProject project;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
doRun(project, false);
doRun(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;

/**
* @goal apply
* @requiresDependencyResolution compile
* @author Jan Lahoda
*/
@Mojo(name = "apply", requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
public class RunApply extends RunJackpot30 {

/**
* @parameter property="project"
* @required
* @readonly
*/
private MavenProject project;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
doRun(project, true);
doRun(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -33,13 +32,23 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.netbeans.modules.jackpot30.cmdline.Main;

public abstract class RunJackpot30 extends AbstractMojo {

protected final void doRun(MavenProject project, boolean apply) throws MojoExecutionException, MojoFailureException {
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

@Parameter(property = "failOnWarnings", defaultValue = "true")
private boolean failOnWarnings;

@Parameter(property = "configurationFile")
private String configurationFile = null;

protected final void doRun(boolean apply) throws MojoExecutionException, MojoFailureException {
try {
String sourceLevel = "1.5";
Xpp3Dom sourceLevelConfiguration = Utils.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin");
Expand All @@ -52,15 +61,13 @@ protected final void doRun(MavenProject project, boolean apply) throws MojoExecu
}
}

String configurationFile = Utils.getJackpotConfigurationFile(project);
boolean failOnWarnings = Utils.getJackpotFailOnWarnings(project);
List<String> cmdLine = new ArrayList<>();

List<String> cmdLine = new ArrayList<String>();

if (apply)
if (apply) {
cmdLine.add("--apply");
else
} else {
cmdLine.add("--no-apply");
}

cmdLine.addAll(sourceAndCompileClassPaths(Collections.singletonList(project)));
cmdLine.add("--source");
Expand All @@ -86,29 +93,25 @@ protected final void doRun(MavenProject project, boolean apply) throws MojoExecu

if (!hasSourceRoots) {
getLog().debug("jackpot30 analyze: Not source roots to operate on");
return ;
return;
}

Path bin = Paths.get(System.getProperty("java.home"))
.resolve("bin");
.resolve("bin");
Path launcher = bin.resolve("java");
if (!Files.exists(launcher)) {
launcher = bin.resolve("java.exe");
}
cmdLine.addAll(0, Arrays.asList(launcher.toAbsolutePath().toString(),
"-classpath", Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.desktop/sun.awt=ALL-UNNAMED",
Main.class.getCanonicalName()));
"-classpath", Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.desktop/sun.awt=ALL-UNNAMED",
Main.class.getCanonicalName()));
if (new ProcessBuilder(cmdLine).inheritIO().start().waitFor() != 0) {
throw new MojoExecutionException("jackpo30 failed.");
}
} catch (IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (InterruptedException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (DependencyResolutionRequiredException ex) {
} catch (IOException | InterruptedException | DependencyResolutionRequiredException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
}
Expand All @@ -117,7 +120,9 @@ private static String toClassPathString(List<String> entries) {
StringBuilder classPath = new StringBuilder();

for (String root : entries) {
if (classPath.length() > 0) classPath.append(File.pathSeparatorChar);
if (classPath.length() > 0) {
classPath.append(File.pathSeparatorChar);
}
classPath.append(root);
}

Expand All @@ -126,22 +131,22 @@ private static String toClassPathString(List<String> entries) {

@SuppressWarnings("unchecked")
public static List<String> sourceAndCompileClassPaths(Iterable<? extends MavenProject> projects) throws DependencyResolutionRequiredException {
List<String> compileSourceRoots = new ArrayList<String>();
List<String> compileClassPath = new ArrayList<String>();
List<String> compileSourceRoots = new ArrayList<>();
List<String> compileClassPath = new ArrayList<>();

for (MavenProject project : projects) {
compileSourceRoots.addAll((List<String>) project.getCompileSourceRoots());

for (Resource r : (List<Resource>) project.getResources()) {
compileSourceRoots.add(r.getDirectory());
}

compileClassPath.addAll((List<String>) project.getCompileClasspathElements());
}

return Arrays.asList("--sourcepath",
toClassPathString(compileSourceRoots),
"--classpath",
toClassPathString(compileClassPath));
toClassPathString(compileSourceRoots),
"--classpath",
toClassPathString(compileClassPath));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,36 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.netbeans.modules.jackpot30.cmdline.Main;

/**
* @goal showgui
*
* @author Jan Lahoda
*/
@Mojo(name = "showgui", requiresProject = true)
public class ShowGuiJackpot30 extends AbstractMojo {

/**
* @parameter property="project"
* @required
* @readonly
*/
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;

@Parameter(property = "configurationFile")
private String configurationFile;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
try {
if (!project.isExecutionRoot()) return;

String configurationFile = Utils.getJackpotConfigurationFile(project);
if (!project.isExecutionRoot()) {
return;
}

if (configurationFile == null)
if (configurationFile == null) {
throw new MojoExecutionException("No configuration file specified, cannot show configuration GUI");
}

List<String> cmdLine = new ArrayList<String>();
List<String> cmdLine = new ArrayList<>();

cmdLine.add("--config-file");
cmdLine.add(configurationFile);
Expand All @@ -59,11 +63,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
System.err.println(cmdLine);

Main.compile(cmdLine.toArray(new String[0]));
} catch (IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (ClassNotFoundException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (DependencyResolutionRequiredException ex) {
} catch (IOException | ClassNotFoundException | DependencyResolutionRequiredException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
}
}
Expand Down
Loading