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

Fixed handling of @filename in all tools

This commit is contained in:
Erik C. Thauvin 2024-08-02 14:23:22 -07:00
parent 0ad964ea4d
commit 002844861b
Signed by: erik
GPG key ID: 776702A6A2DA330E
11 changed files with 297 additions and 188 deletions

View file

@ -5,9 +5,12 @@
package rife.bld.operations;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/**
* Create run-time images using the jlink tool.
@ -16,8 +19,9 @@ import java.util.Map;
* @since 2.0.2
*/
public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation> {
private final JlinkOptions jlinkOptions_ = new JlinkOptions();
private final List<String> disabledPlugins_ = new ArrayList<>();
private final JlinkOptions jlinkOptions_ = new JlinkOptions();
private final List<String> options_ = new ArrayList<>();
public JlinkOperation() {
super("jlink");
@ -37,6 +41,8 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
@Override
public void execute() throws Exception {
disabledPlugins_.forEach(plugin -> addArg("--disable-plugin", plugin));
addArgs(jlinkOptions_);
addArgs(parseOptions());
super.execute();
}
@ -51,16 +57,6 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
return jlinkOptions_;
}
/**
* List available plugins.
*
* @return this operation instance
*/
public JlinkOperation listPlugins() {
addArgs("--list-plugins");
return this;
}
/**
* Provides a list of options to provide to the jlink tool.
* <p>
@ -73,4 +69,49 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
jlinkOptions_.putAll(options);
return this;
}
/**
* List available plugins.
*
* @return this operation instance
*/
public JlinkOperation listPlugins() {
addArgs("--list-plugins");
return this;
}
/**
* Read options and/or mode from a file.
*
* @param filename one or more file
* @return this operation instance
*/
public JlinkOperation options(String... filename) {
options_.addAll(List.of(filename));
return this;
}
/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> options() {
return options_;
}
// Shouldn't be needed, but for some reason jlink doesn't like @filename when called via ToolProvider
private List<String> parseOptions() throws FileNotFoundException {
var list = new ArrayList<String>();
for (var option : options_) {
try (var scanner = new Scanner(new File(option))) {
while (scanner.hasNext()) {
list.addAll(List.of(scanner.next().split(" ")));
}
}
}
return list;
}
}

View file

