diff --git a/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/AggregateState.java b/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/AggregateState.java
index dc58722..1279904 100644
--- a/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/AggregateState.java
+++ b/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/AggregateState.java
@@ -32,7 +32,7 @@
@SuppressWarnings({
"rawtypes", "unchecked"
})
-@Component(property = "condition=true", service = AggregateState.class)
+@Component(property = "condition=true", service = AggregateState.class, immediate = true)
@AggregateImplementation
public class AggregateState {
final static Class ARCHETYPE = Aggregate.class;
diff --git a/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/TrackedService.java b/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/TrackedService.java
index 184d94a..152863c 100644
--- a/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/TrackedService.java
+++ b/biz.aQute.aggregate.provider/src/main/java/biz/aQute/aggregate/provider/TrackedService.java
@@ -9,6 +9,8 @@
import java.util.stream.Collectors;
import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.util.tracker.ServiceTracker;
@@ -116,7 +118,9 @@ private void register() {
logger.debug("registering %s", actualType);
try {
ActualTypeFactory instance = new ActualTypeFactory(this, state, serviceType);
- ServiceRegistration reg = state.context.registerService(actualType.getName(), instance, null);
+ BundleContext context = FrameworkUtil.getBundle(actualType)
+ .getBundleContext();
+ ServiceRegistration reg = context.registerService(actualType.getName(), instance, null);
synchronized (state) {
instance.reg = reg;
if (!state.closed) {
diff --git a/biz.aQute.aggregate.test/.classpath b/biz.aQute.aggregate.test/.classpath
new file mode 100644
index 0000000..77649b9
--- /dev/null
+++ b/biz.aQute.aggregate.test/.classpath
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/biz.aQute.aggregate.test/.project b/biz.aQute.aggregate.test/.project
new file mode 100644
index 0000000..26a7058
--- /dev/null
+++ b/biz.aQute.aggregate.test/.project
@@ -0,0 +1,23 @@
+
+
+ biz.aQute.aggregate.test
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ bndtools.core.bndbuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ bndtools.core.bndnature
+
+
diff --git a/biz.aQute.aggregate.test/.settings/org.eclipse.core.resources.prefs b/biz.aQute.aggregate.test/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..3ebc5a5
--- /dev/null
+++ b/biz.aQute.aggregate.test/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+encoding/.classpath=UTF-8
+encoding//src/test/java/biz/aQute/aggregate/test/AggregateTest.java=UTF-8
+encoding/=UTF-8
+encoding/bnd.bnd=UTF-8
diff --git a/biz.aQute.aggregate.test/.settings/org.eclipse.jdt.core.prefs b/biz.aQute.aggregate.test/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..af07d5f
--- /dev/null
+++ b/biz.aQute.aggregate.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.release=enabled
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/biz.aQute.aggregate.test/b1.bnd b/biz.aQute.aggregate.test/b1.bnd
new file mode 100644
index 0000000..bed0b09
--- /dev/null
+++ b/biz.aQute.aggregate.test/b1.bnd
@@ -0,0 +1 @@
+-includepackage: biz.aQute.aggregate.test.b1
diff --git a/biz.aQute.aggregate.test/b2.bnd b/biz.aQute.aggregate.test/b2.bnd
new file mode 100644
index 0000000..9934834
--- /dev/null
+++ b/biz.aQute.aggregate.test/b2.bnd
@@ -0,0 +1 @@
+-includepackage: biz.aQute.aggregate.test.b2
diff --git a/biz.aQute.aggregate.test/b3.bnd b/biz.aQute.aggregate.test/b3.bnd
new file mode 100644
index 0000000..67fc17b
--- /dev/null
+++ b/biz.aQute.aggregate.test/b3.bnd
@@ -0,0 +1 @@
+-includepackage: biz.aQute.aggregate.test.b3
diff --git a/biz.aQute.aggregate.test/bnd.bnd b/biz.aQute.aggregate.test/bnd.bnd
new file mode 100644
index 0000000..e431e3b
--- /dev/null
+++ b/biz.aQute.aggregate.test/bnd.bnd
@@ -0,0 +1,24 @@
+#
+# biz.aQute.aggregate.test PROVIDER BUNDLE
+#
+
+-buildpath: \
+ osgi.annotation,\
+ org.osgi.service.component.annotations,\
+ org.osgi.framework,\
+ org.osgi.resource,\
+ slf4j.api,\
+ biz.aQute.api.aggregate,\
+ biz.aQute.osgi.diverse.util;version=snapshot
+
+-testpath: \
+ biz.aQute.wrapper.junit,\
+ biz.aQute.wrapper.hamcrest,\
+ org.assertj.core,\
+ biz.aQute.launchpad,\
+ org.osgi.util.tracker,\
+ org.osgi.dto,\
+ org.awaitility,\
+ slf4j.simple
+
+-sub: *.bnd
\ No newline at end of file
diff --git a/biz.aQute.aggregate.test/main.bnd b/biz.aQute.aggregate.test/main.bnd
new file mode 100644
index 0000000..f113958
--- /dev/null
+++ b/biz.aQute.aggregate.test/main.bnd
@@ -0,0 +1 @@
+-includepackage: biz.aQute.aggregate.test
diff --git a/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/Foo.java b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/Foo.java
new file mode 100644
index 0000000..8362582
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/Foo.java
@@ -0,0 +1,5 @@
+package biz.aQute.aggregate.test;
+
+public interface Foo {
+
+}
diff --git a/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/Server.java b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/Server.java
new file mode 100644
index 0000000..31dfdd0
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/Server.java
@@ -0,0 +1,33 @@
+package biz.aQute.aggregate.test;
+
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import biz.aQute.aggregate.api.Aggregate;
+import biz.aQute.osgi.service.util.ObjectClass;
+
+@Component
+public class Server {
+ Logger logger = LoggerFactory.getLogger(Server.class);
+
+ @Activate
+ public Server() {
+ logger.info("activated {}", guard.getServices());
+ }
+
+ @Deactivate
+ public void deactivate() {
+ logger.info("deactivated {}", guard.getServices());
+ }
+
+ @ObjectClass
+ interface AgFoo extends Aggregate {
+ }
+
+ @Reference
+ AgFoo guard;
+}
diff --git a/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b1/B1.java b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b1/B1.java
new file mode 100644
index 0000000..bedb58f
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b1/B1.java
@@ -0,0 +1,10 @@
+package biz.aQute.aggregate.test.b1;
+
+import org.osgi.service.component.annotations.Component;
+
+import biz.aQute.aggregate.test.Foo;
+
+@Component(immediate=true)
+public class B1 implements Foo {
+
+}
diff --git a/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b2/B3.java b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b2/B3.java
new file mode 100644
index 0000000..53333e8
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b2/B3.java
@@ -0,0 +1,10 @@
+package biz.aQute.aggregate.test.b2;
+
+import org.osgi.service.component.annotations.Component;
+
+import biz.aQute.aggregate.test.Foo;
+
+@Component(immediate=true)
+public class B3 implements Foo {
+
+}
diff --git a/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b3/B2.java b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b3/B2.java
new file mode 100644
index 0000000..dc31be5
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/b3/B2.java
@@ -0,0 +1,10 @@
+package biz.aQute.aggregate.test.b3;
+
+import org.osgi.service.component.annotations.Component;
+
+import biz.aQute.aggregate.test.Foo;
+
+@Component(immediate=true)
+public class B2 implements Foo {
+
+}
diff --git a/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/package-info.java b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/package-info.java
new file mode 100644
index 0000000..e1ae206
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/main/java/biz/aQute/aggregate/test/package-info.java
@@ -0,0 +1,9 @@
+@org.osgi.annotation.bundle.Export
+@Version("1.0.0")
+package biz.aQute.aggregate.test;
+
+import org.osgi.annotation.versioning.Version;
+
+/**
+ * An API to do thread based stuff
+ */
diff --git a/biz.aQute.aggregate.test/src/test/java/biz/aQute/aggregate/test/AggregateTest.java b/biz.aQute.aggregate.test/src/test/java/biz/aQute/aggregate/test/AggregateTest.java
new file mode 100644
index 0000000..8aced57
--- /dev/null
+++ b/biz.aQute.aggregate.test/src/test/java/biz/aQute/aggregate/test/AggregateTest.java
@@ -0,0 +1,34 @@
+package biz.aQute.aggregate.test;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+
+import aQute.launchpad.Launchpad;
+import aQute.launchpad.LaunchpadBuilder;
+import biz.aQute.aggregate.api.Aggregate;
+
+public class AggregateTest {
+ static {
+ System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "debug");
+ }
+
+ static LaunchpadBuilder builder = new LaunchpadBuilder().nostart()
+ .bndrun("test.bndrun")
+ .set(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "2");
+
+ interface T1Agg extends Aggregate {}
+
+
+@Ignore
+ @Test
+ public void simple() throws Exception {
+ try (Launchpad lp = builder.create()) {
+ lp.start();
+
+ System.out.println();
+ }
+
+ }
+
+}
diff --git a/biz.aQute.aggregate.test/test.bndrun b/biz.aQute.aggregate.test/test.bndrun
new file mode 100644
index 0000000..e0f72fc
--- /dev/null
+++ b/biz.aQute.aggregate.test/test.bndrun
@@ -0,0 +1,37 @@
+-runpath: slf4j.simple, slf4j.api
+-resolve: cache
+-runfw: org.apache.felix.framework;version='[6.0.2,6.0.2]'
+-runee: JavaSE-1.8
+-runrequires: \
+ osgi.identity;filter:='(osgi.identity=org.apache.felix.scr)',\
+ osgi.identity;filter:='(osgi.identity=org.apache.felix.webconsole.plugins.scriptconsole)',\
+ osgi.identity;filter:='(osgi.identity=org.apache.felix.log)',\
+ osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.provider)',\
+ osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.b1)',\
+ osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.b2)',\
+ osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.b3)',\
+ osgi.identity;filter:='(osgi.identity=biz.aQute.aggregate.test.main)',\
+ osgi.identity;filter:='(osgi.identity=biz.aQute.gogo.commands.provider)'
+-runbundles: \
+ org.apache.commons.fileupload;version='[1.3.2,1.3.3)',\
+ org.apache.commons.io;version='[2.5.0,2.5.1)',\
+ org.apache.felix.configadmin;version='[1.9.12,1.9.13)',\
+ org.apache.felix.gogo.command;version='[1.1.0,1.1.1)',\
+ org.apache.felix.http.servlet-api;version='[1.1.2,1.1.3)',\
+ org.apache.felix.log;version='[1.2.4,1.2.5)',\
+ org.apache.felix.scr;version='[2.1.30,2.1.31)',\
+ org.apache.felix.webconsole;version='[4.3.8,4.3.9)',\
+ org.apache.felix.webconsole.plugins.scriptconsole;version='[1.0.2,1.0.3)',\
+ org.json;version='[1.0.0,1.0.1)',\
+ org.osgi.service.http;version='[1.2.1,1.2.2)',\
+ org.osgi.util.function;version='[1.1.0,1.1.1)',\
+ org.osgi.util.promise;version='[1.1.1,1.1.2)',\
+ biz.aQute.aggregate.provider;version=snapshot,\
+ biz.aQute.aggregate.test.b1;version=snapshot,\
+ biz.aQute.aggregate.test.b2;version=snapshot,\
+ biz.aQute.aggregate.test.b3;version=snapshot,\
+ biz.aQute.aggregate.test.main;version=snapshot,\
+ biz.aQute.api.aggregate;version=snapshot,\
+ biz.aQute.osgi.diverse.util;version=snapshot,\
+ org.apache.felix.gogo.runtime;version='[1.1.2,1.1.3)',\
+ org.apache.felix.gogo.shell;version='[1.1.2,1.1.3)'
\ No newline at end of file
diff --git a/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/AddServiceCapability.java b/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/AddServiceCapability.java
new file mode 100644
index 0000000..89ea1ee
--- /dev/null
+++ b/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/AddServiceCapability.java
@@ -0,0 +1,21 @@
+package biz.aQute.osgi.service.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.osgi.annotation.bundle.Attribute;
+import org.osgi.annotation.bundle.Capability;
+
+/**
+ * Add a service capability to the bundle
+ *
+ */
+@Capability(namespace = "osgi.service", effective = "active")
+@Retention(RetentionPolicy.CLASS)
+@Target(ElementType.TYPE)
+public @interface AddServiceCapability {
+ @Attribute("objectClass")
+ Class>[] value();
+}
\ No newline at end of file
diff --git a/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/ObjectClass.java b/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/ObjectClass.java
new file mode 100644
index 0000000..05486da
--- /dev/null
+++ b/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/ObjectClass.java
@@ -0,0 +1,17 @@
+package biz.aQute.osgi.service.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.osgi.annotation.bundle.Capability;
+
+/**
+ * Add the marked type as a service capability
+ *
+ */
+@Capability(namespace = "osgi.service", effective = "active", attribute = "objectClass=${@class}")
+@Retention(RetentionPolicy.CLASS)
+@Target(ElementType.TYPE)
+public @interface ObjectClass {}
\ No newline at end of file
diff --git a/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/package-info.java b/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/package-info.java
new file mode 100644
index 0000000..cde0ec2
--- /dev/null
+++ b/biz.aQute.osgi.diverse.util/src/main/java/biz/aQute/osgi/service/util/package-info.java
@@ -0,0 +1,9 @@
+@org.osgi.annotation.bundle.Export
+@Version("1.0.0")
+package biz.aQute.osgi.service.util;
+
+import org.osgi.annotation.versioning.Version;
+
+/**
+ * An API to do thread based stuff
+ */