Bug 568231 - Quick Search file pattern match doesn't work as expected

QuickSearch use the right text box to enter filename/path patterns to
limit the files to search in. It allows a comma separated list to
include multiple patterns.
Before this change it works only reasonable without spaces around the
separating commas. Possible spaces where not removed from the separated
pattern and a pattern with leading or trailing spaces rarely matches
anything. (that's why a single pattern is already trimmed)

Change-Id: I36ac86ede8ebec790c79a493dad517369f3ea72b
Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
diff --git a/org.eclipse.text.quicksearch.tests/META-INF/MANIFEST.MF b/org.eclipse.text.quicksearch.tests/META-INF/MANIFEST.MF
index e36372a..47773d8 100644
--- a/org.eclipse.text.quicksearch.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.text.quicksearch.tests/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.text.quicksearch.tests
-Bundle-Version: 1.0.300.qualifier
+Bundle-Version: 1.0.400.qualifier
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.text.quicksearch;bundle-version="1.0.300",
  org.eclipse.core.resources,
diff --git a/org.eclipse.text.quicksearch.tests/pom.xml b/org.eclipse.text.quicksearch.tests/pom.xml
index f477bd8..4ae7019 100644
--- a/org.eclipse.text.quicksearch.tests/pom.xml
+++ b/org.eclipse.text.quicksearch.tests/pom.xml
@@ -24,7 +24,7 @@
 	</parent>
 	<groupId>org.eclipse.text</groupId>
 	<artifactId>org.eclipse.text.quicksearch.tests</artifactId>
-	<version>1.0.300-SNAPSHOT</version>
+	<version>1.0.400-SNAPSHOT</version>
 	<packaging>eclipse-test-plugin</packaging>
 	<properties>
 		<testSuite>${project.artifactId}</testSuite>
diff --git a/org.eclipse.text.quicksearch.tests/src/org/eclipse/text/quicksearch/tests/ResourceMatcherTest.java b/org.eclipse.text.quicksearch.tests/src/org/eclipse/text/quicksearch/tests/ResourceMatcherTest.java
index 4ecce5d..b41102f 100644
--- a/org.eclipse.text.quicksearch.tests/src/org/eclipse/text/quicksearch/tests/ResourceMatcherTest.java
+++ b/org.eclipse.text.quicksearch.tests/src/org/eclipse/text/quicksearch/tests/ResourceMatcherTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2019 Pivotal, Inc.
+ * Copyright (c) 2019, 2020 Pivotal, Inc. and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v2.0
  * which accompanies this distribution, and is available at
@@ -13,6 +13,7 @@
 package org.eclipse.text.quicksearch.tests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.eclipse.core.runtime.Path;
@@ -31,8 +32,21 @@
 
 	@Test
 	public void commaSeparatedPaths() throws Exception {
-		assertMatch(true, "*.java,*.properties", "/myproject/something/nested/foo.java");
-		assertMatch(true, "*.java,*.properties", "/myproject/something/nested/application.properties");
+		String[] patterns = new String[] { //
+				"*.java,*.properties", //
+				"*.java, *.properties", //
+				"*.java ,*.properties", //
+				"*.java , *.properties", //
+				" *.java  ,  *.properties ", //
+				" *.java  ,,  *.properties ", //
+				" *.java  ,  ,  *.properties ", //
+				" *.java  ,*.foo,  *.properties ", //
+		};
+		for (String pattern : patterns) {
+			assertMatch(true, pattern, "/myproject/something/nested/foo.java");
+			assertMatch(true, pattern, "/myproject/something/nested/application.properties");
+			assertMatch(false, pattern, "/myproject/something/nested/test.log");
+		}
 	}
 
 	@Test
@@ -50,6 +64,9 @@
 	private void assertMatch(boolean expectedMatch, String patterns, String path) {
 		assertTrue(new Path(path).isAbsolute());
 		ResourceMatcher matcher = ResourceMatchers.commaSeparatedPaths(patterns);
-		assertEquals(expectedMatch, matcher.matches(new MockResource(path)));
+		assertEquals("Wrong match with pattern: '" + patterns + "'", expectedMatch, matcher.matches(new MockResource(path)));
+
+		// Most ResourceMatchers have a custom toString. Do a quick test to check for thrown exceptions.
+		assertNotNull(matcher.toString());
 	}
 }
