|
22 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
23 | 23 | import static org.junit.jupiter.api.Assertions.assertTrue; |
24 | 24 |
|
| 25 | +import java.io.IOException; |
25 | 26 | import java.io.PrintStream; |
26 | 27 | import java.net.URI; |
27 | 28 | import java.net.URISyntaxException; |
|
31 | 32 | import java.util.concurrent.atomic.AtomicBoolean; |
32 | 33 | import java.util.function.BooleanSupplier; |
33 | 34 |
|
| 35 | +import org.eclipse.core.runtime.FileLocator; |
34 | 36 | import org.eclipse.swt.SWT; |
35 | 37 | import org.eclipse.swt.SWTError; |
36 | 38 | import org.eclipse.swt.SWTException; |
@@ -584,23 +586,18 @@ public static boolean hasPixelNotMatching(Image image, Color nonMatchingColor, R |
584 | 586 |
|
585 | 587 | public static String getPath(String fileName) { |
586 | 588 | 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 |
595 | 594 | } |
596 | | - } else { |
597 | | - uri = URI.create(pluginPath + "/data/" + fileName); |
| 595 | + uri = url.toURI(); |
| 596 | + } catch (URISyntaxException | IOException e) { |
| 597 | + throw new IllegalArgumentException(e); |
598 | 598 | } |
599 | 599 | // Fallback when test is locally executed as plug-in test |
600 | 600 | Path path = Path.of(uri); |
601 | | - if (!Files.exists(path)) { |
602 | | - path = Path.of("data/" + fileName).toAbsolutePath(); |
603 | | - } |
604 | 601 | assertTrue(Files.exists(path), "file not found: " + uri); |
605 | 602 | return path.toString(); |
606 | 603 | } |
|
0 commit comments