8164951: Build broken after JDK-8164745
authorjlahoda
Mon, 29 Aug 2016 18:14:26 +0200
changeset 40604 92e423b99e98
parent 40603 a890cefaa41b
child 40605 926c13175b67
8164951: Build broken after JDK-8164745 Summary: Reverting the fix for JDK-8164745 to investigate a build failure. Reviewed-by: jjg
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java
langtools/test/tools/javac/modules/XModuleTest.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java	Mon Aug 29 08:17:14 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java	Mon Aug 29 18:14:26 2016 +0200
@@ -119,6 +119,10 @@
      */
     final Name completionFailureName;
 
+    /** Module specified with -Xmodule:
+     */
+    final Name moduleOverride;
+
     /** Access to files
      */
     private final JavaFileManager fileManager;
@@ -206,6 +210,9 @@
             ? names.fromString(options.get("failcomplete"))
             : null;
 
+        moduleOverride = options.isSet(Option.XMODULE) ? names.fromString(options.get(Option.XMODULE))
+                                                : null;
+
         // Temporary, until more info is available from the module system.
         boolean useCtProps;
         JavaFileManager fm = context.get(JavaFileManager.class);
@@ -520,15 +527,16 @@
         if (msym == syms.noModule) {
             preferCurrent = false;
             if (userPathsFirst) {
-                scanUserPaths(p, true);
+                scanUserPaths(p);
                 preferCurrent = true;
                 scanPlatformPath(p);
             } else {
                 scanPlatformPath(p);
-                scanUserPaths(p, true);
+                scanUserPaths(p);
             }
         } else if (msym.classLocation == StandardLocation.CLASS_PATH) {
-            scanUserPaths(p, msym.sourceLocation == StandardLocation.SOURCE_PATH);
+            // assert p.modle.sourceLocation == StandardLocation.SOURCE_PATH);
+            scanUserPaths(p);
         } else {
             scanModulePaths(p, msym);
         }
@@ -553,6 +561,23 @@
 
         String packageName = p.fullname.toString();
 
+        if (msym.name == moduleOverride) {
+            if (wantClassFiles) {
+                fillIn(p, CLASS_PATH,
+                       fileManager.list(CLASS_PATH,
+                                        packageName,
+                                        classKinds,
+                                        false));
+            }
+            if (wantSourceFiles && fileManager.hasLocation(SOURCE_PATH)) {
+                fillIn(p, SOURCE_PATH,
+                        fileManager.list(SOURCE_PATH,
+                                        packageName,
+                                        sourceKinds,
+                                        false));
+            }
+        }
+
         Location classLocn = msym.classLocation;
         Location sourceLocn = msym.sourceLocation;
 
@@ -575,7 +600,7 @@
     /**
      * Scans class path and source path for files in given package.
      */
