Skip to content
Snippets Groups Projects
Commit a816ffee authored by dgelessus's avatar dgelessus
Browse files

Simplify CliStarter.getCliPath logic slightly

It can't be made much simpler than this sadly, because of the OSGi and
Eclipse APIs and because of that URL escaping bug in Eclipse that hasn't
been addressed in 15 years...
parent eb4d9e9f
Branches
No related tags found
No related merge requests found
Pipeline #120497 passed
...@@ -202,27 +202,29 @@ public final class CliStarter { ...@@ -202,27 +202,29 @@ public final class CliStarter {
private File getCliPath() throws CliException { private File getCliPath() throws CliException {
final Bundle bundle = Activator.getDefault().getBundle(); final Bundle bundle = Activator.getDefault().getBundle();
final String fileURL = "prob"; final URL entry = bundle.getEntry("prob");
final URL entry = bundle.getEntry(fileURL);
if (entry == null) { if (entry == null) {
throw new CliException( throw new CliException(
"Unable to find directory with prob executables."); "Unable to find directory with prob executables.");
} }
URL fileUrl;
try { try {
URL resolvedUrl = FileLocator.find(bundle, new Path(fileURL), null); fileUrl = FileLocator.toFileURL(entry);
} catch (IOException e) {
// We need to use the 3-arg constructor of URI in order to properly throw new CliException("Input/output error when trying to find '" + entry + "'", e, false);
// escape file system chars. }
URI resolvedUri = new URI("file", FileLocator
.toFileURL(resolvedUrl).getPath(), null);
return new File(resolvedUri); try {
// Eclipse has a long-standing bug where Bundle.getEntry etc. don't correctly escape spaces, non-ASCII characters, etc. in file URLs.
// This makes it impossible to use the standard URL.toURI() method - it will throw an URISyntaxException for these unescaped characters.
// As a workaround, use Eclipse's URIUtil.toURI(URL), which escapes such unescaped characters.
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=145096
// https://probjira.atlassian.net/browse/PROBPLUGIN-87
return new File(URIUtil.toURI(fileUrl));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
throw new CliException("Unable to construct file '" + entry.getPath() + "'", e, false); throw new CliException("Unable to construct file '" + entry.getPath() + "'", e, false);
} catch (IOException e2) {
throw new CliException("Input/output error when trying t find '" + fileURL + "'", e2, false);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment