Skip to content

Commit dd902cc

Browse files
Dani-HubHannesWell
authored andcommitted
PDE should not warn if resource URI of unknown scheme cannot be found
Fixes #2031 Signed-off-by: Daniel Krügler <[email protected]>
1 parent 1d67ed6 commit dd902cc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/ExtensionsErrorReporter.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
* Martin Karpisek <[email protected]> - Bug 526283
14+
* Daniel Kruegler - #2031 - PDE should not warn if resource URI of unknown scheme cannot be found
1415
*******************************************************************************/
1516
package org.eclipse.pde.internal.core.builders;
1617

1718
import java.io.File;
19+
import java.net.URI;
20+
import java.net.URISyntaxException;
1821
import java.util.ArrayList;
1922
import java.util.HashSet;
2023
import java.util.Iterator;
24+
import java.util.List;
2125
import java.util.Map;
2226
import java.util.StringTokenizer;
2327
import java.util.regex.Pattern;
@@ -75,6 +79,8 @@
7579

7680
public class ExtensionsErrorReporter extends ManifestErrorReporter {
7781

82+
private static final List<String> KNOWN_URI_SCHEMES = List.of("platform", "file", "jar"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
83+
7884
/**
7985
* PDE model object for the project. May be <code>null</code> if there is no backing model.
8086
*/
@@ -597,6 +603,42 @@ private boolean resourceExists(String location) {
597603
}
598604
}
599605

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+
}
600642
return false;
601643
}
602644

0 commit comments

Comments
 (0)