import java.util.ArrayList;
-import org.eclipse.core.internal.runtime.PlatformActivator;
import org.simantics.scl.compiler.errors.DoesNotExist;
import org.simantics.scl.compiler.errors.Failable;
import org.simantics.scl.compiler.module.Module;
import java.util.Arrays;
import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class BundleDocumentationSource {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(BundleDocumentationSource.class);
+
public static final Charset UTF8 = Charset.forName("UTF-8");
public final String documentationName;
stream.close();
}
} catch(IOException e) {
- e.printStackTrace();
+ LOGGER.error("Could not get text for {} at {}", documentationName, url);
return null;
}
}
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;
}
return digest.digest();
} catch (NoSuchAlgorithmException e) {
- LOGGER.error("No SHA1 algorithm available", e);
+ LOGGER.error("No SHA1 algorithm found", e);
return new byte[0];
} finally {
stream.close();
}
} catch(IOException e) {
- LOGGER.error("Could not compute digest for {}", this);
+ LOGGER.error("Could not compute digest for {}", getModuleName(), e);
return new byte[0];
}
}
}
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();
+ }
}
}
return;
Files.write(path, newSourceText.getBytes(Charset.forName("UTF-8")));
} catch(IOException e) {
- LOGGER.error("Could not update {} with {}", this, newSourceText, e);
+ LOGGER.error("Could not update module {} in url {} with text {}", getModuleName(), url, newSourceText);
}
checkUpdates();
}
}
}
+ public static String resolveBundleState(Bundle bundle) {
+ switch (bundle.getState()) {
+ case Bundle.UNINSTALLED: return "UNINSTALLED";
+ case Bundle.INSTALLED: return "INSTALLED";
+ case Bundle.RESOLVED: return "RESOLVED";
+ case Bundle.STARTING: return "STARTING";
+ case Bundle.STOPPING: return "STOPPING";
+ case Bundle.ACTIVE: return "ACTIVE";
+ default: return "UNKNOWN";
+ }
+ }
+
}
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) {
}
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<Object, Object, Object, Object> getJavaReferenceValidator(Bundle bundle) {
if(bundle == null)
return null;
@Override
public JavaReferenceValidator<Object, Object, Object, Object> getJavaReferenceValidator(String bundleName) {
- System.out.println("getJavaReferenceValidator(" + bundleName + ")");
+ LOGGER.info("getJavaReferenceValidator(" + bundleName + ")");
return getJavaReferenceValidator(getBundle(bundle.getBundleContext(), bundleName));
}