Skip to content

Commit a8fff73

Browse files
committed
feat: added initial text and image to browser view. No styling!
1 parent dc7d5a8 commit a8fff73

3 files changed

Lines changed: 45 additions & 11 deletions

File tree

plugin/OSGI-INF/l10n/bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ command.label.0=Snyk Test Project
1313
scanWorkspace.name=snykWorkspaceScan
1414
scanWorkspace.label=Snyk Test Workspace
1515

16+
snyk.trust.dialog.warning.text=When scanning project files for vulnerabilities, Snyk may automatically execute code such as invoking the package manager to get dependency information.<br><br>You should only scan projects you trust.<br><br>

plugin/icons/logo_snyk.png

8.64 KB
Loading

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/SnykToolView.java

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
*/
44
package io.snyk.eclipse.plugin.views.snyktoolview;
55

6+
import java.io.ByteArrayOutputStream;
7+
import java.io.InputStream;
8+
import java.net.URL;
9+
import java.util.Base64;
10+
611
import javax.inject.Inject;
712

13+
import org.eclipse.core.runtime.FileLocator;
14+
import org.eclipse.core.runtime.Path;
15+
import org.eclipse.core.runtime.Platform;
816
import org.eclipse.jface.action.Action;
917
import org.eclipse.jface.preference.PreferenceDialog;
1018
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -23,6 +31,7 @@
2331
import org.eclipse.ui.PlatformUI;
2432
import org.eclipse.ui.dialogs.PreferencesUtil;
2533
import org.eclipse.ui.part.ViewPart;
34+
import org.osgi.framework.Bundle;
2635

2736
/**
2837
* The view will replace the old SnykView. TODO move the snyktoolview classes
@@ -101,21 +110,26 @@ private String generateHtmlContent(TreeNode node) {
101110
}
102111

103112
private String generateHtmlContent(String text) {
104-
return "<html><body><h1>" + "</h1><p>Content for " + "</p></body></html>";
113+
return "<html><body<p>" + text + "</p></body></html>";
105114
}
106115

107116
private void initBrowserText() {
117+
String snykWarningText = Platform.getResourceString(Platform.getBundle("io.snyk.eclipse.plugin"),
118+
"%snyk.trust.dialog.warning.text");
119+
120+
Bundle bundle = Platform.getBundle("io.snyk.eclipse.plugin");
121+
URL imageUrl = FileLocator.find(bundle, new Path("icons/logo_snyk.png"), null);
122+
123+
byte[] imageData = getImageDataFromUrl(imageUrl);
108124

109-
browser.setText("<!DOCTYPE html>\n" + "<html lang=\"en\">\n" + "<head>\n" + " <meta charset=\"UTF-8\">\n"
110-
+ " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
111-
+ " <title>Snyk for JetBrains</title>\n" + "</head>\n" + "<body>\n"
112-
+ " <p><strong>Welcome to Snyk for JetBrains</strong></p>\n" + "\n" + " <ol>\n"
113-
+ " <li align=\"left\">Authenticate to Snyk.io</li>\n"
114-
+ " <li align=\"left\">Analyze code for issues and vulnerabilities</li>\n"
115-
+ " <li align=\"left\">Improve your code and upgrade dependencies</li>\n" + " </ol>\n" + "\n"
116-
+ " <p>\n"
117-
+ " When scanning project files for vulnerabilities, Snyk may automatically execute code such as invoking the package manager to get dependency information.<br><br>You should only scan projects you trust.<br><br>\n"
118-
+ "</body>\n" + "</html>");
125+
String base64Image = Base64.getEncoder().encodeToString(imageData);
126+
127+
browser.setText("<!DOCTYPE html> <html lang=\"en\"> <head> <meta charset=\"UTF-8\"> "
128+
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> "
129+
+ "<title>Snyk for JetBrains</title> <style> .container { display: flex; align-items: center; } .logo { margin-right: 20px; } "
130+
+ "</style> </head> <body> <div class=\"container\"> " + "<img src='data:image/png;base64,"
131+
+ base64Image + "' alt='Snyk Logo'>" + "<div> <p><strong>Welcome to Snyk for JetBrains</strong></p>"
132+
+ " <p>\n" + snykWarningText + "</body>\n" + "</html>");
119133
}
120134

121135
private Object createTreeInput() {
@@ -153,6 +167,25 @@ public void run() {
153167

154168
}
155169

170+
public byte[] getImageDataFromUrl(URL imageUrl) {
171+
try {
172+
ByteArrayOutputStream output = new ByteArrayOutputStream();
173+
174+
try (InputStream inputStream = imageUrl.openStream()) {
175+
int n = 0;
176+
byte[] buffer = new byte[1024];
177+
while (-1 != (n = inputStream.read(buffer))) {
178+
output.write(buffer, 0, n);
179+
}
180+
}
181+
182+
return output.toByteArray();
183+
} catch (Exception e) {
184+
e.printStackTrace();
185+
return null;
186+
}
187+
}
188+
156189
private static Shell getShell() {
157190
var activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
158191
if (activeWorkbenchWindow == null)

0 commit comments

Comments
 (0)