You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jl...@apache.org on 2019/03/17 22:02:29 UTC
[incubator-netbeans-jackpot30] branch master updated: Fixing the
maven plugin for jackpot; various related improvements.
This is an automated email from the ASF dual-hosted git repository.
jlahoda pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans-jackpot30.git
The following commit(s) were added to refs/heads/master by this push:
new a398cba Fixing the maven plugin for jackpot; various related improvements.
a398cba is described below
commit a398cba7679a1a6e0591b6b227f107fdb19d7b6d
Author: Jan Lahoda <la...@gmail.com>
AuthorDate: Sun Mar 17 23:02:24 2019 +0100
Fixing the maven plugin for jackpot; various related improvements.
---
cmdline/README.md | 5 +-
cmdline/build.xml | 30 ++++++
cmdline/maven/pom.xml | 39 +++++--
.../modules/jackpot30/maven/RunAnalyze.java | 2 +-
.../netbeans/modules/jackpot30/maven/RunApply.java | 2 +-
.../modules/jackpot30/maven/RunJackpot30.java | 20 +++-
.../modules/jackpot30/maven/ShowGuiJackpot30.java | 2 +-
.../netbeans/modules/jackpot30/maven/Utils.java | 2 +-
.../modules/jackpot30/maven/RunJackpot30Test.java | 1 +
cmdline/maven/tests/sl-15/golden | 0
cmdline/maven/tests/sl-17/golden | 3 -
cmdline/maven/tests/sl-17/jackpot-settings.xml | 13 ++-
cmdline/maven/tests/sl-17/pom.xml | 4 +-
.../maven/tests/sl-17/src/main/java/test/App.java | 4 +-
cmdline/maven/tests/sl-18/golden | 3 +
.../tests/{sl-15 => sl-18}/jackpot-settings.xml | 13 ++-
cmdline/maven/tests/{sl-15 => sl-18}/pom.xml | 8 +-
.../{sl-15 => sl-18}/src/main/java/test/App.java | 4 +-
cmdline/maven/tests/test-custom/golden | 2 +-
cmdline/maven/tests/test-custom/pom.xml | 4 +-
cmdline/maven/tests/test1/golden | 2 +-
cmdline/maven/tests/test1/jackpot-settings.xml | 16 ++-
cmdline/maven/tests/test1/pom.xml | 4 +-
.../netbeans/modules/jackpot30/cmdline/Main.java | 117 ++++++++-------------
.../modules/jackpot30/cmdline/ProcessorImpl.java | 5 +-
.../modules/jackpot30/cmdline/CreateTool.java | 4 +
.../modules/jackpot30/cmdline/CreateToolTest.java | 4 -
.../modules/jackpot30/cmdline/MainTest.java | 34 +++++-
28 files changed, 213 insertions(+), 134 deletions(-)
diff --git a/cmdline/README.md b/cmdline/README.md
index e9f4463..9149e4b 100644
--- a/cmdline/README.md
+++ b/cmdline/README.md
@@ -27,10 +27,11 @@ This tool allows to run NetBeans Java code checker without the NetBeans IDE. Thi
#### To Build
-* NetBeans 10.0
+* Apache NetBeans 10.0
* JDK 8 and JDK 11
* bash
-* ant 1.9.9 or above
+* Apache ant 1.9.9 or above
+* Apache Maven 3.3.9 or above
#### To Run
diff --git a/cmdline/build.xml b/cmdline/build.xml
index a22e2a8..60e9d18 100644
--- a/cmdline/build.xml
+++ b/cmdline/build.xml
@@ -44,6 +44,7 @@
</target>
<target name="build-and-test">
+ <property name="version" value="10.0" />
<condition property="jackpot.root" value="${basedir}" else="${basedir}/..">
<available file="${basedir}/LICENSE" />
</condition>
@@ -70,6 +71,35 @@
<env key="JAVA_HOME" path="${JDK11}" />
<env key="PATH" path="${JDK11}/bin:${env.PATH}" />
</exec>
+ <echo>Installing tool to the local maven repository:</echo>
+ <exec dir="." executable="mvn" failonerror="true">
+ <arg line="install:install-file -Dfile=tool/build/jackpot/jackpot.jar -DgroupId=org.apache.netbeans.modules.jackpot30 -DartifactId=tool -Dversion=${version} -Dpackaging=jar -DgeneratePom=true" />
+ </exec>
+ <echo>Building maven plugin:</echo>
+ <exec dir="maven" executable="mvn" failonerror="true">
+ <arg line="-Dversion=${version} install -DskipTests" />
+ </exec>
+ <echo>Run plugin tests:</echo>
+ <exec dir="maven" executable="mvn" failonerror="true">
+ <env key="JAVA_HOME" path="${JDK11}" />
+ <arg line="-Dmaven.executable=mvn -Djackpot.plugin.version=${version} test" />
+ </exec>
+ <property name="build.maven.repo" location="build/.m2" />
+ <mkdir dir="${build.maven.repo}" />
+ <echo>Installing tool to the target maven repository:</echo>
+ <exec dir="maven" executable="mvn" failonerror="true">
+ <arg line="deploy:deploy-file -Dfile=${basedir}/tool/build/jackpot/jackpot.jar -DgroupId=org.apache.netbeans.modules.jackpot30 -DartifactId=tool -Dversion=${version} -Dpackaging=jar -DgeneratePom=true -DaltDeploymentRepository=temp::default::file://${build.maven.repo} -Durl=file://${build.maven.repo}" />
+ </exec>
+ <echo>Installing plugin to the target maven repository:</echo>
+ <exec dir="maven" executable="mvn" failonerror="true">
+ <arg line="-DskipTests -DaltDeploymentRepository=temp::default::file://${build.maven.repo} deploy" />
+ </exec>
+ <zip destfile="build/.m2.zip">
+ <zipfileset dir="${build.maven.repo}/" />
+ <zipfileset dir="tool/scripts" includes="LICENSE-bin-tool.txt" fullpath="META-INF/LICENSE" />
+ <zipfileset dir="tool/scripts" includes="NOTICE-bin-tool.txt" fullpath="META-INF/NOTICE" />
+ <zipfileset dir="${jackpot.root}" includes="DISCLAIMER" fullpath="META-INF/DISCLAIMER" />
+ </zip>
</target>
<target name="rat">
diff --git a/cmdline/maven/pom.xml b/cmdline/maven/pom.xml
index 474d465..0fe862e 100644
--- a/cmdline/maven/pom.xml
+++ b/cmdline/maven/pom.xml
@@ -19,12 +19,17 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>org.netbeans.modules.jackpot30</groupId>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>jackpot30-maven-plugin</artifactId>
- <version>9.0-SNAPSHOT</version>
+ <version>10.0</version>
<packaging>maven-plugin</packaging>
<name>Jackpot 3.0 Command Line Tool Maven Bridge</name>
+ <parent>
+ <groupId>org.apache.netbeans</groupId>
+ <artifactId>netbeans-parent</artifactId>
+ <version>1</version>
+ </parent>
<url>https://bitbucket.org/jlahoda/jackpot30/overview</url>
<properties>
@@ -36,12 +41,22 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
- <version>2.0</version>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-toolchain</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>2.1.0</version>
</dependency>
<dependency>
- <groupId>org.netbeans.modules.jackpot30</groupId>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>tool</artifactId>
- <version>9.0-SNAPSHOT</version>
+ <version>${version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -79,12 +94,20 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
+ <version>3.8.0</version>
<configuration>
- <source>1.5</source>
- <target>1.5</target>
+ <compilerArgs>
+ <arg>-AdisableJackpotProcessor=true</arg>
+ </compilerArgs>
+ <source>1.8</source>
+ <target>1.8</target>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.5.2</version>
+ </plugin>
</plugins>
</build>
</project>
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunAnalyze.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunAnalyze.java
index f90991a..234c6a0 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunAnalyze.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunAnalyze.java
@@ -30,7 +30,7 @@ import org.apache.maven.project.MavenProject;
public class RunAnalyze extends RunJackpot30 {
/**
- * @parameter expression="${project}"
+ * @parameter property="project"
* @required
* @readonly
*/
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunApply.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunApply.java
index c5f60b6..84863bb 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunApply.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunApply.java
@@ -30,7 +30,7 @@ import org.apache.maven.project.MavenProject;
public class RunApply extends RunJackpot30 {
/**
- * @parameter expression="${project}"
+ * @parameter property="project"
* @required
* @readonly
*/
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java
index 1a329c5..567fe18 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/RunJackpot30.java
@@ -20,6 +20,10 @@ package org.netbeans.modules.jackpot30.maven;
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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -80,10 +84,22 @@ public abstract class RunJackpot30 extends AbstractMojo {
return ;
}
- Main.compile(cmdLine.toArray(new String[0]));
+ Path bin = Paths.get(System.getProperty("java.home"))
+ .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(),
+ "--add-exports=jdk.javadoc/com.sun.tools.javadoc.main=ALL-UNNAMED",
+ "--add-opens=java.base/java.net=ALL-UNNAMED",
+ "--add-opens=java.desktop/sun.awt=ALL-UNNAMED",
+ Main.class.getCanonicalName()));
+ new ProcessBuilder(cmdLine).inheritIO().start().waitFor();
} catch (IOException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
- } catch (ClassNotFoundException ex) {
+ } catch (InterruptedException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (DependencyResolutionRequiredException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/ShowGuiJackpot30.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/ShowGuiJackpot30.java
index cdcf0c2..d96a1df 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/ShowGuiJackpot30.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/ShowGuiJackpot30.java
@@ -35,7 +35,7 @@ import org.netbeans.modules.jackpot30.cmdline.Main;
public class ShowGuiJackpot30 extends AbstractMojo {
/**
- * @parameter expression="${project}"
+ * @parameter property="project"
* @required
* @readonly
*/
diff --git a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java
index 3278617..5ea91a9 100644
--- a/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java
+++ b/cmdline/maven/src/main/java/org/netbeans/modules/jackpot30/maven/Utils.java
@@ -47,7 +47,7 @@ public class Utils {
}
public static String getJackpotConfigurationFile(MavenProject project) {
- Xpp3Dom configuration = getPluginConfiguration(project, "org.netbeans.modules.jackpot30", "jackpot30-maven-plugin");
+ Xpp3Dom configuration = getPluginConfiguration(project, "org.apache.netbeans.modules.jackpot30", "jackpot30-maven-plugin");
if (configuration != null) {
Xpp3Dom configurationFileElement = configuration.getChild("configurationFile");
diff --git a/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java b/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
index a4ce6fe..ab8bd81 100644
--- a/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
+++ b/cmdline/maven/src/test/java/org/netbeans/modules/jackpot30/maven/RunJackpot30Test.java
@@ -67,6 +67,7 @@ public class RunJackpot30Test extends TestCase {
Process p = Runtime.getRuntime().exec(new String[] {
maven,
+ "-Djackpot.plugin.version=10.0",
"-q",
"jackpot30:analyze"
}, null, testDir);
diff --git a/cmdline/maven/tests/sl-15/golden b/cmdline/maven/tests/sl-15/golden
deleted file mode 100644
index e69de29..0000000
diff --git a/cmdline/maven/tests/sl-17/golden b/cmdline/maven/tests/sl-17/golden
index ca57851..e69de29 100644
--- a/cmdline/maven/tests/sl-17/golden
+++ b/cmdline/maven/tests/sl-17/golden
@@ -1,3 +0,0 @@
-${basedir}/src/main/java/test/App.java:51: warning: [Can_Use_Diamond] redundant type arguments in new expression (use diamond operator instead).
- List<String> l = new ArrayList<String>();
- ^
diff --git a/cmdline/maven/tests/sl-17/jackpot-settings.xml b/cmdline/maven/tests/sl-17/jackpot-settings.xml
index ad1cb92..a0a69de 100644
--- a/cmdline/maven/tests/sl-17/jackpot-settings.xml
+++ b/cmdline/maven/tests/sl-17/jackpot-settings.xml
@@ -16,8 +16,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<hints>
- <settings>
- <Javac_canUseDiamond enabled="true"/>
- </settings>
-</hints>
+<!DOCTYPE configuration PUBLIC "-//NetBeans//DTD Tool Configuration 1.0//EN" "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd">
+<configuration>
+ <tool kind="hints" type="text/x-java">
+ <node name="Javac_canUseLambda">
+ <attribute name="enabled" value="true"/>
+ </node>
+ </tool>
+</configuration>
diff --git a/cmdline/maven/tests/sl-17/pom.xml b/cmdline/maven/tests/sl-17/pom.xml
index 7d2e6ae..405c3e6 100644
--- a/cmdline/maven/tests/sl-17/pom.xml
+++ b/cmdline/maven/tests/sl-17/pom.xml
@@ -42,9 +42,9 @@
<build>
<plugins>
<plugin>
- <groupId>org.netbeans.modules.jackpot30</groupId>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>jackpot30-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>${jackpot.plugin.version}</version>
<configuration>
<configurationFile>jackpot-settings.xml</configurationFile>
</configuration>
diff --git a/cmdline/maven/tests/sl-17/src/main/java/test/App.java b/cmdline/maven/tests/sl-17/src/main/java/test/App.java
index ed277d6..80b18f6 100644
--- a/cmdline/maven/tests/sl-17/src/main/java/test/App.java
+++ b/cmdline/maven/tests/sl-17/src/main/java/test/App.java
@@ -18,11 +18,9 @@
*/
package test;
-import java.util.*;
-
public class App {
public static void main( String[] args ) {
- List<String> l = new ArrayList<String>();
+ Runnable r = new Runnable() { public void run() { } };
}
}
diff --git a/cmdline/maven/tests/sl-18/golden b/cmdline/maven/tests/sl-18/golden
new file mode 100644
index 0000000..880da9c
--- /dev/null
+++ b/cmdline/maven/tests/sl-18/golden
@@ -0,0 +1,3 @@
+${basedir}/src/main/java/test/App.java:24: warning: [Convert_to_Lambda_or_Member_Reference] This anonymous inner class creation can be turned into a lambda expression.
+ Runnable r = new Runnable() { public void run() { } };
+ ^
diff --git a/cmdline/maven/tests/sl-15/jackpot-settings.xml b/cmdline/maven/tests/sl-18/jackpot-settings.xml
similarity index 71%
rename from cmdline/maven/tests/sl-15/jackpot-settings.xml
rename to cmdline/maven/tests/sl-18/jackpot-settings.xml
index ad1cb92..a0a69de 100644
--- a/cmdline/maven/tests/sl-15/jackpot-settings.xml
+++ b/cmdline/maven/tests/sl-18/jackpot-settings.xml
@@ -16,8 +16,11 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<hints>
- <settings>
- <Javac_canUseDiamond enabled="true"/>
- </settings>
-</hints>
+<!DOCTYPE configuration PUBLIC "-//NetBeans//DTD Tool Configuration 1.0//EN" "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd">
+<configuration>
+ <tool kind="hints" type="text/x-java">
+ <node name="Javac_canUseLambda">
+ <attribute name="enabled" value="true"/>
+ </node>
+ </tool>
+</configuration>
diff --git a/cmdline/maven/tests/sl-15/pom.xml b/cmdline/maven/tests/sl-18/pom.xml
similarity index 91%
rename from cmdline/maven/tests/sl-15/pom.xml
rename to cmdline/maven/tests/sl-18/pom.xml
index 4dd38ce..d080ea1 100644
--- a/cmdline/maven/tests/sl-15/pom.xml
+++ b/cmdline/maven/tests/sl-18/pom.xml
@@ -42,9 +42,9 @@
<build>
<plugins>
<plugin>
- <groupId>org.netbeans.modules.jackpot30</groupId>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>jackpot30-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>${jackpot.plugin.version}</version>
<configuration>
<configurationFile>jackpot-settings.xml</configurationFile>
</configuration>
@@ -54,8 +54,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
- <source>1.5</source>
- <target>1.5</target>
+ <source>1.8</source>
+ <target>1.8</target>
</configuration>
</plugin>
</plugins>
diff --git a/cmdline/maven/tests/sl-15/src/main/java/test/App.java b/cmdline/maven/tests/sl-18/src/main/java/test/App.java
similarity index 92%
rename from cmdline/maven/tests/sl-15/src/main/java/test/App.java
rename to cmdline/maven/tests/sl-18/src/main/java/test/App.java
index ed277d6..80b18f6 100644
--- a/cmdline/maven/tests/sl-15/src/main/java/test/App.java
+++ b/cmdline/maven/tests/sl-18/src/main/java/test/App.java
@@ -18,11 +18,9 @@
*/
package test;
-import java.util.*;
-
public class App {
public static void main( String[] args ) {
- List<String> l = new ArrayList<String>();
+ Runnable r = new Runnable() { public void run() { } };
}
}
diff --git a/cmdline/maven/tests/test-custom/golden b/cmdline/maven/tests/test-custom/golden
index 8965aa8..c1e0330 100644
--- a/cmdline/maven/tests/test-custom/golden
+++ b/cmdline/maven/tests/test-custom/golden
@@ -1,3 +1,3 @@
-${basedir}/src/main/java/test/App.java:48: warning: [test] test
+${basedir}/src/main/java/test/App.java:23: warning: [test] test
System.err.println(args[0].length() == 0);
^
diff --git a/cmdline/maven/tests/test-custom/pom.xml b/cmdline/maven/tests/test-custom/pom.xml
index 8a652e4..f263af8 100644
--- a/cmdline/maven/tests/test-custom/pom.xml
+++ b/cmdline/maven/tests/test-custom/pom.xml
@@ -42,9 +42,9 @@
<build>
<plugins>
<plugin>
- <groupId>org.netbeans.modules.jackpot30</groupId>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>jackpot30-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>${jackpot.plugin.version}</version>
</plugin>
</plugins>
</build>
diff --git a/cmdline/maven/tests/test1/golden b/cmdline/maven/tests/test1/golden
index 6488245..6bafa1b 100644
--- a/cmdline/maven/tests/test1/golden
+++ b/cmdline/maven/tests/test1/golden
@@ -1,3 +1,3 @@
-${basedir}/src/main/java/test/App.java:50: warning: [Synchronization_on_non_final_field] Synchronization on non-final field
+${basedir}/src/main/java/test/App.java:25: warning: [Synchronization_on_non_final_field] Synchronization on non-final field
synchronized (LOCK) {
^
diff --git a/cmdline/maven/tests/test1/jackpot-settings.xml b/cmdline/maven/tests/test1/jackpot-settings.xml
index d7a49c2..bf0a94a 100644
--- a/cmdline/maven/tests/test1/jackpot-settings.xml
+++ b/cmdline/maven/tests/test1/jackpot-settings.xml
@@ -16,8 +16,14 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<hints>
- <settings>
- <org.netbeans.modules.java.hints.SyncOnNonFinal enabled="true"/>
- </settings>
-</hints>
+<!DOCTYPE configuration PUBLIC "-//NetBeans//DTD Tool Configuration 1.0//EN" "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd">
+<configuration>
+ <tool kind="hints" type="text/x-java">
+ <node name="org.netbeans.modules.java.hints.SyncOnNonFinal">
+ <attribute name="enabled" value="true"/>
+ </node>
+ <node name="org.netbeans.modules.java.hints.threading.Tiny.canBeFinal">
+ <attribute name="enabled" value="false"/>
+ </node>
+ </tool>
+</configuration>
diff --git a/cmdline/maven/tests/test1/pom.xml b/cmdline/maven/tests/test1/pom.xml
index a350188..87b4c1b 100644
--- a/cmdline/maven/tests/test1/pom.xml
+++ b/cmdline/maven/tests/test1/pom.xml
@@ -42,9 +42,9 @@
<build>
<plugins>
<plugin>
- <groupId>org.netbeans.modules.jackpot30</groupId>
+ <groupId>org.apache.netbeans.modules.jackpot30</groupId>
<artifactId>jackpot30-maven-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <version>${jackpot.plugin.version}</version>
<configuration>
<configurationFile>jackpot-settings.xml</configurationFile>
</configuration>
diff --git a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
index 39d995a..d154e78 100644
--- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
+++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java
@@ -19,9 +19,6 @@
package org.netbeans.modules.jackpot30.cmdline;
-import java.awt.BorderLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
@@ -30,11 +27,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.UncheckedIOException;
import java.io.Writer;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
@@ -50,7 +43,6 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.AbstractPreferences;
@@ -58,11 +50,6 @@ import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import javax.lang.model.SourceVersion;
-import javax.swing.JCheckBox;
-import javax.swing.JDialog;
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeListener;
import joptsimple.ArgumentAcceptingOptionSpec;
@@ -70,7 +57,6 @@ import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.netbeans.api.java.classpath.ClassPath;
-import org.netbeans.api.java.classpath.GlobalPathRegistry;
import org.netbeans.api.java.source.CompilationController;
import org.netbeans.api.java.source.ModificationResult;
import org.netbeans.modules.editor.tools.storage.api.ToolPreferences;
@@ -96,26 +82,20 @@ import org.netbeans.modules.java.hints.spiimpl.batch.BatchUtilities;
import org.netbeans.modules.java.hints.spiimpl.batch.ProgressHandleWrapper;
import org.netbeans.modules.java.hints.spiimpl.batch.ProgressHandleWrapper.ProgressHandleAbstraction;
import org.netbeans.modules.java.hints.spiimpl.batch.Scopes;
-import org.netbeans.modules.java.hints.spiimpl.options.HintsPanel;
import org.netbeans.modules.java.hints.spiimpl.options.HintsSettings;
-import org.netbeans.modules.java.hints.spiimpl.refactoring.Utilities.ClassPathBasedHintWrapper;
-import org.netbeans.modules.java.source.parsing.JavaPathRecognizer;
import org.netbeans.modules.parsing.impl.indexing.CacheFolder;
import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater;
+import org.netbeans.modules.refactoring.spi.RefactoringElementImplementation;
import org.netbeans.spi.editor.hints.ErrorDescription;
import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
import org.netbeans.spi.editor.hints.Fix;
import org.netbeans.spi.editor.hints.Severity;
import org.netbeans.spi.java.classpath.ClassPathProvider;
-import org.netbeans.spi.java.classpath.PathResourceImplementation;
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
import org.netbeans.spi.java.hints.Hint.Kind;
import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
import org.openide.filesystems.FileObject;
-import org.openide.filesystems.FileStateInvalidException;
import org.openide.filesystems.FileUtil;
-import org.openide.filesystems.URLMapper;
-import org.openide.util.BaseUtilities;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.Pair;
@@ -145,10 +125,11 @@ public class Main {
try {
Class.forName("javax.lang.model.element.ModuleElement");
} catch (ClassNotFoundException ex) {
- System.err.println("Error: no suitable javac found, please run on JDK 10+.");
+ System.err.println("Error: no suitable javac found, please run on JDK 11+.");
return 1;
}
System.setProperty("netbeans.user", "/tmp/tmp-foo");
+ System.setProperty("SourcePath.no.source.filter", "true");
OptionParser parser = new OptionParser();
// ArgumentAcceptingOptionSpec<File> projects = parser.accepts("project", "project(s) to refactor").withRequiredArg().withValuesSeparatedBy(File.pathSeparatorChar).ofType(File.class);
@@ -520,44 +501,31 @@ public class Main {
return GroupResult.NO_HINTS_FOUND;
}
- Object[] register2Lookup = new Object[] {
- new ClassPathProviderImpl(rootConfiguration.bootCP, rootConfiguration.compileCP, rootConfiguration.sourceCP),
- new JavaPathRecognizer(),
- new SourceLevelQueryImpl(rootConfiguration.sourceCP, sourceLevel)
- };
-
- GroupResult[] result = new GroupResult[1];
+ RootConfiguration prevConfig = currentRootConfiguration.get();
- Lookups.executeWith(new ProxyLookup(Lookups.fixed(register2Lookup), Lookup.getDefault()), () -> {
- try {
- Field implementations = ClassPath.class.getDeclaredField("implementations");
- implementations.setAccessible(true);
- AtomicReference r = (AtomicReference) implementations.get(null);
- r.set(null);
- } catch (Throwable t) {
- throw new IllegalStateException(t);
- }
+ try {
+ currentRootConfiguration.set(rootConfiguration);
try {
if (globalConfig.apply) {
apply(hints, rootConfiguration.rootFolders.toArray(new Folder[0]), progress, hintSettings, globalConfig.out);
- result[0] = GroupResult.SUCCESS; //TODO: WarningsAndErrors?
+ return GroupResult.SUCCESS; //TODO: WarningsAndErrors?
} else {
findOccurrences(hints, rootConfiguration.rootFolders.toArray(new Folder[0]), progress, hintSettings, wae);
if (wae.errors != 0 || (wae.warnings != 0 && globalConfig.failOnWarnings)) {
- result[0] = GroupResult.FAILURE;
+ return GroupResult.FAILURE;
} else {
- result[0] = GroupResult.SUCCESS;
+ return GroupResult.SUCCESS;
}
}
} catch (IOException t) {
throw new UncheckedIOException(t);
}
- });
-
- return result[0];
+ } finally {
+ currentRootConfiguration.set(prevConfig);
+ }
}
private static class MemoryPreferences extends AbstractPreferences {
@@ -687,7 +655,6 @@ public class Main {
for (Entry<HintMetadata, ? extends Collection<? extends HintDescription>> entry: all.entrySet()) {
if (hardcoded.containsKey(entry.getKey())) {
if (toEnableIn.isEnabled(entry.getKey()) && entry.getKey().kind == Kind.INSPECTION && !entry.getKey().options.contains(Options.NO_BATCH)) {
- System.err.println("enabled:" + entry.getKey().displayName);
descs.addAll(entry.getValue());
}
} else {
@@ -728,7 +695,7 @@ public class Main {
@Override public void cannotVerifySpan(Resource r) {
//TODO: ignored - what to do?
}
- }, problems, new AtomicBoolean());
+ }, true, problems, new AtomicBoolean());
}
private static void print(ErrorDescription error, WarningsAndErrors wae, Map<String, String> id2DisplayName) throws IOException {
@@ -766,7 +733,7 @@ public class Main {
BatchResult occurrences = BatchSearch.findOccurrences(descs, Scopes.specifiedFoldersScope(sourceRoot), w, settings);
List<MessageImpl> problems = new LinkedList<MessageImpl>();
- Collection<ModificationResult> diffs = BatchUtilities.applyFixes(occurrences, w, new AtomicBoolean(), problems);
+ Collection<ModificationResult> diffs = BatchUtilities.applyFixes(occurrences, w, new AtomicBoolean(), new ArrayList<RefactoringElementImplementation>(), null, true, problems);
if (out != null) {
for (ModificationResult mr : diffs) {
@@ -938,26 +905,26 @@ public class Main {
}
}
- public static final class ClassPathProviderImpl implements ClassPathProvider {
- private final ClassPath boot;
- private final ClassPath compile;
- private final ClassPath source;
+ private static final ThreadLocal<RootConfiguration> currentRootConfiguration = new ThreadLocal<>();
- public ClassPathProviderImpl(ClassPath boot, ClassPath compile, ClassPath source) {
- this.boot = boot;
- this.compile = compile;
- this.source = source;
- }
+ @ServiceProvider(service=ClassPathProvider.class, position=100)
+ public static final class ClassPathProviderImpl implements ClassPathProvider {
@Override
public ClassPath findClassPath(FileObject file, String type) {
- if (source.findOwnerRoot(file) != null) {
+ RootConfiguration rootConfiguration = currentRootConfiguration.get();
+
+ if (rootConfiguration == null) {
+ return null;
+ }
+
+ if (rootConfiguration.sourceCP.findOwnerRoot(file) != null) {
if (ClassPath.BOOT.equals(type)) {
- return boot;
+ return rootConfiguration.bootCP;
} else if (ClassPath.COMPILE.equals(type)) {
- return compile;
+ return rootConfiguration.compileCP;
} else if (ClassPath.SOURCE.equals(type)) {
- return source;
+ return rootConfiguration.sourceCP;
}
}
@@ -965,25 +932,25 @@ public class Main {
}
}
+ @ServiceProvider(service=SourceLevelQueryImplementation2.class, position=100)
public static final class SourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
- private final ClassPath sourceCP;
- private final Result sourceLevel;
-
- public SourceLevelQueryImpl(ClassPath sourceCP, final String sourceLevel) {
- this.sourceCP = sourceCP;
- this.sourceLevel = new Result() {
- @Override public String getSourceLevel() {
- return sourceLevel;
- }
- @Override public void addChangeListener(ChangeListener listener) {}
- @Override public void removeChangeListener(ChangeListener listener) {}
- };
- }
@Override
public Result getSourceLevel(FileObject javaFile) {
- if (sourceCP.findOwnerRoot(javaFile) != null) {
- return sourceLevel;
+ RootConfiguration rootConfiguration = currentRootConfiguration.get();
+
+ if (rootConfiguration == null) {
+ return null;
+ }
+
+ if (rootConfiguration.sourceCP.findOwnerRoot(javaFile) != null) {
+ return new Result() {
+ @Override public String getSourceLevel() {
+ return rootConfiguration.sourceLevel;
+ }
+ @Override public void addChangeListener(ChangeListener listener) {}
+ @Override public void removeChangeListener(ChangeListener listener) {}
+ };
} else {
return null;
}
diff --git a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java
index 74784bc..0014e97 100644
--- a/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java
+++ b/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/ProcessorImpl.java
@@ -93,7 +93,7 @@ import org.openide.util.Lookup;
* @author lahvac
*/
@SupportedAnnotationTypes("*")
-@SupportedOptions("hintsConfiguration")
+@SupportedOptions({"hintsConfiguration", "disableJackpotProcessor"})
public class ProcessorImpl extends AbstractProcessor {
public static final String CONFIGURATION_OPTION = "hintsConfiguration";
@@ -102,7 +102,8 @@ public class ProcessorImpl extends AbstractProcessor {
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
-
+ if ("true".equals(processingEnv.getOptions().get("disableJackpotProcessor")))
+ return false;
if (!roundEnv.processingOver()) {
Trees trees = Trees.instance(processingEnv);
for (Element root : roundEnv.getRootElements()) {
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateTool.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateTool.java
index 1418643..2b04b7b 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateTool.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateTool.java
@@ -21,6 +21,7 @@ package org.netbeans.modules.jackpot30.cmdline;
import java.util.regex.Pattern;
import javax.annotation.processing.Processor;
import org.netbeans.modules.jackpot30.cmdline.Main.BCPFallBack;
+import org.netbeans.modules.jackpot30.cmdline.Main.SourceLevelQueryImpl;
import org.netbeans.modules.jackpot30.cmdline.lib.CreateStandaloneJar;
import org.netbeans.modules.jackpot30.cmdline.lib.CreateStandaloneJar.Info;
import org.netbeans.modules.java.hints.declarative.PatternConvertorImpl;
@@ -30,6 +31,7 @@ import org.netbeans.modules.java.j2seproject.J2SEProject;
import org.netbeans.modules.java.platform.DefaultJavaPlatformProvider;
import org.netbeans.modules.project.ui.OpenProjectsTrampolineImpl;
import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
/**
*
@@ -49,6 +51,8 @@ public class CreateTool extends CreateStandaloneJar {
.addMetaInfRegistrations(new MetaInfRegistration(org.netbeans.modules.project.uiapi.OpenProjectsTrampoline.class, OpenProjectsTrampolineImpl.class))
.addMetaInfRegistrations(new MetaInfRegistration(Processor.class, ProcessorImpl.class))
.addMetaInfRegistrations(new MetaInfRegistration(ClassPathProvider.class.getName(), BCPFallBack.class.getName(), 9999))
+ .addMetaInfRegistrations(new MetaInfRegistration(ClassPathProvider.class.getName(), Main.ClassPathProviderImpl.class.getName(), 100))
+ .addMetaInfRegistrations(new MetaInfRegistration(SourceLevelQueryImplementation2.class.getName(), SourceLevelQueryImpl.class.getName(), 100))
.addMetaInfRegistrationToCopy(PatternConvertor.class.getName())
.addExcludePattern(Pattern.compile("junit\\.framework\\..*"));
}
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolTest.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolTest.java
index e65513d..2e3fe02 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolTest.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/CreateToolTest.java
@@ -188,8 +188,4 @@ public class CreateToolTest extends MainTest {
};
}
- public void testSourcePath() throws Exception {
- //the test is unstable in MainTest, but run it here:
- DISABLEDtestSourcePath();
- }
}
diff --git a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
index d92851d..5310b20 100644
--- a/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
+++ b/cmdline/tool/test/unit/src/org/netbeans/modules/jackpot30/cmdline/MainTest.java
@@ -457,7 +457,7 @@ public class MainTest extends NbTestCase {
"1.6");
}
- public void DISABLEDtestSourcePath() throws Exception {
+ public void testSourcePath() throws Exception {
String golden =
"package test;\n" +
"public class Test {\n" +
@@ -829,6 +829,38 @@ public class MainTest extends NbTestCase {
Arrays.asList(Main.splitGroupArg("a\\ b a\\\\b")));
}
+ public void testSourceLevelMatches1() throws Exception {
+ runSourceLevelMatches("1.8",
+ "${workdir}/src/test/Test.java:4: warning: [Convert_to_Lambda_or_Member_Reference] This anonymous inner class creation can be turned into a lambda expression.\n" +
+ " Runnable r = new Runnable() { public void run() { } };\n" +
+ " ^\n");
+ }
+
+ public void testSourceLevelMatches2() throws Exception {
+ runSourceLevelMatches("1.7",
+ "");
+ }
+
+ private void runSourceLevelMatches(String sourceLevel, String expectedOutput) throws Exception {
+ String code = "package test;\n" +
+ "public class Test {\n" +
+ " private void test(java.util.Collection c) {\n" +
+ " Runnable r = new Runnable() { public void run() { } };\n" +
+ " }\n" +
+ "}\n";
+
+ doRunCompiler(code,
+ expectedOutput,
+ null,
+ "src/test/Test.java",
+ code,
+ null,
+ "--hint",
+ "Convert to Lambda or Member Reference",
+ "--source",
+ sourceLevel);
+ }
+
private static final String DONT_APPEND_PATH = new String("DONT_APPEND_PATH");
private static final String IGNORE = new String("IGNORE");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists