Skip to content

Commit

Permalink
Error when parsing resource filter (#2914)
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored Oct 24, 2023
1 parent 7e07649 commit 1c837a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.core.internal.resources.PreferenceInitializer;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -1335,7 +1337,19 @@ public Preferences setSettingsUrl(String settingsUrl) {
}

public Preferences setResourceFilters(List<String> resourceFilters) {
this.resourceFilters = resourceFilters == null ? new ArrayList<>() : resourceFilters;
if (resourceFilters != null) {
this.resourceFilters = resourceFilters.stream().filter((resource) -> {
try {
Pattern.compile(resource);
return true;
} catch (Exception e) {
JavaLanguageServerPlugin.logInfo("Invalid preference: " + Preferences.JAVA_RESOURCE_FILTERS + "=" + resource);
return false;
}
}).collect(Collectors.toList());
} else {
this.resourceFilters = Collections.emptyList();
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ public void testResourceFilters() throws Exception {
}
}

@Test
public void testInvalidResourceFilters() throws Exception {
List<String> resourceFilters = preferenceManager.getPreferences().getResourceFilters();
try {
String name = "salut";
importProjects("maven/" + name);
IProject project = getProject(name);
assertIsJavaProject(project);
List<String> pref = Arrays.asList("**/node_modules/**", "node_modules", "\\.git");
assertEquals(3, pref.size());
preferenceManager.getPreferences().setResourceFilters(pref);
projectsManager.configureFilters(new NullProgressMonitor());
waitForJobsToComplete();
List<String> filters = preferenceManager.getPreferences().getResourceFilters();
assertEquals(2, filters.size());
} finally {
preferenceManager.getPreferences().setResourceFilters(resourceFilters);
}
}

@Test
public void dontFilterGitLikePackages() throws Exception {
//See https://github.com/eclipse/eclipse.jdt.ls/issues/2244
Expand Down

0 comments on commit 1c837a4

Please sign in to comment.