aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1704273 - in /aries/trunk/blueprint/blueprint-maven-plugin/src: main/java/org/apache/aries/blueprint/plugin/ test/java/org/apache/aries/blueprint/plugin/
Date Mon, 21 Sep 2015 11:54:51 GMT
Author: cschneider
Date: Mon Sep 21 11:54:42 2015
New Revision: 1704273

URL: http://svn.apache.org/viewvc?rev=1704273&view=rev
Log:
[ARIES-1414] Allow to configure code generation based on namespaces

Modified:
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
    aries/trunk/blueprint/blueprint-maven-plugin/src/test/java/org/apache/aries/blueprint/plugin/GeneratorTest.java

Modified: aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java?rev=1704273&r1=1704272&r2=1704273&view=diff
==============================================================================
--- aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
(original)
+++ aries/trunk/blueprint/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
Mon Sep 21 11:54:42 2015
@@ -61,12 +61,11 @@ public class GenerateMojo extends Abstra
     protected List<String> scanPaths;
     
     /**
-     * true: Purely annotated mode (needs jpa 2.1.0 and transaction-blueprint 1.1.0)
-     * false: XML based mode for JPA 1.x and transaction-blueprint < 1.1.0
-     * @parameter default-value="true"
-     * @required
+     * Which extension namespaces should the plugin support
+     * 
+     * @parameter 
      */
-    protected boolean persistenceAnnotated;
+    protected Set<String> namespaces;
 
     public void execute() throws MojoExecutionException, MojoFailureException {
         try {
@@ -83,7 +82,7 @@ public class GenerateMojo extends Abstra
             Set<Class<?>> classes = FilteredClassFinder.findClasses(finder, scanPaths);
             Context context = new Context(classes);
             context.resolve();
-            new Generator(context, new FileOutputStream(file), persistenceAnnotated).generate();
+            new Generator(context, new FileOutputStream(file), namespaces).generate();
         } catch (Exception e) {
             throw new MojoExecutionException("Error building commands help", e);
         }

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=1704273&r1=1704272&r2=1704273&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
Mon Sep 21 11:54:42 2015
@@ -20,6 +20,9 @@ package org.apache.aries.blueprint.plugi
 
 import java.io.OutputStream;
 import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.persistence.PersistenceContext;
 import javax.persistence.PersistenceUnit;
@@ -29,7 +32,6 @@ import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.aries.blueprint.plugin.model.Bean;
 import org.apache.aries.blueprint.plugin.model.Context;
-import org.apache.aries.blueprint.plugin.model.OsgiServiceRef;
 import org.apache.aries.blueprint.plugin.model.ProducedBean;
 import org.apache.aries.blueprint.plugin.model.Property;
 import org.apache.aries.blueprint.plugin.model.PropertyWriter;
@@ -38,18 +40,21 @@ import org.apache.aries.blueprint.plugin
 public class Generator implements PropertyWriter {
     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";
-    private static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0";
-    private static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
-    private static final String NS_TX = "http://aries.apache.org/xmlns/transactions/v1.2.0";
-
+    public static final String NS_JPA = "http://aries.apache.org/xmlns/jpa/v1.1.0";
+    public static final String NS_JPA2 = "http://aries.apache.org/xmlns/jpa/v2.0.0";
+    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 boolean persistenceAnnotated;
+    private Set<String> namespaces;
 
-    public Generator(Context context, OutputStream os, boolean persistenceAnnotated) throws
XMLStreamException {
+    public Generator(Context context, OutputStream os, Set<String> namespaces) throws
XMLStreamException {
         this.context = context;
-        this.persistenceAnnotated = persistenceAnnotated;
-        
+        this.namespaces = namespaces;
+        if (this.namespaces == null) {
+            this.namespaces = new HashSet<String>(Arrays.asList(NS_TX2, NS_JPA2));
+        }
         XMLOutputFactory factory = XMLOutputFactory.newInstance();
         writer = factory.createXMLStreamWriter(os);
     }
@@ -61,16 +66,17 @@ public class Generator implements Proper
             writeBlueprint();
             writer.writeCharacters("\n");
             
-            if (persistenceAnnotated) {
-                if (isJpaUsed()) {
-                    writer.writeEmptyElement(NS_JPA2, "enable");
-                    writer.writeCharacters("\n");
-                }
+            if (namespaces.contains(NS_JPA2) && isJpaUsed()) {
+                writer.writeEmptyElement(NS_JPA2, "enable");
+                writer.writeCharacters("\n");
+            }
+            if (namespaces.contains(NS_TX) && isJtaUsed()) {
                 writer.writeEmptyElement(NS_TX, "enable-annotations");
                 writer.writeCharacters("\n");
-                //if (isJtaUsed()) {
-//                    writer.writeEmptyElement(NS_TX, "enable-annotations");
-                //}
+            }
+            if (namespaces.contains(NS_TX2) && isJtaUsed()) {
+                writer.writeEmptyElement(NS_TX2, "enable");
+                writer.writeCharacters("\n");
             }
             for (Bean bean : context.getBeans()) {
                 writeBeanStart(bean);
@@ -117,14 +123,21 @@ public class Generator implements Proper
         writer.writeStartElement("blueprint");
         writer.writeDefaultNamespace(NS_BLUEPRINT);
         writer.writeNamespace("ext", NS_EXT);
-        if (persistenceAnnotated) {
-            writer.writeNamespace("jpa", NS_JPA2);
-        } else {
-            writer.writeNamespace("jpa", NS_JPA);
+        for (String namespace : namespaces) {
+            String prefix = getPrefixForNamesapace(namespace);
+            writer.writeNamespace(prefix, namespace);
         }
-        writer.writeNamespace("tx", NS_TX);
     }
     
+    private String getPrefixForNamesapace(String namespace) {
+        if (namespace.contains("jpa")) {
+            return "jpa";
+        } if (namespace.contains("transactions")) {
+            return "tx";
+        }
+        return "other";
+    }
+
     public void writeBeanStart(Bean bean) throws XMLStreamException {
         writer.writeStartElement("bean");
         writer.writeAttribute("id", bean.id);
@@ -141,8 +154,10 @@ public class Generator implements Proper
         }
         writer.writeCharacters("\n");
         
-        if (!persistenceAnnotated) {
+        if (namespaces.contains(NS_TX)) {
             writeTransactional(bean.transactionDef);
+        }
+        if (namespaces.contains(NS_JPA)) {
             writePersistenceFields(bean.persistenceFields);
         }
     }

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=1704273&r1=1704272&r2=1704273&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
Mon Sep 21 11:54:42 2015
@@ -24,6 +24,8 @@ import static org.apache.aries.blueprint
 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;
@@ -56,7 +58,8 @@ public class GeneratorTest {
         Context context = new Context(beanClasses);
         context.resolve();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        new Generator(context, os, false).generate();
+        Set<String> namespaces = new HashSet<String>(Arrays.asList(Generator.NS_JPA,
Generator.NS_TX));
+        new Generator(context, os, namespaces).generate();
         System.out.println(os.toString("UTF-8"));
 
         document = readToDocument(os);
@@ -85,7 +88,6 @@ public class GeneratorTest {
         // @Autowired
         Assert.assertEquals("my1", xpath.evaluate("property[@name='bean2']/@ref", bean1));
 
-
     }
 
     private Document readToDocument(ByteArrayOutputStream os) throws ParserConfigurationException,



Mime
View raw message