Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions test/jdk/tools/jpackage/apps/PrintEnv.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2021, 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.
*/

import java.util.List;
import java.util.ArrayList;

public class PrintEnv {

public static void main(String[] args) {
List<String> lines = printArgs(args);
lines.forEach(System.out::println);
}

private static List<String> printArgs(String[] args) {
List<String> lines = new ArrayList<>();

for (String arg : args) {
if (arg.startsWith(PRINT_ENV_VAR)) {
String name = arg.substring(PRINT_ENV_VAR.length());
lines.add(name + "=" + System.getenv(name));
} else if (arg.startsWith(PRINT_SYS_PROP)) {
String name = arg.substring(PRINT_SYS_PROP.length());
lines.add(name + "=" + System.getProperty(name));
} else {
throw new IllegalArgumentException();
}
}

return lines;
}

private final static String PRINT_ENV_VAR = "--print-env-var=";
private final static String PRINT_SYS_PROP = "--print-sys-prop=";
}
113 changes: 0 additions & 113 deletions test/jdk/tools/jpackage/apps/installer/Hello.java

This file was deleted.

22 changes: 13 additions & 9 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
Expand Down Expand Up @@ -56,6 +56,8 @@ public final class HelloApp {
}

private JarBuilder prepareSources(Path srcDir) throws IOException {
final String srcClassName = appDesc.srcClassName();

final String qualifiedClassName = appDesc.className();

final String className = qualifiedClassName.substring(
Expand Down Expand Up @@ -83,9 +85,9 @@ private JarBuilder prepareSources(Path srcDir) throws IOException {
// Add package directive and replace class name in java source file.
// Works with simple test Hello.java.
// Don't expect too much from these regexps!
Pattern classNameRegex = Pattern.compile("\\bHello\\b");
Pattern classNameRegex = Pattern.compile("\\b" + srcClassName + "\\b");
Pattern classDeclaration = Pattern.compile(
"(^.*\\bclass\\s+)\\bHello\\b(.*$)");
"(^.*\\bclass\\s+)\\b" + srcClassName + "\\b(.*$)");
Pattern importDirective = Pattern.compile(
"(?<=import (?:static )?+)[^;]+");
AtomicBoolean classDeclared = new AtomicBoolean();
Expand All @@ -97,7 +99,8 @@ private JarBuilder prepareSources(Path srcDir) throws IOException {
System.lineSeparator(), line);
});

