From a4300b37d18ab48a9bc115a846f4fb34499d4b60 Mon Sep 17 00:00:00 2001 From: Geert Bevin Date: Sun, 25 Aug 2024 14:07:36 -0400 Subject: [PATCH 1/3] Added JlinkOptions, JmodOptions and JpackageOptions File argument alternatives with Path and String. Moved launches configurations from JPackage options to operation. --- .idea/misc.xml | 22 + .../rife/bld/operations/JlinkOperation.java | 25 ++ .../rife/bld/operations/JlinkOptions.java | 52 +++ .../rife/bld/operations/JmodOperation.java | 51 +++ .../java/rife/bld/operations/JmodOptions.java | 178 ++++++++ .../bld/operations/JpackageOperation.java | 96 ++++- .../rife/bld/operations/JpackageOptions.java | 385 ++++++++++++++++-- .../bld/operations/TestJlinkOperation.java | 47 ++- .../bld/operations/TestJmodOperation.java | 126 +++++- .../bld/operations/TestJpackageOperation.java | 232 ++++++++++- 10 files changed, 1151 insertions(+), 63 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 8678395..58cce37 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/rife/bld/operations/JlinkOperation.java b/src/main/java/rife/bld/operations/JlinkOperation.java index d0ae64a..1adc9ef 100644 --- a/src/main/java/rife/bld/operations/JlinkOperation.java +++ b/src/main/java/rife/bld/operations/JlinkOperation.java @@ -4,7 +4,10 @@ */ package rife.bld.operations; +import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -35,6 +38,28 @@ public JlinkOperation cmdFiles(String... file) { return this; } + /** + * Read options and/or mode from file(s). + * + * @param file one or more file + * @return this operation instance + */ + public JlinkOperation cmdFiles(File... file) { + cmdFiles_.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList()); + return this; + } + + /** + * Read options and/or mode from file(s). + * + * @param file one or more file + * @return this operation instance + */ + public JlinkOperation cmdFiles(Path... file) { + cmdFiles_.addAll(Arrays.stream(file).map(Path::toString).toList()); + return this; + } + /** * Retrieves the list of files containing options or mode. * diff --git a/src/main/java/rife/bld/operations/JlinkOptions.java b/src/main/java/rife/bld/operations/JlinkOptions.java index c0f931a..e7f8d44 100644 --- a/src/main/java/rife/bld/operations/JlinkOptions.java +++ b/src/main/java/rife/bld/operations/JlinkOptions.java @@ -4,6 +4,8 @@ */ package rife.bld.operations; +import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -161,6 +163,34 @@ public JlinkOptions modulePath(String path) { return this; } + /** + * Module path. + *

+ * If not specified, the JDKs jmods directory will be used, if it exists. If specified, but it does not contain the + * java.base module, the JDKs jmods directory will be added, if it exists. + * + * @param path the module path + * @return this map of options + */ + public JlinkOptions modulePath(File path) { + put("--module-path", path.getAbsolutePath()); + return this; + } + + /** + * Module path. + *

+ * If not specified, the JDKs jmods directory will be used, if it exists. If specified, but it does not contain the + * java.base module, the JDKs jmods directory will be added, if it exists. + * + * @param path the module path + * @return this map of options + */ + public JlinkOptions modulePath(Path path) { + put("--module-path", path.toString()); + return this; + } + /** * Exclude include header files. * @@ -202,6 +232,28 @@ public JlinkOptions output(String path) { return this; } + /** + * Location of output path. + * + * @param path the output path + * @return this map of options + */ + public JlinkOptions output(File path) { + put("--output", path.getAbsolutePath()); + return this; + } + + /** + * Location of output path. + * + * @param path the output path + * @return this map of options + */ + public JlinkOptions output(Path path) { + put("--output", path.toString()); + return this; + } + /** * Associates {@code null} with the specified key in this map. If the map previously contained a mapping for the * key, the old value is replaced. diff --git a/src/main/java/rife/bld/operations/JmodOperation.java b/src/main/java/rife/bld/operations/JmodOperation.java index cc9b317..cf36fc7 100644 --- a/src/main/java/rife/bld/operations/JmodOperation.java +++ b/src/main/java/rife/bld/operations/JmodOperation.java @@ -4,7 +4,10 @@ */ package rife.bld.operations; +import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -44,6 +47,28 @@ public JmodOperation cmdFiles(String... file) { return this; } + /** + * Read options and/or mode from file(s). + * + * @param file one or more file + * @return this operation instance + */ + public JmodOperation cmdFiles(File... file) { + cmdFiles.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList()); + return this; + } + + /** + * Read options and/or mode from file(s). + * + * @param file one or more file + * @return this operation instance + */ + public JmodOperation cmdFiles(Path... file) { + cmdFiles.addAll(Arrays.stream(file).map(Path::toString).toList()); + return this; + } + @Override public void execute() throws Exception { if (operationMode_ != null) { @@ -82,6 +107,32 @@ public JmodOperation jmodFile(String file) { return this; } + /** + * Specifies name of the JMOD file to create or from which to retrieve information. + *

+ * The JMOD file is required. + * + * @param file the JMOD file + * @return this operation instance + */ + public JmodOperation jmodFile(File file) { + jmodFile_ = file.getAbsolutePath(); + return this; + } + + /** + * Specifies name of the JMOD file to create or from which to retrieve information. + *

+ * The JMOD file is required. + * + * @param file the JMOD file + * @return this operation instance + */ + public JmodOperation jmodFile(Path file) { + jmodFile_ = file.toString(); + return this; + } + /** * Retrieves the list of options for the jmod tool. *

diff --git a/src/main/java/rife/bld/operations/JmodOptions.java b/src/main/java/rife/bld/operations/JmodOptions.java index c043206..81ed4c3 100644 --- a/src/main/java/rife/bld/operations/JmodOptions.java +++ b/src/main/java/rife/bld/operations/JmodOptions.java @@ -4,6 +4,8 @@ */ package rife.bld.operations; +import java.io.File; +import java.nio.file.Path; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; @@ -39,6 +41,28 @@ public JmodOptions cmds(String path) { return this; } + /** + * Location of native commands. + * + * @param path the location + * @return this map of options + */ + public JmodOptions cmds(File path) { + put("--cmds", path.getAbsolutePath()); + return this; + } + + /** + * Location of native commands. + * + * @param path the location + * @return this map of options + */ + public JmodOptions cmds(Path path) { + put("--cmds", path.toString()); + return this; + } + /** * Compression to use when creating the JMOD archive. *

@@ -68,6 +92,28 @@ public JmodOptions config(String path) { return this; } + /** + * Location of user-editable config files + * + * @param path the path to the config files + * @return this map of options + */ + public JmodOptions config(File path) { + put("--config", path.getAbsolutePath()); + return this; + } + + /** + * Location of user-editable config files + * + * @param path the path to the config files + * @return this map of options + */ + public JmodOptions config(Path path) { + put("--config", path.toString()); + return this; + } + /** * Date and time for the timestamps of entries. * @@ -90,6 +136,28 @@ public JmodOptions dir(String path) { return this; } + /** + * Target directory for extract + * + * @param path the directory path + * @return this map of options + */ + public JmodOptions dir(File path) { + put("--dir", path.getAbsolutePath()); + return this; + } + + /** + * Target directory for extract + * + * @param path the directory path + * @return this map of options + */ + public JmodOptions dir(Path path) { + put("--dir", path.toString()); + return this; + } + /** * Exclude from the default root set of modules. * @@ -163,6 +231,28 @@ public JmodOptions headerFiles(String path) { return this; } + /** + * Location of header files. + * + * @param path the location + * @return this map of options + */ + public JmodOptions headerFiles(File path) { + put("--header-files", path.getAbsolutePath()); + return this; + } + + /** + * Location of header files. + * + * @param path the location + * @return this map of options + */ + public JmodOptions headerFiles(Path path) { + put("--header-files", path.toString()); + return this; + } + /** * Location of legal notices. * @@ -174,6 +264,28 @@ public JmodOptions legalNotices(String path) { return this; } + /** + * Location of legal notices. + * + * @param path the location + * @return this map of options + */ + public JmodOptions legalNotices(File path) { + put("--legal-notices", path.getAbsolutePath()); + return this; + } + + /** + * Location of legal notices. + * + * @param path the location + * @return this map of options + */ + public JmodOptions legalNotices(Path path) { + put("--legal-notices", path.toString()); + return this; + } + /** * Location of native libraries. * @@ -185,6 +297,28 @@ public JmodOptions libs(String path) { return this; } + /** + * Location of native libraries. + * + * @param path the location + * @return this map of options + */ + public JmodOptions libs(File path) { + put("--libs", path.getAbsolutePath()); + return this; + } + + /** + * Location of native libraries. + * + * @param path the location + * @return this map of options + */ + public JmodOptions libs(Path path) { + put("--libs", path.toString()); + return this; + } + /** * Main class. * @@ -207,6 +341,28 @@ public JmodOptions manPages(String path) { return this; } + /** + * Location of man pages. + * + * @param path the location + * @return this map of options + */ + public JmodOptions manPages(File path) { + put("--man-pages", path.getAbsolutePath()); + return this; + } + + /** + * Location of man pages. + * + * @param path the location + * @return this map of options + */ + public JmodOptions manPages(Path path) { + put("--man-pages", path.toString()); + return this; + } + /** * Module path. * @@ -218,6 +374,28 @@ public JmodOptions modulePath(String path) { return this; } + /** + * Module path. + * + * @param path the module path + * @return this map of options + */ + public JmodOptions modulePath(File path) { + put("--module-path", path.getAbsolutePath()); + return this; + } + + /** + * Module path. + * + * @param path the module path + * @return this map of options + */ + public JmodOptions modulePath(Path path) { + put("--module-path", path.toString()); + return this; + } + /** * Module version. * diff --git a/src/main/java/rife/bld/operations/JpackageOperation.java b/src/main/java/rife/bld/operations/JpackageOperation.java index 911d53a..e7a1286 100644 --- a/src/main/java/rife/bld/operations/JpackageOperation.java +++ b/src/main/java/rife/bld/operations/JpackageOperation.java @@ -4,7 +4,10 @@ */ package rife.bld.operations; +import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -17,25 +20,48 @@ public class JpackageOperation extends AbstractToolProviderOperation { private final List cmdFiles_ = new ArrayList<>(); private final JpackageOptions jpackageOptions_ = new JpackageOptions(); + private final List launchers_ = new ArrayList<>(); public JpackageOperation() { super("jpackage"); } - @Override - public void execute() throws Exception { - toolArgs(cmdFiles_.stream().map(opt -> '@' + opt).toList()); - toolArgs(jpackageOptions_); - super.execute(); + /** + * List of application launchers. + *

+ * The main application launcher will be built from the command line options. + *

+ * Additional alternative launchers can be built using this option, and this option can be used to build multiple + * additional launchers. + * + * @param launcher one or more {@link JpackageOperation.Launcher} + * @return this operation instance + */ + public JpackageOperation addLauncher(Launcher... launcher) { + launchers_.addAll(Arrays.asList(launcher)); + return this; } /** - * Retrieves the list of files containing options or mode. + * Read options and/or mode from file(s). * - * @return the list of files + * @param file one or more file + * @return this operation instance */ - public List fileOptions() { - return cmdFiles_; + public JpackageOperation cmdFiles(File... file) { + cmdFiles_.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList()); + return this; + } + + /** + * Read options and/or mode from file(s). + * + * @param file one or more file + * @return this operation instance + */ + public JpackageOperation cmdFiles(Path... file) { + cmdFiles_.addAll(Arrays.stream(file).map(Path::toString).toList()); + return this; } /** @@ -49,6 +75,25 @@ public JpackageOperation cmdFiles(String... file) { return this; } + /** + * Retrieves the list of files containing options or mode. + * + * @return the list of files + */ + public List cmdFiles() { + return cmdFiles_; + } + + @Override + public void execute() throws Exception { + toolArgs(cmdFiles_.stream().map(opt -> '@' + opt).toList()); + for (var l : launchers_) { + toolArgs("--add-launcher", l.name + '=' + l.path); + } + toolArgs(jpackageOptions_); + super.execute(); + } + /** * Retrieves the list of options for the jpackage tool. *

@@ -72,4 +117,37 @@ public JpackageOperation jpackageOptions(Map options) { jpackageOptions_.putAll(options); return this; } + + /** + * Retrieves the list of application launchers. + * + * @return the list of launchers + */ + public List launchers() { + return launchers_; + } + + /** + * Name of launcher, and a path to a Properties file that contains a list of key, value pairs. + *

+ * The keys {@code module}, {@code main-jar}, {@code main-class}, {@code description}, + * {@code arguments}, {@code java-options}, {@code app-version}, {@code icon}, + * {@code launcher-as-service}, {@code win-console}, {@code win-shortcut}, {@code win-menu}, + * {@code linux-app-category}, and {@code linux-shortcut} can be used. + *

+ * These options are added to, or used to overwrite, the original command line options to build an additional + * alternative launcher. + * + * @param name the name + * @param path absolute path or relative to the current directory + */ + public record Launcher(String name, String path) { + public Launcher(String name, File path) { + this(name, path.getAbsolutePath()); + } + + public Launcher(String name, Path path) { + this(name, path.toString()); + } + } } diff --git a/src/main/java/rife/bld/operations/JpackageOptions.java b/src/main/java/rife/bld/operations/JpackageOptions.java index 0df7a4b..bc33f90 100644 --- a/src/main/java/rife/bld/operations/JpackageOptions.java +++ b/src/main/java/rife/bld/operations/JpackageOptions.java @@ -4,6 +4,9 @@ */ package rife.bld.operations; +import java.io.File; +import java.nio.file.Path; +import java.util.Arrays; import java.util.HashMap; /** @@ -24,24 +27,6 @@ public JpackageOptions aboutUrl(String url) { return this; } - /** - * List of application launchers. - *

- * The main application launcher will be built from the command line options. - *

- * Additional alternative launchers can be built using this option, and this option can be used to build multiple - * additional launchers. - * - * @param launcher one or more {@link Launcher} - * @return this map of options - */ - public JpackageOptions addLauncher(Launcher... launcher) { - for (var l : launcher) { - put("--add-launcher", l.name + '=' + l.path); - } - return this; - } - /** * List of modules to add. *

@@ -82,6 +67,29 @@ public JpackageOptions appImage(String path) { return this; } + /** + * Location of the predefined application image that is used to build an installable package. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions appImage(File path) { + put("--app-image", path.getAbsolutePath()); + return this; + } + + /** + * Location of the predefined application image that is used to build an installable package. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions appImage(Path path) { + put("--app-image", path.toString()); + return this; + } + /** * Version of the application and/or package. * @@ -139,6 +147,33 @@ public JpackageOptions dest(String path) { return this; } + /** + * Path where generated output file is placed. + *

+ * Defaults to the current working directory. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions dest(File path) { + put("--dest", path.getAbsolutePath()); + return this; + } + + /** + * Path where generated output file is placed. + *

+ * Defaults to the current working directory. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions dest(Path path) { + put("--dest", path.toString()); + return this; + } + /** * Path to a Properties file that contains list of key, value pairs. *

@@ -153,6 +188,35 @@ public JpackageOptions fileAssociations(String... path) { return this; } + /** + * Path to a Properties file that contains list of key, value pairs. + *

+ * The keys {@code extension}, {@code mime-type}, {@code icon}, and {@code description} can be used to describe the + * association. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions fileAssociations(File... path) { + put("--file-associations", String.join(",", Arrays.stream(path).map(File::getAbsolutePath).toList())); + return this; + } + + /** + * Path to a Properties file that contains list of key, value pairs. + *

+ * The keys {@code extension}, {@code mime-type}, {@code icon}, and {@code description} can be used to describe the + * association. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions fileAssociations(Path... path) { + put("--file-associations", String.join(",", Arrays.stream(path).map(Path::toString).toList())); + return this; + } + /** * Path of the icon of the application package. * @@ -164,6 +228,29 @@ public JpackageOptions icon(String path) { return this; } + /** + * Path of the icon of the application package. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions icon(File path) { + put("--icon", path.getAbsolutePath()); + return this; + } + + /** + * Path of the icon of the application package. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions icon(Path path) { + put("--icon", path.toString()); + return this; + } + /** * Path of the input directory that contains the files to be packaged. *

@@ -177,6 +264,32 @@ public JpackageOptions input(String path) { return this; } + /** + * Path of the input directory that contains the files to be packaged. + *

+ * All files in the input directory will be packaged into the application image. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions input(File path) { + put("--input", path.getAbsolutePath()); + return this; + } + + /** + * Path of the input directory that contains the files to be packaged. + *

+ * All files in the input directory will be packaged into the application image. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions input(Path path) { + put("--input", path.toString()); + return this; + } + /** * Absolute path of the installation directory of the application. * @@ -188,6 +301,29 @@ public JpackageOptions installDir(String path) { return this; } + /** + * Absolute path of the installation directory of the application. + * + * @param path the absolute directory path + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions installDir(File path) { + put("--install-dir", path.getAbsolutePath()); + return this; + } + + /** + * Absolute path of the installation directory of the application. + * + * @param path the absolute directory path + * @return this map of options + */ + public JpackageOptions installDir(Path path) { + put("--install-dir", path.toString()); + return this; + } + /** * Options to pass to the Java runtime. * @@ -243,6 +379,29 @@ public JpackageOptions licenseFile(String path) { return this; } + /** + * Path to the license file. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions licenseFile(File path) { + put("--license-file", path.getAbsolutePath()); + return this; + } + + /** + * Path to the license file. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions licenseFile(Path path) { + put("--license-file", path.toString()); + return this; + } + /** * Group value of the RPM {@code .spec} file or Section value of DEB control file. * @@ -395,6 +554,29 @@ public JpackageOptions macDmgContent(String... additionalContent) { return this; } + /** + * Include all the referenced content in the dmg. + * + * @param additionalContent one or more path + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions macDmgContent(File... additionalContent) { + put("--mac-dmg-content", String.join(",", Arrays.stream(additionalContent).map(File::getAbsolutePath).toList())); + return this; + } + + /** + * Include all the referenced content in the dmg. + * + * @param additionalContent one or more path + * @return this map of options + */ + public JpackageOptions macDmgContent(Path... additionalContent) { + put("--mac-dmg-content", String.join(",", Arrays.stream(additionalContent).map(Path::toString).toList())); + return this; + } + /** * Path to file containing entitlements to use when signing executables and libraries in the bundle. * @@ -406,6 +588,29 @@ public JpackageOptions macEntitlements(String path) { return this; } + /** + * Path to file containing entitlements to use when signing executables and libraries in the bundle. + * + * @param path the fie path + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions macEntitlements(File path) { + put("--mac-entitlements", path.getAbsolutePath()); + return this; + } + + /** + * Path to file containing entitlements to use when signing executables and libraries in the bundle. + * + * @param path the fie path + * @return this map of options + */ + public JpackageOptions macEntitlements(Path path) { + put("--mac-entitlements", path.toString()); + return this; + } + /** * Identity used to sign "pkg" installer. *

@@ -593,6 +798,36 @@ public JpackageOptions modulePath(String... path) { return this; } + /** + * List of module paths. + *

+ * Each path is either a directory of modules or the path to a modular jar. + *

+ * Each path is absolute or relative to the current directory. + * + * @param path one or more path + * @return this map of options + */ + public JpackageOptions modulePath(File... path) { + put("--module-path", String.join(":", Arrays.stream(path).map(File::getAbsolutePath).toList())); + return this; + } + + /** + * List of module paths. + *

+ * Each path is either a directory of modules or the path to a modular jar. + *

+ * Each path is absolute or relative to the current directory. + * + * @param path one or more path + * @return this map of options + */ + public JpackageOptions modulePath(Path... path) { + put("--module-path", String.join(":", Arrays.stream(path).map(Path::toString).toList())); + return this; + } + /** * Name of the application and/or package. * @@ -628,6 +863,35 @@ public JpackageOptions resourceDir(String path) { return this; } + /** + * Path to override jpackage resources. + *

+ * Icons, template files, and other resources of jpackage can be over-ridden by adding replacement resources to + * this directory. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions resourceDir(File path) { + put("--resource-dir", path.getAbsolutePath()); + return this; + } + + /** + * Path to override jpackage resources. + *

+ * Icons, template files, and other resources of jpackage can be over-ridden by adding replacement resources to + * this directory. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions resourceDir(Path path) { + put("--resource-dir", path.toString()); + return this; + } + /** * Path of the predefined runtime image that will be copied into the application image. *

@@ -646,6 +910,43 @@ public JpackageOptions runtimeImage(String path) { return this; } + /** + * Path of the predefined runtime image that will be copied into the application image. + *

+ * If not specified, jpackage will run jlink to create the runtime image using options: + * {@link JlinkOptions#stripNativeCommands(boolean) stripNativeCommands} + * {@link JlinkOptions#stripDebug(boolean) stripDebug} {@link JlinkOptions#noManPages(boolean) noManPages} + * {@link JlinkOptions#noHeaderFiles(boolean) noHeaderFiles} + *

+ * Option is required when creating a runtime package. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions runtimeImage(File path) { + put("--runtime-image", path.getAbsolutePath()); + return this; + } + + /** + * Path of the predefined runtime image that will be copied into the application image. + *

+ * If not specified, jpackage will run jlink to create the runtime image using options: + * {@link JlinkOptions#stripNativeCommands(boolean) stripNativeCommands} + * {@link JlinkOptions#stripDebug(boolean) stripDebug} {@link JlinkOptions#noManPages(boolean) noManPages} + * {@link JlinkOptions#noHeaderFiles(boolean) noHeaderFiles} + *

+ * Option is required when creating a runtime package. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions runtimeImage(Path path) { + put("--runtime-image", path.toString()); + return this; + } + /** * Strip debug information. * @@ -676,6 +977,37 @@ public JpackageOptions temp(String path) { return this; } + /** + * Path of a new or empty directory used to create temporary files. + *

+ * If specified, the temp dir will not be removed upon the task completion and must be removed manually. + *

+ * If not specified, a temporary directory will be created and removed upon the task completion. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + @SuppressWarnings("UnusedReturnValue") + public JpackageOptions temp(File path) { + put("--temp", path.getAbsolutePath()); + return this; + } + + /** + * Path of a new or empty directory used to create temporary files. + *

+ * If specified, the temp dir will not be removed upon the task completion and must be removed manually. + *

+ * If not specified, a temporary directory will be created and removed upon the task completion. + * + * @param path absolute path or relative to the current directory + * @return this map of options + */ + public JpackageOptions temp(Path path) { + put("--temp", path.toString()); + return this; + } + /** * The type of package to create. *

@@ -868,21 +1200,4 @@ public enum PackageType { this.type = type; } } - - /** - * Name of launcher, and a path to a Properties file that contains a list of key, value pairs. - *

- * The keys {@code module}, {@code main-jar}, {@code main-class}, {@code description}, - * {@code arguments}, {@code java-options}, {@code app-version}, {@code icon}, - * {@code launcher-as-service}, {@code win-console}, {@code win-shortcut}, {@code win-menu}, - * {@code linux-app-category}, and {@code linux-shortcut} can be used. - *

- * These options are added to, or used to overwrite, the original command line options to build an additional - * alternative launcher. - * - * @param name the name - * @param path absolute path or relative to the current directory - */ - public record Launcher(String name, String path) { - } } diff --git a/src/test/java/rife/bld/operations/TestJlinkOperation.java b/src/test/java/rife/bld/operations/TestJlinkOperation.java index 88086e7..66f4dfc 100644 --- a/src/test/java/rife/bld/operations/TestJlinkOperation.java +++ b/src/test/java/rife/bld/operations/TestJlinkOperation.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import static org.junit.jupiter.api.Assertions.*; @@ -89,11 +90,21 @@ void testCmdFiles() { assertTrue(out.contains("List of available plugins:"), out); } + @Test + void testCmdFilesPath() { + System.setOut(new PrintStream(outputStreamCaptor)); + var jlink = new JlinkOperation().cmdFiles(Path.of("src/test/resources/jlink/options_verbose.txt"), + Path.of("src/test/resources/jlink/options_version.txt")); + assertDoesNotThrow(jlink::execute); + var out = outputStreamCaptor.toString(); + assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); + } + @Test void testCmdFilesVersion() { System.setOut(new PrintStream(outputStreamCaptor)); - var jlink = new JlinkOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt", - "src/test/resources/jlink/options_version.txt"); + var jlink = new JlinkOperation().cmdFiles(new File("src/test/resources/jlink/options_verbose.txt"), + new File("src/test/resources/jlink/options_version.txt")); assertDoesNotThrow(jlink::execute); var out = outputStreamCaptor.toString(); assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); @@ -118,10 +129,10 @@ void testExecute() throws IOException { var output = new File(tmpdir, "jlink"); var options = new JlinkOptions() - .modulePath("src/test/resources/jlink/build/jmod") + .modulePath(new File("src/test/resources/jlink/build/jmod")) .addModules("dev.mccue.tree") .launcher("tree", "dev.mccue.tree", "dev.mccue.tree.Tree") - .output(output.getAbsolutePath()); + .output(output); if (Runtime.version().version().get(0) >= 21) { options.compress(ZipCompression.ZIP_6); } else { @@ -144,6 +155,20 @@ void testHelp() { assertTrue(jlink.toolArgs().isEmpty(), "args not empty"); } + @Test + void testModulePath() { + var options = new JlinkOptions(); + + options.modulePath("foo"); + assertEquals("foo", options.get("--module-path")); + options.modulePath(Path.of("bar")); + assertEquals("bar", options.get("--module-path")); + + var foo = new File("foo"); + options.modulePath(foo); + assertEquals(foo.getAbsolutePath(), options.get("--module-path")); + } + @Test void testNoArguments() { var jlink = new JlinkOperation(); @@ -152,6 +177,20 @@ void testNoArguments() { assertThrows(ExitStatusException.class, jlink::execute); } + @Test + void testOutput() { + var options = new JlinkOptions(); + + options.output("foo"); + assertEquals("foo", options.get("--output")); + options.output(Path.of("bar")); + assertEquals("bar", options.get("--output")); + + var foo = new File("foo"); + options.output(foo); + assertEquals(foo.getAbsolutePath(), options.get("--output")); + } + @Test void testVersion() { System.setOut(new PrintStream(outputStreamCaptor)); diff --git a/src/test/java/rife/bld/operations/TestJmodOperation.java b/src/test/java/rife/bld/operations/TestJmodOperation.java index ac68b0d..1d4b036 100644 --- a/src/test/java/rife/bld/operations/TestJmodOperation.java +++ b/src/test/java/rife/bld/operations/TestJmodOperation.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; +import java.nio.file.Path; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.HashMap; @@ -84,7 +85,7 @@ void testArguments() { @Test void testCmdFiles() { System.setOut(new PrintStream(outputStreamCaptor)); - var jmod = new JmodOperation().cmdFiles("src/test/resources/jlink/options_version.txt"); + var jmod = new JmodOperation().cmdFiles(new File("src/test/resources/jlink/options_version.txt")); assertDoesNotThrow(jmod::execute); var out = outputStreamCaptor.toString(); assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); @@ -98,7 +99,7 @@ void testCmdFilesCreate() throws IOException { var jmod = new JmodOperation() .cmdFiles("src/test/resources/jlink/options_jmod.txt") - .jmodFile(mod.getAbsolutePath()); + .jmodFile(mod); assertDoesNotThrow(jmod::execute); assertTrue(mod.exists(), "mod does not exist"); @@ -107,6 +108,39 @@ void testCmdFilesCreate() throws IOException { } } + @Test + void testCmdFilesPath() { + System.setOut(new PrintStream(outputStreamCaptor)); + var jmod = new JmodOperation().cmdFiles(Path.of("src/test/resources/jlink/options_version.txt")); + assertDoesNotThrow(jmod::execute); + var out = outputStreamCaptor.toString(); + assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); + } + + @Test + void testCmds() { + var options = new JmodOptions().cmds("foo"); + assertEquals("foo", options.get("--cmds")); + options = options.cmds(Path.of("bar")); + assertEquals("bar", options.get("--cmds")); + + var foo = new File("foo"); + options.cmds(foo); + assertEquals(foo.getAbsolutePath(), options.get("--cmds")); + } + + @Test + void testConfig() { + var options = new JmodOptions().config("foo"); + assertEquals("foo", options.get("--config")); + options = options.config(Path.of("bar")); + assertEquals("bar", options.get("--config")); + + var foo = new File("foo"); + options.config(foo); + assertEquals(foo.getAbsolutePath(), options.get("--config")); + } + @Test void testCreate() throws IOException { var tmpdir = Files.createTempDirectory("bld-jmod-test").toFile(); @@ -119,7 +153,7 @@ void testCreate() throws IOException { .classpath("src/test/resources/jlink/build/jar/dev.mccue.apple.jar"); var jmod = new JmodOperation() .operationMode(OperationMode.CREATE) - .jmodFile(mod.getAbsolutePath()) + .jmodFile(mod) .jmodOptions(options); assertDoesNotThrow(jmod::execute); @@ -129,6 +163,18 @@ void testCreate() throws IOException { } } + @Test + void testDir() { + var options = new JmodOptions().dir("foo"); + assertEquals("foo", options.get("--dir")); + options = options.dir(Path.of("bar")); + assertEquals("bar", options.get("--dir")); + + var foo = new File("foo"); + options.dir(foo); + assertEquals(foo.getAbsolutePath(), options.get("--dir")); + } + @Test void testExecute() throws IOException { var tmpdir = Files.createTempDirectory("bld-jmod-test").toFile(); @@ -142,7 +188,7 @@ void testExecute() throws IOException { var jmod = new JmodOperation() .operationMode(OperationMode.CREATE) - .jmodFile(mod.getAbsolutePath()) + .jmodFile(mod) .jmodOptions(options); assertDoesNotThrow(jmod::execute); @@ -165,6 +211,18 @@ void testExecute() throws IOException { } } + @Test + void testHeaderFiles() { + var options = new JmodOptions().headerFiles("foo"); + assertEquals("foo", options.get("--header-files")); + options = options.headerFiles(Path.of("bar")); + assertEquals("bar", options.get("--header-files")); + + var foo = new File("foo"); + options.headerFiles(foo); + assertEquals(foo.getAbsolutePath(), options.get("--header-files")); + } + @Test void testHelp() { var jmod = new JmodOperation().toolArgs("--help-extra"); @@ -172,6 +230,66 @@ void testHelp() { assertTrue(jmod.toolArgs().isEmpty(), "args not empty"); } + @Test + void testJmodFile() { + var op = new JmodOperation().jmodFile("foo"); + assertEquals("foo", op.jmodFile()); + op = op.jmodFile(Path.of("bar")); + assertEquals("bar", op.jmodFile()); + + var foo = new File("foo"); + op.jmodFile(foo); + assertEquals(foo.getAbsolutePath(), op.jmodFile()); + } + + @Test + void testLegalNotices() { + var options = new JmodOptions().legalNotices("foo"); + assertEquals("foo", options.get("--legal-notices")); + options = options.legalNotices(Path.of("bar")); + assertEquals("bar", options.get("--legal-notices")); + + var foo = new File("foo"); + options.legalNotices(foo); + assertEquals(foo.getAbsolutePath(), options.get("--legal-notices")); + } + + @Test + void testLibs() { + var options = new JmodOptions().libs("foo"); + assertEquals("foo", options.get("--libs")); + options = options.libs(Path.of("bar")); + assertEquals("bar", options.get("--libs")); + + var foo = new File("foo"); + options.libs(foo); + assertEquals(foo.getAbsolutePath(), options.get("--libs")); + } + + @Test + void testManPages() { + var options = new JmodOptions().manPages("foo"); + assertEquals("foo", options.get("--man-pages")); + options = options.manPages(Path.of("bar")); + assertEquals("bar", options.get("--man-pages")); + + var foo = new File("foo"); + options.manPages(foo); + assertEquals(foo.getAbsolutePath(), options.get("--man-pages")); + } + + @Test + void testModulePath() { + var options = new JmodOptions().modulePath("foo"); + assertEquals("foo", options.get("--module-path")); + options = options.modulePath(Path.of("bar")); + assertEquals("bar", options.get("--module-path")); + + var foo = new File("foo"); + options.modulePath(foo); + assertEquals(foo.getAbsolutePath(), options.get("--module-path")); + } + @Test void testNoArguments() { var jmod = new JmodOperation(); diff --git a/src/test/java/rife/bld/operations/TestJpackageOperation.java b/src/test/java/rife/bld/operations/TestJpackageOperation.java index 35657b0..8dd5061 100644 --- a/src/test/java/rife/bld/operations/TestJpackageOperation.java +++ b/src/test/java/rife/bld/operations/TestJpackageOperation.java @@ -10,12 +10,14 @@ import rife.tools.FileUtils; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.PrintStream; import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import static org.junit.jupiter.api.Assertions.*; -import static rife.bld.operations.JpackageOptions.Launcher; +import static rife.bld.operations.JpackageOperation.Launcher; import static rife.bld.operations.JpackageOptions.PackageType; public class TestJpackageOperation { @@ -27,11 +29,42 @@ public void tearDown() { System.setOut(stdout); } + @Test + void testAddLauncher() { + var op = new JpackageOperation(); + + var foo = new Launcher("foo-name", "foo-path"); + var bar = new Launcher("bar-name", Path.of("bar-path")); + assertEquals(bar.name(), "bar-name"); + assertEquals(bar.path(), "bar-path"); + + var f = new File("foo/bar"); + var foobar = new Launcher("foobar", f); + assertEquals(foobar.name(), "foobar"); + assertEquals(foobar.path(), f.getAbsolutePath()); + + op = op.addLauncher(foo); + assertTrue(op.launchers().contains(foo), "foo not found"); + op.addLauncher(bar); + assertTrue(op.launchers().contains(bar), "bar not found"); + } + + @Test + void testAppImage() { + var options = new JpackageOptions().appImage("foo"); + assertEquals("foo", options.get("--app-image")); + options.appImage(Path.of("bar")); + assertEquals("bar", options.get("--app-image")); + + var foo = new File("foo"); + options = options.appImage(foo); + assertEquals(foo.getAbsolutePath(), options.get("--app-image")); + } + @Test void testArguments() { var args = new HashMap(); args.put("--about-url", "about-url"); - args.put("--add-launcher", "name=path"); args.put("--add-modules", "modules-1,modules-2"); args.put("--app-content", "content-1,content-2"); args.put("--app-image", "app-image"); @@ -93,7 +126,6 @@ void testArguments() { var options = new JpackageOptions() .aboutUrl(args.get("--about-url")) - .addLauncher(new Launcher("name", "path")) .addModules(args.get("--add-modules").split(",")) .appContent(args.get("--app-content").split(",")) .appImage(args.get("--app-image")) @@ -162,6 +194,35 @@ void testArguments() { } + @Test + void testCmdFiles() { + System.setOut(new PrintStream(outputStreamCaptor)); + var jpackage = new JpackageOperation().cmdFiles(new File("src/test/resources/jlink/options_verbose.txt"), + new File("src/test/resources/jlink/options_version.txt")); + assertDoesNotThrow(jpackage::execute); + var out = outputStreamCaptor.toString(); + assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); + } + + @Test + void testCmdFilesPath() { + System.setOut(new PrintStream(outputStreamCaptor)); + var jpackage = new JpackageOperation().cmdFiles(Path.of("src/test/resources/jlink/options_verbose.txt"), + Path.of("src/test/resources/jlink/options_version.txt")); + assertDoesNotThrow(jpackage::execute); + var out = outputStreamCaptor.toString(); + assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); + } + + @Test + void testCmdFilesVersion() { + System.setOut(new PrintStream(outputStreamCaptor)); + var jpackage = new JpackageOperation().cmdFiles("src/test/resources/jlink/options_version.txt"); + assertDoesNotThrow(jpackage::execute); + var out = outputStreamCaptor.toString(); + assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); + } + @Test void testCreatePackage() throws Exception { var tmpdir = Files.createTempDirectory("bld-jpackage-test").toFile(); @@ -196,13 +257,29 @@ void testCreatePackage() throws Exception { } @Test - void testCmdFiles() { - System.setOut(new PrintStream(outputStreamCaptor)); - var jpackage = new JpackageOperation().cmdFiles("src/test/resources/jlink/options_verbose.txt", - "src/test/resources/jlink/options_version.txt"); - assertDoesNotThrow(jpackage::execute); - var out = outputStreamCaptor.toString(); - assertTrue(out.matches("[\\d.]+[\\r\\n]+"), out); + void testDest() { + var options = new JpackageOptions().dest("foo"); + assertEquals("foo", options.get("--dest")); + options = options.dest(Path.of("bar")); + assertEquals("bar", options.get("--dest")); + + var foo = new File("foo"); + options.dest(foo); + assertEquals(foo.getAbsolutePath(), options.get("--dest")); + } + + @Test + void testFileAssociations() { + var options = new JpackageOptions().fileAssociations("foo", "bar"); + assertEquals("foo,bar", options.get("--file-associations")); + + options = options.fileAssociations(Path.of("bar"), Path.of("foo")); + assertEquals("bar,foo", options.get("--file-associations")); + + var foo = new File("foo"); + var bar = new File("bar"); + options.fileAssociations(foo, bar); + assertEquals(foo.getAbsolutePath() + ',' + bar.getAbsolutePath(), options.get("--file-associations")); } @Test @@ -212,14 +289,147 @@ void testHelp() { assertTrue(jpackage.toolArgs().isEmpty(), "args not empty"); } + @Test + void testIcon() { + var options = new JpackageOptions().icon("foo"); + assertEquals("foo", options.get("--icon")); + options = options.icon(Path.of("bar")); + assertEquals("bar", options.get("--icon")); + + var foo = new File("foo"); + options.icon(foo); + assertEquals(foo.getAbsolutePath(), options.get("--icon")); + } + + @Test + void testInput() { + var options = new JpackageOptions(); + + options.input("foo"); + assertEquals("foo", options.get("--input")); + options.input(Path.of("bar")); + assertEquals("bar", options.get("--input")); + + var foo = new File("foo"); + options.input(foo); + assertEquals(foo.getAbsolutePath(), options.get("--input")); + } + + @Test + void testInstallDir() { + var options = new JpackageOptions().installDir("foo"); + assertEquals("foo", options.get("--install-dir")); + options = options.installDir(Path.of("bar")); + assertEquals("bar", options.get("--install-dir")); + + var foo = new File("foo"); + options.installDir(foo); + assertEquals(foo.getAbsolutePath(), options.get("--install-dir")); + } + + @Test + void testLicenseFile() { + var options = new JpackageOptions().licenseFile("foo"); + assertEquals("foo", options.get("--license-file")); + options = options.licenseFile(Path.of("bar")); + assertEquals("bar", options.get("--license-file")); + + var foo = new File("foo"); + options.licenseFile(foo); + assertEquals(foo.getAbsolutePath(), options.get("--license-file")); + } + + @Test + void testMacDmgContent() { + var options = new JpackageOptions().macDmgContent("foo", "bar"); + assertEquals("foo,bar", options.get("--mac-dmg-content")); + + options = options.macDmgContent(Path.of("bar"), Path.of("foo")); + assertEquals("bar,foo", options.get("--mac-dmg-content")); + + var foo = new File("foo"); + var bar = new File("bar"); + options.macDmgContent(foo, bar); + assertEquals(foo.getAbsolutePath() + ',' + bar.getAbsolutePath(), options.get("--mac-dmg-content")); + } + + @Test + void testMacEntitlements() { + var options = new JpackageOptions().macEntitlements("foo"); + assertEquals("foo", options.get("--mac-entitlements")); + options = options.macEntitlements(Path.of("bar")); + assertEquals("bar", options.get("--mac-entitlements")); + + var foo = new File("foo"); + options.macEntitlements(foo); + assertEquals(foo.getAbsolutePath(), options.get("--mac-entitlements")); + } + + @Test + void testModule() { + var options = new JpackageOptions().module("name"); + assertEquals("name", options.get("--module")); + + options.module("name", "class"); + assertEquals("name:class", options.get("--module")); + } + + @Test + void testModulePath() { + var options = new JpackageOptions().modulePath("foo"); + assertEquals("foo", options.get("--module-path")); + options = options.modulePath(Path.of("bar")); + assertEquals("bar", options.get("--module-path")); + + var foo = new File("foo"); + options.modulePath(foo); + assertEquals(foo.getAbsolutePath(), options.get("--module-path")); + } + @Test void testNoArguments() { var jpackage = new JpackageOperation(); - assertTrue(jpackage.fileOptions().isEmpty(), "file options not empty"); + assertTrue(jpackage.cmdFiles().isEmpty(), "file options not empty"); assertTrue(jpackage.jpackageOptions().isEmpty(), "jpackage options not empty"); assertThrows(ExitStatusException.class, jpackage::execute); } + @Test + void testResourceDir() { + var options = new JpackageOptions().resourceDir("foo"); + assertEquals("foo", options.get("--resource-dir")); + options = options.resourceDir(Path.of("bar")); + assertEquals("bar", options.get("--resource-dir")); + + var foo = new File("foo"); + options.resourceDir(foo); + assertEquals(foo.getAbsolutePath(), options.get("--resource-dir")); + } + + @Test + void testRuntimeImage() { + var options = new JpackageOptions().runtimeImage("foo"); + assertEquals("foo", options.get("--runtime-image")); + options = options.runtimeImage(Path.of("bar")); + assertEquals("bar", options.get("--runtime-image")); + + var foo = new File("foo"); + options.runtimeImage(foo); + assertEquals(foo.getAbsolutePath(), options.get("--runtime-image")); + } + + @Test + void testTemp() { + var options = new JpackageOptions().temp("foo"); + assertEquals("foo", options.get("--temp")); + options = options.temp(Path.of("bar")); + assertEquals("bar", options.get("--temp")); + + var foo = new File("foo"); + options.temp(foo); + assertEquals(foo.getAbsolutePath(), options.get("--temp")); + } + @Test void testVersion() { System.setOut(new PrintStream(outputStreamCaptor)); From 5821022fee99e5f714349792edb034c5c5c6b607 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 25 Aug 2024 16:09:30 -0700 Subject: [PATCH 2/3] Fixed Jpackage main module specification --- src/main/java/rife/bld/operations/JmodOptions.java | 6 ++++++ src/main/java/rife/bld/operations/JpackageOptions.java | 2 +- .../java/rife/bld/operations/TestJpackageOperation.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/rife/bld/operations/JmodOptions.java b/src/main/java/rife/bld/operations/JmodOptions.java index 81ed4c3..64469a5 100644 --- a/src/main/java/rife/bld/operations/JmodOptions.java +++ b/src/main/java/rife/bld/operations/JmodOptions.java @@ -47,6 +47,7 @@ public JmodOptions cmds(String path) { * @param path the location * @return this map of options */ + @SuppressWarnings("UnusedReturnValue") public JmodOptions cmds(File path) { put("--cmds", path.getAbsolutePath()); return this; @@ -76,6 +77,7 @@ public JmodOptions cmds(Path path) { * @param compression the {@link ZipCompression compression} level * @return this map of options */ + @SuppressWarnings("UnusedReturnValue") public JmodOptions compress(ZipCompression compression) { put("--compress", compression.level); return this; @@ -237,6 +239,7 @@ public JmodOptions headerFiles(String path) { * @param path the location * @return this map of options */ + @SuppressWarnings("UnusedReturnValue") public JmodOptions headerFiles(File path) { put("--header-files", path.getAbsolutePath()); return this; @@ -270,6 +273,7 @@ public JmodOptions legalNotices(String path) { * @param path the location * @return this map of options */ + @SuppressWarnings("UnusedReturnValue") public JmodOptions legalNotices(File path) { put("--legal-notices", path.getAbsolutePath()); return this; @@ -303,6 +307,7 @@ public JmodOptions libs(String path) { * @param path the location * @return this map of options */ + @SuppressWarnings("UnusedReturnValue") public JmodOptions libs(File path) { put("--libs", path.getAbsolutePath()); return this; @@ -347,6 +352,7 @@ public JmodOptions manPages(String path) { * @param path the location * @return this map of options */ + @SuppressWarnings("UnusedReturnValue") public JmodOptions manPages(File path) { put("--man-pages", path.getAbsolutePath()); return this; diff --git a/src/main/java/rife/bld/operations/JpackageOptions.java b/src/main/java/rife/bld/operations/JpackageOptions.java index bc33f90..c802492 100644 --- a/src/main/java/rife/bld/operations/JpackageOptions.java +++ b/src/main/java/rife/bld/operations/JpackageOptions.java @@ -779,7 +779,7 @@ public JpackageOptions module(String name) { */ @SuppressWarnings("JavadocDeclaration") public JpackageOptions module(String name, String mainClass) { - put("--module-name", name + "/" + mainClass); + put("--module", name + "/" + mainClass); return this; } diff --git a/src/test/java/rife/bld/operations/TestJpackageOperation.java b/src/test/java/rife/bld/operations/TestJpackageOperation.java index 8dd5061..4d317ce 100644 --- a/src/test/java/rife/bld/operations/TestJpackageOperation.java +++ b/src/test/java/rife/bld/operations/TestJpackageOperation.java @@ -371,7 +371,7 @@ void testModule() { assertEquals("name", options.get("--module")); options.module("name", "class"); - assertEquals("name:class", options.get("--module")); + assertEquals("name/class", options.get("--module")); } @Test From 0b9581cf125554776b993ff22bbb05837e064604 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 25 Aug 2024 18:46:15 -0700 Subject: [PATCH 3/3] Made paths specifications absolute --- .../rife/bld/operations/JlinkOperation.java | 3 +- .../rife/bld/operations/JlinkOptions.java | 4 +- .../rife/bld/operations/JmodOperation.java | 4 +- .../java/rife/bld/operations/JmodOptions.java | 16 +- .../bld/operations/JpackageOperation.java | 4 +- .../rife/bld/operations/JpackageOptions.java | 29 +-- .../bld/operations/TestJlinkOperation.java | 26 +-- .../bld/operations/TestJmodOperation.java | 108 ++++++---- .../bld/operations/TestJpackageOperation.java | 192 ++++++++++-------- 9 files changed, 219 insertions(+), 167 deletions(-) diff --git a/src/main/java/rife/bld/operations/JlinkOperation.java b/src/main/java/rife/bld/operations/JlinkOperation.java index 1adc9ef..50ab932 100644 --- a/src/main/java/rife/bld/operations/JlinkOperation.java +++ b/src/main/java/rife/bld/operations/JlinkOperation.java @@ -26,7 +26,6 @@ public JlinkOperation() { super("jlink"); } - /** * Read options and/or mode from file(s). * @@ -56,7 +55,7 @@ public JlinkOperation cmdFiles(File... file) { * @return this operation instance */ public JlinkOperation cmdFiles(Path... file) { - cmdFiles_.addAll(Arrays.stream(file).map(Path::toString).toList()); + cmdFiles_.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList()); return this; } diff --git a/src/main/java/rife/bld/operations/JlinkOptions.java b/src/main/java/rife/bld/operations/JlinkOptions.java index e7f8d44..f358ad1 100644 --- a/src/main/java/rife/bld/operations/JlinkOptions.java +++ b/src/main/java/rife/bld/operations/JlinkOptions.java @@ -187,7 +187,7 @@ public JlinkOptions modulePath(File path) { * @return this map of options */ public JlinkOptions modulePath(Path path) { - put("--module-path", path.toString()); + put("--module-path", path.toFile().getAbsolutePath()); return this; } @@ -250,7 +250,7 @@ public JlinkOptions output(File path) { * @return this map of options */ public JlinkOptions output(Path path) { - put("--output", path.toString()); + put("--output", path.toFile().getAbsolutePath()); return this; } diff --git a/src/main/java/rife/bld/operations/JmodOperation.java b/src/main/java/rife/bld/operations/JmodOperation.java index cf36fc7..ae68688 100644 --- a/src/main/java/rife/bld/operations/JmodOperation.java +++ b/src/main/java/rife/bld/operations/JmodOperation.java @@ -65,7 +65,7 @@ public JmodOperation cmdFiles(File... file) { * @return this operation instance */ public JmodOperation cmdFiles(Path... file) { - cmdFiles.addAll(Arrays.stream(file).map(Path::toString).toList()); + cmdFiles.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList()); return this; } @@ -129,7 +129,7 @@ public JmodOperation jmodFile(File file) { * @return this operation instance */ public JmodOperation jmodFile(Path file) { - jmodFile_ = file.toString(); + jmodFile_ = file.toFile().getAbsolutePath(); return this; } diff --git a/src/main/java/rife/bld/operations/JmodOptions.java b/src/main/java/rife/bld/operations/JmodOptions.java index 64469a5..d85a5eb 100644 --- a/src/main/java/rife/bld/operations/JmodOptions.java +++ b/src/main/java/rife/bld/operations/JmodOptions.java @@ -60,7 +60,7 @@ public JmodOptions cmds(File path) { * @return this map of options */ public JmodOptions cmds(Path path) { - put("--cmds", path.toString()); + put("--cmds", path.toFile().getAbsolutePath()); return this; } @@ -112,7 +112,7 @@ public JmodOptions config(File path) { * @return this map of options */ public JmodOptions config(Path path) { - put("--config", path.toString()); + put("--config", path.toFile().getAbsolutePath()); return this; } @@ -156,7 +156,7 @@ public JmodOptions dir(File path) { * @return this map of options */ public JmodOptions dir(Path path) { - put("--dir", path.toString()); + put("--dir", path.toFile().getAbsolutePath()); return this; } @@ -252,7 +252,7 @@ public JmodOptions headerFiles(File path) { * @return this map of options */ public JmodOptions headerFiles(Path path) { - put("--header-files", path.toString()); + put("--header-files", path.toFile().getAbsolutePath()); return this; } @@ -286,7 +286,7 @@ public JmodOptions legalNotices(File path) { * @return this map of options */ public JmodOptions legalNotices(Path path) { - put("--legal-notices", path.toString()); + put("--legal-notices", path.toFile().getAbsolutePath()); return this; } @@ -320,7 +320,7 @@ public JmodOptions libs(File path) { * @return this map of options */ public JmodOptions libs(Path path) { - put("--libs", path.toString()); + put("--libs", path.toFile().getAbsolutePath()); return this; } @@ -365,7 +365,7 @@ public JmodOptions manPages(File path) { * @return this map of options */ public JmodOptions manPages(Path path) { - put("--man-pages", path.toString()); + put("--man-pages", path.toFile().getAbsolutePath()); return this; } @@ -398,7 +398,7 @@ public JmodOptions modulePath(File path) { * @return this map of options */ public JmodOptions modulePath(Path path) { - put("--module-path", path.toString()); + put("--module-path", path.toFile().getAbsolutePath()); return this; } diff --git a/src/main/java/rife/bld/operations/JpackageOperation.java b/src/main/java/rife/bld/operations/JpackageOperation.java index e7a1286..9e2ff76 100644 --- a/src/main/java/rife/bld/operations/JpackageOperation.java +++ b/src/main/java/rife/bld/operations/JpackageOperation.java @@ -60,7 +60,7 @@ public JpackageOperation cmdFiles(File... file) { * @return this operation instance */ public JpackageOperation cmdFiles(Path... file) { - cmdFiles_.addAll(Arrays.stream(file).map(Path::toString).toList()); + cmdFiles_.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList()); return this; } @@ -147,7 +147,7 @@ public Launcher(String name, File path) { } public Launcher(String name, Path path) { - this(name, path.toString()); + this(name, path.toFile().getAbsolutePath()); } } } diff --git a/src/main/java/rife/bld/operations/JpackageOptions.java b/src/main/java/rife/bld/operations/JpackageOptions.java index c802492..e4e40e3 100644 --- a/src/main/java/rife/bld/operations/JpackageOptions.java +++ b/src/main/java/rife/bld/operations/JpackageOptions.java @@ -86,7 +86,7 @@ public JpackageOptions appImage(File path) { */ @SuppressWarnings("UnusedReturnValue") public JpackageOptions appImage(Path path) { - put("--app-image", path.toString()); + put("--app-image", path.toFile().getAbsolutePath()); return this; } @@ -170,7 +170,7 @@ public JpackageOptions dest(File path) { * @return this map of options */ public JpackageOptions dest(Path path) { - put("--dest", path.toString()); + put("--dest", path.toFile().getAbsolutePath()); return this; } @@ -213,7 +213,8 @@ public JpackageOptions fileAssociations(File... path) { * @return this map of options */ public JpackageOptions fileAssociations(Path... path) { - put("--file-associations", String.join(",", Arrays.stream(path).map(Path::toString).toList())); + put("--file-associations", String.join(",", + Arrays.stream(path).map(Path::toFile).map(File::getAbsolutePath).toList())); return this; } @@ -247,7 +248,7 @@ public JpackageOptions icon(File path) { * @return this map of options */ public JpackageOptions icon(Path path) { - put("--icon", path.toString()); + put("--icon", path.toFile().getAbsolutePath()); return this; } @@ -286,7 +287,7 @@ public JpackageOptions input(File path) { * @return this map of options */ public JpackageOptions input(Path path) { - put("--input", path.toString()); + put("--input", path.toFile().getAbsolutePath()); return this; } @@ -320,7 +321,7 @@ public JpackageOptions installDir(File path) { * @return this map of options */ public JpackageOptions installDir(Path path) { - put("--install-dir", path.toString()); + put("--install-dir", path.toFile().getAbsolutePath()); return this; } @@ -398,7 +399,7 @@ public JpackageOptions licenseFile(File path) { * @return this map of options */ public JpackageOptions licenseFile(Path path) { - put("--license-file", path.toString()); + put("--license-file", path.toFile().getAbsolutePath()); return this; } @@ -573,7 +574,8 @@ public JpackageOptions macDmgContent(File... additionalContent) { * @return this map of options */ public JpackageOptions macDmgContent(Path... additionalContent) { - put("--mac-dmg-content", String.join(",", Arrays.stream(additionalContent).map(Path::toString).toList())); + put("--mac-dmg-content", String.join(",", + Arrays.stream(additionalContent).map(Path::toFile).map(File::getAbsolutePath).toList())); return this; } @@ -607,7 +609,7 @@ public JpackageOptions macEntitlements(File path) { * @return this map of options */ public JpackageOptions macEntitlements(Path path) { - put("--mac-entitlements", path.toString()); + put("--mac-entitlements", path.toFile().getAbsolutePath()); return this; } @@ -824,7 +826,8 @@ public JpackageOptions modulePath(File... path) { * @return this map of options */ public JpackageOptions modulePath(Path... path) { - put("--module-path", String.join(":", Arrays.stream(path).map(Path::toString).toList())); + put("--module-path", String.join(":", + Arrays.stream(path).map(Path::toFile).map(File::getAbsolutePath).toList())); return this; } @@ -888,7 +891,7 @@ public JpackageOptions resourceDir(File path) { * @return this map of options */ public JpackageOptions resourceDir(Path path) { - put("--resource-dir", path.toString()); + put("--resource-dir", path.toFile().getAbsolutePath()); return this; } @@ -943,7 +946,7 @@ public JpackageOptions runtimeImage(File path) { * @return this map of options */ public JpackageOptions runtimeImage(Path path) { - put("--runtime-image", path.toString()); + put("--runtime-image", path.toFile().getAbsolutePath()); return this; } @@ -1004,7 +1007,7 @@ public JpackageOptions temp(File path) { * @return this map of options */ public JpackageOptions temp(Path path) { - put("--temp", path.toString()); + put("--temp", path.toFile().getAbsolutePath()); return this; } diff --git a/src/test/java/rife/bld/operations/TestJlinkOperation.java b/src/test/java/rife/bld/operations/TestJlinkOperation.java index 66f4dfc..a42d74f 100644 --- a/src/test/java/rife/bld/operations/TestJlinkOperation.java +++ b/src/test/java/rife/bld/operations/TestJlinkOperation.java @@ -158,15 +158,16 @@ void testHelp() { @Test void testModulePath() { var options = new JlinkOptions(); - options.modulePath("foo"); assertEquals("foo", options.get("--module-path")); - options.modulePath(Path.of("bar")); - assertEquals("bar", options.get("--module-path")); - var foo = new File("foo"); - options.modulePath(foo); - assertEquals(foo.getAbsolutePath(), options.get("--module-path")); + var barPath = Path.of("bar"); + options.modulePath(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--module-path")); + + var fooFile = new File("foo"); + options.modulePath(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--module-path")); } @Test @@ -180,15 +181,16 @@ void testNoArguments() { @Test void testOutput() { var options = new JlinkOptions(); - options.output("foo"); assertEquals("foo", options.get("--output")); - options.output(Path.of("bar")); - assertEquals("bar", options.get("--output")); - var foo = new File("foo"); - options.output(foo); - assertEquals(foo.getAbsolutePath(), options.get("--output")); + var barPath = Path.of("bar"); + options.output(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--output")); + + var fooFile = new File("foo"); + options.output(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--output")); } @Test diff --git a/src/test/java/rife/bld/operations/TestJmodOperation.java b/src/test/java/rife/bld/operations/TestJmodOperation.java index 1d4b036..54d79f8 100644 --- a/src/test/java/rife/bld/operations/TestJmodOperation.java +++ b/src/test/java/rife/bld/operations/TestJmodOperation.java @@ -121,24 +121,28 @@ void testCmdFilesPath() { void testCmds() { var options = new JmodOptions().cmds("foo"); assertEquals("foo", options.get("--cmds")); - options = options.cmds(Path.of("bar")); - assertEquals("bar", options.get("--cmds")); - var foo = new File("foo"); - options.cmds(foo); - assertEquals(foo.getAbsolutePath(), options.get("--cmds")); + var barPath = Path.of("bar"); + options = options.cmds(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--cmds")); + + var fooFile = new File("foo"); + options.cmds(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--cmds")); } @Test void testConfig() { var options = new JmodOptions().config("foo"); assertEquals("foo", options.get("--config")); - options = options.config(Path.of("bar")); - assertEquals("bar", options.get("--config")); - var foo = new File("foo"); - options.config(foo); - assertEquals(foo.getAbsolutePath(), options.get("--config")); + var barPath = Path.of("bar"); + options = options.config(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--config")); + + var fooFile = new File("foo"); + options.config(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--config")); } @Test @@ -167,12 +171,14 @@ void testCreate() throws IOException { void testDir() { var options = new JmodOptions().dir("foo"); assertEquals("foo", options.get("--dir")); - options = options.dir(Path.of("bar")); - assertEquals("bar", options.get("--dir")); - var foo = new File("foo"); - options.dir(foo); - assertEquals(foo.getAbsolutePath(), options.get("--dir")); + var barPath = Path.of("bar"); + options = options.dir(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--dir")); + + var fooFile = new File("foo"); + options.dir(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--dir")); } @Test @@ -215,12 +221,14 @@ void testExecute() throws IOException { void testHeaderFiles() { var options = new JmodOptions().headerFiles("foo"); assertEquals("foo", options.get("--header-files")); - options = options.headerFiles(Path.of("bar")); - assertEquals("bar", options.get("--header-files")); - var foo = new File("foo"); - options.headerFiles(foo); - assertEquals(foo.getAbsolutePath(), options.get("--header-files")); + var barPath = Path.of("bar"); + options = options.headerFiles(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--header-files")); + + var fooFile = new File("foo"); + options.headerFiles(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--header-files")); } @Test @@ -234,60 +242,70 @@ void testHelp() { void testJmodFile() { var op = new JmodOperation().jmodFile("foo"); assertEquals("foo", op.jmodFile()); - op = op.jmodFile(Path.of("bar")); - assertEquals("bar", op.jmodFile()); - var foo = new File("foo"); - op.jmodFile(foo); - assertEquals(foo.getAbsolutePath(), op.jmodFile()); + var barPath = Path.of("bar"); + op = op.jmodFile(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), op.jmodFile()); + + var fooFile = new File("foo"); + op.jmodFile(fooFile); + assertEquals(fooFile.getAbsolutePath(), op.jmodFile()); } @Test void testLegalNotices() { var options = new JmodOptions().legalNotices("foo"); assertEquals("foo", options.get("--legal-notices")); - options = options.legalNotices(Path.of("bar")); - assertEquals("bar", options.get("--legal-notices")); - var foo = new File("foo"); - options.legalNotices(foo); - assertEquals(foo.getAbsolutePath(), options.get("--legal-notices")); + var barPath = Path.of("bar"); + options = options.legalNotices(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--legal-notices")); + + var fooFile = new File("foo"); + options.legalNotices(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--legal-notices")); } @Test void testLibs() { var options = new JmodOptions().libs("foo"); assertEquals("foo", options.get("--libs")); - options = options.libs(Path.of("bar")); - assertEquals("bar", options.get("--libs")); - var foo = new File("foo"); - options.libs(foo); - assertEquals(foo.getAbsolutePath(), options.get("--libs")); + var barPath = Path.of("bar"); + options = options.libs(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--libs")); + + var fooFile = new File("foo"); + options.libs(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--libs")); } @Test void testManPages() { var options = new JmodOptions().manPages("foo"); assertEquals("foo", options.get("--man-pages")); - options = options.manPages(Path.of("bar")); - assertEquals("bar", options.get("--man-pages")); - var foo = new File("foo"); - options.manPages(foo); - assertEquals(foo.getAbsolutePath(), options.get("--man-pages")); + var barPath = Path.of("bar"); + options = options.manPages(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--man-pages")); + + var fooFile = new File("foo"); + options.manPages(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--man-pages")); } @Test void testModulePath() { var options = new JmodOptions().modulePath("foo"); assertEquals("foo", options.get("--module-path")); - options = options.modulePath(Path.of("bar")); - assertEquals("bar", options.get("--module-path")); - var foo = new File("foo"); - options.modulePath(foo); - assertEquals(foo.getAbsolutePath(), options.get("--module-path")); + var barPath = Path.of("bar"); + options = options.modulePath(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--module-path")); + + var fooFile = new File("foo"); + options.modulePath(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--module-path")); } @Test diff --git a/src/test/java/rife/bld/operations/TestJpackageOperation.java b/src/test/java/rife/bld/operations/TestJpackageOperation.java index 4d317ce..f81a822 100644 --- a/src/test/java/rife/bld/operations/TestJpackageOperation.java +++ b/src/test/java/rife/bld/operations/TestJpackageOperation.java @@ -33,32 +33,35 @@ public void tearDown() { void testAddLauncher() { var op = new JpackageOperation(); - var foo = new Launcher("foo-name", "foo-path"); - var bar = new Launcher("bar-name", Path.of("bar-path")); - assertEquals(bar.name(), "bar-name"); - assertEquals(bar.path(), "bar-path"); - - var f = new File("foo/bar"); - var foobar = new Launcher("foobar", f); - assertEquals(foobar.name(), "foobar"); - assertEquals(foobar.path(), f.getAbsolutePath()); - - op = op.addLauncher(foo); - assertTrue(op.launchers().contains(foo), "foo not found"); - op.addLauncher(bar); - assertTrue(op.launchers().contains(bar), "bar not found"); + var fooLauncher = new Launcher("foo-name", "foo-path"); + var barPath = Path.of("bar-path"); + var barLauncher = new Launcher("bar-name", barPath); + assertEquals("bar-name", barLauncher.name()); + assertEquals(barPath.toFile().getAbsolutePath(), barLauncher.path()); + + var fooFile = new File("foo/bar"); + var foobarLauncher = new Launcher("foobar", fooFile); + assertEquals("foobar", foobarLauncher.name()); + assertEquals(fooFile.getAbsolutePath(), foobarLauncher.path()); + + op = op.addLauncher(fooLauncher); + assertTrue(op.launchers().contains(fooLauncher), "foo not found"); + op.addLauncher(barLauncher); + assertTrue(op.launchers().contains(barLauncher), "bar not found"); } @Test void testAppImage() { var options = new JpackageOptions().appImage("foo"); assertEquals("foo", options.get("--app-image")); - options.appImage(Path.of("bar")); - assertEquals("bar", options.get("--app-image")); - var foo = new File("foo"); - options = options.appImage(foo); - assertEquals(foo.getAbsolutePath(), options.get("--app-image")); + var barPath = Path.of("bar"); + options.appImage(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--app-image")); + + var fooFile = new File("foo"); + options = options.appImage(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--app-image")); } @Test @@ -260,12 +263,14 @@ void testCreatePackage() throws Exception { void testDest() { var options = new JpackageOptions().dest("foo"); assertEquals("foo", options.get("--dest")); - options = options.dest(Path.of("bar")); - assertEquals("bar", options.get("--dest")); - var foo = new File("foo"); - options.dest(foo); - assertEquals(foo.getAbsolutePath(), options.get("--dest")); + var barPath = Path.of("bar"); + options = options.dest(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--dest")); + + var fooFile = new File("foo"); + options.dest(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--dest")); } @Test @@ -273,13 +278,16 @@ void testFileAssociations() { var options = new JpackageOptions().fileAssociations("foo", "bar"); assertEquals("foo,bar", options.get("--file-associations")); - options = options.fileAssociations(Path.of("bar"), Path.of("foo")); - assertEquals("bar,foo", options.get("--file-associations")); + var barPath = Path.of("bar"); + var fooPath = Path.of("foo"); + options = options.fileAssociations(barPath, fooPath); + assertEquals(barPath.toFile().getAbsolutePath() + ',' + fooPath.toFile().getAbsolutePath(), + options.get("--file-associations")); - var foo = new File("foo"); - var bar = new File("bar"); - options.fileAssociations(foo, bar); - assertEquals(foo.getAbsolutePath() + ',' + bar.getAbsolutePath(), options.get("--file-associations")); + var fooFile = new File("foo"); + var barFile = new File("bar"); + options.fileAssociations(fooFile, barFile); + assertEquals(fooFile.getAbsolutePath() + ',' + barFile.getAbsolutePath(), options.get("--file-associations")); } @Test @@ -293,12 +301,14 @@ void testHelp() { void testIcon() { var options = new JpackageOptions().icon("foo"); assertEquals("foo", options.get("--icon")); - options = options.icon(Path.of("bar")); - assertEquals("bar", options.get("--icon")); - var foo = new File("foo"); - options.icon(foo); - assertEquals(foo.getAbsolutePath(), options.get("--icon")); + var barPath = Path.of("bar"); + options = options.icon(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--icon")); + + var fooFile = new File("foo"); + options.icon(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--icon")); } @Test @@ -307,36 +317,42 @@ void testInput() { options.input("foo"); assertEquals("foo", options.get("--input")); - options.input(Path.of("bar")); - assertEquals("bar", options.get("--input")); - var foo = new File("foo"); - options.input(foo); - assertEquals(foo.getAbsolutePath(), options.get("--input")); + var barPath = Path.of("bar"); + options.input(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--input")); + + var fooFile = new File("foo"); + options.input(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--input")); } @Test void testInstallDir() { var options = new JpackageOptions().installDir("foo"); assertEquals("foo", options.get("--install-dir")); - options = options.installDir(Path.of("bar")); - assertEquals("bar", options.get("--install-dir")); - var foo = new File("foo"); - options.installDir(foo); - assertEquals(foo.getAbsolutePath(), options.get("--install-dir")); + var barPath = Path.of("bar"); + options = options.installDir(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--install-dir")); + + var fooFile = new File("foo"); + options.installDir(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--install-dir")); } @Test void testLicenseFile() { var options = new JpackageOptions().licenseFile("foo"); assertEquals("foo", options.get("--license-file")); - options = options.licenseFile(Path.of("bar")); - assertEquals("bar", options.get("--license-file")); - var foo = new File("foo"); - options.licenseFile(foo); - assertEquals(foo.getAbsolutePath(), options.get("--license-file")); + var barPath = Path.of("bar"); + options = options.licenseFile(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--license-file")); + + var fooFile = new File("foo"); + options.licenseFile(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--license-file")); } @Test @@ -344,25 +360,31 @@ void testMacDmgContent() { var options = new JpackageOptions().macDmgContent("foo", "bar"); assertEquals("foo,bar", options.get("--mac-dmg-content")); - options = options.macDmgContent(Path.of("bar"), Path.of("foo")); - assertEquals("bar,foo", options.get("--mac-dmg-content")); + var barPath = Path.of("bar"); + var fooPath = Path.of("foo"); - var foo = new File("foo"); - var bar = new File("bar"); - options.macDmgContent(foo, bar); - assertEquals(foo.getAbsolutePath() + ',' + bar.getAbsolutePath(), options.get("--mac-dmg-content")); + options = options.macDmgContent(barPath, fooPath); + assertEquals(barPath.toFile().getAbsolutePath() + ',' + fooPath.toFile().getAbsolutePath(), + options.get("--mac-dmg-content")); + + var fooFile = new File("foo"); + var barFile = new File("bar"); + options.macDmgContent(fooFile, barFile); + assertEquals(fooFile.getAbsolutePath() + ',' + barFile.getAbsolutePath(), options.get("--mac-dmg-content")); } @Test void testMacEntitlements() { var options = new JpackageOptions().macEntitlements("foo"); assertEquals("foo", options.get("--mac-entitlements")); - options = options.macEntitlements(Path.of("bar")); - assertEquals("bar", options.get("--mac-entitlements")); - var foo = new File("foo"); - options.macEntitlements(foo); - assertEquals(foo.getAbsolutePath(), options.get("--mac-entitlements")); + var barPath = Path.of("bar"); + options = options.macEntitlements(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--mac-entitlements")); + + var fooFile = new File("foo"); + options.macEntitlements(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--mac-entitlements")); } @Test @@ -378,12 +400,14 @@ void testModule() { void testModulePath() { var options = new JpackageOptions().modulePath("foo"); assertEquals("foo", options.get("--module-path")); - options = options.modulePath(Path.of("bar")); - assertEquals("bar", options.get("--module-path")); - var foo = new File("foo"); - options.modulePath(foo); - assertEquals(foo.getAbsolutePath(), options.get("--module-path")); + var barPath = Path.of("bar"); + options = options.modulePath(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--module-path")); + + var fooFile = new File("foo"); + options.modulePath(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--module-path")); } @Test @@ -398,36 +422,42 @@ void testNoArguments() { void testResourceDir() { var options = new JpackageOptions().resourceDir("foo"); assertEquals("foo", options.get("--resource-dir")); - options = options.resourceDir(Path.of("bar")); - assertEquals("bar", options.get("--resource-dir")); - var foo = new File("foo"); - options.resourceDir(foo); - assertEquals(foo.getAbsolutePath(), options.get("--resource-dir")); + var barPath = Path.of("bar"); + options = options.resourceDir(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--resource-dir")); + + var fooFile = new File("foo"); + options.resourceDir(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--resource-dir")); } @Test void testRuntimeImage() { var options = new JpackageOptions().runtimeImage("foo"); assertEquals("foo", options.get("--runtime-image")); - options = options.runtimeImage(Path.of("bar")); - assertEquals("bar", options.get("--runtime-image")); - var foo = new File("foo"); - options.runtimeImage(foo); - assertEquals(foo.getAbsolutePath(), options.get("--runtime-image")); + var barPath = Path.of("bar"); + options = options.runtimeImage(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--runtime-image")); + + var fooFile = new File("foo"); + options.runtimeImage(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--runtime-image")); } @Test void testTemp() { var options = new JpackageOptions().temp("foo"); assertEquals("foo", options.get("--temp")); - options = options.temp(Path.of("bar")); - assertEquals("bar", options.get("--temp")); - var foo = new File("foo"); - options.temp(foo); - assertEquals(foo.getAbsolutePath(), options.get("--temp")); + var barPath = Path.of("bar"); + options = options.temp(barPath); + assertEquals(barPath.toFile().getAbsolutePath(), options.get("--temp")); + + var fooFile = new File("foo"); + options.temp(fooFile); + assertEquals(fooFile.getAbsolutePath(), options.get("--temp")); } @Test