aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1804251 - in /aries/trunk/blueprint/plugin: blueprint-maven-plugin-itest/src/it/simple-project/ blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/ blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/p...
Date Sun, 06 Aug 2017 18:26:33 GMT
Author: alien11689
Date: Sun Aug  6 18:26:33 2017
New Revision: 1804251

URL: http://svn.apache.org/viewvc?rev=1804251&view=rev
Log:
[ARIES-1737] Generate custom type converters in blueprint xml

Added:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/CustomTypeConverterWriter.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter1.java
      - copied, changed from r1804208, aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter2.java
Modified:
    aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/simple-project/verify.groovy
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
    aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/BlueprintFileWriterTest.java

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/simple-project/verify.groovy
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/simple-project/verify.groovy?rev=1804251&r1=1804250&r2=1804251&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/simple-project/verify.groovy
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin-itest/src/it/simple-project/verify.groovy
Sun Aug  6 18:26:33 2017
@@ -23,3 +23,4 @@ def xml = new groovy.util.XmlSlurper().p
 assert xml.name() == 'blueprint'
 assert xml.bean.find{ it.@class == 'p1.T1'}.@id == 't1'
 assert xml.bean.find{ it.@class == 'p1.T2'}.size() == 0
+assert xml.'type-converters'.size() == 0

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java?rev=1804251&r1=1804250&r2=1804251&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/Blueprint.java
Sun Aug  6 18:26:33 2017
@@ -32,12 +32,9 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
 
 public class Blueprint implements BlueprintRegistry, ContextEnricher, XmlWriter {
     private static final String NS_BLUEPRINT = "http://www.osgi.org/xmlns/blueprint/v1.0.0";
@@ -139,11 +136,16 @@ public class Blueprint implements Bluepr
 
     public void write(XMLStreamWriter writer) throws XMLStreamException {
         writeBlueprint(writer);
+        writeTypeConverters(writer);
         writeBeans(writer);
         writeCustomWriters(writer);
         writer.writeEndElement();
     }
 
+    private void writeTypeConverters(XMLStreamWriter writer) throws XMLStreamException {
+        new CustomTypeConverterWriter(beanRefStore).write(writer);
+    }
+
     private void writeCustomWriters(XMLStreamWriter writer) throws XMLStreamException {
         List<String> customWriterKeys = new ArrayList<>(customWriters.keySet());
         Collections.sort(customWriterKeys);

Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/CustomTypeConverterWriter.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/CustomTypeConverterWriter.java?rev=1804251&view=auto
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/CustomTypeConverterWriter.java
(added)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/model/CustomTypeConverterWriter.java
Sun Aug  6 18:26:33 2017
@@ -0,0 +1,57 @@
+/**
+ * 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.spi.XmlWriter;
+import org.osgi.service.blueprint.container.Converter;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+class CustomTypeConverterWriter implements XmlWriter {
+
+    private static final String defaultBlueprintConverter = "blueprintConverter";
+    private final BeanRefStore beanRefStore;
+
+    CustomTypeConverterWriter(BeanRefStore beanRefStore) {
+        this.beanRefStore = beanRefStore;
+    }
+
+    public void write(XMLStreamWriter writer) throws XMLStreamException {
+        List<BeanRef> typeConverters = beanRefStore.getAllMatching(new BeanTemplate(Converter.class,
new Annotation[0]));
+        if (hasCustomTypeConverters(typeConverters)) {
+            return;
+        }
+        writer.writeStartElement("type-converters");
+        for (BeanRef typeConverter : typeConverters) {
+            if (defaultBlueprintConverter.equals(typeConverter.id)) {
+                continue;
+            }
+            writer.writeEmptyElement("ref");
+            writer.writeAttribute("component-id", typeConverter.id);
+        }
+        writer.writeEndElement();
+    }
+
+    private boolean hasCustomTypeConverters(List<BeanRef> typeConverters) {
+        return typeConverters.isEmpty() || typeConverters.size() == 1 && "blueprintConverter".equals(typeConverters.get(0).id);
+    }
+}

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=1804251&r1=1804250&r2=1804251&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 Aug  6 18:26:33 2017
@@ -912,6 +912,14 @@ public class BlueprintFileWriterTest {
         assertXpathEquals(bean, "count(argument[7]/array/ref)", "0");
     }
 
+    @Test
+    public void shouldFindTypeConverters() throws Exception {
+        Node typeConverters = getTypeConverters();
+        assertXpathEquals(typeConverters, "count(*)", "2");
+        assertXpathEquals(typeConverters, "ref[1]/@component-id", "converter1");
+        assertXpathEquals(typeConverters, "ref[2]/@component-id", "converter2");
+    }
+
     private void assertXpathDoesNotExist(Node node, String xpathExpression) throws XPathExpressionException
{
         assertXpathEquals(node, "count(" + xpathExpression + ")", "0");
     }
@@ -934,6 +942,10 @@ public class BlueprintFileWriterTest {
         return (Node) xpath.evaluate("/blueprint/bean[@id='" + id + "']", document, XPathConstants.NODE);
     }
 
+    private static Node getTypeConverters() throws XPathExpressionException {
+        return (Node) xpath.evaluate("/blueprint/type-converters", document, XPathConstants.NODE);
+    }
+
     private static Node getCmPropertiesById(String id) throws XPathExpressionException {
         return (Node) xpath.evaluate("/blueprint/cm-properties[@id='" + id + "']", document,
XPathConstants.NODE);
     }

Copied: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter1.java
(from r1804208, aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java)
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter1.java?p2=aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter1.java&p1=aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java&r1=1804208&r2=1804251&rev=1804251&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/MyBean1.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter1.java
Sun Aug  6 18:26:33 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
@@ -16,51 +16,22 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.aries.blueprint.plugin.test;
+package org.apache.aries.blueprint.plugin.test.converters;
 
-import org.springframework.context.annotation.Lazy;
+import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.ReifiedType;
 
-import javax.annotation.PostConstruct;
 import javax.inject.Singleton;
-import javax.transaction.Transactional;
-import javax.transaction.Transactional.TxType;
 
 @Singleton
-@Transactional(value=TxType.REQUIRES_NEW)
-@Lazy
-public class MyBean1 extends ParentBean {
-
-    public void overridenInit() {
-        // By overriding the method and removing the annotation, this method has lost its
-        // @PostConstruct method because it isn't @Inherited
-    }
-
-    @PostConstruct
-    public void init() {
-
-    }
-
-    @Transactional(TxType.NOT_SUPPORTED)
-    public void txNotSupported() {
-    }
-
-    @Transactional(TxType.MANDATORY)
-    public void txMandatory() {
-    }
-
-    @Transactional(TxType.NEVER)
-    public void txNever() {
-    }
-
-    @Transactional(TxType.REQUIRED)
-    public void txRequired() {
-    }
-
+public class Converter1 implements Converter {
     @Override
-    public void txOverridenWithoutTransactional() {
+    public boolean canConvert(Object o, ReifiedType reifiedType) {
+        return false;
     }
 
-    @Transactional(TxType.REQUIRES_NEW)
-    public void txOverridenWithRequiresNew() {
+    @Override
+    public Object convert(Object o, ReifiedType reifiedType) throws Exception {
+        return null;
     }
 }

Added: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter2.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter2.java?rev=1804251&view=auto
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter2.java
(added)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/test/converters/Converter2.java
Sun Aug  6 18:26:33 2017
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.blueprint.plugin.test.converters;
+
+import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.ReifiedType;
+
+import javax.inject.Singleton;
+
+@Singleton
+public class Converter2 implements Converter {
+    @Override
+    public boolean canConvert(Object o, ReifiedType reifiedType) {
+        return false;
+    }
+
+    @Override
+    public Object convert(Object o, ReifiedType reifiedType) throws Exception {
+        return null;
+    }
+}



Mime
View raw message