-    private void scanUserPaths(PackageSymbol p, boolean includeSourcePath) throws IOException {
+    private void scanUserPaths(PackageSymbol p) throws IOException {
         Set<JavaFileObject.Kind> kinds = getPackageFileKinds();
 
         Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds);
@@ -586,7 +611,7 @@
         sourceKinds.remove(JavaFileObject.Kind.CLASS);
         boolean wantSourceFiles = !sourceKinds.isEmpty();
 
-        boolean haveSourcePath = includeSourcePath && fileManager.hasLocation(SOURCE_PATH);
+        boolean haveSourcePath = fileManager.hasLocation(SOURCE_PATH);
 
         if (verbose && verbosePath) {
             if (fileManager instanceof StandardJavaFileManager) {
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Mon Aug 29 08:17:14 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Mon Aug 29 18:14:26 2016 +0200
@@ -392,7 +392,6 @@
                             if (moduleOverride != null) {
                                 checkNoAllModulePath();
                                 defaultModule = moduleFinder.findModule(names.fromString(moduleOverride));
-                                defaultModule.sourceLocation = StandardLocation.SOURCE_PATH;
                             } else {
                                 // Question: why not do findAllModules and initVisiblePackages here?
                                 // i.e. body of unnamedModuleCompleter
@@ -433,9 +432,7 @@
 
             if (defaultModule != syms.unnamedModule) {
                 syms.unnamedModule.completer = getUnnamedModuleCompleter();
-                if (moduleOverride == null) {
-                    syms.unnamedModule.sourceLocation = StandardLocation.SOURCE_PATH;
-                }
+                syms.unnamedModule.sourceLocation = StandardLocation.SOURCE_PATH;
                 syms.unnamedModule.classLocation = StandardLocation.CLASS_PATH;
             }
 
--- a/langtools/test/tools/javac/modules/XModuleTest.java	Mon Aug 29 08:17:14 2016 -0700
+++ b/langtools/test/tools/javac/modules/XModuleTest.java	Mon Aug 29 18:14:26 2016 +0200
@@ -27,9 +27,7 @@
  * @library /tools/lib
  * @modules
  *      jdk.compiler/com.sun.tools.javac.api
- *      jdk.compiler/com.sun.tools.javac.code
  *      jdk.compiler/com.sun.tools.javac.main
- *      jdk.compiler/com.sun.tools.javac.processing
  * @build toolbox.ToolBox toolbox.JavacTask toolbox.ModuleBuilder ModuleTestBase
  * @run main XModuleTest
  */
@@ -37,22 +35,12 @@
 import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Set;
 
-import javax.annotation.processing.AbstractProcessor;
-import javax.annotation.processing.RoundEnvironment;
-import javax.annotation.processing.SupportedAnnotationTypes;
-import javax.lang.model.SourceVersion;
-import javax.lang.model.element.ModuleElement;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.util.Elements;
-
-import com.sun.tools.javac.code.Symtab;
-import com.sun.tools.javac.processing.JavacProcessingEnvironment;
 import toolbox.JavacTask;
 import toolbox.ModuleBuilder;
 import toolbox.Task;
-import toolbox.Task.Expect;
+import toolbox.TestRunner;
+import toolbox.ToolBox;
 
 public class XModuleTest extends ModuleTestBase {
 
@@ -123,22 +111,15 @@
         Path classes = base.resolve("classes");
         tb.createDirectories(classes);
 
-        List<String> log = new JavacTask(tb)
-                .options("-Xmodule:java.compiler",
-                         "--class-path", cpClasses.toString(),
-                         "-XDrawDiagnostics")
+        String log = new JavacTask(tb)
+                .options("-Xmodule:java.compiler", "--class-path", cpClasses.toString())
                 .outdir(classes)
                 .files(src.resolve("javax/lang/model/element/Extra.java"))
-                .run(Expect.FAIL)
+                .run()
                 .writeAll()
-                .getOutputLines(Task.OutputKind.DIRECT);
+                .getOutput(Task.OutputKind.DIRECT);
 
-        List<String> expectedOut = Arrays.asList(
-                "Extra.java:1:76: compiler.err.doesnt.exist: p",
-                "1 error"
-        );
-
-        if (!expectedOut.equals(log))
+        if (!log.isEmpty())
             throw new Exception("expected output not found: " + log);
     }
 
@@ -321,103 +302,4 @@
                 .run()
                 .writeAll();
     }
-
-    @Test
-    public void testUnnamedIsolation(Path base) throws Exception {
-        //note: avoiding use of java.base, as that gets special handling on some places:
-        Path sourcePath = base.resolve("source-path");
-        tb.writeJavaFiles(sourcePath, "package src; public class Src {}");
-
-        Path classPathSrc = base.resolve("class-path-src");
-        tb.writeJavaFiles(classPathSrc, "package cp; public class CP { }");
-        Path classPath = base.resolve("classPath");
-        tb.createDirectories(classPath);
-
-        String cpLog = new JavacTask(tb)
-                .outdir(classPath)
-                .files(findJavaFiles(classPathSrc))
-                .run()
-                .writeAll()
-                .getOutput(Task.OutputKind.DIRECT);
-
-        if (!cpLog.isEmpty())
-            throw new Exception("expected output not found: " + cpLog);
-
-        Path modulePathSrc = base.resolve("module-path-src");
-        tb.writeJavaFiles(modulePathSrc,
-                          "module m {}",
-                          "package m; public class M {}");
-        Path modulePath = base.resolve("modulePath");
-        tb.createDirectories(modulePath.resolve("m"));
-
-        String modLog = new JavacTask(tb)
-                .outdir(modulePath.resolve("m"))
-                .files(findJavaFiles(modulePathSrc))
-                .run()
-                .writeAll()
-                .getOutput(Task.OutputKind.DIRECT);
-
-        if (!modLog.isEmpty())
-            throw new Exception("expected output not found: " + modLog);
-
-        Path src = base.resolve("src");
-        tb.writeJavaFiles(src, "package m; public class Extra { }");
-        Path classes = base.resolve("classes");
-        tb.createDirectories(classes);
-
-        String log = new JavacTask(tb)
-                .options("-Xmodule:m",
-                         "--class-path", classPath.toString(),
-                         "--source-path", sourcePath.toString(),
-                         "--module-path", modulePath.toString(),
-                         "-XDaccessInternalAPI=true",
-                         "--processor-path", System.getProperty("test.classes"),
-                         "-processor", CheckModuleContentProcessing.class.getName())
-                .outdir(classes)
-                .files(findJavaFiles(sourcePath))
-                .run()
-                .writeAll()
-                .getOutput(Task.OutputKind.DIRECT);
-
-        if (!log.isEmpty())
-            throw new Exception("expected output not found: " + log);
-    }
-
-    @SupportedAnnotationTypes("*")
-    public static final class CheckModuleContentProcessing extends AbstractProcessor {
-
-        @Override
-        public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
-            Symtab syms = Symtab.instance(((JavacProcessingEnvironment) processingEnv).getContext());
-            Elements elements = processingEnv.getElementUtils();
-            ModuleElement unnamedModule = syms.unnamedModule;
-            ModuleElement mModule = elements.getModuleElement("m");
-
-            assertNonNull("mModule found", mModule);
-            assertNonNull("src.Src from m", elements.getTypeElement(mModule, "src.Src"));
-            assertNull("cp.CP not from m", elements.getTypeElement(mModule, "cp.CP"));
-            assertNull("src.Src not from unnamed", elements.getTypeElement(unnamedModule, "src.Src"));
-            assertNonNull("cp.CP from unnamed", elements.getTypeElement(unnamedModule, "cp.CP"));
-
-            return false;
-        }
-
-        @Override
-        public SourceVersion getSupportedSourceVersion() {
-            return SourceVersion.latest();
-        }
-
-    }
-
-    private static void assertNonNull(String msg, Object val) {
-        if (val == null) {
-            throw new AssertionError(msg);
-        }
-    }
-
-    private static void assertNull(String msg, Object val) {
-        if (val != null) {
-            throw new AssertionError(msg);
-        }
-    }
 }