Skip to content

Commit e018f6c

Browse files
committed
FISH-13358 Fix IllegalArgumentException in SWT Image.init
1 parent 6f6f12a commit e018f6c

10 files changed

Lines changed: 48 additions & 45 deletions

File tree

21 Bytes
Loading
Binary file not shown.
-1014 Bytes
Loading
-618 Bytes
Loading
Binary file not shown.
Binary file not shown.
-1014 Bytes
Loading

bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/PayaraServerPlugin.java

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
******************************************************************************/
99

1010
/******************************************************************************
11-
* Copyright (c) 2018-2022 Payara Foundation
11+
* Copyright (c) 2018-2026 Payara Foundation
1212
* All rights reserved. This program and the accompanying materials
1313
* are made available under the terms of the Eclipse Public License v2.0
1414
* which accompanies this distribution, and is available at
@@ -23,10 +23,12 @@
2323
import static java.nio.charset.Charset.defaultCharset;
2424
import static org.eclipse.core.runtime.IStatus.ERROR;
2525
import static org.eclipse.core.runtime.IStatus.INFO;
26-
import static org.eclipse.jface.resource.ImageDescriptor.createFromURL;
2726
import static org.eclipse.wst.server.core.ServerCore.addRuntimeLifecycleListener;
2827

28+
import java.io.ByteArrayInputStream;
2929
import java.io.BufferedReader;
30+
import java.io.IOException;
31+
import java.io.InputStream;
3032
import java.io.InputStreamReader;
3133
import java.util.Arrays;
3234
import java.util.HashMap;
@@ -39,7 +41,9 @@
3941
import org.eclipse.core.runtime.Status;
4042
import org.eclipse.jface.resource.ImageDescriptor;
4143
import org.eclipse.jface.resource.ImageRegistry;
44+
import org.eclipse.swt.SWTException;
4245
import org.eclipse.swt.graphics.Image;
46+
import org.eclipse.swt.graphics.ImageData;
4347
import org.eclipse.ui.plugin.AbstractUIPlugin;
4448
import org.eclipse.wst.server.core.IRuntime;
4549
import org.eclipse.wst.server.core.internal.ResourceManager;
@@ -89,18 +93,37 @@ public void start(BundleContext context) throws Exception {
8993
@Override
9094
protected void initializeImageRegistry(ImageRegistry reg) {
9195
super.initializeImageRegistry(reg);
92-
reg.put(GF_SERVER_IMG, createFromURL(getBundle().getEntry("icons/obj16/payara-blue.png")));
93-
reg.put(EAR_MODULE_IMG, createFromURL(getBundle().getEntry("icons/obj16/ear.gif")));
94-
reg.put(EJB_MODULE_IMG, createFromURL(getBundle().getEntry("icons/obj16/ejb_module.gif")));
95-
reg.put(LOG_FILE_IMG, createFromURL(getBundle().getEntry("icons/obj16/logfile.png")));
96-
reg.put(WEB_MODULE_IMG, createFromURL(getBundle().getEntry("icons/obj16/web_module.gif")));
97-
reg.put(WEBSERVICE_IMG, createFromURL(getBundle().getEntry("icons/obj16/webservice.png")));
98-
reg.put(RESOURCES_IMG, createFromURL(getBundle().getEntry("icons/obj16/resources.gif")));
99-
reg.put(GF_WIZARD, createFromURL(getBundle().getEntry("icons/wizard75x66.png")));
96+
reg.put(GF_SERVER_IMG, createImageDescriptor("icons/obj16/payara-blue.png"));
97+
reg.put(EAR_MODULE_IMG, createImageDescriptor("icons/obj16/ear.gif"));
98+
reg.put(EJB_MODULE_IMG, createImageDescriptor("icons/obj16/ejb_module.gif"));
99+
reg.put(LOG_FILE_IMG, createImageDescriptor("icons/obj16/logfile.png"));
100+
reg.put(WEB_MODULE_IMG, createImageDescriptor("icons/obj16/web_module.gif"));
101+
reg.put(WEBSERVICE_IMG, createImageDescriptor("icons/obj16/webservice.png"));
102+
reg.put(RESOURCES_IMG, createImageDescriptor("icons/obj16/resources.gif"));
103+
reg.put(GF_WIZARD, createImageDescriptor("icons/wizard75x66.png"));
100104
}
101105

106+
public static ImageDescriptor createImageDescriptor(String path) {
107+
if (BUNDLE == null) {
108+
return ImageDescriptor.getMissingImageDescriptor();
109+
}
102110

103-
/**
111+
var imageUrl = BUNDLE.getEntry(path);
112+
if (imageUrl == null) {
113+
logError("Unable to locate image resource: " + path);
114+
return ImageDescriptor.getMissingImageDescriptor();
115+
}
116+
117+
try (InputStream input = imageUrl.openStream()) {
118+
byte[] imageBytes = input.readAllBytes();
119+
return ImageDescriptor.createFromImageData(new ImageData(new ByteArrayInputStream(imageBytes)));
120+
} catch (IOException | SWTException | IllegalArgumentException e) {
121+
logError("Unable to load image resource: " + path, e);
122+
return ImageDescriptor.getMissingImageDescriptor();
123+
}
124+
}
125+
126+
/**
104127
* Return the image with the given key from the image registry.
105128
* @param key java.lang.String
106129
* @return org.eclipse.jface.parts.IImage
@@ -118,26 +141,6 @@ public static ImageDescriptor getImageDescriptor(String key) {
118141
return getInstance().getImageRegistry().getDescriptor(key);
119142
}
120143

121-
// /**
122-
// * Register an image with the registry.
123-
// * @param key java.lang.String
124-
// * @param partialURL java.lang.String
125-
// */
126-
// private void registerImage(ImageRegistry registry, String key, String partialURL) {
127-
// if (ICON_BASE_URL == null) {
128-
// String pathSuffix = "icons/";
129-
// ICON_BASE_URL = singleton.getBundle().getEntry(pathSuffix);
130-
// }
131-
//
132-
// try {
133-
// ImageDescriptor id = ImageDescriptor.createFromURL(new URL(ICON_BASE_URL, partialURL));
134-
// registry.put(key, id);
135-
// imageDescriptors.put(key, id);
136-
// } catch (Exception e) {
137-
// Trace.trace(Trace.WARNING, "Error registering image", e);
138-
// }
139-
// }
140-
141144
@Override
142145
public void stop(BundleContext v) throws Exception {
143146
logMessage("STOP IS CALLED!!!!!!!!!!!!!!!!");
@@ -216,4 +219,4 @@ public static boolean is31OrAbove(IRuntime runtime) {
216219
return runtime.getRuntimeType().getId().equals(RUNTIME_TYPE);
217220
}
218221

219-
}
222+
}

bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/ui/PayaraToolsUIPlugin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
******************************************************************************/
99

1010
/******************************************************************************
11-
* Copyright (c) 2018-2022 Payara Foundation
11+
* Copyright (c) 2018-2026 Payara Foundation
1212
* All rights reserved. This program and the accompanying materials
1313
* are made available under the terms of the Eclipse Public License v2.0
1414
* which accompanies this distribution, and is available at
@@ -18,7 +18,6 @@
1818

1919
package fish.payara.eclipse.tools.server.ui;
2020

21-
import static org.eclipse.jface.resource.ImageDescriptor.createFromURL;
2221
import static org.eclipse.wst.server.core.IServer.STATE_UNKNOWN;
2322

2423
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -31,6 +30,7 @@
3130
import org.eclipse.wst.server.core.internal.UpdateServerJob;
3231

3332
import fish.payara.eclipse.tools.server.PayaraServer;
33+
import fish.payara.eclipse.tools.server.PayaraServerPlugin;
3434

3535
/**
3636
* This is used as the OSGi bundle activator, as well as the central place to get images from.
@@ -96,14 +96,14 @@ public static Image getImg(String key) {
9696
protected void initializeImageRegistry(ImageRegistry reg) {
9797
super.initializeImageRegistry(reg);
9898

99-
reg.put(EAR_MODULE_IMG, createFromURL(getBundle().getEntry("icons/obj16/ear.gif")));
100-
reg.put(EJB_MODULE_IMG, createFromURL(getBundle().getEntry("icons/obj16/ejb_module.gif")));
101-
reg.put(GF_SERVER_IMG, createFromURL(getBundle().getEntry("icons/obj16/payara-blue.png")));
102-
reg.put(LOG_FILE_IMG, createFromURL(getBundle().getEntry("icons/obj16/logfile.png")));
103-
reg.put(WEB_MODULE_IMG, createFromURL(getBundle().getEntry("icons/obj16/web_module.gif")));
104-
reg.put(WEBSERVICE_IMG, createFromURL(getBundle().getEntry("icons/obj16/webservice.png")));
105-
reg.put(RESOURCES_IMG, createFromURL(getBundle().getEntry("icons/obj16/resources.gif")));
106-
reg.put(GF_WIZARD, createFromURL(getBundle().getEntry("icons/wizard75x66.png")));
99+
reg.put(EAR_MODULE_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/ear.gif"));
100+
reg.put(EJB_MODULE_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/ejb_module.gif"));
101+
reg.put(GF_SERVER_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/payara-blue.png"));
102+
reg.put(LOG_FILE_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/logfile.png"));
103+
reg.put(WEB_MODULE_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/web_module.gif"));
104+
reg.put(WEBSERVICE_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/webservice.png"));
105+
reg.put(RESOURCES_IMG, PayaraServerPlugin.createImageDescriptor("icons/obj16/resources.gif"));
106+
reg.put(GF_WIZARD, PayaraServerPlugin.createImageDescriptor("icons/wizard75x66.png"));
107107
}
108108

109-
}
109+
}

bundles/fish.payara.eclipse.tools.server/src/fish/payara/eclipse/tools/server/utils/PayaraLocationUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
******************************************************************************/
99

1010
/******************************************************************************
11-
* Copyright (c) 2018-2024 Payara Foundation
11+
* Copyright (c) 2018-2026 Payara Foundation
1212
* All rights reserved. This program and the accompanying materials
1313
* are made available under the terms of the Eclipse Public License v2.0
1414
* which accompanies this distribution, and is available at
@@ -188,7 +188,7 @@ public static synchronized PayaraLocationUtils find(File location) {
188188
return payaraLocation;
189189
}
190190

191-
String GLASSFISH_VERSION_PROPERTIES = "glassfish\\config\\branding\\glassfish-version.properties";
191+
private static final String GLASSFISH_VERSION_PROPERTIES = "glassfish/config/branding/glassfish-version.properties";
192192

193193
// #### PayaraLocation instance methods
194194

0 commit comments

Comments
 (0)