This patch enables Gwt's custom resource-filters to handle patterns that end in
'/'. As per the specs in ant's DirectoryScanner, such patterns are handled by
appending a '**' to the pattern.
Patch by: amitmanjhi
Review by: jat (desk review)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@4900 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/resource/impl/DefaultFilters.java b/dev/core/src/com/google/gwt/dev/resource/impl/DefaultFilters.java
index 3ff40d8..0fc980c 100644
--- a/dev/core/src/com/google/gwt/dev/resource/impl/DefaultFilters.java
+++ b/dev/core/src/com/google/gwt/dev/resource/impl/DefaultFilters.java
@@ -27,8 +27,8 @@
* TODO: this class needs to be revisited, when Gwt's Ant is upgraded.
*
* Currently, we do not go to ant if (a) the filterList is empty, or (b) the
- * filterList has "common" patterns. Exception: When pattern or path ends in
- * '/', we defer to ant.
+ * filterList has "common" patterns. Exception: When path ends in '/', we defer
+ * to ant.
*
* TODO: This code could be made more general and cleaner by removing the
* dependency on Ant completely. All ant patterns could be compiled into
@@ -294,6 +294,14 @@
if (antPatternString.indexOf("***") != -1) {
return null;
}
+ if (antPatternString.endsWith("/")) {
+ /*
+ * From the DirectoryScanner.html spec: When a pattern ends with a '/' or
+ * '\', "**" is appended. if ant pattern = testing/, path = testing/foo,
+ * result = true.
+ */
+ antPatternString = antPatternString + "**";
+ }
StringBuffer sb = new StringBuffer();
int length = antPatternString.length();
for (int i = 0; i < length; i++) {
@@ -312,15 +320,6 @@
sb.append("(/[^/]*)*");
i += 2; // handled 2 more chars than usual
} else {
- /*
- * TODO: handle patterns that end in /. For now, ant's matching seem
- * inconsistent.
- *
- * ant pattern = testing/, path = testing/foo, result = true.
- */
- if (i == length - 1) {
- return null;
- }
sb.append(c);
}
break;
diff --git a/dev/core/test/com/google/gwt/dev/resource/impl/DefaultFiltersTest.java b/dev/core/test/com/google/gwt/dev/resource/impl/DefaultFiltersTest.java
index 3059de3..d2fccd7 100644
--- a/dev/core/test/com/google/gwt/dev/resource/impl/DefaultFiltersTest.java
+++ b/dev/core/test/com/google/gwt/dev/resource/impl/DefaultFiltersTest.java
@@ -243,18 +243,14 @@
*/
public void testFilterConversion() {
List<String> nullFilters = Arrays.asList(new String[] {
- "***/testing/**", "**/{/**", "**/}/**", "**/+/**", "**/testing/",
- "**/testing/**/"});
+ "***/testing/**", "**/{/**", "**/}/**", "**/+/**",});
List<String> okayFilters = new ArrayList<String>();
okayFilters.addAll(Arrays.asList(new String[] {
"**/#/**", "**/~/**", "Foo", "Bar", "foo/**", "foo/*Test*java",
"**/testing/**", "**/testing/**/Foo*Bar*.java",
"**/testing/**/Foo$*r.class",}));
String doubleStarPrefixes[] = {"", "/", "**/", "/**/", "foo**/", "/foo**/"};
- // TODO: uncomment when we handle prefixes that end in /
- // String doubleStarSuffixes[] = {"", "/", "/**", "/**/", "/**foo",
- // "/**foo/"};
- String doubleStarSuffixes[] = {"", "/**", "/**foo"};
+ String doubleStarSuffixes[] = {"", "/", "/**", "/**/", "/**foo", "/**foo/"};
String middleString = "testing";
for (String doubleStarPrefix : doubleStarPrefixes) {
for (String doubleStarSuffix : doubleStarSuffixes) {
@@ -263,11 +259,6 @@
}
List<String> testPaths = getMiscPaths("testing", false);
- /*
- * TODO: investigate inconsistencies.
- *
- * ant pattern = testing/, path = testing/foo, result = true.
- */
DefaultFilters filters = new DefaultFilters();
for (String filter : nullFilters) {
assertNull(filter + " conversion should be null",
@@ -279,8 +270,8 @@
assertNotNull(filter + " conversion should be non-null", pattern);
ResourceFilterString antFilterString = getAntFilter(
- new String[] {filter}, EMPTY_ARRAY, DEFAULT_EXCLUDES, NOT_JAVA, "ant_"
- + filter);
+ new String[] {filter}, EMPTY_ARRAY, DEFAULT_EXCLUDES, NOT_JAVA,
+ "ant_" + filter);
ResourceFilterString customFilterString = new ResourceFilterString(
filters.customFilterWithCatchAll(new String[] {filter}, EMPTY_ARRAY,
true, null, NOT_JAVA), "custom_" + pattern);
@@ -332,8 +323,8 @@
// pass non-empty include and exclude array. Matches nothing
filter = getFilterWithoutCatchAll(mergedPatterns, mergedPatterns, NOT_JAVA);
advancedPaths.testAdvancedPath(
- getAntFilter(mergedPatterns, mergedPatterns, DEFAULT_EXCLUDES, NOT_JAVA,
- "ant_mergedPatterns_mergedPatterns"),
+ getAntFilter(mergedPatterns, mergedPatterns, DEFAULT_EXCLUDES,
+ NOT_JAVA, "ant_mergedPatterns_mergedPatterns"),
new ResourceFilterString(filter, "custom_mergedPatterns_mergedPatterns"));
}