ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional Rpm.java
Date Tue, 13 May 2003 07:22:02 GMT
bodewig     2003/05/13 00:22:02

  Modified:    .        WHATSNEW
               docs/manual/OptionalTasks rpm.html
               src/main/org/apache/tools/ant/taskdefs/optional Rpm.java
  Log:
  Make <rpm> deal with RedHat 8+'s rpmbuild command.
  
  PR: 14650
  Submitted by:	Ville Skytta <ville dot skytta at iki dot fi>
  
  Revision  Changes    Path
  1.415     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.414
  retrieving revision 1.415
  diff -u -r1.414 -r1.415
  --- WHATSNEW	12 May 2003 14:00:08 -0000	1.414
  +++ WHATSNEW	13 May 2003 07:22:02 -0000	1.415
  @@ -313,6 +313,9 @@
     add new-line characters at the end of files that get concatenated but
     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
   ===================================
   
  
  
  
  1.6       +13 -3     ant/docs/manual/OptionalTasks/rpm.html
  
  Index: rpm.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/rpm.html,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- rpm.html	9 Jul 2002 21:05:52 -0000	1.5
  +++ rpm.html	13 May 2003 07:22:02 -0000	1.6
  @@ -23,7 +23,7 @@
     </tr>
     <tr>
       <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>
     </tr>
     <tr>
  @@ -52,7 +52,17 @@
           to remove the sources after the build.
           See the the <tt>--rmsource</tt>  option of rpmbuild.</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">very similar idea to the cvs task.  the default is "-bb"</td>
       <td align="center" valign="top">No</td>
  @@ -65,7 +75,7 @@
   </table>
   <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>
   
   </body>
  
  
  
  1.14      +62 -4     ant/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java
  
  Index: Rpm.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Rpm.java	10 Feb 2003 14:13:45 -0000	1.13
  +++ Rpm.java	13 May 2003 07:22:02 -0000	1.14
  @@ -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.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.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 {
       
  @@ -91,6 +96,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,7 +130,9 @@
           
           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 @@
       }
   
       /**
  -     * 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) {
  @@ -259,5 +272,50 @@
        */
       public void setError(File 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";
       }
   }
  
  
  

Mime
View raw message