diff options
author | Paul Pazderski | 2020-10-26 12:10:09 +0000 |
---|---|---|
committer | Paul Pazderski | 2020-10-26 17:22:26 +0000 |
commit | e40c92f719d2dd4017ffd2990cd5dc6630f4f3a8 (patch) | |
tree | 8652708baf3a0e31454a64d10abef9c6a802e21f | |
parent | 6c75d96e39e7421210e1a47a787ded7c1b99e539 (diff) | |
download | eclipse.platform.text-e40c92f719d2dd4017ffd2990cd5dc6630f4f3a8.tar.gz eclipse.platform.text-e40c92f719d2dd4017ffd2990cd5dc6630f4f3a8.tar.xz eclipse.platform.text-e40c92f719d2dd4017ffd2990cd5dc6630f4f3a8.zip |
Bug 568231 - Quick Search file pattern match doesn't work as expectedI20201028-0610I20201028-0130I20201028-0020I20201027-2350I20201027-1800
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>
5 files changed, 57 insertions, 11 deletions
diff --git a/org.eclipse.text.quicksearch.tests/META-INF/MANIFEST.MF b/org.eclipse.text.quicksearch.tests/META-INF/MANIFEST.MF index e36372ac8ca..47773d8875a 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 @@ Manifest-Version: 1.0 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 f477bd856db..4ae7019ce54 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 4ecce5d0736..b41102f9efc 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 @@ public class ResourceMatcherTest { @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 @@ public class ResourceMatcherTest { 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 b7917ed296b..e8908f559b0 100644 --- a/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF +++ b/org.eclipse.text.quicksearch/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 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 841bd19ec75..2dd43d182e3 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 @@ import org.eclipse.core.resources.IResource; public class ResourceMatchers { + /** + * ResourceMatcher to match anything unconditional. + */ public static ResourceMatcher ANY = new ResourceMatcher() { @Override public String toString() { @@ -30,6 +33,15 @@ public class ResourceMatchers { } }; + /** + * 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 @@ public class ResourceMatchers { } 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 @@ public class ResourceMatchers { @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 @@ public class ResourceMatchers { }; } + /** + * 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$ |