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/testcases/org/apache/tools/ant/util FileUtilsTest.java
Date Tue, 28 May 2002 06:13:11 GMT
bodewig     02/05/27 23:13:11

  Modified:    src/etc/testcases/taskdefs Tag: ANT_15_BRANCH available.xml
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Available.java Definer.java
               src/main/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        FileUtils.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_15_BRANCH AvailableTest.java
               src/testcases/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        FileUtilsTest.java
  Log:
  Change signature of Available#setFile back to a File argument without
  breaking the path seatch ability.
  
  PR: 9079
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.2   +10 -0     jakarta-ant/src/etc/testcases/taskdefs/available.xml
  
  Index: available.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/available.xml,v
  retrieving revision 1.9.2.1
  retrieving revision 1.9.2.2
  diff -u -r1.9.2.1 -r1.9.2.2
  --- available.xml	21 May 2002 09:52:23 -0000	1.9.2.1
  +++ available.xml	28 May 2002 06:13:10 -0000	1.9.2.2
  @@ -141,4 +141,14 @@
       <delete dir="${user.dir}/test"/>
       <delete file="${user.dir}/test.jar"/>
     </target>
  +
  +  <target name="searchInPathNotThere">
  +    <available file="not_there" filepath="..:optional"
  +               property="test" />
  +  </target>
  +
  +  <target name="searchInPathIsThere">
  +    <available file="pvcs.xml" filepath="..:optional"
  +               property="test" />
  +  </target>
   </project>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.44.2.2  +3 -2      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java
  
  Index: Available.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java,v
  retrieving revision 1.44.2.1
  retrieving revision 1.44.2.2
  diff -u -r1.44.2.1 -r1.44.2.2
  --- Available.java	7 May 2002 12:06:49 -0000	1.44.2.1
  +++ Available.java	28 May 2002 06:13:10 -0000	1.44.2.2
  @@ -185,8 +185,9 @@
        *
        * @param file the name of the file which is required.
        */
  -    public void setFile(String file) {
  -        this.file = file;
  +    public void setFile(File f) {
  +        this.file = FileUtils.newFileUtils()
  +            .removeLeadingPath(getProject().getBaseDir(), f);
       }
   
       /**
  
  
  
  1.15.2.4  +3 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java
  
  Index: Definer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v
  retrieving revision 1.15.2.3
  retrieving revision 1.15.2.4
  diff -u -r1.15.2.3 -r1.15.2.4
  --- Definer.java	27 May 2002 15:15:36 -0000	1.15.2.3
  +++ Definer.java	28 May 2002 06:13:10 -0000	1.15.2.4
  @@ -128,6 +128,8 @@
        * This allow multiple taskdef/typedef to use the same class loader,
        * so they can be used togheter. It eliminate the need to
        * put them in the CLASSPATH.
  +     *
  +     * @since Ant 1.5
        */
       public void setLoaderRef(Reference r) {
           loaderId = r.getRefId();
  @@ -240,7 +242,7 @@
           if (loaderId != null) {
               Object reusedLoader = project.getReference(loaderId);
               if (reusedLoader != null) {
  -                if(reusedLoader instanceof AntClassLoader) {
  +                if (reusedLoader instanceof AntClassLoader) {
                       return (AntClassLoader)reusedLoader;
                   }
                   // In future the reference object may be the <loader> type
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.25.2.3  +25 -1     jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.25.2.2
  retrieving revision 1.25.2.3
  diff -u -r1.25.2.2 -r1.25.2.3
  --- FileUtils.java	23 May 2002 05:37:37 -0000	1.25.2.2
  +++ FileUtils.java	28 May 2002 06:13:10 -0000	1.25.2.3
  @@ -95,7 +95,7 @@
    * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
    * @author <a href="mailto:jtulley@novell.com">Jeff Tulley</a> 
    *
  - * @version $Revision: 1.25.2.2 $
  + * @version $Revision: 1.25.2.3 $
    */
   
   public class FileUtils {
  @@ -854,5 +854,29 @@
           return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath());
       }
   
  +    /**
  +     * Removes a leading path from a second path.
  +     *
  +     * @param leading The leading path, must not be null, must be absolute.
  +     * @param path The path to remove from, must not be null, must be absolute.
  +     *
  +     * @return path's normalized absolute if it doesn't start with
  +     * leading, path's path with leading's path removed otherwise.
  +     *
  +     * @since Ant 1.5
  +     */
  +    public String removeLeadingPath(File leading, File path) {
  +        String l = normalize(leading.getAbsolutePath()).getAbsolutePath();
  +        String p = normalize(path.getAbsolutePath()).getAbsolutePath();
  +        if (p.startsWith(l)) {
  +            String result = p.substring(l.length());
  +            if (result.startsWith(File.separator)) {
  +                result = result.substring(File.separator.length());
  +            }
  +            return result;
  +        } else {
  +            return p;
  +        }
  +    }
   }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.10.2.2  +12 -0     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java
  
  Index: AvailableTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/AvailableTest.java,v
  retrieving revision 1.10.2.1
  retrieving revision 1.10.2.2
  diff -u -r1.10.2.1 -r1.10.2.2
  --- AvailableTest.java	7 May 2002 12:06:49 -0000	1.10.2.1
  +++ AvailableTest.java	28 May 2002 06:13:10 -0000	1.10.2.2
  @@ -222,4 +222,16 @@
           executeTarget("test24");
           assertEquals("true",project.getProperty("test"));
       }
  +
  +    // File is not found in specified filepath
  +    public void testSearchInPathNotThere() {
  +        executeTarget("searchInPathNotThere");
  +        assertNull(project.getProperty("test"));
  +    }
  +
  +    // File is not found in specified filepath
  +    public void testSearchInPathIsThere() {
  +        executeTarget("searchInPathIsThere");
  +        assertEquals("true",project.getProperty("test"));
  +    }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.9.2.1   +24 -0     jakarta-ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
  
  Index: FileUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java,v
  retrieving revision 1.9
  retrieving revision 1.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- FileUtilsTest.java	2 Apr 2002 08:42:44 -0000	1.9
  +++ FileUtilsTest.java	28 May 2002 06:13:11 -0000	1.9.2.1
  @@ -383,6 +383,30 @@
       }
   
       /**
  +     * Test removeLeadingPath.
  +     */
  +    public void testRemoveLeadingPath() {
  +        assertEquals("bar", fu.removeLeadingPath(new File("/foo"), 
  +                                                 new File("/foo/bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("/foo/"), 
  +                                                 new File("/foo/bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("\\foo"), 
  +                                                 new File("\\foo\\bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("\\foo\\"), 
  +                                                 new File("\\foo\\bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:/foo"), 
  +                                                 new File("c:/foo/bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:/foo/"), 
  +                                                 new File("c:/foo/bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo"), 
  +                                                 new File("c:\\foo\\bar")));
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo\\"), 
  +                                                 new File("c:\\foo\\bar")));
  +        assertEquals(fu.normalize("/bar").getAbsolutePath(), 
  +                     fu.removeLeadingPath(new File("/foo"), new File("/bar")));
  +    }
  +
  +    /**
        * adapt file separators to local conventions
        */
       private String localize(String path) {
  
  
  

--
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