Skip to content

Commit 168d7fd

Browse files
feat: add project scan capability, preserve workspace scan function [ROAD-1239] (#119)
* feat: ✨ scan project (instead of workspace) when triggering project scan from context menu * feat: ✨ add new Snyk Test Workspace context menu item * docs: updated CHANGELOG.md * chore: bump required protocol version to 5 for new command. * fix: update httpcomponents to 4.5.14 * docs: update CHANGELOG.md * fix: remove redundant if
1 parent fe8dd25 commit 168d7fd

File tree

12 files changed

+72
-30
lines changed

12 files changed

+72
-30
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
## [2.0.0] - Unreleased
44
### Changes
5-
- submit runtime information of jdk and os to language server
5+
- Snyk Test now scans the selected project
6+
- Added new Snyk Test Workspace command
7+
8+
## [2.0.0] - v20221222.164444
9+
### Changes
10+
- Submit runtime information of jdk and os to language server
11+
12+
### Fixed
13+
- NPE when finishing Snyk Wizard in empty workspace
614

715
## [2.0.0] - v20221220.094322
816
### Changes

plugin/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Bundle-ClassPath: .,
2929
target/dependency/commons-codec-1.15.jar,
3030
target/dependency/commons-lang3-3.12.0.jar,
3131
target/dependency/commons-logging-1.2.jar,
32-
target/dependency/httpclient-4.5.13.jar,
32+
target/dependency/httpclient-4.5.14.jar,
3333
target/dependency/httpcore-4.4.16.jar,
3434
target/dependency/jackson-annotations-2.14.1.jar,
3535
target/dependency/jackson-core-2.14.1.jar,

plugin/OSGI-INF/l10n/bundle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ page.name=Snyk
88
command.name=Run
99
command.label=Snyk Test
1010
command.label.0=Snyk Test
11+
12+
scanWorkspace.name=snykWorkspaceScan
13+
scanWorkspace.label=Snyk Test Workspace
14+
command.label.0=Snyk Test Workspace
15+

plugin/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bin.includes = plugin.xml,\
1010
target/dependency/commons-codec-1.15.jar,\
1111
target/dependency/commons-lang3-3.12.0.jar,\
1212
target/dependency/commons-logging-1.2.jar,\
13-
target/dependency/httpclient-4.5.13.jar,\
13+
target/dependency/httpclient-4.5.14.jar,\
1414
target/dependency/httpcore-4.4.16.jar,\
1515
target/dependency/jackson-annotations-2.14.1.jar,\
1616
target/dependency/jackson-core-2.14.1.jar,\

plugin/io.snyk.eclipse.plugin.eml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<lib name="commons-logging-1.2.jar" scope="COMPILE">
1414
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-logging-1.2.jar!/"/>
1515
</lib>
16-
<lib name="httpclient-4.5.13.jar" scope="COMPILE">
17-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpclient-4.5.13.jar!/"/>
16+
<lib name="httpclient-4.5.14.jar" scope="COMPILE">
17+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpclient-4.5.14.jar!/"/>
1818
</lib>
1919
<lib name="httpcore-4.4.16.jar" scope="COMPILE">
2020
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpcore-4.4.16.jar!/"/>
@@ -37,7 +37,7 @@
3737
<level name="Maven: com.fasterxml.jackson.core:jackson-databind:2.14.1" value="project"/>
3838
<level name="Maven: org.apache.commons:commons-lang3:3.12.0" value="project"/>
3939
<level name="Maven: org.apache.httpcomponents:httpcore:4.4.16" value="project"/>
40-
<level name="Maven: org.apache.httpcomponents:httpclient:4.5.13" value="project"/>
40+
<level name="Maven: org.apache.httpcomponents:httpclient:4.5.14" value="project"/>
4141
<level name="Maven: commons-logging:commons-logging:1.2" value="project"/>
4242
<level name="Maven: commons-codec:commons-codec:1.15" value="project"/>
4343
<level name="Maven: javax.inject:javax.inject:1" value="project"/>

plugin/plugin.xml

+17
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
id="io.snyk.eclipse.plugin.commands.execute"
5252
name="%command.name">
5353
</command>
54+
<command
55+
defaultHandler="io.snyk.eclipse.plugin.views.ScanWorkspaceMenuHandler"
56+
id="io.snyk.eclipse.plugin.commands.snykWorkspaceScan"
57+
name="%scanWorkspace.name">
58+
</command>
5459
</extension>
5560
<extension
5661
point="org.eclipse.ui.menus">
@@ -73,6 +78,12 @@
7378
</with>
7479
</visibleWhen>
7580
</command>
81+
<command
82+
commandId="io.snyk.eclipse.plugin.commands.snykWorkspaceScan"
83+
icon="icons/patch.png"
84+
label="%scanWorkspace.label"
85+
style="push">
86+
</command>
7687
</menuContribution>
7788
</extension>
7889
<extension point="org.eclipse.ui.menus">
@@ -93,6 +104,12 @@
93104
</with>
94105
</visibleWhen>
95106
</command>
107+
<command
108+
commandId="io.snyk.eclipse.plugin.commands.snykWorkspaceScan"
109+
icon="icons/patch.png"
110+
label="%scanWorkspace.label"
111+
style="push">
112+
</command>
96113
</menuContribution>
97114
</extension>
98115
<extension point="org.eclipse.ui.startup">

plugin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>org.apache.httpcomponents</groupId>
4848
<artifactId>httpclient</artifactId>
49-
<version>4.5.13</version>
49+
<version>4.5.14</version>
5050
<exclusions>
5151
<exclusion>
5252
<!-- fix vulnerability in referenced dependency by adding it explicitly below and excluding it here -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.snyk.eclipse.plugin.views;
2+
3+
import org.eclipse.core.commands.AbstractHandler;
4+
import org.eclipse.core.commands.ExecutionEvent;
5+
import org.eclipse.core.commands.ExecutionException;
6+
import org.eclipse.ui.IWorkbenchWindow;
7+
import org.eclipse.ui.handlers.HandlerUtil;
8+
9+
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;
10+
11+
public class ScanWorkspaceMenuHandler extends AbstractHandler {
12+
13+
public Object execute(ExecutionEvent event) throws ExecutionException {
14+
SnykExtendedLanguageClient.getInstance().triggerScan(null);
15+
return null;
16+
}
17+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ public void run() {
213213
public void run() {
214214
if (alreadyRunning)
215215
return;
216-
showMessage(RUNNING);
217216
scanWorkspace.setEnabled(false);
218217
abortScanning.setEnabled(true);
218+
showMessage(RUNNING);
219219

220220
CompletableFuture.runAsync(() -> {
221221
SnykExtendedLanguageClient.getInstance().triggerScan(null);
@@ -285,9 +285,9 @@ public void enableScanBasedOnConfig() {
285285
public void testProject(String projectName) {
286286
if (alreadyRunning)
287287
return;
288-
showMessage(RUNNING);
289288
scanWorkspace.setEnabled(false);
290289
abortScanning.setEnabled(true);
290+
showMessage(RUNNING);
291291

292292
CompletableFuture.runAsync(() -> {
293293
alreadyRunning = true;

plugin/src/main/java/io/snyk/languageserver/download/LsBinaries.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class LsBinaries {
66
private static final String LS_DOWNLOAD_BASE_URL = "https://static.snyk.io/snyk-ls";
7-
public static final String REQUIRED_LS_PROTOCOL_VERSION = "4";
7+
public static final String REQUIRED_LS_PROTOCOL_VERSION = "5";
88

99
public static URI getBaseUri() {
1010
return URI.create(String.format("%s/%s", LS_DOWNLOAD_BASE_URL, REQUIRED_LS_PROTOCOL_VERSION));

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

+14-19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.stream.Collectors;
1010

1111
import org.eclipse.core.resources.IProject;
12+
import org.eclipse.core.runtime.Platform;
1213
import org.eclipse.jdt.internal.core.JavaProject;
1314
import org.eclipse.jface.viewers.IStructuredSelection;
1415
import org.eclipse.jface.wizard.WizardDialog;
@@ -58,27 +59,27 @@ public void triggerScan(IWorkbenchWindow window) {
5859
runSnykWizard();
5960
} else {
6061
try {
61-
executeCommand("snyk.workspace.scan", new ArrayList<>());
62-
63-
if (window == null) {
64-
window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
65-
}
6662
if (window == null) {
63+
executeCommand("snyk.workspace.scan", new ArrayList<>());
6764
return;
6865
}
66+
6967
ISelectionService service = window.getSelectionService();
7068
IStructuredSelection structured = (IStructuredSelection) service.getSelection();
7169

7270
Object firstElement = structured.getFirstElement();
73-
71+
IProject project = null;
72+
if (firstElement instanceof JavaProject) {
73+
project = ((JavaProject) firstElement).getProject();
74+
}
75+
7476
if (firstElement instanceof IProject) {
75-
IProject project = (IProject) firstElement;
76-
runForProject(project.getName());
77+
project = (IProject) firstElement;
7778
}
7879

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()));
8283
}
8384
} catch (Exception e) {
8485
SnykLogger.logError(e);
@@ -118,12 +119,8 @@ public void addTrustedPaths(SnykTrustedFoldersParams param) {
118119
var trustedPaths = storedTrustedPaths.split(File.pathSeparator);
119120
var pathSet = new HashSet<>(Arrays.asList(trustedPaths));
120121
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)));
127124
}
128125

129126
@Override
@@ -193,6 +190,4 @@ public CompletableFuture<ShowDocumentResult> showDocument(ShowDocumentParams par
193190
});
194191
}
195192

196-
197-
198193
}

tests/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>org.apache.httpcomponents</groupId>
4444
<artifactId>httpclient</artifactId>
45-
<version>4.5.13</version>
45+
<version>4.5.14</version>
4646
<exclusions>
4747
<exclusion>
4848
<!-- fix vulnerability in referenced dependency by adding it explicitly below and excluding it here -->

0 commit comments

Comments
 (0)