bodewig 2005/03/17 04:01:19 Modified: . CONTRIBUTORS WHATSNEW src/main/org/apache/tools/ant/taskdefs/optional Rpm.java Log: 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). Revision Changes Path 1.47 +1 -0 ant/CONTRIBUTORS Index: CONTRIBUTORS =================================================================== RCS file: /home/cvs/ant/CONTRIBUTORS,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- CONTRIBUTORS 17 Mar 2005 08:10:49 -0000 1.46 +++ CONTRIBUTORS 17 Mar 2005 12:01:18 -0000 1.47 @@ -222,4 +222,5 @@ Yohann Roussel Yuji Yamano Yves Martin +Zach Garner Zdenek Wagner 1.785 +2 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.784 retrieving revision 1.785 diff -u -r1.784 -r1.785 --- WHATSNEW 17 Mar 2005 09:59:36 -0000 1.784 +++ WHATSNEW 17 Mar 2005 12:01:18 -0000 1.785 @@ -287,6 +287,8 @@ 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: ----------- 1.25 +55 -8 ant/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java Index: Rpm.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- Rpm.java 9 Feb 2005 07:54:12 -0000 1.24 +++ Rpm.java 17 Mar 2005 12:01:19 -0000 1.25 @@ -90,6 +90,17 @@ 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 * * @throws BuildException is there is a problem in the task execution. @@ -124,8 +135,13 @@ 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 @@ } 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 @@ } 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 @@ 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()); @@ -257,6 +281,29 @@ } /** + * 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> * otherwise.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]