src/jdk.jdeps/share/classes/com/sun/tools/jdeps/JdepsTask.java
changeset 48253 82767203606e
parent 47357 74700c8e39e9
child 48543 7067fe4e054e
equal deleted inserted replaced
48252:77b88d8f8380 48253:82767203606e
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   538             log.flush();
   538             log.flush();
   539         }
   539         }
   540     }
   540     }
   541 
   541 
   542     boolean run() throws IOException {
   542     boolean run() throws IOException {
   543         try (JdepsConfiguration config = buildConfig(command.allModules())) {
   543         try (JdepsConfiguration config = buildConfig()) {
   544             if (!options.nowarning) {
   544             if (!options.nowarning) {
   545                 // detect split packages
   545                 // detect split packages
   546                 config.splitPackages().entrySet()
   546                 config.splitPackages().entrySet()
   547                       .stream()
   547                       .stream()
   548                       .sorted(Map.Entry.comparingByKey())
   548                       .sorted(Map.Entry.comparingByKey())
   551                                             e.getValue().stream().collect(joining(" "))));
   551                                             e.getValue().stream().collect(joining(" "))));
   552             }
   552             }
   553 
   553 
   554             // check if any module specified in --add-modules, --require, and -m is missing
   554             // check if any module specified in --add-modules, --require, and -m is missing
   555             options.addmods.stream()
   555             options.addmods.stream()
   556                 .filter(mn -> !config.isValidToken(mn))
   556                 .filter(mn -> !JdepsConfiguration.isToken(mn))
   557                 .forEach(mn -> config.findModule(mn).orElseThrow(() ->
   557                 .forEach(mn -> config.findModule(mn).orElseThrow(() ->
   558                     new UncheckedBadArgs(new BadArgs("err.module.not.found", mn))));
   558                     new UncheckedBadArgs(new BadArgs("err.module.not.found", mn))));
   559 
   559 
   560             return command.run(config);
   560             return command.run(config);
   561         }
   561         }
   562     }
   562     }
   563 
   563 
   564     private JdepsConfiguration buildConfig(boolean allModules) throws IOException {
   564     private JdepsConfiguration buildConfig() throws IOException {
   565         JdepsConfiguration.Builder builder =
   565         JdepsConfiguration.Builder builder =
   566             new JdepsConfiguration.Builder(options.systemModulePath);
   566             new JdepsConfiguration.Builder(options.systemModulePath);
   567 
   567 
   568         builder.upgradeModulePath(options.upgradeModulePath)
   568         builder.upgradeModulePath(options.upgradeModulePath)
   569                .appModulePath(options.modulePath)
   569                .appModulePath(options.modulePath)
   570                .addmods(options.addmods);
   570                .addmods(options.addmods)
   571 
   571                .addmods(command.addModules());
   572         if (allModules) {
       
   573             // check all system modules in the image
       
   574             builder.allModules();
       
   575         }
       
   576 
   572 
   577         if (options.classpath != null)
   573         if (options.classpath != null)
   578             builder.addClassPath(options.classpath);
   574             builder.addClassPath(options.classpath);
   579 
   575 
   580         if (options.multiRelease != null)
   576         if (options.multiRelease != null)
   653          *
   649          *
   654          * When a named module is analyzed, it will analyze the dependences
   650          * When a named module is analyzed, it will analyze the dependences
   655          * only.  The method should be overridden when this command should
   651          * only.  The method should be overridden when this command should
   656          * analyze all modules instead.
   652          * analyze all modules instead.
   657          */
   653          */
   658         boolean allModules() {
   654         Set<String> addModules() {
   659             return false;
   655             return Set.of();
   660         }
   656         }
   661 
   657 
   662         @Override
   658         @Override
   663         public String toString() {
   659         public String toString() {
   664             return option.toString();
   660             return option.toString();
   869         /*
   865         /*
   870          * Returns true if --require is specified so that all modules are
   866          * Returns true if --require is specified so that all modules are
   871          * analyzed to find all modules that depend on the modules specified in the
   867          * analyzed to find all modules that depend on the modules specified in the
   872          * --require option directly and indirectly
   868          * --require option directly and indirectly
   873          */
   869          */
   874         public boolean allModules() {
   870         Set<String> addModules() {
   875             return options.requires.size() > 0;
   871             return options.requires.size() > 0 ? Set.of("ALL-SYSTEM") : Set.of();
   876         }
   872         }
   877     }
   873     }
   878 
   874 
   879 
   875 
   880     class GenModuleInfo extends Command {
   876     class GenModuleInfo extends Command {
   973         }
   969         }
   974 
   970 
   975         /*
   971         /*
   976          * Returns true to analyze all modules
   972          * Returns true to analyze all modules
   977          */
   973          */
   978         public boolean allModules() {
   974         Set<String> addModules() {
   979             return true;
   975             return Set.of("ALL-SYSTEM", "ALL-MODULE-PATH");
   980         }
   976         }
   981     }
   977     }
   982 
   978 
   983     class ListModuleDeps extends Command {
   979     class ListModuleDeps extends Command {
   984         final boolean jdkinternals;
   980         final boolean jdkinternals;