1 package org.simantics.scl.osgi.internal;
3 import java.util.Hashtable;
4 import java.util.concurrent.ForkJoinPool;
6 import org.osgi.framework.BundleActivator;
7 import org.osgi.framework.BundleContext;
8 import org.simantics.scl.compiler.errors.Failable;
9 import org.simantics.scl.compiler.module.Module;
10 import org.simantics.scl.compiler.module.repository.ModuleRepository;
11 import org.simantics.scl.compiler.module.repository.UpdateListener;
12 import org.simantics.scl.compiler.source.repository.ModuleSourceRepository;
13 import org.simantics.scl.compiler.source.repository.ProceduralModuleSourceRepository;
14 import org.simantics.scl.compiler.source.repository.SourceRepositories;
15 import org.simantics.scl.osgi.SCLOsgi;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class Activator implements BundleActivator {
21 private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
23 public static final String PLUGIN_ID = "org.simantics.scl.osgi";
25 private static BundleContext context;
27 public static BundleContext getContext() {
31 @SuppressWarnings({ "rawtypes", "unchecked" })
32 public void start(BundleContext bundleContext) throws Exception {
33 Activator.context = bundleContext;
35 Hashtable properties = new Hashtable();
36 bundleContext.registerService(ModuleSourceRepository.class,
37 SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
39 bundleContext.registerService(ModuleSourceRepository.class,
40 new ProceduralModuleSourceRepository() {
42 protected ModuleRepository getModuleRepository(UpdateListener listener) {
43 return SCLOsgi.MODULE_REPOSITORY;
47 // Let's try to compile StandardLibrary asynchronously to speed up
48 // the compilation when we actually need it the first time
49 LOGGER.info("Warming up SCL-compiler with StandardLibrary");
50 ForkJoinPool.commonPool().submit(() -> {
51 Failable<Module> module = SCLOsgi.MODULE_REPOSITORY.getModule("StandardLibrary");
52 LOGGER.info("StandardLibrary compiled {}", module);
56 public void stop(BundleContext bundleContext) throws Exception {
57 Activator.context = null;