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=a805e6026607c2f31e708651ba67fa982d5d5d90;hp=fc9799de706d6625e401d47dd3320aa7a900cc91;hb=5704e9deb877257b2c0c542e185fda124cf3ce37;hpb=c52bf8a84f74dd22f49ca1c6e5443720c2d0ac3a 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 fc9799de7..a805e6026 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,5 +1,6 @@ package org.simantics.scl.osgi.internal; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -13,17 +14,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", "") @@ -75,13 +81,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 +105,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(); + } } } @@ -151,10 +167,11 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up return false; return Files.exists(path); } catch (IOException e) { + LOGGER.debug("Could not check if {} is updateable", this, e); return false; } } - + @Override public void update(String newSourceText) { try { @@ -163,7 +180,7 @@ public class BundleModuleSource extends EncodedTextualModuleSource implements Up 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(); }