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%2FOsgiJavaReferenceValidatorFactory.java;h=2f3c869b478aa631bb652b07341ab66a8abd5dbe;hp=03524e8831bd5e5bfe42aadcc763a107ed5ea548;hb=5704e9deb877257b2c0c542e185fda124cf3ce37;hpb=c26409b1caf2f1e560d37c5befd11b442399c3fe diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java index 03524e883..2f3c869b4 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/OsgiJavaReferenceValidatorFactory.java @@ -2,15 +2,21 @@ package org.simantics.scl.osgi.internal; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; import org.osgi.framework.wiring.BundleWiring; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator; import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory; import org.simantics.scl.compiler.internal.codegen.types.RuntimeJavaReferenceValidator; import org.simantics.scl.compiler.types.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +@SuppressWarnings("restriction") public class OsgiJavaReferenceValidatorFactory implements JavaReferenceValidatorFactory { + private static final Logger LOGGER = LoggerFactory.getLogger(OsgiJavaReferenceValidatorFactory.class); + private final Bundle bundle; public OsgiJavaReferenceValidatorFactory(Bundle bundle) { @@ -18,16 +24,27 @@ public class OsgiJavaReferenceValidatorFactory implements JavaReferenceValidator } private static ClassLoader getClassLoader(Bundle bundle) { - 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) { + LOGGER.info("Starting bundle {} with state {}", bundle.getSymbolicName(), BundleUtils.resolveBundleState(bundle)); + try { + bundle.start(); + } catch (BundleException e) { + throw new InternalCompilerError("Couldn't activate bundle " + bundle.getSymbolicName() + ". Bundle state is " + BundleUtils.resolveBundleState(bundle)); + } + wiring = bundle.adapt(BundleWiring.class); + } + if (wiring != null) return wiring.getClassLoader(); - throw new InternalCompilerError("Cannot get the class loader for bundle " + bundle.getSymbolicName() + "."); + else + throw new InternalCompilerError("Cannot get the class loader for bundle " + bundle.getSymbolicName() + ". Bundle state is " + BundleUtils.resolveBundleState(bundle)); } } + @SuppressWarnings("unchecked") private static JavaReferenceValidator getJavaReferenceValidator(Bundle bundle) { if(bundle == null) return null; @@ -46,7 +63,7 @@ public class OsgiJavaReferenceValidatorFactory implements JavaReferenceValidator @Override public JavaReferenceValidator getJavaReferenceValidator(String bundleName) { - System.out.println("getJavaReferenceValidator(" + bundleName + ")"); + LOGGER.info("getJavaReferenceValidator(" + bundleName + ")"); return getJavaReferenceValidator(getBundle(bundle.getBundleContext(), bundleName)); }