Skip to content

Commit d99852c

Browse files
committed
fix: use getAccessibleTopLevelProjects
1 parent 56add6d commit d99852c

4 files changed

Lines changed: 12 additions & 19 deletions

File tree

plugin/src/main/java/io/snyk/eclipse/plugin/properties/preferences/FolderConfigs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void addAll(List<FolderConfig> folderConfigs) {
8080
}
8181

8282
public FolderConfigsParam updateFolderConfigs() {
83-
List<IProject> openProjects = ResourceUtils.getOpenProjects();
83+
List<IProject> openProjects = ResourceUtils.getAccessibleTopLevelProjects();
8484

8585
List<String> projectPaths = openProjects.stream().map(project -> project.getLocation().toOSString())
8686
.collect(Collectors.toList());

plugin/src/main/java/io/snyk/eclipse/plugin/utils/ResourceUtils.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
public class ResourceUtils {
2424

25-
private static final Comparator<IProject> projectByPathComparator = new Comparator<IProject>() {
25+
private static final Comparator<IProject> projectByPathComparator = new Comparator<IProject>() {
2626
@Override
2727
public int compare(IProject o1, IProject o2) {
2828
Path fullPath = ResourceUtils.getFullPath(o1);
@@ -68,7 +68,7 @@ public static Path getFullPath(IResource resource) {
6868

6969
public static IProject getProjectByPath(Path path) {
7070
var projects = getAccessibleTopLevelProjects();
71-
71+
7272
for (IProject iProject : projects) {
7373
Path projectPath = ResourceUtils.getFullPath(iProject);
7474
if (path.normalize().startsWith(projectPath)) {
@@ -79,15 +79,10 @@ public static IProject getProjectByPath(Path path) {
7979
}
8080

8181
public static List<IProject> getAccessibleTopLevelProjects() {
82-
var projects = Arrays.stream(ResourcesPlugin.getWorkspace().getRoot().getProjects())
83-
.filter((project) -> {
84-
return project.isAccessible()
85-
&& !project.isDerived()
86-
&& !project.isHidden();
87-
})
88-
.sorted(projectByPathComparator)
89-
.collect(Collectors.toList());
90-
82+
var projects = Arrays.stream(ResourcesPlugin.getWorkspace().getRoot().getProjects()).filter((project) -> {
83+
return project.isAccessible() && !project.isDerived() && !project.isHidden();
84+
}).sorted(projectByPathComparator).collect(Collectors.toList());
85+
9186
Set<IProject> topLevel = new TreeSet<>(projectByPathComparator);
9287
boolean add = true;
9388
for (IProject iProject : projects) {
@@ -103,6 +98,7 @@ public static List<IProject> getAccessibleTopLevelProjects() {
10398
topLevel.add(iProject);
10499
}
105100
}
106-
101+
107102
return new ArrayList<>(topLevel);
108103
}
104+
}

plugin/src/main/java/io/snyk/languageserver/protocolextension/SnykExtendedLanguageClient.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
import org.apache.commons.lang3.StringUtils;
4242
import org.apache.commons.lang3.exception.ExceptionUtils;
4343
import org.eclipse.core.resources.IProject;
44-
import org.eclipse.core.resources.ResourcesPlugin;
45-
import org.eclipse.jdt.internal.core.JavaProject;
46-
import org.eclipse.jface.viewers.IStructuredSelection;
4744
import org.eclipse.jface.wizard.WizardDialog;
4845
import org.eclipse.lsp4e.LSPEclipseUtils;
4946
import org.eclipse.lsp4e.LanguageClientImpl;
@@ -682,7 +679,7 @@ public void setToolWindow(ISnykToolView toolView) {
682679
}
683680

684681
public void clearCache() {
685-
List<IProject> openProjects = ResourceUtils.getOpenProjects();
682+
List<IProject> openProjects = ResourceUtils.getAccessibleTopLevelProjects();
686683
for (IProject iProject : openProjects) {
687684
IssueCacheHolder.getInstance().getCacheInstance(iProject).clearAll();
688685
}

tests/src/test/java/io/snyk/languageserver/LsConfigurationUpdaterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void testGetSettings() {
7777
assertEquals("false", settings.getActivateSnykCodeQuality());
7878
assertEquals("/usr/local/bin/snyk", settings.getCliPath());
7979
assertEquals("my-token", settings.getToken());
80-
assertArrayEquals(new String[] { "/path1", "/path2" }, settings.getTrustedFolders());
80+
assertArrayEquals(new String[] { "path1", "path2" }, settings.getTrustedFolders());
8181
assertEquals("automatic", settings.getScanningMode());
8282
assertEquals("token", settings.getAuthenticationMethod());
8383
assertEquals(LsBinaries.REQUIRED_LS_PROTOCOL_VERSION, settings.getRequiredProtocolVersion());
@@ -114,7 +114,7 @@ private void setupPreferenceMock() {
114114
.thenReturn("false");
115115
when(preferenceMock.getPref(Preferences.CLI_PATH, "")).thenReturn("/usr/local/bin/snyk");
116116
when(preferenceMock.getPref(Preferences.AUTH_TOKEN_KEY, "")).thenReturn("my-token");
117-
when(preferenceMock.getPref(Preferences.TRUSTED_FOLDERS)).thenReturn("/path1:/path2");
117+
when(preferenceMock.getPref(Preferences.TRUSTED_FOLDERS)).thenReturn("path1:path2");
118118
when(preferenceMock.getBooleanPref(Preferences.SCANNING_MODE_AUTOMATIC)).thenReturn(true);
119119
when(preferenceMock.getBooleanPref(Preferences.USE_TOKEN_AUTH, false)).thenReturn(true);
120120
when(preferenceMock.getPref(Preferences.FILTER_DELTA_NEW_ISSUES, Boolean.FALSE.toString())).thenReturn("true");

0 commit comments

Comments
 (0)