Skip to content

Commit 1de772c

Browse files
author
Alexey Semenyuk
committed
8294806: jpackaged-app ignores splash screen from jar file
Reviewed-by: almatvee
1 parent d9db906 commit 1de772c

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

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

+1-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -38,9 +38,6 @@
3838
import java.util.Optional;
3939
import java.util.Properties;
4040
import java.util.ResourceBundle;
41-
import java.util.jar.Attributes;
42-
import java.util.jar.JarFile;
43-
import java.util.jar.Manifest;
4441
import java.util.regex.Matcher;
4542
import java.util.regex.Pattern;
4643

@@ -507,15 +504,6 @@ public boolean processArguments() {
507504
}
508505
}
509506

510-
if (hasMainJar && !hasMainClass) {
511-
// try to get main-class from manifest
512-
String mainClass = getMainClassFromManifest();
513-
if (mainClass != null) {
514-
CLIOptions.setOptionValue(
515-
CLIOptions.APPCLASS.getId(), mainClass);
516-
}
517-
}
518-
519507
// display error for arguments that are not supported
520508
// for current configuration.
521509

@@ -825,27 +813,4 @@ private static String unquoteIfNeeded(String in) {
825813
}
826814
return sb.toString();
827815
}
828-
829-
private String getMainClassFromManifest() {
830-
if (mainJarPath == null ||
831-
input == null ) {
832-
return null;
833-
}
834-
835-
JarFile jf;
836-
try {
837-
Path file = Path.of(input, mainJarPath);
838-
if (!Files.exists(file)) {
839-
return null;
840-
}
841-
jf = new JarFile(file.toFile());
842-
Manifest m = jf.getManifest();
843-
Attributes attrs = (m != null) ? m.getMainAttributes() : null;
844-
if (attrs != null) {
845-
return attrs.getValue(Attributes.Name.MAIN_CLASS);
846-
}
847-
} catch (IOException ignore) {}
848-
return null;
849-
}
850-
851816
}

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -66,16 +66,21 @@ void create(Path appImage) throws IOException {
6666
content.add(Map.entry("app.mainmodule", launcherData.moduleName()
6767
+ "/" + launcherData.qualifiedClassName()));
6868
} else {
69-
// If the app is contained in an unnamed jar then launch it the
70-
// legacy way and the main class string must be
71-
// of the format com/foo/Main
7269
if (launcherData.mainJarName() != null) {
73-
content.add(Map.entry("app.classpath",
74-
appCfgLayout.appDirectory().resolve(
75-
launcherData.mainJarName())));
70+
Path mainJarPath = appCfgLayout.appDirectory().resolve(
71+
launcherData.mainJarName());
72+
73+
if (launcherData.isClassNameFromMainJar()) {
74+
content.add(Map.entry("app.mainjar", mainJarPath));
75+
} else {
76+
content.add(Map.entry("app.classpath", mainJarPath));
77+
}
78+
}
79+
80+
if (!launcherData.isClassNameFromMainJar()) {
81+
content.add(Map.entry("app.mainclass",
82+
launcherData.qualifiedClassName()));
7683
}
77-
content.add(Map.entry("app.mainclass",
78-
launcherData.qualifiedClassName()));
7984
}
8085

8186
for (var value : launcherData.classPath()) {

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -60,6 +60,10 @@ String qualifiedClassName() {
6060
return qualifiedClassName;
6161
}
6262

63+
boolean isClassNameFromMainJar() {
64+
return jarMainClass != null;
65+
}
66+
6367
String packageName() {
6468
int sepIdx = qualifiedClassName.lastIndexOf('.');
6569
if (sepIdx < 0) {
@@ -209,6 +213,7 @@ private static LauncherData createNonModular(
209213
if (attrs != null) {
210214
launcherData.qualifiedClassName = attrs.getValue(
211215
Attributes.Name.MAIN_CLASS);
216+
launcherData.jarMainClass = launcherData.qualifiedClassName;
212217
}
213218
}
214219
}
@@ -315,6 +320,7 @@ private static List<Path> getPathListParameter(String paramName,
315320
}
316321

317322
private String qualifiedClassName;
323+
private String jarMainClass;
318324
private Path mainJarName;
319325
private List<Path> classPath;
320326
private List<Path> modulePath;

test/jdk/tools/jpackage/share/jdk/jpackage/tests/MainClassTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import jdk.jpackage.test.JavaTool;
4545
import jdk.jpackage.test.Annotations.Parameters;
4646
import jdk.jpackage.test.Annotations.Test;
47+
import jdk.jpackage.test.CfgFile;
4748
import jdk.jpackage.test.Functional.ThrowingConsumer;
4849
import static jdk.jpackage.tests.MainClassTest.Script.MainClassType.*;
4950

@@ -246,6 +247,39 @@ public void test() throws IOException {
246247
nonExistingMainClass)).apply(output.stream());
247248
}
248249
}
250+
251+
CfgFile cfg = cmd.readLauncherCfgFile();
252+
if (!cmd.hasArgument("--module")) {
253+
verifyCfgFileForNonModularApp(cmd, cfg);
254+
}
255+
}
256+
257+
private static void verifyCfgFileForNonModularApp(JPackageCommand cmd,
258+
CfgFile cfg) {
259+
final List<String> mainJarProperties = List.of("app.mainjar");
260+
final List<String> classPathProperties = List.of("app.mainclass",
261+
"app.classpath");
262+
263+
final List<String> withProperties;
264+
final List<String> withoutProperties;
265+
266+
if (cmd.hasArgument("--main-jar") && !cmd.hasArgument("--main-class")) {
267+
withProperties = mainJarProperties;
268+
withoutProperties = classPathProperties;
269+
} else {
270+
withProperties = classPathProperties;
271+
withoutProperties = mainJarProperties;
272+
}
273+
274+
withProperties.forEach(prop -> {
275+
TKit.assertNotNull(cfg.getValue("Application", prop), String.format(
276+
"Check \"%s\" property is set", prop));
277+
});
278+
279+
withoutProperties.forEach(prop -> {
280+
TKit.assertNull(cfg.getValueUnchecked("Application", prop),
281+
String.format("Check \"%s\" property is NOT set", prop));
282+
});
249283
}
250284

251285
private void initJarWithWrongMainClass() throws IOException {

0 commit comments

Comments
 (0)