From 406b83bd82acad9de517d62b77f53ef5770fc79e Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 26 Aug 2024 14:25:15 -0700 Subject: [PATCH] Moved command files specification to the tool provider abstract operation --- .../AbstractToolProviderOperation.java | 148 ++++++++++-------- .../rife/bld/operations/JlinkOperation.java | 77 +-------- .../rife/bld/operations/JlinkOptions.java | 6 +- .../rife/bld/operations/JmodOperation.java | 69 +------- .../bld/operations/JpackageOperation.java | 75 +-------- .../rife/bld/operations/JpackageOptions.java | 6 +- .../bld/operations/TestJpackageOperation.java | 2 +- 7 files changed, 90 insertions(+), 293 deletions(-) diff --git a/src/main/java/rife/bld/operations/AbstractToolProviderOperation.java b/src/main/java/rife/bld/operations/AbstractToolProviderOperation.java index 0001298..6a6d40e 100644 --- a/src/main/java/rife/bld/operations/AbstractToolProviderOperation.java +++ b/src/main/java/rife/bld/operations/AbstractToolProviderOperation.java @@ -27,6 +27,7 @@ */ public abstract class AbstractToolProviderOperation> extends AbstractOperation> { + private final List cmdFiles_ = new ArrayList<>(); private final List toolArgs_ = new ArrayList<>(); private final String toolName_; @@ -39,6 +40,81 @@ public AbstractToolProviderOperation(String toolName) { toolName_ = toolName; } + /** + * Read options and/or mode from file(s). + * + * @param files one or more files + * @return this operation instance + */ + public T 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 + */ + @SuppressWarnings({"unchecked"}) + public T cmdFiles(List files) { + cmdFiles_.addAll(files.stream().map(File::getAbsolutePath).toList()); + return (T) this; + } + + /** + * Read options and/or mode from file(s). + * + * @param files one or more files + * @return this operation instance + */ + public T cmdFiles(File... files) { + return cmdFiles(List.of(files)); + } + + /** + * Read options and/or mode from file(s). + * + * @param files one or more files + * @return this operation instance + */ + public T cmdFiles(Path... files) { + return cmdFilesPaths(List.of(files)); + } + + /** + * Retrieves the list of files containing options or mode. + * + * @return the list of files + */ + public List cmdFiles() { + return cmdFiles_; + } + + /** + * Read options and/or mode from file(s). + * + * @param files one or more files + * @return this operation instance + */ + @SuppressWarnings({"unchecked"}) + public T cmdFilesPaths(List files) { + cmdFiles_.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList()); + return (T) this; + } + + /** + * Read options and/or mode from file(s). + * + * @param files one or more files + * @return this operation instance + */ + @SuppressWarnings({"unchecked"}) + public T cmdFilesStrings(List files) { + cmdFiles_.addAll(files); + return (T) this; + } + /** * Runs an instance of the tool. *

@@ -98,84 +174,20 @@ public List 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. - * - * @param files the list of files - * @return this operation instance - * @throws FileNotFoundException if a file cannot be found - */ - public T toolArgsFromFile(List 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 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. + * Parses arguments to pass to the tool from the {@link #cmdFiles() command 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 files) throws IOException { - var args = new ArrayList(); - - for (var file : files) { + protected void toolArgsFromFiles() throws IOException { + for (var file : cmdFiles_) { try (var reader = Files.newBufferedReader(Paths.get(file), Charset.defaultCharset())) { var tokenizer = new CommandLineTokenizer(reader); String token; while ((token = tokenizer.nextToken()) != null) { - args.add(token); + toolArgs_.add(token); } } } - - toolArgs(args); - - return (T) this; } /** diff --git a/src/main/java/rife/bld/operations/JlinkOperation.java b/src/main/java/rife/bld/operations/JlinkOperation.java index 498f5c0..654eeb1 100644 --- a/src/main/java/rife/bld/operations/JlinkOperation.java +++ b/src/main/java/rife/bld/operations/JlinkOperation.java @@ -4,8 +4,6 @@ */ package rife.bld.operations; -import java.io.File; -import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -17,7 +15,6 @@ * @since 2.1.0 */ public class JlinkOperation extends AbstractToolProviderOperation { - private final List cmdFiles_ = new ArrayList<>(); private final List disabledPlugins_ = new ArrayList<>(); private final JlinkOptions jlinkOptions_ = new JlinkOptions(); @@ -25,78 +22,6 @@ public JlinkOperation() { super("jlink"); } - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JlinkOperation 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 JlinkOperation cmdFiles(List files) { - cmdFiles_.addAll(files.stream().map(File::getAbsolutePath).toList()); - return this; - } - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JlinkOperation cmdFiles(File... files) { - 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 files) { - cmdFiles_.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList()); - return this; - } - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JlinkOperation cmdFilesStrings(List files) { - cmdFiles_.addAll(files); - return this; - } - - /** - * Retrieves the list of files containing options or mode. - * - * @return the list of files - */ - public List cmdFiles() { - return cmdFiles_; - } - /** * Disable the plugin(s) mentioned. * @@ -120,7 +45,7 @@ public JlinkOperation disablePlugin(String... plugins) { @Override public void execute() throws Exception { - toolArgsFromFileStrings(cmdFiles_); + toolArgsFromFiles(); disabledPlugins_.forEach(plugin -> toolArgs("--disable-plugin", plugin)); toolArgs(jlinkOptions_); super.execute(); diff --git a/src/main/java/rife/bld/operations/JlinkOptions.java b/src/main/java/rife/bld/operations/JlinkOptions.java index 6cef875..1bdb19f 100644 --- a/src/main/java/rife/bld/operations/JlinkOptions.java +++ b/src/main/java/rife/bld/operations/JlinkOptions.java @@ -174,7 +174,7 @@ public JlinkOptions limitModule(String... modules) { * 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. + * {@code java.base} module, the JDKs jmods directory will be added, if it exists. * * @param path the module path * @return this map of options @@ -188,7 +188,7 @@ public JlinkOptions modulePath(String path) { * 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. + * {@code java.base} module, the JDKs jmods directory will be added, if it exists. * * @param path the module path * @return this map of options @@ -201,7 +201,7 @@ public JlinkOptions modulePath(File path) { * 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. + * {@code java.base} module, the JDKs jmods directory will be added, if it exists. * * @param path the module path * @return this map of options diff --git a/src/main/java/rife/bld/operations/JmodOperation.java b/src/main/java/rife/bld/operations/JmodOperation.java index 34896bb..a2aa91e 100644 --- a/src/main/java/rife/bld/operations/JmodOperation.java +++ b/src/main/java/rife/bld/operations/JmodOperation.java @@ -6,9 +6,6 @@ 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; /** @@ -18,7 +15,6 @@ * @since 2.1.0 */ public class JmodOperation extends AbstractToolProviderOperation { - private final List cmdFiles = new ArrayList<>(); private final JmodOptions jmodOptions_ = new JmodOptions(); private String jmodFile_; private OperationMode operationMode_; @@ -27,76 +23,13 @@ public JmodOperation() { super("jmod"); } - /** - * Retrieves the list of files containing options or mode. - * - * @return the list of files - */ - public List cmdFiles() { - return cmdFiles; - } - - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JmodOperation 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 JmodOperation cmdFiles(File... files) { - cmdFiles.addAll(Arrays.stream(files).map(File::getAbsolutePath).toList()); - return this; - } - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JmodOperation 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 JmodOperation cmdFilesPaths(List files) { - cmdFiles.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList()); - return this; - } - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JmodOperation cmdFilesStrings(List files) { - cmdFiles.addAll(files); - return this; - } - @Override public void execute() throws Exception { if (operationMode_ != null) { toolArgs(operationMode_.mode); } - toolArgsFromFileStrings(cmdFiles); + toolArgsFromFiles(); toolArgs(jmodOptions_); if (jmodFile_ != null) { diff --git a/src/main/java/rife/bld/operations/JpackageOperation.java b/src/main/java/rife/bld/operations/JpackageOperation.java index d359505..07b87b8 100644 --- a/src/main/java/rife/bld/operations/JpackageOperation.java +++ b/src/main/java/rife/bld/operations/JpackageOperation.java @@ -17,7 +17,6 @@ * @since 2.1.0 */ public class JpackageOperation extends AbstractToolProviderOperation { - private final List cmdFiles_ = new ArrayList<>(); private final JpackageOptions jpackageOptions_ = new JpackageOptions(); private final List launchers_ = new ArrayList<>(); @@ -56,81 +55,9 @@ 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 files) { - cmdFiles_.addAll(files.stream().map(File::getAbsolutePath).toList()); - return this; - } - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JpackageOperation cmdFiles(File... files) { - 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 files) { - cmdFiles_.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList()); - return this; - } - - /** - * Read options and/or mode from file(s). - * - * @param files one or more files - * @return this operation instance - */ - public JpackageOperation cmdFilesStrings(List files) { - cmdFiles_.addAll(files); - 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()); + toolArgs(cmdFiles().stream().map(opt -> '@' + opt).toList()); for (var l : launchers_) { toolArgs("--add-launcher", l.name + '=' + l.path); } diff --git a/src/main/java/rife/bld/operations/JpackageOptions.java b/src/main/java/rife/bld/operations/JpackageOptions.java index 19122bf..feeb297 100644 --- a/src/main/java/rife/bld/operations/JpackageOptions.java +++ b/src/main/java/rife/bld/operations/JpackageOptions.java @@ -667,7 +667,7 @@ public JpackageOptions macDmgContentPaths(List additionalContents) { * @param additionalContents one or more paths * @return this map of options */ - public JpackageOptions macDmgContentPaths(Path... additionalContents) { + public JpackageOptions macDmgContent(Path... additionalContents) { return macDmgContentPaths(List.of(additionalContents)); } @@ -790,7 +790,7 @@ public JpackageOptions macSign(boolean sign) { } /** - * Team or user name portion in Apple signing identities. + * User or team name portion in Apple signing identities. *

* For direct control of the signing identity used to sign application images or installers use * {@link #macAppImageSignIdentity(String) macAppImageSignIdentity} and/or @@ -1254,7 +1254,7 @@ public JpackageOptions winMenuGroup(String menuGroup) { } /** - * Request to perform an install on a per-user basis. + * Request to perform an installation on a per-user basis. * * @param winPerUserInstall {@code true} for per-user install, {@code false} otherwise * @return this map of options diff --git a/src/test/java/rife/bld/operations/TestJpackageOperation.java b/src/test/java/rife/bld/operations/TestJpackageOperation.java index ed3df25..f81a822 100644 --- a/src/test/java/rife/bld/operations/TestJpackageOperation.java +++ b/src/test/java/rife/bld/operations/TestJpackageOperation.java @@ -363,7 +363,7 @@ void testMacDmgContent() { var barPath = Path.of("bar"); var fooPath = Path.of("foo"); - options = options.macDmgContentPaths(barPath, fooPath); + options = options.macDmgContent(barPath, fooPath); assertEquals(barPath.toFile().getAbsolutePath() + ',' + fooPath.toFile().getAbsolutePath(), options.get("--mac-dmg-content"));