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 2009/09/18 13:57:04 UTC
svn commit: r816591 - in /ant/core/trunk: WHATSNEW
docs/manual/CoreTypes/resources.html
src/main/org/apache/tools/ant/types/resources/selectors/Name.java
src/tests/antunit/types/resources/selectors/name-test.xml
Author: bodewig
Date: Fri Sep 18 11:57:04 2009
New Revision: 816591
URL: http://svn.apache.org/viewvc?rev=816591&view=rev
Log:
handleDirSep on name selector. PR 47858
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTypes/resources.html
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java
ant/core/trunk/src/tests/antunit/types/resources/selectors/name-test.xml
Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=816591&r1=816590&r2=816591&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Sep 18 11:57:04 2009
@@ -976,6 +976,10 @@
* <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
=============================================
Modified: ant/core/trunk/docs/manual/CoreTypes/resources.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTypes/resources.html?rev=816591&r1=816590&r2=816591&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTypes/resources.html (original)
+++ ant/core/trunk/docs/manual/CoreTypes/resources.html Fri Sep 18 11:57:04 2009
@@ -545,6 +545,16 @@
<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>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java?rev=816591&r1=816590&r2=816591&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/selectors/Name.java Fri Sep 18 11:57:04 2009
@@ -31,6 +31,7 @@
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 @@
/**
* 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 @@
/**
* Get the regular expression used by this Name ResourceSelector.
* @return the String selection pattern.
+ * @since Ant 1.8.0
*/
public String getRegex() {
return regex;
@@ -92,6 +95,26 @@
}
/**
+ * 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.
* @return whether the Resource was selected.
@@ -107,7 +130,7 @@
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 @@
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('\\', '/');
}
}
Modified: ant/core/trunk/src/tests/antunit/types/resources/selectors/name-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/types/resources/selectors/name-test.xml?rev=816591&r1=816590&r2=816591&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/resources/selectors/name-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/types/resources/selectors/name-test.xml Fri Sep 18 11:57:04 2009
@@ -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>