Browse Source

handleDirSep on name selector. PR 47858

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@816591 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 15 years ago
parent
commit
2e0b8b7d3c
4 changed files with 82 additions and 7 deletions
  1. +4
    -0
      WHATSNEW
  2. +10
    -0
      docs/manual/CoreTypes/resources.html
  3. +32
    -2
      src/main/org/apache/tools/ant/types/resources/selectors/Name.java
  4. +36
    -5
      src/tests/antunit/types/resources/selectors/name-test.xml

+ 4
- 0
WHATSNEW View File

@@ -976,6 +976,10 @@ Other changes:
* <property location="from" basedir="to" relative="true"/> can now
calculate relative paths.

* The <name> selector supports a new handleDirSep attribute that
makes it ignore differences between / and \ separators.
Bugzilla Report 47858.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 10
- 0
docs/manual/CoreTypes/resources.html View File

@@ -545,6 +545,16 @@ platforms.
<td valign="top">Whether name comparisons are case-sensitive</td>
<td align="center" valign="top">No, default <i>true</i></td>
</tr>
<tr>
<td valign="top">handledirsep</td>
<td valign="top">
If this is specified, the mapper will treat a \ character in a
resource name or name attribute as a / for the purposes of
matching. This attribute can be true or false, the default is
false.
<em>Since Ant 1.8.0.</em>
<td align="center" valign="top">No</td>
</tr>
</table>

<h4><a name="rsel.exists">exists</a></h4>


+ 32
- 2
src/main/org/apache/tools/ant/types/resources/selectors/Name.java View File

@@ -31,6 +31,7 @@ public class Name implements ResourceSelector {
private String regex = null;
private String pattern;
private boolean cs = true;
private boolean handleDirSep = false;

// caches for performance reasons
private RegularExpression reg;
@@ -61,6 +62,7 @@ public class Name implements ResourceSelector {
/**
* Set the regular expression to compare names against.
* @param r the regex to set.
* @since Ant 1.8.0
*/
public void setRegex(String r) {
regex = r;
@@ -70,6 +72,7 @@ public class Name implements ResourceSelector {
/**
* Get the regular expression used by this Name ResourceSelector.
* @return the String selection pattern.
* @since Ant 1.8.0
*/
public String getRegex() {
return regex;
@@ -91,6 +94,26 @@ public class Name implements ResourceSelector {
return cs;
}

/**
* Attribute specifing whether to ignore the difference
* between / and \ (the two common directory characters).
* @param handleDirSep a boolean, default is false.
* @since Ant 1.8.0
*/
public void setHandleDirSep(boolean handleDirSep) {
this.handleDirSep = handleDirSep;
}

/**
* Whether the difference between / and \ (the two common
* directory characters) is ignored.
*
* @since Ant 1.8.0
*/
public boolean doesHandledirSep() {
return handleDirSep;
}

/**
* Return true if this Resource is selected.
* @param r the Resource to check.
@@ -107,7 +130,7 @@ public class Name implements ResourceSelector {

private boolean matches(String name) {
if (pattern != null) {
return SelectorUtils.match(pattern, name, cs);
return SelectorUtils.match(modify(pattern), modify(name), cs);
} else {
if (reg == null) {
reg = new RegularExpression();
@@ -118,7 +141,14 @@ public class Name implements ResourceSelector {
if (!cs) {
options |= Regexp.MATCH_CASE_INSENSITIVE;
}
return expression.matches(name, options);
return expression.matches(modify(name), options);
}
}

private String modify(String s) {
if (s == null || !handleDirSep || s.indexOf("\\") == -1) {
return s;
}
return s.replace('\\', '/');
}
}

+ 36
- 5
src/tests/antunit/types/resources/selectors/name-test.xml View File

@@ -15,8 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">

<import file="../../../antunit-base.xml" />

@@ -32,7 +31,7 @@
<resourcecount when="equal" count="1">
<restrict>
<fileset dir="${output}"/>
<rsel:name name="*"/>
<name name="*"/>
</restrict>
</resourcecount>
</au:assertTrue>
@@ -40,7 +39,7 @@
<resourcecount when="equal" count="0">
<restrict>
<fileset dir="${output}"/>
<rsel:name name=".*"/>
<name name=".*"/>
</restrict>
</resourcecount>
</au:assertTrue>
@@ -51,9 +50,41 @@
<resourcecount when="equal" count="1">
<restrict>
<fileset dir="${output}"/>
<rsel:name regex=".*"/>
<name regex=".*"/>
</restrict>
</resourcecount>
</au:assertTrue>
</target>

<target name="testHandledirSep" depends="createTestdir">
<au:assertTrue>
<!-- only one should match the current platform -->
<resourcecount when="equal" count="1">
<resources>
<restrict>
<fileset dir="${output}"/>
<name name="**/${file}"/>
</restrict>
<restrict>
<fileset dir="${output}"/>
<name name="**\${file}"/>
</restrict>
</resources>
</resourcecount>
</au:assertTrue>
<au:assertTrue>
<resourcecount when="equal" count="2">
<resources>
<restrict>
<fileset dir="${output}"/>
<name name="**/${file}" handleDirSep="true"/>
</restrict>
<restrict>
<fileset dir="${output}"/>
<name name="**\${file}" handleDirSep="true"/>
</restrict>
</resources>
</resourcecount>
</au:assertTrue>
</target>
</project>

Loading…
Cancel
Save