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 2018/04/26 05:12:01 UTC

[incubator-netbeans] branch master updated: [NETBEANS-710] Ensure the javac's module system is initialized before constructing scope, fixing DeclarativeHintsParserTest tests on JDK 11 by using the default platform's bootclasspath implicitly rather than explicitly.

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a102db  [NETBEANS-710] Ensure the javac's module system is initialized before constructing scope, fixing DeclarativeHintsParserTest tests on JDK 11 by using the default platform's bootclasspath implicitly rather than explicitly.
9a102db is described below

commit 9a102db55c58820f92c94a190528b2ed6ff727ed
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Sun Apr 22 10:43:31 2018 +0200

    [NETBEANS-710] Ensure the javac's module system is initialized before constructing scope, fixing DeclarativeHintsParserTest tests on JDK 11 by using the default platform's bootclasspath implicitly rather than explicitly.
---
 java.hints.declarative/nbproject/project.xml         |  4 ++++
 .../hints/declarative/ClassPathProviderImpl.java     |  6 ++----
 .../hints/declarative/DeclarativeHintsParser.java    |  1 +
 .../modules/java/hints/declarative/Hacks.java        |  3 +--
 .../hints/declarative/MethodInvocationContext.java   | 14 +++-----------
 .../modules/java/TestJavaPlatformProviderImpl.java   | 20 ++------------------
 6 files changed, 13 insertions(+), 35 deletions(-)

diff --git a/java.hints.declarative/nbproject/project.xml b/java.hints.declarative/nbproject/project.xml
index 8908c51..09d333e 100644
--- a/java.hints.declarative/nbproject/project.xml
+++ b/java.hints.declarative/nbproject/project.xml
@@ -373,6 +373,10 @@
                         <compile-dependency/>
                     </test-dependency>
                     <test-dependency>
+                        <code-name-base>org.netbeans.modules.java.j2seplatform</code-name-base>
+                        <compile-dependency/>
+                    </test-dependency>
+                    <test-dependency>
                         <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
                     </test-dependency>
                     <test-dependency>
