Skip to content

Commit a982169

Browse files
fix: race-conditions during startup, bugfixes (#269)
* fix: race-conditions during startup * fix: tests and tool view * fix: don't wait for download if testing * chore: fix a few pmd violations * fix: a few more PMD issues * fix: a download bug * fix: select issue from cache for ai fix * fix: more linting fixes * fix: even more linting * fix: pmd found even more! we fixed it! * fix: test failure * fix: NPE --------- Co-authored-by: Abdelrahman Shawki Hassan <[email protected]>
1 parent e95fd35 commit a982169

35 files changed

+1543
-1064
lines changed

plugin/src/main/java/io/snyk/eclipse/plugin/SnykStartup.java

+25-24
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,42 @@ public class SnykStartup implements IStartup {
3838
private static SnykToolView snykToolView;
3939
private static boolean downloading = true;
4040
private static ILog logger;
41-
41+
4242
@Override
4343
public void earlyStartup() {
4444
if (logger == null) {
4545
logger = Platform.getLog(getClass());
4646
}
4747
runtimeEnvironment = new LsRuntimeEnvironment();
48-
Job initJob = new Job("Downloading latest CLI release...") {
48+
Job initJob = new Job("Initializing Snyk...") {
4949
@Override
5050
protected IStatus run(IProgressMonitor monitor) {
51+
monitor.beginTask("Initializing...", 100);
52+
downloadIfNeeded(monitor);
53+
monitor.subTask("Starting Language Server...");
54+
55+
try {
56+
SnykLanguageServer.startSnykLanguageServer();
57+
58+
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
59+
Preferences prefs = Preferences.getInstance();
60+
if (prefs.getAuthToken().isBlank() && !prefs.isTest()) {
61+
monitor.subTask("Starting Snyk Wizard to configure initial settings...");
62+
SnykWizard.createAndLaunch();
63+
}
64+
});
65+
} catch (RuntimeException e) {
66+
SnykLogger.logError(e);
67+
}
68+
monitor.done();
69+
return Status.OK_STATUS;
70+
}
71+
72+
private void downloadIfNeeded(IProgressMonitor monitor) {
5173
try {
5274
logger.info("LS: Checking for needed download");
5375
if (downloadLS()) {
54-
monitor.beginTask("Downloading CLI", 100);
76+
monitor.subTask("Downloading CLI");
5577
logger.info("LS: Need to download");
5678
downloading = true;
5779
download(monitor);
@@ -60,27 +82,6 @@ protected IStatus run(IProgressMonitor monitor) {
6082
logError(exception);
6183
}
6284
downloading = false;
63-
monitor.subTask("Starting Snyk CLI in Language Server mode...");
64-
startLanguageServer();
65-
66-
PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
67-
Preferences prefs = Preferences.getInstance();
68-
if (prefs.getAuthToken().isBlank() && !prefs.isTest()) {
69-
monitor.subTask("Starting Snyk Wizard to configure initial settings...");
70-
SnykWizard.createAndLaunch();
71-
}
72-
});
73-
monitor.done();
74-
75-
return Status.OK_STATUS;
76-
}
77-
78-
private void startLanguageServer() {
79-
try {
80-
SnykLanguageServer.startSnykLanguageServer();
81-
} catch (RuntimeException e) {
82-
logError(e);
83-
}
8485
}
8586
};
8687
initJob.setPriority(Job.LONG);

plugin/src/main/java/io/snyk/eclipse/plugin/analytics/TaskProcessor.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
public class TaskProcessor {
2020
// left = taskToExecute, right = callback function
21-
private final Queue<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> taskQueue = new ConcurrentLinkedQueue<>();
21+
private static final Queue<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> taskQueue = new ConcurrentLinkedQueue<>();
2222

2323
private TaskProcessor() {
2424
CompletableFuture.runAsync(() -> {
@@ -29,11 +29,9 @@ private TaskProcessor() {
2929
private static TaskProcessor instance;
3030

3131
public static TaskProcessor getInstance() {
32-
synchronized (TaskProcessor.class) {
32+
synchronized (taskQueue) {
3333
if (instance == null) {
34-
if (instance == null) {
35-
instance = new TaskProcessor();
36-
}
34+
instance = new TaskProcessor();
3735
}
3836
}
3937
return instance;

0 commit comments

Comments
 (0)