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

Moved command files specification to the tool provider abstract operation

This commit is contained in:
Erik C. Thauvin 2024-08-26 14:25:15 -07:00
parent b4801b5b07
commit 406b83bd82
Signed by: erik
GPG key ID: 776702A6A2DA330E
7 changed files with 90 additions and 293 deletions

View file

@ -27,6 +27,7 @@ import java.util.spi.ToolProvider;
*/
public abstract class AbstractToolProviderOperation<T extends AbstractToolProviderOperation<T>>
extends AbstractOperation<AbstractToolProviderOperation<T>> {
private final List<String> cmdFiles_ = new ArrayList<>();
private final List<String> toolArgs_ = new ArrayList<>();
private final String toolName_;
@ -39,6 +40,81 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
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<File> 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<String> 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<Path> 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<String> files) {
cmdFiles_.addAll(files);
return (T) this;
}
/**
* Runs an instance of the tool.
* <p>
@ -98,84 +174,20 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
}
/**
* 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 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<File> 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>();
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;
}
/**

View file

@ -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 @@ import java.util.Map;
* @since 2.1.0
*/
public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation> {
private final List<String> cmdFiles_ = new ArrayList<>();
private final List<String> disabledPlugins_ = new ArrayList<>();
private final JlinkOptions jlinkOptions_ = new JlinkOptions();
@ -25,78 +22,6 @@ public class JlinkOperation extends AbstractToolProviderOperation<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<File> 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<Path> 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<String> files) {
cmdFiles_.addAll(files);
return this;
}
/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> cmdFiles() {
return cmdFiles_;
}
/**
* Disable the plugin(s) mentioned.
*
@ -120,7 +45,7 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
@Override
public void execute() throws Exception {
toolArgsFromFileStrings(cmdFiles_);
toolArgsFromFiles();
disabledPlugins_.forEach(plugin -> toolArgs("--disable-plugin", plugin));
toolArgs(jlinkOptions_);
super.execute();

View file

@ -174,7 +174,7 @@ public class JlinkOptions extends LinkedHashMap<String, String> {
* Module path.
* <p>
* 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 class JlinkOptions extends LinkedHashMap<String, String> {
* Module path.
* <p>
* 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 class JlinkOptions extends LinkedHashMap<String, String> {
* Module path.
* <p>
* 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

View file

@ -6,9 +6,6 @@ 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;
/**
@ -18,7 +15,6 @@ import java.util.Map;
* @since 2.1.0
*/
public class JmodOperation extends AbstractToolProviderOperation<JmodOperation> {
private final List<String> cmdFiles = new ArrayList<>();
private final JmodOptions jmodOptions_ = new JmodOptions();
private String jmodFile_;
private OperationMode operationMode_;
@ -27,76 +23,13 @@ public class JmodOperation extends AbstractToolProviderOperation<JmodOperation>
super("jmod");
}
/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> 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<Path> 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<String> 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) {

View file

@ -17,7 +17,6 @@ import java.util.Map;
* @since 2.1.0
*/
public class JpackageOperation extends AbstractToolProviderOperation<JpackageOperation> {
private final List<String> cmdFiles_ = new ArrayList<>();
private final JpackageOptions jpackageOptions_ = new JpackageOptions();
private final List<Launcher> launchers_ = new ArrayList<>();
@ -56,81 +55,9 @@ public class JpackageOperation extends AbstractToolProviderOperation<JpackageOpe
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;
}
/**
* 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<Path> 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<String> files) {
cmdFiles_.addAll(files);
return this;
}
/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> 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);
}

View file

@ -667,7 +667,7 @@ public class JpackageOptions extends LinkedHashMap<String, String> {
* @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 class JpackageOptions extends LinkedHashMap<String, String> {
}
/**
* Team or user name portion in Apple signing identities.
* User or team name portion in Apple signing identities.
* <p>
* 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 class JpackageOptions extends LinkedHashMap<String, String> {
}
/**
* 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

View file

@ -363,7 +363,7 @@ public class TestJpackageOperation {
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"));