You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2016/06/15 19:23:47 UTC
svn commit: r1748624 [2/3] - in /aries/branches/java6support/blueprint: ./
blueprint-bundle/ blueprint-cm/
blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/
blueprint-cm/src/main/resources/OSGI-INF/blueprint/ blueprint-core/
blueprin...
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java Wed Jun 15 19:23:47 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,62 +18,71 @@
*/
package org.apache.aries.blueprint.plugin;
-import java.io.File;
-import java.io.OutputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
import org.apache.aries.blueprint.plugin.model.Context;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.xbean.finder.ClassFinder;
import org.sonatype.plexus.build.incremental.BuildContext;
+import java.io.File;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
/**
- * Generates blueprint from spring annotations
- * @goal blueprint-generate
- * @phase process-classes
- * @requiresDependencyResolution compile
- * @inheritByDefault false
- * @description Generates blueprint file from spring annotations @Component, @Autowire and @Value
+ * Generates blueprint from CDI and spring annotations
*/
+@Mojo(name="blueprint-generate", requiresDependencyResolution=ResolutionScope.COMPILE,
+ defaultPhase=LifecyclePhase.PROCESS_CLASSES, inheritByDefault=false)
public class GenerateMojo extends AbstractMojo {
- /**
- * The maven project.
- *
- * @parameter default-value="${project}"
- * @required
- */
+ @Parameter(defaultValue="${project}", required=true)
protected MavenProject project;
- /**
- * @parameter
- * @required
- */
+ @Parameter(required=true)
protected List<String> scanPaths;
/**
* Which extension namespaces should the plugin support
- *
- * @parameter
*/
+ @Parameter
protected Set<String> namespaces;
-
+
+ @Component
+ private BuildContext buildContext;
+
/**
- * @component
+ * Name of file to generate
*/
- private BuildContext buildContext;
+ @Parameter(defaultValue="autowire.xml")
+ protected String generatedFileName;
+
+ /**
+ * Specifies the default activation setting that will be defined for components.
+ * Default is null, which indicates eager (blueprint default).
+ * If LAZY then default-activation will be set to lazy.
+ * If EAGER then default-activation will be explicitly set to eager.
+ */
+ @Parameter
+ protected Activation defaultActivation;
public void execute() throws MojoExecutionException, MojoFailureException {
+ if (scanPaths.size() == 0 || scanPaths.iterator().next() == null) {
+ throw new MojoExecutionException("Configuration scanPaths must be set");
+ }
if (!buildContext.hasDelta(new File(project.getCompileSourceRoots().iterator().next()))) {
return;
}
@@ -99,24 +108,24 @@ public class GenerateMojo extends Abstra
resource.setDirectory(generatedDir);
project.addResource(resource);
- File file = new File(generatedDir, "OSGI-INF/blueprint/autowire.xml");
+ File file = new File(generatedDir, "OSGI-INF/blueprint/" + generatedFileName);
file.getParentFile().mkdirs();
System.out.println("Generating blueprint to " + file);
OutputStream fos = buildContext.newFileOutputStream(file);
- new Generator(context, fos, namespaces).generate();
+ new Generator(context, fos, namespaces, defaultActivation).generate();
fos.close();
}
private ClassFinder createProjectScopeFinder() throws MalformedURLException {
List<URL> urls = new ArrayList<URL>();
- urls.add( new File(project.getBuild().getOutputDirectory()).toURI().toURL() );
- for ( Object artifactO : project.getArtifacts() ) {
- Artifact artifact = (Artifact)artifactO;
+ urls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL());
+ for (Object artifactO : project.getArtifacts()) {
+ Artifact artifact = (Artifact) artifactO;
File file = artifact.getFile();
- if ( file != null ) {
- urls.add( file.toURI().toURL() );
+ if (file != null) {
+ urls.add(file.toURI().toURL());
}
}
ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java Wed Jun 15 19:23:47 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,27 +18,29 @@
*/
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;
import org.apache.aries.blueprint.plugin.model.Property;
import org.apache.aries.blueprint.plugin.model.PropertyWriter;
import org.apache.aries.blueprint.plugin.model.TransactionalDef;
+import org.apache.aries.blueprint.plugin.model.service.ServiceProviderWriter;
+
+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 {
+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";
@@ -46,16 +48,15 @@ public class Generator implements Proper
public static final String NS_TX = "http://aries.apache.org/xmlns/transactions/v1.2.0";
public static final String NS_TX2 = "http://aries.apache.org/xmlns/transactions/v2.0.0";
- private Context context;
- private XMLStreamWriter writer;
- private Set<String> namespaces;
+ private final Context context;
+ private final XMLStreamWriter writer;
+ private final Set<String> namespaces;
+ private final Activation defaultActivation;
- public Generator(Context context, OutputStream os, Set<String> namespaces) throws XMLStreamException {
+ public Generator(Context context, OutputStream os, Set<String> namespaces, Activation defaultActivation) throws XMLStreamException {
this.context = context;
- this.namespaces = namespaces;
- if (this.namespaces == null) {
- this.namespaces = new HashSet<String>(Arrays.asList(NS_TX2, NS_JPA2));
- }
+ this.namespaces = namespaces != null ? namespaces : new HashSet<>(Arrays.asList(NS_TX2, NS_JPA2));
+ this.defaultActivation = defaultActivation;
XMLOutputFactory factory = XMLOutputFactory.newInstance();
writer = factory.createXMLStreamWriter(os);
}
@@ -81,13 +82,14 @@ public class Generator implements Proper
}
for (Bean bean : context.getBeans()) {
writeBeanStart(bean);
+ bean.writeArguments(this);
bean.writeProperties(this);
writer.writeEndElement();
writer.writeCharacters("\n");
}
new OsgiServiceRefWriter(writer).write(context.getServiceRefs());
- new OsgiServiceProviderWriter(writer).write(context.getBeans());
+ new ServiceProviderWriter(writer).write(context.getServiceProviders());
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;
}
@@ -126,12 +128,16 @@ public class Generator implements Proper
String prefix = getPrefixForNamesapace(namespace);
writer.writeNamespace(prefix, namespace);
}
+ if (defaultActivation != null) {
+ writer.writeAttribute("default-activation", defaultActivation.name().toLowerCase());
+ }
}
private String getPrefixForNamesapace(String namespace) {
if (namespace.contains("jpa")) {
return "jpa";
- } if (namespace.contains("transactions")) {
+ }
+ if (namespace.contains("transactions")) {
return "tx";
}
return "other";
@@ -141,12 +147,20 @@ public class Generator implements Proper
writer.writeStartElement("bean");
writer.writeAttribute("id", bean.id);
writer.writeAttribute("class", bean.clazz.getName());
- writer.writeAttribute("ext", NS_EXT, "field-injection", "true");
+ if (bean.needFieldInjection()) {
+ writer.writeAttribute("ext", NS_EXT, "field-injection", "true");
+ }
if (bean.isPrototype) {
writer.writeAttribute("scope", "prototype");
}
+ if (bean.activation != null) {
+ writer.writeAttribute("activation", bean.activation.toString());
+ }
+ if (bean.dependsOn != null) {
+ writer.writeAttribute("depends-on", bean.dependsOn);
+ }
if (bean instanceof ProducedBean) {
- writeFactory((ProducedBean)bean);
+ writeFactory((ProducedBean) bean);
}
if (bean.initMethod != null) {
writer.writeAttribute("init-method", bean.initMethod);
@@ -172,7 +186,7 @@ public class Generator implements Proper
}
private void writeTransactional(TransactionalDef transactionDef)
- throws XMLStreamException {
+ throws XMLStreamException {
if (transactionDef != null) {
writer.writeCharacters(" ");
writer.writeEmptyElement("tx", "transaction", NS_TX);
@@ -225,4 +239,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/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/OsgiServiceRefWriter.java Wed Jun 15 19:23:47 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");
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Bean.java Wed Jun 15 19:23:47 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,63 +18,129 @@
*/
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.apache.aries.blueprint.plugin.Activation;
+import org.apache.aries.blueprint.plugin.model.service.ServiceProvider;
+import org.apache.commons.lang.StringUtils;
+import org.ops4j.pax.cdi.api.OsgiService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.DependsOn;
+import org.springframework.context.annotation.Lazy;
+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.AnnotatedElement;
+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 final 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 List<ServiceProvider> serviceProviders = new ArrayList<>();
+ public Activation activation;
+ public String dependsOn;
public Bean(Class<?> clazz) {
super(clazz, BeanRef.getBeanName(clazz));
Introspector introspector = new Introspector(clazz);
- // Init method
- Method initMethod = introspector.methodWith(PostConstruct.class);
- if (initMethod != null) {
- this.initMethod = initMethod.getName();
+ activation = getActivation(clazz);
+ dependsOn = getDependsOn(clazz);
+
+ initMethod = findMethodAnnotatedWith(introspector, PostConstruct.class);
+ destroyMethod = findMethodAnnotatedWith(introspector, PreDestroy.class);
+
+ interpretTransactionalMethods(clazz);
+
+ this.isPrototype = isPrototype(clazz);
+ this.persistenceFields = findPersistenceFields(introspector);
+
+ setQualifiersFromAnnotations(clazz.getAnnotations());
+
+ interpretServiceProvider();
+ }
+
+ protected String getDependsOn(AnnotatedElement annotatedElement) {
+ DependsOn annotation = annotatedElement.getAnnotation(DependsOn.class);
+ if (annotation == null || annotation.value().length == 0) {
+ return null;
}
+ String[] value = annotation.value();
+ return StringUtils.join(value, " ");
+ }
- // Destroy method
- Method destroyMethod = introspector.methodWith(PreDestroy.class);
- if (destroyMethod != null) {
- this.destroyMethod = destroyMethod.getName();
+ protected Activation getActivation(AnnotatedElement annotatedElement) {
+ Lazy lazy = annotatedElement.getAnnotation(Lazy.class);
+ if (lazy == null) {
+ return null;
}
+ return lazy.value() ? Activation.LAZY : Activation.EAGER;
+ }
+
+ private void interpretServiceProvider() {
+ ServiceProvider serviceProvider = ServiceProvider.fromBean(this);
+ if (serviceProvider != null) {
+ serviceProviders.add(serviceProvider);
+ }
+ }
+
+ private List<Field> findPersistenceFields(Introspector introspector) {
+ return introspector.fieldsWith(PersistenceContext.class, PersistenceUnit.class);
+ }
- // Transactional methods
+ private void interpretTransactionalMethods(Class<?> clazz) {
transactionDefs.addAll(new JavaxTransactionFactory().create(clazz));
transactionDefs.addAll(new SpringTransactionFactory().create(clazz));
- this.isPrototype = isPrototype(clazz);
- this.persistenceFields = introspector.fieldsWith(PersistenceContext.class, PersistenceUnit.class);
- properties = new TreeSet<Property>();
}
- private boolean isPrototype(Class<?> clazz)
- {
+ private String findMethodAnnotatedWith(Introspector introspector, Class<? extends Annotation> annotation) {
+ Method initMethod = introspector.methodWith(annotation);
+ if (initMethod == null) {
+ return null;
+ }
+ return initMethod.getName();
+ }
+
+ private boolean isPrototype(Class<?> clazz) {
return clazz.getAnnotation(Singleton.class) == null && clazz.getAnnotation(Component.class) == null;
}
public void resolve(Matcher matcher) {
+ resolveArguments(matcher);
+ resolveFiields(matcher);
+ resolveMethods(matcher);
+ }
+
+ private void resolveMethods(Matcher matcher) {
+ for (Method method : new Introspector(clazz).methodsWith(Value.class, Autowired.class, Inject.class)) {
+ Property prop = Property.create(matcher, method);
+ if (prop != null) {
+ properties.add(prop);
+ }
+ }
+ }
+
+ private void resolveFiields(Matcher 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 +149,64 @@ public class Bean extends BeanRef {
}
}
+ protected void resolveArguments(Matcher matcher) {
+ Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
+ for (Constructor constructor : declaredConstructors) {
+ Annotation inject = constructor.getAnnotation(Inject.class);
+ Annotation autowired = constructor.getAnnotation(Autowired.class);
+ if (inject != null || autowired != null || declaredConstructors.length == 1) {
+ resolveArguments(matcher, constructor.getParameterTypes(), constructor.getParameterAnnotations());
+ break;
+ }
+ }
+ }
+ protected void resolveArguments(Matcher matcher, Class[] parameterTypes, Annotation[][] parameterAnnotations) {
+ 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);
- @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;
+ 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));
+ }
+ }
+
+ 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 +220,19 @@ public class Bean extends BeanRef {
}
}
+ public void writeArguments(ArgumentWriter writer) {
+ for (Argument argument : constructorArguments) {
+ writer.writeArgument(argument);
+ }
+ }
+
+
+ public boolean needFieldInjection() {
+ for (Property property : properties) {
+ if (property.isField) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/BeanRef.java Wed Jun 15 19:23:47 2016
@@ -1,28 +1,46 @@
+/**
+ * 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.model;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Named;
+import javax.inject.Qualifier;
import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
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,36 +48,57 @@ public class BeanRef implements Comparab
public BeanRef(Field field) {
this(field.getType());
- for (Annotation ann : field.getAnnotations()) {
+ parseQualifiers(field);
+ }
+
+ public BeanRef(Method method) {
+ this(method.getParameterTypes()[0]);
+ parseQualifiers(method);
+ }
+
+ private void parseQualifiers(AnnotatedElement annotatedElement) {
+ Annotation[] annotations = annotatedElement.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) {
- Component component = clazz.getAnnotation(Component.class);
- Named named = clazz.getAnnotation(Named.class);
+ return getBeanName(clazz, clazz);
+ }
+
+ public static String getBeanName(Class<?> clazz, AnnotatedElement annotatedElement) {
+ Component component = annotatedElement.getAnnotation(Component.class);
+ Named named = annotatedElement.getAnnotation(Named.class);
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);
+ if (template.id != null) {
+ return template.id.equals(id);
+ }
return assignable && qualifiers.values().containsAll(template.qualifiers.values());
}
@@ -67,9 +106,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/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Context.java Wed Jun 15 19:23:47 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,35 @@
*/
package org.apache.aries.blueprint.plugin.model;
+import org.apache.aries.blueprint.plugin.model.service.ServiceProvider;
+import org.ops4j.pax.cdi.api.OsgiService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.blueprint.container.BlueprintContainer;
+import org.osgi.service.blueprint.container.Converter;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+import javax.inject.Singleton;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
-import javax.enterprise.inject.Produces;
-
-import org.ops4j.pax.cdi.api.OsgiService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.blueprint.container.BlueprintContainer;
-import org.osgi.service.blueprint.container.Converter;
-
public class Context implements Matcher {
- SortedSet<BeanRef> reg;
+ SortedSet<BeanRef> reg = new TreeSet<BeanRef>();
+ private final List<ServiceProvider> serviceProviders = new ArrayList<>();
public Context(Class<?>... beanClasses) {
this(Arrays.asList(beanClasses));
}
public Context(Collection<Class<?>> beanClasses) {
- this.reg = new TreeSet<BeanRef>();
addBlueprintRefs();
addBeans(beanClasses);
}
@@ -64,16 +68,35 @@ public class Context implements Matcher
Bean bean = new Bean(clazz);
reg.add(bean);
addServiceRefs(clazz);
- addProducedBeans(clazz, bean);
+ addProducedBeans(bean);
+ addServiceProviders(bean);
+ }
+
+ private void addServiceProviders(Bean bean) {
+ serviceProviders.addAll(bean.serviceProviders);
}
- private void addProducedBeans(Class<?> clazz, BeanRef factoryBean) {
- for (Method method : clazz.getMethods()) {
+ private void addProducedBeans(BeanRef factoryBean) {
+ for (Method method : factoryBean.clazz.getMethods()) {
Produces produces = method.getAnnotation(Produces.class);
+ Named named = method.getAnnotation(Named.class);
+ Singleton singleton = method.getAnnotation(Singleton.class);
if (produces != null) {
Class<?> producedClass = method.getReturnType();
- ProducedBean producedBean = new ProducedBean(producedClass, factoryBean, method.getName());
+ ProducedBean producedBean;
+ if (named != null) {
+ producedBean = new ProducedBean(producedClass, named.value(), factoryBean, method);
+ } else {
+ producedBean = new ProducedBean(producedClass, factoryBean, method);
+ }
+ if (singleton != null) {
+ producedBean.setSingleton();
+ }
reg.add(producedBean);
+ ServiceProvider serviceProvider = ServiceProvider.fromMethod(producedBean, method);
+ if (serviceProvider != null) {
+ serviceProviders.add(serviceProvider);
+ }
}
}
}
@@ -82,14 +105,22 @@ public class Context implements Matcher
for (Field field : new Introspector(clazz).fieldsWith(OsgiService.class)) {
reg.add(new OsgiServiceRef(field));
}
+ for (Method method : new Introspector(clazz).methodsWith(OsgiService.class)) {
+ reg.add(new OsgiServiceRef(method));
+ }
}
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)) {
@@ -103,7 +134,7 @@ public class Context implements Matcher
TreeSet<Bean> beans = new TreeSet<Bean>();
for (BeanRef ref : reg) {
if (ref instanceof Bean) {
- beans.add((Bean)ref);
+ beans.add((Bean) ref);
}
}
return beans;
@@ -113,10 +144,13 @@ public class Context implements Matcher
TreeSet<OsgiServiceRef> serviceRefs = new TreeSet<OsgiServiceRef>();
for (BeanRef ref : reg) {
if (ref instanceof OsgiServiceRef) {
- serviceRefs.add((OsgiServiceRef)ref);
+ serviceRefs.add((OsgiServiceRef) ref);
}
}
return serviceRefs;
}
+ public List<ServiceProvider> getServiceProviders() {
+ return serviceProviders;
+ }
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Introspector.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Introspector.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Introspector.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Introspector.java Wed Jun 15 19:23:47 2016
@@ -18,6 +18,13 @@
*/
package org.apache.aries.blueprint.plugin.model;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Sets;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -26,13 +33,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
-
/**
* Class to find uniquely-named fields declared in a class hierarchy with specified annotations.
*/
@@ -47,7 +47,7 @@ public final class Introspector {
}
/**
- * @param
+ * @param requiredAnnotations annotations the fields must have
* @return fields in the given class (including parent classes) that match this finder's annotations requirements.
* @throws UnsupportedOperationException if any field matching the annotations requirement shares its name with a
* field declared elsewhere in the class hierarchy.
@@ -84,7 +84,6 @@ public final class Introspector {
/**
* Check that each field name is defined no more than once
- * @param originalClazz
* @param acceptedFieldName
* @param acceptedFieldsWithSameName
*/
@@ -122,12 +121,15 @@ public final class Introspector {
return Iterables.getOnlyElement(methods, null);
}
- public <T extends Annotation> List<Method> methodsWith(Class<T> annotationClass) {
+ @SafeVarargs
+ public final List<Method> methodsWith(Class<? extends Annotation>... annotationClasses) {
List<Method> methods = new ArrayList<>();
for (Method method : originalClazz.getMethods()) {
- T annotation = method.getAnnotation(annotationClass);
- if (annotation != null) {
- methods.add(method);
+ for(Class<? extends Annotation> annotationClass : annotationClasses) {
+ if (method.getAnnotation(annotationClass) != null) {
+ methods.add(method);
+ break;
+ }
}
}
return methods;
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Matcher.java Wed Jun 15 19:23:47 2016
@@ -18,8 +18,6 @@
*/
package org.apache.aries.blueprint.plugin.model;
-
-
public interface Matcher {
BeanRef getMatching(BeanRef template);
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/OsgiServiceRef.java Wed Jun 15 19:23:47 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,25 +18,78 @@
*/
package org.apache.aries.blueprint.plugin.model;
-import java.lang.reflect.Field;
-
import org.ops4j.pax.cdi.api.OsgiService;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Named;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
/**
* Synthetic bean that refers to an OSGi service
*/
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();
- id = getBeanName(clazz);
- if (filter != null) {
- id = id + "-" + getId(filter);
+ ServiceFilter serviceFilter = extractServiceFilter(field);
+ filter = serviceFilter.filter;
+ compName = serviceFilter.compName;
+ id = generateReferenceId(field);
+ }
+
+ private String generateReferenceId(AnnotatedElement annotatedElement) {
+ String prefix = getBeanName(clazz, annotatedElement);
+ String suffix = createIdSuffix(annotatedElement);
+ return prefix + suffix;
+ }
+
+ private String createIdSuffix(AnnotatedElement annotatedElement) {
+ if (shouldAddSuffix(annotatedElement)) {
+ if (filter != null) {
+ return "-" + getId(filter);
+ }
+ if (compName != null) {
+ return "-" + compName;
+ }
}
+ return "";
+ }
+
+ private boolean shouldAddSuffix(AnnotatedElement annotatedElement) {
+ Component component = annotatedElement.getAnnotation(Component.class);
+ Named named = annotatedElement.getAnnotation(Named.class);
+ return (component == null || "".equals(component.value())) &&
+ (named == null || "".equals(named.value()));
+ }
+
+ public OsgiServiceRef(Method method) {
+ super(method);
+ ServiceFilter serviceFilter = extractServiceFilter(method);
+ filter = serviceFilter.filter;
+ compName = serviceFilter.compName;
+ id = generateReferenceId(method);
+ }
+
+ private ServiceFilter extractServiceFilter(AnnotatedElement annotatedElement) {
+ OsgiService osgiService = annotatedElement.getAnnotation(OsgiService.class);
+ return extractServiceFilter(osgiService);
+ }
+
+ private ServiceFilter extractServiceFilter(OsgiService osgiService) {
+ String filterValue = osgiService.filter();
+ return new ServiceFilter(filterValue);
+ }
+
+ public OsgiServiceRef(Class<?> clazz, OsgiService osgiService, String name) {
+ super(clazz, name);
+ ServiceFilter serviceFilter = extractServiceFilter(osgiService);
+ filter = serviceFilter.filter;
+ compName = serviceFilter.compName;
}
private String getId(String raw) {
@@ -50,4 +103,21 @@ public class OsgiServiceRef extends Bean
return builder.toString();
}
+ private static class ServiceFilter {
+ final public String filter;
+ final public String compName;
+
+ public ServiceFilter(String filterValue) {
+ if (filterValue == null) {
+ filter = null;
+ compName = null;
+ } else if (filterValue.contains("(")) {
+ filter = filterValue;
+ compName = null;
+ } else {
+ filter = null;
+ compName = filterValue;
+ }
+ }
+ }
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java Wed Jun 15 19:23:47 2016
@@ -1,14 +1,69 @@
+/**
+ * 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.model;
+import org.apache.aries.blueprint.plugin.Activation;
+
+import java.lang.reflect.Method;
+
public class ProducedBean extends Bean {
public String factoryMethod;
public BeanRef factoryBean;
-
- public ProducedBean(Class<?> clazz, BeanRef factoryBean, String factoryMethod) {
+ private Method producingMethod;
+
+ public ProducedBean(Class<?> clazz, BeanRef factoryBean, Method factoryMethod) {
+ this(clazz, null, factoryBean,factoryMethod);
+ }
+
+ public ProducedBean(Class<?> clazz, String id, BeanRef factoryBean, Method factoryMethod) {
super(clazz);
+ if(id != null) {
+ this.id = id;
+ }
this.factoryBean = factoryBean;
- this.factoryMethod = factoryMethod;
+ this.factoryMethod = factoryMethod.getName();
+ this.producingMethod = factoryMethod;
+ overrideActivationIfNeeded(factoryMethod);
+ overrideDependsOnIfNeeded(factoryMethod);
+ }
+
+ private void overrideActivationIfNeeded(Method factoryMethod) {
+ Activation methodActivation = getActivation(factoryMethod);
+ if (methodActivation != null) {
+ this.activation = methodActivation;
+ }
+ }
+
+ private void overrideDependsOnIfNeeded(Method factoryMethod) {
+ String dependsOn = getDependsOn(factoryMethod);
+ if (dependsOn != null) {
+ this.dependsOn = dependsOn;
+ }
}
+ public void setSingleton() {
+ this.isPrototype = false;
+ }
+
+ @Override
+ protected void resolveArguments(Matcher matcher) {
+ resolveArguments(matcher, producingMethod.getParameterTypes(), producingMethod.getParameterAnnotations());
+ }
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Property.java Wed Jun 15 19:23:47 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,24 +18,27 @@
*/
package org.apache.aries.blueprint.plugin.model;
-import java.lang.reflect.Field;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
public class Property implements Comparable<Property> {
- public String name;
- public String ref;
- public String value;
+ public final String name;
+ public final String ref;
+ public final String value;
+ public final boolean isField;
- public Property(String name, String ref, String value) {
+ public Property(String name, String ref, String value, boolean isField) {
this.name = name;
this.ref = ref;
this.value = value;
+ this.isField = isField;
}
public static Property create(Matcher matcher, Field field) {
@@ -43,15 +46,44 @@ public class Property implements Compara
if (needsInject(field)) {
BeanRef matching = matcher.getMatching(new BeanRef(field));
String ref = (matching == null) ? getRefName(field) : matching.id;
- return new Property(field.getName(), ref, null);
- } else if (value != null){
- return new Property(field.getName(), null, cleanValue(value.value()));
+ return new Property(field.getName(), ref, null, true);
+ } else if (value != null) {
+ return new Property(field.getName(), null, cleanValue(value.value()), true);
} else {
// Field is not a property
return null;
}
}
+ public static Property create(Matcher matcher, Method method) {
+ String propertyName = resolveProperty(method);
+ if (propertyName == null) {
+ return null;
+ }
+
+ Value value = method.getAnnotation(Value.class);
+ if (value != null) {
+ return new Property(propertyName, null, cleanValue(value.value()), false);
+ }
+
+ if (needsInject(method)) {
+ BeanRef beanRef = new BeanRef(method);
+ BeanRef matching = matcher.getMatching(beanRef);
+ String ref = (matching == null) ? beanRef.id : matching.id;
+ return new Property(propertyName, ref, null, false);
+ }
+
+ return null;
+ }
+
+ private static String resolveProperty(Method method) {
+ if (method.getParameterTypes().length != 1) {
+ return null;
+ }
+ String propertyName = method.getName().substring(3);
+ return makeFirstLetterLower(propertyName);
+ }
+
/**
* Assume it is defined in another manually created blueprint context with default name
* @param field
@@ -62,20 +94,20 @@ public class Property implements Compara
if (named != null) {
return named.value();
}
- Qualifier qualifier = field.getAnnotation(Qualifier.class);
+ Qualifier qualifier = field.getAnnotation(Qualifier.class);
if (qualifier != null) {
return qualifier.value();
}
return Bean.getBeanName(field.getType());
}
- private static boolean needsInject(Field field) {
- return field.getAnnotation(Autowired.class) != null || field.getAnnotation(Inject.class) != null;
+ private static boolean needsInject(AnnotatedElement annotatedElement) {
+ return annotatedElement.getAnnotation(Autowired.class) != null || annotatedElement.getAnnotation(Inject.class) != null;
}
/**
* Remove default value definition
- *
+ *
* @param value
* @return
*/
@@ -88,4 +120,7 @@ public class Property implements Compara
return name.compareTo(other.name);
}
+ private static String makeFirstLetterLower(String name) {
+ return name.substring(0, 1).toLowerCase() + name.substring(1, name.length());
+ }
}
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java Wed Jun 15 19:23:47 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,69 +18,76 @@
*/
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;
+import org.apache.aries.blueprint.plugin.test.MyProduced;
import org.apache.aries.blueprint.plugin.test.ServiceA;
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();
Set<String> namespaces = new HashSet<String>(Arrays.asList(Generator.NS_JPA, Generator.NS_TX));
- new Generator(context, os, namespaces).generate();
+ new Generator(context, os, namespaces, null).generate();
System.out.println(os.toString("UTF-8"));
document = readToDocument(os);
xpath = XPathFactory.newInstance().newXPath();
- //xpath.setNamespaceContext(new NameSpaces(document));
- Node bean1 = (Node) xpath.evaluate("/blueprint/bean[@id='myBean1']", document, XPathConstants.NODE);
+ }
+
+ @Test
+ public void testGenerateBeanWithInitDestroyAndfieldInjection() throws Exception {
+ Node bean1 = getBeanById("myBean1");
- // 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));
+ assertXpathEquals(bean1, "@class", MyBean1.class.getName());
+ assertXpathEquals(bean1, "@init-method", "init");
+ assertXpathEquals(bean1, "@destroy-method", "destroy");
+ assertXpathEquals(bean1, "@field-injection", "true");
+ assertXpathDoesNotExist(bean1, "@scope");
+ }
+
+ @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 +95,60 @@ 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");
+
+ assertXpathEquals(bean1, "context/@unitname", "person");
+ assertXpathEquals(bean1, "context/@property", "em");
+ }
+
+ @Test
+ public void testGeneratePersistenceUnit() throws Exception {
+ Node bean1 = getBeanById("myBean1");
+
+ assertXpathEquals(bean1, "unit/@unitname", "person");
+ assertXpathEquals(bean1, "unit/@property", "emf");
+ }
+
+ @Test
+ public void testGenerateAutowiredBean() throws Exception {
+ Node bean1 = getBeanById("myBean1");
+
+ assertXpathEquals(bean1, "property[@name='bean2']/@ref", "my1");
+ }
+
+ @Test
+ public void testGenerateServiceWithOneInterface() throws Exception {
+ Node serviceAImpl2 = getServiceByRef("my2");
+ assertXpathEquals(serviceAImpl2, "@interface", ServiceA.class.getName());
+ assertXpathDoesNotExist(serviceAImpl2, "@auto-export");
+ assertXpathDoesNotExist(serviceAImpl2, "interfaces");
+ }
+
+ @Test
+ public void testGenerateServiceWithAutoExport() throws Exception {
+ Node serviceAImpl3 = getServiceByRef("serviceAImpl3");
+ assertXpathDoesNotExist(serviceAImpl3, "@interface");
+ assertXpathEquals(serviceAImpl3, "@auto-export", "interfaces");
+ assertXpathDoesNotExist(serviceAImpl3, "interfaces");
+ }
+
+ @Test
+ public void testGenerateServiceWith2Interfaces() throws Exception {
+ Node serviceABImpl = getServiceByRef("serviceABImpl");
+
+ assertXpathDoesNotExist(serviceABImpl, "@interface");
+ assertXpathDoesNotExist(serviceABImpl, "@auto-export");
NodeList interfaceValues = (NodeList) xpath.evaluate("interfaces/value", serviceABImpl, XPathConstants.NODESET);
Set<String> interfaceNames = new HashSet<String>();
@@ -130,11 +156,226 @@ 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");
+ assertXpathDoesNotExist(myBean5, "@field-injection");
+ assertXpathEquals(myBean5, "argument[1]/@ref", "my2");
+ assertXpathEquals(myBean5, "argument[2]/@ref", "my1");
+ assertXpathEquals(myBean5, "argument[3]/@ref", "serviceABImpl");
+ assertXpathEquals(myBean5, "argument[4]/@value", "100");
+ assertXpathEquals(myBean5, "argument[5]/@ref", "ser1");
+ assertXpathEquals(myBean5, "argument[6]/@ref", "ser2");
+ assertXpathEquals(myBean5, "argument[7]/@ref", "serviceAImplQualified");
+ }
+
+ @Test
+ public void testGenerateBeanWithConstructorInjectionWithoutInjectAnnotation() throws Exception {
+ // Bean with constructor injection
+ Node myBean6 = getBeanById("myBean6");
+ assertXpathEquals(myBean6, "argument[1]/@ref", "my2");
+ }
+
+ @Test
+ public void testGenerateReferenceWithComponentName() throws Exception {
+ Node ser1 = getReferenceById("ser1");
+ assertXpathEquals(ser1, "@component-name", "myRef");
+ assertXpathDoesNotExist(ser1, "@filter");
+ }
+
+ @Test
+ public void testGenerateReferenceWithFilter() throws Exception {
+ Node ser2 = getReferenceById("ser2");
+ assertXpathDoesNotExist(ser2, "@component-name");
+ assertXpathEquals(ser2, "@filter", "(mode=123)");
}
- private Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException,
+ @Test
+ public void testProducesNamedBeans() throws Exception {
+ Node bean1 = getBeanById("produced1");
+ assertXpathEquals(bean1, "@class", "org.apache.aries.blueprint.plugin.test.MyProduced");
+ assertXpathEquals(bean1, "@factory-ref", "myFactoryNamedBean");
+ assertXpathEquals(bean1, "@factory-method", "createBean1");
+ assertXpathEquals(bean1, "@scope", "prototype");
+
+ Node bean2 = getBeanById("produced2");
+ assertXpathEquals(bean1, "@class", "org.apache.aries.blueprint.plugin.test.MyProduced");
+ assertXpathEquals(bean2, "@factory-ref", "myFactoryNamedBean");
+ assertXpathEquals(bean2, "@factory-method", "createBean2");
+ assertXpathDoesNotExist(bean2, "@scope");
+
+ Node myBean5 = getBeanById("myBean5");
+ assertXpathEquals(myBean5, "argument[8]/@ref", "produced2");
+ }
+
+ @Test
+ public void testProducesBeanUsingParametersNotConstructor() throws Exception {
+ Node bean1 = getBeanById("myProducedWithConstructor");
+ assertXpathEquals(bean1, "@class", "org.apache.aries.blueprint.plugin.test.MyProducedWithConstructor");
+ assertXpathEquals(bean1, "@factory-ref", "myFactoryBean");
+ assertXpathEquals(bean1, "@factory-method", "createBeanWithParameters");
+ assertXpathEquals(bean1, "argument[1]/@ref", "myBean1");
+ assertXpathEquals(bean1, "argument[2]/@value", "100");
+ assertXpathEquals(bean1, "argument[3]/@ref", "ser1");
+ }
+
+ @Test
+ public void testExposeProducedBeanAsServiceWithAutoExport() throws Exception {
+ Node service = getServiceByRef("producedForService");
+ assertXpathEquals(service, "@auto-export", "interfaces");
+ assertXpathDoesNotExist(service, "@interface");
+ assertXpathDoesNotExist(service, "interfaces");
+ assertXpathDoesNotExist(service, "service-properties");
+ }
+
+ @Test
+ public void testExposeProducedBeanAsServiceWithOneInterface() throws Exception {
+ Node service = getServiceByRef("producedForServiceWithOneInterface");
+ assertXpathDoesNotExist(service, "@auto-export");
+ assertXpathEquals(service, "@interface", MyProduced.class.getName());
+ assertXpathDoesNotExist(service, "interfaces");
+ assertXpathDoesNotExist(service, "service-properties");
+ }
+
+ @Test
+ public void testExposeProducedBeanAsServiceWithTwoInterfaces() throws Exception {
+ Node service = getServiceByRef("producedForServiceWithTwoInterfaces");
+ assertXpathDoesNotExist(service, "@auto-export");
+ assertXpathDoesNotExist(service, "@interface");
+ assertXpathEquals(service, "count(interfaces/value)", "2");
+ assertXpathEquals(service, "interfaces/value[1]", MyProduced.class.getName());
+ assertXpathEquals(service, "interfaces/value[2]", ServiceA.class.getName());
+ assertXpathDoesNotExist(service, "service-properties");
+ }
+
+ @Test
+ public void testExposeProducedBeanAsServiceWithServiceProperties() throws Exception {
+ Node service = getServiceByRef("producedForServiceWithProperties");
+ assertXpathEquals(service, "@auto-export", "interfaces");
+ assertXpathDoesNotExist(service, "@interface");
+ assertXpathDoesNotExist(service, "interfaces");
+ assertXpathEquals(service, "count(service-properties/entry)", "2");
+ assertXpathEquals(service, "service-properties/entry[@key='n1']/@value", "v1");
+ assertXpathEquals(service, "service-properties/entry[@key='n2']/@value", "v2");
+ }
+
+ @Test
+ public void testSetterInjection() throws Exception {
+ Node bean1 = getBeanById("beanWithSetters");
+ assertXpathDoesNotExist(bean1, "@field-injection");
+
+ assertXpathDoesNotExist(bean1, "property[@name='useless']");
+ assertXpathDoesNotExist(bean1, "property[@name='iOnlyHaveSetPrefix']");
+ assertXpathDoesNotExist(bean1, "property[@name='ihaveMoreThenOneParameter']");
+ assertXpathDoesNotExist(bean1, "property[@name='iOnlyHaveSetPrefixValue']");
+ assertXpathDoesNotExist(bean1, "property[@name='ihaveMoreThenOneParameterValue']");
+
+ assertXpathEquals(bean1, "property[@name='myValue']/@value", "test");
+ assertXpathEquals(bean1, "property[@name='serviceA1']/@ref", "my1");
+ assertXpathEquals(bean1, "property[@name='serviceA2']/@ref", "my1");
+ assertXpathEquals(bean1, "property[@name='serviceB']/@ref", "serviceABImpl");
+ assertXpathEquals(bean1, "property[@name='serviceB2']/@ref", "serviceB2Id");
+ assertXpathEquals(bean1, "property[@name='serviceBRef']/@ref", "serviceB-typeB1Ref");
+ assertXpathEquals(bean1, "property[@name='serviceB2Ref']/@ref", "serviceB2IdRef");
+ assertXpathEquals(bean1, "property[@name='serviceB3Ref']/@ref", "serviceB-B3Ref");
+
+ Node reference1 = getReferenceById("serviceB-typeB1Ref");
+ assertXpathEquals(reference1, "@interface", ServiceB.class.getName());
+ assertXpathEquals(reference1, "@filter", "(type=B1Ref)");
+
+ Node reference2 = getReferenceById("serviceB2IdRef");
+ assertXpathEquals(reference2, "@interface", ServiceB.class.getName());
+ assertXpathEquals(reference2, "@filter", "(type=B2Ref)");
+
+ Node reference3 = getReferenceById("serviceB-B3Ref");
+ assertXpathEquals(reference3, "@interface", ServiceB.class.getName());
+ assertXpathEquals(reference3, "@component-name", "B3Ref");
+ }
+
+ @Test
+ public void testLazyWithTrueBeanHasActivationEager() throws Exception {
+ Node bean = getBeanById("beanWithSetters");
+
+ assertXpathEquals(bean, "@activation", "eager");
+ }
+
+ @Test
+ public void testLazyBeanHasActivationLazy() throws Exception {
+ Node bean = getBeanById("myBean1");
+
+ assertXpathEquals(bean, "@activation", "lazy");
+ }
+
+ @Test
+ public void testBeanWithoutLazyAnnotationHasNotActivationAttribute() throws Exception {
+ Node bean1 = getBeanById("myBean3");
+
+ assertXpathDoesNotExist(bean1, "@activation");
+ }
+
+ @Test
+ public void testLazyProducedBeanOverriddenByFactoryMethodAnnotation() throws Exception {
+ Node bean = getBeanById("producedEager");
+
+ assertXpathEquals(bean, "@activation", "eager");
+ }
+
+ @Test
+ public void testBeanWithoutDependsOnHasNotDependsOnAttribute() throws Exception {
+ Node bean = getBeanById("beanWithSetters");
+
+ assertXpathDoesNotExist(bean, "@depends-on");
+ }
+
+ @Test
+ public void testBeanWithEmptyDependsOnHasNotDependsOnAttribute() throws Exception {
+ Node bean = getBeanById("myBean6");
+
+ assertXpathDoesNotExist(bean, "@depends-on");
+ }
+
+ @Test
+ public void testBeanWithOneIdInDependsOnHasDependsOnAttribute() throws Exception {
+ Node bean = getBeanById("myBean5");
+
+ assertXpathEquals(bean, "@depends-on", "myBean6");
+ }
+
+ @Test
+ public void testBeanWithTwoIdInDependsOnHasDependsOnAttribute() throws Exception {
+ Node bean = getBeanById("myBean4");
+
+ assertXpathEquals(bean, "@depends-on", "myBean5 myBean6");
+ }
+
+ @Test
+ public void testProducedBeanMetohodWithoutDependsOnHasNotDependsOnAttribute() throws Exception {
+ Node bean = getBeanById("produced1");
+
+ assertXpathDoesNotExist(bean, "@depends-on");
+ }
+
+ @Test
+ public void testProducedBeanMethodWithDependsOnHasDependsOnAttribute() throws Exception {
+ Node bean = getBeanById("produced2");
+
+ assertXpathEquals(bean, "@depends-on", "produced1");
+ }
+
+ private void assertXpathDoesNotExist(Node node, String xpathExpression) throws XPathExpressionException {
+ assertXpathEquals(node, "count(" + xpathExpression + ")", "0");
+ }
+
+ private void assertXpathEquals(Node node, String xpathExpression, String expected) throws XPathExpressionException {
+ assertEquals(expected, xpath.evaluate(xpathExpression, node));
+ }
+
+ private static Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException,
SAXException, IOException {
InputStream is = new ByteArrayInputStream(os.toByteArray());
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
@@ -142,4 +383,16 @@ public class GeneratorTest {
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/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean1.java Wed Jun 15 19:23:47 2016
@@ -1,3 +1,21 @@
+/**
+ * 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.bad;
import javax.inject.Inject;
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean2.java Wed Jun 15 19:23:47 2016
@@ -1,3 +1,21 @@
+/**
+ * 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.bad;
import javax.inject.Inject;
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/BadFieldBean3.java Wed Jun 15 19:23:47 2016
@@ -1,3 +1,21 @@
+/**
+ * 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.bad;
import javax.inject.Singleton;
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/FieldBean4.java Wed Jun 15 19:23:47 2016
@@ -1,3 +1,21 @@
+/**
+ * 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.bad;
import javax.inject.Singleton;
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithField.java Wed Jun 15 19:23:47 2016
@@ -1,3 +1,21 @@
+/**
+ * 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.bad;
import org.apache.aries.blueprint.plugin.test.MyBean1;
Modified: aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java
URL: http://svn.apache.org/viewvc/aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java?rev=1748624&r1=1748623&r2=1748624&view=diff
==============================================================================
--- aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java (original)
+++ aries/branches/java6support/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/bad/ParentWithInjectedField.java Wed Jun 15 19:23:47 2016
@@ -1,3 +1,21 @@
+/**
+ * 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.bad;
import javax.inject.Inject;