Skip to content

Commit c31f1ba

Browse files
Grigoriy Piskunbbakerman
authored andcommitted
OSGi DS 1.2 compatibility (#96)
* Made DefaultTypeFunction compatible with OSGi DS 1.2 * Added bundle task to the build.gradle file and bundle.bnd file that allows to pack the library as OSGi bundle.
1 parent 32df1c8 commit c31f1ba

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import java.text.SimpleDateFormat
2+
import aQute.bnd.gradle.Bundle
23

34
buildscript {
45
repositories {
@@ -156,3 +157,8 @@ bintray {
156157
}
157158
}
158159
}
160+
161+
task bundle(type: Bundle) {
162+
from sourceSets.main.output
163+
bndfile = file('bundle.bnd')
164+
}

bundle.bnd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Export-Package: graphql.annotations.*;version="3.0.3"
2+
Bundle-SymbolicName: graphql.annotations
3+
-nouses=true

src/main/java/graphql/annotations/DefaultTypeFunction.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.osgi.service.component.annotations.Activate;
2323
import org.osgi.service.component.annotations.Component;
2424
import org.osgi.service.component.annotations.Reference;
25-
import org.osgi.service.component.annotations.ReferencePolicyOption;
26-
import org.osgi.service.component.annotations.ServiceScope;
25+
import org.osgi.service.component.annotations.ReferenceCardinality;
26+
import org.osgi.service.component.annotations.ReferencePolicy;
2727

2828
import java.lang.reflect.AnnotatedParameterizedType;
2929
import java.lang.reflect.AnnotatedType;
@@ -41,11 +41,9 @@
4141
import static graphql.annotations.util.NamingKit.toGraphqlName;
4242
import static graphql.schema.GraphQLEnumType.newEnum;
4343

44-
@Component(scope = ServiceScope.SINGLETON, property = "type=default")
44+
@Component(property = "type=default")
4545
public class DefaultTypeFunction implements TypeFunction {
4646

47-
@Reference(target = "(!(type=default))",
48-
policyOption = ReferencePolicyOption.GREEDY)
4947
protected List<TypeFunction> otherFunctions = new ArrayList<>();
5048

5149
private CopyOnWriteArrayList<TypeFunction> typeFunctions;
@@ -355,6 +353,18 @@ public DefaultTypeFunction() {
355353
typeFunctions.add(new ObjectFunction());
356354
}
357355

356+
@Reference(cardinality = ReferenceCardinality.MULTIPLE,
357+
policy = ReferencePolicy.DYNAMIC,
358+
service = TypeFunction.class,
359+
target = "(!(type=default))")
360+
void addFunction(TypeFunction function) {
361+
this.otherFunctions.add(function);
362+
}
363+
364+
void removeFunction(TypeFunction function) {
365+
this.otherFunctions.remove(function);
366+
}
367+
358368
@Activate
359369
protected void activate() {
360370
for (TypeFunction function : otherFunctions) {

0 commit comments

Comments
 (0)