X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.osgi%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fosgi%2Finternal%2FBundleModuleSource.java;h=23edcccc2c1a0d1df294b7b92d6dfed978c181b4;hb=7b50064579d979d2f3e8901bad32b219c5e1441d;hp=92385a1ed3f9be600ffb0ea33d0ff5e10cda913b;hpb=e030dd5359ab50cf88fc891af61b6cf43c01f86f;p=simantics%2Fplatform.git 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 92385a1ed..23edcccc2 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 @@ -13,17 +13,22 @@ import java.util.Arrays; import org.eclipse.core.runtime.FileLocator; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; import org.osgi.framework.wiring.BundleWiring; import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.repository.UpdateListener; import org.simantics.scl.compiler.source.EncodedTextualModuleSource; import org.simantics.scl.compiler.types.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import gnu.trove.set.hash.THashSet; public class BundleModuleSource extends EncodedTextualModuleSource implements UpdateListener.Observable { + private static final Logger LOGGER = LoggerFactory.getLogger(BundleModuleSource.class); + public static final ImportDeclaration[] DEFAULT_IMPORTS = new ImportDeclaration[] { new ImportDeclaration("Builtin", ""), new ImportDeclaration("StandardLibrary", "") @@ -54,7 +59,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 @@ -75,13 +80,13 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up } return digest.digest(); } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); + LOGGER.error("No SHA1 algorithm found", e); return new byte[0]; } finally { stream.close(); } } catch(IOException e) { - e.printStackTrace(); + LOGGER.error("Could not compute digest for {}", getModuleName(), e); return new byte[0]; } } @@ -99,17 +104,27 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up } return url.openStream(); } - + @Override public ClassLoader getClassLoader() { - if(bundle.getSymbolicName().equals("org.simantics.scl.runtime")) + if (bundle.getSymbolicName().equals("org.simantics.scl.runtime")) return Type.class.getClassLoader(); else { BundleWiring wiring = bundle.adapt(BundleWiring.class); - if(wiring != null) + if (wiring == null && bundle.getState() == Bundle.INSTALLED) { + try { + bundle.start(); + } catch (BundleException e) { + LOGGER.error("Could not start bundle {}", bundle.getSymbolicName(), e); + } + wiring = bundle.adapt(BundleWiring.class); + } + if (wiring != null) { return wiring.getClassLoader(); - else + } else { + LOGGER.error("Couldn't find class loader for bundle {} with state {}", bundle.getSymbolicName(), BundleUtils.resolveBundleState(bundle)); return getClass().getClassLoader(); + } } } @@ -146,7 +161,10 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up @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; } @@ -156,9 +174,11 @@ 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(); + LOGGER.error("Could not update module {} in url {} with text {}", getModuleName(), url, newSourceText); } checkUpdates(); }