You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2017/03/26 22:33:18 UTC

svn commit: r1788779 - in /axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin: pom.xml src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java

Author: veithen
Date: Sun Mar 26 22:33:17 2017
New Revision: 1788779

URL: http://svn.apache.org/viewvc?rev=1788779&view=rev
Log:
Add experimental feature to axis2-repo-maven-plugin to generate an axis2.xml file automatically.

Modified:
    axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/pom.xml
    axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java

Modified: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/pom.xml?rev=1788779&r1=1788778&r2=1788779&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/pom.xml Sun Mar 26 22:33:17 2017
@@ -51,6 +51,15 @@
             <version>3.0.1</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.ws.commons.axiom</groupId>
+            <artifactId>axiom-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ws.commons.axiom</groupId>
+            <artifactId>axiom-impl</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>addressing</artifactId>
             <version>${project.version}</version>

Modified: axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java?rev=1788779&r1=1788778&r2=1788779&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java (original)
+++ axis/axis2/java/core/trunk/modules/tool/axis2-repo-maven-plugin/src/main/java/org/apache/axis2/maven2/repo/AbstractCreateRepositoryMojo.java Sun Mar 26 22:33:17 2017
@@ -20,7 +20,13 @@
 package org.apache.axis2.maven2.repo;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -29,6 +35,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMXMLBuilderFactory;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -91,8 +104,15 @@ public abstract class AbstractCreateRepo
     private File axis2xml;
     
     /**
+     * Specifies whether an <tt>axis2.xml</tt> file should be generated (Experimental).
+     * 
+     * @parameter
+     */
+    private boolean generateAxis2xml;
+    
+    /**
      * The directory (relative to the repository root) where the <tt>axis2.xml</tt> file will be
-     * copied. If this parameter is not set, then the file will be copied into the repository
+     * written. If this parameter is not set, then the file will be written into the repository
      * root.
      * 
      * @parameter
@@ -268,14 +288,65 @@ public abstract class AbstractCreateRepo
                 }
             }
         }
-        if (axis2xml != null) {
-            log.info("Copying axis2.xml");
+        if (generateAxis2xml || axis2xml != null) {
             File targetDirectory = configurationDirectory == null
                     ? outputDirectory : new File(outputDirectory, configurationDirectory);
-            try {
-                FileUtils.copyFile(axis2xml, new File(targetDirectory, "axis2.xml"));
-            } catch (IOException ex) {
-                throw new MojoExecutionException("Error copying axis2.xml file: " + ex.getMessage(), ex);
+            targetDirectory.mkdirs();
+            File axis2xmlFile = new File(targetDirectory, "axis2.xml");
+            if (axis2xml != null) {
+                log.info("Copying axis2.xml");
+                try {
+                    FileUtils.copyFile(axis2xml, axis2xmlFile);
+                } catch (IOException ex) {
+                    throw new MojoExecutionException("Error copying axis2.xml file: " + ex.getMessage(), ex);
+                }
+            } else {
+                log.info("Generating axis2.xml");
+                try {
+                    FilterArtifacts filter = new FilterArtifacts();
+                    filter.addFilter(new ScopeFilter(getScope(), null));
+                    filter.addFilter(new TypeFilter("jar", null));
+                    List<URL> urls = new ArrayList<URL>();
+                    for (Artifact artifact : filter.filter(projectArtifacts)) {
+                        urls.add(artifact.getFile().toURI().toURL());
+                    }
+                    URLClassLoader classLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]));
+                    InputStream in = classLoader.getResourceAsStream("org/apache/axis2/deployment/axis2_default.xml");
+                    if (in == null) {
+                        throw new MojoFailureException("The default axis2.xml file could not be found");
+                    }
+                    try {
+                        OMDocument axis2xmlDoc = OMXMLBuilderFactory.createOMBuilder(in).getDocument();
+                        for (Iterator<OMNode> it = axis2xmlDoc.getOMDocumentElement().getDescendants(false); it.hasNext(); ) {
+                            OMNode node = it.next();
+                            if (node instanceof OMElement) {
+                                OMElement element = (OMElement)node;
+                                String classAttr = element.getAttributeValue(new QName("class"));
+                                if (classAttr != null) {
+                                    try {
+                                        classLoader.loadClass(classAttr);
+                                    } catch (ClassNotFoundException ex) {
+                                        it.remove();
+                                    }
+                                }
+                            }
+                        }
+                        OutputStream out = new FileOutputStream(axis2xmlFile);
+                        try {
+                            axis2xmlDoc.serialize(out);
+                        } finally {
+                            out.close();
+                        }
+                    } finally {
+                        in.close();
+                    }
+                } catch (ArtifactFilterException ex) {
+                    throw new MojoExecutionException(ex.getMessage(), ex);
+                } catch (IOException ex) {
+                    throw new MojoExecutionException(ex.getMessage(), ex);
+                } catch (XMLStreamException ex) {
+                    throw new MojoExecutionException(ex.getMessage(), ex);
+                }
             }
         }
     }