use of org.apache.tools.ant.taskdefs.LogOutputStream in project ant by apache.
the class ANTLR method run.
/**
* execute in a forked VM
*/
private int run(String[] command) throws BuildException {
PumpStreamHandler psh = new PumpStreamHandler(new LogOutputStream(this, Project.MSG_INFO), new TeeOutputStream(new LogOutputStream(this, Project.MSG_WARN), bos));
Execute exe = new Execute(psh, null);
exe.setAntRun(getProject());
if (workingdir != null) {
exe.setWorkingDirectory(workingdir);
}
exe.setCommandline(command);
try {
return exe.execute();
} catch (IOException e) {
throw new BuildException(e, getLocation());
} finally {
FileUtils.close(bos);
}
}
use of org.apache.tools.ant.taskdefs.LogOutputStream in project ant by apache.
the class Cab method execute.
/**
* execute this task.
* @throws BuildException on error.
*/
@Override
public void execute() throws BuildException {
checkConfiguration();
Vector<String> files = getFileList();
// quick exit if the target is up to date
if (isUpToDate(files)) {
return;
}
log("Building " + archiveType + ": " + cabFile.getAbsolutePath());
if (!Os.isFamily("windows")) {
log("Using listcab/libcabinet", Project.MSG_VERBOSE);
StringBuilder sb = new StringBuilder();
files.forEach(f -> sb.append(f).append("\n"));
sb.append("\n").append(cabFile.getAbsolutePath()).append("\n");
try {
Process p = Execute.launch(getProject(), new String[] { "listcab" }, null, baseDir != null ? baseDir : getProject().getBaseDir(), true);
OutputStream out = p.getOutputStream();
// Create the stream pumpers to forward listcab's stdout and stderr to the log
// note: listcab is an interactive program, and issues prompts for every new line.
// Therefore, make it show only with verbose logging turned on.
LogOutputStream outLog = new LogOutputStream(this, Project.MSG_VERBOSE);
LogOutputStream errLog = new LogOutputStream(this, Project.MSG_ERR);
StreamPumper outPump = new StreamPumper(p.getInputStream(), outLog);
StreamPumper errPump = new StreamPumper(p.getErrorStream(), errLog);
// Pump streams asynchronously
new Thread(outPump).start();
new Thread(errPump).start();
out.write(sb.toString().getBytes());
out.flush();
out.close();
// A wild default for when the thread is interrupted
int result = DEFAULT_RESULT;
try {
// Wait for the process to finish
result = p.waitFor();
// Wait for the end of output and error streams
outPump.waitFor();
outLog.close();
errPump.waitFor();
errLog.close();
} catch (InterruptedException ie) {
log("Thread interrupted: " + ie);
}
// Informative summary message in case of errors
if (Execute.isFailure(result)) {
log("Error executing listcab; error code: " + result);
}
} catch (IOException ex) {
throw new BuildException("Problem creating " + cabFile + " " + ex.getMessage(), getLocation());
}
} else {
try {
File listFile = createListFile(files);
ExecTask exec = createExec();
File outFile = null;
// die if cabarc fails
exec.setFailonerror(true);
exec.setDir(baseDir);
if (!doVerbose) {
outFile = FILE_UTILS.createTempFile("ant", "", null, true, true);
exec.setOutput(outFile);
}
exec.setExecutable("cabarc");
exec.createArg().setValue("-r");
exec.createArg().setValue("-p");
if (!doCompress) {
exec.createArg().setValue("-m");
exec.createArg().setValue("none");
}
if (cmdOptions != null) {
exec.createArg().setLine(cmdOptions);
}
exec.createArg().setValue("n");
exec.createArg().setFile(cabFile);
exec.createArg().setValue("@" + listFile.getAbsolutePath());
exec.execute();
if (outFile != null) {
outFile.delete();
}
listFile.delete();
} catch (IOException ioe) {
throw new BuildException("Problem creating " + cabFile + " " + ioe.getMessage(), getLocation());
}
}
}
use of org.apache.tools.ant.taskdefs.LogOutputStream in project ant by apache.
the class SunRmic method execute.
/**
* Run the rmic compiler.
* @return true if the compilation succeeded
* @throws BuildException on error
*/
@Override
public boolean execute() throws BuildException {
getRmic().log("Using SUN rmic compiler", Project.MSG_VERBOSE);
Commandline cmd = setupRmicCommand();
// Create an instance of the rmic, redirecting output to
// the project log
LogOutputStream logstr = new LogOutputStream(getRmic(), Project.MSG_WARN);
boolean success = false;
try {
Class<?> c = Class.forName(RMIC_CLASSNAME);
Constructor<?> cons = c.getConstructor(OutputStream.class, String.class);
Object rmic = cons.newInstance(logstr, "rmic");
Method doRmic = c.getMethod("compile", String[].class);
boolean ok = Boolean.TRUE.equals(doRmic.invoke(rmic, (Object) cmd.getArguments()));
success = true;
return ok;
} catch (ClassNotFoundException ex) {
if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) {
throw new BuildException(ERROR_NO_RMIC_ON_CLASSPATH_JAVA_9, getRmic().getLocation());
}
throw new BuildException(ERROR_NO_RMIC_ON_CLASSPATH, getRmic().getLocation());
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
}
throw new BuildException(ERROR_RMIC_FAILED, ex, getRmic().getLocation());
} finally {
try {
logstr.close();
} catch (IOException e) {
// original error will be passed up
if (success) {
// NOSONAR
throw new BuildException(e);
}
}
}
}
use of org.apache.tools.ant.taskdefs.LogOutputStream in project checkstyle by checkstyle.
the class CheckstyleAntTask method getListeners.
/**
* Return the list of listeners set in this task.
*
* @return the list of listeners.
* @throws BuildException if the listeners could not be created.
*/
private AuditListener[] getListeners() {
final int formatterCount = Math.max(1, formatters.size());
final AuditListener[] listeners = new AuditListener[formatterCount];
// formatters
try {
if (formatters.isEmpty()) {
final OutputStream debug = new LogOutputStream(this, Project.MSG_DEBUG);
final OutputStream err = new LogOutputStream(this, Project.MSG_ERR);
listeners[0] = new DefaultLogger(debug, AutomaticBean.OutputStreamOptions.CLOSE, err, AutomaticBean.OutputStreamOptions.CLOSE);
} else {
for (int i = 0; i < formatterCount; i++) {
final Formatter formatter = formatters.get(i);
listeners[i] = formatter.createListener(this);
}
}
} catch (IOException ex) {
throw new BuildException(String.format(Locale.ROOT, "Unable to create listeners: " + "formatters {%s}.", formatters), ex);
}
return listeners;
}
Aggregations