changeset 4274:1898244b4732

Module names of automatic modules should be version-free names
author jlahoda
date Wed, 24 Aug 2016 23:23:00 +0200
parents 5a5b5ef095c4
children d1d80e52e44c
files src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java test/tools/javac/modules/AutomaticModules.java test/tools/javac/modules/EdgeCases.java test/tools/javac/modules/ModulePathTest.java
diffstat 4 files changed, 57 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Wed Aug 24 13:04:11 2016 -0700
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Wed Aug 24 23:23:00 2016 +0200
@@ -1072,7 +1072,8 @@
                     }
 
                     // finally clean up the module name
-                    mn =  mn.replaceAll("[^A-Za-z0-9]", ".")  // replace non-alphanumeric
+                    mn =  mn.replaceAll("(\\.|\\d)*$", "")    // remove trailing version
+                            .replaceAll("[^A-Za-z0-9]", ".")  // replace non-alphanumeric
                             .replaceAll("(\\.)(\\1)+", ".")   // collapse repeating dots
                             .replaceAll("^\\.", "")           // drop leading dots
                             .replaceAll("\\.$", "");          // drop trailing dots
--- a/test/tools/javac/modules/AutomaticModules.java	Wed Aug 24 13:04:11 2016 -0700
+++ b/test/tools/javac/modules/AutomaticModules.java	Wed Aug 24 23:23:00 2016 +0200
@@ -308,4 +308,54 @@
             throw new Exception("expected output not found: " + log);
         }
     }
+
+    @Test
+    public void testDropTrailingVersion(Path base) throws Exception {
+        Path legacySrc = base.resolve("legacy-src");
+        tb.writeJavaFiles(legacySrc,
+                          "package api; public class Api {}");
+        Path legacyClasses = base.resolve("legacy-classes");
+        Files.createDirectories(legacyClasses);
+
+        String log = new JavacTask(tb)
+                .options()
+                .outdir(legacyClasses)
+                .files(findJavaFiles(legacySrc))
+                .run()
+                .writeAll()
+                .getOutput(Task.OutputKind.DIRECT);
+
+        if (!log.isEmpty()) {
+            throw new Exception("unexpected output: " + log);
+        }
+
+        Path modulePath = base.resolve("module-path");
+
+        Files.createDirectories(modulePath);
+
+        Path jar = modulePath.resolve("test1.jar");
+
+        new JarTask(tb, jar)
+          .baseDir(legacyClasses)
+          .files("api/Api.class")
+          .run();
+
+        Path moduleSrc = base.resolve("module-src");
+        Path m = moduleSrc.resolve("m");
+
+        Path classes = base.resolve("classes");
+
+        Files.createDirectories(classes);
+
+        tb.writeJavaFiles(m,
+                          "module m { requires test; }",
+                          "package impl; public class Impl { public void e(api.Api api) { } }");
+
+        new JavacTask(tb)
+                .options("--module-source-path", moduleSrc.toString(), "--module-path", modulePath.toString())
+                .outdir(classes)
+                .files(findJavaFiles(moduleSrc))
+                .run()
+                .writeAll();
+    }
 }
--- a/test/tools/javac/modules/EdgeCases.java	Wed Aug 24 13:04:11 2016 -0700
+++ b/test/tools/javac/modules/EdgeCases.java	Wed Aug 24 23:23:00 2016 +0200
@@ -202,7 +202,7 @@
 
         Files.createDirectories(modulePath);
 
-        Path automaticJar = modulePath.resolve("m1-1.0.jar");
+        Path automaticJar = modulePath.resolve("a-1.0.jar");
 
         new JarTask(tb, automaticJar)
           .baseDir(automaticClasses)
@@ -212,11 +212,11 @@
         Path src = base.resolve("src");
         Path src_m2 = src.resolve("m2");
         tb.writeJavaFiles(src_m2,
-                          "module m2 { requires m1; exports api2; }",
+                          "module m2 { requires a; exports api2; }",
                           "package api2; public class Api2 { public static api1.Api1 get() { return null; } }");
         Path src_m3 = src.resolve("m3");
         tb.writeJavaFiles(src_m3,
-                          "module m3 { requires m1; requires m2; }",
+                          "module m3 { requires a; requires m2; }",
                           "package test; public class Test { { api2.Api2.get(); api1.Api1 a1; } }");
         Path classes = base.resolve("classes");
         tb.createDirectories(classes);
--- a/test/tools/javac/modules/ModulePathTest.java	Wed Aug 24 13:04:11 2016 -0700
+++ b/test/tools/javac/modules/ModulePathTest.java	Wed Aug 24 23:23:00 2016 +0200
@@ -177,7 +177,7 @@
                 .run()
                 .writeAll();
 
-        Path moduleJar = base.resolve("m1.jar");
+        Path moduleJar = base.resolve("a.jar");
         new JarTask(tb, moduleJar)
           .baseDir(jarClasses)
           .files("p/CC.class")
@@ -190,7 +190,7 @@
 
         new JavacTask(tb, Task.Mode.CMDLINE)
                 .outdir(classes)
-                .options("--module-path", moduleJar.toString(), "--add-modules", "m1")
+                .options("--module-path", moduleJar.toString(), "--add-modules", "a")
                 .files(findJavaFiles(src))
                 .run()
                 .writeAll();