< prev index next >
test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java
Print this page
*** 135,147 ****
--- 135,149 ----
};
if (moduleName == null && CLASS_NAME.equals(qualifiedClassName)) {
// 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();
+ }
});
} else if (appDesc.jmodFileName() != null) {
// Modular app in .jmod file
cmd.addPrerequisiteAction(unused -> {
createBundle(appDesc, getModulePath.get());
*** 150,165 ****
// Modular app in .jar file
cmd.addPrerequisiteAction(unused -> {
final Path jarFile;
if (moduleName == null) {
jarFile = cmd.inputDir().resolve(appDesc.jarFileName());
! } else {
jarFile = getModulePath.get().resolve(appDesc.jarFileName());
}
!
TKit.withTempDirectory("src",
workDir -> prepareSources(workDir).setOutputJar(jarFile).create());
});
}
if (moduleName == null) {
cmd.addArguments("--main-jar", appDesc.jarFileName());
--- 152,170 ----
// Modular app in .jar file
cmd.addPrerequisiteAction(unused -> {
final Path jarFile;
if (moduleName == null) {
jarFile = cmd.inputDir().resolve(appDesc.jarFileName());
! } else if (getModulePath.get() != null) {
jarFile = getModulePath.get().resolve(appDesc.jarFileName());
+ } else {
+ jarFile = null;
}
! if (jarFile != null) {
TKit.withTempDirectory("src",
workDir -> prepareSources(workDir).setOutputJar(jarFile).create());
+ }
});
}
if (moduleName == null) {
cmd.addArguments("--main-jar", appDesc.jarFileName());
*** 258,283 ****
return outputDir.resolve(jarAppDesc.jarFileName());
}
public static void executeLauncherAndVerifyOutput(JPackageCommand cmd,
String... args) {
final Path launcherPath = cmd.appLauncherPath();
if (cmd.isFakeRuntime(String.format("Not running [%s] launcher",
launcherPath))) {
! return;
}
! assertApp(launcherPath)
.addDefaultArguments(Optional
.ofNullable(cmd.getAllArgumentValues("--arguments"))
.orElseGet(() -> new String[0]))
.addJavaOptions(Optional
.ofNullable(cmd.getAllArgumentValues("--java-options"))
! .orElseGet(() -> new String[0]))
! .executeAndVerifyOutput(args);
}
public final static class AppOutputVerifier {
AppOutputVerifier(Path helloAppLauncher) {
this.launcherPath = helloAppLauncher;
this.params = new HashMap<>();
this.defaultLauncherArgs = new ArrayList<>();
--- 263,298 ----
return outputDir.resolve(jarAppDesc.jarFileName());
}
public static void executeLauncherAndVerifyOutput(JPackageCommand cmd,
String... args) {
+ getVerifier(cmd, args).executeAndVerifyOutput(args);
+ }
+
+ public static Executor.Result executeLauncher(JPackageCommand cmd,
+ String... args) {
+ return getVerifier(cmd, args).executeOnly(args);
+ }
+
+ private static AppOutputVerifier getVerifier(JPackageCommand cmd,
+ String... args) {
final Path launcherPath = cmd.appLauncherPath();
if (cmd.isFakeRuntime(String.format("Not running [%s] launcher",
launcherPath))) {
! return null;
}
! return assertApp(launcherPath)
.addDefaultArguments(Optional
.ofNullable(cmd.getAllArgumentValues("--arguments"))
.orElseGet(() -> new String[0]))
.addJavaOptions(Optional
.ofNullable(cmd.getAllArgumentValues("--java-options"))
! .orElseGet(() -> new String[0]));
}
+
public final static class AppOutputVerifier {
AppOutputVerifier(Path helloAppLauncher) {
this.launcherPath = helloAppLauncher;
this.params = new HashMap<>();
this.defaultLauncherArgs = new ArrayList<>();
*** 324,334 ****
})
.collect(Collectors.toList()));
}
public void executeAndVerifyOutput(String... args) {
! // Output file will be created in the current directory.
Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME);
ThrowingFunction.toFunction(Files::deleteIfExists).apply(outputFile);
final Path executablePath;
if (launcherPath.isAbsolute()) {
--- 339,369 ----
})
.collect(Collectors.toList()));
}
public void executeAndVerifyOutput(String... args) {
! getExecutor(args).dumpOutput().execute();
!
! final List<String> launcherArgs = List.of(args);
! final List<String> appArgs;
! if (launcherArgs.isEmpty()) {
! appArgs = defaultLauncherArgs;
! } else {
! appArgs = launcherArgs;
! }
!
! Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME);
! verifyOutputFile(outputFile, appArgs, params);
! }
!
! public Executor.Result executeOnly(String...args) {
! return getExecutor(args).saveOutput().executeWithoutExitCodeCheck();
! }
!
! private Executor getExecutor(String...args) {
!
! // Output file might be created in the current directory.
Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME);
ThrowingFunction.toFunction(Files::deleteIfExists).apply(outputFile);
final Path executablePath;
if (launcherPath.isAbsolute()) {
*** 337,361 ****
// Make sure path to executable is relative to the current directory.
executablePath = Path.of(".").resolve(launcherPath.normalize());
}
final List<String> launcherArgs = List.of(args);
! new Executor()
.setDirectory(outputFile.getParent())
.setExecutable(executablePath)
! .addArguments(launcherArgs)
! .dumpOutput()
! .execute();
!
! final List<String> appArgs;
! if (launcherArgs.isEmpty()) {
! appArgs = defaultLauncherArgs;
! } else {
! appArgs = launcherArgs;
! }
!
! verifyOutputFile(outputFile, appArgs, params);
}
private final Path launcherPath;
private final List<String> defaultLauncherArgs;
private final Map<String, String> params;
--- 372,385 ----
// Make sure path to executable is relative to the current directory.
executablePath = Path.of(".").resolve(launcherPath.normalize());
}
final List<String> launcherArgs = List.of(args);
! return new Executor()
.setDirectory(outputFile.getParent())
.setExecutable(executablePath)
! .addArguments(launcherArgs);
}
private final Path launcherPath;
private final List<String> defaultLauncherArgs;
private final Map<String, String> params;
< prev index next >