Browse Source

failOnError and showOutput attributes for <rpm>

Submitted by:	Zach Garner <zach at awarix dot com>

In Ant 1.6.2 <rpm> wouldn't fail even if the command failed, CVS HEAD
would fail unconditionally if the command failed.  If chose 1.6.2's
behavior as default for failOnError (i.e. it is false by default).


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278009 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 20 years ago
parent
commit
89d025a11d
3 changed files with 58 additions and 8 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +2
    -0
      WHATSNEW
  3. +55
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java

+ 1
- 0
CONTRIBUTORS View File

@@ -222,4 +222,5 @@ Wolf Siberski
Yohann Roussel
Yuji Yamano
Yves Martin
Zach Garner
Zdenek Wagner

+ 2
- 0
WHATSNEW View File

@@ -287,6 +287,8 @@ Other changes:
used to document packages that don't hold source files but a
package.html file. Bugzilla Report 25339.

* <rpm> has new attributes failonerror and showoutput attributes.

Fixed bugs:
-----------



+ 55
- 8
src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java View File

@@ -89,6 +89,17 @@ public class Rpm extends Task {
*/
private File error;

/**
* Halt on error return value from rpm build.
*/
private boolean failOnError = false;

/**
* Show output of RPM build command on console. This does not affect
* the printing of output and error messages to files.
*/
private boolean showoutput = true;

/**
* Execute the task
*
@@ -124,8 +135,13 @@ public class Rpm extends Task {
OutputStream outputstream = null;
OutputStream errorstream = null;
if (error == null && output == null) {
streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
Project.MSG_WARN);
if (showoutput) {
streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
Project.MSG_WARN);
} else {
streamhandler = new LogStreamHandler(this, Project.MSG_DEBUG,
Project.MSG_DEBUG);
}
} else {
if (output != null) {
try {
@@ -135,8 +151,10 @@ public class Rpm extends Task {
} catch (IOException e) {
throw new BuildException(e, getLocation());
}
} else {
} else if (showoutput) {
outputstream = new LogOutputStream(this, Project.MSG_INFO);
} else {
outputstream = new LogOutputStream(this, Project.MSG_DEBUG);
}
if (error != null) {
try {
@@ -146,8 +164,10 @@ public class Rpm extends Task {
} catch (IOException e) {
throw new BuildException(e, getLocation());
}
} else {
} else if (showoutput) {
errorstream = new LogOutputStream(this, Project.MSG_WARN);
} else {
errorstream = new LogOutputStream(this, Project.MSG_DEBUG);
}
streamhandler = new PumpStreamHandler(outputstream, errorstream);
}
@@ -164,10 +184,14 @@ public class Rpm extends Task {
try {
log("Building the RPM based on the " + specFile + " file");
int returncode = exe.execute();
if (returncode != 0) {
throw new BuildException("'" +
toExecute.getExecutable() +
"' failed with exit code "+returncode);
if (Execute.isFailure(returncode)) {
String msg = "'" + toExecute.getExecutable()
+ "' failed with exit code " + returncode;
if (failOnError) {
throw new BuildException(msg);
} else {
log(msg, Project.MSG_ERR);
}
}
} catch (IOException e) {
throw new BuildException(e, getLocation());
@@ -256,6 +280,29 @@ public class Rpm extends Task {
this.rpmBuildCommand = c;
}

/**
* If true, stop the build process when the rpmbuild command exits with
* an error status.
* @param value <tt>true</tt> if it should halt, otherwise
* <tt>false</tt>
*
* @since Ant 1.6.3
*/
public void setFailOnError(boolean value) {
failOnError = value;
}

/**
* If false, no output from the RPM build command will be logged.
* @param value <tt>true</tt> if output should be logged, otherwise
* <tt>false</tt>
*
* @since Ant 1.6.3
*/
public void setShowoutput(boolean value) {
showoutput = value;
}

/**
* Checks whether <code>rpmbuild</code> is on the PATH and returns
* the absolute path to it - falls back to <code>rpm</code>


Loading…
Cancel
Save