Skip to content

Commit

Permalink
Merge pull request #49 from ethauvin/main
Browse files Browse the repository at this point in the history
Moved command files specification to the tool provider abstract operation
  • Loading branch information
ethauvin authored Aug 26, 2024
2 parents b4801b5 + 406b83b commit df680a4
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 293 deletions.
148 changes: 80 additions & 68 deletions src/main/java/rife/bld/operations/AbstractToolProviderOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
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_;

Expand All @@ -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<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>
Expand Down Expand Up @@ -98,84 +174,20 @@ public List<String> 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<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.
* 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<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;
}

/**
Expand Down
77 changes: 1 addition & 76 deletions src/main/java/rife/bld/operations/JlinkOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,86 +15,13 @@
* @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();

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<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.
*
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rife/bld/operations/JlinkOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public JlinkOptions limitModule(String... modules) {
* 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
Expand All @@ -188,7 +188,7 @@ public JlinkOptions modulePath(String path) {
* 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
Expand All @@ -201,7 +201,7 @@ public JlinkOptions modulePath(File path) {
* 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
Expand Down
Loading

0 comments on commit df680a4

Please sign in to comment.