git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@904213 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -31,7 +31,7 @@ Fixed bugs: | |||||
| Other changes: | 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: | Changes that could break older environments: | ||||
| @@ -221,6 +221,9 @@ Changes that could break older environments: | |||||
| file. So Ant is now capable of supporting several ProjectHelper | file. So Ant is now capable of supporting several ProjectHelper | ||||
| implementations, deciding on which to use depending of the input build file. | 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: | Fixed bugs: | ||||
| ----------- | ----------- | ||||
| @@ -66,16 +66,29 @@ public abstract class MappingSelector extends BaseSelector { | |||||
| /** | /** | ||||
| * Defines the FileNameMapper to use (nested mapper element). | * Defines the FileNameMapper to use (nested mapper element). | ||||
| * @return a mapper to be configured | * @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 { | public Mapper createMapper() throws BuildException { | ||||
| if (mapperElement != null) { | |||||
| if (map != null || mapperElement != null) { | |||||
| throw new BuildException("Cannot define more than one mapper"); | throw new BuildException("Cannot define more than one mapper"); | ||||
| } | } | ||||
| mapperElement = new Mapper(getProject()); | mapperElement = new Mapper(getProject()); | ||||
| return mapperElement; | 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; | |||||
| } | |||||
| /** | /** | ||||
| * Checks to make sure all settings are kosher. In this case, it | * 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. | * means that the dest attribute has been set and we have a mapper. | ||||
| @@ -84,13 +97,15 @@ public abstract class MappingSelector extends BaseSelector { | |||||
| if (targetdir == null) { | if (targetdir == null) { | ||||
| setError("The targetdir attribute is required."); | setError("The targetdir attribute is required."); | ||||
| } | } | ||||
| if (mapperElement == null) { | |||||
| map = new IdentityMapper(); | |||||
| } else { | |||||
| map = mapperElement.getImplementation(); | |||||
| } | |||||
| if (map == null) { | 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 @@ public abstract class MappingSelector extends BaseSelector { | |||||
| + targetdir.getName() + " with filename " + filename); | + targetdir.getName() + " with filename " + filename); | ||||
| } | } | ||||
| String destname = destfiles[0]; | String destname = destfiles[0]; | ||||
| File destfile = new File(targetdir, destname); | |||||
| File destfile = FILE_UTILS.resolveFile(targetdir, destname); | |||||
| boolean selected = selectionTest(file, destfile); | boolean selected = selectionTest(file, destfile); | ||||
| return selected; | return selected; | ||||
| @@ -24,6 +24,7 @@ import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
| import org.apache.tools.ant.types.Mapper; | import org.apache.tools.ant.types.Mapper; | ||||
| import org.apache.tools.ant.util.FileNameMapper; | import org.apache.tools.ant.util.FileNameMapper; | ||||
| import org.apache.tools.ant.util.FileUtils; | |||||
| import org.apache.tools.ant.util.IdentityMapper; | import org.apache.tools.ant.util.IdentityMapper; | ||||
| /** | /** | ||||
| @@ -35,7 +36,6 @@ import org.apache.tools.ant.util.IdentityMapper; | |||||
| * @since 1.5 | * @since 1.5 | ||||
| */ | */ | ||||
| public class PresentSelector extends BaseSelector { | public class PresentSelector extends BaseSelector { | ||||
| private File targetdir = null; | private File targetdir = null; | ||||
| private Mapper mapperElement = null; | private Mapper mapperElement = null; | ||||
| private FileNameMapper map = null; | private FileNameMapper map = null; | ||||
| @@ -86,17 +86,29 @@ public class PresentSelector extends BaseSelector { | |||||
| /** | /** | ||||
| * Defines the FileNameMapper to use (nested mapper element). | * Defines the FileNameMapper to use (nested mapper element). | ||||
| * @return a mapper to be configured | * @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 { | public Mapper createMapper() throws BuildException { | ||||
| if (mapperElement != null) { | |||||
| if (map != null || mapperElement != null) { | |||||
| throw new BuildException("Cannot define more than one mapper"); | throw new BuildException("Cannot define more than one mapper"); | ||||
| } | } | ||||
| mapperElement = new Mapper(getProject()); | mapperElement = new Mapper(getProject()); | ||||
| return mapperElement; | 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. | * 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 | * It could be a <code>negate</code> boolean, but by doing things | ||||
| @@ -123,13 +135,15 @@ public class PresentSelector extends BaseSelector { | |||||
| if (targetdir == null) { | if (targetdir == null) { | ||||
| setError("The targetdir attribute is required."); | setError("The targetdir attribute is required."); | ||||
| } | } | ||||
| if (mapperElement == null) { | |||||
| map = new IdentityMapper(); | |||||
| } else { | |||||
| map = mapperElement.getImplementation(); | |||||
| } | |||||
| if (map == null) { | 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 @@ public class PresentSelector extends BaseSelector { | |||||
| + targetdir + " with filename " + filename); | + targetdir + " with filename " + filename); | ||||
| } | } | ||||
| String destname = destfiles[0]; | String destname = destfiles[0]; | ||||
| File destfile = new File(targetdir, destname); | |||||
| File destfile = FileUtils.getFileUtils().resolveFile(targetdir, destname); | |||||
| return destfile.exists() == destmustexist; | return destfile.exists() == destmustexist; | ||||
| } | } | ||||
| @@ -173,9 +187,8 @@ public class PresentSelector extends BaseSelector { | |||||
| * @return the values as an array of strings | * @return the values as an array of strings | ||||
| */ | */ | ||||
| public String[] getValues() { | public String[] getValues() { | ||||
| return new String[]{"srconly", "both"}; | |||||
| return new String[] { "srconly", "both" }; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -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> | |||||
| @@ -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> | |||||
| @@ -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> | |||||