diff --git a/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF b/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF
index b7917ed..e8908f5 100644
--- a/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF
+++ b/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.text.quicksearch;singleton:=true
-Bundle-Version: 1.0.300.qualifier
+Bundle-Version: 1.0.400.qualifier
 Bundle-Activator: org.eclipse.text.quicksearch.internal.ui.QuickSearchActivator
 Require-Bundle: org.eclipse.ui;bundle-version="[3.113.0,4.0.0)",
  org.eclipse.core.resources;bundle-version="[3.13.0,4.0.0)",
diff --git a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/pathmatch/ResourceMatchers.java b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/pathmatch/ResourceMatchers.java
index 841bd19..2dd43d1 100644
--- a/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/pathmatch/ResourceMatchers.java
+++ b/org.eclipse.text.quicksearch/src/org/eclipse/text/quicksearch/internal/core/pathmatch/ResourceMatchers.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2019 Pivotal, Inc. and others.
+ * Copyright (c) 2019, 2020 Pivotal, Inc. and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -19,6 +19,9 @@
 
 public class ResourceMatchers {
 
+	/**
+	 * ResourceMatcher to match anything unconditional.
+	 */
 	public static ResourceMatcher ANY = new ResourceMatcher() {
 		@Override
 		public String toString() {
@@ -30,6 +33,15 @@
 		}
 	};
 
+	/**
+	 * Build ResourceMatcher for (optional) comma separated path patterns. More than
+	 * one pattern can be supplied comma separated. For more than one pattern the
+	 * matcher will match if <em>any</em> of the patterns match. Empty input match
+	 * anything.
+	 *
+	 * @param text patterns to match. Not <code>null</code>
+	 * @return ResourceMatcher for given path patterns
+	 */
 	public static ResourceMatcher commaSeparatedPaths(String text) {
 		text = text.trim();
 		if (text.isEmpty()) {
@@ -37,16 +49,27 @@
 		}
 		String[] paths = text.split(","); //$NON-NLS-1$
 		if (paths.length==1) {
-			return path(paths[0]);
+			return path(paths[0].trim());
 		} else {
 			ResourceMatcher[] matchers = new ResourceMatcher[paths.length];
 			for (int i = 0; i < matchers.length; i++) {
-				matchers[i] = path(paths[i]);
+				String pattern = paths[i].trim();
+				if (!pattern.isEmpty()) {
+					matchers[i] = path(pattern);
+				}
 			}
 			return either(matchers);
 		}
 	}
 
+	/**
+	 * Create ResourceMatcher returning <code>true</code>/match if <em>any</em> of
+	 * the given matchers returns a match.
+	 *
+	 * @param matchers the matchers to combined with OR semantics. Not
+	 *                 <code>null</code>.
+	 * @return new ResourceMatcher combining the given matchers
+	 */
 	private static ResourceMatcher either(ResourceMatcher... matchers) {
 		return new ResourceMatcher() {
 
@@ -66,7 +89,7 @@
 			@Override
 			public boolean matches(IResource resource) {
 				for (ResourceMatcher m : matchers) {
-					if (m.matches(resource)) {
+					if (m != null && m.matches(resource)) {
 						return true;
 					}
 				}
@@ -75,6 +98,12 @@
 		};
 	}
 
+	/**
+	 * Create a ResourceMatcher for the given pattern.
+	 *
+	 * @param _pat the pattern to match
+	 * @return the ResourceMatcher for given pattern
+	 */
 	private static ResourceMatcher path(String _pat) {
 		if (!_pat.startsWith("/") && !_pat.startsWith("**/")) { //$NON-NLS-1$ //$NON-NLS-2$
 			_pat = "**/"+_pat; //$NON-NLS-1$