Skip to content

Commit

Permalink
Error when parsing resource filter
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Oct 19, 2023
1 parent fe0ac4c commit 743ecd2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;

import org.eclipse.core.internal.resources.PreferenceInitializer;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -1336,6 +1337,15 @@ public Preferences setSettingsUrl(String settingsUrl) {

public Preferences setResourceFilters(List<String> resourceFilters) {
this.resourceFilters = resourceFilters == null ? new ArrayList<>() : resourceFilters;
if (resourceFilters != null) {
String argument = String.join("|", resourceFilters);
try {
Pattern.compile(argument);
} catch (Exception e) {
JavaLanguageServerPlugin.logInfo("Invalid preference: " + Preferences.JAVA_RESOURCE_FILTERS + "=" + argument);
this.resourceFilters = JAVA_RESOURCE_FILTERS_DEFAULT;
}
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.jdt.ls.core.internal.handlers.BuildWorkspaceHandler;
import org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer;
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.CHANGE_TYPE;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.lsp4j.InitializeParams;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -196,6 +197,24 @@ 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);
preferenceManager.getPreferences().setResourceFilters(Arrays.asList("**/node_modules/**", "node_modules", "\\.git"));
projectsManager.configureFilters(new NullProgressMonitor());
waitForJobsToComplete();
List<String> filters = preferenceManager.getPreferences().getResourceFilters();
assertEquals(Preferences.JAVA_RESOURCE_FILTERS_DEFAULT.size(), 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 743ecd2

Please sign in to comment.