--- old/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/CfgFile.java 2020-08-24 18:09:00.176340500 -0400 +++ new/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/CfgFile.java 2020-08-24 18:08:59.060053300 -0400 @@ -25,6 +25,7 @@ package jdk.incubator.jpackage.internal; import java.io.IOException; +import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -35,6 +36,7 @@ import static jdk.incubator.jpackage.internal.StandardBundlerParam.APP_NAME; import static jdk.incubator.jpackage.internal.StandardBundlerParam.JAVA_OPTIONS; import static jdk.incubator.jpackage.internal.StandardBundlerParam.ARGUMENTS; +import static jdk.incubator.jpackage.internal.StandardBundlerParam.VERSION; /** * App launcher's config file. @@ -49,6 +51,7 @@ launcherName = APP_NAME.fetchFrom(params); javaOptions = JAVA_OPTIONS.fetchFrom(params); arguments = ARGUMENTS.fetchFrom(params); + version = VERSION.fetchFrom(params); return this; } @@ -82,11 +85,20 @@ ApplicationLayout appImagelayout = appLayout.resolveAt(appImage); Path modsDir = appImagelayout.appModsDirectory(); - if (!javaOptions.isEmpty() || Files.isDirectory(modsDir)) { - content.add(Map.entry("[JavaOptions]", SECTION_TAG)); - for (var value : javaOptions) { - content.add(Map.entry("java-options", value)); - } + + content.add(Map.entry("[JavaOptions]", SECTION_TAG)); + + // always let app know it's version + content.add(Map.entry( + "java-options", "-Djpackage.app-version=" + version)); + + // add user supplied java options if there are any + for (var value : javaOptions) { + content.add(Map.entry("java-options", value)); + } + + // add module path if there is one + if (Files.isDirectory(modsDir)) { content.add(Map.entry("java-options", "--module-path")); content.add(Map.entry("java-options", appCfgLayout.appModsDirectory())); @@ -126,6 +138,7 @@ } private String launcherName; + private String version; private LauncherData launcherData; List arguments; List javaOptions; --- old/src/jdk.incubator.jpackage/macosx/native/applauncher/MacLauncher.cpp 2020-08-24 18:09:07.925814100 -0400 +++ new/src/jdk.incubator.jpackage/macosx/native/applauncher/MacLauncher.cpp 2020-08-24 18:09:06.871823800 -0400 @@ -52,6 +52,8 @@ jvmLauncher = AppLauncher() .setImageRoot(appImageRoot) .addJvmLibName(_T("Contents/Home/lib/libjli.dylib")) + // add backup - older version such as JDK11 have it in jli sub-dir + .addJvmLibName(_T("Contents/Home/lib/jli/libjli.dylib")) .setAppDir(FileUtils::mkpath() << appImageRoot << _T("Contents/app")) .setDefaultRuntimePath(FileUtils::mkpath() << appImageRoot << _T("Contents/runtime")) --- old/src/jdk.incubator.jpackage/share/native/applauncher/JvmLauncher.cpp 2020-08-24 18:09:15.631523600 -0400 +++ new/src/jdk.incubator.jpackage/share/native/applauncher/JvmLauncher.cpp 2020-08-24 18:09:14.515492600 -0400 @@ -89,6 +89,11 @@ } } while (0); + do { + addArgument(_T("-Djpackage.app-path=") + + SysInfo::getProcessModulePath()); + } while (0); + // No validation of data in config file related to how Java app should be // launched intentionally. // Just read what is in config file and put on jvm's command line as is. --- old/test/jdk/tools/jpackage/apps/image/Hello.java 2020-08-24 18:09:23.463355200 -0400 +++ new/test/jdk/tools/jpackage/apps/image/Hello.java 2020-08-24 18:09:22.372333900 -0400 @@ -68,7 +68,13 @@ lines.add("args.length: " + args.length); - lines.addAll(List.of(args)); + for (String arg : args) { + if (arg.startsWith("jpackage.app")) { + lines.add(arg + "=" + System.getProperty(arg)); + } else { + lines.add(arg); + } + } for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) { String value = System.getProperty("param" + index); --- old/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java 2020-08-24 18:09:31.197524200 -0400 +++ new/test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java 2020-08-24 18:09:30.093699800 -0400 @@ -65,6 +65,28 @@ } @Test + public void testJpackageProps() { + String appVersion = "3.0"; + JPackageCommand cmd = JPackageCommand.helloAppImage( + JavaAppDesc.parse("Hello")) + // Disable default logic adding `--verbose` option + // to jpackage command line. + .ignoreDefaultVerbose(true) + .saveConsoleOutput(true) + .addArguments("--app-version", appVersion, "--arguments", + "jpackage.app-version jpackage.app-path") + .ignoreDefaultRuntime(true); + + cmd.executeAndAssertImageCreated(); + Path launcherPath = cmd.appLauncherPath(); + + List output = HelloApp.executeLauncher(cmd).getOutput(); + + TKit.assertTextStream("jpackage.app-version=" + appVersion).apply(output.stream()); + TKit.assertTextStream("jpackage.app-path=").apply(output.stream()); + } + + @Test public void testVersion() { List output = getJPackageToolProvider() --- old/test/jdk/tools/jpackage/apps/com.hello/com/hello/Hello.java 2020-08-24 18:09:38.971499300 -0400 +++ /dev/null 2020-08-24 18:09:39.000000000 -0400 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.hello; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; - -public class Hello { - - private static final String MSG = "jpackage test application"; - private static final int EXPECTED_NUM_OF_PARAMS = 3; // Starts at 1 - - public static void main(String[] args) { - String outputFile = "appOutput.txt"; - File file = new File(outputFile); - - try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)))) { - System.out.println(MSG); - out.println(MSG); - - System.out.println("args.length: " + args.length); - out.println("args.length: " + args.length); - - for (String arg : args) { - System.out.println(arg); - out.println(arg); - } - - for (int index = 1; index <= EXPECTED_NUM_OF_PARAMS; index++) { - String value = System.getProperty("param" + index); - if (value != null) { - System.out.println("-Dparam" + index + "=" + value); - out.println("-Dparam" + index + "=" + value); - } - } - } catch (Exception ex) { - System.err.println(ex.toString()); - } - } - -} --- old/test/jdk/tools/jpackage/apps/com.hello/module-info.java 2020-08-24 18:09:43.474348500 -0400 +++ /dev/null 2020-08-24 18:09:44.000000000 -0400 @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -module com.hello { - exports com.hello; -}