You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ge...@apache.org on 2018/02/20 08:40:56 UTC
[incubator-netbeans] branch master updated: [NETBEANS-353] Using
the (--)release setting in Maven projects to return an appropriate value
from SourceLevelQuery. Won't affect the boot/system module class path at
this time. (#408)
This is an automated email from the ASF dual-hosted git repository.
geertjan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new c6ec0e0 [NETBEANS-353] Using the (--)release setting in Maven projects to return an appropriate value from SourceLevelQuery. Won't affect the boot/system module class path at this time. (#408)
c6ec0e0 is described below
commit c6ec0e0bc2bb8e994b1321afd0840f2e2c6d93cf
Author: Jan Lahoda <la...@gmail.com>
AuthorDate: Tue Feb 20 09:40:54 2018 +0100
[NETBEANS-353] Using the (--)release setting in Maven projects to return an appropriate value from SourceLevelQuery. Won't affect the boot/system module class path at this time. (#408)
---
.../org/netbeans/modules/maven/api/Constants.java | 1 +
.../maven/queries/MavenSourceLevelImpl.java | 47 ++++++++++++----------
.../maven/queries/MavenSourceLevelImplTest.java | 27 +++++++++++++
3 files changed, 54 insertions(+), 21 deletions(-)
diff --git a/maven/src/org/netbeans/modules/maven/api/Constants.java b/maven/src/org/netbeans/modules/maven/api/Constants.java
index 8c7c759..2020e56 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 interface Constants {
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 0086784..774e088 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.io.File;
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.netbeans.spi.project.ProjectServiceProvider;
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 @@ public class MavenSourceLevelImpl implements SourceLevelQueryImplementation2 {
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 @@ public class MavenSourceLevelImpl implements SourceLevelQueryImplementation2 {
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 691f903..7bea36a 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 class MavenSourceLevelImplTest extends NbTestCase {
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));
+ }
+
}
--
To stop receiving notification emails like this one, please contact
geertjan@apache.org.
---------------------------------------------------------------------
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