1 package org.simantics.scl.osgi.internal;
4 import java.util.ArrayList;
5 import java.util.Collection;
6 import java.util.Enumeration;
8 import org.osgi.framework.Bundle;
9 import org.osgi.framework.BundleContext;
10 import org.osgi.framework.BundleEvent;
11 import org.osgi.service.component.ComponentContext;
12 import org.osgi.service.component.annotations.Activate;
13 import org.osgi.service.component.annotations.Component;
14 import org.osgi.service.component.annotations.Deactivate;
15 import org.osgi.util.tracker.BundleTracker;
16 import org.simantics.scl.compiler.testing.TestRunnable;
17 import org.simantics.scl.compiler.testing.repository.TestRepository;
19 import gnu.trove.map.hash.THashMap;
22 public class BundleTestScriptRepository implements TestRepository {
25 THashMap<String, BundleTestScriptRunnable> testsRunnables = new THashMap<String, BundleTestScriptRunnable>();
26 THashMap<Bundle, ArrayList<String>> testsPerBundle = new THashMap<Bundle, ArrayList<String>>();
29 public void activate(ComponentContext context) {
30 tracker = new Tracker(context.getBundleContext());
35 public void deactivate() {
39 class Tracker extends BundleTracker<Bundle> {
40 public Tracker(BundleContext context) {
41 super(context, 0xffffffff, null);
45 synchronized public Bundle addingBundle(Bundle bundle, BundleEvent event) {
46 Enumeration<URL> urls = bundle.findEntries("sclTests", "*.sts", true);
48 ArrayList<String> modulesInThisBundle = new ArrayList<String>();
49 while(urls.hasMoreElements()) {
50 URL url = urls.nextElement();
51 String path = url.getPath();
52 String testName = path.substring(10, path.length()-4);
53 testsRunnables.put(testName, new BundleTestScriptRunnable(testName, url));
54 modulesInThisBundle.add(testName);
56 testsPerBundle.put(bundle, modulesInThisBundle);
62 synchronized public void removedBundle(Bundle bundle, BundleEvent event,
64 ArrayList<String> moduleList = testsPerBundle.get(bundle);
65 if(moduleList != null)
66 for(String moduleName : moduleList)
67 testsRunnables.remove(moduleName);
72 public void collectTests(Collection<TestRunnable> tests) {
73 tests.addAll(testsRunnables.values());