changeset 14515:5dbfdd461d03

Change -listmods to list observable modules
author alanb
date Sun, 29 Nov 2015 19:43:15 +0000
parents ab5b6e7e9db6
children 8898f03465f2 db40b83b1071
files src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java src/java.base/share/classes/sun/launcher/LauncherHelper.java src/java.base/share/classes/sun/launcher/resources/launcher.properties src/java.base/share/native/libjli/java.c test/jdk/jigsaw/launcher/listmods/ListModsTest.java test/jdk/jigsaw/launcher/listmods/src/java.transaction/javax/transaction/Transaction.java test/jdk/jigsaw/launcher/listmods/src/java.transaction/javax/transaction/atomic/Atomic.java test/jdk/jigsaw/launcher/listmods/src/java.transaction/module-info.java test/jdk/jigsaw/launcher/listmods/src/m1/module-info.java
diffstat 9 files changed, 233 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Sun Nov 29 10:55:13 2015 +0000
+++ b/src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java	Sun Nov 29 19:43:15 2015 +0000
@@ -69,6 +69,16 @@
     // the token for "all system modules"
     private static final String ALL_SYSTEM = "ALL-SYSTEM";
 
+    // ModuleFinder for the initial configuration
+    private static ModuleFinder initialFinder;
+
+    /**
+     * Returns the ModuleFinder for the initial configuration
+     */
+    public static ModuleFinder finder() {
+        assert initialFinder != null;
+        return initialFinder;
+    }
 
     /**
      * Initialize the module system, returning the boot Layer.
@@ -238,6 +248,9 @@
         // total time to initialize
         PerfCounters.bootstrapTime.addElapsedTimeFrom(t0);
 
+        // remember the ModuleFinder
+        initialFinder = finder;
+
         return bootLayer;
     }
 
--- a/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Sun Nov 29 10:55:13 2015 +0000
+++ b/src/java.base/share/classes/sun/launcher/LauncherHelper.java	Sun Nov 29 19:43:15 2015 +0000
@@ -43,7 +43,7 @@
 import java.io.IOException;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
-import java.lang.module.Configuration;
+import java.lang.module.ModuleFinder;
 import java.lang.module.ModuleReference;
 import java.lang.module.ModuleDescriptor;
 import java.lang.module.ModuleDescriptor.Requires;
@@ -895,7 +895,7 @@
     }
 
     /**
-     * Called by the launcher to list modules in the boot Layer.
+     * Called by the launcher to list the observable modules.
      * If called without any sub-options then the output is a simple list of
      * the modules. If called with sub-options then the sub-options are the
      * names of the modules to list (-listmods:java.base,java.desktop for
@@ -906,35 +906,32 @@
     {
         initOutput(printToStderr);
 
-        Layer layer = Layer.boot();
-        if (layer == null)
-            return;
+        ModuleFinder finder = jdk.internal.module.ModuleBootstrap.finder();
 
-        Configuration cf = layer.configuration();
         int colon = optionFlag.indexOf(':');
         if (colon == -1) {
-            cf.modules().stream()
+            finder.findAll().stream()
                 .sorted(Comparator.comparing(ModuleReference::descriptor))
                 .forEach(md -> {
-                        ostream.println(midAndLocation(md.descriptor(),
-                                                       md.location()));
-                    });
+                    ostream.println(midAndLocation(md.descriptor(),
+                                                   md.location()));
+                });
         } else {
             String[] names = optionFlag.substring(colon+1).split(",");
             for (String name: names) {
-                ModuleReference mref = cf.findModule(name).orElse(null);
+                ModuleReference mref = finder.find(name).orElse(null);
                 if (mref == null) {
-                    // skip as module is not in the boot Layer
+                    // not found
                     continue;
                 }
 
                 ModuleDescriptor md = mref.descriptor();
                 ostream.println(midAndLocation(md, mref.location()));
 
-                for (Requires d: md.requires()) {
+                for (Requires d : md.requires()) {
                     ostream.format("  requires %s%n", d);
                 }
-                for (String s: md.uses()) {
+                for (String s : md.uses()) {
                     ostream.format("  uses %s%n", s);
                 }
 
--- a/src/java.base/share/classes/sun/launcher/resources/launcher.properties	Sun Nov 29 10:55:13 2015 +0000
+++ b/src/java.base/share/classes/sun/launcher/resources/launcher.properties	Sun Nov 29 19:43:15 2015 +0000
@@ -58,7 +58,7 @@
 \    -limitmods <modulename>[,<modulename>...]\n\
 \                  limit the universe of observable modules\n\
 \    -listmods[:<modulename>[,<modulename>...]]\n\
-\                  list the modules in the initial configuration\n\
+\                  list the observable modules\n\
 \    -D<name>=<value>\n\
 \                  set a system property\n\
 \    -verbose:[class|gc|jni]\n\
--- a/src/java.base/share/native/libjli/java.c	Sun Nov 29 10:55:13 2015 +0000
+++ b/src/java.base/share/native/libjli/java.c	Sun Nov 29 19:43:15 2015 +0000
@@ -396,10 +396,7 @@
     if (listModules != NULL) {
         ListModules(env, listModules);
         CHECK_EXCEPTION_LEAVE(1);
-        if (what == NULL) {
-            /* No main class or module specified */
-            LEAVE();
-        }
+        LEAVE();
     }
 
     if (printVersion || showVersion) {
@@ -1178,6 +1175,7 @@
         } else if (JLI_StrCmp(arg, "-listmods") == 0 ||
                    JLI_StrCCmp(arg, "-listmods:") == 0) {
             listModules = arg;
+            return JNI_TRUE;
         } else if (JLI_StrCCmp(arg, "-XaddReads:") == 0) {
             static jboolean haveAddReads = JNI_FALSE;
             /* -XaddReads only allowed once */
@@ -1300,10 +1298,7 @@
     }
 
     if (*pwhat == NULL) {
-        /* No main class or module specified */
-        if (listModules == NULL) {
-            *pret = 1;
-        }
+        *pret = 1;
     } else if (mode == LM_UNKNOWN) {
         /* default to LM_CLASS if -m, -jar and -cp options are
          * not specified */
--- a/test/jdk/jigsaw/launcher/listmods/ListModsTest.java	Sun Nov 29 10:55:13 2015 +0000
+++ b/test/jdk/jigsaw/launcher/listmods/ListModsTest.java	Sun Nov 29 19:43:15 2015 +0000
@@ -23,15 +23,20 @@
 
 /**
  * @test
- * @library /lib/testlibrary
- * @build ListModsTest jdk.testlibrary.*
+ * @library ../../lib /lib/testlibrary
+ * @modules java.se
+ * @build ListModsTest CompilerUtils jdk.testlibrary.*
  * @run testng ListModsTest
  * @summary Basic test for java -listmods
  */
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
 import static jdk.testlibrary.ProcessTools.*;
 import jdk.testlibrary.OutputAnalyzer;
 
+import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 import static org.testng.Assert.*;
 
@@ -41,11 +46,27 @@
 
 public class ListModsTest {
 
-    private static String TEST_CLASSES = System.getProperty("test.classes");
+    private static final String TEST_SRC = System.getProperty("test.src");
+    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
+    private static final Path MODS_DIR = Paths.get("mods");
+    private static final Path UPGRADEMODS_DIR = Paths.get("upgrademods");
 
-    public static void main(String[] args) {
-        int ret = Integer.parseInt(args[0]);
-        System.exit(ret);
+    @BeforeTest
+    public void setup() throws Exception {
+        boolean compiled;
+
+        // javac -d mods/m1 -mp mods src/m1/**
+        compiled = CompilerUtils.compile(
+                SRC_DIR.resolve("m1"),
+                MODS_DIR.resolve("m1"));
+        assertTrue(compiled);
+
+        // javac -d upgrademods/java.transaction -mp mods src/java.transaction/**
+        compiled = CompilerUtils.compile(
+                SRC_DIR.resolve("java.transaction"),
+                UPGRADEMODS_DIR.resolve("java.transaction"));
+        assertTrue(compiled);
+
     }
 
 
@@ -56,12 +77,13 @@
                 .outputTo(System.out)
                 .errorTo(System.out);
         output.shouldContain("java.base");
+        output.shouldContain("java.xml");
         assertTrue(output.getExitValue() == 0);
     }
 
 
     @Test
-    public void testListOne() throws Exception {
+    public void testListOneModule() throws Exception {
         OutputAnalyzer output
             = executeTestJava("-listmods:java.base")
                 .outputTo(System.out)
@@ -73,7 +95,7 @@
 
 
     @Test
-    public void testListMany() throws Exception {
+    public void testListTwoModules() throws Exception {
         OutputAnalyzer output
             = executeTestJava("-listmods:java.base,java.xml")
                 .outputTo(System.out)
@@ -92,32 +114,90 @@
             = executeTestJava("-listmods:java.rhubarb")
                 .outputTo(System.out)
                 .errorTo(System.out);
+        output.shouldNotContain("java.base");
         output.shouldNotContain("java.rhubarb");
         assertTrue(output.getExitValue() == 0);
     }
 
 
     @Test
-    public void testWithMainClass() throws Exception {
+    public void testListWithModulePath() throws Exception {
         OutputAnalyzer output
-            = executeTestJava("-listmods",
-                              "-cp", TEST_CLASSES, "ListModsTest", "0")
+            = executeTestJava("-mp", MODS_DIR.toString(), "-listmods")
                 .outputTo(System.out)
                 .errorTo(System.out);
         output.shouldContain("java.base");
+        output.shouldContain("m1");
         assertTrue(output.getExitValue() == 0);
     }
 
 
     @Test
-    public void testWithFailingClass() throws Exception {
+    public void testListWithUpgradeModulePath() throws Exception {
         OutputAnalyzer output
-            = executeTestJava("-listmods",
-                              "-cp", TEST_CLASSES, "ListModsTest", "1")
+            = executeTestJava("-upgrademodulepath", UPGRADEMODS_DIR.toString(),
+                              "-listmods:java.transaction")
+                .outputTo(System.out)
+                .errorTo(System.out);
+        output.shouldContain("exports javax.transaction.atomic");
+        assertTrue(output.getExitValue() == 0);
+    }
+
+
+    @Test
+    public void testListWithLimitMods1() throws Exception {
+        OutputAnalyzer output
+            = executeTestJava("-limitmods", "java.compact1", "-listmods")
+                .outputTo(System.out)
+                .errorTo(System.out);
+        output.shouldContain("java.compact1");
+        output.shouldContain("java.base");
+        output.shouldNotContain("java.xml");
+        assertTrue(output.getExitValue() == 0);
+    }
+
+
+    @Test
+    public void testListWithLimitMods2() throws Exception {
+        OutputAnalyzer output
+            = executeTestJava("-mp", MODS_DIR.toString(),
+                              "-limitmods", "java.compact1",
+                              "-listmods")
                 .outputTo(System.out)
                 .errorTo(System.out);
         output.shouldContain("java.base");
-        assertTrue(output.getExitValue() == 1);
+        output.shouldNotContain("m1");
+        assertTrue(output.getExitValue() == 0);
+    }
+
+
+    /**
+     * java -version -listmods => should print version and exit
+     */
+    @Test
+    public void testListWithPrintVersion1() throws Exception {
+        OutputAnalyzer output
+            = executeTestJava("-version", "-listmods")
+                .outputTo(System.out)
+                .errorTo(System.out);
+        output.shouldNotContain("java.base");
+        output.shouldContain("Runtime Environment");
+        assertTrue(output.getExitValue() == 0);
+    }
+
+
+    /**
+     * java -listmods -version => should list modules and exit
+     */
+    @Test
+    public void testListWithPrintVersion2() throws Exception {
+        OutputAnalyzer output
+            = executeTestJava("-listmods", "-version")
+                .outputTo(System.out)
+                .errorTo(System.out);
+        output.shouldContain("java.base");
+        output.shouldNotContain("Runtime Environment");
+        assertTrue(output.getExitValue() == 0);
     }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/listmods/src/java.transaction/javax/transaction/Transaction.java	Sun Nov 29 19:43:15 2015 +0000
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.transaction;
+
+public class Transaction {
+
+    public Transaction() { }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/listmods/src/java.transaction/javax/transaction/atomic/Atomic.java	Sun Nov 29 19:43:15 2015 +0000
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package javax.transaction.atomic;
+
+public interface Atomic {
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/listmods/src/java.transaction/module-info.java	Sun Nov 29 19:43:15 2015 +0000
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+module java.transaction {
+    exports javax.transaction;
+    exports javax.transaction.atomic;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/jigsaw/launcher/listmods/src/m1/module-info.java	Sun Nov 29 19:43:15 2015 +0000
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+module m1 {
+}