Skip to content

Commit e71ca89

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents 79baa5a + 6c10cbf commit e71ca89

File tree

4 files changed

+63
-26
lines changed

4 files changed

+63
-26
lines changed

bundles/org.eclipse.jface/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Export-Package: org.eclipse.jface,
1818
org.eclipse.jface.fieldassist,
1919
org.eclipse.jface.fieldassist.images,
2020
org.eclipse.jface.images,
21-
org.eclipse.jface.internal;x-friends:="org.eclipse.ui.workbench,org.eclipse.e4.ui.workbench.renderers.swt",
21+
org.eclipse.jface.internal;x-friends:="org.eclipse.ui.workbench,org.eclipse.e4.ui.workbench.renderers.swt,org.eclipse.jface.tests",
2222
org.eclipse.jface.internal.provisional.action;x-friends:="org.eclipse.ui.workbench,org.eclipse.ui.ide",
2323
org.eclipse.jface.layout,
2424
org.eclipse.jface.menus,

bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919

2020

2121
import java.io.BufferedInputStream;
22+
import java.io.File;
2223
import java.io.IOException;
2324
import java.io.InputStream;
2425
import java.net.MalformedURLException;
2526
import java.net.URL;
26-
import java.nio.file.Files;
27-
import java.nio.file.Path;
2827
import java.util.function.Function;
2928
import java.util.regex.Matcher;
3029
import java.util.regex.Pattern;
@@ -246,24 +245,16 @@ private static String getxPath(String name, int zoom) {
246245
*
247246
* @return {@link String} or <code>null</code> if the file cannot be found
248247
*/
249-
private static String getFilePath(URL url, boolean logIOException) {
248+
private static String getFilePath(URL url, boolean logException) {
250249
try {
251250
if (!InternalPolicy.OSGI_AVAILABLE) {
252-
if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
253-
return IPath.fromOSString(url.getFile()).toOSString();
254-
return null;
251+
return getFilePath(url);
255252
}
256253
url = resolvePathVariables(url);
257254
URL locatedURL = FileLocator.toFileURL(url);
258-
if (FILE_PROTOCOL.equalsIgnoreCase(locatedURL.getProtocol())) {
259-
String filePath = IPath.fromOSString(locatedURL.getPath()).toOSString();
260-
if (Files.exists(Path.of(filePath))) {
261-
return filePath;
262-
}
263-
}
264-
return null;
255+
return getFilePath(locatedURL);
265256
} catch (IOException e) {
266-
if (logIOException) {
257+
if (logException) {
267258
Policy.logException(e);
268259
} else if (InternalPolicy.DEBUG_LOG_URL_IMAGE_DESCRIPTOR_MISSING_2x) {
269260
String path = url.getPath();
@@ -275,6 +266,16 @@ private static String getFilePath(URL url, boolean logIOException) {
275266
}
276267
}
277268

269+
private static String getFilePath(URL url) {
270+
if (FILE_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
271+
File file = IPath.fromOSString(url.getPath()).toFile();
272+
if (file.exists()) {
273+
return file.getPath();
274+
}
275+
}
276+
return null;
277+
}
278+
278279
private static URL resolvePathVariables(URL url) {
279280
URL platformURL = FileLocator.find(url); // Resolve variables within URL's path
280281
if (platformURL != null) {

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/e4/compatibility/CompatibilityEditor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ public class CompatibilityEditor extends CompatibilityPart {
5959
@Override
6060
IWorkbenchPart createPart(WorkbenchPartReference reference) throws PartInitException {
6161
IWorkbenchPart part = super.createPart(reference);
62-
IEditorInput input = ((EditorReference) reference).getEditorInput();
63-
if (input instanceof MultiEditorInput && part instanceof MultiEditor) {
64-
createMultiEditorChildren(part, input);
62+
if (part instanceof MultiEditor) {
63+
IEditorInput input = ((EditorReference) reference).getEditorInput();
64+
if (input instanceof MultiEditorInput) {
65+
createMultiEditorChildren(part, input);
66+
}
6567
}
6668
return part;
6769
}

tests/org.eclipse.jface.tests/src/org/eclipse/jface/tests/images/UrlImageDescriptorTest.java

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import static org.junit.Assert.assertNotSame;
2222
import static org.junit.Assert.assertNull;
2323

24+
import java.io.File;
2425
import java.io.IOException;
2526
import java.net.URL;
2627

2728
import org.eclipse.core.runtime.Adapters;
2829
import org.eclipse.core.runtime.IPath;
30+
import org.eclipse.jface.internal.InternalPolicy;
2931
import org.eclipse.jface.resource.ImageDescriptor;
3032
import org.eclipse.swt.graphics.Image;
3133
import org.eclipse.swt.graphics.ImageData;
@@ -122,20 +124,52 @@ public void testImageFileNameProviderGetxName() {
122124

123125
@Test
124126
public void testImageFileNameProviderGetxName_forFileURL() throws IOException {
125-
URL imageFileURL = tempFolder.newFile("image.png").toURI().toURL();
126-
tempFolder.newFile("image@2x.png");
127+
testImageFileNameProviderGetxName_forFileURL(true);
128+
}
129+
130+
@Test
131+
public void testImageFileNameProviderGetxName_forFileURL_noOSGi() throws IOException {
132+
testImageFileNameProviderGetxName_forFileURL(false);
133+
}
134+
135+
private void testImageFileNameProviderGetxName_forFileURL(boolean osgiAvailable) throws IOException {
136+
boolean oldOsgiAvailable = InternalPolicy.OSGI_AVAILABLE;
137+
InternalPolicy.OSGI_AVAILABLE = osgiAvailable;
138+
try {
139+
URL imageFileURL = tempFolder.newFile("image.png").toURI().toURL();
140+
tempFolder.newFile("image@2x.png");
141+
ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageFileURL);
142+
143+
ImageFileNameProvider fileNameProvider = Adapters.adapt(descriptor, ImageFileNameProvider.class);
144+
assertNotNull("URLImageDescriptor does not adapt to ImageFileNameProvider", fileNameProvider);
145+
String imagePath100 = fileNameProvider.getImagePath(100);
146+
assertNotNull("URLImageDescriptor ImageFileNameProvider does not return the 100% path", imagePath100);
147+
assertEquals(IPath.fromOSString(imagePath100).lastSegment(), "image.png");
148+
String imagePath200 = fileNameProvider.getImagePath(200);
149+
assertNotNull("URLImageDescriptor ImageFileNameProvider does not return the @2x path", imagePath200);
150+
assertEquals(IPath.fromOSString(imagePath200).lastSegment(), "image@2x.png");
151+
String imagePath150 = fileNameProvider.getImagePath(150);
152+
assertNull("URLImageDescriptor's ImageFileNameProvider does return a @1.5x path", imagePath150);
153+
} finally {
154+
InternalPolicy.OSGI_AVAILABLE = oldOsgiAvailable;
155+
}
156+
}
157+
158+
@Test
159+
public void testImageFileNameProviderGetxName_forFileURL_WhiteSpace() throws IOException {
160+
File imageFolder = tempFolder.newFolder("folder with spaces");
161+
File imageFile = new File(imageFolder, "image with spaces.png");
162+
imageFile.createNewFile();
163+
164+
// This is an invalid URL because the whitespace characters are not properly encoded
165+
URL imageFileURL = new URL("file", null, imageFile.getPath());
127166
ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageFileURL);
128167

129168
ImageFileNameProvider fileNameProvider = Adapters.adapt(descriptor, ImageFileNameProvider.class);
130169
assertNotNull("URLImageDescriptor does not adapt to ImageFileNameProvider", fileNameProvider);
170+
131171
String imagePath100 = fileNameProvider.getImagePath(100);
132172
assertNotNull("URLImageDescriptor ImageFileNameProvider does not return the 100% path", imagePath100);
133-
assertEquals(IPath.fromOSString(imagePath100).lastSegment(), "image.png");
134-
String imagePath200 = fileNameProvider.getImagePath(200);
135-
assertNotNull("URLImageDescriptor ImageFileNameProvider does not return the @2x path", imagePath200);
136-
assertEquals(IPath.fromOSString(imagePath200).lastSegment(), "image@2x.png");
137-
String imagePath150 = fileNameProvider.getImagePath(150);
138-
assertNull("URLImageDescriptor's ImageFileNameProvider does return a @1.5x path", imagePath150);
139173
}
140174

141175
@Test

0 commit comments

Comments
 (0)