Browse Source

Mapper-aware selectors (depends, different, present) now accept typedef'd FileNameMappers

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@904213 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 15 years ago
parent
commit
9fd3da80a6
6 changed files with 190 additions and 23 deletions
  1. +4
    -1
      WHATSNEW
  2. +24
    -9
      src/main/org/apache/tools/ant/types/selectors/MappingSelector.java
  3. +26
    -13
      src/main/org/apache/tools/ant/types/selectors/PresentSelector.java
  4. +45
    -0
      src/tests/antunit/types/selectors/depend-test.xml
  5. +46
    -0
      src/tests/antunit/types/selectors/different-test.xml
  6. +45
    -0
      src/tests/antunit/types/selectors/present-test.xml

+ 4
- 1
WHATSNEW View File

@@ -31,7 +31,7 @@ Fixed bugs:
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 @@ Changes that could break older environments:
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:
-----------



+ 24
- 9
src/main/org/apache/tools/ant/types/selectors/MappingSelector.java View File

@@ -66,16 +66,29 @@ public abstract class MappingSelector extends BaseSelector {
/**
* 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;
}
/**
* 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 @@ public abstract class MappingSelector extends BaseSelector {
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 @@ public abstract class MappingSelector extends BaseSelector {
+ 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;


+ 26
- 13
src/main/org/apache/tools/ant/types/selectors/PresentSelector.java View File

@@ -24,6 +24,7 @@ import org.apache.tools.ant.BuildException;
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 @@ import org.apache.tools.ant.util.IdentityMapper;
* @since 1.5
*/
public class PresentSelector extends BaseSelector {

private File targetdir = null;
private Mapper mapperElement = null;
private FileNameMapper map = null;
@@ -86,17 +86,29 @@ public class PresentSelector extends BaseSelector {
/**
* 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 @@ public class PresentSelector extends BaseSelector {
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 @@ public class PresentSelector extends BaseSelector {
+ 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 @@ public class PresentSelector extends BaseSelector {
* @return the values as an array of strings
*/
public String[] getValues() {
return new String[]{"srconly", "both"};
return new String[] { "srconly", "both" };
}
}

}


+ 45
- 0
src/tests/antunit/types/selectors/depend-test.xml View File

@@ -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>

+ 46
- 0
src/tests/antunit/types/selectors/different-test.xml View File

@@ -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>

+ 45
- 0
src/tests/antunit/types/selectors/present-test.xml View File

@@ -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>

Loading…
Cancel
Save