X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.osgi%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fosgi%2Finternal%2FBundleTestScriptRepository.java;h=689ffc3289a81d82321a4107b5797e6887441619;hb=5704e9deb877257b2c0c542e185fda124cf3ce37;hp=9bbebd30b1a65ca7932a5ec5d7db3a27fef31045;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleTestScriptRepository.java b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleTestScriptRepository.java index 9bbebd30b..689ffc328 100644 --- a/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleTestScriptRepository.java +++ b/bundles/org.simantics.scl.osgi/src/org/simantics/scl/osgi/internal/BundleTestScriptRepository.java @@ -1,76 +1,76 @@ -package org.simantics.scl.osgi.internal; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.util.tracker.BundleTracker; -import org.simantics.scl.compiler.testing.TestRunnable; -import org.simantics.scl.compiler.testing.repository.TestRepository; - -import gnu.trove.map.hash.THashMap; - -@Component -public class BundleTestScriptRepository implements TestRepository { - - Tracker tracker; - THashMap testsRunnables = new THashMap(); - THashMap> testsPerBundle = new THashMap>(); - - @Activate - public void activate(ComponentContext context) { - tracker = new Tracker(context.getBundleContext()); - tracker.open(); - } - - @Deactivate - public void deactivate() { - tracker.close(); - } - - class Tracker extends BundleTracker { - public Tracker(BundleContext context) { - super(context, 0xffffffff, null); - } - - @Override - synchronized public Bundle addingBundle(Bundle bundle, BundleEvent event) { - Enumeration urls = bundle.findEntries("sclTests", "*.sts", true); - if(urls != null) { - ArrayList modulesInThisBundle = new ArrayList(); - while(urls.hasMoreElements()) { - URL url = urls.nextElement(); - String path = url.getPath(); - String testName = path.substring(10, path.length()-4); - testsRunnables.put(testName, new BundleTestScriptRunnable(testName, url)); - modulesInThisBundle.add(testName); - } - testsPerBundle.put(bundle, modulesInThisBundle); - } - return bundle; - } - - @Override - synchronized public void removedBundle(Bundle bundle, BundleEvent event, - Bundle object) { - ArrayList moduleList = testsPerBundle.get(bundle); - if(moduleList != null) - for(String moduleName : moduleList) - testsRunnables.remove(moduleName); - } - }; - - @Override - public void collectTests(Collection tests) { - tests.addAll(testsRunnables.values()); - } - -} +package org.simantics.scl.osgi.internal; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Enumeration; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.util.tracker.BundleTracker; +import org.simantics.scl.compiler.testing.TestRunnable; +import org.simantics.scl.compiler.testing.repository.TestRepository; + +import gnu.trove.map.hash.THashMap; + +@Component +public class BundleTestScriptRepository implements TestRepository { + + Tracker tracker; + THashMap testsRunnables = new THashMap(); + THashMap> testsPerBundle = new THashMap>(); + + @Activate + public void activate(ComponentContext context) { + tracker = new Tracker(context.getBundleContext()); + tracker.open(); + } + + @Deactivate + public void deactivate() { + tracker.close(); + } + + class Tracker extends BundleTracker { + public Tracker(BundleContext context) { + super(context, 0xffffffff, null); + } + + @Override + synchronized public Bundle addingBundle(Bundle bundle, BundleEvent event) { + Enumeration urls = bundle.findEntries("sclTests", "*.sts", true); + if(urls != null) { + ArrayList modulesInThisBundle = new ArrayList(); + while(urls.hasMoreElements()) { + URL url = urls.nextElement(); + String path = url.getPath(); + String testName = path.substring(10, path.length()-4); + testsRunnables.put(testName, new BundleTestScriptRunnable(testName, url)); + modulesInThisBundle.add(testName); + } + testsPerBundle.put(bundle, modulesInThisBundle); + } + return bundle; + } + + @Override + synchronized public void removedBundle(Bundle bundle, BundleEvent event, + Bundle object) { + ArrayList moduleList = testsPerBundle.get(bundle); + if(moduleList != null) + for(String moduleName : moduleList) + testsRunnables.remove(moduleName); + } + }; + + @Override + public void collectTests(Collection tests) { + tests.addAll(testsRunnables.values()); + } + +}