@ -15,9 +15,10 @@ import java.util.List;
* @since 2.0.2
*/
public class JlinkOptions extends HashMap<String, String> {
/**
/**ranran
* All Modules Path.
*/
@SuppressWarnings("unused")
public final static String ALL_MODULE_PATH = "ALL-MODULE-PATH";
/**
@ -48,22 +49,11 @@ public class JlinkOptions extends HashMap<String, String> {
return this;
}
/**
* Read options from file.
*
* @param filename the filename
* @return this map of options
*/
public JlinkOptions filename(String filename) {
put("@" + filename);
return this;
}
/**
* Compression to use in compressing resources.
* <p>
* Where {@link ZipCompression#ZIP_0 ZIP_0} provides no compression and {@link ZipCompression#ZIP_9 ZIP_9} provides the
* best compression.
* Where {@link ZipCompression#ZIP_0 ZIP_0} provides no compression and {@link ZipCompression#ZIP_9 ZIP_9} provides
* the best compression.
* <p>Default is {@link ZipCompression#ZIP_6 ZIP_6}
*
* @param compression the {@link ZipCompression compression} level
@ -110,6 +100,7 @@ public class JlinkOptions extends HashMap<String, String> {
* @param module the module
* @return this map of options
*/
@SuppressWarnings("UnusedReturnValue")
public JlinkOptions launcher(String name, String module) {
put("--launcher", name + "=" + module);
return this;
@ -268,7 +259,7 @@ public class JlinkOptions extends HashMap<String, String> {
}
/**
* Enable verbose tracing
* Enable verbose tracing.
*
* @param verbose {@code true} to enable verbose tracing, {@code false} otherwise.
* @return this map of options

View file

@ -7,6 +7,8 @@ package rife.bld.operations;
import rife.bld.operations.exceptions.ExitStatusException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
@ -17,6 +19,7 @@ import java.util.Map;
*/
public class JmodOperation extends AbstractToolProviderOperation<JmodOperation> {
private final JmodOptions jmodOptions_ = new JmodOptions();
private final List<String> options_ = new ArrayList<>();
private String jmodFile_;
private OperationMode operationMode_;
@ -98,6 +101,26 @@ public class JmodOperation extends AbstractToolProviderOperation<JmodOperation>
return this;
}
/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> options() {
return options_;
}
/**
* Read options and/or mode from a file.
*
* @param filename one or more file
* @return this operation instance
*/
public JmodOperation options(String... filename) {
options_.addAll(List.of(filename));
return this;
}
/**
* The operation modes.
*/

View file

@ -135,17 +135,6 @@ public class JmodOptions extends HashMap<String, String> {
return this;
}
/**
* Read options from the specified file.
*
* @param filename the filename
* @return this map of options
*/
public JmodOptions filename(String filename) {
put("@" + filename);
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.

View file

@ -5,6 +5,8 @@
package rife.bld.operations;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
@ -15,6 +17,7 @@ import java.util.Map;
*/
public class JpackageOperation extends AbstractToolProviderOperation<JpackageOperation> {
private final JpackageOptions jpackageOptions_ = new JpackageOptions();
private final List<String> options_ = new ArrayList<>();
public JpackageOperation() {
super("jpackage");
@ -23,9 +26,29 @@ public class JpackageOperation extends AbstractToolProviderOperation<JpackageOpe
@Override
public void execute() throws Exception {
addArgs(jpackageOptions_);
addArgs(options_.stream().map(opt -> '@' + opt).toList());
super.execute();
}
/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> options(){
return options_;
}
/**
* Read options and/or mode from a file.
*
* @param filename one or more file
* @return this operation instance
*/
public JpackageOperation options(String... filename) {
options_.addAll(List.of(filename));
return this;
}
/**
* Retrieves the list of options for the jpackage tool.
* <p>

View file

@ -25,17 +25,6 @@ public class JpackageOptions extends HashMap<String, String> {
return this;
}
/**
* Read options and/or mode from a file.
*
* @param filename the filename
* @return this map of options
*/
public JpackageOptions filename(String filename) {
put("@" + filename);
return this;
}
/**
* List of application launchers.
* <p>
@ -135,7 +124,9 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Path where generated output file is placed
* Path where generated output file is placed.
* <p>
* Defaults to the current working directory.
*
* @param path absolute path or relative to the current directory
* @return this map of options
@ -160,18 +151,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Options to pass to the Java runtime.
*
* @param options the options
* @return this map of options
*/
public JpackageOptions javaOptions(String... options) {
put("--java-options", String.join(" ", options));
return this;
}
/**
* Path of the icon of the application package/
* Path of the icon of the application package.
*
* @param path absolute path or relative to the current directory
* @return this map of options
@ -195,7 +175,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Absolute path of the installation directory of the application
* Absolute path of the installation directory of the application.
*
* @param path the absolute directory path
* @return this map of options
@ -205,6 +185,32 @@ public class JpackageOptions extends HashMap<String, String> {
return this;
}
/**
* Options to pass to the Java runtime.
*
* @param options the options
* @return this map of options
*/
public JpackageOptions javaOptions(String... options) {
put("--java-options", String.join(" ", options));
return this;
}
/**
* List of options to pass to jlink.
* <p>
* If not specified, defaults to {@link JlinkOptions#stripNativeCommands(boolean) stripNativeCommands}
* {@link JlinkOptions#stripDebug(boolean) stripDebug} {@link JlinkOptions#noManPages(boolean) noManPages}
* {@link JlinkOptions#noHeaderFiles(boolean) noHeaderFiles}.
*
* @param options the {@link JlinkOptions}
* @return this map of options
*/
public JpackageOptions jlinkOptions(JlinkOptions options) {
put("--jlink-options", String.join(" ", options.toList()));
return this;
}
/**
* Request to create an installer that will register the main application launcher as a background service-type
* application.
@ -222,37 +228,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* List of options to pass to jlink.
* <p>
* If not specified, defaults to {@link JlinkOptions#stripNativeCommands(boolean) stripNativeCommands}
* {@link JlinkOptions#stripDebug(boolean) stripDebug} {@link JlinkOptions#noManPages(boolean) noManPages}
* {@link JlinkOptions#noHeaderFiles(boolean) noHeaderFiles}.
*
* @param options the {@link JlinkOptions}
* @return this map of options
*/
public JpackageOptions jlinkOptions(JlinkOptions options) {
put("--jlink-options", String.join(" ", options.toList()));
return this;
}
/**
* Required packages or capabilities for the application.
*
* @param packageDeps {@code true} if required, {@code false} otherwise
* @return this map of options
*/
public JpackageOptions linuxPackageDeps(boolean packageDeps) {
if (packageDeps) {
put("--linux-package-deps");
} else {
remove("--linux-package-deps");
}
return this;
}
/**
* Path to the license file
* Path to the license file.
*
* @param path absolute path or relative to the current directory
* @return this map of options
@ -263,7 +239,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Group value of the RPM {@code <name>.spec} file or Section value of DEB control file
* Group value of the RPM {@code <name>.spec} file or Section value of DEB control file.
*
* @param appCategory the application category
* @return this map of options
@ -285,7 +261,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Maintainer for .deb package.
* Maintainer for {@code .deb} package.
*
* @param maintainer the maintainer
* @return this map of options
@ -307,16 +283,16 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Creates a shortcut for the application.
* Required packages or capabilities for the application.
*
* @param shortcut {@code true| to create a shortcut, {@code false} otherwise
* @param packageDeps {@code true} if required, {@code false} otherwise
* @return this map of options
*/
public JpackageOptions linuxShortcut(boolean shortcut) {
if (shortcut) {
put("--linux-shortcut");
public JpackageOptions linuxPackageDeps(boolean packageDeps) {
if (packageDeps) {
put("--linux-package-deps");
} else {
remove("--linux-shortcut");
remove("--linux-package-deps");
}
return this;
}
@ -333,7 +309,9 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Type of the license ({@code License: <value>} of the RPM .spec)
* Type of the license.
* <p>
* {@code License: <value>} of the RPM {@code .spec}
*
* @param licenseType the license type
* @return this map of options
@ -343,6 +321,21 @@ public class JpackageOptions extends HashMap<String, String> {
return this;
}
/**
* Creates a shortcut for the application.
*
* @param shortcut {@code true| to create a shortcut, {@code false} otherwise
* @return this map of options
*/
public JpackageOptions linuxShortcut(boolean shortcut) {
if (shortcut) {
put("--linux-shortcut");
} else {
remove("--linux-shortcut");
}
return this;
}
/**
* String used to construct {@code LSApplicationCategoryType} in application plist.
* <p>
@ -439,7 +432,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Name of the application as it appears in the Menu Bar
* Name of the application as it appears in the Menu Bar.
* <p>
* This can be different from the application name.
* <p>
@ -530,7 +523,8 @@ public class JpackageOptions extends HashMap<String, String> {
/**
* The main JAR of the application; containing the main class.
* <p>
* Either {@link #module(String, String) module} or {@link #mainJar(String) mainJar} option can be specified but not both.
* Either {@link #module(String, String) module} or {@link #mainJar(String) mainJar} option can be specified but
* not both.
*
* @param jar the path relative to the input path
* @return this map of options
@ -548,7 +542,8 @@ public class JpackageOptions extends HashMap<String, String> {
* <p>
* When this option is specified, the main module will be linked in the Java runtime image.
* <p>
* Either {@link #module(String, String) module} or {@link #mainJar(String) mainJar} option can be specified but not both.
* Either {@link #module(String, String) module} or {@link #mainJar(String) mainJar} option can be specified but
* not both.
*
* @param name the module name
* @return this map of options
@ -565,7 +560,8 @@ public class JpackageOptions extends HashMap<String, String> {
* <p>
* When this option is specified, the main module will be linked in the Java runtime image.
* <p>
* Either {@link #module(String, String) module} or {@link #mainJar(String) mainJar} option can be specified but not both.
* Either {@link #module(String, String) module} or {@link #mainJar(String) mainJar} option can be specified but
* not both.
*
* @param name the module name
* @param mainClass the main class
@ -577,16 +573,6 @@ public class JpackageOptions extends HashMap<String, String> {
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.
*
* @param key key with which the specified value is to be associated
*/
public void put(String key) {
put(key, null);
}
/**
* List of module paths.
* <p>
@ -598,7 +584,7 @@ public class JpackageOptions extends HashMap<String, String> {
* @return this map of options
*/
public JpackageOptions modulePath(String... path) {
put("--module-path", String.join(",", path));
put("--module-path", String.join(":", path));
return this;
}
@ -613,6 +599,16 @@ public class JpackageOptions extends HashMap<String, String> {
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.
*
* @param key key with which the specified value is to be associated
*/
public void put(String key) {
put(key, null);
}
/**
* Path to override jpackage resources.
* <p>
@ -677,6 +673,8 @@ public class JpackageOptions extends HashMap<String, String> {
/**
* The type of package to create.
* <p>
* If this option is not specified a platform dependent default type will be created.
*
* @param type the package type
* @return this map of options
@ -729,7 +727,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Adds a dialog to enable the user to choose a directory in which the product is installed..
* Adds a dialog to enable the user to choose a directory in which the product is installed.
*
* @param winDirChooser {@code true} to let the user choose a directory, {@code false} otherwise
* @return this map of options
@ -867,7 +865,7 @@ public class JpackageOptions extends HashMap<String, String> {
}
/**
* Name of launcher, and a path to a Properties file that contains a list of key, value pairs/
* Name of launcher, and a path to a Properties file that contains a list of key, value pairs.
* <p>
* The keys {@code module}, {@code main-jar}, {@code main-class}, {@code description},
* {@code arguments}, {@code java-options}, {@code app-version}, {@code icon},