ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs ExecTaskTest.java
Date Tue, 19 Apr 2005 22:26:37 GMT
stevel      2005/04/19 15:26:37

  Modified:    docs/manual/CoreTasks exec.html
               src/etc/testcases/taskdefs/exec exec.xml
               src/main/org/apache/tools/ant/taskdefs ExecTask.java
               src/testcases/org/apache/tools/ant/taskdefs
                        ExecTaskTest.java
  Log:
  Now for the fun. Exec adds an osfamily attribute, so you can restrict execution to a platform
such as nt, or unix. This propagates to execon, so into chmod, attrib, etc. We could therefore
adapt them use osfamily as their way of being unix or windows only.
  
  Revision  Changes    Path
  1.50      +9 -2      ant/docs/manual/CoreTasks/exec.html
  
  Index: exec.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/CoreTasks/exec.html,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- exec.html	30 Mar 2005 17:08:27 -0000	1.49
  +++ exec.html	19 Apr 2005 22:26:37 -0000	1.50
  @@ -17,7 +17,7 @@
   
   <p>Note that you cannot interact with the forked program, the only way
   to send input to it is via the input and inputstring attributes. Also note that
  -in Ant 1.6, any attempt to read input in the forked program will receive an
  +since Ant 1.6, any attempt to read input in the forked program will receive an
   EOF (-1). This is a change from Ant 1.5, where such an attempt would block.</p>
   
   
  @@ -115,7 +115,14 @@
       <td valign="top">list of Operating Systems on which the command may be
         executed. If the current OS's name is contained in this list, the command will
         be executed. The OS's name is determined by the Java Virtual machine and is set
  -      in the &quot;os.name&quot; system property.</td>
  +      in the &quot;os.name&quot; system property.
  +      </td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
  +  <tr>
  +    <td valign="top">osfamily</td>
  +    <td valign="top">OS family as used in the &lt;os&gt; condition.
  +    <em>since Ant 1.7</em></td>
       <td align="center" valign="top">No</td>
     </tr>
     <tr>
  
  
  
  1.6       +28 -0     ant/src/etc/testcases/taskdefs/exec/exec.xml
  
  Index: exec.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/exec/exec.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- exec.xml	24 Sep 2004 18:55:16 -0000	1.5
  +++ exec.xml	19 Apr 2005 22:26:37 -0000	1.6
  @@ -329,6 +329,34 @@
           </fail>
       </target>
   
  +    <!-- test will succeed as the OS wont match-->
  +    <target name="testExecUnknownOS">
  +      <exec executable="nonexistent-program-we-expect"
  +        failonerror="true"
  +        os="ZX81">
  +      </exec>
  +    </target>
  +
  +    <target name="testExecOSFamily">
  +      <exec executable="uptime"
  +        failonerror="true"
  +        osFamily="unix">
  +      </exec>
  +      <exec executable="time"
  +        failonerror="true"
  +        osFamily="nt">
  +        <arg value="/t" />
  +      </exec>
  +    </target>    
  +    
  +    <target name="testExecInconsistentSettings">
  +      <exec executable="nonexistent-program-we-expect"
  +        failonerror="true"
  +        osFamily="WIN9X"
  +        os="linux unix">
  +      </exec>
  +    </target>
  +    
       <target name="cleanup">
           <delete>
               <fileset file="${logFile}" />
  
  
  
  1.81      +31 -6     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.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- ExecTask.java	11 Mar 2005 20:29:00 -0000	1.80
  +++ ExecTask.java	19 Apr 2005 22:26:37 -0000	1.81
  @@ -21,10 +21,13 @@
   import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Vector;
  +import java.util.Locale;
  +
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.ProjectComponent;
  +import org.apache.tools.ant.taskdefs.condition.Os;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.Environment;
   import org.apache.tools.ant.types.Path;
  @@ -43,6 +46,7 @@
       private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
   
       private String os;
  +    private String osFamily;
   
       private File dir;
       protected boolean failOnError = false;
  @@ -383,6 +387,15 @@
   
   
       /**
  +     * Restrict this execution to a single OS Family
  +     * @param osFamily
  +     */
  +    public void setOsFamily(String osFamily) {
  +        this.osFamily = osFamily.toLowerCase(Locale.US);
  +    }
  +
  +
  +    /**
        * The method attempts to figure out where the executable is so that we can feed
        * the full path. We first try basedir, then the exec dir, and then
        * fallback to the straight executable name (i.e. on the path).
  @@ -516,21 +529,33 @@
        * @return boolean.
        * <ul>
        * <li>
  -     * <code>true</code> if the os under which Ant is running is
  -     * matches one os in the os attribute
  -     * or if the os attribute is null</li>
  +     * <li><code>true</code> if the os and osfamily attributes are null.</li>
  +     * <li><code>true</code> if osfamily is set, and the os family and
must match
  +     * that of the current OS, according to the logic of
  +     * {@link Os#isOs(String, String, String, String)}, and the result of the
  +     * <code>os</code> attribute must also evaluate true.
  +     * </li>
  +     * <li>
  +     * <code>true</code> if os is set, and the system.property os.name
  +     * is found in the os attribute,</li>
        * <li><code>false</code> otherwise.</li>
        * </ul>
        */
       protected boolean isValidOs() {
  -        // test if os match
  +        //hand osfamily off to Os class, if set
  +        if(osFamily!=null && !Os.isOs(osFamily,null,null,null)) {
  +            return false;
  +        }
  +        //the Exec OS check is different from Os.isOs(), which
  +        //probes for a specific OS. Instead it searches the os field
  +        //for the current os.name
           String myos = System.getProperty("os.name");
           log("Current OS is " + myos, Project.MSG_VERBOSE);
           if ((os != null) && (os.indexOf(myos) < 0)) {
               // this command will be executed only on the specified OS
               log("This OS, " + myos
  -                + " was not found in the specified list of valid OSes: " + os,
  -                Project.MSG_VERBOSE);
  +                    + " was not found in the specified list of valid OSes: " + os,
  +                    Project.MSG_VERBOSE);
               return false;
           }
           return true;
  
  
  
  1.19      +12 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java
  
  Index: ExecTaskTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ExecTaskTest.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ExecTaskTest.java	6 Jan 2005 12:05:04 -0000	1.18
  +++ ExecTaskTest.java	19 Apr 2005 22:26:37 -0000	1.19
  @@ -383,6 +383,18 @@
           assertTrue("log file found after spawn", logFile.exists());
       }
   
  +    public void testExecUnknownOS() {
  +        executeTarget("testExecUnknownOS");
  +    }
  +
  +    public void testExecOSFamily() {
  +        executeTarget("testExecOSFamily");
  +    }
  +
  +    public void testExecInconsistentSettings() {
  +        executeTarget("testExecInconsistentSettings");
  +    }
  +    
       private static class MonitoredBuild implements Runnable {
           private Thread worker;
           private File myBuildFile = null;
  
  
  

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


Mime
View raw message