You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2003/01/27 15:51:50 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ExecTask.java

conor       2003/01/27 06:51:50

  Modified:    src/main/org/apache/tools/ant/taskdefs ExecTask.java
  Log:
  Resolve the executable if possible in <exec>
  
  PR:	16040
  
  Revision  Changes    Path
  1.43      +32 -2     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  
  Index: ExecTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -w -u -r1.42 -r1.43
  --- ExecTask.java	25 Jul 2002 15:21:04 -0000	1.42
  +++ ExecTask.java	27 Jan 2003 14:51:49 -0000	1.43
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -67,6 +67,7 @@
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.Environment;
   import org.apache.tools.ant.util.StringUtils;
  +import org.apache.tools.ant.util.FileUtils;
   
   /**
    * Executes a given command if the os platform is appropriate.
  @@ -97,6 +98,7 @@
       private String resultProperty;
       private boolean failIfExecFails = true;
       private boolean append = false;
  +    private String executable;
   
       /**
        * Controls whether the VM (1.3 and above) is used to execute the
  @@ -128,7 +130,7 @@
        * The command to execute.
        */
       public void setExecutable(String value) {
  -        cmdl.setExecutable(value);
  +        this.executable = value;
       }
   
       /**
  @@ -239,10 +241,38 @@
       }
   
       /**
  +     * Attempt to figure out where the executable is so that we can feed 
  +     * the full path - first try basedir, then the exec dir and then
  +     * fallback to the straight executable name (i.e. on ther path)
  +     *
  +     * @return the executable as a full path if it can be determined.
  +     */
  +    private String resolveExecutable() {
  +        // try to find the executable
  +        File executableFile = getProject().resolveFile(executable);
  +        if (executableFile.exists()) {
  +            return executableFile.getAbsolutePath();
  +        }
  +        
  +        // now try to resolve against the dir if given
  +        if (dir != null) {
  +            FileUtils fileUtils = FileUtils.newFileUtils();
  +            executableFile = fileUtils.resolveFile(dir, executable);
  +            if (executableFile.exists()) {
  +                return executableFile.getAbsolutePath();
  +            }
  +        }
  +
  +        // couldn't find it - must be on path
  +        return executable;            
  +    }
  +    
  +    /**
        * Do the work.
        */
       public void execute() throws BuildException {
           File savedDir = dir; // possibly altered in prepareExec
  +        cmdl.setExecutable(resolveExecutable());
           checkConfiguration();
           if (isValidOs()) {
               try {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ExecTask.java

Posted by Stefan Bodewig <bo...@apache.org>.
On 27 Jan 2003, <co...@apache.org> wrote:

>   Resolve the executable if possible in <exec>

Please provide an extra option to enable this behavior.  I wouldn't
want this to be the default for the very same reason the "." is not in
my PATH.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>