From a816ffee0adbb73075f6a682458d28ae894d1177 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:22:34 +0200 Subject: [PATCH] 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... --- de.prob.core/src/de/prob/cli/CliStarter.java | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/de.prob.core/src/de/prob/cli/CliStarter.java b/de.prob.core/src/de/prob/cli/CliStarter.java index fe265146..972c94fd 100644 --- a/de.prob.core/src/de/prob/cli/CliStarter.java +++ b/de.prob.core/src/de/prob/cli/CliStarter.java @@ -202,27 +202,29 @@ public final class CliStarter { private File getCliPath() throws CliException { final Bundle bundle = Activator.getDefault().getBundle(); - final String fileURL = "prob"; - final URL entry = bundle.getEntry(fileURL); + final URL entry = bundle.getEntry("prob"); if (entry == null) { throw new CliException( "Unable to find directory with prob executables."); } + URL fileUrl; try { - URL resolvedUrl = FileLocator.find(bundle, new Path(fileURL), null); - - // We need to use the 3-arg constructor of URI in order to properly - // escape file system chars. - URI resolvedUri = new URI("file", FileLocator - .toFileURL(resolvedUrl).getPath(), null); + fileUrl = FileLocator.toFileURL(entry); + } catch (IOException e) { + throw new CliException("Input/output error when trying to find '" + entry + "'", e, false); + } - 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) { 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); } } -- GitLab