You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2010/01/28 19:53:11 UTC

svn commit: r904213 - in /ant/core/trunk: ./ src/main/org/apache/tools/ant/types/selectors/ src/tests/antunit/types/selectors/

Author: mbenson
Date: Thu Jan 28 18:53:10 2010
New Revision: 904213

URL: http://svn.apache.org/viewvc?rev=904213&view=rev
Log:
Mapper-aware selectors (depends, different, present) now accept typedef'd FileNameMappers

Added:
    ant/core/trunk/src/tests/antunit/types/selectors/depend-test.xml   (with props)
    ant/core/trunk/src/tests/antunit/types/selectors/different-test.xml   (with props)
    ant/core/trunk/src/tests/antunit/types/selectors/present-test.xml   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
    ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=904213&r1=904212&r2=904213&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Jan 28 18:53:10 2010
@@ -31,7 +31,7 @@
 Other changes:
 --------------
 
-Changes from Ant 1.7.1 TO Ant 1.8.0RC1
+Changes from Ant 1.7.1 TO Ant 1.8.0RCx
 ======================================
 
 Changes that could break older environments:
@@ -221,6 +221,9 @@
    file. So Ant is now capable of supporting several ProjectHelper
    implementations, deciding on which to use depending of the input build file.
 
+ * Mapper-aware selectors (depends, different, present) now accept typedef'd
+   FileNameMappers.
+
 Fixed bugs:
 -----------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java?rev=904213&r1=904212&r2=904213&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/MappingSelector.java Thu Jan 28 18:53:10 2010
@@ -66,10 +66,10 @@
     /**
      * Defines the FileNameMapper to use (nested mapper element).
      * @return a mapper to be configured
-     * @throws BuildException if more that one mapper defined
+     * @throws BuildException if more than one mapper defined
      */
     public Mapper createMapper() throws BuildException {
-        if (mapperElement != null) {
+        if (map != null || mapperElement != null) {
             throw new BuildException("Cannot define more than one mapper");
         }
         mapperElement = new Mapper(getProject());
@@ -77,6 +77,19 @@
     }
 
     /**
+     * Add a configured FileNameMapper instance.
+     * @param fileNameMapper the FileNameMapper to add
+     * @throws BuildException if more than one mapper defined
+     * @since Ant 1.8.0
+     */
+    public void addConfigured(FileNameMapper fileNameMapper) {
+        if (map != null || mapperElement != null) {
+            throw new BuildException("Cannot define more than one mapper");
+        }
+        this.map = fileNameMapper;
+    }
+ 
+    /**
      * Checks to make sure all settings are kosher. In this case, it
      * means that the dest attribute has been set and we have a mapper.
      */
@@ -84,13 +97,15 @@
         if (targetdir == null) {
             setError("The targetdir attribute is required.");
         }
-        if (mapperElement == null) {
-            map = new IdentityMapper();
-        } else {
-            map = mapperElement.getImplementation();
-        }
         if (map == null) {
-            setError("Could not set <mapper> element.");
+            if (mapperElement == null) {
+                map = new IdentityMapper();
+            } else {
+                map = mapperElement.getImplementation();
+                if (map == null) {
+                    setError("Could not set <mapper> element.");
+                }
+            }
         }
     }
 
@@ -121,7 +136,7 @@
                     + targetdir.getName() + " with filename " + filename);
         }
         String destname = destfiles[0];
