You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2016/03/10 08:53:48 UTC
svn commit: r1734369 - in /aries/trunk/blueprint/blueprint-maven-plugin/src:
main/java/org/apache/aries/blueprint/plugin/
main/java/org/apache/aries/blueprint/plugin/model/
test/java/org/apache/aries/blueprint/plugin/
test/java/org/apache/aries/bluepri...
Author: cschneider
Date: Thu Mar 10 07:53:45 2016
New Revision: 1734369
URL: http://svn.apache.org/viewvc?rev=1734369&view=rev
Log:
[ARIES-1501] Add constructor injection and component name in reference
Added:
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java
- copied, changed from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ArgumentWriter.java
- copied, changed from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/AnnotatedService.java
aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImplQualified.java
- copied, changed from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceC.java
- copied, changed from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
Removed:
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BuiltInBeanRef.java
Modified:
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,19 +18,8 @@
*/
package org.apache.aries.blueprint.plugin;
-import java.io.OutputStream;
-import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
+import org.apache.aries.blueprint.plugin.model.Argument;
+import org.apache.aries.blueprint.plugin.model.ArgumentWriter;
import org.apache.aries.blueprint.plugin.model.Bean;
import org.apache.aries.blueprint.plugin.model.Context;
import org.apache.aries.blueprint.plugin.model.ProducedBean;
@@ -38,7 +27,19 @@ import org.apache.aries.blueprint.plugin
import org.apache.aries.blueprint.plugin.model.PropertyWriter;
import org.apache.aries.blueprint.plugin.model.TransactionalDef;
-public class Generator implements PropertyWriter {
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.OutputStream;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class Generator implements PropertyWriter, ArgumentWriter {
private static final String NS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
private static final String NS_EXT = "http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0";
public static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0";
@@ -81,6 +82,7 @@ public class Generator implements Proper
}
for (Bean bean : context.getBeans()) {
writeBeanStart(bean);
+ bean.writeArguments(this);
bean.writeProperties(this);
writer.writeEndElement();
writer.writeCharacters("\n");
@@ -102,9 +104,9 @@ public class Generator implements Proper
private boolean isJpaUsed() {
boolean jpaUsed = false;
for (Bean bean : context.getBeans()) {
- if (bean.persistenceFields.size() > 0) {
- jpaUsed = true;
- }
+ if (bean.persistenceFields.size() > 0) {
+ jpaUsed = true;
+ }
}
return jpaUsed;
}
@@ -131,7 +133,8 @@ public class Generator implements Proper
private String getPrefixForNamesapace(String namespace) {
if (namespace.contains("jpa")) {
return "jpa";
- } if (namespace.contains("transactions")) {
+ }
+ if (namespace.contains("transactions")) {
return "tx";
}
return "other";
@@ -146,7 +149,7 @@ public class Generator implements Proper
writer.writeAttribute("scope", "prototype");
}
if (bean instanceof ProducedBean) {
- writeFactory((ProducedBean)bean);
+ writeFactory((ProducedBean) bean);
}
if (bean.initMethod != null) {
writer.writeAttribute("init-method", bean.initMethod);
@@ -225,4 +228,19 @@ public class Generator implements Proper
}
}
+ @Override
+ public void writeArgument(Argument argument) {
+ try {
+ writer.writeCharacters(" ");
+ writer.writeEmptyElement("argument");
+ if (argument.getRef() != null) {
+ writer.writeAttribute("ref", argument.getRef());
+ } else if (argument.getValue() != null) {
+ writer.writeAttribute("value", argument.getValue());
+ }
+ writer.writeCharacters("\n");
+ } catch (XMLStreamException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceProviderWriter.java Thu Mar 10 07:53:45 2016
@@ -18,22 +18,20 @@
*/
package org.apache.aries.blueprint.plugin;
-import java.util.Collection;
-import java.util.List;
-
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import org.apache.aries.blueprint.plugin.model.Bean;
import org.ops4j.pax.cdi.api.OsgiServiceProvider;
import org.ops4j.pax.cdi.api.Properties;
import org.ops4j.pax.cdi.api.Property;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.util.Collection;
+import java.util.List;
public class OsgiServiceProviderWriter {
- private XMLStreamWriter writer;
+ private final XMLStreamWriter writer;
public OsgiServiceProviderWriter(XMLStreamWriter writer) {
this.writer = writer;
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java Thu Mar 10 07:53:45 2016
@@ -18,15 +18,14 @@
*/
package org.apache.aries.blueprint.plugin;
-import java.util.Collection;
+import org.apache.aries.blueprint.plugin.model.OsgiServiceRef;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.aries.blueprint.plugin.model.OsgiServiceRef;
+import java.util.Collection;
public class OsgiServiceRefWriter {
- private XMLStreamWriter writer;
+ private final XMLStreamWriter writer;
public OsgiServiceRefWriter(XMLStreamWriter writer) {
this.writer = writer;
@@ -45,6 +44,9 @@ public class OsgiServiceRefWriter {
if (serviceBean.filter != null && !"".equals(serviceBean.filter)) {
writer.writeAttribute("filter", serviceBean.filter);
}
+ if (serviceBean.compName != null && !"".equals(serviceBean.compName)) {
+ writer.writeAttribute("component-name", serviceBean.compName);
+ }
writer.writeCharacters("\n");
}
Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java (from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java&r1=1734268&r2=1734369&rev=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Argument.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,8 +18,20 @@
*/
package org.apache.aries.blueprint.plugin.model;
+public class Argument {
+ private final String ref;
+ private final String value;
+ public Argument(String ref, String value) {
+ this.ref = ref;
+ this.value = value;
+ }
-public interface Matcher {
- BeanRef getMatching(BeanRef template);
+ public String getRef() {
+ return this.ref;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
}
Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ArgumentWriter.java (from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ArgumentWriter.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ArgumentWriter.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java&r1=1734268&r2=1734369&rev=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ArgumentWriter.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,8 +18,6 @@
*/
package org.apache.aries.blueprint.plugin.model;
-
-
-public interface Matcher {
- BeanRef getMatching(BeanRef template);
+public interface ArgumentWriter {
+ void writeArgument(Argument argument);
}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,31 +18,37 @@
*/
package org.apache.aries.blueprint.plugin.model;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import org.ops4j.pax.cdi.api.OsgiService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
+import javax.inject.Named;
import javax.inject.Singleton;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
public class Bean extends BeanRef {
public String initMethod;
public String destroyMethod;
- public SortedSet<Property> properties;
+ public SortedSet<Property> properties = new TreeSet<>();
+ public List<Argument> constructorArguments = new ArrayList<>();
+ public Set<OsgiServiceRef> serviceRefs = new HashSet<>();
public List<Field> persistenceFields;
- public Set<TransactionalDef> transactionDefs = new HashSet<TransactionalDef>();
+ public Set<TransactionalDef> transactionDefs = new HashSet<>();
public boolean isPrototype;
public Bean(Class<?> clazz) {
@@ -66,15 +72,15 @@ public class Bean extends BeanRef {
transactionDefs.addAll(new SpringTransactionFactory().create(clazz));
this.isPrototype = isPrototype(clazz);
this.persistenceFields = introspector.fieldsWith(PersistenceContext.class, PersistenceUnit.class);
- properties = new TreeSet<Property>();
+ setQualifiersFromAnnotations(clazz.getAnnotations());
}
- private boolean isPrototype(Class<?> clazz)
- {
+ private boolean isPrototype(Class<?> clazz) {
return clazz.getAnnotation(Singleton.class) == null && clazz.getAnnotation(Component.class) == null;
}
public void resolve(Matcher matcher) {
+ resolveConstructorArguments(matcher);
for (Field field : new Introspector(clazz).fieldsWith(Value.class, Autowired.class, Inject.class)) {
Property prop = Property.create(matcher, field);
if (prop != null) {
@@ -83,15 +89,61 @@ public class Bean extends BeanRef {
}
}
+ private void resolveConstructorArguments(Matcher matcher) {
+ for (Constructor constructor : clazz.getDeclaredConstructors()) {
+ Annotation inject = constructor.getAnnotation(Inject.class);
+ Annotation autowired = constructor.getAnnotation(Autowired.class);
+ if (inject != null || autowired != null) {
+ Class[] parameterTypes = constructor.getParameterTypes();
+ Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
+ for (int i = 0; i < parameterTypes.length; ++i) {
+ Annotation[] annotations = parameterAnnotations[i];
+ String ref = null;
+ String value = null;
+ Value valueAnnotation = findAnnotation(annotations, Value.class);
+ OsgiService osgiServiceAnnotation = findAnnotation(annotations, OsgiService.class);
+
+ if (valueAnnotation != null) {
+ value = valueAnnotation.value();
+ }
+
+ if (osgiServiceAnnotation != null) {
+ Named namedAnnotation = findAnnotation(annotations, Named.class);
+ ref = namedAnnotation != null ? namedAnnotation.value() : getBeanNameFromSimpleName(parameterTypes[i].getSimpleName());
+ OsgiServiceRef osgiServiceRef = new OsgiServiceRef(parameterTypes[i], osgiServiceAnnotation, ref);
+ serviceRefs.add(osgiServiceRef);
+ }
+
+ if (ref == null && value == null && osgiServiceAnnotation == null) {
+ BeanRef template = new BeanRef(parameterTypes[i]);
+ template.setQualifiersFromAnnotations(annotations);
+ BeanRef bean = matcher.getMatching(template);
+ if (bean != null) {
+ ref = bean.id;
+ } else {
+ Named namedAnnotation = findAnnotation(annotations, Named.class);
+ if (namedAnnotation != null) {
+ ref = namedAnnotation.value();
+ } else {
+ ref = getBeanName(parameterTypes[i]);
+ }
+ }
+ }
+
+ constructorArguments.add(new Argument(ref, value));
+ }
+ break;
+ }
+ }
+ }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((clazz == null) ? 0 : clazz.getName().hashCode());
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
+ private static <T> T findAnnotation(Annotation[] annotations, Class<T> annotation) {
+ for (Annotation a : annotations) {
+ if (a.annotationType() == annotation) {
+ return annotation.cast(a);
+ }
+ }
+ return null;
}
@Override
@@ -105,4 +157,11 @@ public class Bean extends BeanRef {
}
}
+ public void writeArguments(ArgumentWriter writer) {
+ for (Argument argument : constructorArguments) {
+ writer.writeArgument(argument);
+ }
+ }
+
+
}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java Thu Mar 10 07:53:45 2016
@@ -1,28 +1,26 @@
package org.apache.aries.blueprint.plugin.model;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Named;
+import javax.inject.Qualifier;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
-import javax.inject.Named;
-
-import org.springframework.stereotype.Component;
-
public class BeanRef implements Comparable<BeanRef> {
public String id;
public Class<?> clazz;
- public Map<Class<? extends Annotation>, Annotation> qualifiers;
-
+ public Map<Class<? extends Annotation>, Annotation> qualifiers = new HashMap<>();
+
/**
- *
* @param clazz interface or implementation class
*/
public BeanRef(Class<?> clazz) {
this.clazz = clazz;
- this.qualifiers = new HashMap<Class<? extends Annotation>, Annotation>();
}
-
+
public BeanRef(Class<?> clazz, String id) {
this(clazz);
this.id = id;
@@ -30,15 +28,20 @@ public class BeanRef implements Comparab
public BeanRef(Field field) {
this(field.getType());
- for (Annotation ann : field.getAnnotations()) {
+ Annotation[] annotations = field.getAnnotations();
+ setQualifiersFromAnnotations(annotations);
+ }
+
+ protected void setQualifiersFromAnnotations(Annotation[] annotations) {
+ for (Annotation ann : annotations) {
if (isQualifier(ann) != null) {
this.qualifiers.put(ann.annotationType(), ann);
}
}
}
- private javax.inject.Qualifier isQualifier(Annotation ann) {
- return ann.annotationType().getAnnotation(javax.inject.Qualifier.class);
+ private Qualifier isQualifier(Annotation ann) {
+ return ann.annotationType().getAnnotation(Qualifier.class);
}
public static String getBeanName(Class<?> clazz) {
@@ -47,17 +50,17 @@ public class BeanRef implements Comparab
if (component != null && !"".equals(component.value())) {
return component.value();
} else if (named != null && !"".equals(named.value())) {
- return named.value();
+ return named.value();
} else {
String name = clazz.getSimpleName();
return getBeanNameFromSimpleName(name);
}
}
- private static String getBeanNameFromSimpleName(String name) {
+ protected static String getBeanNameFromSimpleName(String name) {
return name.substring(0, 1).toLowerCase() + name.substring(1, name.length());
}
-
+
public boolean matches(BeanRef template) {
boolean assignable = template.clazz.isAssignableFrom(this.clazz);
return assignable && qualifiers.values().containsAll(template.qualifiers.values());
@@ -67,9 +70,31 @@ public class BeanRef implements Comparab
public int compareTo(BeanRef other) {
return this.id.compareTo(other.id);
}
-
+
@Override
public String toString() {
return this.clazz.getSimpleName() + "(" + this.id + ")";
}
+
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof BeanRef)) return false;
+ final BeanRef other = (BeanRef) o;
+ if (!other.canEqual(this)) return false;
+ if (this.id == null ? other.id != null : !this.id.equals(other.id)) return false;
+ if (this.clazz == null ? other.clazz != null : !this.clazz.equals(other.clazz)) return false;
+ return true;
+ }
+
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + (this.id == null ? 0 : this.id.hashCode());
+ result = result * PRIME + (this.clazz == null ? 0 : this.clazz.hashCode());
+ return result;
+ }
+
+ protected boolean canEqual(Object other) {
+ return other instanceof BeanRef;
+ }
}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java Thu Mar 10 07:53:45 2016
@@ -87,9 +87,14 @@ public class Context implements Matcher
public void resolve() {
for (Bean bean : getBeans()) {
bean.resolve(this);
+ addServiceRefs(bean);
}
}
+ private void addServiceRefs(Bean bean) {
+ reg.addAll(bean.serviceRefs);
+ }
+
public BeanRef getMatching(BeanRef template) {
for (BeanRef bean : reg) {
if (bean.matches(template)) {
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java Thu Mar 10 07:53:45 2016
@@ -18,8 +18,6 @@
*/
package org.apache.aries.blueprint.plugin.model;
-
-
public interface Matcher {
BeanRef getMatching(BeanRef template);
}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java Thu Mar 10 07:53:45 2016
@@ -27,18 +27,40 @@ import org.ops4j.pax.cdi.api.OsgiService
*/
public class OsgiServiceRef extends BeanRef {
- public String filter;
+ final public String filter;
+ final public String compName;
+
public OsgiServiceRef(Field field) {
super(field);
OsgiService osgiService = field.getAnnotation(OsgiService.class);
- filter = osgiService.filter();
+ String filterValue = osgiService.filter();
+ if (filterValue.contains("(")) {
+ filter = filterValue;
+ compName = null;
+ } else {
+ compName = filterValue;
+ filter = null;
+ }
id = getBeanName(clazz);
if (filter != null) {
id = id + "-" + getId(filter);
}
}
+ public OsgiServiceRef(Class<?> clazz, OsgiService osgiService, String name) {
+ super(clazz, name);
+ String filterValue = osgiService.filter();
+ if (filterValue.contains("(")) {
+ filter = filterValue;
+ compName = null;
+ } else {
+ compName = filterValue;
+ filter = null;
+ }
+ }
+
+
private String getId(String raw) {
StringBuilder builder = new StringBuilder();
for (int c = 0; c < raw.length(); c++) {
Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/AnnotatedService.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/AnnotatedService.java?rev=1734369&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/AnnotatedService.java (added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/AnnotatedService.java Thu Mar 10 07:53:45 2016
@@ -0,0 +1,12 @@
+package org.apache.aries.blueprint.plugin;
+
+import javax.inject.Named;
+import javax.inject.Qualifier;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+@Named("annotatedService")
+public @interface AnnotatedService {
+}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,23 +18,7 @@
*/
package org.apache.aries.blueprint.plugin;
-import static java.util.Arrays.asList;
-import static org.apache.aries.blueprint.plugin.FilteredClassFinder.findClasses;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathFactory;
-
+import com.google.common.collect.Sets;
import org.apache.aries.blueprint.plugin.model.Context;
import org.apache.aries.blueprint.plugin.model.TransactionalDef;
import org.apache.aries.blueprint.plugin.test.MyBean1;
@@ -42,25 +26,41 @@ import org.apache.aries.blueprint.plugin
import org.apache.aries.blueprint.plugin.test.ServiceB;
import org.apache.commons.io.output.ByteArrayOutputStream;
import org.apache.xbean.finder.ClassFinder;
-import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
-import com.google.common.collect.Sets;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.aries.blueprint.plugin.FilteredClassFinder.findClasses;
+import static org.junit.Assert.assertEquals;
public class GeneratorTest {
- private XPath xpath;
- private Document document;
+ private static XPath xpath;
+ private static Document document;
- @Test
- public void testGenerate() throws Exception {
- ClassFinder classFinder = new ClassFinder(this.getClass().getClassLoader());
+ @BeforeClass
+ public static void setUp() throws Exception {
+ ClassFinder classFinder = new ClassFinder(GeneratorTest.class.getClassLoader());
String packageName = MyBean1.class.getPackage().getName();
- Set<Class<?>> beanClasses = findClasses(classFinder, asList(packageName));
+ Set<Class<?>> beanClasses = findClasses(classFinder, Collections.singletonList(packageName));
Context context = new Context(beanClasses);
context.resolve();
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -70,17 +70,23 @@ public class GeneratorTest {
document = readToDocument(os);
xpath = XPathFactory.newInstance().newXPath();
- //xpath.setNamespaceContext(new NameSpaces(document));
- Node bean1 = (Node) xpath.evaluate("/blueprint/bean[@id='myBean1']", document, XPathConstants.NODE);
+ }
- // Bean
- Assert.assertEquals(MyBean1.class.getName(), xpath.evaluate("@class", bean1));
- Assert.assertEquals("init", xpath.evaluate("@init-method", bean1));
- Assert.assertEquals("destroy", xpath.evaluate("@destroy-method", bean1));
- Assert.assertEquals("true", xpath.evaluate("@field-injection", bean1));
- Assert.assertEquals("", xpath.evaluate("@scope", bean1));
+ @Test
+ public void testGenerateBeanWithInitDestroyAndfieldInjection() throws Exception {
+ Node bean1 = getBeanById("myBean1");
+
+ assertEquals(MyBean1.class.getName(), xpath.evaluate("@class", bean1));
+ assertEquals("init", xpath.evaluate("@init-method", bean1));
+ assertEquals("destroy", xpath.evaluate("@destroy-method", bean1));
+ assertEquals("true", xpath.evaluate("@field-injection", bean1));
+ assertEquals("", xpath.evaluate("@scope", bean1));
+ }
+
+ @Test
+ public void testGenerateTransactional() throws Exception {
+ Node bean1 = getBeanById("myBean1");
- // @Transactional
NodeList txs = (NodeList) xpath.evaluate("transaction", bean1, XPathConstants.NODESET);
Set<TransactionalDef> defs = new HashSet<TransactionalDef>();
for (int i = 0; i < txs.getLength(); ++i) {
@@ -88,41 +94,59 @@ public class GeneratorTest {
defs.add(new TransactionalDef(xpath.evaluate("@method", tx), xpath.evaluate("@value", tx)));
}
Set<TransactionalDef> expectedDefs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"),
- new TransactionalDef("txNotSupported", "NotSupported"),
- new TransactionalDef("txMandatory", "Mandatory"),
- new TransactionalDef("txNever", "Never"),
- new TransactionalDef("txRequired", "Required"),
- new TransactionalDef("txOverridenWithRequiresNew", "RequiresNew"),
- new TransactionalDef("txSupports", "Supports"));
- Assert.assertEquals(expectedDefs, defs);
-
- // @PersistenceContext
- Assert.assertEquals("person", xpath.evaluate("context/@unitname", bean1));
- Assert.assertEquals("em", xpath.evaluate("context/@property", bean1));
-
- // @PersistenceUnit
- Assert.assertEquals("person", xpath.evaluate("unit/@unitname", bean1));
- Assert.assertEquals("emf", xpath.evaluate("unit/@property", bean1));
-
- // @Autowired
- Assert.assertEquals("my1", xpath.evaluate("property[@name='bean2']/@ref", bean1));
-
- // Service with 1 interface
- Node serviceAImpl2 = (Node) xpath.evaluate("/blueprint/service[@ref='my2']", document, XPathConstants.NODE);
- Assert.assertEquals(ServiceA.class.getName(), xpath.evaluate("@interface", serviceAImpl2));
- Assert.assertEquals("", xpath.evaluate("@auto-export", serviceAImpl2));
- Assert.assertEquals("", xpath.evaluate("interfaces", serviceAImpl2));
-
- // Service with 0 interfaces (using auto-export=interfaces instead)
- Node serviceAImpl3 = (Node) xpath.evaluate("/blueprint/service[@ref='serviceAImpl3']", document, XPathConstants.NODE);
- Assert.assertEquals("", xpath.evaluate("@interface", serviceAImpl3));
- Assert.assertEquals("interfaces", xpath.evaluate("@auto-export", serviceAImpl3));
- Assert.assertEquals("", xpath.evaluate("interfaces", serviceAImpl3));
-
- // Service with 2 interfaces (using <interfaces><value>ServiceA</value><value>ServiceB</value></interfaces>
- Node serviceABImpl = (Node) xpath.evaluate("/blueprint/service[@ref='serviceABImpl']", document, XPathConstants.NODE);
- Assert.assertEquals("", xpath.evaluate("@interface", serviceABImpl));
- Assert.assertEquals("", xpath.evaluate("@auto-export", serviceABImpl));
+ new TransactionalDef("txNotSupported", "NotSupported"),
+ new TransactionalDef("txMandatory", "Mandatory"),
+ new TransactionalDef("txNever", "Never"),
+ new TransactionalDef("txRequired", "Required"),
+ new TransactionalDef("txOverridenWithRequiresNew", "RequiresNew"),
+ new TransactionalDef("txSupports", "Supports"));
+ assertEquals(expectedDefs, defs);
+ }
+
+ @Test
+ public void testGeneratePersistenceContext() throws Exception {
+ Node bean1 = getBeanById("myBean1");
+
+ assertEquals("person", xpath.evaluate("context/@unitname", bean1));
+ assertEquals("em", xpath.evaluate("context/@property", bean1));
+ }
+
+ @Test
+ public void testGeneratePersistenceUnit() throws Exception {
+ Node bean1 = getBeanById("myBean1");
+
+ assertEquals("person", xpath.evaluate("unit/@unitname", bean1));
+ assertEquals("emf", xpath.evaluate("unit/@property", bean1));
+ }
+
+ @Test
+ public void testGenerateAutowiredBean() throws Exception {
+ Node bean1 = getBeanById("myBean1");
+
+ assertEquals("my1", xpath.evaluate("property[@name='bean2']/@ref", bean1));
+ }
+
+ @Test
+ public void testGenerateServiceWithOneInterface() throws Exception {
+ Node serviceAImpl2 = getServiceByRef("my2");
+ assertEquals(ServiceA.class.getName(), xpath.evaluate("@interface", serviceAImpl2));
+ assertEquals("", xpath.evaluate("@auto-export", serviceAImpl2));
+ assertEquals("", xpath.evaluate("interfaces", serviceAImpl2));
+ }
+
+ @Test
+ public void testGenerateServiceWithAutoExport() throws Exception {
+ Node serviceAImpl3 = getServiceByRef("serviceAImpl3");
+ assertEquals("", xpath.evaluate("@interface", serviceAImpl3));
+ assertEquals("interfaces", xpath.evaluate("@auto-export", serviceAImpl3));
+ assertEquals("", xpath.evaluate("interfaces", serviceAImpl3));
+ }
+
+ @Test
+ public void testGenerateServiceWith2Interfaces() throws Exception {
+ Node serviceABImpl = getServiceByRef("serviceABImpl");
+ assertEquals("", xpath.evaluate("@interface", serviceABImpl));
+ assertEquals("", xpath.evaluate("@auto-export", serviceABImpl));
NodeList interfaceValues = (NodeList) xpath.evaluate("interfaces/value", serviceABImpl, XPathConstants.NODESET);
Set<String> interfaceNames = new HashSet<String>();
@@ -130,16 +154,55 @@ public class GeneratorTest {
Node interfaceValue = interfaceValues.item(i);
interfaceNames.add(interfaceValue.getTextContent());
}
- Assert.assertEquals(Sets.newHashSet(ServiceA.class.getName(), ServiceB.class.getName()),
- interfaceNames);
+ assertEquals(Sets.newHashSet(ServiceA.class.getName(), ServiceB.class.getName()),
+ interfaceNames);
+ }
+
+ @Test
+ public void testGenerateBeanWithConstructorInjection() throws Exception {
+ // Bean with constructor injection
+ Node myBean5 = getBeanById("myBean5");
+ assertEquals("my2", xpath.evaluate("argument[1]/@ref", myBean5));
+ assertEquals("my1", xpath.evaluate("argument[2]/@ref", myBean5));
+ assertEquals("serviceABImpl", xpath.evaluate("argument[3]/@ref", myBean5));
+ assertEquals("100", xpath.evaluate("argument[4]/@value", myBean5));
+ assertEquals("ser1", xpath.evaluate("argument[5]/@ref", myBean5));
+ assertEquals("ser2", xpath.evaluate("argument[6]/@ref", myBean5));
+ assertEquals("serviceAImplQualified", xpath.evaluate("argument[7]/@ref", myBean5));
+ }
+
+ @Test
+ public void testGenerateReferenceWithComponentName() throws Exception {
+ Node ser1 = getReferenceById("ser1");
+ assertEquals("myRef", xpath.evaluate("@component-name", ser1));
+ assertEquals("", xpath.evaluate("@filter", ser1));
}
- private Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException,
- SAXException, IOException {
+ @Test
+ public void testGenerateReferenceWithFilter() throws Exception {
+ Node ser2 = getReferenceById("ser2");
+ assertEquals("", xpath.evaluate("@component-name", ser2));
+ assertEquals("(mode=123)", xpath.evaluate("@filter", ser2));
+ }
+
+ private static Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException,
+ SAXException, IOException {
InputStream is = new ByteArrayInputStream(os.toByteArray());
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
return builder.parse(is);
}
+ private static Node getBeanById(String id) throws XPathExpressionException {
+ return (Node) xpath.evaluate("/blueprint/bean[@id='" + id + "']", document, XPathConstants.NODE);
+ }
+
+ private static Node getServiceByRef(String id) throws XPathExpressionException {
+ return (Node) xpath.evaluate("/blueprint/service[@ref='" + id + "']", document, XPathConstants.NODE);
+ }
+
+ private static Node getReferenceById(String id) throws XPathExpressionException {
+ return (Node) xpath.evaluate("/blueprint/reference[@id='" + id + "']", document, XPathConstants.NODE);
+ }
+
}
Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java?rev=1734369&r1=1734368&r2=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/model/BeanTest.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,15 +18,7 @@
*/
package org.apache.aries.blueprint.plugin.model;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Set;
-
-import javax.inject.Named;
-
+import com.google.common.collect.Sets;
import org.apache.aries.blueprint.plugin.bad.BadBean1;
import org.apache.aries.blueprint.plugin.bad.BadBean2;
import org.apache.aries.blueprint.plugin.bad.BadBean3;
@@ -37,11 +29,18 @@ import org.apache.aries.blueprint.plugin
import org.apache.aries.blueprint.plugin.test.MyBean1;
import org.apache.aries.blueprint.plugin.test.MyBean3;
import org.apache.aries.blueprint.plugin.test.MyBean4;
+import org.apache.aries.blueprint.plugin.test.MyBean5;
import org.apache.aries.blueprint.plugin.test.ServiceAImpl1;
import org.junit.Assert;
import org.junit.Test;
-import com.google.common.collect.Sets;
+import javax.inject.Named;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
public class BeanTest {
@@ -63,12 +62,12 @@ public class BeanTest {
assertEquals("serviceA", prop.ref);
Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"),
- new TransactionalDef("txNotSupported", "NotSupported"),
- new TransactionalDef("txMandatory", "Mandatory"),
- new TransactionalDef("txNever", "Never"),
- new TransactionalDef("txRequired", "Required"),
- new TransactionalDef("txOverridenWithRequiresNew", "RequiresNew"),
- new TransactionalDef("txSupports", "Supports"));
+ new TransactionalDef("txNotSupported", "NotSupported"),
+ new TransactionalDef("txMandatory", "Mandatory"),
+ new TransactionalDef("txNever", "Never"),
+ new TransactionalDef("txRequired", "Required"),
+ new TransactionalDef("txOverridenWithRequiresNew", "RequiresNew"),
+ new TransactionalDef("txSupports", "Supports"));
assertEquals(expectedTxs, bean.transactionDefs);
}
@@ -85,12 +84,12 @@ public class BeanTest {
assertTrue(bean.isPrototype);
Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"),
- new TransactionalDef("txNotSupported", "NotSupported"),
- new TransactionalDef("txMandatory", "Mandatory"),
- new TransactionalDef("txNever", "Never"),
- new TransactionalDef("txRequired", "Required"),
- new TransactionalDef("txRequiresNew", "RequiresNew"),
- new TransactionalDef("txSupports", "Supports"));
+ new TransactionalDef("txNotSupported", "NotSupported"),
+ new TransactionalDef("txMandatory", "Mandatory"),
+ new TransactionalDef("txNever", "Never"),
+ new TransactionalDef("txRequired", "Required"),
+ new TransactionalDef("txRequiresNew", "RequiresNew"),
+ new TransactionalDef("txSupports", "Supports"));
assertEquals(expectedTxs, bean.transactionDefs);
}
@@ -156,4 +155,25 @@ public class BeanTest {
public void testFieldBean4() {
new Context(FieldBean4.class).resolve();
}
+
+ @Test
+ public void testParseBeanWithConstructorInject() {
+ Bean bean = new Bean(MyBean5.class);
+ bean.resolve(new Context());
+ assertEquals(MyBean5.class, bean.clazz);
+ assertEquals("myBean5", bean.id); // Name derived from class name
+ assertNull("There should be no initMethod", bean.initMethod);
+ assertNull("There should be no destroyMethod", bean.destroyMethod);
+ assertTrue("There should be no persistenceUnit", bean.persistenceFields.isEmpty());
+ assertEquals(0, bean.properties.size());
+ assertEquals(7, bean.constructorArguments.size());
+ assertEquals("my2", bean.constructorArguments.get(0).getRef());
+ assertEquals("serviceA", bean.constructorArguments.get(1).getRef());
+ assertEquals("serviceB", bean.constructorArguments.get(2).getRef());
+ assertEquals("100", bean.constructorArguments.get(3).getValue());
+ assertEquals("ser1", bean.constructorArguments.get(4).getRef());
+ assertEquals("ser2", bean.constructorArguments.get(5).getRef());
+ assertEquals("serviceA", bean.constructorArguments.get(6).getRef());
+ }
+
}
Added: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java?rev=1734369&view=auto
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java (added)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java Thu Mar 10 07:53:45 2016
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.plugin.test;
+
+import org.apache.aries.blueprint.plugin.AnnotatedService;
+import org.ops4j.pax.cdi.api.OsgiService;
+import org.springframework.beans.factory.annotation.Value;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+@Singleton
+public class MyBean5 {
+
+ ServiceA serviceA1;
+
+ ServiceA serviceA2;
+
+ ServiceB serviceB;
+
+ int bla;
+
+ ServiceC myReference;
+ ServiceC myReference2;
+
+ ServiceA serviceAAnnotated;
+
+ @Inject
+ public MyBean5(@Named("my2") ServiceA serviceA1,
+ ServiceA serviceA2,
+ ServiceB serviceB,
+ @Value("100") int bla,
+ @OsgiService(filter = "myRef") @Named("ser1") ServiceC myReference,
+ @OsgiService(filter = "(mode=123)") @Named("ser2") ServiceC myReference2,
+ @AnnotatedService ServiceA serviceAAnnotated) {
+ this.serviceA1 = serviceA1;
+ this.serviceA2 = serviceA2;
+ this.serviceB = serviceB;
+ this.bla = bla;
+ this.myReference = myReference;
+ this.myReference2 = myReference2;
+ this.serviceAAnnotated = serviceAAnnotated;
+ }
+}
Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImplQualified.java (from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImplQualified.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImplQualified.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java&r1=1734268&r2=1734369&rev=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceAImplQualified.java Thu Mar 10 07:53:45 2016
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -16,10 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.aries.blueprint.plugin.model;
+package org.apache.aries.blueprint.plugin.test;
+import org.apache.aries.blueprint.plugin.AnnotatedService;
+import javax.inject.Singleton;
-public interface Matcher {
- BeanRef getMatching(BeanRef template);
+@Singleton
+@AnnotatedService
+public class ServiceAImplQualified implements ServiceA {
}
Copied: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceC.java (from r1734268, aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceC.java?p2=aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceC.java&p1=aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java&r1=1734268&r2=1734369&rev=1734369&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/ServiceC.java Thu Mar 10 07:53:45 2016
@@ -16,10 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.aries.blueprint.plugin.model;
+package org.apache.aries.blueprint.plugin.test;
+public interface ServiceC {
-
-public interface Matcher {
- BeanRef getMatching(BeanRef template);
}