aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1775285 - in /aries/trunk/blueprint/plugin/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/pax/ test/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/blueprint/plugin/test/
Date Tue, 20 Dec 2016 12:41:01 GMT
Author: alien11689
Date: Tue Dec 20 12:41:01 2016
New Revision: 1775285

URL: http://svn.apache.org/viewvc?rev=1775285&view=rev
Log:
[ARIES-1641] Read service.ranking property as ranking attribute in service element, This closes
#60

Modified:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/pax/OsgiServiceProviderHandler.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryBeanAsService.java

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/pax/OsgiServiceProviderHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/pax/OsgiServiceProviderHandler.java?rev=1775285&r1=1775284&r2=1775285&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/pax/OsgiServiceProviderHandler.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/pax/OsgiServiceProviderHandler.java
Tue Dec 20 12:41:01 2016
@@ -31,11 +31,15 @@ import org.ops4j.pax.cdi.api.Property;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 import java.lang.reflect.AnnotatedElement;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 public class OsgiServiceProviderHandler implements BeanAnnotationHandler<OsgiServiceProvider>
{
+
+    private static final List<String> SPECIAL_PROPERTIES = Collections.singletonList("service.ranking");
+
     @Override
     public Class<OsgiServiceProvider> getAnnotation() {
         return OsgiServiceProvider.class;
@@ -83,6 +87,7 @@ public class OsgiServiceProviderHandler
         }
 
         if (!propertiesAsMap.isEmpty()) {
+            writeRanking(writer, propertiesAsMap);
             writeProperties(writer, propertiesAsMap);
         }
 
@@ -126,16 +131,29 @@ public class OsgiServiceProviderHandler
         writer.writeCharacters("\n");
     }
 
+    private void writeRanking(XMLStreamWriter writer, Map<String, String> propertiesAsMap)
throws XMLStreamException {
+        if (propertiesAsMap.containsKey("service.ranking")) {
+            try {
+                Integer ranking = Integer.parseInt(propertiesAsMap.get("service.ranking"));
+                writer.writeAttribute("ranking", ranking.toString());
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException("service.ranking property must be an integer!");
+            }
+        }
+    }
+
     private void writeProperties(XMLStreamWriter writer, Map<String, String> properties)
throws XMLStreamException {
         writer.writeCharacters("    ");
         writer.writeStartElement("service-properties");
         writer.writeCharacters("\n");
         for (Map.Entry<String, String> property : properties.entrySet()) {
-            writer.writeCharacters("        ");
-            writer.writeEmptyElement("entry");
-            writer.writeAttribute("key", property.getKey());
-            writer.writeAttribute("value", property.getValue());
-            writer.writeCharacters("\n");
+            if (!SPECIAL_PROPERTIES.contains(property.getKey())) {
+                writer.writeCharacters("        ");
+                writer.writeEmptyElement("entry");
+                writer.writeAttribute("key", property.getKey());
+                writer.writeAttribute("value", property.getValue());
+                writer.writeCharacters("\n");
+            }
         }
         writer.writeCharacters("    ");
         writer.writeEndElement();

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java?rev=1775285&r1=1775284&r2=1775285&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java
Tue Dec 20 12:41:01 2016
@@ -191,6 +191,18 @@ public class GeneratorTest {
     }
 
     @Test
+    public void testGenerateServiceWithRanking() throws Exception {
+        Node serviceWithRanking = getServiceByRef("serviceWithRanking");
+
+        assertXpathDoesNotExist(serviceWithRanking, "@interface");
+        assertXpathEquals(serviceWithRanking, "@auto-export", "interfaces");
+        assertXpathDoesNotExist(serviceWithRanking, "interfaces");
+        assertXpathEquals(serviceWithRanking, "@ranking", "100");
+        assertXpathEquals(serviceWithRanking, "count(service-properties/entry)", "0");
+        assertXpathDoesNotExist(serviceWithRanking, "service-properties/entry[@key='service.ranking']");
+    }
+
+    @Test
     public void testGenerateBeanWithConstructorInjection() throws Exception {
         // Bean with constructor injection
         Node myBean5 = getBeanById("myBean5");
@@ -289,9 +301,11 @@ public class GeneratorTest {
         assertXpathEquals(service, "@auto-export", "interfaces");
         assertXpathDoesNotExist(service, "@interface");
         assertXpathDoesNotExist(service, "interfaces");
+        assertXpathEquals(service, "@ranking", "100");
         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");
+        assertXpathDoesNotExist(service, "service-properties/entry[@key='service.ranking']");
     }
 
     @Test

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryBeanAsService.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryBeanAsService.java?rev=1775285&r1=1775284&r2=1775285&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryBeanAsService.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyFactoryBeanAsService.java
Tue Dec 20 12:41:01 2016
@@ -54,7 +54,8 @@ public class MyFactoryBeanAsService {
     @OsgiServiceProvider
     @Properties({
         @Property(name = "n1", value = "v1"),
-        @Property(name = "n2", value = "v2")
+        @Property(name = "n2", value = "v2"),
+        @Property(name = "service.ranking", value = "100")
     })
     public MyProduced createBeanWithServiceExpose4() {
         return new MyProduced("My message");



Mime
View raw message