-        File destfile = new File(targetdir, destname);
+        File destfile = FILE_UTILS.resolveFile(targetdir, destname);
 
         boolean selected = selectionTest(file, destfile);
         return selected;

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java?rev=904213&r1=904212&r2=904213&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/PresentSelector.java Thu Jan 28 18:53:10 2010
@@ -24,6 +24,7 @@
 import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.Mapper;
 import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.IdentityMapper;
 
 /**
@@ -35,7 +36,6 @@
  * @since 1.5
  */
 public class PresentSelector extends BaseSelector {
-
     private File targetdir = null;
     private Mapper mapperElement = null;
     private FileNameMapper map = null;
@@ -86,17 +86,29 @@
     /**
      * Defines the FileNameMapper to use (nested mapper element).
      * @return a mapper to be configured
-     * @throws BuildException if more that one mapper defined
+     * @throws BuildException if more than one mapper defined
      */
     public Mapper createMapper() throws BuildException {
-        if (mapperElement != null) {
+        if (map != null || mapperElement != null) {
             throw new BuildException("Cannot define more than one mapper");
         }
         mapperElement = new Mapper(getProject());
         return mapperElement;
     }
 
-
+    /**
+     * Add a configured FileNameMapper instance.
+     * @param fileNameMapper the FileNameMapper to add
+     * @throws BuildException if more than one mapper defined
+     * @since Ant 1.8.0
+     */
+    public void addConfigured(FileNameMapper fileNameMapper) {
+        if (map != null || mapperElement != null) {
+            throw new BuildException("Cannot define more than one mapper");
+        }
+        this.map = fileNameMapper;
+    }
+ 
     /**
      * This sets whether to select a file if its dest file is present.
      * It could be a <code>negate</code> boolean, but by doing things
@@ -123,13 +135,15 @@
         if (targetdir == null) {
             setError("The targetdir attribute is required.");
         }
-        if (mapperElement == null) {
-            map = new IdentityMapper();
-        } else {
-            map = mapperElement.getImplementation();
-        }
         if (map == null) {
-            setError("Could not set <mapper> element.");
+            if (mapperElement == null) {
+                map = new IdentityMapper();
+            } else {
+                map = mapperElement.getImplementation();
+                if (map == null) {
+                    setError("Could not set <mapper> element.");
+                }
+            }
         }
     }
 
@@ -160,7 +174,7 @@
                     + targetdir + " with filename " + filename);
         }
         String destname = destfiles[0];
-        File destfile = new File(targetdir, destname);
+        File destfile = FileUtils.getFileUtils().resolveFile(targetdir, destname);
         return destfile.exists() == destmustexist;
     }
 
@@ -173,9 +187,8 @@
          * @return the values as an array of strings
          */
         public String[] getValues() {
-            return new String[]{"srconly", "both"};
+            return new String[] { "srconly", "both" };
         }
     }
 
 }
-

Added: ant/core/trunk/src/tests/antunit/types/selectors/depend-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/selectors/depend-test.xml?rev=904213&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/selectors/depend-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/selectors/depend-test.xml Thu Jan 28 18:53:10 2010
@@ -0,0 +1,45 @@
+<?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" default="antunit">
+
+  <import file="../../antunit-base.xml" />
+
+  <property name="output.dir" location="output" />
+  <property name="foo.file" location="${output.dir}/foo" />
+
+  <target name="setUp">
+    <touch file="${foo.file}" mkdirs="true" />
+  </target>
+
+  <target name="tearDown">
+    <delete dir="${output.dir}" />
+  </target>
+
+  <target name="testMapperByTypedef" depends="setUp">
+    <au:assertTrue>
+      <resourcecount count="1">
+        <fileset file="${foo.file}">
+          <depend targetdir="${basedir}"><!-- dummy targetdir -->
+            <mergemapper to="${ant.file}" />
+          </depend>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+</project>

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

Added: ant/core/trunk/src/tests/antunit/types/selectors/different-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/selectors/different-test.xml?rev=904213&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/selectors/different-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/selectors/different-test.xml Thu Jan 28 18:53:10 2010
@@ -0,0 +1,46 @@
+<?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" default="antunit">
+
+  <import file="../../antunit-base.xml" />
+
+  <property name="output.dir" location="output" />
+  <property name="foo.file" location="${output.dir}/foo" />
+
+  <target name="setUp">
+    <mkdir dir="${output.dir}"/>
+    <echo file="${foo.file}">foo</echo>
+  </target>
+
+  <target name="tearDown">
+    <delete dir="${output.dir}" />
+  </target>
+
+  <target name="testMapperByTypedef" depends="setUp">
+    <au:assertTrue>
+      <resourcecount count="1">
+        <fileset file="${foo.file}">
+          <different targetdir="${basedir}"><!-- dummy targetdir -->
+            <mergemapper to="${ant.file}" />
+          </different>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+</project>

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

Added: ant/core/trunk/src/tests/antunit/types/selectors/present-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/selectors/present-test.xml?rev=904213&view=auto
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/selectors/present-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/types/selectors/present-test.xml Thu Jan 28 18:53:10 2010
@@ -0,0 +1,45 @@
+<?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" default="antunit">
+
+  <import file="../../antunit-base.xml" />
+
+  <property name="output.dir" location="output" />
+  <property name="foo.file" location="${output.dir}/foo" />
+
+  <target name="setUp">
+    <touch file="${foo.file}" mkdirs="true" />
+  </target>
+
+  <target name="tearDown">
+    <delete dir="${output.dir}" />
+  </target>
+
+  <target name="testMapperByTypedef" depends="setUp">
+    <au:assertTrue>
+      <resourcecount count="1">
+        <fileset file="${foo.file}">
+          <present targetdir="${basedir}"><!-- dummy targetdir -->
+            <mergemapper to="${ant.file}" />
+          </present>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
+</project>

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