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/taskdefs BasenameTest.java
Date Fri, 27 Sep 2002 06:59:17 GMT
bodewig     2002/09/26 23:59:17

  Modified:    .        Tag: ANT_15_BRANCH WHATSNEW
               src/etc/testcases/taskdefs Tag: ANT_15_BRANCH basename.xml
               src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
                        Basename.java
               src/testcases/org/apache/tools/ant/taskdefs Tag:
                        ANT_15_BRANCH BasenameTest.java
  Log:
  Merge basename suffix fix from CVS HEAD
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.263.2.82 +3 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.263.2.81
  retrieving revision 1.263.2.82
  diff -u -r1.263.2.81 -r1.263.2.82
  --- WHATSNEW	27 Sep 2002 06:20:13 -0000	1.263.2.81
  +++ WHATSNEW	27 Sep 2002 06:59:16 -0000	1.263.2.82
  @@ -9,6 +9,9 @@
   * <junitreport> created an empty junit-noframes.html if no format had
     been specified.
   
  +* <basename> would remove more than it should if the file name
  +  contained more than one dot.
  +
   Other changes:
   --------------
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +16 -0     jakarta-ant/src/etc/testcases/taskdefs/basename.xml
  
  Index: basename.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/basename.xml,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- basename.xml	20 Mar 2002 02:48:15 -0000	1.1
  +++ basename.xml	27 Sep 2002 06:59:16 -0000	1.1.2.1
  @@ -22,4 +22,20 @@
       <basename property="file.wo.suf" file="foo.txt" suffix="txt"/>
     </target>
   
  +  <target name="testMultipleDots">
  +    <basename property="file.wo.suf" file="foo.bar.txt" suffix="txt"/>
  +  </target>
  +
  +  <target name="testNoDots">
  +    <basename property="file.wo.suf" file="foo.bartxt" suffix="txt"/>
  +  </target>
  +  
  +  <target name="testValueEqualsSuffixWithDot">
  +    <basename property="file.wo.suf" file=".txt" suffix=".txt"/>
  +  </target>
  +
  +  <target name="testValueEqualsSuffixWithoutDot">
  +    <basename property="file.wo.suf" file=".txt" suffix="txt"/>
  +  </target>
  +  
   </project>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.4   +16 -11    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Basename.java
  
  Index: Basename.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Basename.java,v
  retrieving revision 1.2.2.3
  retrieving revision 1.2.2.4
  diff -u -r1.2.2.3 -r1.2.2.4
  --- Basename.java	23 Jun 2002 03:27:07 -0000	1.2.2.3
  +++ Basename.java	27 Sep 2002 06:59:16 -0000	1.2.2.4
  @@ -118,20 +118,25 @@
   
     // The method executing the task
     public void execute() throws BuildException {
  -      String value;
         if (property == null) {
  -          throw new BuildException("property attribute required", location);
  +          throw new BuildException("property attribute required", getLocation());
         }
         if (file == null) {
  -          throw new BuildException("file attribute required", location);
  -      } else {
  -        value = file.getName();
  -        if (suffix != null && value.endsWith(suffix)) {
  -            int pos = value.indexOf('.');
  -            value = value.substring(0, pos);
  -        }
  -        getProject().setNewProperty(property, value);
  +          throw new BuildException("file attribute required", getLocation());
         }
  +      String value = file.getName();
  +      if (suffix != null && value.endsWith(suffix)) {
  +          // if the suffix does not starts with a '.' and the
  +          // char preceding the suffix is a '.', we assume the user
  +          // wants to remove the '.' as well (see docs)
  +          int pos = value.length() - suffix.length();
  +          if (pos > 0 && suffix.charAt(0) != '.' 
  +              && value.charAt(pos - 1) == '.') {
  +              pos--;
  +          }
  +          value = value.substring(0, pos);
  +      }
  +      getProject().setNewProperty(property, value);
     }
   }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.1   +26 -8     jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/BasenameTest.java
  
  Index: BasenameTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/BasenameTest.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- BasenameTest.java	20 Mar 2002 02:56:57 -0000	1.2
  +++ BasenameTest.java	27 Sep 2002 06:59:16 -0000	1.2.2.1
  @@ -84,20 +84,38 @@
   
       public void test4() { 
           executeTarget("test4");
  -        String expected = "foo.txt";
           String checkprop = project.getProperty("file.w.suf");
  -        if (!checkprop.equals(expected)) { 
  -            fail("basename failed");
  -        }
  +        assertEquals("foo.txt", checkprop);
       }
       
       public void test5() { 
           executeTarget("test5");
  -        String expected = "foo";
           String checkprop = project.getProperty("file.wo.suf");
  -        if (!checkprop.equals(expected)) { 
  -            fail("basename failed");
  -        }
  +        assertEquals("foo", checkprop);
       }
       
  +    public void testMultipleDots() { 
  +        executeTarget("testMultipleDots");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("foo.bar", checkprop);
  +    }
  +    
  +    public void testNoDots() { 
  +        executeTarget("testNoDots");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("foo.bar", checkprop);
  +    }
  +
  +    public void testValueEqualsSuffixWithDot() { 
  +        executeTarget("testValueEqualsSuffixWithDot");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("", checkprop);
  +    }
  +
  +    public void testValueEqualsSuffixWithoutDot() { 
  +        executeTarget("testValueEqualsSuffixWithoutDot");
  +        String checkprop = project.getProperty("file.wo.suf");
  +        assertEquals("", checkprop);
  +    }
  +
   }
  
  
  

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