From 89d025a11df25e7edd6820ec47cc4859ea7a7ecc Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 17 Mar 2005 12:01:19 +0000 Subject: [PATCH] failOnError and showOutput attributes for Submitted by: Zach Garner In Ant 1.6.2 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 --- CONTRIBUTORS | 1 + WHATSNEW | 2 + .../tools/ant/taskdefs/optional/Rpm.java | 63 ++++++++++++++++--- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 759c50086..6ad90a0ff 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -222,4 +222,5 @@ Wolf Siberski Yohann Roussel Yuji Yamano Yves Martin +Zach Garner Zdenek Wagner diff --git a/WHATSNEW b/WHATSNEW index 834a825d8..63312ae3a 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -287,6 +287,8 @@ Other changes: used to document packages that don't hold source files but a package.html file. Bugzilla Report 25339. +* has new attributes failonerror and showoutput attributes. + Fixed bugs: ----------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java index 6ec283ee6..fefe54486 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java @@ -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 true if it should halt, otherwise + * false + * + * @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 true if output should be logged, otherwise + * false + * + * @since Ant 1.6.3 + */ + public void setShowoutput(boolean value) { + showoutput = value; + } + /** * Checks whether rpmbuild is on the PATH and returns * the absolute path to it - falls back to rpm