Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 50236 invoked from network); 27 Sep 2002 06:59:25 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 27 Sep 2002 06:59:25 -0000 Received: (qmail 11223 invoked by uid 97); 27 Sep 2002 07:00:15 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 11168 invoked by uid 97); 27 Sep 2002 07:00:14 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 11157 invoked by uid 97); 27 Sep 2002 07:00:13 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Date: 27 Sep 2002 06:59:17 -0000 Message-ID: <20020927065917.28857.qmail@icarus.apache.org> From: bodewig@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs BasenameTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 @@ * created an empty junit-noframes.html if no format had been specified. +* 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 @@ + + + + + + + + + + + + + + + + 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: For additional commands, e-mail: