track JUnitService in activator
setup felix obr as build repo
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@906452 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/sigil/gogo/junit/sigil.properties b/sigil/gogo/junit/sigil.properties
index b305d9e..b569438 100644
--- a/sigil/gogo/junit/sigil.properties
+++ b/sigil/gogo/junit/sigil.properties
@@ -16,5 +16,6 @@
org.apache.tools.ant;version=1.7.0, \
org.osgi.framework;version=1.5.0, \
org.osgi.service.command;version=0.2.0, \
+ org.osgi.util.tracker;version=1.3.2, \
# end
diff --git a/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java b/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java
index fe3a78d..16a473d 100644
--- a/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java
+++ b/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/Activator.java
@@ -19,21 +19,48 @@
package org.apache.felix.sigil.gogo.junit;
import java.util.Hashtable;
+import java.util.Map;
+import org.apache.felix.sigil.junit.server.JUnitService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.command.CommandProcessor;
+import org.osgi.util.tracker.ServiceTracker;
public class Activator implements BundleActivator
{
- public void start( BundleContext ctx ) throws Exception
+ public void start( final BundleContext ctx ) throws Exception
{
- Hashtable props = new Hashtable();
+ final Hashtable props = new Hashtable();
props.put(CommandProcessor.COMMAND_SCOPE, "sigil");
- props.put(CommandProcessor.COMMAND_FUNCTION, new String[] { "junit" });
- ctx.registerService( SigilJunit.class.getName(), new SigilJunit(), props );
+ props.put(CommandProcessor.COMMAND_FUNCTION, new String[] { "junit" });
+
+ ServiceTracker tracker = new ServiceTracker(ctx, JUnitService.class.getName(), null) {
+ private Map<ServiceReference, ServiceRegistration> regs;
+
+ @Override
+ public Object addingService( ServiceReference reference )
+ {
+ JUnitService svc = ( JUnitService ) super.addingService( reference );
+ ServiceRegistration reg = ctx.registerService( SigilJunit.class.getName(), new SigilJunit(svc), props );
+ regs.put(reference, reg);
+ return svc;
+ }
+
+ @Override
+ public void removedService( ServiceReference reference, Object service )
+ {
+ ServiceRegistration reg = regs.remove( reference );
+ reg.unregister();
+ super.removedService( reference, service );
+ }
+
+ };
+ tracker.open();
}
public void stop( BundleContext ctx ) throws Exception
diff --git a/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java b/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java
index a659499..829a4d0 100644
--- a/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java
+++ b/sigil/gogo/junit/src/org/apache/felix/sigil/gogo/junit/SigilJunit.java
@@ -46,9 +46,13 @@
OPTIONS.addOption("q", "quiet", false, "Run tests quietly, i.e. don't print steps to console" );
}
- private JUnitService service;
+ private final JUnitService service;
+
+ public SigilJunit(JUnitService service) {
+ this.service = service;
+ }
- public void junit(String[] args) throws IOException, ParseException {
+ public boolean junit(String[] args) throws IOException, ParseException {
Parser p = new GnuParser();
CommandLine cmd = p.parse(OPTIONS, args);
String[] cargs = cmd.getArgs();
@@ -57,6 +61,7 @@
System.out.println( "\t" + t );
System.out.flush();
}
+ return true;
}
else {
boolean quiet = cmd.hasOption( 'q' );
@@ -68,11 +73,11 @@
System.out.println( "Writing results to " + dir.getAbsolutePath() );
System.out.flush();
}
- runTests( cargs, quiet, dir );
+ return runTests( cargs, quiet, dir );
}
}
- private void runTests(String[] args, boolean quiet, File dir) throws IOException {
+ private boolean runTests(String[] args, boolean quiet, File dir) throws IOException {
int count = 0;
int failures = 0;
int errors = 0;
@@ -123,6 +128,8 @@
System.out.println( "Ran " + count + " tests. " + failures + " failures " + errors + " errors." );
System.out.flush();
+
+ return failures + errors == 0;
}
private TestSuite[] findTests(String t) {