I've attached a patch that fixes two problems in the RPM Task:
- Provide a way to halt the build if the RPM build command exists with
an error status. Currently users must save the output to a file, and
grep the output for error messages if they want to automatically halt
the build when the RPM build command fails.
To fix this, I've added a haltonerror option which defaults to false to
preserve the current behavior. This simply checks the exist status of
the Execute process.
- Provide a way to quiet the RPM build process. Currently when building,
all messages to stdout and stderr are logged to MSG_INFO and MSG_WARN
respectively. It's not uncommon for there to be a thousand lines of
output. Unfortunately the RPM build tool prints a lot of relatively
useless information to stderr.
To fix this, I've added a showoutput option which defaults to true to
preserve the current behavior. When set to false, I log the all of the
output to MSG_DEBUG. A message "[rpm] Building the RPM based on the
foo.spec file" is still logged to MSG_INFO.
Thanks,
Zach Garner
--- apache-ant-1.6.2/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java.orig 2005-03-14 20:35:21.000000000 -0600
+++ apache-ant-1.6.2/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java 2005-03-16 10:55:53.476864272 -0600
@@ -89,6 +89,17 @@
private File error;
/**
+ * Halt on error return value from rpm build.
+ */
+ private boolean haltonerror = 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.
@@ -123,8 +134,13 @@
OutputStream outputstream = null;
OutputStream errorstream = null;
if (error == null && output == null) {
- streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
+ 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 {
@@ -134,8 +150,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 {
@@ -145,8 +163,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);
}
@@ -161,8 +181,16 @@
exe.setCommandline(toExecute.getCommandline());
try {
- exe.execute();
+ int exitValue = exe.execute();
log("Building the RPM based on the " + specFile + " file");
+
+ if (Execute.isFailure(exitValue)) {
+ if (haltonerror) {
+ throw new BuildException("RPM Build failed", getLocation());
+ } else {
+ log("RPM Build FAILED", Project.MSG_ERR);
+ }
+ }
} catch (IOException e) {
throw new BuildException(e, getLocation());
} finally {
@@ -263,6 +291,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
+ */
+ public void setHaltonerror(boolean value) {
+ haltonerror = 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
+ */
+ 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]