diff --git a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/ClassPathProviderImpl.java b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/ClassPathProviderImpl.java
index 9a13ba4..4d0d37b 100644
--- a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/ClassPathProviderImpl.java
+++ b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/ClassPathProviderImpl.java
@@ -33,10 +33,8 @@ public class ClassPathProviderImpl implements ClassPathProvider {
 
     public ClassPath findClassPath(FileObject file, String type) {
         if ("hint".equals(file.getExt())) {
-            if (ClassPath.BOOT.equals(type)) {
-                return MethodInvocationContext.computeClassPaths()[0];
-            } else if (ClassPath.COMPILE.equals(type)) {
-                return MethodInvocationContext.computeClassPaths()[1];
+            if (ClassPath.COMPILE.equals(type)) {
+                return MethodInvocationContext.computeCompileClassPath();
             }
         }
 
diff --git a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
index ddfe296..bf4729c 100644
--- a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
+++ b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
@@ -477,6 +477,7 @@ public class DeclarativeHintsParser {
         JavaSource.create(cpInfo).runUserActionTask(new Task<CompilationController>() {
             @SuppressWarnings("fallthrough")
             public void run(CompilationController parameter) throws Exception {
+                parameter.toPhase(JavaSource.Phase.RESOLVED);
                 if (invocation == null || invocation.length() == 0) {
                     //XXX: report an error
                     return ;
diff --git a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Hacks.java b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Hacks.java
index fd10dad..7ff8c27 100644
--- a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Hacks.java
+++ b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Hacks.java
@@ -75,13 +75,12 @@ public class Hacks {
 
     private static final String SOURCE_LEVEL = "1.8"; //TODO: could be possibly inferred from the current Java platform
 
-    public static Map<String, byte[]> compile(ClassPath boot, ClassPath compile, final String code) throws IOException {
+    public static Map<String, byte[]> compile(ClassPath compile, final String code) throws IOException {
         DiagnosticListener<JavaFileObject> devNull = new DiagnosticListener<JavaFileObject>() {
             public void report(Diagnostic<? extends JavaFileObject> diagnostic) {}
         };
         StandardJavaFileManager sjfm = ToolProvider.getSystemJavaCompiler().getStandardFileManager(devNull, null, null);
 
-        sjfm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, toFiles(boot));
         sjfm.setLocation(StandardLocation.CLASS_PATH, toFiles(compile));
 
         final Map<String, ByteArrayOutputStream> class2BAOS = new HashMap<String, ByteArrayOutputStream>();
diff --git a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
index cf822f7..13f8747 100644
--- a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
+++ b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
@@ -231,10 +231,8 @@ public class MethodInvocationContext {
 
         code.append("}\n");
 
-        ClassPath[] classpaths = computeClassPaths();
-
         try {
-            final Map<String, byte[]> classes = Hacks.compile(classpaths[0], classpaths[1], code.toString());
+            final Map<String, byte[]> classes = Hacks.compile(computeCompileClassPath(), code.toString());
 
             if (!classes.containsKey("$." + className)) {
                 //presumably an error in the custom code, skip
@@ -271,14 +269,8 @@ public class MethodInvocationContext {
         "import org.netbeans.modules.java.hints.declarative.conditionapi.Variable;"
     };
 
-    static ClassPath[] computeClassPaths() {
-        ClassPath boot = JavaPlatform.getDefault().getBootstrapLibraries();
-        ClassPath compile = ClassPathSupport.createClassPath(apiJarURL());
-
-        return new ClassPath[] {
-            boot,
-            compile
-        };
+    static ClassPath computeCompileClassPath() {
+        return ClassPathSupport.createClassPath(apiJarURL());
     }
 
     public static URL apiJarURL() {
diff --git a/java.source/test/unit/src/org/netbeans/modules/java/TestJavaPlatformProviderImpl.java b/java.source/test/unit/src/org/netbeans/modules/java/TestJavaPlatformProviderImpl.java
index acefa28..57b4b90 100644
--- a/java.source/test/unit/src/org/netbeans/modules/java/TestJavaPlatformProviderImpl.java
+++ b/java.source/test/unit/src/org/netbeans/modules/java/TestJavaPlatformProviderImpl.java
@@ -31,6 +31,7 @@ import org.netbeans.api.java.classpath.ClassPath;
 import org.netbeans.api.java.platform.JavaPlatform;
 import org.netbeans.modules.java.platform.implspi.JavaPlatformProvider;
 import org.netbeans.api.java.platform.Specification;
+import org.netbeans.modules.java.source.BootClassPathUtil;
 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileStateInvalidException;
@@ -82,24 +83,7 @@ public class TestJavaPlatformProviderImpl implements JavaPlatformProvider {
 
         private static synchronized ClassPath getBootClassPath() {
             if (bootClassPath == null) {
-                String cp = System.getProperty("sun.boot.class.path");
-                List<URL> urls = new ArrayList<>();
-                String[] paths = cp.split(Pattern.quote(System.getProperty("path.separator")));
-                for (String path : paths) {
-                    File f = new File(path);
-
-                    if (!f.canRead())
-                        continue;
-
-                    FileObject fo = FileUtil.toFileObject(f);
-                    if (FileUtil.isArchiveFile(fo)) {
-                        fo = FileUtil.getArchiveRoot(fo);
-                    }
-                    if (fo != null) {
-                        urls.add(fo.toURL());
-                    }
-                }
-                bootClassPath = ClassPathSupport.createClassPath((URL[])urls.toArray(new URL[0]));
+                bootClassPath = BootClassPathUtil.getBootClassPath();
             }
             return bootClassPath;
         }

-- 
To stop receiving notification emails like this one, please contact
jlahoda@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