*
* @throws BuildException is there is a problem in the task execution.
*/
public void execute() throws BuildException {
Commandline toExecute = new Commandline();
toExecute.setExecutable(rpmBuildCommand == null
? guessRpmBuildCommand()
: rpmBuildCommand);
if (topDir != null) {
toExecute.createArgument().setValue("--define");
toExecute.createArgument().setValue("_topdir" + topDir);
}
toExecute.createArgument().setLine(command);
if (cleanBuildDir) {
toExecute.createArgument().setValue("--clean");
}
if (removeSpec) {
toExecute.createArgument().setValue("--rmspec");
}
if (removeSource) {
toExecute.createArgument().setValue("--rmsource");
}
toExecute.createArgument().setValue("SPECS/" + specFile);
ExecuteStreamHandler streamhandler = null;
OutputStream outputstream = null;
OutputStream errorstream = null;
if (error == null && output == null) {
streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
Project.MSG_WARN);
} else {
if (output != null) {
try {
BufferedOutputStream bos
= new BufferedOutputStream(new FileOutputStream(output));
outputstream = new PrintStream(bos);
} catch (IOException e) {
throw new BuildException(e, getLocation());
}
} else {
outputstream = new LogOutputStream(this, Project.MSG_INFO);
}
if (error != null) {
try {
BufferedOutputStream bos
= new BufferedOutputStream(new FileOutputStream(error));
errorstream = new PrintStream(bos);
} catch (IOException e) {
throw new BuildException(e, getLocation());
}
} else {
errorstream = new LogOutputStream(this, Project.MSG_WARN);
}
streamhandler = new PumpStreamHandler(outputstream, errorstream);
}
Execute exe = new Execute(streamhandler, null);
exe.setAntRun(getProject());
if (topDir == null) {
topDir = getProject().getBaseDir();
}
exe.setWorkingDirectory(topDir);
exe.setCommandline(toExecute.getCommandline());
try {
exe.execute();
log("Building the RPM based on the " + specFile + " file");
} catch (IOException e) {
throw new BuildException(e, getLocation());