2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 00:07:12 -07:00

Merge pull request #48 from ethauvin/main

More cleanups to jlink, jmod & jpackage operations and options
This commit is contained in:
Geert Bevin 2024-08-26 10:09:29 -04:00 committed by GitHub
commit d68905b944
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 394 additions and 115 deletions

View file

@ -6,11 +6,13 @@ package rife.bld.operations;
import rife.bld.operations.exceptions.ExitStatusException; import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -67,25 +69,23 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
/** /**
* Adds arguments to pass to the tool. * Adds arguments to pass to the tool.
* *
* @param arg one or more argument * @param args tbe list of arguments
* @return this operation * @return this operation
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings({"unchecked"})
public T toolArgs(String... arg) { public T toolArgs(List<String> args) {
toolArgs(List.of(arg)); toolArgs_.addAll(args);
return (T) this; return (T) this;
} }
/** /**
* Adds arguments to pass to the tool. * Adds arguments to pass to the tool.
* *
* @param args the argument to add * @param args one or more arguments
* @return this operation * @return this operation
*/ */
@SuppressWarnings({"unchecked", "UnusedReturnValue"}) public T toolArgs(String... args) {
public T toolArgs(List<String> args) { return toolArgs(List.of(args));
toolArgs_.addAll(args);
return (T) this;
} }
/** /**
@ -97,6 +97,28 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
return toolArgs_; return toolArgs_;
} }
/**
* Parses arguments to pass to the tool from the given files.
*
* @param files one or more files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFile(String... files) throws IOException {
return toolArgsFromFileStrings(List.of(files));
}
/**
* Parses arguments to pass to the tool from the given files.
*
* @param files one or more files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFile(Path... files) throws IOException {
return toolArgsFromFilePaths(List.of(files));
}
/** /**
* Parses arguments to pass to the tool from the given files. * Parses arguments to pass to the tool from the given files.
* *
@ -104,8 +126,41 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
* @return this operation instance * @return this operation instance
* @throws FileNotFoundException if a file cannot be found * @throws FileNotFoundException if a file cannot be found
*/ */
@SuppressWarnings({"unchecked", "UnusedReturnValue"}) public T toolArgsFromFile(List<File> files) throws IOException {
public T toolArgsFromFile(List<String> files) throws IOException { return toolArgsFromFileStrings(files.stream().map(File::getAbsolutePath).toList());
}
/**
* Parses arguments to pass to the tool from the given files.
*
* @param files one or more files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFile(File... files) throws IOException {
return toolArgsFromFile(List.of(files));
}
/**
* Parses arguments to pass to the tool from the given files.
*
* @param files the list of files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFilePaths(List<Path> files) throws IOException {
return toolArgsFromFileStrings(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList());
}
/**
* Parses arguments to pass to the tool from the given files.
*
* @param files the list of files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
@SuppressWarnings({"unchecked"})
public T toolArgsFromFileStrings(List<String> files) throws IOException {
var args = new ArrayList<String>(); var args = new ArrayList<String>();
for (var file : files) { for (var file : files) {

View file

@ -7,7 +7,6 @@ package rife.bld.operations;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -29,33 +28,63 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JlinkOperation cmdFiles(String... file) { public JlinkOperation cmdFiles(String... files) {
cmdFiles_.addAll(List.of(file)); return cmdFilesStrings(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(List<File> files) {
cmdFiles_.addAll(files.stream().map(File::getAbsolutePath).toList());
return this; return this;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JlinkOperation cmdFiles(File... file) { public JlinkOperation cmdFiles(File... files) {
cmdFiles_.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList()); return cmdFiles(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(Path... files) {
return cmdFilesPaths(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFilesPaths(List<Path> files) {
cmdFiles_.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList());
return this; return this;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JlinkOperation cmdFiles(Path... file) { public JlinkOperation cmdFilesStrings(List<String> files) {
cmdFiles_.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList()); cmdFiles_.addAll(files);
return this; return this;
} }
@ -69,19 +98,29 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
} }
/** /**
* Disable the plugin mentioned. * Disable the plugin(s) mentioned.
* *
* @param plugin the plugin name * @param plugins the plugin name(s)
* @return this map of options * @return this map of options
*/ */
public JlinkOperation disablePlugin(String... plugin) { public JlinkOperation disablePlugin(List<String> plugins) {
disabledPlugins_.addAll(List.of(plugin)); disabledPlugins_.addAll(plugins);
return this; return this;
} }
/**
* Disable the plugin(s) mentioned.
*
* @param plugins the plugin name(s)
* @return this map of options
*/
public JlinkOperation disablePlugin(String... plugins) {
return disablePlugin(List.of(plugins));
}
@Override @Override
public void execute() throws Exception { public void execute() throws Exception {
toolArgsFromFile(cmdFiles_); toolArgsFromFileStrings(cmdFiles_);
disabledPlugins_.forEach(plugin -> toolArgs("--disable-plugin", plugin)); disabledPlugins_.forEach(plugin -> toolArgs("--disable-plugin", plugin));
toolArgs(jlinkOptions_); toolArgs(jlinkOptions_);
super.execute(); super.execute();

View file

@ -7,7 +7,7 @@ package rife.bld.operations;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
/** /**
@ -16,7 +16,7 @@ import java.util.List;
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a> * @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 2.1.0 * @since 2.1.0
*/ */
public class JlinkOptions extends HashMap<String, String> { public class JlinkOptions extends LinkedHashMap<String, String> {
/** /**
* All Modules Path. * All Modules Path.
*/ */
@ -28,12 +28,24 @@ public class JlinkOptions extends HashMap<String, String> {
* <p> * <p>
* Module can also be {@link #ALL_MODULE_PATH} * Module can also be {@link #ALL_MODULE_PATH}
* *
* @param modules one or more module * @param modules one or more modules
* @return this map of options
*/
public JlinkOptions addModules(List<String> modules) {
put("--add-modules", String.join(",", modules));
return this;
}
/**
* Root modules to resolve in addition to the initial modules.
* <p>
* Module can also be {@link #ALL_MODULE_PATH}
*
* @param modules one or more modules
* @return this map of options * @return this map of options
*/ */
public JlinkOptions addModules(String... modules) { public JlinkOptions addModules(String... modules) {
put("--add-modules", String.join(",", modules)); return addModules(List.of(modules));
return this;
} }
/** /**
@ -141,13 +153,22 @@ public class JlinkOptions extends HashMap<String, String> {
/** /**
* Limit the universe of observable modules. * Limit the universe of observable modules.
* *
* @param module one or more module * @param modules one or more modules
* @return this map of options * @return this map of options
*/ */
public JlinkOptions limitModule(String... module) { public JlinkOptions limitModule(List<String> modules) {
put("--limit-modules", String.join(",", module)); put("--limit-modules", String.join(",", modules));
return this; return this;
} }
/**
* Limit the universe of observable modules.
*
* @param modules one or more modules
* @return this map of options
*/
public JlinkOptions limitModule(String... modules) {
return limitModule(List.of(modules));
}
/** /**
* Module path. * Module path.
@ -304,14 +325,24 @@ public class JlinkOptions extends HashMap<String, String> {
/** /**
* Suggest providers that implement the given service types from the module path. * Suggest providers that implement the given service types from the module path.
* *
* @param name one or more provider name * @param names one or more provider names
* @return this map of options * @return this map of options
*/ */
public JlinkOptions suggestProviders(String... name) { public JlinkOptions suggestProviders(List<String> names) {
put("--suggest-providers", String.join(",", name)); put("--suggest-providers", String.join(",", names));
return this; return this;
} }
/**
* Suggest providers that implement the given service types from the module path.
*
* @param names one or more provider names
* @return this map of options
*/
public JlinkOptions suggestProviders(String... names) {
return suggestProviders(List.of(names));
}
public List<String> toList() { public List<String> toList() {
var list = new ArrayList<String>(); var list = new ArrayList<String>();
forEach((k, v) -> { forEach((k, v) -> {

View file

@ -36,36 +36,57 @@ public class JmodOperation extends AbstractToolProviderOperation<JmodOperation>
return cmdFiles; return cmdFiles;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JmodOperation cmdFiles(String... file) { public JmodOperation cmdFiles(String... files) {
cmdFiles.addAll(List.of(file)); return cmdFilesStrings(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JmodOperation cmdFiles(File... files) {
cmdFiles.addAll(Arrays.stream(files).map(File::getAbsolutePath).toList());
return this; return this;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JmodOperation cmdFiles(File... file) { public JmodOperation cmdFiles(Path... files) {
cmdFiles.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList()); return cmdFilesPaths(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JmodOperation cmdFilesPaths(List<Path> files) {
cmdFiles.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList());
return this; return this;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JmodOperation cmdFiles(Path... file) { public JmodOperation cmdFilesStrings(List<String> files) {
cmdFiles.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList()); cmdFiles.addAll(files);
return this; return this;
} }
@ -75,7 +96,7 @@ public class JmodOperation extends AbstractToolProviderOperation<JmodOperation>
toolArgs(operationMode_.mode); toolArgs(operationMode_.mode);
} }
toolArgsFromFile(cmdFiles); toolArgsFromFileStrings(cmdFiles);
toolArgs(jmodOptions_); toolArgs(jmodOptions_);
if (jmodFile_ != null) { if (jmodFile_ != null) {
@ -129,8 +150,7 @@ public class JmodOperation extends AbstractToolProviderOperation<JmodOperation>
* @return this operation instance * @return this operation instance
*/ */
public JmodOperation jmodFile(Path file) { public JmodOperation jmodFile(Path file) {
jmodFile_ = file.toFile().getAbsolutePath(); return jmodFile(file.toFile());
return this;
} }
/** /**

View file

@ -10,7 +10,8 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.LinkedHashMap;
import java.util.List;
/** /**
* Options for jmod tool. * Options for jmod tool.
@ -18,7 +19,7 @@ import java.util.HashMap;
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a> * @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 2.1.0 * @since 2.1.0
*/ */
public class JmodOptions extends HashMap<String, String> { public class JmodOptions extends LinkedHashMap<String, String> {
/** /**
* Application jar files|dir containing classes. * Application jar files|dir containing classes.
* *
@ -187,12 +188,12 @@ public class JmodOptions extends HashMap<String, String> {
/** /**
* Exclude files matching the supplied pattern list. * Exclude files matching the supplied pattern list.
* *
* @param pattern one or more pattern * @param patterns one or more patterns
* @return the map of options * @return the map of options
*/ */
public JmodOptions exclude(FilePattern... pattern) { public JmodOptions exclude(List<FilePattern> patterns) {
var args = new ArrayList<String>(); var args = new ArrayList<String>();
for (var p : pattern) { for (var p : patterns) {
if (p.type == FilePatternType.GLOB) { if (p.type == FilePatternType.GLOB) {
args.add("glob:" + p.pattern); args.add("glob:" + p.pattern);
} else if (p.type == FilePatternType.REGEX) { } else if (p.type == FilePatternType.REGEX) {
@ -203,6 +204,16 @@ public class JmodOptions extends HashMap<String, String> {
return this; return this;
} }
/**
* Exclude files matching the supplied pattern list.
*
* @param patterns one or more patterns
* @return the map of options
*/
public JmodOptions exclude(FilePattern... patterns) {
return exclude(List.of(patterns));
}
/** /**
* Compute and record hashes to tie a packaged module with modules matching the given regular expression pattern and * Compute and record hashes to tie a packaged module with modules matching the given regular expression pattern and
* depending upon it directly or indirectly. The hashes are recorded in the JMOD file being created, or a JMOD file * depending upon it directly or indirectly. The hashes are recorded in the JMOD file being created, or a JMOD file

View file

@ -7,7 +7,6 @@ package rife.bld.operations;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -34,44 +33,89 @@ public class JpackageOperation extends AbstractToolProviderOperation<JpackageOpe
* Additional alternative launchers can be built using this option, and this option can be used to build multiple * Additional alternative launchers can be built using this option, and this option can be used to build multiple
* additional launchers. * additional launchers.
* *
* @param launcher one or more {@link JpackageOperation.Launcher} * @param launchers one or more {@link Launcher launchers}
* @return this operation instance * @return this operation instance
*/ */
public JpackageOperation addLauncher(Launcher... launcher) { public JpackageOperation addLauncher(List<Launcher> launchers) {
launchers_.addAll(Arrays.asList(launcher)); launchers_.addAll(launchers);
return this;
}
/**
* List of application launchers.
* <p>
* The main application launcher will be built from the command line options.
* <p>
* Additional alternative launchers can be built using this option, and this option can be used to build multiple
* additional launchers.
*
* @param launchers one or more {@link Launcher launchers}
* @return this operation instance
*/
public JpackageOperation addLauncher(Launcher... launchers) {
return addLauncher(List.of(launchers));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JpackageOperation cmdFiles(List<File> files) {
cmdFiles_.addAll(files.stream().map(File::getAbsolutePath).toList());
return this; return this;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JpackageOperation cmdFiles(File... file) { public JpackageOperation cmdFiles(File... files) {
cmdFiles_.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList()); return cmdFiles(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JpackageOperation cmdFiles(Path... files) {
return cmdFilesPaths(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JpackageOperation cmdFiles(String... files) {
return cmdFilesStrings(List.of(files));
}
/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JpackageOperation cmdFilesPaths(List<Path> files) {
cmdFiles_.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList());
return this; return this;
} }
/** /**
* Read options and/or mode from file(s). * Read options and/or mode from file(s).
* *
* @param file one or more file * @param files one or more files
* @return this operation instance * @return this operation instance
*/ */
public JpackageOperation cmdFiles(Path... file) { public JpackageOperation cmdFilesStrings(List<String> files) {
cmdFiles_.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList()); cmdFiles_.addAll(files);
return this;
}
/**
* Read options and/or mode from file(s).
*
* @param file one or more file
* @return this operation instance
*/
public JpackageOperation cmdFiles(String... file) {
cmdFiles_.addAll(List.of(file));
return this; return this;
} }
@ -147,7 +191,7 @@ public class JpackageOperation extends AbstractToolProviderOperation<JpackageOpe
} }
public Launcher(String name, Path path) { public Launcher(String name, Path path) {
this(name, path.toFile().getAbsolutePath()); this(name, path.toFile());
} }
} }
} }

View file

@ -6,8 +6,7 @@ package rife.bld.operations;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays; import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
@ -16,7 +15,7 @@ import java.util.List;
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a> * @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 2.1.0 * @since 2.1.0
*/ */
public class JpackageOptions extends HashMap<String, String> { public class JpackageOptions extends LinkedHashMap<String, String> {
/** /**
* URL of the application's home page. * URL of the application's home page.
* *
@ -36,11 +35,39 @@ public class JpackageOptions extends HashMap<String, String> {
* (if {@link #module(String, String) module} is specified), or the default set of modules (if * (if {@link #module(String, String) module} is specified), or the default set of modules (if
* {@link #mainJar(String) mainJar} is specified) are used. * {@link #mainJar(String) mainJar} is specified) are used.
* *
* @param modules one or more module * @param modules one or more modules
* @return this map of options
*/
public JpackageOptions addModules(List<String> modules) {
put("--add-modules", String.join(",", modules));
return this;
}
/**
* List of modules to add.
* <p>
* This module list, along with the main module (if specified) will be passed to jlink as the
* {@link JlinkOptions#addModules(String...) addModules} argument. If not specified, either just the main module
* (if {@link #module(String, String) module} is specified), or the default set of modules (if
* {@link #mainJar(String) mainJar} is specified) are used.
*
* @param modules one or more modules
* @return this map of options * @return this map of options
*/ */
public JpackageOptions addModules(String... modules) { public JpackageOptions addModules(String... modules) {
put("--add-modules", String.join(",", modules)); return addModules(List.of(modules));
}
/**
* List of paths to files and/or directories to add to the application payload.
* <p>
* <b>Requires Java 20 or higher</b>.
*
* @param additionalContents one or more paths
* @return this map of options
*/
public JpackageOptions appContent(List<String> additionalContents) {
put("--app-content", String.join(",", additionalContents));
return this; return this;
} }
@ -49,12 +76,11 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* <b>Requires Java 20 or higher</b>. * <b>Requires Java 20 or higher</b>.
* *
* @param additionalContent one or more path * @param additionalContents one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions appContent(String... additionalContent) { public JpackageOptions appContent(String... additionalContents) {
put("--app-content", String.join(",", additionalContent)); return appContent(List.of(additionalContents));
return this;
} }
/** /**
@ -103,14 +129,24 @@ public class JpackageOptions extends HashMap<String, String> {
/** /**
* Command line arguments to pass to main class if no command line arguments are given to the launcher. * Command line arguments to pass to main class if no command line arguments are given to the launcher.
* *
* @param argument one or more argument * @param arguments one or more arguments
* @return this map of options * @return this map of options
*/ */
public JpackageOptions arguments(String... argument) { public JpackageOptions arguments(List<String> arguments) {
put("--arguments", String.join(" ", argument)); put("--arguments", String.join(" ", arguments));
return this; return this;
} }
/**
* Command line arguments to pass to main class if no command line arguments are given to the launcher.
*
* @param arguments one or more arguments
* @return this map of options
*/
public JpackageOptions arguments(String... arguments) {
return arguments(List.of(arguments));
}
/** /**
* Copyright of the application. * Copyright of the application.
* *
@ -180,8 +216,9 @@ public class JpackageOptions extends HashMap<String, String> {
* @param paths absolute paths or relative to the current directory * @param paths absolute paths or relative to the current directory
* @return this map of options * @return this map of options
*/ */
public JpackageOptions fileAssociations(String... paths) { public JpackageOptions fileAssociationsStrings(List<String> paths) {
return fileAssociationsStrings(List.of(paths)); put("--file-associations", String.join(",", paths));
return this;
} }
/** /**
@ -193,9 +230,8 @@ public class JpackageOptions extends HashMap<String, String> {
* @param paths absolute paths or relative to the current directory * @param paths absolute paths or relative to the current directory
* @return this map of options * @return this map of options
*/ */
public JpackageOptions fileAssociationsStrings(List<String> paths) { public JpackageOptions fileAssociations(String... paths) {
put("--file-associations", String.join(",", paths)); return fileAssociationsStrings(List.of(paths));
return this;
} }
/** /**
@ -234,8 +270,8 @@ public class JpackageOptions extends HashMap<String, String> {
* @param paths absolute paths or relative to the current directory * @param paths absolute paths or relative to the current directory
* @return this map of options * @return this map of options
*/ */
public JpackageOptions fileAssociations(Path... paths) { public JpackageOptions fileAssociationsPaths(List<Path> paths) {
return fileAssociationsPaths(List.of(paths)); return fileAssociations(paths.stream().map(Path::toFile).toList());
} }
/** /**
@ -247,8 +283,8 @@ public class JpackageOptions extends HashMap<String, String> {
* @param paths absolute paths or relative to the current directory * @param paths absolute paths or relative to the current directory
* @return this map of options * @return this map of options
*/ */
public JpackageOptions fileAssociationsPaths(List<Path> paths) { public JpackageOptions fileAssociations(Path... paths) {
return fileAssociations(paths.stream().map(Path::toFile).toList()); return fileAssociationsPaths(List.of(paths));
} }
/** /**
@ -316,6 +352,7 @@ public class JpackageOptions extends HashMap<String, String> {
* @param path absolute path or relative to the current directory * @param path absolute path or relative to the current directory
* @return this map of options * @return this map of options
*/ */
@SuppressWarnings("UnusedReturnValue")
public JpackageOptions input(Path path) { public JpackageOptions input(Path path) {
return input(path.toFile()); return input(path.toFile());
} }
@ -358,11 +395,21 @@ public class JpackageOptions extends HashMap<String, String> {
* @param options the options * @param options the options
* @return this map of options * @return this map of options
*/ */
public JpackageOptions javaOptions(String... options) { public JpackageOptions javaOptions(List<String> options) {
put("--java-options", String.join(" ", options)); put("--java-options", String.join(" ", options));
return this; return this;
} }
/**
* Options to pass to the Java runtime.
*
* @param options the options
* @return this map of options
*/
public JpackageOptions javaOptions(String... options) {
return javaOptions(List.of(options));
}
/** /**
* List of options to pass to jlink. * List of options to pass to jlink.
* <p> * <p>
@ -572,35 +619,66 @@ public class JpackageOptions extends HashMap<String, String> {
/** /**
* Include all the referenced content in the dmg. * Include all the referenced content in the dmg.
* *
* @param additionalContent one or more path * @param additionalContents one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions macDmgContent(String... additionalContent) { public JpackageOptions macDmgContent(String... additionalContents) {
put("--mac-dmg-content", String.join(",", additionalContent)); return macDmgContentStrings(List.of(additionalContents));
return this;
} }
/** /**
* Include all the referenced content in the dmg. * Include all the referenced content in the dmg.
* *
* @param additionalContent one or more path * @param additionalContents one or more paths
* @return this map of options * @return this map of options
*/ */
@SuppressWarnings("UnusedReturnValue") @SuppressWarnings("UnusedReturnValue")
public JpackageOptions macDmgContent(File... additionalContent) { public JpackageOptions macDmgContent(List<File> additionalContents) {
put("--mac-dmg-content", String.join(",", Arrays.stream(additionalContent).map(File::getAbsolutePath).toList())); put("--mac-dmg-content", String.join(",", additionalContents.stream().map(File::getAbsolutePath).toList()));
return this; return this;
} }
/** /**
* Include all the referenced content in the dmg. * Include all the referenced content in the dmg.
* *
* @param additionalContent one or more path * @param additionalContents one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions macDmgContent(Path... additionalContent) { @SuppressWarnings("UnusedReturnValue")
public JpackageOptions macDmgContent(File... additionalContents) {
return macDmgContent(List.of(additionalContents));
}
/**
* Include all the referenced content in the dmg.
*
* @param additionalContents one or more paths
* @return this map of options
*/
public JpackageOptions macDmgContentPaths(List<Path> additionalContents) {
put("--mac-dmg-content", String.join(",", put("--mac-dmg-content", String.join(",",
Arrays.stream(additionalContent).map(Path::toFile).map(File::getAbsolutePath).toList())); additionalContents.stream().map(Path::toFile).map(File::getAbsolutePath).toList()));
return this;
}
/**
* Include all the referenced content in the dmg.
*
* @param additionalContents one or more paths
* @return this map of options
*/
public JpackageOptions macDmgContentPaths(Path... additionalContents) {
return macDmgContentPaths(List.of(additionalContents));
}
/**
* Include all the referenced content in the dmg.
*
* @param additionalContents one or more paths
* @return this map of options
*/
public JpackageOptions macDmgContentStrings(List<String> additionalContents) {
put("--mac-dmg-content", String.join(",", additionalContents));
return this; return this;
} }
@ -815,7 +893,7 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* Each path is absolute or relative to the current directory. * Each path is absolute or relative to the current directory.
* *
* @param paths one or more path * @param paths one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions modulePath(String... paths) { public JpackageOptions modulePath(String... paths) {
@ -829,7 +907,7 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* Each path is absolute or relative to the current directory. * Each path is absolute or relative to the current directory.
* *
* @param paths one or more path * @param paths one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions modulePathStrings(List<String> paths) { public JpackageOptions modulePathStrings(List<String> paths) {
@ -844,9 +922,10 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* Each path is absolute or relative to the current directory. * Each path is absolute or relative to the current directory.
* *
* @param paths one or more path * @param paths one or more paths
* @return this map of options * @return this map of options
*/ */
@SuppressWarnings("UnusedReturnValue")
public JpackageOptions modulePath(File... paths) { public JpackageOptions modulePath(File... paths) {
return modulePath(List.of(paths)); return modulePath(List.of(paths));
} }
@ -858,7 +937,7 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* Each path is absolute or relative to the current directory. * Each path is absolute or relative to the current directory.
* *
* @param paths one or more path * @param paths one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions modulePath(List<File> paths) { public JpackageOptions modulePath(List<File> paths) {
@ -872,7 +951,7 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* Each path is absolute or relative to the current directory. * Each path is absolute or relative to the current directory.
* *
* @param paths one or more path * @param paths one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions modulePath(Path... paths) { public JpackageOptions modulePath(Path... paths) {
@ -886,7 +965,7 @@ public class JpackageOptions extends HashMap<String, String> {
* <p> * <p>
* Each path is absolute or relative to the current directory. * Each path is absolute or relative to the current directory.
* *
* @param paths one or more path * @param paths one or more paths
* @return this map of options * @return this map of options
*/ */
public JpackageOptions modulePathPaths(List<Path> paths) { public JpackageOptions modulePathPaths(List<Path> paths) {

View file

@ -363,7 +363,7 @@ public class TestJpackageOperation {
var barPath = Path.of("bar"); var barPath = Path.of("bar");
var fooPath = Path.of("foo"); var fooPath = Path.of("foo");
options = options.macDmgContent(barPath, fooPath); options = options.macDmgContentPaths(barPath, fooPath);
assertEquals(barPath.toFile().getAbsolutePath() + ',' + fooPath.toFile().getAbsolutePath(), assertEquals(barPath.toFile().getAbsolutePath() + ',' + fooPath.toFile().getAbsolutePath(),
options.get("--mac-dmg-content")); options.get("--mac-dmg-content"));