mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 00:07:12 -07:00
Use System.out and System.out instead of StringWriter
This commit is contained in:
parent
c38594a173
commit
8118f42285
2 changed files with 16 additions and 45 deletions
|
@ -6,8 +6,6 @@ package rife.bld.operations;
|
|||
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -33,22 +31,6 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
toolName_ = toolName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tool command line argument.
|
||||
*
|
||||
* @param arg the argument
|
||||
* @param value the value
|
||||
* @return this operation
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
|
||||
public T addArg(String arg, String value) {
|
||||
toolArgs_.add(arg);
|
||||
if (value != null && !value.isEmpty()) {
|
||||
toolArgs_.add(value);
|
||||
}
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tool command line arguments.
|
||||
*
|
||||
|
@ -57,7 +39,12 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
*/
|
||||
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
|
||||
protected T addArgs(Map<String, String> args) {
|
||||
args.forEach(this::addArg);
|
||||
args.forEach((k, v) -> {
|
||||
toolArgs_.add(k);
|
||||
if (v != null && !v.isEmpty()) {
|
||||
toolArgs_.add(v);
|
||||
}
|
||||
});
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
@ -88,7 +75,7 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
/**
|
||||
* Runs an instance of the tool.
|
||||
* <p>
|
||||
* Command line arguments are automatically cleared.
|
||||
* On success, command line arguments are automatically cleared.
|
||||
*
|
||||
* @throws Exception if an error occurred
|
||||
*/
|
||||
|
@ -98,32 +85,16 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
|||
System.err.println("No " + toolName_ + " command line arguments specified.");
|
||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
}
|
||||
var stderr = new StringWriter();
|
||||
var stdout = new StringWriter();
|
||||
try (var err = new PrintWriter(stderr); var out = new PrintWriter(stdout)) {
|
||||
var tool = ToolProvider.findFirst(toolName_).orElseThrow(() ->
|
||||
new IllegalStateException("No " + toolName_ + " tool found."));
|
||||
var status = tool.run(out, err, toolArgs_.toArray(new String[0]));
|
||||
out.flush();
|
||||
err.flush();
|
||||
var tool = ToolProvider.findFirst(toolName_).orElseThrow(() ->
|
||||
new IllegalStateException("No " + toolName_ + " tool found."));
|
||||
|
||||
if (status != 0) {
|
||||
System.out.println(tool.name() + ' ' + String.join(" ", toolArgs_));
|
||||
}
|
||||
|
||||
var output = stdout.toString();
|
||||
if (!output.isBlank()) {
|
||||
System.out.println(output);
|
||||
}
|
||||
var error = stderr.toString();
|
||||
if (!error.isBlank()) {
|
||||
System.err.println(error);
|
||||
}
|
||||
|
||||
ExitStatusException.throwOnFailure(status);
|
||||
} finally {
|
||||
toolArgs_.clear();
|
||||
var status = tool.run(System.out, System.err, toolArgs_.toArray(new String[0]));
|
||||
if (status != 0) {
|
||||
System.out.println(tool.name() + ' ' + String.join(" ", toolArgs_));
|
||||
}
|
||||
ExitStatusException.throwOnFailure(status);
|
||||
|
||||
toolArgs_.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
|
|||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
disabledPlugins_.forEach(plugin -> addArg("--disable-plugin", plugin));
|
||||
disabledPlugins_.forEach(plugin -> addArgs("--disable-plugin", plugin));
|
||||
addArgs(jlinkOptions_);
|
||||
addArgs(parseOptions());
|
||||
super.execute();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue