# HG changeset patch # User herrick # Date 1550685163 18000 # Node ID 7fc5a57945d2cc60452d55b3ece4193e8e30c98a # Parent 9d5fccd974218fdab327b028a8c01a4688a8f08e 8217798: modular jar linking in jpackage Reviewed-by: almatvee, kbr diff -r 9d5fccd97421 -r 7fc5a57945d2 src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java Sun Feb 17 14:08:26 2019 -0500 +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java Wed Feb 20 12:52:43 2019 -0500 @@ -162,7 +162,7 @@ } static String getMainModule(Map params) { - String result = ""; + String result = null; String mainModule = StandardBundlerParam.MODULE.fetchFrom(params); if (mainModule != null) { @@ -184,7 +184,8 @@ StandardBundlerParam.MODULE_PATH.fetchFrom(params); Set limitModules = StandardBundlerParam.LIMIT_MODULES.fetchFrom(params); - Path javaBasePath = findPathOfModule(modulePath, "java.base.jmod"); + Path javaBasePath = findPathOfModule(modulePath, + "java.base.jmod").resolve("java.base.jmod"); Set addModules = getValidModules(modulePath, StandardBundlerParam.ADD_MODULES.fetchFrom(params), limitModules); @@ -194,7 +195,6 @@ result = getModuleVersion(javaBasePath.toFile(), modulePath, addModules, limitModules); } - return result; } @@ -265,25 +265,30 @@ } // Modules - + String mainModule = getMainModule(params); if (mainJarType == ModFile.ModType.UnnamedJar) { // The default for an unnamed jar is ALL_DEFAULT addModules.add(ModuleHelper.ALL_DEFAULT); } else if (mainJarType == ModFile.ModType.Unknown || mainJarType == ModFile.ModType.ModularJar) { - String mainModule = getMainModule(params); - addModules.add(mainModule); + if (mainModule == null) { + addModules.add(ModuleHelper.ALL_DEFAULT); + } + } + + Set validModules = + getValidModules(modulePath, addModules, limitModules); + if (mainModule != null) { + validModules.add(mainModule); } - addModules.addAll(getValidModules( - modulePath, addModules, limitModules)); Log.verbose(MessageFormat.format( - I18N.getString("message.modules"), addModules.toString())); + I18N.getString("message.modules"), validModules.toString())); AppRuntimeImageBuilder appRuntimeBuilder = new AppRuntimeImageBuilder(); appRuntimeBuilder.setOutputDir(outputDir); appRuntimeBuilder.setModulePath(modulePath); - appRuntimeBuilder.setAddModules(addModules); + appRuntimeBuilder.setAddModules(validModules); appRuntimeBuilder.setLimitModules(limitModules); appRuntimeBuilder.setExcludeFileList(excludeFileList); appRuntimeBuilder.setStripNativeCommands(stripNativeCommands); @@ -327,20 +332,17 @@ } // Returns the path to the JDK modules in the user defined module path. - static Path findPathOfModule( - List modulePath, String moduleName) { - Path result = null; + static Path findPathOfModule( List modulePath, String moduleName) { for (Path path : modulePath) { Path moduleNamePath = path.resolve(moduleName); if (Files.exists(moduleNamePath)) { - result = path; - break; + return path; } } - return result; + return null; } /* @@ -437,7 +439,6 @@ } } } - return result; } diff -r 9d5fccd97421 -r 7fc5a57945d2 src/jdk.jpackage/share/classes/jdk/jpackage/internal/ModuleManager.java --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ModuleManager.java Sun Feb 17 14:08:26 2019 -0500 +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/ModuleManager.java Wed Feb 20 12:52:43 2019 -0500 @@ -78,41 +78,45 @@ return result; } - private static List getAllModulesInDirectory(String Folder, + private static List getAllModulesInDirectory(String folder, EnumSet Search) { List result = new ArrayList(); - File lfolder = new File(Folder); - File[] files = lfolder.listFiles(); + File lfolder = new File(folder); + File[] files = { lfolder }; + if (lfolder.isDirectory()) { + files = lfolder.listFiles(); + } - for (File file : files) { - ModFile modFile = new ModFile(file); + if (files != null) { + for (File file : files) { + ModFile modFile = new ModFile(file); - switch (modFile.getModType()) { - case Unknown: - break; - case UnnamedJar: - if (Search.contains(SearchType.UnnamedJar)) { - result.add(modFile); - } - break; - case ModularJar: - if (Search.contains(SearchType.ModularJar)) { - result.add(modFile); - } - break; - case Jmod: - if (Search.contains(SearchType.Jmod)) { - result.add(modFile); - } - break; - case ExplodedModule: - if (Search.contains(SearchType.ExplodedModule)) { - result.add(modFile); - } - break; + switch (modFile.getModType()) { + case Unknown: + break; + case UnnamedJar: + if (Search.contains(SearchType.UnnamedJar)) { + result.add(modFile); + } + break; + case ModularJar: + if (Search.contains(SearchType.ModularJar)) { + result.add(modFile); + } + break; + case Jmod: + if (Search.contains(SearchType.Jmod)) { + result.add(modFile); + } + break; + case ExplodedModule: + if (Search.contains(SearchType.ExplodedModule)) { + result.add(modFile); + } + break; + } } } - return result; } }