From fc6592d9ea9963243ec9dd310d1e9a2c5ca21a24 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 13 May 2003 07:22:02 +0000 Subject: [PATCH] Make deal with RedHat 8+'s rpmbuild command. PR: 14650 Submitted by: Ville Skytta git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274565 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 + docs/manual/OptionalTasks/rpm.html | 16 ++++- .../tools/ant/taskdefs/optional/Rpm.java | 66 +++++++++++++++++-- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 92beb8c24..fc5540f12 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -313,6 +313,9 @@ Other changes: add new-line characters at the end of files that get concatenated but don't end in newlines. Bugzilla Report 12511. +* will detect the rpmbuild executable of RedHat 8.0 and newer + and use that if it is on your PATH. Bugzilla Report 14650. + Changes from Ant 1.5.2 to Ant 1.5.3 =================================== diff --git a/docs/manual/OptionalTasks/rpm.html b/docs/manual/OptionalTasks/rpm.html index c8470b495..670b8377d 100644 --- a/docs/manual/OptionalTasks/rpm.html +++ b/docs/manual/OptionalTasks/rpm.html @@ -23,7 +23,7 @@ specFile - The name of the spec File to be used. + The name of the spec file to be used. Yes @@ -52,7 +52,17 @@ directory. to remove the sources after the build. See the the --rmsource option of rpmbuild. No - + + + rpmBuildCommand + The executable to use for building the RPM. + Defaults to rpmbuild if it can be found or + rpm otherwise. Set this if you don't have either on + your PATH or want to use a different executable. Since Ant + 1.6. + No + + command very similar idea to the cvs task. the default is "-bb" No @@ -65,7 +75,7 @@ directory.
-

Copyright © 2001-2002 Apache Software Foundation. All rights +

Copyright © 2001-2003 Apache Software Foundation. All rights Reserved.

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 67784d529..ccce935ee 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2001-2002 The Apache Software Foundation. All rights + * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -59,6 +59,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; +import java.util.Enumeration; +import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -67,11 +69,14 @@ import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; import org.apache.tools.ant.taskdefs.LogOutputStream; import org.apache.tools.ant.taskdefs.LogStreamHandler; import org.apache.tools.ant.taskdefs.PumpStreamHandler; +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. - * @author lucas@collab.net + * + * @author lucas@collab.net */ public class Rpm extends Task { @@ -90,6 +95,12 @@ public class Rpm extends Task { */ private String command = "-bb"; + /** + * The executable to use for building the packages. + * @since Ant 1.6 + */ + private String rpmBuildCommand = null; + /** * clean BUILD directory */ @@ -119,7 +130,9 @@ public class Rpm extends Task { Commandline toExecute = new Commandline(); - toExecute.setExecutable("rpm"); + toExecute.setExecutable(rpmBuildCommand == null + ? guessRpmBuildCommand() + : rpmBuildCommand); if (topDir != null) { toExecute.createArgument().setValue("--define"); toExecute.createArgument().setValue("_topdir" + topDir); @@ -206,7 +219,7 @@ public class Rpm extends Task { } /** - * What command to issue to the rpm tool; optional. + * What command to issue to the rpm build tool; optional. * The default is "-bb" */ public void setCommand(String c) { @@ -260,4 +273,49 @@ public class Rpm extends Task { 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"; + } }