|
11 | 11 | * Contributors: |
12 | 12 | * IBM Corporation - initial API and implementation |
13 | 13 | * Martin Karpisek <[email protected]> - Bug 526283 |
| 14 | + * Daniel Kruegler - #2031 - PDE should not warn if resource URI of unknown scheme cannot be found |
14 | 15 | *******************************************************************************/ |
15 | 16 | package org.eclipse.pde.internal.core.builders; |
16 | 17 |
|
17 | 18 | import java.io.File; |
| 19 | +import java.net.URI; |
| 20 | +import java.net.URISyntaxException; |
18 | 21 | import java.util.ArrayList; |
19 | 22 | import java.util.HashSet; |
20 | 23 | import java.util.Iterator; |
| 24 | +import java.util.List; |
21 | 25 | import java.util.Map; |
22 | 26 | import java.util.StringTokenizer; |
23 | 27 | import java.util.regex.Pattern; |
|
75 | 79 |
|
76 | 80 | public class ExtensionsErrorReporter extends ManifestErrorReporter { |
77 | 81 |
|
| 82 | + private static final List<String> KNOWN_URI_SCHEMES = List.of("platform", "file", "jar"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 83 | + |
78 | 84 | /** |
79 | 85 | * PDE model object for the project. May be <code>null</code> if there is no backing model. |
80 | 86 | */ |
@@ -597,6 +603,42 @@ private boolean resourceExists(String location) { |
597 | 603 | } |
598 | 604 | } |
599 | 605 |
|
| 606 | + if (bundleJar == null && isValidUriOfUnknownProtocol(location)) { |
| 607 | + return true; |
| 608 | + } |
| 609 | + |
| 610 | + return false; |
| 611 | + } |
| 612 | + |
| 613 | + private static boolean isValidUriOfUnknownProtocol(String location) { |
| 614 | + try { |
| 615 | + final var uri = new URI(location); |
| 616 | + if (uri.isAbsolute()) { |
| 617 | + final var scheme = uri.getScheme(); |
| 618 | + boolean isKnownProtocol = false; |
| 619 | + // Exclude those URI forms where we have already special |
| 620 | + // handling for or where we are sure that they are known URLs: |
| 621 | + for (String knownScheme : KNOWN_URI_SCHEMES) { |
| 622 | + if (knownScheme.equalsIgnoreCase(scheme)) { |
| 623 | + isKnownProtocol = true; |
| 624 | + break; |
| 625 | + } |
| 626 | + } |
| 627 | + |
| 628 | + if (!isKnownProtocol) { |
| 629 | + // Exclude syntactically valid file paths that are also |
| 630 | + // syntactically valid URIs, such as "C:/path" where |
| 631 | + // "C" would be interpreted as unknown URI scheme: |
| 632 | + try { |
| 633 | + java.nio.file.Path.of(location); |
| 634 | + } catch (java.nio.file.InvalidPathException e) { |
| 635 | + return true; |
| 636 | + } |
| 637 | + } |
| 638 | + } |
| 639 | + } catch (URISyntaxException e) { |
| 640 | + // URI is invalid |
| 641 | + } |
600 | 642 | return false; |
601 | 643 | } |
602 | 644 |
|
|
0 commit comments