ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ExecTask.java ExecuteOn.java
Date Wed, 10 Apr 2002 10:27:53 GMT
bodewig     02/04/10 03:27:52

  Modified:    src/main/org/apache/tools/ant/taskdefs ExecTask.java
                        ExecuteOn.java
  Log:
  Bug 7552 auditing of <exec> - dir may have been altered in execute.
  
  Fix backwards incompatible API change I've introduced last week
  (setTimeout's argument has been changed from Integer to Long).
  
  Fix the code in <apply> that should ensure that dest has been
  specified.
  
  Revision  Changes    Path
  1.32      +46 -18    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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- ExecTask.java	5 Apr 2002 12:56:34 -0000	1.31
  +++ ExecTask.java	10 Apr 2002 10:27:52 -0000	1.32
  @@ -59,6 +59,7 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.Environment;
  +import org.apache.tools.ant.util.StringUtils;
   
   import java.io.File;
   import java.io.FileOutputStream;
  @@ -81,8 +82,6 @@
    */
   public class ExecTask extends Task {
   
  -    private static String lSep = System.getProperty("line.separator");
  -
       private String os;
       private File out;
       private File dir;
  @@ -98,17 +97,33 @@
       private boolean failIfExecFails=true;
       private boolean append = false;
   
  -    /** Controls whether the VM (1.3 and above) is used to execute the command */
  +    /** 
  +     * Controls whether the VM (1.3 and above) is used to execute the
  +     * command 
  +     */
       private boolean vmLauncher = true;
   
       /**
        * Timeout in milliseconds after which the process will be killed.
  +     *
  +     * @since Ant 1.5
        */
       public void setTimeout(Long value) {
           timeout = value;
       }
   
       /**
  +     * Timeout in milliseconds after which the process will be killed.
  +     */
  +    public void setTimeout(Integer value) {
  +        if (value == null) {
  +            timeout = null;
  +        } else {
  +            setTimeout(new Long(value.intValue()));
  +        }
  +    }
  +
  +    /**
        * The command to execute.
        */
       public void setExecutable(String value) {
  @@ -123,7 +138,8 @@
       }
   
       /**
  -     * Only execute the process if <code>os.name</code> is included in this
string.
  +     * Only execute the process if <code>os.name</code> is included in
  +     * this string.
        */
       public void setOs(String os) {
           this.os = os;
  @@ -185,7 +201,8 @@
       /**
        * fill a property in with a result. 
        * when no property is defined: failure to execute
  -     * @since 1.5
  +     *
  +     * @since Ant 1.5
        */
       public void setResultProperty(String resultProperty) {
           this.resultProperty=resultProperty;
  @@ -222,9 +239,14 @@
        * Do the work.
        */
       public void execute() throws BuildException {
  +        File savedDir = dir; // possibly altered in prepareExec
           checkConfiguration();
           if (isValidOs()) {
  -            runExec(prepareExec());
  +            try {
  +                runExec(prepareExec());
  +            } finally {
  +                dir = savedDir;
  +            }
           }
       }
   
  @@ -272,13 +294,13 @@
       protected Execute prepareExec() throws BuildException {
           // default directory to the project's base directory
           if (dir == null) {
  -          dir = project.getBaseDir();
  +            dir = project.getBaseDir();
           }
           // show the command
           log(cmdl.toString(), Project.MSG_VERBOSE);
   
           Execute exe = new Execute(createHandler(), createWatchdog());
  -        exe.setAntRun(project);
  +        exe.setAntRun(getProject());
           exe.setWorkingDirectory(dir);
           exe.setVMLauncher(vmLauncher);
           String[] environment = env.getVariables();
  @@ -294,7 +316,8 @@
       }
   
       /**
  -     * A Utility method for this classes and subclasses to run an Execute instance (an
external command).
  +     * A Utility method for this classes and subclasses to run an
  +     * Execute instance (an external command).
        */
       protected final void runExecute(Execute exe) throws IOException {
           int err = -1; // assume the worst
  @@ -307,7 +330,8 @@
           maybeSetResultPropertyValue(err);
           if (err != 0) {
               if (failOnError) {
  -                throw new BuildException(taskType + " returned: "+err, location);
  +                throw new BuildException(taskType + " returned: "+err, 
  +                                         location);
               } else {
                   log("Result: " + err, Project.MSG_ERR);
               }
  @@ -319,7 +343,7 @@
               StringBuffer val = new StringBuffer();
               while ((line = in.readLine()) != null) {
                   if (val.length() != 0) {
  -                    val.append(lSep);
  +                    val.append(StringUtils.LINE_SEP);
                   }
                   val.append(line);
               }
  @@ -328,7 +352,8 @@
       }
   
       /**
  -     * Run the command using the given Execute instance. This may be overidden by subclasses
  +     * Run the command using the given Execute instance. This may be
  +     * overidden by subclasses
        */
       protected void runExec(Execute exe) throws BuildException {
           exe.setCommandline(cmdl.getCommandline());
  @@ -336,7 +361,8 @@
               runExecute(exe);
           } catch (IOException e) {
               if (failIfExecFails) {
  -                throw new BuildException("Execute failed: "+e.toString(),e, location);
  +                throw new BuildException("Execute failed: "+e.toString(), e, 
  +                                         location);
               } else {
                   log("Execute failed: "+e.toString(), Project.MSG_ERR);
               }
  @@ -356,9 +382,11 @@
                   log("Output redirected to " + out, Project.MSG_VERBOSE);
                   return new PumpStreamHandler(fos);
               } catch (FileNotFoundException fne) {
  -                throw new BuildException("Cannot write to "+out, fne, location);
  +                throw new BuildException("Cannot write to "+out, fne, 
  +                                         location);
               } catch (IOException ioe) {
  -                throw new BuildException("Cannot write to "+out, ioe, location);
  +                throw new BuildException("Cannot write to "+out, ioe, 
  +                                         location);
               }
           } else if (outputprop != null) {
               baos = new ByteArrayOutputStream();
  @@ -375,7 +403,7 @@
        */
       protected ExecuteWatchdog createWatchdog() throws BuildException {
           if (timeout == null) {
  -          return null;
  +            return null;
           }
           return new ExecuteWatchdog(timeout.longValue());
       }
  @@ -386,10 +414,10 @@
       protected void logFlush() {
           try {
               if (fos != null) {
  -              fos.close();
  +                fos.close();
               }
               if (baos != null) {
  -              baos.close();
  +                baos.close();
               }
           } catch (IOException io) {}
       }
  
  
  
  1.23      +5 -5      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java
  
  Index: ExecuteOn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteOn.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ExecuteOn.java	4 Mar 2002 08:49:35 -0000	1.22
  +++ ExecuteOn.java	10 Apr 2002 10:27:52 -0000	1.23
  @@ -144,8 +144,8 @@
        */
       public Commandline.Marker createSrcfile() {
           if (srcFilePos != null) {
  -            throw new BuildException(taskType + " doesn\'t support multiple srcfile elements.",
  -                                     location);
  +            throw new BuildException(taskType + " doesn\'t support multiple "
  +                                     + "srcfile elements.", location);
           }
           srcFilePos = cmdl.createMarker();
           return srcFilePos;
  @@ -157,8 +157,8 @@
        */
       public Commandline.Marker createTargetfile() {
           if (targetFilePos != null) {
  -            throw new BuildException(taskType + " doesn\'t support multiple targetfile
elements.",
  -                                     location);
  +            throw new BuildException(taskType + " doesn\'t support multiple "
  +                                     + "targetfile elements.", location);
           }
           targetFilePos = cmdl.createMarker();
           srcIsFirst = (srcFilePos != null);
  @@ -193,7 +193,7 @@
               if (mapperElement == null) {
                   throw new BuildException("no mapper specified", location);
               }
  -            if (mapperElement == null) {
  +            if (destDir == null) {
                   throw new BuildException("no dest attribute specified", 
                                            location);
               }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message