Files.write(srcFile, Files.readAllLines(HELLO_JAVA).stream().map(line -> {
Files.write(srcFile,
Files.readAllLines(appDesc.srcJavaPath()).stream().map(line -> {
Matcher m;
if (classDeclared.getPlain()) {
if ((m = classNameRegex.matcher(line)).find()) {
Expand Down Expand Up @@ -144,13 +147,14 @@ void addTo(JPackageCommand cmd) {
return cmd.getArgumentValue("--module-path", cmd::inputDir, Path::of);
};

if (moduleName == null && CLASS_NAME.equals(qualifiedClassName)) {
if (moduleName == null && CLASS_NAME.equals(qualifiedClassName)
&& HELLO_JAVA.equals(appDesc.srcJavaPath())) {
// Use Hello.java as is.
cmd.addPrerequisiteAction((self) -> {
if (self.inputDir() != null) {
Path jarFile = self.inputDir().resolve(appDesc.jarFileName());
createJarBuilder().setOutputJar(jarFile).addSourceFile(
HELLO_JAVA).create();
appDesc.srcJavaPath()).create();
}
});
} else if (appDesc.jmodFileName() != null) {
Expand All @@ -159,7 +163,7 @@ void addTo(JPackageCommand cmd) {
createBundle(appDesc, getModulePath.get());
});
} else {
// Modular app in .jar file
// Modular/non-modular app in .jar file
cmd.addPrerequisiteAction(unused -> {
final Path jarFile;
if (moduleName == null) {
Expand Down Expand Up @@ -195,7 +199,7 @@ void addTo(JPackageCommand cmd) {
}

static JavaAppDesc createDefaltAppDesc() {
return new JavaAppDesc().setClassName(CLASS_NAME).setBundleFileName("hello.jar");
return new JavaAppDesc().setSrcJavaPath(HELLO_JAVA).setClassName(CLASS_NAME).setBundleFileName("hello.jar");
}

static void verifyOutputFile(Path outputFile, List<String> args,
Expand Down Expand Up @@ -462,7 +466,7 @@ public static AppOutputVerifier assertApp(Path helloAppLauncher) {
private final JavaAppDesc appDesc;

private static final Path HELLO_JAVA = TKit.TEST_SRC_ROOT.resolve(
"apps/image/Hello.java");
"apps/Hello.java");

private final static String CLASS_NAME = HELLO_JAVA.getFileName().toString().split(
"\\.", 2)[0];
Expand Down
32 changes: 29 additions & 3 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, 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
Expand Down Expand Up @@ -30,6 +30,11 @@ public final class JavaAppDesc {
public JavaAppDesc() {
}

public JavaAppDesc setSrcJavaPath(Path v) {
srcJavaPath = v;
return this;
}

public JavaAppDesc setClassName(String v) {
qualifiedClassName = v;
return this;
Expand All @@ -55,6 +60,15 @@ public JavaAppDesc setWithMainClass(boolean v) {
return this;
}

public Path srcJavaPath() {
return srcJavaPath;
}

public String srcClassName() {
String fname = srcJavaPath().getFileName().toString();
return fname.substring(0, fname.lastIndexOf('.'));
}

public String className() {
return qualifiedClassName;
}
Expand Down Expand Up @@ -113,6 +127,9 @@ public boolean isWithMainClass() {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (srcJavaPath != null) {
sb.append(srcJavaPath.toString()).append('*');
}
if (bundleFileName != null) {
sb.append(bundleFileName).append(':');
}
Expand All @@ -135,7 +152,7 @@ public String toString() {
* Create Java application description form encoded string value.
*
* Syntax of encoded Java application description is
* [(jar_file|jmods_file|exploded_jmods_file):][module_name/]qualified_class_name[!][@module_version].
* [src_java_file*][(jar_file|jmods_file|exploded_jmods_file):][module_name/]qualified_class_name[!][@module_version].
*
* E.g.: `duke.jar:com.other/com.other.foo.bar.Buz!@3.7` encodes modular
* application. Module name is `com.other`. Main class is
Expand Down Expand Up @@ -168,8 +185,16 @@ public static JavaAppDesc parse(final String javaAppDesc) {
return desc;
}

String srcJavaPathAndOther = Functional.identity(() -> {
String[] components = javaAppDesc.split("\\*", 2);
if (components.length == 2) {
desc.setSrcJavaPath(Path.of(components[0]));
}
return components[components.length - 1];
}).get();

String moduleNameAndOther = Functional.identity(() -> {
String[] components = javaAppDesc.split(":", 2);
String[] components = srcJavaPathAndOther.split(":", 2);
if (components.length == 2) {
desc.setBundleFileName(components[0]);
}
Expand Down Expand Up @@ -206,6 +231,7 @@ public static JavaAppDesc parse(final String javaAppDesc) {
return desc;
}

private Path srcJavaPath;
private String qualifiedClassName;
private String moduleName;
private String bundleFileName;
Expand Down
12 changes: 7 additions & 5 deletions test/jdk/tools/jpackage/share/AddLauncherTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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
Expand Down Expand Up @@ -185,9 +185,13 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) {
cmd.ignoreDefaultRuntime(true); // because of --add-modules
}

final String expectedMod = JavaAppDesc.parse(modularAppDesc.toString())
.setBundleFileName(null)
.setSrcJavaPath(null)
.toString();

new AdditionalLauncher("ModularAppLauncher")
.addRawProperties(Map.entry("module", JavaAppDesc.parse(
modularAppDesc.toString()).setBundleFileName(null).toString()))
.addRawProperties(Map.entry("module", expectedMod))
.addRawProperties(Map.entry("main-jar", ""))
.applyTo(cmd);

Expand All @@ -208,8 +212,6 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) {
String moduleValue = cfg.getValue("Application", "app.mainmodule");
String mainClass = null;
String classpath = null;
String expectedMod = JavaAppDesc.parse(
modularAppDesc.toString()).setBundleFileName(null).toString();
TKit.assertEquals(expectedMod, moduleValue,
String.format("Check value of app.mainmodule=[%s]" +
"in ModularAppLauncher cfg file is as expected", expectedMod));
Expand Down
Loading