mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 08:17:11 -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 rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -33,22 +31,6 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
||||||
toolName_ = toolName;
|
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.
|
* Adds tool command line arguments.
|
||||||
*
|
*
|
||||||
|
@ -57,7 +39,12 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
|
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
|
||||||
protected T addArgs(Map<String, String> args) {
|
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;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +75,7 @@ public abstract class AbstractToolProviderOperation<T extends AbstractToolProvid
|
||||||
/**
|
/**
|
||||||
* Runs an instance of the tool.
|
* Runs an instance of the tool.
|
||||||
* <p>
|
* <p>
|
||||||
* Command line arguments are automatically cleared.
|
* On success, command line arguments are automatically cleared.
|
||||||
*
|
*
|
||||||
* @throws Exception if an error occurred
|
* @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.");
|
System.err.println("No " + toolName_ + " command line arguments specified.");
|
||||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
var stderr = new StringWriter();
|
var tool = ToolProvider.findFirst(toolName_).orElseThrow(() ->
|
||||||
var stdout = new StringWriter();
|
new IllegalStateException("No " + toolName_ + " tool found."));
|
||||||
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();
|
|
||||||
|
|
||||||
if (status != 0) {
|
var status = tool.run(System.out, System.err, toolArgs_.toArray(new String[0]));
|
||||||
System.out.println(tool.name() + ' ' + String.join(" ", toolArgs_));
|
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();
|
|
||||||
}
|
}
|
||||||
|
ExitStatusException.throwOnFailure(status);
|
||||||
|
|
||||||
|
toolArgs_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws Exception {
|
public void execute() throws Exception {
|
||||||
disabledPlugins_.forEach(plugin -> addArg("--disable-plugin", plugin));
|
disabledPlugins_.forEach(plugin -> addArgs("--disable-plugin", plugin));
|
||||||
addArgs(jlinkOptions_);
|
addArgs(jlinkOptions_);
|
||||||
addArgs(parseOptions());
|
addArgs(parseOptions());
|
||||||
super.execute();
|
super.execute();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue