jdk/test/tools/jlink/JLinkTest.java
changeset 39304 8d9ceb81a46e
parent 39153 26b3cb81aac9
child 39321 c60f34e8c057
equal deleted inserted replaced
39303:5aefc354587e 39304:8d9ceb81a46e
    51  *          jdk.jlink/jdk.tools.jlink.internal
    51  *          jdk.jlink/jdk.tools.jlink.internal
    52  *          jdk.jlink/jdk.tools.jmod
    52  *          jdk.jlink/jdk.tools.jmod
    53  *          jdk.jlink/jdk.tools.jimage
    53  *          jdk.jlink/jdk.tools.jimage
    54  *          jdk.compiler
    54  *          jdk.compiler
    55  * @build tests.*
    55  * @build tests.*
    56  * @run main/othervm -verbose:gc -Xmx1g JLinkTest
    56  * @run main/othervm -Xmx1g JLinkTest
    57  */
    57  */
    58 public class JLinkTest {
    58 public class JLinkTest {
    59     // number of built-in plugins from jdk.jlink module
    59     // number of built-in plugins from jdk.jlink module
    60     private static int getNumJlinkPlugins() {
    60     private static int getNumJlinkPlugins() {
    61         ModuleDescriptor desc = Plugin.class.getModule().getDescriptor();
    61         ModuleDescriptor desc = Plugin.class.getModule().getDescriptor();
    62         return desc.provides().
    62         return desc.provides().
    63                     get(TransformerPlugin.class.getName()).
    63                     get(TransformerPlugin.class.getName()).
    64                     providers().size();
    64                     providers().size();
    65     }
    65     }
    66 
    66 
       
    67     private static boolean isOfJLinkModule(Plugin p) {
       
    68         return p.getClass().getModule() == Plugin.class.getModule();
       
    69     }
       
    70 
    67     public static void main(String[] args) throws Exception {
    71     public static void main(String[] args) throws Exception {
    68 
    72 
    69         Helper helper = Helper.newHelper();
    73         Helper helper = Helper.newHelper();
    70         if (helper == null) {
    74         if (helper == null) {
    71             System.err.println("Test not run");
    75             System.err.println("Test not run");
    72             return;
    76             return;
    73         }
    77         }
    74         helper.generateDefaultModules();
    78         helper.generateDefaultModules();
    75         int numPlugins = getNumJlinkPlugins();
    79         // expected num. of plugins from jdk.jlink module
       
    80         int expectedJLinkPlugins = getNumJlinkPlugins();
       
    81         int totalPlugins = 0;
    76         {
    82         {
    77             // number of built-in plugins
    83             // number of built-in plugins
    78             List<Plugin> builtInPlugins = new ArrayList<>();
    84             List<Plugin> builtInPlugins = new ArrayList<>();
    79             builtInPlugins.addAll(PluginRepository.getPlugins(Layer.boot()));
    85             builtInPlugins.addAll(PluginRepository.getPlugins(Layer.boot()));
       
    86             totalPlugins = builtInPlugins.size();
       
    87             // actual num. of plugins loaded from jdk.jlink module
       
    88             int actualJLinkPlugins = 0;
    80             for (Plugin p : builtInPlugins) {
    89             for (Plugin p : builtInPlugins) {
    81                 p.getState();
    90                 p.getState();
    82                 p.getType();
    91                 p.getType();
    83             }
    92                 if (isOfJLinkModule(p)) {
    84             // Note: other boot layer modules may provide jlink plugins.
    93                     actualJLinkPlugins++;
    85             // We should at least see the builtin plugins from jdk.jlink.
    94                 }
    86             if (builtInPlugins.size() < numPlugins) {
    95             }
    87                 throw new AssertionError("Found plugins doesn't match expected number : " +
    96             if (expectedJLinkPlugins != actualJLinkPlugins) {
    88                         numPlugins + "\n" + builtInPlugins);
    97                 throw new AssertionError("Actual plugins loaded from jdk.jlink: " +
       
    98                         actualJLinkPlugins + " which doesn't match expected number : " +
       
    99                         expectedJLinkPlugins);
    89             }
   100             }
    90         }
   101         }
    91 
   102 
    92         {
   103         {
    93             String moduleName = "bug8134651";
   104             String moduleName = "bug8134651";
   148             jdk.tools.jlink.internal.Main.run(new String[]{"--list-plugins"}, new PrintWriter(writer));
   159             jdk.tools.jlink.internal.Main.run(new String[]{"--list-plugins"}, new PrintWriter(writer));
   149             String output = writer.toString();
   160             String output = writer.toString();
   150             long number = Stream.of(output.split("\\R"))
   161             long number = Stream.of(output.split("\\R"))
   151                     .filter((s) -> s.matches("Plugin Name:.*"))
   162                     .filter((s) -> s.matches("Plugin Name:.*"))
   152                     .count();
   163                     .count();
   153             if (number != numPlugins) {
   164             if (number != totalPlugins) {
   154                 System.err.println(output);
   165                 System.err.println(output);
   155                 throw new AssertionError("Found: " + number + " expected " + numPlugins);
   166                 throw new AssertionError("Found: " + number + " expected " + totalPlugins);
   156             }
   167             }
   157         }
   168         }
   158 
   169 
   159         // filter out files and resources + Skip debug + compress
   170         // filter out files and resources + Skip debug + compress
   160         {
   171         {