|
9 | 9 | import java.util.stream.Collectors;
|
10 | 10 |
|
11 | 11 | import org.eclipse.core.resources.IProject;
|
| 12 | +import org.eclipse.core.runtime.Platform; |
12 | 13 | import org.eclipse.jdt.internal.core.JavaProject;
|
13 | 14 | import org.eclipse.jface.viewers.IStructuredSelection;
|
14 | 15 | import org.eclipse.jface.wizard.WizardDialog;
|
@@ -58,27 +59,27 @@ public void triggerScan(IWorkbenchWindow window) {
|
58 | 59 | runSnykWizard();
|
59 | 60 | } else {
|
60 | 61 | try {
|
61 |
| - executeCommand("snyk.workspace.scan", new ArrayList<>()); |
62 |
| - |
63 |
| - if (window == null) { |
64 |
| - window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); |
65 |
| - } |
66 | 62 | if (window == null) {
|
| 63 | + executeCommand("snyk.workspace.scan", new ArrayList<>()); |
67 | 64 | return;
|
68 | 65 | }
|
| 66 | + |
69 | 67 | ISelectionService service = window.getSelectionService();
|
70 | 68 | IStructuredSelection structured = (IStructuredSelection) service.getSelection();
|
71 | 69 |
|
72 | 70 | Object firstElement = structured.getFirstElement();
|
73 |
| - |
| 71 | + IProject project = null; |
| 72 | + if (firstElement instanceof JavaProject) { |
| 73 | + project = ((JavaProject) firstElement).getProject(); |
| 74 | + } |
| 75 | + |
74 | 76 | if (firstElement instanceof IProject) {
|
75 |
| - IProject project = (IProject) firstElement; |
76 |
| - runForProject(project.getName()); |
| 77 | + project = (IProject) firstElement; |
77 | 78 | }
|
78 | 79 |
|
79 |
| - if (firstElement instanceof JavaProject) { |
80 |
| - JavaProject javaproject = (JavaProject) firstElement; |
81 |
| - runForProject(javaproject.getProject().getName()); |
| 80 | + if (project != null) { |
| 81 | + runForProject(project.getName()); |
| 82 | + executeCommand("snyk.workspaceFolder.scan", List.of(project.getLocation().toOSString())); |
82 | 83 | }
|
83 | 84 | } catch (Exception e) {
|
84 | 85 | SnykLogger.logError(e);
|
@@ -118,12 +119,8 @@ public void addTrustedPaths(SnykTrustedFoldersParams param) {
|
118 | 119 | var trustedPaths = storedTrustedPaths.split(File.pathSeparator);
|
119 | 120 | var pathSet = new HashSet<>(Arrays.asList(trustedPaths));
|
120 | 121 | pathSet.addAll(Arrays.asList(param.getTrustedFolders()));
|
121 |
| - Preferences.getInstance().store(Preferences.TRUSTED_FOLDERS, |
122 |
| - pathSet.stream() |
123 |
| - .filter(s -> !s.isBlank()) |
124 |
| - .map(s -> s.trim()) |
125 |
| - .distinct() |
126 |
| - .collect(Collectors.joining(File.pathSeparator))); |
| 122 | + Preferences.getInstance().store(Preferences.TRUSTED_FOLDERS, pathSet.stream().filter(s -> !s.isBlank()) |
| 123 | + .map(s -> s.trim()).distinct().collect(Collectors.joining(File.pathSeparator))); |
127 | 124 | }
|
128 | 125 |
|
129 | 126 | @Override
|
@@ -193,6 +190,4 @@ public CompletableFuture<ShowDocumentResult> showDocument(ShowDocumentParams par
|
193 | 190 | });
|
194 | 191 | }
|
195 | 192 |
|
196 |
| - |
197 |
| - |
198 | 193 | }
|
0 commit comments