Skip to content

Commit

Permalink
feat: add project scan capability, preserve workspace scan function [R…
Browse files Browse the repository at this point in the history
…OAD-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
  • Loading branch information
bastiandoetsch authored Jan 4, 2023
1 parent fe8dd25 commit 168d7fd
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 30 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

## [2.0.0] - Unreleased
### Changes
- submit runtime information of jdk and os to language server
- Snyk Test now scans the selected project
- Added new Snyk Test Workspace command

## [2.0.0] - v20221222.164444
### Changes
- Submit runtime information of jdk and os to language server

### Fixed
- NPE when finishing Snyk Wizard in empty workspace

## [2.0.0] - v20221220.094322
### Changes
Expand Down
2 changes: 1 addition & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Bundle-ClassPath: .,
target/dependency/commons-codec-1.15.jar,
target/dependency/commons-lang3-3.12.0.jar,
target/dependency/commons-logging-1.2.jar,
target/dependency/httpclient-4.5.13.jar,
target/dependency/httpclient-4.5.14.jar,
target/dependency/httpcore-4.4.16.jar,
target/dependency/jackson-annotations-2.14.1.jar,
target/dependency/jackson-core-2.14.1.jar,
Expand Down
5 changes: 5 additions & 0 deletions plugin/OSGI-INF/l10n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ page.name=Snyk
command.name=Run
command.label=Snyk Test
command.label.0=Snyk Test

scanWorkspace.name=snykWorkspaceScan
scanWorkspace.label=Snyk Test Workspace
command.label.0=Snyk Test Workspace

2 changes: 1 addition & 1 deletion plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bin.includes = plugin.xml,\
target/dependency/commons-codec-1.15.jar,\
target/dependency/commons-lang3-3.12.0.jar,\
target/dependency/commons-logging-1.2.jar,\
target/dependency/httpclient-4.5.13.jar,\
target/dependency/httpclient-4.5.14.jar,\
target/dependency/httpcore-4.4.16.jar,\
target/dependency/jackson-annotations-2.14.1.jar,\
target/dependency/jackson-core-2.14.1.jar,\
Expand Down
6 changes: 3 additions & 3 deletions plugin/io.snyk.eclipse.plugin.eml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<lib name="commons-logging-1.2.jar" scope="COMPILE">
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-logging-1.2.jar!/"/>
</lib>
<lib name="httpclient-4.5.13.jar" scope="COMPILE">
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpclient-4.5.13.jar!/"/>
<lib name="httpclient-4.5.14.jar" scope="COMPILE">
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpclient-4.5.14.jar!/"/>
</lib>
<lib name="httpcore-4.4.16.jar" scope="COMPILE">
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpcore-4.4.16.jar!/"/>
Expand All @@ -37,7 +37,7 @@
<level name="Maven: com.fasterxml.jackson.core:jackson-databind:2.14.1" value="project"/>
<level name="Maven: org.apache.commons:commons-lang3:3.12.0" value="project"/>
<level name="Maven: org.apache.httpcomponents:httpcore:4.4.16" value="project"/>
<level name="Maven: org.apache.httpcomponents:httpclient:4.5.13" value="project"/>
<level name="Maven: org.apache.httpcomponents:httpclient:4.5.14" value="project"/>
<level name="Maven: commons-logging:commons-logging:1.2" value="project"/>
<level name="Maven: commons-codec:commons-codec:1.15" value="project"/>
<level name="Maven: javax.inject:javax.inject:1" value="project"/>
Expand Down
17 changes: 17 additions & 0 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
id="io.snyk.eclipse.plugin.commands.execute"
name="%command.name">
</command>
<command
defaultHandler="io.snyk.eclipse.plugin.views.ScanWorkspaceMenuHandler"
id="io.snyk.eclipse.plugin.commands.snykWorkspaceScan"
name="%scanWorkspace.name">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
Expand All @@ -73,6 +78,12 @@
</with>
</visibleWhen>
</command>
<command
commandId="io.snyk.eclipse.plugin.commands.snykWorkspaceScan"
icon="icons/patch.png"
label="%scanWorkspace.label"
style="push">
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.menus">
Expand All @@ -93,6 +104,12 @@
</with>
</visibleWhen>
</command>
<command
commandId="io.snyk.eclipse.plugin.commands.snykWorkspaceScan"
icon="icons/patch.png"
label="%scanWorkspace.label"
style="push">
</command>
</menuContribution>
</extension>
<extension point="org.eclipse.ui.startup">
Expand Down
2 changes: 1 addition & 1 deletion plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<version>4.5.14</version>
<exclusions>
<exclusion>
<!-- fix vulnerability in referenced dependency by adding it explicitly below and excluding it here -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.snyk.eclipse.plugin.views;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;

public class ScanWorkspaceMenuHandler extends AbstractHandler {

public Object execute(ExecutionEvent event) throws ExecutionException {
SnykExtendedLanguageClient.getInstance().triggerScan(null);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public void run() {
public void run() {
if (alreadyRunning)
return;
showMessage(RUNNING);
scanWorkspace.setEnabled(false);
abortScanning.setEnabled(true);
showMessage(RUNNING);

CompletableFuture.runAsync(() -> {
SnykExtendedLanguageClient.getInstance().triggerScan(null);
Expand Down Expand Up @@ -285,9 +285,9 @@ public void enableScanBasedOnConfig() {
public void testProject(String projectName) {
if (alreadyRunning)
return;
showMessage(RUNNING);
scanWorkspace.setEnabled(false);
abortScanning.setEnabled(true);
showMessage(RUNNING);

CompletableFuture.runAsync(() -> {
alreadyRunning = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

public static URI getBaseUri() {
return URI.create(String.format("%s/%s", LS_DOWNLOAD_BASE_URL, REQUIRED_LS_PROTOCOL_VERSION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.stream.Collectors;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
Expand Down Expand Up @@ -58,27 +59,27 @@ public void triggerScan(IWorkbenchWindow window) {
runSnykWizard();
} else {
try {
executeCommand("snyk.workspace.scan", new ArrayList<>());

if (window == null) {
window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}
if (window == null) {
executeCommand("snyk.workspace.scan", new ArrayList<>());
return;
}

ISelectionService service = window.getSelectionService();
IStructuredSelection structured = (IStructuredSelection) service.getSelection();

Object firstElement = structured.getFirstElement();

IProject project = null;
if (firstElement instanceof JavaProject) {
project = ((JavaProject) firstElement).getProject();
}

if (firstElement instanceof IProject) {
IProject project = (IProject) firstElement;
runForProject(project.getName());
project = (IProject) firstElement;
}

if (firstElement instanceof JavaProject) {
JavaProject javaproject = (JavaProject) firstElement;
runForProject(javaproject.getProject().getName());
if (project != null) {
runForProject(project.getName());
executeCommand("snyk.workspaceFolder.scan", List.of(project.getLocation().toOSString()));
}
} catch (Exception e) {
SnykLogger.logError(e);
Expand Down Expand Up @@ -118,12 +119,8 @@ public void addTrustedPaths(SnykTrustedFoldersParams param) {
var trustedPaths = storedTrustedPaths.split(File.pathSeparator);
var pathSet = new HashSet<>(Arrays.asList(trustedPaths));
pathSet.addAll(Arrays.asList(param.getTrustedFolders()));
Preferences.getInstance().store(Preferences.TRUSTED_FOLDERS,
pathSet.stream()
.filter(s -> !s.isBlank())
.map(s -> s.trim())
.distinct()
.collect(Collectors.joining(File.pathSeparator)));
Preferences.getInstance().store(Preferences.TRUSTED_FOLDERS, pathSet.stream().filter(s -> !s.isBlank())
.map(s -> s.trim()).distinct().collect(Collectors.joining(File.pathSeparator)));
}

@Override
Expand Down Expand Up @@ -193,6 +190,4 @@ public CompletableFuture<ShowDocumentResult> showDocument(ShowDocumentParams par
});
}



}
2 changes: 1 addition & 1 deletion tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<version>4.5.14</version>
<exclusions>
<exclusion>
<!-- fix vulnerability in referenced dependency by adding it explicitly below and excluding it here -->
Expand Down

0 comments on commit 168d7fd

Please sign in to comment.