X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.osgi%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fosgi%2Finternal%2FBundleModuleSource.java;h=fc9799de706d6625e401d47dd3320aa7a900cc91;hp=3213cf9b5419e7d501fdba77afd93218babc0c9e;hb=c52bf8a84f74dd22f49ca1c6e5443720c2d0ac3a;hpb=c26409b1caf2f1e560d37c5befd11b442399c3fe diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java index 3213cf9b5..fc9799de7 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleModuleSource.java @@ -1,13 +1,12 @@ package org.simantics.scl.osgi.internal; +import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; @@ -55,7 +54,7 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up } @Override - protected ImportDeclaration[] getBuiltinImports(UpdateListener listener) { + public ImportDeclaration[] getBuiltinImports(UpdateListener listener) { if(bundle.getSymbolicName().equals("org.simantics.scl.runtime")) return DEFAULT_IMPORTS_FOR_STANDARD_LIBRARY; else @@ -126,19 +125,31 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up } } } - - private Path getPath() throws IOException { - try { - return Paths.get(FileLocator.toFileURL(url).toURI()); - } catch (URISyntaxException e) { - throw new IOException(e); + + /* + * This code is a copy from org.simantics.utils.ui.BundleUtils + */ + public static File resolveWritableBundleFile(URL url) throws IOException { + // This returns file, jar, http etc. - essentially resolves the bundle protocol + URL resolved = FileLocator.resolve(url); + if (resolved.getProtocol().equals("file")) { + return new File(resolved.getPath()); } + return null; } - + + private Path getPath() throws IOException { + File file = resolveWritableBundleFile(url); + return file != null ? file.toPath() : null; + } + @Override public boolean isUpdateable() { try { - return Files.exists(getPath()); + Path path = getPath(); + if(path == null) + return false; + return Files.exists(path); } catch (IOException e) { return false; } @@ -148,6 +159,8 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up public void update(String newSourceText) { try { Path path = getPath(); + if(path == null) + return; Files.write(path, newSourceText.getBytes(Charset.forName("UTF-8"))); } catch(IOException e) { e.printStackTrace();