Skip to content

Commit 0e86478

Browse files
committed
Resolve resources URLs as file-URLs if running in an OSGi environment
Don't consider the 'PLUGIN_PATH' property anymore, which is set in I-build tests and whose handling doesn't work anymore. Fixes #2001
1 parent cd7cd6b commit 0e86478

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/SwtTestUtil.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.jupiter.api.Assertions.assertNotNull;
2323
import static org.junit.jupiter.api.Assertions.assertTrue;
2424

25+
import java.io.IOException;
2526
import java.io.PrintStream;
2627
import java.net.URI;
2728
import java.net.URISyntaxException;
@@ -31,6 +32,7 @@
3132
import java.util.concurrent.atomic.AtomicBoolean;
3233
import java.util.function.BooleanSupplier;
3334

35+
import org.eclipse.core.runtime.FileLocator;
3436
import org.eclipse.swt.SWT;
3537
import org.eclipse.swt.SWTError;
3638
import org.eclipse.swt.SWTException;
@@ -584,23 +586,18 @@ public static boolean hasPixelNotMatching(Image image, Color nonMatchingColor, R
584586

585587
public static String getPath(String fileName) {
586588
URI uri;
587-
String pluginPath = System.getProperty("PLUGIN_PATH");
588-
if (pluginPath == null) {
589-
URL url = SwtTestUtil.class.getResource(fileName);
590-
assertNotNull(url, "URL == null for file " + fileName);
591-
try {
592-
uri = url.toURI();
593-
} catch (URISyntaxException e) {
594-
throw new IllegalArgumentException(e);
589+
URL url = SwtTestUtil.class.getResource(fileName);
590+
assertNotNull(url, "URL == null for file " + fileName);
591+
try {
592+
if (!"file".equals(url.getProtocol())) {
593+
url = FileLocator.toFileURL(url); // probably running in an OSGi runtime and this should work
595594
}
596-
} else {
597-
uri = URI.create(pluginPath + "/data/" + fileName);
595+
uri = url.toURI();
596+
} catch (URISyntaxException | IOException e) {
597+
throw new IllegalArgumentException(e);
598598
}
599599
// Fallback when test is locally executed as plug-in test
600600
Path path = Path.of(uri);
601-
if (!Files.exists(path)) {
602-
path = Path.of("data/" + fileName).toAbsolutePath();
603-
}
604601
assertTrue(Files.exists(path), "file not found: " + uri);
605602
return path.toString();
606603
}

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,11 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLjava_lang_String()
319319

320320
@Test
321321
public void test_ConstructorLorg_eclipse_swt_graphics_Device_ImageFileNameProvider() {
322-
Exception e;
322+
Exception e;
323323

324324
// Null provider
325325
ImageFileNameProvider provider1 = null;
326-
e = assertThrows(IllegalArgumentException.class, ()->new Image(display, provider1));
326+
e = assertThrows(IllegalArgumentException.class, ()->new Image(display, provider1));
327327
assertSWTProblem("Incorrect exception thrown for provider == null", SWT.ERROR_NULL_ARGUMENT, e);
328328

329329
// Invalid provider

tests/org.eclipse.swt.tests/META-INF/MANIFEST.MF

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Require-Bundle: org.junit;bundle-version="4.13.2",
1515
junit-platform-suite-commons;bundle-version="1.12.0",
1616
junit-platform-suite-engine;bundle-version="1.12.0",
1717
org.eclipse.swt;bundle-version="3.120.0",
18+
org.eclipse.equinox.common,
1819
org.eclipse.test;bundle-version="3.6.200",
1920
org.eclipse.test.performance;bundle-version="3.13.0"
2021
Eclipse-BundleShape: dir

0 commit comments

Comments
 (0)