You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/02/20 08:40:58 UTC

[GitHub] geertjanw closed pull request #408: [NETBEANS-353] Using the (--)release setting in Maven projects to ret?

geertjanw closed pull request #408: [NETBEANS-353] Using the (--)release setting in Maven projects to ret?
URL: https://github.com/apache/incubator-netbeans/pull/408
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/maven/src/org/netbeans/modules/maven/api/Constants.java b/maven/src/org/netbeans/modules/maven/api/Constants.java
index 8c7c7591e..2020e56f5 100644
--- a/maven/src/org/netbeans/modules/maven/api/Constants.java
+++ b/maven/src/org/netbeans/modules/maven/api/Constants.java
@@ -86,6 +86,7 @@
     public static final String PLUGIN_CHECKSTYLE = "maven-checkstyle-plugin";//NOI18N
     
     public static final String ENCODING_PARAM = "encoding"; //NOI18N
+    public static final String RELEASE_PARAM = "release";//NOI18N
     public static final String SOURCE_PARAM = "source";//NOI18N
     public static final String TARGET_PARAM = "target";//NOI18N
 
diff --git a/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java b/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java
index 0086784ae..774e0889d 100644
--- a/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java
+++ b/maven/src/org/netbeans/modules/maven/queries/MavenSourceLevelImpl.java
@@ -25,6 +25,7 @@
 import java.net.URI;
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
@@ -44,6 +45,7 @@
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.util.ChangeSupport;
+import org.openide.util.Pair;
 import org.openide.util.Utilities;
 import org.openide.util.WeakListeners;
 
@@ -58,6 +60,20 @@
     private static final Logger LOGGER = Logger.getLogger(MavenSourceLevelImpl.class.getName());
     
     static final Pattern PROFILE = Pattern.compile("-profile (compact1|compact2|compact3){1}?");
+
+    private static final List<Pair<String, String>> SOURCE_PROPERTIES_AND_PARAM = Arrays.asList(
+        Pair.of("maven.compiler.release", Constants.RELEASE_PARAM), //NOI18N
+        Pair.of("maven.compiler.source", Constants.SOURCE_PARAM)   //NOI18N
+    );
+
+    private static final List<Pair<String, String>> TEST_PROPERTIES_AND_PARAM = Arrays.asList(
+        Pair.of("maven.compiler.testRelease", "testRelease"),       //NOI18N
+        Pair.of("maven.compiler.release", Constants.RELEASE_PARAM), //NOI18N
+        Pair.of("maven.compiler.testSource", "testSource"),        //NOI18N
+        //#237986 in tests, first try "testSource" param, then fallback to "source":
+        Pair.of("maven.compiler.source", Constants.SOURCE_PARAM)   //NOI18N
+    );
+
     private final Project project;
 
     public MavenSourceLevelImpl(Project proj) {
@@ -73,43 +89,32 @@ private String getSourceLevelString(FileObject javaFile) {
         URI uri = Utilities.toURI(file);
         assert "file".equals(uri.getScheme());
         String goal = "compile"; //NOI18N
-        String property = "maven.compiler.source";
-        String param = Constants.SOURCE_PARAM;
+        List<Pair<String, String>> propertiesAndParams = SOURCE_PROPERTIES_AND_PARAM;
         NbMavenProjectImpl nbprj = project.getLookup().lookup(NbMavenProjectImpl.class);
         for (URI testuri : nbprj.getSourceRoots(true)) {
             if (uri.getPath().startsWith(testuri.getPath())) {
                 goal = "testCompile"; //NOI18N
-                property = "maven.compiler.testSource";
-                param = "testSource";
+                propertiesAndParams = TEST_PROPERTIES_AND_PARAM;
             }
         }
         for (URI testuri : nbprj.getGeneratedSourceRoots(true)) {
             if (uri.getPath().startsWith(testuri.getPath())) {
                 goal = "testCompile"; //NOI18N
-                property = "maven.compiler.testSource";
-                param = "testSource";
+                propertiesAndParams = TEST_PROPERTIES_AND_PARAM;
             }
         }
-        String sourceLevel = PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS,  //NOI18N
-                                                              Constants.PLUGIN_COMPILER,  //NOI18N
-                                                              param,  //NOI18N
-                                                              goal,
-                                                              property);
-        if (sourceLevel != null) {
-            return sourceLevel;
-        }
-        if ("testCompile".equals(goal)) { //#237986 in tests, first try "testSource" param, then fallback to "source"
-            sourceLevel = PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS,  //NOI18N
-                                                              Constants.PLUGIN_COMPILER,  //NOI18N
-                                                              Constants.SOURCE_PARAM,  //NOI18N
-                                                              "testCompile",
-                                                              "maven.compiler.source");            
+
+        for (Pair<String, String> propertyAndParam : propertiesAndParams) {
+            String sourceLevel = PluginPropertyUtils.getPluginProperty(project, Constants.GROUP_APACHE_PLUGINS,  //NOI18N
+                                                                  Constants.PLUGIN_COMPILER,  //NOI18N
+                                                                  propertyAndParam.second(),
+                                                                  goal,
+                                                                  propertyAndParam.first());
             if (sourceLevel != null) {
                 return sourceLevel;
             }
         }
         
-        
         String version = PluginPropertyUtils.getPluginVersion(
                 nbprj.getOriginalMavenProject(),
                 Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER);
diff --git a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSourceLevelImplTest.java b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSourceLevelImplTest.java
index 691f9036e..7bea36a70 100644
--- a/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSourceLevelImplTest.java
+++ b/maven/test/unit/src/org/netbeans/modules/maven/queries/MavenSourceLevelImplTest.java
@@ -183,4 +183,31 @@ public void testPattern() throws Exception {
         assertTrue(m.find());
         assertEquals("compact1", m.group(1));
     }
+
+    public void testRelease() throws Exception { // #NETBEANS-353
+        TestFileUtils.writeFile(wd,
+                "pom.xml",
+                "<project xmlns='http://maven.apache.org/POM/4.0.0'>" +
+                "<modelVersion>4.0.0</modelVersion>" +
+                "<groupId>grp</groupId>" +
+                "<artifactId>art</artifactId>" +
+                "<packaging>jar</packaging>" +
+                "<version>0</version>" +
+                "<build><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.6</version><executions>" +
+                "<execution><id>comp-src</id><phase>compile</phase><goals><goal>compile</goal></goals><configuration><release>1.8</release></configuration></execution>" +
+                "<execution><id>comp-tsrc</id><phase>test-compile</phase><goals><goal>testCompile</goal></goals><configuration><release>1.9</release></configuration></execution>" +
+                "</executions></plugin></plugins></build>" +
+                "</project>");
+        FileObject src = FileUtil.createFolder(wd, "src/main/java");
+        FileObject gsrc = FileUtil.createFolder(wd, "target/generated-sources/xjc");
+        gsrc.createData("Whatever.class");
+        FileObject tsrc = FileUtil.createFolder(wd, "src/test/java");
+        FileObject gtsrc = FileUtil.createFolder(wd, "target/generated-test-sources/jaxb");
+        gtsrc.createData("Whatever.class");
+        assertEquals("1.8", SourceLevelQuery.getSourceLevel(src));
+        assertEquals("1.8", SourceLevelQuery.getSourceLevel(gsrc));
+        assertEquals("9", SourceLevelQuery.getSourceLevel(tsrc));
+        assertEquals("9", SourceLevelQuery.getSourceLevel(gtsrc));
+    }
+
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists