2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 00:07:12 -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},

View file

@ -15,24 +15,7 @@ import static org.junit.jupiter.api.Assertions.*;
public class TestJlinkOperation {
@Test
void testNoArguments() {
var jlink = new JlinkOperation();
assertThrows(ExitStatusException.class, jlink::execute);
}
@Test
void testDisablePlugin() {
var jlink = new JlinkOperation()
.disablePlugin("vm")
.disablePlugin("system-modules")
.listPlugins();
assertDoesNotThrow(jlink::execute);
assertTrue(jlink.toolArgs().containsAll(List.of("vm", "system-modules")));
}
@Test
void testOptions() {
void testArguments() {
var args = new HashMap<String, String>();
args.put("--add-modules", "module-1,module-2");
args.put("--bind-services", null);
@ -78,9 +61,40 @@ public class TestJlinkOperation {
assertEquals("name-2=module-2", options.get("--launcher"), "incorrect launcher");
}
@Test
void testDisablePlugin() {
var jlink = new JlinkOperation()
.disablePlugin("vm")
.disablePlugin("system-modules")
.listPlugins();
assertDoesNotThrow(jlink::execute);
assertTrue(jlink.toolArgs().containsAll(List.of("vm", "system-modules")));
}
@Test
void testHelp() {
var jlink = new JlinkOperation().addArgs("--help");
assertDoesNotThrow(jlink::execute);
}
@Test
void testNoArguments() {
var jlink = new JlinkOperation();
assertTrue(jlink.jlinkOptions().isEmpty(), "jlink options not empty");
assertTrue(jlink.options().isEmpty(), "options not empty");
assertThrows(ExitStatusException.class, jlink::execute);
}
@Test
void testOptions() {
var jlink = new JlinkOperation().options("src/test/resources/options_verbose.txt");
assertDoesNotThrow(jlink::execute);
}
@Test
void testVersion() {
var jlink = new JlinkOperation().addArgs("--version");
var jlink = new JlinkOperation().addArgs("--verbose", "--version");
assertDoesNotThrow(jlink::execute);
}
}

View file

@ -16,13 +16,7 @@ import static org.junit.jupiter.api.Assertions.*;
public class TestJmodOperation {
@Test
void testNoArguments() {
var jmod = new JmodOperation();
assertThrows(ExitStatusException.class, jmod::execute);
}
@Test
void testOptions() {
void testArguments() {
var args = new HashMap<String, String>();
args.put("--class-path", "classpath");
args.put("--cmds", "cmds");
@ -43,7 +37,6 @@ public class TestJmodOperation {
args.put("--module-version", "module-version");
args.put("--target-platform", "target-platform");
args.put("--warn-if-resolved", "deprecated");
args.put("@filename", null);
var options = new JmodOptions()
.classpath(args.get("--class-path"))
@ -56,7 +49,6 @@ public class TestJmodOperation {
.dryRun(true)
.exclude(new JmodOptions.FilePattern(JmodOptions.FilePatternType.GLOB, "glob"),
new JmodOptions.FilePattern(JmodOptions.FilePatternType.REGEX, "regex"))
.filename("filename")
.hashModules(args.get("--hash-modules"))
.headerFiles(args.get("--header-files"))
.legalNotices(args.get("--legal-notices"))
@ -76,6 +68,29 @@ public class TestJmodOperation {
}
}
@Test
void testHelp() {
var jmod = new JmodOperation()
.operationMode(JmodOperation.OperationMode.HASH)
.jmodFile("foo")
.addArgs("--help-extra");
assertDoesNotThrow(jmod::execute);
}
@Test
void testNoArguments() {
var jmod = new JmodOperation();
assertTrue(jmod.options().isEmpty(), "options not empty");
assertTrue(jmod.jmodOptions().isEmpty(), "jmod options not empty");
assertThrows(ExitStatusException.class, jmod::execute);
}
@Test
void testOptions() {
var jpackage = new JpackageOperation().options("src/test/resources/options_version.txt");
assertDoesNotThrow(jpackage::execute);
}
@Test
void testVersion() {
var jmod = new JmodOperation()

View file

@ -15,44 +15,9 @@ import java.util.HashMap;
import static org.junit.jupiter.api.Assertions.*;
public class TestJpackageOperation {
@Test
void testCreatePackage() throws Exception {
var tmpdir = Files.createTempDirectory("bld-jpackage-test").toFile();
tmpdir.deleteOnExit();
var options = new JpackageOptions()
.input("lib/bld")
.name("bld")
.mainJar("bld-wrapper.jar")
.javaOptions("--enable-preview")
.dest(tmpdir.getAbsolutePath())
.verbose(true);
var os = System.getProperty("os.version");
if (os.endsWith("MANJARO")) {
options.type(JpackageOptions.PackageType.DEB);
}
var jpackage = new JpackageOperation().jpackageOptions(options);
jpackage.execute();
var files = tmpdir.listFiles();
assertNotNull(files, "files should not be null");
assertTrue(files.length > 0, "No files found");
assertTrue(files[0].getName().matches("bld.*\\.[A-Za-z]{3}"), "Package not found");
FileUtils.deleteDirectory(tmpdir);
}
@Test
void testNoArguments() {
var jpackage = new JpackageOperation();
assertThrows(ExitStatusException.class, jpackage::execute);
}
@Test
void testOptions() {
void testArguments() {
var args = new HashMap<String, String>();
args.put("--about-url", "about-url");
args.put("--add-launcher", "name=path");
@ -95,7 +60,7 @@ public class TestJpackageOperation {
args.put("--main-class", "main-class");
args.put("--main-jar", "main-jar");
args.put("--module", "module");
args.put("--module-path", "module-path-1,module-path-2");
args.put("--module-path", "module-path-1:module-path-2");
args.put("--name", "name");
args.put("--resource-dir", "resource-dir");
args.put("--runtime-image", "runtime-image");
@ -114,7 +79,6 @@ public class TestJpackageOperation {
args.put("--win-shortcut-prompt", null);
args.put("--win-update-url", "win-update-url");
args.put("--win-upgrade-uuid", "win-upgrade-uuid");
args.put("@filename", null);
var options = new JpackageOptions()
.aboutUrl(args.get("--about-url"))
@ -176,8 +140,7 @@ public class TestJpackageOperation {
.winShortcut(true)
.winShortcutPrompt(true)
.winUpdateUrl(args.get("--win-update-url"))
.winUpgradeUuid(args.get("--win-upgrade-uuid"))
.filename("filename");
.winUpgradeUuid(args.get("--win-upgrade-uuid"));
assertEquals(options.size(), args.size(), "Wrong number of arguments");
@ -188,9 +151,59 @@ public class TestJpackageOperation {
}
@Test
void testCreatePackage() throws Exception {
var tmpdir = Files.createTempDirectory("bld-jpackage-test").toFile();
tmpdir.deleteOnExit();
var options = new JpackageOptions()
.input("lib/bld")
.name("bld")
.mainJar("bld-wrapper.jar")
.javaOptions("--enable-preview")
.dest(tmpdir.getAbsolutePath())
.verbose(true);
var os = System.getProperty("os.version");
if (os.endsWith("MANJARO")) {
options.type(JpackageOptions.PackageType.DEB);
}
var jpackage = new JpackageOperation().jpackageOptions(options);
jpackage.execute();
var files = tmpdir.listFiles();
assertNotNull(files, "files should not be null");
assertTrue(files.length > 0, "No files found");
assertTrue(files[0].getName().matches("bld.*\\.[A-Za-z]{3}"), "Package not found");
FileUtils.deleteDirectory(tmpdir);
}
@Test
void testHelp() {
var jpackage = new JpackageOperation().addArgs("--help");
assertDoesNotThrow(jpackage::execute);
}
@Test
void testNoArguments() {
var jpackage = new JpackageOperation();
assertTrue(jpackage.options().isEmpty(), "options not empty");
assertTrue(jpackage.jpackageOptions().isEmpty(), "jpackage options not empty");
assertThrows(ExitStatusException.class, jpackage::execute);
}
@Test
void testOptions() {
var jpackage = new JpackageOperation().options("src/test/resources/options_verbose.txt");
assertDoesNotThrow(jpackage::execute);
}
@Test
void testVersion() {
var jpackage = new JpackageOperation().addArgs("--version");
var jpackage = new JpackageOperation().addArgs("--verbose", "--version");
assertDoesNotThrow(jpackage::execute);
}
}

View file

@ -0,0 +1 @@
--verbose --version

View file

@ -0,0 +1 @@
--version