Skip to content

Commit 34394a3

Browse files
committed
fix: replace string path with path path and other fixes
1 parent 083ad75 commit 34394a3

9 files changed

Lines changed: 79 additions & 57 deletions

File tree

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.snyk.eclipse.plugin.properties.preferences;
22

3+
import java.nio.file.Path;
34
import java.util.ArrayList;
45
import java.util.List;
56
import java.util.stream.Collectors;
@@ -39,34 +40,39 @@ public void addFolderConfig(FolderConfig folderConfig) {
3940
}
4041
}
4142

42-
public List<String> getLocalBranches(String folderPath) {
43-
String json = preferenceState.get(folderPath, null);
43+
public List<String> getLocalBranches(Path projectPath) {
44+
String json = preferenceState.get(normalizePath(projectPath), null);
4445
if (json != null) {
4546
FolderConfig folderConfig = gson.fromJson(json, FolderConfig.class);
4647
return folderConfig.getLocalBranches();
4748
}
4849
return List.of();
4950
}
5051

51-
public void setBaseBranch(String folderPath, String newBaseBranch) {
52-
String json = preferenceState.get(folderPath, null);
52+
private String normalizePath(Path projectPath) {
53+
return projectPath.normalize().toString();
54+
}
55+
56+
public void setBaseBranch(Path projectPath, String newBaseBranch) {
57+
String path = normalizePath(projectPath);
58+
String json = preferenceState.get(path, null);
5359
if (json == null) {
54-
SnykLogger.logInfo("No valid configuration for project: " + folderPath);
60+
SnykLogger.logInfo("No valid configuration for project: " + path);
5561
return;
5662
}
5763
FolderConfig folderConfig = gson.fromJson(json, FolderConfig.class);
5864
folderConfig.setBaseBranch(newBaseBranch);
5965
String updatedJson = gson.toJson(folderConfig);
60-
preferenceState.put(folderPath, updatedJson);
66+
preferenceState.put(path, updatedJson);
6167
try {
6268
preferenceState.flush();
6369
} catch (Exception e) {
6470
SnykLogger.logError(e);
6571
}
6672
}
6773

68-
public String getBaseBranch(String folderPath) {
69-
String json = preferenceState.get(folderPath, null);
74+
public String getBaseBranch(Path projectPath) {
75+
String json = preferenceState.get(normalizePath(projectPath), null);
7076
if (json == null)
7177
return null;
7278
FolderConfig folderConfig = gson.fromJson(json, FolderConfig.class);
@@ -82,7 +88,7 @@ public void addAll(List<FolderConfig> folderConfigs) {
8288
public FolderConfigsParam updateFolderConfigs() {
8389
List<IProject> openProjects = ResourceUtils.getAccessibleTopLevelProjects();
8490

85-
List<String> projectPaths = openProjects.stream().map(project -> project.getLocation().toOSString())
91+
List<String> projectPaths = openProjects.stream().map(project -> ResourceUtils.getFullPath(project).toString())
8692
.collect(Collectors.toList());
8793

8894
FolderConfigsParam folderConfigs = getFolderConfigs(projectPaths);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,8 @@ public boolean isTest() {
261261
return getBooleanPref("isTesting");
262262
}
263263

264+
public static boolean isDeltaEnabled() {
265+
return Preferences.getInstance().getBooleanPref(Preferences.FILTER_DELTA_NEW_ISSUES);
266+
}
267+
264268
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/MenuHandler.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.snyk.eclipse.plugin.views;
22

3+
import java.nio.file.Path;
4+
import java.util.concurrent.CompletableFuture;
5+
36
import org.eclipse.core.commands.AbstractHandler;
47
import org.eclipse.core.commands.ExecutionEvent;
58
import org.eclipse.core.commands.ExecutionException;
@@ -10,7 +13,7 @@
1013
import org.eclipse.ui.IWorkbenchWindow;
1114
import org.eclipse.ui.handlers.HandlerUtil;
1215

13-
import io.snyk.languageserver.LsCommandID;
16+
import io.snyk.eclipse.plugin.utils.ResourceUtils;
1417
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;
1518

1619
public class MenuHandler extends AbstractHandler {
@@ -23,7 +26,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
2326

2427
Object firstElement = structured.getFirstElement();
2528
IProject project = null;
26-
29+
2730
if (firstElement instanceof JavaProject) {
2831
project = ((JavaProject) firstElement).getProject();
2932
}
@@ -32,7 +35,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
3235
project = (IProject) firstElement;
3336
}
3437

35-
SnykExtendedLanguageClient.getInstance().triggerScan(project.getFullPath().toOSString());
38+
Path fullPath = ResourceUtils.getFullPath(project);
39+
40+
CompletableFuture.runAsync(() -> {
41+
SnykExtendedLanguageClient.getInstance().triggerScan(fullPath);
42+
});
43+
3644
return null;
3745
}
3846
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/ScanWorkspaceMenuHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.snyk.eclipse.plugin.views;
22

3+
import java.util.concurrent.CompletableFuture;
4+
35
import org.eclipse.core.commands.AbstractHandler;
46
import org.eclipse.core.commands.ExecutionEvent;
57
import org.eclipse.core.commands.ExecutionException;
@@ -9,7 +11,9 @@
911
public class ScanWorkspaceMenuHandler extends AbstractHandler {
1012

1113
public Object execute(ExecutionEvent event) throws ExecutionException {
12-
SnykExtendedLanguageClient.getInstance().triggerScan(null);
14+
CompletableFuture.runAsync(() -> {
15+
SnykExtendedLanguageClient.getInstance().triggerScan(null);
16+
});
1317
return null;
1418
}
1519
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/BaseBranchDialog.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

3+
import java.nio.file.Path;
34
import java.util.Arrays;
5+
import java.util.concurrent.CompletableFuture;
46

57
import org.eclipse.core.resources.IProject;
68
import org.eclipse.swt.SWT;
@@ -24,7 +26,7 @@ public class BaseBranchDialog {
2426
public BaseBranchDialog() {
2527
}
2628

27-
public void baseBranchDialog(Display display, String projectPath, String[] localBranches) {
29+
public void baseBranchDialog(Display display, Path projectPath, String[] localBranches) {
2830
Shell shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
2931
shell.setText("Choose base branch for net-new issues scanning");
3032
shell.setLayout(new GridLayout(1, false));
@@ -48,7 +50,9 @@ public void widgetSelected(SelectionEvent e) {
4850
if (Arrays.asList(localBranches).contains(selectedBranch)) {
4951
preferenceState.setBaseBranch(projectPath, selectedBranch);
5052
shell.close();
51-
SnykExtendedLanguageClient.getInstance().triggerScan(projectPath);
53+
CompletableFuture.runAsync(() -> {
54+
SnykExtendedLanguageClient.getInstance().triggerScan(projectPath);
55+
});
5256
} else {
5357
SnykLogger.logInfo("Branch is not a valid local branch for repository: " + projectPath);
5458
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/SnykToolView.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

33
import java.nio.file.Paths;
4+
import java.util.concurrent.CompletableFuture;
45

56
import org.eclipse.jface.action.IMenuManager;
67
import org.eclipse.jface.action.MenuManager;
@@ -101,16 +102,17 @@ public void selectionChanged(SelectionChangedEvent event) {
101102
.getBooleanPref(Preferences.FILTER_DELTA_NEW_ISSUES);
102103
if (node instanceof ContentRootNode && deltaEnabled) {
103104
ContentRootNode contentNode = (ContentRootNode) node;
104-
String projectPath = contentNode.getPath().toString();
105-
String[] localBranches = folderConfigs.getLocalBranches(projectPath).toArray(new String[0]);
105+
String[] localBranches = folderConfigs.getLocalBranches(contentNode.getPath())
106+
.toArray(new String[0]);
106107

107-
new BaseBranchDialog().baseBranchDialog(Display.getDefault(), projectPath, localBranches);
108+
new BaseBranchDialog().baseBranchDialog(Display.getDefault(), contentNode.getPath(),
109+
localBranches);
108110
}
109111
});
110112
}
111113
});
112114

113-
if (Preferences.getInstance().getBooleanPref(Preferences.FILTER_DELTA_NEW_ISSUES))
115+
if (Preferences.isDeltaEnabled())
114116
this.enableDelta();
115117
}
116118

@@ -131,7 +133,6 @@ public void setNodeText(BaseTreeNode node, String text) {
131133
node.setText(text);
132134
Display.getDefault().asyncExec(() -> {
133135
this.treeViewer.refresh(node, true);
134-
this.treeViewer.refresh(node.getParent(), true);
135136
});
136137
}
137138

@@ -202,7 +203,7 @@ public void refreshTree() {
202203
public void resetNode(BaseTreeNode node) {
203204
if (node != null)
204205
node.reset();
205-
206+
206207
Display.getDefault().asyncExec(() -> {
207208
this.treeViewer.refresh(node, true);
208209
});
@@ -278,12 +279,10 @@ public void enableDelta() {
278279
for (BaseTreeNode node : children) {
279280
if (node instanceof ContentRootNode) {
280281
ContentRootNode contentNode = (ContentRootNode) node;
281-
String projectPath = contentNode.getPath().toString();
282-
String projectName = ResourceUtils.getProjectByPath(contentNode.getPath()).getName();
283-
String baseBranch = folderConfigs.getBaseBranch(projectPath);
282+
String baseBranch = folderConfigs.getBaseBranch(contentNode.getPath());
284283

285284
contentNode.setName(String.format("%s - Click here choose base branch [ current: %s ]",
286-
projectName, baseBranch));
285+
contentNode.getName(), baseBranch));
287286
}
288287
}
289288
}
@@ -305,7 +304,9 @@ public void disableDelta() {
305304
}
306305
}
307306

308-
SnykExtendedLanguageClient.getInstance().triggerScan(null);
307+
CompletableFuture.runAsync(() -> {
308+
SnykExtendedLanguageClient.getInstance().triggerScan(null);
309+
});
309310
}
310311

311312
// Helper method to add a command if it's not already present

plugin/src/main/java/io/snyk/languageserver/LsCommandID.java renamed to plugin/src/main/java/io/snyk/languageserver/LsConstants.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.snyk.languageserver;
22

3-
public interface LsCommandID {
3+
public interface LsConstants {
44
public static final String COMMAND_LOGIN = "snyk.login";
55
public static final String COMMAND_GET_ACTIVE_USER = "snyk.getActiveUser";
66
public static final String COMMAND_WORKSPACE_SCAN = "snyk.workspace.scan";
@@ -12,5 +12,10 @@ public interface LsCommandID {
1212
public static final String COMMAND_GET_FEATURE_FLAG_STATUS = "snyk.getFeatureFlagStatus";
1313
public static final String COMMAND_CODE_FIX_DIFFS = "snyk.code.fixDiffs";
1414
public static final String COMMAND_CODE_SUBMIT_FIX_FEEDBACK = "snyk.code.submitFixFeedback";
15-
15+
public static final String SNYK_HAS_AUTHENTICATED = "$/snyk.hasAuthenticated";
16+
public static final String SNYK_IS_AVAILABLE_CLI = "$/snyk.isAvailableCli";
17+
public static final String SNYK_ADD_TRUSTED_FOLDERS = "$/snyk.addTrustedFolders";
18+
public static final String SNYK_SCAN = "$/snyk.scan";
19+
public static final String SNYK_PUBLISH_DIAGNOSTICS_316 = "$/snyk.publishDiagnostics316";
20+
public static final String SNYK_FOLDER_CONFIG = "$/snyk.folderConfigs";
1621
}

plugin/src/main/java/io/snyk/languageserver/LsNotificationID.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)