Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 32750 invoked from network); 16 Apr 2004 08:36:50 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 16 Apr 2004 08:36:50 -0000 Received: (qmail 16053 invoked by uid 500); 16 Apr 2004 08:36:23 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 15893 invoked by uid 500); 16 Apr 2004 08:36:22 -0000 Mailing-List: contact dev-help@ant.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 dev@ant.apache.org Received: (qmail 15878 invoked by uid 500); 16 Apr 2004 08:36:22 -0000 Received: (qmail 15871 invoked from network); 16 Apr 2004 08:36:22 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 16 Apr 2004 08:36:22 -0000 Received: (qmail 32719 invoked by uid 1146); 16 Apr 2004 08:36:46 -0000 Date: 16 Apr 2004 08:36:46 -0000 Message-ID: <20040416083646.32718.qmail@minotaur.apache.org> From: bodewig@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs StyleTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N bodewig 2004/04/16 01:36:46 Modified: . Tag: ANT_16_BRANCH WHATSNEW docs/manual/CoreTasks Tag: ANT_16_BRANCH style.html src/etc/testcases/taskdefs/style Tag: ANT_16_BRANCH build.xml src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH XSLTProcess.java src/testcases/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH StyleTest.java Log: merge Revision Changes Path No revision No revision 1.503.2.70 +2 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.503.2.69 retrieving revision 1.503.2.70 diff -u -r1.503.2.69 -r1.503.2.70 --- WHATSNEW 16 Apr 2004 07:49:42 -0000 1.503.2.69 +++ WHATSNEW 16 Apr 2004 08:36:46 -0000 1.503.2.70 @@ -71,6 +71,8 @@ * now also captures stderr output. Bugzilla Report 28349. +* now supports a nested . Bugzilla Report 11249. + Changes from Ant 1.6.0 to Ant 1.6.1 =================================== No revision No revision 1.29.2.4 +19 -1 ant/docs/manual/CoreTasks/style.html Index: style.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/style.html,v retrieving revision 1.29.2.3 retrieving revision 1.29.2.4 diff -u -r1.29.2.3 -r1.29.2.4 --- style.html 9 Feb 2004 22:12:07 -0000 1.29.2.3 +++ style.html 16 Apr 2004 08:36:46 -0000 1.29.2.4 @@ -57,7 +57,8 @@ extension desired file extension to be used for the targets. If not - specified, the default is ".html". + specified, the default is ".html". Will be ignored if + a nested <mapper> has been specified. No @@ -289,6 +290,16 @@ +

mapper

+ +

since Ant 1.6.2

+ +

You can define filename transformations by using a nested mapper element. The default mapper +used by <xslt> removes the file extension from the +source file and adds the extension specified via the extension +attribute.

+

Examples

  @@ -335,6 +346,13 @@
       <attribute name="http://xml.apache.org/xalan/features/optimize" value="true"/>
     </factory>
   </xslt>
+ +

Using a mapper

+
<xslt basedir="in" destdir="out"
  +      style="style/apache.xsl">
  +  <mapper type="glob" from="*.xml.en" to="*.html.en"/>
  +</xslt>
+

Copyright © 2000-2004 The Apache Software Foundation. All rights No revision No revision 1.3.2.1 +15 -0 ant/src/etc/testcases/taskdefs/style/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/style/build.xml,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- build.xml 12 Sep 2003 13:59:35 -0000 1.3 +++ build.xml 16 Apr 2004 08:36:46 -0000 1.3.2.1 @@ -42,6 +42,21 @@ + + + + + + + + + + No revision No revision 1.78.2.6 +64 -7 ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java Index: XSLTProcess.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v retrieving revision 1.78.2.5 retrieving revision 1.78.2.6 diff -u -r1.78.2.5 -r1.78.2.6 --- XSLTProcess.java 16 Apr 2004 07:49:42 -0000 1.78.2.5 +++ XSLTProcess.java 16 Apr 2004 08:36:46 -0000 1.78.2.6 @@ -25,9 +25,11 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DynamicConfigurator; import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Mapper; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.XMLCatalog; +import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.FileUtils; /** @@ -133,6 +135,13 @@ private AntClassLoader loader = null; /** + * Mapper to use when a set of files gets processed. + * + * @since Ant 1.6.2 + */ + private Mapper mapperElement = null; + + /** * Creates a new XSLTProcess Task. */ public XSLTProcess() { @@ -163,6 +172,21 @@ } /** + * Defines the mapper to map source to destination files. + * @return a mapper to be configured + * @exception BuildException if more than one mapper is defined + * @since Ant 1.6.2 + */ + public Mapper createMapper() throws BuildException { + if (mapperElement != null) { + throw new BuildException("Cannot define more than one mapper", + getLocation()); + } + mapperElement = new Mapper(getProject()); + return mapperElement; + } + + /** * Executes the task. * * @exception BuildException if there is an execution problem. @@ -437,7 +461,6 @@ File stylesheet) throws BuildException { - String fileExt = targetExtension; File outFile = null; File inFile = null; @@ -451,13 +474,26 @@ return; } - int dotPos = xmlFile.lastIndexOf('.'); - if (dotPos > 0) { - outFile = new File(destDir, - xmlFile.substring(0, xmlFile.lastIndexOf('.')) + fileExt); + FileNameMapper mapper = null; + if (mapperElement != null) { + mapper = mapperElement.getImplementation(); } else { - outFile = new File(destDir, xmlFile + fileExt); + mapper = new StyleMapper(); + } + + String[] outFileName = mapper.mapFileName(xmlFile); + if (outFileName == null || outFileName.length == 0) { + log("Skipping " + inFile + " it cannot get mapped to output.", + Project.MSG_VERBOSE); + return; + } else if (outFileName == null || outFileName.length > 1) { + log("Skipping " + inFile + " its mapping is ambiguos.", + Project.MSG_VERBOSE); + return; } + + outFile = new File(destDir, outFileName[0]); + if (force || inFile.lastModified() > outFile.lastModified() || styleSheetLastModified > outFile.lastModified()) { @@ -921,5 +957,26 @@ } // -- class Attribute } // -- class Factory + + /** + * Mapper implementation of the "traditional" way <xslt> + * mapped filenames. + * + *

If the file has an extension, chop it off. Append whatever + * the user has specified as extension or ".html".

+ * + * @since Ant 1.6.2 + */ + private class StyleMapper implements FileNameMapper { + public void setFrom(String from) {} + public void setTo(String to) {} + public String[] mapFileName(String xmlFile) { + int dotPos = xmlFile.lastIndexOf('.'); + if (dotPos > 0) { + xmlFile = xmlFile.substring(0, dotPos); + } + return new String[] {xmlFile + targetExtension}; + } + } } No revision No revision 1.6.2.5 +14 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java Index: StyleTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java,v retrieving revision 1.6.2.4 retrieving revision 1.6.2.5 diff -u -r1.6.2.4 -r1.6.2.5 --- StyleTest.java 9 Mar 2004 17:02:02 -0000 1.6.2.4 +++ StyleTest.java 16 Apr 2004 08:36:46 -0000 1.6.2.5 @@ -82,6 +82,20 @@ } + public void testDefaultMapper() throws Exception { + assertTrue(!getProject().resolveFile("out/data.html").exists()); + expectFileContains("testDefaultMapper", + "out/data.html", + "set='myvalue'"); + } + + public void testCustomMapper() throws Exception { + assertTrue(!getProject().resolveFile("out/out.xml").exists()); + expectFileContains("testCustomMapper", + "out/out.xml", + "set='myvalue'"); + } + // ************* copied from ConcatTest ************* // ------------------------------------------------------ --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org