Skip to content

Commit 0b45439

Browse files
ackebastiandoetsch
andauthored
fix: make sure all images created are disposed (#263)
* fix: make sure all images created are disposed * fix: lint fixes for NullAssignment * fix: moved all images to ImageRegistry * fix: revert changes in BaseTreeNode * fix: failing unit tests on server * fix: img handler leak * fix: build (limit to 2024.12) * fix: disable image descriptor retrieval for unit tests without display * fix: linting * chore: bump version to 3.1.0 * fix: preference migration & defaults * chore: remove unused import * fix: tests and bugs * fix: don't explicitly generate image when adding an image --------- Co-authored-by: Bastian Doetsch <bastian.doetsch@snyk.io>
1 parent a982169 commit 0b45439

File tree

29 files changed

+323
-279
lines changed

29 files changed

+323
-279
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
- add scan summary to custom UI, updating scan statuses live
77
- added support for DeepCode AI Fixes
88
- new severity icons
9+
- moved non-secret preferences to standard preference store, only use secure store for tokens
910

1011
### Fixes
12+
- leak of image handles on big projects
13+
- startup and initialization errors - now waiting for init of secure store, download and config
1114
- fixes open & ignored issue filtering toggles
1215

1316
## [3.0.0]

feature/category.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<site>
3-
<feature url="features/io.snyk.scanner_3.0.0.qualifier.jar" id="io.snyk.scanner" version="3.0.0.qualifier">
3+
<feature url="features/io.snyk.scanner_3.1.0.qualifier.jar" id="io.snyk.scanner" version="3.1.0.qualifier">
44
<category name="io.snyk.scanner"/>
55
</feature>
66
<category-def name="io.snyk.scanner" label="Snyk Security">

feature/feature.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<feature
33
id="io.snyk.scanner"
44
label="Snyk Security"
5-
version="3.0.0.qualifier"
5+
version="3.1.0.qualifier"
66
provider-name="Snyk">
77

88
<description url="https://snyk.io">

feature/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.snyk</groupId>
66
<artifactId>parent</artifactId>
7-
<version>3.0.0-SNAPSHOT</version>
7+
<version>3.1.0-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>io.snyk.scanner</artifactId>

plugin/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-RequiredExecutionEnvironment: JavaSE-17
55
Bundle-SymbolicName: io.snyk.eclipse.plugin;singleton:=true
6-
Bundle-Version: 3.0.0.qualifier
6+
Bundle-Version: 3.1.0.qualifier
77
Bundle-Activator: io.snyk.eclipse.plugin.Activator
88
Bundle-Vendor: %Bundle-Vendor
99
Require-Bundle: org.eclipse.ui,

plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.snyk</groupId>
77
<artifactId>parent</artifactId>
8-
<version>3.0.0-SNAPSHOT</version>
8+
<version>3.1.0-SNAPSHOT</version>
99
</parent>
1010

1111

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

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,95 @@
22

33
import org.eclipse.core.runtime.Platform;
44
import org.eclipse.jface.resource.ImageDescriptor;
5+
import org.eclipse.jface.resource.ImageRegistry;
6+
import org.eclipse.swt.widgets.Display;
57
import org.eclipse.ui.plugin.AbstractUIPlugin;
68
import org.osgi.framework.BundleContext;
79

10+
import io.snyk.eclipse.plugin.preferences.Preferences;
11+
import io.snyk.eclipse.plugin.utils.SnykIcons;
12+
813
/**
914
* The activator class controls the plug-in life cycle
1015
*/
1116
public class Activator extends AbstractUIPlugin {
12-
// The plug-in ID
13-
public static final String PLUGIN_ID = "io.snyk.eclipse.plugin"; //$NON-NLS-1$
14-
public static final String PLUGIN_VERSION = Platform.getBundle(Activator.PLUGIN_ID).getVersion().toString();
15-
public static final String INTEGRATION_NAME = "ECLIPSE";
16-
17-
// The shared instance
18-
private static Activator plugin;
19-
20-
@Override
21-
public void start(BundleContext context) throws Exception {
22-
super.start(context);
23-
plugin = this;
24-
}
25-
26-
@Override
27-
public void stop(BundleContext context) throws Exception {
28-
plugin = null;
29-
super.stop(context);
30-
}
31-
32-
/**
33-
* Returns the shared instance
34-
*
35-
* @return the shared instance
36-
*/
37-
public static Activator getDefault() {
38-
return plugin;
39-
}
40-
41-
/**
42-
* Returns an image descriptor for the image file at the given plug-in relative
43-
* path
44-
*
45-
* @param path the path
46-
* @return the image descriptor
47-
*/
48-
public static ImageDescriptor getImageDescriptor(String path) {
49-
return imageDescriptorFromPlugin(PLUGIN_ID, path);
50-
}
17+
private static final String ICONS_TRANSPARENT_PNG = "/icons/transparent.png";
18+
private static final String ICONS_ENABLED_PNG = "/icons/enabled.png";
19+
private static final String ICONS_SEVERITY_LOW_PNG = "/icons/severity_low.png";
20+
private static final String ICONS_SEVERITY_MEDIUM_PNG = "/icons/severity_medium.png";
21+
private static final String ICONS_SEVERITY_HIGH_PNG = "/icons/severity_high.png";
22+
private static final String ICONS_SEVERITY_CRITICAL_PNG = "/icons/severity_critical.png";
23+
private static final String ICONS_IAC_DISABLED_PNG = "/icons/iac_disabled.png";
24+
private static final String ICONS_IAC_PNG = "/icons/iac.png";
25+
private static final String ICONS_OSS_DISABLED_PNG = "/icons/oss_disabled.png";
26+
private static final String ICONS_OSS_PNG = "/icons/oss.png";
27+
private static final String ICONS_CODE_DISABLED_PNG = "/icons/code_disabled.png";
28+
private static final String ICONS_CODE_PNG = "/icons/code.png";
29+
// The plug-in ID
30+
public static final String PLUGIN_ID = "io.snyk.eclipse.plugin"; //$NON-NLS-1$
31+
public static final String PLUGIN_VERSION = Platform.getBundle(Activator.PLUGIN_ID).getVersion().toString();
32+
public static final String INTEGRATION_NAME = "ECLIPSE";
33+
34+
// The shared instance
35+
private static Activator plugin;
36+
37+
@Override
38+
public void start(BundleContext context) throws Exception {
39+
super.start(context);
40+
plugin = this;
41+
}
42+
43+
@Override
44+
public void stop(BundleContext context) throws Exception {
45+
super.stop(context);
46+
}
47+
48+
/**
49+
* Returns the shared instance
50+
*
51+
* @return the shared instance
52+
*/
53+
public static Activator getDefault() {
54+
return plugin;
55+
}
56+
57+
/**
58+
* Returns an image descriptor for the image file at the given plug-in relative
59+
* path
60+
*
61+
* @param path the path
62+
* @return the image descriptor
63+
*/
64+
public ImageDescriptor getImageDescriptor(String key) {
65+
if (Preferences.getInstance().isTest()) return null;
66+
// Use syncExec to invoke code on the SWT thread and wait for it to finish
67+
return Display.getDefault().syncCall(() -> {
68+
var imageDescriptor = getImageRegistry().getDescriptor(key);
69+
if (imageDescriptor == null) {
70+
imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
71+
}
72+
return imageDescriptor;
73+
});
74+
}
75+
76+
@Override
77+
protected void initializeImageRegistry(ImageRegistry registry) {
78+
addImageDescriptorToRegistry(registry, SnykIcons.CODE_ID, ICONS_CODE_PNG);
79+
addImageDescriptorToRegistry(registry, SnykIcons.CODE_DISABLED_ID, ICONS_CODE_DISABLED_PNG);
80+
addImageDescriptorToRegistry(registry, SnykIcons.OSS_ID, ICONS_OSS_PNG);
81+
addImageDescriptorToRegistry(registry, SnykIcons.OSS_DISABLED_ID, ICONS_OSS_DISABLED_PNG);
82+
addImageDescriptorToRegistry(registry, SnykIcons.IAC_ID, ICONS_IAC_PNG);
83+
addImageDescriptorToRegistry(registry, SnykIcons.IAC_DISABLED_ID, ICONS_IAC_DISABLED_PNG);
84+
addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_CRITICAL_ID, ICONS_SEVERITY_CRITICAL_PNG);
85+
addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_HIGH_ID, ICONS_SEVERITY_HIGH_PNG);
86+
addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_MEDIUM_ID, ICONS_SEVERITY_MEDIUM_PNG);
87+
addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_LOW_ID, ICONS_SEVERITY_LOW_PNG);
88+
addImageDescriptorToRegistry(registry, SnykIcons.ENABLED_ID, ICONS_ENABLED_PNG);
89+
addImageDescriptorToRegistry(registry, SnykIcons.DISABLED_ID, ICONS_TRANSPARENT_PNG);
90+
}
91+
92+
private void addImageDescriptorToRegistry(ImageRegistry registry, String key, String path) {
93+
ImageDescriptor descriptor = imageDescriptorFromPlugin(PLUGIN_ID, path);
94+
registry.put(key, descriptor);
95+
}
5196
}

plugin/src/main/java/io/snyk/eclipse/plugin/html/BaseHtmlProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import io.snyk.eclipse.plugin.preferences.Preferences;
1818
import io.snyk.eclipse.plugin.utils.ResourceUtils;
19+
import io.snyk.eclipse.plugin.utils.SnykLogger;
1920

2021
public class BaseHtmlProvider {
2122
private final Random random = new Random();
@@ -137,13 +138,12 @@ public String replaceCssVariables(String html) {
137138
return htmlStyled;
138139
}
139140

140-
@SuppressWarnings("PMD.EmptyCatchBlock")
141141
private int getDefaultFontSize() {
142142
int fontSize = 13;
143143
try {
144144
fontSize = getCurrentTheme().getFontRegistry().getFontData(JFaceResources.TEXT_FONT)[0].getHeight();
145145
} catch (IllegalStateException e) {
146-
// TODO improve the logic here. Expected only in unit tests.
146+
SnykLogger.logInfo("cannot get default font-size from Eclipse, using default (13)");
147147
}
148148
return fontSize;
149149
}

0 commit comments

Comments
 (0)