Skip to content

Commit 303631e

Browse files
author
Andy Herrick
committed
8256475: Fix Behavior when Installer name differs from application name.
Reviewed-by: asemenyuk, almatvee, kizune
1 parent fa3cfcd commit 303631e

File tree

18 files changed

+203
-40
lines changed

18 files changed

+203
-40
lines changed

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.stream.Stream;
4848
import static jdk.jpackage.internal.OverridableResource.createResource;
4949
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
50+
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
5051
import static jdk.jpackage.internal.StandardBundlerParam.VERSION;
5152
import static jdk.jpackage.internal.StandardBundlerParam.RELEASE;
5253
import static jdk.jpackage.internal.StandardBundlerParam.VENDOR;
@@ -71,8 +72,7 @@ public class LinuxDebBundler extends LinuxPackageBundler {
7172
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(),
7273
String.class,
7374
params -> {
74-
String nm = APP_NAME.fetchFrom(params);
75-
75+
String nm = INSTALLER_NAME.fetchFrom(params);
7676
if (nm == null) return null;
7777

7878
// make sure to lower case and spaces/underscores become dashes

src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.stream.Collectors;
3939

4040
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
41+
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
4142
import static jdk.jpackage.internal.StandardBundlerParam.LICENSE_FILE;
4243
import static jdk.jpackage.internal.StandardBundlerParam.VERSION;
4344
import static jdk.jpackage.internal.StandardBundlerParam.RELEASE;
@@ -73,7 +74,7 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
7374
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(),
7475
String.class,
7576
params -> {
76-
String nm = APP_NAME.fetchFrom(params);
77+
String nm = INSTALLER_NAME.fetchFrom(params);
7778
if (nm == null) return null;
7879

7980
// make sure to lower case and spaces become dashes

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacAppStoreBundler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public Path bundle(Map<String, ? super Object> params,
143143
ProcessBuilder pb;
144144

145145
// create the final pkg file
146-
Path finalPKG = outdir.resolve(INSTALLER_NAME.fetchFrom(params)
146+
Path finalPKG = outdir.resolve(MAC_INSTALLER_NAME.fetchFrom(params)
147147
+ INSTALLER_SUFFIX.fetchFrom(params)
148148
+ ".pkg");
149149
Files.createDirectories(outdir);

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacBaseInstallerBundler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.regex.Matcher;
3838
import java.util.regex.Pattern;
3939
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
40+
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
4041
import static jdk.jpackage.internal.StandardBundlerParam.INSTALL_DIR;
4142
import static jdk.jpackage.internal.StandardBundlerParam.PREDEFINED_APP_IMAGE;
4243
import static jdk.jpackage.internal.StandardBundlerParam.VERSION;
@@ -75,12 +76,12 @@ public abstract class MacBaseInstallerBundler extends AbstractBundler {
7576
params -> "",
7677
null);
7778

78-
public static final BundlerParamInfo<String> INSTALLER_NAME =
79+
public static final BundlerParamInfo<String> MAC_INSTALLER_NAME =
7980
new StandardBundlerParam<> (
8081
"mac.installerName",
8182
String.class,
8283
params -> {
83-
String nm = APP_NAME.fetchFrom(params);
84+
String nm = INSTALLER_NAME.fetchFrom(params);
8485
if (nm == null) return null;
8586

8687
String version = VERSION.fetchFrom(params);

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacDmgBundler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private Path buildDMG( Map<String, ? super Object> params,
270270
}
271271

272272
Path protoDMG = imagesRoot.resolve(APP_NAME.fetchFrom(params) +"-tmp.dmg");
273-
Path finalDMG = outdir.resolve(INSTALLER_NAME.fetchFrom(params)
273+
Path finalDMG = outdir.resolve(MAC_INSTALLER_NAME.fetchFrom(params)
274274
+ INSTALLER_SUFFIX.fetchFrom(params) + ".dmg");
275275

276276
Path srcFolder = APP_IMAGE_TEMP_ROOT.fetchFrom(params);

src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/MacPkgBundler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ private Path createPKG(Map<String, ? super Object> params,
448448
IOUtils.exec(pb);
449449

450450
// build final package
451-
Path finalPKG = outdir.resolve(INSTALLER_NAME.fetchFrom(params)
451+
Path finalPKG = outdir.resolve(MAC_INSTALLER_NAME.fetchFrom(params)
452452
+ INSTALLER_SUFFIX.fetchFrom(params)
453453
+ ".pkg");
454454
Files.createDirectories(outdir);

src/jdk.jpackage/share/classes/jdk/jpackage/internal/AddLauncherArguments.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.List;
3232
import jdk.jpackage.internal.Arguments.CLIOptions;
3333
import static jdk.jpackage.internal.StandardBundlerParam.LAUNCHER_DATA;
34+
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
3435

3536
/*
3637
* AddLauncherArguments
@@ -158,8 +159,10 @@ private String getOptionValue(CLIOptions option) {
158159
Map<String, ? super Object> tmp = new HashMap<>(original);
159160
List.of(exclude).forEach(tmp::remove);
160161

161-
// remove LauncherData from map so it will re-run the defaultValueFunction
162+
// remove LauncherData from map so it will be re-computed
162163
tmp.remove(LAUNCHER_DATA.getID());
164+
// remove "application-name" so it will be re-computed
165+
tmp.remove(APP_NAME.getID());
163166

164167
if (additional.containsKey(CLIOptions.MODULE.getId())) {
165168
tmp.remove(CLIOptions.MAIN_JAR.getId());

src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,16 @@ static List<String> getLauncherNames(Path appImageDir,
233233
return launchers;
234234
}
235235

236+
public static String extractAppName(Path appImageDir) {
237+
try {
238+
return AppImageFile.load(appImageDir).getLauncherName();
239+
} catch (IOException ioe) {
240+
Log.verbose(MessageFormat.format(I18N.getString(
241+
"warning.foreign-app-image"), appImageDir));
242+
return null;
243+
}
244+
}
245+
236246
private static String xpathQueryNullable(XPath xPath, String xpathExpr,
237247
Document xml) throws XPathExpressionException {
238248
NodeList nodes = (NodeList) xPath.evaluate(xpathExpr, xml,

src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,59 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
128128
(s, p) -> Path.of(s)
129129
);
130130

131-
static final StandardBundlerParam<String> APP_NAME =
131+
static final StandardBundlerParam<Path> PREDEFINED_APP_IMAGE =
132+
new StandardBundlerParam<>(
133+
Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId(),
134+
Path.class,
135+
params -> null,
136+
(s, p) -> Path.of(s));
137+
138+
// this is the raw --app-name arg - used in APP_NAME and INSTALLER_NAME
139+
static final StandardBundlerParam<String> NAME =
132140
new StandardBundlerParam<>(
133141
Arguments.CLIOptions.NAME.getId(),
134142
String.class,
143+
params -> null,
144+
(s, p) -> s
145+
);
146+
147+
// this is the application name, either from the app-image (if given),
148+
// the name (if given) derived from the main-class, or the runtime image
149+
static final StandardBundlerParam<String> APP_NAME =
150+
new StandardBundlerParam<>(
151+
"application-name",
152+
String.class,
135153
params -> {
136-
String s = MAIN_CLASS.fetchFrom(params);
137-
if (s != null) {
138-
int idx = s.lastIndexOf(".");
139-
if (idx >= 0) {
140-
return s.substring(idx+1);
141-
}
142-
return s;
143-
} else if (isRuntimeInstaller(params)) {
144-
Path f = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
145-
if (f != null) {
146-
return f.getFileName().toString();
154+
Path appImage = PREDEFINED_APP_IMAGE.fetchFrom(params);
155+
String appName = NAME.fetchFrom(params);
156+
if (appImage != null) {
157+
String name = AppImageFile.extractAppName(appImage);
158+
appName = (name != null) ? name : appName;
159+
} else if (appName == null) {
160+
String s = MAIN_CLASS.fetchFrom(params);
161+
if (s != null) {
162+
int idx = s.lastIndexOf(".");
163+
appName = (idx < 0) ? s : s.substring(idx+1);
164+
} else if (isRuntimeInstaller(params)) {
165+
Path f = PREDEFINED_RUNTIME_IMAGE.fetchFrom(params);
166+
if (f != null) {
167+
appName = f.getFileName().toString();
168+
}
147169
}
148170
}
149-
return null;
171+
return appName;
172+
},
173+
(s, p) -> s
174+
);
175+
176+
static final StandardBundlerParam<String> INSTALLER_NAME =
177+
new StandardBundlerParam<>(
178+
"installer-name",
179+
String.class,
180+
params -> {
181+
String installerName = NAME.fetchFrom(params);
182+
return (installerName != null) ? installerName :
183+
APP_NAME.fetchFrom(params);
150184
},
151185
(s, p) -> s
152186
);
@@ -285,12 +319,6 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
285319
(s, p) -> s
286320
);
287321

288-
static final StandardBundlerParam<Path> PREDEFINED_APP_IMAGE =
289-
new StandardBundlerParam<>(
290-
Arguments.CLIOptions.PREDEFINED_APP_IMAGE.getId(),
291-
Path.class,
292-
params -> null,
293-
(s, p) -> Path.of(s));
294322

295323
@SuppressWarnings("unchecked")
296324
static final StandardBundlerParam<List<Map<String, ? super Object>>> ADD_LAUNCHERS =

src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ error.tool-old-version=Can not find {0} {1} or newer
7272
error.tool-old-version.advice=Please install {0} {1} or newer
7373
error.jlink.failed=jlink failed with: {0}
7474
error.blocked.option=jlink option [{0}] is not permitted in --jlink-options
75+
error.no.name=Name not specified with --name and cannot infer one from app-image
7576

7677
warning.no.jdk.modules.found=Warning: No JDK Modules found
7778
warning.foreign-app-image=Warning: app-image dir ({0}) not generated by jpackage.

0 commit comments

Comments
 (0)