src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java
branchJDK-8200758-branch
changeset 57197 7fc5a57945d2
parent 57126 8041f62342f0
child 57213 8ff0a29bf9bc
equal deleted inserted replaced
57194:9d5fccd97421 57197:7fc5a57945d2
   160 
   160 
   161         return result;
   161         return result;
   162     }
   162     }
   163 
   163 
   164     static String getMainModule(Map<String, ? super Object> params) {
   164     static String getMainModule(Map<String, ? super Object> params) {
   165         String result = "";
   165         String result = null;
   166         String mainModule = StandardBundlerParam.MODULE.fetchFrom(params);
   166         String mainModule = StandardBundlerParam.MODULE.fetchFrom(params);
   167 
   167 
   168         if (mainModule != null) {
   168         if (mainModule != null) {
   169             int index = mainModule.indexOf("/");
   169             int index = mainModule.indexOf("/");
   170 
   170 
   182         String result = "";
   182         String result = "";
   183         List<Path> modulePath =
   183         List<Path> modulePath =
   184                 StandardBundlerParam.MODULE_PATH.fetchFrom(params);
   184                 StandardBundlerParam.MODULE_PATH.fetchFrom(params);
   185         Set<String> limitModules =
   185         Set<String> limitModules =
   186                 StandardBundlerParam.LIMIT_MODULES.fetchFrom(params);
   186                 StandardBundlerParam.LIMIT_MODULES.fetchFrom(params);
   187         Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod");
   187         Path javaBasePath = findPathOfModule(modulePath,
       
   188                 "java.base.jmod").resolve("java.base.jmod");
   188         Set<String> addModules = getValidModules(modulePath,
   189         Set<String> addModules = getValidModules(modulePath,
   189                 StandardBundlerParam.ADD_MODULES.fetchFrom(params),
   190                 StandardBundlerParam.ADD_MODULES.fetchFrom(params),
   190                 limitModules);
   191                 limitModules);
   191 
   192 
   192 
   193 
   193         if (javaBasePath != null && javaBasePath.toFile().exists()) {
   194         if (javaBasePath != null && javaBasePath.toFile().exists()) {
   194             result = getModuleVersion(javaBasePath.toFile(),
   195             result = getModuleVersion(javaBasePath.toFile(),
   195                     modulePath, addModules, limitModules);
   196                     modulePath, addModules, limitModules);
   196         }
   197         }
   197 
       
   198         return result;
   198         return result;
   199     }
   199     }
   200 
   200 
   201     static Path getJDKHome(Map<String, ? super Object> params) {
   201     static Path getJDKHome(Map<String, ? super Object> params) {
   202         Path result = null;
   202         Path result = null;
   263             // user specified only main class, all jars will be on the classpath
   263             // user specified only main class, all jars will be on the classpath
   264             mainJarType = ModFile.ModType.UnnamedJar;
   264             mainJarType = ModFile.ModType.UnnamedJar;
   265         }
   265         }
   266 
   266 
   267         // Modules
   267         // Modules
   268 
   268         String mainModule = getMainModule(params);
   269         if (mainJarType == ModFile.ModType.UnnamedJar) {
   269         if (mainJarType == ModFile.ModType.UnnamedJar) {
   270             // The default for an unnamed jar is ALL_DEFAULT
   270             // The default for an unnamed jar is ALL_DEFAULT
   271             addModules.add(ModuleHelper.ALL_DEFAULT);
   271             addModules.add(ModuleHelper.ALL_DEFAULT);
   272         } else if (mainJarType == ModFile.ModType.Unknown ||
   272         } else if (mainJarType == ModFile.ModType.Unknown ||
   273                 mainJarType == ModFile.ModType.ModularJar) {
   273                 mainJarType == ModFile.ModType.ModularJar) {
   274             String mainModule = getMainModule(params);
   274             if (mainModule == null) {
   275             addModules.add(mainModule);
   275                 addModules.add(ModuleHelper.ALL_DEFAULT);
   276         }
   276             }
   277         addModules.addAll(getValidModules(
   277         } 
   278                 modulePath, addModules, limitModules));
   278 
       
   279         Set<String> validModules =
       
   280                   getValidModules(modulePath, addModules, limitModules);
       
   281         if (mainModule != null) {
       
   282             validModules.add(mainModule);
       
   283         }
   279 
   284 
   280         Log.verbose(MessageFormat.format(
   285         Log.verbose(MessageFormat.format(
   281                 I18N.getString("message.modules"), addModules.toString()));
   286                 I18N.getString("message.modules"), validModules.toString()));
   282 
   287 
   283         AppRuntimeImageBuilder appRuntimeBuilder = new AppRuntimeImageBuilder();
   288         AppRuntimeImageBuilder appRuntimeBuilder = new AppRuntimeImageBuilder();
   284         appRuntimeBuilder.setOutputDir(outputDir);
   289         appRuntimeBuilder.setOutputDir(outputDir);
   285         appRuntimeBuilder.setModulePath(modulePath);
   290         appRuntimeBuilder.setModulePath(modulePath);
   286         appRuntimeBuilder.setAddModules(addModules);
   291         appRuntimeBuilder.setAddModules(validModules);
   287         appRuntimeBuilder.setLimitModules(limitModules);
   292         appRuntimeBuilder.setLimitModules(limitModules);
   288         appRuntimeBuilder.setExcludeFileList(excludeFileList);
   293         appRuntimeBuilder.setExcludeFileList(excludeFileList);
   289         appRuntimeBuilder.setStripNativeCommands(stripNativeCommands);
   294         appRuntimeBuilder.setStripNativeCommands(stripNativeCommands);
   290         appRuntimeBuilder.setUserArguments(new HashMap<String,String>());
   295         appRuntimeBuilder.setUserArguments(new HashMap<String,String>());
   291 
   296 
   325         appRuntimeBuilder.build();
   330         appRuntimeBuilder.build();
   326         imageBuilder.prepareJreFiles();
   331         imageBuilder.prepareJreFiles();
   327     }
   332     }
   328 
   333 
   329     // Returns the path to the JDK modules in the user defined module path.
   334     // Returns the path to the JDK modules in the user defined module path.
   330     static Path findPathOfModule(
   335     static Path findPathOfModule( List<Path> modulePath, String moduleName) {
   331             List<Path> modulePath, String moduleName) {
       
   332         Path result = null;
       
   333 
   336 
   334         for (Path path : modulePath) {
   337         for (Path path : modulePath) {
   335             Path moduleNamePath = path.resolve(moduleName);
   338             Path moduleNamePath = path.resolve(moduleName);
   336 
   339 
   337             if (Files.exists(moduleNamePath)) {
   340             if (Files.exists(moduleNamePath)) {
   338                 result = path;
   341                 return path;
   339                 break;
   342             }
   340             }
   343         }
   341         }
   344 
   342 
   345         return null;
   343         return result;
       
   344     }
   346     }
   345 
   347 
   346     /*
   348     /*
   347      * Returns the set of modules that would be visible by default for
   349      * Returns the set of modules that would be visible by default for
   348      * a non-modular-aware application consisting of the given elements.
   350      * a non-modular-aware application consisting of the given elements.
   435                 if (version.isPresent()) {
   437                 if (version.isPresent()) {
   436                     result = version.get().toString();
   438                     result = version.get().toString();
   437                 }
   439                 }
   438             }
   440             }
   439         }
   441         }
   440 
       
   441         return result;
   442         return result;
   442     }
   443     }
   443 
   444 
   444     private static class ModuleHelper {
   445     private static class ModuleHelper {
   445         // The token for "all modules on the module path".
   446         // The token for "all modules on the module path".