aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1782663 - in /aries/trunk/blueprint/plugin/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/handlers/config/ test/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/blueprint/plugin/test/
Date Sun, 12 Feb 2017 12:11:20 GMT
Author: alien11689
Date: Sun Feb 12 12:11:20 2017
New Revision: 1782663

URL: http://svn.apache.org/viewvc?rev=1782663&view=rev
Log:
[ARIES-1683] Fix placeholder-prefix and placeholder-suffix generation from Config annotation

Modified:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigAnnotationHandler.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigPropertiesHandler.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigWriter.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/BeanWithConfig.java

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigAnnotationHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigAnnotationHandler.java?rev=1782663&r1=1782662&r2=1782663&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigAnnotationHandler.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigAnnotationHandler.java
Sun Feb 12 12:11:20 2017
@@ -37,10 +37,7 @@ public class ConfigAnnotationHandler imp
     public void handleBeanAnnotation(AnnotatedElement annotatedElement, String id,
                                      ContextEnricher contextEnricher, BeanEnricher beanEnricher)
{
         Config config = annotatedElement.getAnnotation(Config.class);
-        XmlWriter writer = new ConfigWriter(config);
-        contextEnricher.addBlueprintContentWriter("config", writer);
-        contextEnricher.getBlueprintConfiguration().getNamespaces().add(ConfigWriter.CONFIG_NS);
-        
+        contextEnricher.addBlueprintContentWriter("cm/property-placeholder", new ConfigWriter(config));
     }
 
 }

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigPropertiesHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigPropertiesHandler.java?rev=1782663&r1=1782662&r2=1782663&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigPropertiesHandler.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigPropertiesHandler.java
Sun Feb 12 12:11:20 2017
@@ -73,16 +73,4 @@ public class ConfigPropertiesHandler imp
         return ConfigProperties.class;
     }
 
-    private Class<?> getClass(AnnotatedElement annotatedElement) {
-        if (annotatedElement instanceof Class<?>) {
-            return (Class<?>) annotatedElement;
-        }
-        if (annotatedElement instanceof Method) {
-            return ((Method) annotatedElement).getParameterTypes()[0];
-        }
-        if (annotatedElement instanceof Field) {
-            return ((Field) annotatedElement).getType();
-        }
-        throw new RuntimeException("Unknown annotated element");
-    }
 }

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigWriter.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigWriter.java?rev=1782663&r1=1782662&r2=1782663&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigWriter.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/handlers/config/ConfigWriter.java
Sun Feb 12 12:11:20 2017
@@ -6,9 +6,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,19 +18,19 @@
  */
 package org.apache.aries.blueprint.plugin.handlers.config;
 
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
-
 import org.apache.aries.blueprint.annotation.config.Config;
 import org.apache.aries.blueprint.annotation.config.DefaultProperty;
 import org.apache.aries.blueprint.plugin.spi.XmlWriter;
 
-public class ConfigWriter implements XmlWriter {
-    
-    static final String CONFIG_NS = "http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0";
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+class ConfigWriter implements XmlWriter {
+
+    private static final String CONFIG_NS = "http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0";
     private Config config;
 
-    public ConfigWriter(Config config) {
+    ConfigWriter(Config config) {
         this.config = config;
     }
 
@@ -40,10 +40,10 @@ public class ConfigWriter implements Xml
         writer.writeDefaultNamespace(CONFIG_NS);
         writer.writeAttribute("persistent-id", config.pid());
         if (!"${".equals(config.placeholderPrefix())) {
-            writer.writeAttribute("placeholder-prefix", config.updatePolicy());
+            writer.writeAttribute("placeholder-prefix", config.placeholderPrefix());
         }
         if (!"}".equals(config.placeholderSuffix())) {
-            writer.writeAttribute("placeholder-suffix", config.updatePolicy());
+            writer.writeAttribute("placeholder-suffix", config.placeholderSuffix());
         }
         writer.writeAttribute("update-strategy", config.updatePolicy());
 

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java?rev=1782663&r1=1782662&r2=1782663&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java
Sun Feb 12 12:11:20 2017
@@ -769,6 +769,17 @@ public class BlueprintFileWriterTest {
         assertXpathEquals(consumer, "argument[2]/@ref", "testBean2");
     }
 
+    @Test
+    public void shouldGeneratePropertyPlaceholder() throws Exception {
+        Node propertyPlaceholder = getPropertyPlaceholderByPersistentId("org.apache.aries.my");
+        assertXpathEquals(propertyPlaceholder, "@placeholder-prefix", "$[");
+        assertXpathEquals(propertyPlaceholder, "@placeholder-suffix", "]");
+        assertXpathEquals(propertyPlaceholder, "@update-strategy", "reload");
+        assertXpathEquals(propertyPlaceholder, "count(default-properties/property)", "2");
+        assertXpathEquals(propertyPlaceholder, "default-properties/property[@name='title']/@value",
"My Title");
+        assertXpathEquals(propertyPlaceholder, "default-properties/property[@name='test2']/@value",
"v2");
+    }
+
     private void assertXpathDoesNotExist(Node node, String xpathExpression) throws XPathExpressionException
{
         assertXpathEquals(node, "count(" + xpathExpression + ")", "0");
     }
@@ -807,4 +818,7 @@ public class BlueprintFileWriterTest {
         return (Node) xpath.evaluate("/blueprint/reference-list[@id='" + id + "']", document,
XPathConstants.NODE);
     }
 
+    private static Node getPropertyPlaceholderByPersistentId(String id) throws XPathExpressionException
{
+        return (Node) xpath.evaluate("/blueprint/property-placeholder[@persistent-id='" +
id + "']", document, XPathConstants.NODE);
+    }
 }

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/BeanWithConfig.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/BeanWithConfig.java?rev=1782663&r1=1782662&r2=1782663&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/BeanWithConfig.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/BeanWithConfig.java
Sun Feb 12 12:11:20 2017
@@ -18,25 +18,22 @@
  */
 package org.apache.aries.blueprint.plugin.test;
 
-import javax.enterprise.inject.Produces;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
 import org.apache.aries.blueprint.annotation.config.Config;
-import org.apache.aries.blueprint.annotation.config.ConfigProperties;
 import org.apache.aries.blueprint.annotation.config.ConfigProperty;
 import org.apache.aries.blueprint.annotation.config.DefaultProperty;
 
-import java.util.Properties;
+import javax.enterprise.inject.Produces;
+import javax.inject.Named;
+import javax.inject.Singleton;
 
-@Config//
-( //
-    pid = "org.apache.aries.my", //
-    placeholderPrefix = "$[", //
-    placeholderSuffix = "]", //
-    defaults = { 
-                @DefaultProperty(key="title", value="My Title")
-    }
+@Config(
+        pid = "org.apache.aries.my",
+        placeholderPrefix = "$[",
+        placeholderSuffix = "]",
+        defaults = {
+                @DefaultProperty(key = "title", value = "My Title"),
+                @DefaultProperty(key = "test2", value = "v2")
+        }
 )
 @Singleton
 public class BeanWithConfig {



Mime
View raw message