--- old/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java 2019-09-20 07:14:22.006697100 -0400 +++ new/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxAppImageBuilder.java 2019-09-20 07:14:20.787813600 -0400 @@ -48,12 +48,7 @@ private static final String LIBRARY_NAME = "libapplauncher.so"; final static String DEFAULT_ICON = "java32.png"; - private final Path root; - private final Path appDir; - private final Path appModsDir; - private final Path runtimeDir; - private final Path binDir; - private final Path mdir; + private final ApplicationLayout appLayout; public static final BundlerParamInfo ICON_PNG = new StandardBundlerParam<>( @@ -70,35 +65,17 @@ }, (s, p) -> new File(s)); - public LinuxAppImageBuilder(Map params, Path imageOutDir) - throws IOException { - super(params, - imageOutDir.resolve(APP_NAME.fetchFrom(params) + "/runtime")); - - Objects.requireNonNull(imageOutDir); - - this.root = imageOutDir.resolve(APP_NAME.fetchFrom(params)); - this.appDir = root.resolve("app"); - this.appModsDir = appDir.resolve("mods"); - this.runtimeDir = root.resolve("runtime"); - this.binDir = root.resolve("bin"); - this.mdir = runtimeDir.resolve("lib"); - Files.createDirectories(appDir); - Files.createDirectories(runtimeDir); + private static ApplicationLayout createAppLayout(Map params, + Path imageOutDir) { + return ApplicationLayout.linuxApp().resolveAt( + imageOutDir.resolve(APP_NAME.fetchFrom(params))); } - public LinuxAppImageBuilder(String appName, Path imageOutDir) + public LinuxAppImageBuilder(Map params, Path imageOutDir) throws IOException { - super(null, imageOutDir.resolve(appName)); - - Objects.requireNonNull(imageOutDir); + super(params, createAppLayout(params, imageOutDir).runtimeDirectory()); - this.root = imageOutDir.resolve(appName); - this.appDir = null; - this.appModsDir = null; - this.runtimeDir = null; - this.binDir = null; - this.mdir = null; + appLayout = createAppLayout(params, imageOutDir); } private void writeEntry(InputStream in, Path dstFile) throws IOException { @@ -110,19 +87,31 @@ return APP_NAME.fetchFrom(params); } - public static String getLauncherCfgName( - Map params) { - return "app" + File.separator + APP_NAME.fetchFrom(params) + ".cfg"; + private Path getLauncherCfgPath(Map params) { + return appLayout.appDirectory().resolve( + APP_NAME.fetchFrom(params) + ".cfg"); } @Override public Path getAppDir() { - return appDir; + return appLayout.appDirectory(); } @Override public Path getAppModsDir() { - return appModsDir; + return appLayout.appModsDirectory(); + } + + @Override + protected String getCfgAppDir() { + return Path.of("$APPDIR").resolve( + ApplicationLayout.linuxApp().appDirectory()).toString() + File.separator; + } + + @Override + protected String getCfgRuntimeDir() { + return Path.of("$APPDIR").resolve( + ApplicationLayout.linuxApp().runtimeDirectory()).toString(); } @Override @@ -130,19 +119,20 @@ throws IOException { Map originalParams = new HashMap<>(params); - try { - IOUtils.writableOutputDir(root); - IOUtils.writableOutputDir(binDir); - } catch (PackagerException pe) { - throw new RuntimeException(pe); - } + appLayout.roots().stream().forEach(dir -> { + try { + IOUtils.writableOutputDir(dir); + } catch (PackagerException pe) { + throw new RuntimeException(pe); + } + }); // create the primary launcher createLauncherForEntryPoint(params); // Copy library to the launcher folder try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { - writeEntry(is_lib, binDir.resolve(LIBRARY_NAME)); + writeEntry(is_lib, appLayout.dllDirectory().resolve(LIBRARY_NAME)); } // create the additional launchers, if any @@ -166,8 +156,8 @@ private void createLauncherForEntryPoint( Map params) throws IOException { - // Copy executable to Linux folder - Path executableFile = binDir.resolve(getLauncherName(params)); + // Copy executable to launchers folder + Path executableFile = appLayout.launchersDirectory().resolve(getLauncherName(params)); try (InputStream is_launcher = getResourceAsStream("jpackageapplauncher")) { writeEntry(is_launcher, executableFile); @@ -176,14 +166,15 @@ executableFile.toFile().setExecutable(true, false); executableFile.toFile().setWritable(true, true); - writeCfgFile(params, root.resolve(getLauncherCfgName(params)).toFile()); + writeCfgFile(params, getLauncherCfgPath(params).toFile()); } private void copyIcon(Map params) throws IOException { File icon = ICON_PNG.fetchFrom(params); - File iconTarget = binDir.resolve(APP_NAME.fetchFrom(params) + ".png").toFile(); + File iconTarget = appLayout.destktopIntegrationDirectory().resolve( + APP_NAME.fetchFrom(params) + ".png").toFile(); InputStream in = locateResource( iconTarget.getName(), @@ -205,7 +196,7 @@ } File srcdir = appResources.getBaseDirectory(); for (String fname : appResources.getIncludedFiles()) { - copyEntry(appDir, srcdir, fname); + copyEntry(appLayout.appDirectory(), srcdir, fname); } } }