changeset 4287:d26b4bb63771

exports private should accept packages which contain only resources.
author jlahoda
date Wed, 07 Sep 2016 15:24:07 +0200
parents df338e714f64
children 58e13c1ee886
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java test/tools/javac/modules/ReportNonExistentPackageTest.java
diffstat 4 files changed, 53 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java	Tue Sep 06 15:11:25 2016 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java	Wed Sep 07 15:24:07 2016 +0200
@@ -549,7 +549,7 @@
     // One plausible solution is to detect if the module's sourceLocation
     // is the same as the module's classLocation.
     private void scanModulePaths(PackageSymbol p, ModuleSymbol msym) throws IOException {
-        Set<JavaFileObject.Kind> kinds = getPackageFileKinds();
+        Set<JavaFileObject.Kind> kinds = EnumSet.allOf(JavaFileObject.Kind.class);//getPackageFileKinds();
 
         Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds);
         classKinds.remove(JavaFileObject.Kind.SOURCE);
@@ -601,7 +601,7 @@
      * Scans class path and source path for files in given package.
      */
     private void scanUserPaths(PackageSymbol p) throws IOException {
-        Set<JavaFileObject.Kind> kinds = getPackageFileKinds();
+        Set<JavaFileObject.Kind> kinds = EnumSet.allOf(JavaFileObject.Kind.class);//getPackageFileKinds();
 
         Set<JavaFileObject.Kind> classKinds = EnumSet.copyOf(kinds);
         classKinds.remove(JavaFileObject.Kind.SOURCE);
@@ -691,6 +691,7 @@
                                       allowSigFiles &&
                                       fo.getName().endsWith(".sig");
                     if (!sigFile) {
+                        p.flags_field |= Flags.HAS_RESOURCE;
                         extraFileActions(p, fo);
                         break;
                     }
@@ -706,7 +707,9 @@
                     break;
                 }
                 default:
+                    p.flags_field |= Flags.HAS_RESOURCE;
                     extraFileActions(p, fo);
+                    break;
                 }
             }
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Tue Sep 06 15:11:25 2016 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Flags.java	Wed Sep 07 15:24:07 2016 +0200
@@ -293,6 +293,11 @@
      */
     public static final long SYSTEM_MODULE = 1L<<53;
 
+    /**
+     * Flag to indicate the given PackageSymbol contains any non-.java and non-.class resources.
+     */
+    public static final long HAS_RESOURCE = 1L<<54;
+
     /** Modifier masks.
      */
     public static final int
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Tue Sep 06 15:11:25 2016 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java	Wed Sep 07 15:24:07 2016 +0200
@@ -813,7 +813,8 @@
 
         @Override
         public void visitExports(JCExports tree) {
-            if (tree.directive.packge != null && tree.directive.packge.members().isEmpty()) {
+            if (tree.directive.packge.members().isEmpty() &&
+                (!tree.directive.isPrivate() || (tree.directive.packge.flags() & Flags.HAS_RESOURCE) == 0)) {
                 log.error(tree.qualid.pos(), Errors.PackageEmptyOrNotFound(tree.directive.packge));
             }
             msym.directives = msym.directives.prepend(tree.directive);
--- a/test/tools/javac/modules/ReportNonExistentPackageTest.java	Tue Sep 06 15:11:25 2016 +0200
+++ b/test/tools/javac/modules/ReportNonExistentPackageTest.java	Wed Sep 07 15:24:07 2016 +0200
@@ -103,4 +103,45 @@
         if (!log.contains("module-info.java:1:20: compiler.err.package.empty.or.not.found: p1"))
             throw new Exception("expected output not found");
     }
+
+    @Test
+    public void testExportPrivateEmptyPackage(Path base) throws Exception {
+        Path src = base.resolve("src");
+        tb.writeJavaFiles(src,
+                "module m { exports private p; }");
+        Path classes = base.resolve("classes");
+        Files.createDirectories(classes);
+
+        String log = new JavacTask(tb)
+                .options("-XDrawDiagnostics")
+                .outdir(classes)
+                .files(findJavaFiles(src))
+                .run(Task.Expect.FAIL)
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+        if (!log.contains("module-info.java:1:28: compiler.err.package.empty.or.not.found: p"))
+            throw new Exception("expected output not found, actual output: " + log);
+    }
+
+    @Test
+    public void testExportPrivateOnlyWithResources(Path base) throws Exception {
+        Path src = base.resolve("src");
+        tb.writeJavaFiles(src,
+                "module m { exports private p; }");
+        Path resource = src.resolve("p").resolve("resource.properties");
+        Files.createDirectories(resource.getParent());
+        Files.newOutputStream(resource).close();
+        Path classes = base.resolve("classes");
+        Files.createDirectories(classes);
+
+        String log = new JavacTask(tb)
+                .sourcepath(src.toString())
+                .outdir(classes)
+                .files(findJavaFiles(src))
+                .run()
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+        if (!log.equals(""))
+            throw new Exception("expected output not found, actual output: " + log);
+    }
 }