You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/09/26 14:00:51 UTC

svn commit: r699288 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTypes/mapper.html src/main/org/apache/tools/ant/types/defaults.properties src/main/org/apache/tools/ant/util/FirstMatchMapper.java src/tests/antunit/types/firstmatch-test.xml

Author: bodewig
Date: Fri Sep 26 05:00:51 2008
New Revision: 699288

URL: http://svn.apache.org/viewvc?rev=699288&view=rev
Log:
Add a firstmatchmapper.  PR 44873.

Added:
    ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java   (with props)
    ant/core/trunk/src/tests/antunit/types/firstmatch-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTypes/mapper.html
    ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=699288&r1=699287&r2=699288&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Sep 26 05:00:51 2008
@@ -385,6 +385,11 @@
  * <compositemapper>'s order of results is now predictable.
    Bugzilla Report 44873
 
+ * a new <firstmatchmapper> has been added, which works similar to
+   <compositemapper> but only returns the results of the first nested
+   mapper that matches.
+   Bugzilla Report 44873
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTypes/mapper.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/mapper.html?rev=699288&r1=699287&r2=699288&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/mapper.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/mapper.html Fri Sep 26 05:00:51 2008
@@ -887,6 +887,39 @@
     <code>&lt;mapper <b>type</b>&gt;</code> attribute.
   </p>
 
+<h4><a name="firstmatch-mapper">firstmatchmapper (since Ant 1.8.0)</a></h4>
+    <p>
+      This mapper supports an arbitrary number of nested mappers and
+      returns the results of the first mapper that matches.  This is
+      different from <a href="#composite-mapper">composite mapper</a>
+      which collects the results of all matching children.</p>
+<b>Examples:</b>
+<blockquote><pre>
+&lt;firstmatchmapper&gt;
+  &lt;globmapper from="*.txt" to="*.bak"/&gt;
+  &lt;globmapper from="*A.*" to="*B.*"/&gt;
+&lt;/firstmatchmapper&gt;
+</pre></blockquote>
+
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Source file name</b></td>
+    <td valign="top"><b>Target file names</b></td>
+  </tr>
+  <tr>
+    <td valign="center"><code>foo/bar/A.txt</code></td>
+    <td valign="top"><code>foo/bar/A.bak</code></td>
+  </tr>
+  <tr>
+    <td valign="center"><code>foo/bar/A.java</code></td>
+    <td valign="top"><code>foo/bar/B.java</code></td>
+  </tr>
+</table>
+
+  <p>The firstmatchmapper has no corresponding
+    <code>&lt;mapper <b>type</b>&gt;</code> attribute.
+  </p>
+
 
 
 </body>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties?rev=699288&r1=699287&r2=699288&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/defaults.properties Fri Sep 26 05:00:51 2008
@@ -45,6 +45,7 @@
 compositemapper=org.apache.tools.ant.util.CompositeMapper
 chainedmapper=org.apache.tools.ant.util.ChainedMapper
 filtermapper=org.apache.tools.ant.types.mappers.FilterMapper
+firstmatchmapper=org.apache.tools.ant.util.FirstMatchMapper
 
 #this condition is in here because it is the sole
 #condition defined in Ant1.6

Added: ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java?rev=699288&view=auto
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java (added)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java Fri Sep 26 05:00:51 2008
@@ -0,0 +1,48 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * A <CODE>ContainerMapper</CODE> that returns the results of its
+ * first constituent <CODE>FileNameMapper</CODE>s that matches.
+ *
+ * @since Ant 1.8.0
+ */
+public class FirstMatchMapper extends ContainerMapper {
+
+    /** {@inheritDoc}. */
+    public String[] mapFileName(String sourceFileName) {
+        for (Iterator iter = getMappers().iterator(); iter.hasNext();) {
+            FileNameMapper mapper = (FileNameMapper) iter.next();
+            if (mapper != null) {
+                String[] mapped = mapper.mapFileName(sourceFileName);
+                if (mapped != null) {
+                    return mapped;
+                }
+            }
+        }
+        return null;
+    }
+
+}
+

Propchange: ant/core/trunk/src/main/org/apache/tools/ant/util/FirstMatchMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ant/core/trunk/src/tests/antunit/types/firstmatch-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/firstmatch-test.xml?rev=699288&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/firstmatch-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/firstmatch-test.xml Fri Sep 26 05:00:51 2008
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<project xmlns:au="antlib:org.apache.ant.antunit"
+         name="firstmatch-test"
+         default="antunit">
+
+  <import file="../antunit-base.xml" />
+
+  <target name="testMatch">
+    <mkdir dir="${input}"/>
+    <touch file="${input}/A"/>
+    <touch file="${input}/B"/>
+    <mkdir dir="${output}"/>
+    <copy todir="${output}" enablemultiplemappings="true">
+      <fileset dir="${input}"/>
+      <firstmatchmapper>
+        <globmapper from="A" to="A.txt"/>
+        <identitymapper/>
+      </firstmatchmapper>
+    </copy>
+    <au:assertFileExists file="${output}/A.txt"/>
+    <au:assertFileExists file="${output}/B"/>
+    <au:assertFileDoesntExist file="${output}/A"/>
+    <au:assertFileDoesntExist file="${output}/B.txt"/>
+  </target>
+</project>

Propchange: ant/core/trunk/src/tests/antunit/types/firstmatch-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native