--- src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java 2003-10-13 02:19:42.000000000 +0000 +++ src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java 2003-10-13 02:24:16.000000000 +0000 @@ -59,6 +59,8 @@ import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Enumeration; +import java.util.Vector; import org.apache.tools.ant.Task; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -67,7 +69,9 @@ import org.apache.tools.ant.taskdefs.LogOutputStream; import org.apache.tools.ant.taskdefs.PumpStreamHandler; import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; /** * Invokes the rpm tool to build a Linux installation file. @@ -91,6 +95,12 @@ private String command = "-bb"; /** + * The executable to use for building the packages. + * @since Ant 1.6 + */ + private String rpmBuildCommand = null; + + /** * clean BUILD directory */ private boolean cleanBuildDir = false; @@ -119,6 +129,9 @@ Commandline toExecute = new Commandline(); - toExecute.setExecutable("rpm"); + toExecute.setExecutable(rpmBuildCommand == null + ? guessRpmBuildCommand() + : rpmBuildCommand); + if (topDir != null) { toExecute.createArgument().setValue("--define"); @@ -260,4 +273,49 @@ public void setError(File error) { this.error = error; } + + /** + * The executable to run when building; optional. + * The default is rpmbuild. + * + * @since Ant 1.6 + * @param c the rpm build executable + */ + public void setRpmBuildCommand(String c) { + this.rpmBuildCommand = c; + } + + /** + * Checks whether rpmbuild is on the PATH and returns + * the absolute path to it - falls back to rpm + * otherwise. + * + * @since 1.6 + */ + protected String guessRpmBuildCommand() { + Vector env = Execute.getProcEnvironment(); + String path = null; + for (Enumeration enum = env.elements(); enum.hasMoreElements();) { + String var = (String) enum.nextElement(); + if (var.startsWith("PATH=") || var.startsWith("Path=")) { + path = var.substring(6 /* "PATH=".length() + 1 */); + break; + } + } + + if (path != null) { + Path p = new Path(getProject(), path); + String[] pElements = p.list(); + for (int i = 0; i < pElements.length; i++) { + File f = new File(pElements[i], + "rpmbuild" + + (Os.isFamily("dos") ? ".exe" : "")); + if (f.canRead()) { + return f.getAbsolutePath(); + } + } + } + + return "rpm"; + } }