Browse Source

Make <rpm> deal with RedHat 8+'s rpmbuild command.

PR: 14650
Submitted by:	Ville Skytta <ville dot skytta at iki dot fi>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274565 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
fc6592d9ea
3 changed files with 78 additions and 7 deletions
  1. +3
    -0
      WHATSNEW
  2. +13
    -3
      docs/manual/OptionalTasks/rpm.html
  3. +62
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java

+ 3
- 0
WHATSNEW View File

@@ -313,6 +313,9 @@ Other changes:
add new-line characters at the end of files that get concatenated but add new-line characters at the end of files that get concatenated but
don't end in newlines. Bugzilla Report 12511. don't end in newlines. Bugzilla Report 12511.


* <rpm> 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 Changes from Ant 1.5.2 to Ant 1.5.3
=================================== ===================================




+ 13
- 3
docs/manual/OptionalTasks/rpm.html View File

@@ -23,7 +23,7 @@
</tr> </tr>
<tr> <tr>
<td valign="top">specFile</td> <td valign="top">specFile</td>
<td valign="top">The name of the spec File to be used.</td>
<td valign="top">The name of the spec file to be used.</td>
<td valign="top" align="center">Yes</td> <td valign="top" align="center">Yes</td>
</tr> </tr>
<tr> <tr>
@@ -52,7 +52,17 @@ directory.</td>
to remove the sources after the build. to remove the sources after the build.
See the the <tt>--rmsource</tt> option of rpmbuild.</td> See the the <tt>--rmsource</tt> option of rpmbuild.</td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> <tr>
</tr>
<tr>
<td valign="top">rpmBuildCommand</td>
<td valign="top">The executable to use for building the RPM.
Defaults to <code>rpmbuild</code> if it can be found or
<code>rpm</code> otherwise. Set this if you don't have either on
your PATH or want to use a different executable. <em>Since Ant
1.6</em>.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">command</td> <td valign="top">command</td>
<td valign="top">very similar idea to the cvs task. the default is "-bb"</td> <td valign="top">very similar idea to the cvs task. the default is "-bb"</td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
@@ -65,7 +75,7 @@ directory.</td>
</table> </table>
<hr> <hr>


<p align="center">Copyright &copy; 2001-2002 Apache Software Foundation. All rights
<p align="center">Copyright &copy; 2001-2003 Apache Software Foundation. All rights
Reserved.</p> Reserved.</p>


</body> </body>


+ 62
- 4
src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; 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.LogOutputStream;
import org.apache.tools.ant.taskdefs.LogStreamHandler; import org.apache.tools.ant.taskdefs.LogStreamHandler;
import org.apache.tools.ant.taskdefs.PumpStreamHandler; 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.Commandline;
import org.apache.tools.ant.types.Path;


/** /**
* Invokes the rpm tool to build a Linux installation file. * Invokes the rpm tool to build a Linux installation file.
* @author lucas@collab.net
*
* @author lucas@collab.net
*/ */
public class Rpm extends Task { public class Rpm extends Task {
@@ -90,6 +95,12 @@ public class Rpm extends Task {
*/ */
private String command = "-bb"; private String command = "-bb";


/**
* The executable to use for building the packages.
* @since Ant 1.6
*/
private String rpmBuildCommand = null;

/** /**
* clean BUILD directory * clean BUILD directory
*/ */
@@ -119,7 +130,9 @@ public class Rpm extends Task {
Commandline toExecute = new Commandline(); Commandline toExecute = new Commandline();


toExecute.setExecutable("rpm");
toExecute.setExecutable(rpmBuildCommand == null
? guessRpmBuildCommand()
: rpmBuildCommand);
if (topDir != null) { if (topDir != null) {
toExecute.createArgument().setValue("--define"); toExecute.createArgument().setValue("--define");
toExecute.createArgument().setValue("_topdir" + topDir); 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" * The default is "-bb"
*/ */
public void setCommand(String c) { public void setCommand(String c) {
@@ -260,4 +273,49 @@ public class Rpm extends Task {
public void setError(File error) { public void setError(File error) {
this.error = error; this.error = error;
} }

/**
* The executable to run when building; optional.
* The default is <code>rpmbuild</code>.
*
* @since Ant 1.6
* @param c the rpm build executable
*/
public void setRpmBuildCommand(String c) {
this.rpmBuildCommand = c;
}

/**
* Checks whether <code>rpmbuild</code> is on the PATH and returns
* the absolute path to it - falls back to <code>rpm</code>
* 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";
}
} }

Loading…
Cancel
Save