8294806: jpackaged-app ignores splash screen from jar file

Reviewed-by: almatvee
This commit is contained in:
Alexey Semenyuk 2023-04-11 16:16:07 +00:00
parent d9db90636f
commit 1de772cd89
4 changed files with 56 additions and 46 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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
@ -38,9 +38,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -507,15 +504,6 @@ public class Arguments {
}
}
if (hasMainJar && !hasMainClass) {
// try to get main-class from manifest
String mainClass = getMainClassFromManifest();
if (mainClass != null) {
CLIOptions.setOptionValue(
CLIOptions.APPCLASS.getId(), mainClass);
}
}
// display error for arguments that are not supported
// for current configuration.
@ -825,27 +813,4 @@ public class Arguments {
}
return sb.toString();
}
private String getMainClassFromManifest() {
if (mainJarPath == null ||
input == null ) {
return null;
}
JarFile jf;
try {
Path file = Path.of(input, mainJarPath);
if (!Files.exists(file)) {
return null;
}
jf = new JarFile(file.toFile());
Manifest m = jf.getManifest();
Attributes attrs = (m != null) ? m.getMainAttributes() : null;
if (attrs != null) {
return attrs.getValue(Attributes.Name.MAIN_CLASS);
}
} catch (IOException ignore) {}
return null;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
@ -66,16 +66,21 @@ final class CfgFile {
content.add(Map.entry("app.mainmodule", launcherData.moduleName()
+ "/" + launcherData.qualifiedClassName()));
} else {
// If the app is contained in an unnamed jar then launch it the
// legacy way and the main class string must be
// of the format com/foo/Main
if (launcherData.mainJarName() != null) {
content.add(Map.entry("app.classpath",
appCfgLayout.appDirectory().resolve(
launcherData.mainJarName())));
Path mainJarPath = appCfgLayout.appDirectory().resolve(
launcherData.mainJarName());
if (launcherData.isClassNameFromMainJar()) {
content.add(Map.entry("app.mainjar", mainJarPath));
} else {
content.add(Map.entry("app.classpath", mainJarPath));
}
}
if (!launcherData.isClassNameFromMainJar()) {
content.add(Map.entry("app.mainclass",
launcherData.qualifiedClassName()));
}
content.add(Map.entry("app.mainclass",
launcherData.qualifiedClassName()));
}
for (var value : launcherData.classPath()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, 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
@ -60,6 +60,10 @@ final class LauncherData {
return qualifiedClassName;
}
boolean isClassNameFromMainJar() {
return jarMainClass != null;
}
String packageName() {
int sepIdx = qualifiedClassName.lastIndexOf('.');
if (sepIdx < 0) {
@ -209,6 +213,7 @@ final class LauncherData {
if (attrs != null) {
launcherData.qualifiedClassName = attrs.getValue(
Attributes.Name.MAIN_CLASS);
launcherData.jarMainClass = launcherData.qualifiedClassName;
}
}
}
@ -315,6 +320,7 @@ final class LauncherData {
}
private String qualifiedClassName;
private String jarMainClass;
private Path mainJarName;
private List<Path> classPath;
private List<Path> modulePath;

View File

@ -44,6 +44,7 @@ import jdk.jpackage.test.HelloApp;
import jdk.jpackage.test.JavaTool;
import jdk.jpackage.test.Annotations.Parameters;
import jdk.jpackage.test.Annotations.Test;
import jdk.jpackage.test.CfgFile;
import jdk.jpackage.test.Functional.ThrowingConsumer;
import static jdk.jpackage.tests.MainClassTest.Script.MainClassType.*;
@ -246,6 +247,39 @@ public final class MainClassTest {
nonExistingMainClass)).apply(output.stream());
}
}
CfgFile cfg = cmd.readLauncherCfgFile();
if (!cmd.hasArgument("--module")) {
verifyCfgFileForNonModularApp(cmd, cfg);
}
}
private static void verifyCfgFileForNonModularApp(JPackageCommand cmd,
CfgFile cfg) {
final List<String> mainJarProperties = List.of("app.mainjar");
final List<String> classPathProperties = List.of("app.mainclass",
"app.classpath");
final List<String> withProperties;
final List<String> withoutProperties;
if (cmd.hasArgument("--main-jar") && !cmd.hasArgument("--main-class")) {
withProperties = mainJarProperties;
withoutProperties = classPathProperties;
} else {
withProperties = classPathProperties;
withoutProperties = mainJarProperties;
}
withProperties.forEach(prop -> {
TKit.assertNotNull(cfg.getValue("Application", prop), String.format(
"Check \"%s\" property is set", prop));
});
withoutProperties.forEach(prop -> {
TKit.assertNull(cfg.getValueUnchecked("Application", prop),
String.format("Check \"%s\" property is NOT set", prop));
});
}
private void initJarWithWrongMainClass() throws IOException {