aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1747457 - 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...
Date Wed, 08 Jun 2016 21:35:06 GMT
Author: alien11689
Date: Wed Jun  8 21:35:06 2016
New Revision: 1747457

URL: http://svn.apache.org/viewvc?rev=1747457&view=rev
Log:
[ARIES-1568] Support @DependsOn annotation

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/model/Bean.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.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/test/MyBean4.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/MyBean6.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryNamedBean.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=1747457&r1=1747456&r2=1747457&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
Wed Jun  8 21:35:06 2016
@@ -156,6 +156,9 @@ public class Generator implements Proper
         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);
         }

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=1747457&r1=1747456&r2=1747457&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
Wed Jun  8 21:35:06 2016
@@ -20,9 +20,11 @@ package org.apache.aries.blueprint.plugi
 
 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;
 
@@ -56,12 +58,15 @@ public class Bean extends BeanRef {
     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);
 
         activation = getActivation(clazz);
+        dependsOn = getDependsOn(clazz);
+
         initMethod = findMethodAnnotatedWith(introspector, PostConstruct.class);
         destroyMethod = findMethodAnnotatedWith(introspector, PreDestroy.class);
 
@@ -75,6 +80,15 @@ public class Bean extends BeanRef {
         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, " ");
+    }
+
     protected Activation getActivation(AnnotatedElement annotatedElement) {
         Lazy lazy = annotatedElement.getAnnotation(Lazy.class);
         if (lazy == null) {

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java?rev=1747457&r1=1747456&r2=1747457&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ProducedBean.java
Wed Jun  8 21:35:06 2016
@@ -29,20 +29,19 @@ public class ProducedBean extends Bean {
     private Method producingMethod;
 
     public ProducedBean(Class<?> clazz, BeanRef factoryBean, Method factoryMethod)
{
-        super(clazz);
-        this.factoryBean = factoryBean;
-        this.factoryMethod = factoryMethod.getName();
-        this.producingMethod = factoryMethod;
-        overrideActivationIfNeeded(factoryMethod);
+        this(clazz, null, factoryBean,factoryMethod);
     }
 
     public ProducedBean(Class<?> clazz, String id, BeanRef factoryBean, Method factoryMethod)
{
         super(clazz);
-        this.id = id;
+        if(id != null) {
+            this.id = id;
+        }
         this.factoryBean = factoryBean;
         this.factoryMethod = factoryMethod.getName();
         this.producingMethod = factoryMethod;
         overrideActivationIfNeeded(factoryMethod);
+        overrideDependsOnIfNeeded(factoryMethod);
     }
 
     private void overrideActivationIfNeeded(Method factoryMethod) {
@@ -52,6 +51,13 @@ public class ProducedBean extends Bean {
         }
     }
 
+    private void overrideDependsOnIfNeeded(Method factoryMethod) {
+        String dependsOn = getDependsOn(factoryMethod);
+        if (dependsOn != null) {
+            this.dependsOn = dependsOn;
+        }
+    }
+
     public void setSingleton() {
         this.isPrototype = false;
     }

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=1747457&r1=1747456&r2=1747457&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
Wed Jun  8 21:35:06 2016
@@ -325,6 +325,48 @@ public class GeneratorTest {
         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");
     }

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java?rev=1747457&r1=1747456&r2=1747457&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean4.java
Wed Jun  8 21:35:06 2016
@@ -18,14 +18,16 @@
  */
 package org.apache.aries.blueprint.plugin.test;
 
-import javax.inject.Inject;
-
 import org.osgi.framework.BundleContext;
+import org.springframework.context.annotation.DependsOn;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.inject.Inject;
+
 @Component
+@DependsOn({"myBean5", "myBean6"})
 public class MyBean4 {
 
     @Inject

Modified: 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=1747457&r1=1747456&r2=1747457&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean5.java
Wed Jun  8 21:35:06 2016
@@ -21,12 +21,14 @@ package org.apache.aries.blueprint.plugi
 import org.apache.aries.blueprint.plugin.AnnotatedService;
 import org.ops4j.pax.cdi.api.OsgiService;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.DependsOn;
 
 import javax.inject.Inject;
 import javax.inject.Named;
 import javax.inject.Singleton;
 
 @Singleton
+@DependsOn("myBean6")
 public class MyBean5 {
 
     ServiceA serviceA1;

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java?rev=1747457&r1=1747456&r2=1747457&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean6.java
Wed Jun  8 21:35:06 2016
@@ -18,10 +18,13 @@
  */
 package org.apache.aries.blueprint.plugin.test;
 
+import org.springframework.context.annotation.DependsOn;
+
 import javax.inject.Named;
 import javax.inject.Singleton;
 
 @Singleton
+@DependsOn
 public class MyBean6 {
 
     private final ServiceA serviceA1;

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryNamedBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryNamedBean.java?rev=1747457&r1=1747456&r2=1747457&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryNamedBean.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryNamedBean.java
Wed Jun  8 21:35:06 2016
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.blueprint.plugin.test;
 
+import org.springframework.context.annotation.DependsOn;
 import org.springframework.context.annotation.Lazy;
 
 import javax.enterprise.inject.Produces;
@@ -36,6 +37,7 @@ public class MyFactoryNamedBean {
     @Produces
     @Named("produced2")
     @Singleton
+    @DependsOn("produced1")
     public MyProduced createBean2() {
         return new MyProduced("My message");
     }



Mime
View raw message