aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alien11...@apache.org
Subject svn commit: r1779058 - in /aries/trunk/blueprint/plugin/blueprint-maven-plugin: pom.xml src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java src/main/java/org/apache/aries/blueprint/plugin/Generator.java
Date Mon, 16 Jan 2017 16:08:10 GMT
Author: alien11689
Date: Mon Jan 16 16:08:10 2017
New Revision: 1779058

URL: http://svn.apache.org/viewvc?rev=1779058&view=rev
Log:
[MAINTENANCE] Format blueprint using only java api

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

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/pom.xml?rev=1779058&r1=1779057&r2=1779058&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/pom.xml (original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/pom.xml Mon Jan 16 16:08:10 2017
@@ -274,11 +274,6 @@
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.glassfish.jaxb</groupId>
-            <artifactId>txw2</artifactId>
-            <version>2.2.11</version>
-        </dependency>
     </dependencies>
 
 

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java?rev=1779058&r1=1779057&r2=1779058&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/GenerateMojo.java
Mon Jan 16 16:08:10 2017
@@ -121,7 +121,7 @@ public class GenerateMojo extends Abstra
 
             Set<Class<?>> classes = FilteredClassFinder.findClasses(finder, toScan);
 
-            BlueprintConfiguration blueprintConfiguration = new BlueprintConfigurationImpl(namespaces,
defaultActivation, customParameters);
+            BlueprintConfigurationImpl blueprintConfiguration = new BlueprintConfigurationImpl(namespaces,
defaultActivation, customParameters);
 
             Context context = new Context(blueprintConfiguration, classes);
             context.resolve();
@@ -133,7 +133,7 @@ public class GenerateMojo extends Abstra
         }
     }
 
-    private void writeBlueprint(Context context, BlueprintConfiguration blueprintConfiguration)
throws Exception {
+    private void writeBlueprint(Context context, BlueprintConfigurationImpl blueprintConfiguration)
throws Exception {
         String buildDir = project.getBuild().getDirectory();
         String generatedBaseDir = buildDir + "/generated-sources/blueprint";
         Resource resource = new Resource();

Modified: aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
URL: http://svn.apache.org/viewvc/aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java?rev=1779058&r1=1779057&r2=1779058&view=diff
==============================================================================
--- aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
(original)
+++ aries/trunk/blueprint/plugin/blueprint-maven-plugin/src/main/java/org/apache/aries/blueprint/plugin/Generator.java
Mon Jan 16 16:08:10 2017
@@ -18,7 +18,6 @@
  */
 package org.apache.aries.blueprint.plugin;
 
-import com.sun.xml.txw2.output.IndentingXMLStreamWriter;
 import org.apache.aries.blueprint.plugin.model.Argument;
 import org.apache.aries.blueprint.plugin.model.ArgumentWriter;
 import org.apache.aries.blueprint.plugin.model.Bean;
@@ -32,6 +31,14 @@ import org.apache.aries.blueprint.plugin
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.OutputStream;
 import java.util.Map;
 
@@ -43,18 +50,22 @@ public class Generator implements Proper
     private final Context context;
     private final BlueprintConfiguration blueprintConfiguration;
     private final XMLStreamWriter writer;
+    private final OutputStream os;
+    private final ByteArrayOutputStream temp = new ByteArrayOutputStream();
 
-    public Generator(Context context, OutputStream os, BlueprintConfiguration blueprintConfiguration)
throws XMLStreamException {
+    public Generator(Context context, OutputStream os, BlueprintConfigurationImpl blueprintConfiguration)
throws XMLStreamException {
         this.context = context;
         this.blueprintConfiguration = blueprintConfiguration;
-        writer = createWriter(os);
+        this.writer = XMLOutputFactory.newFactory().createXMLStreamWriter(temp);
+        this.os = os;
     }
 
-    private XMLStreamWriter createWriter(OutputStream os) throws XMLStreamException {
-        return new IndentingXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(os));
+    public void generate() {
+        generateXml();
+        printFormatted();
     }
 
-    public void generate() {
+    private void generateXml() {
         try {
             writer.writeStartDocument();
             writeBlueprint();
@@ -78,6 +89,23 @@ public class Generator implements Proper
         }
     }
 
+    private void printFormatted() {
+        try {
+            TransformerFactory factory = TransformerFactory.newInstance();
+
+            Transformer transformer = factory.newTransformer();
+            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+
+
+            transformer.transform(
+                    new StreamSource(new ByteArrayInputStream(temp.toByteArray())),
+                    new StreamResult(os));
+        } catch (TransformerException e) {
+            throw new RuntimeException("Cannot print file", e);
+        }
+    }
+
     private void writeBlueprint() throws XMLStreamException {
         writer.writeStartElement("blueprint");
         writer.writeDefaultNamespace(NS_BLUEPRINT);



Mime
View raw message