ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs StyleTest.java
Date Fri, 16 Apr 2004 08:36:46 GMT
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 @@
   
   * <sshexec> now also captures stderr output.  Bugzilla Report 28349.
   
  +* <xslt> now supports a nested <mapper>.  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 @@
     <tr>
       <td valign="top">extension</td>
       <td valign="top">desired file extension to be used for the targets. If not
  -      specified, the default is &quot;.html&quot;.</td>
  +      specified, the default is &quot;.html&quot;.  Will be ignored if
  +      a nested &lt;mapper&gt; has been specified.</td>
       <td align="center" valign="top">No</td>
     </tr>
     <tr>
  @@ -289,6 +290,16 @@
   </table>
   </blockquote>
   
  +<h4>mapper</h4>
  +
  +<p><em>since Ant 1.6.2</em></p>
  +
  +<p>You can define filename transformations by using a nested <a
  +href="../CoreTypes/mapper.html">mapper</a> element. The default mapper
  +used by <code>&lt;xslt&gt;</code> removes the file extension from the
  +source file and adds the extension specified via the extension
  +attribute.</p>
  +
   <h3>Examples</h3>
   <blockquote>
     <pre>
  @@ -335,6 +346,13 @@
       &lt;attribute name=&quot;http://xml.apache.org/xalan/features/optimize&quot;
value=&quot;true&quot;/&gt;
     &lt;/factory&gt;
   &lt;/xslt&gt;</pre>
  +
  +  <h4>Using a mapper</h4>
  +<pre>&lt;xslt basedir=&quot;in&quot; destdir=&quot;out&quot;
  +      style=&quot;style/apache.xsl&quot;&gt;
  +  &lt;mapper type=&quot;glob&quot; from=&quot;*.xml.en&quot; to=&quot;*.html.en&quot;/&gt;
  +&lt;/xslt&gt;</pre>
  +
    </blockquote>
   <hr>
   <p align="center">Copyright &copy; 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 @@
         </style>
     </target>
   
  +  <target name="testDefaultMapper">
  +    <property name="value" value="myvalue"/>
  +    <style style="printParams.xsl" destDir="${out.dir}" basedir=".">
  +      <param name="set" expression="${value}"/>
  +    </style>
  +  </target>
  +
  +  <target name="testCustomMapper">
  +    <property name="value" value="myvalue"/>
  +    <style style="printParams.xsl" destDir="${out.dir}" basedir=".">
  +      <param name="set" expression="${value}"/>
  +      <mapper type="glob" from="data.*" to="out.*"/>
  +    </style>
  +  </target>
  +
     <target name="testNewerStylesheet">
         <antcall target="copyXsl">
           <param name="xsl.value" value="old-value"/>
  
  
  
  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 &lt;xslt&gt;
  +     * mapped filenames.
  +     *
  +     * <p>If the file has an extension, chop it off.  Append whatever
  +     * the user has specified as extension or ".html".</p>
  +     *
  +     * @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


Mime
View raw message