bodewig     2003/11/25 03:46:21

  Modified:    src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
                        ExecTask.java
  Log:
  Merge from HEAD
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.61.2.2  +46 -3     ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  
  Index: ExecTask.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v
  retrieving revision 1.61.2.1
  retrieving revision 1.61.2.2
  diff -u -r1.61.2.1 -r1.61.2.2
  --- ExecTask.java     21 Nov 2003 11:13:15 -0000      1.61.2.1
  +++ ExecTask.java     25 Nov 2003 11:46:21 -0000      1.61.2.2
  @@ -56,11 +56,14 @@
   
   import java.io.File;
   import java.io.IOException;
  +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;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.Environment;
  +import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.util.FileUtils;
   
   /**
  @@ -286,6 +289,16 @@
       }
   
       /**
  +     * Indicates whether to attempt to resolve the executable to a
  +     * file
  +     *
  +     * @since Ant 1.6
  +     */
  +    public boolean getResolveExecutable() {
  +        return resolveExecutable;
  +    }
  +
  +    /**
        * Add an environment variable to the launched process.
        *
        * @param var new environment variable
  @@ -362,11 +375,15 @@
        * the full path - first try basedir, then the exec dir and then
        * fallback to the straight executable name (i.e. on ther path)
        *
  +     * @param exec the name of the executable
  +     * @param searchPath if true, the excutable will be looked up in
  +     * the PATH environment and the absolute path is returned.
  +     *
        * @return the executable as a full path if it can be determined.
        *
        * @since Ant 1.6
        */
  -    protected String resolveExecutable(String exec) {
  +    protected String resolveExecutable(String exec, boolean searchPath) {
           if (!resolveExecutable) {
               return exec;
           }
  @@ -377,9 +394,9 @@
               return executableFile.getAbsolutePath();
           }
   
  +        FileUtils fileUtils = FileUtils.newFileUtils();
           // now try to resolve against the dir if given
           if (dir != null) {
  -            FileUtils fileUtils = FileUtils.newFileUtils();
               executableFile = fileUtils.resolveFile(dir, exec);
               if (executableFile.exists()) {
                   return executableFile.getAbsolutePath();
  @@ -387,6 +404,32 @@
           }
   
           // couldn't find it - must be on path
  +        if (searchPath) {
  +            Vector env = Execute.getProcEnvironment();
  +            Enumeration e = env.elements();
  +            Path p = null;
  +            while (e.hasMoreElements()) {
  +                String line = (String) e.nextElement();
  +                if (line.startsWith("PATH=") || line.startsWith("Path=")) {
  +                    p = new Path(getProject(), line.substring(5));
  +                    break;
  +                }
  +            }
  +
  +            if (p != null) {
  +                String[] dirs = p.list();
  +                for (int i = 0; i < dirs.length; i++) {
  +                    executableFile = fileUtils.resolveFile(new File(dirs[i]),
  +                                                           exec);
  +                    if (executableFile.exists()) {
  +                        return executableFile.getAbsolutePath();
  +                    }
  +                }
  +            }
  +        }
  +
  +        // searchPath is false, or no PATH or not found - keep our
  +        // fingers crossed.
           return exec;
       }
   
  @@ -402,7 +445,7 @@
        */
       public void execute() throws BuildException {
           File savedDir = dir; // possibly altered in prepareExec
  -        cmdl.setExecutable(resolveExecutable(executable));
  +        cmdl.setExecutable(resolveExecutable(executable, false));
           checkConfiguration();
           if (isValidOs()) {
               try {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to