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/05/01 15:43:40 UTC

svn commit: r1793357 - in /axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin: pom.xml src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java src/site/markdown/usage.md

Author: veithen
Date: Mon May  1 15:43:40 2017
New Revision: 1793357

URL: http://svn.apache.org/viewvc?rev=1793357&view=rev
Log:
Invoke the SchemaCompiler directly instead of executing XSD2Java. Also realign parameter names with axis2-wsdl2code-maven-plugin.

Modified:
    axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/pom.xml
    axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java
    axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/usage.md

Modified: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/pom.xml?rev=1793357&r1=1793356&r2=1793357&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/pom.xml (original)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/pom.xml Mon May  1 15:43:40 2017
@@ -14,7 +14,7 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.axis2</groupId>
+            <groupId>${project.groupId}</groupId>
             <artifactId>axis2-adb-codegen</artifactId>
             <version>${project.version}</version>
         </dependency>
@@ -26,6 +26,11 @@
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>maven-shared</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
     <reporting>

Modified: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java?rev=1793357&r1=1793356&r2=1793357&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java (original)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java Mon May  1 15:43:40 2017
@@ -1,14 +1,18 @@
 package org.apache.axis2.maven.xsd2java;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.axis2.schema.XSD2Java;
+import org.apache.axis2.maven.shared.NamespaceMapping;
+import org.apache.axis2.maven.shared.NamespaceMappingUtil;
+import org.apache.axis2.schema.CompilerOptions;
+import org.apache.axis2.schema.SchemaCompilationException;
+import org.apache.axis2.schema.SchemaCompiler;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.xml.sax.InputSource;
 
 /**
  * Generates Java classes from the specified XSD schema files.
@@ -32,7 +36,7 @@ public class XSD2JavaMojo extends Abstra
      * @parameter
      * @required true
      */
-    protected List<String> xsdFiles;
+    private File[] xsdFiles;
 
     /**
      * The output directory for the generated Java code.
@@ -45,54 +49,23 @@ public class XSD2JavaMojo extends Abstra
      * Mapping of namespaces to target Java packages.
      * @parameter
      */
-    protected List<String> namespace2Packages;
+    private NamespaceMapping[] namespaceMappings;
 
-    /**
-     * Run the 'xsd2java' utility.
-     * @throws MojoExecutionException if an error occurs during processing
-     * @throws MojoFailureException if an error occurs during processing
-     */
     public void execute() throws MojoExecutionException, MojoFailureException {
-
-        String[] args = getCommandLineArgumentsForXSD2Java();
-
+        outputFolder.mkdirs();
+        CompilerOptions compilerOptions = new CompilerOptions();
+        compilerOptions.setOutputLocation(outputFolder);
+        compilerOptions.setGenerateAll(true);
+        NamespaceMappingUtil.addToMap(namespaceMappings, compilerOptions.getNs2PackageMap());
+        compilerOptions.setWriteOutput(true);
         try {
-            XSD2Java.main(args);
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            throw new MojoExecutionException("An error occurred during 'xsd2java' processing: " + ex.getMessage(), ex);
-        }
-
-    }
-
-    /**
-     * Process the maven parameters to xsd2java command-line arguments
-     * @return the array of command line arguments
-     */
-    private String[] getCommandLineArgumentsForXSD2Java() {
-
-        final List<String> commandLineArguments = new ArrayList<String>();
-
-        // add the namespace-to-package mappings
-        if (namespace2Packages != null) {
-            for (String namespace2Package : namespace2Packages) {
-                commandLineArguments.add("-ns2p");
-                commandLineArguments.add(namespace2Package);
+            for (File xsdFile : xsdFiles) {
+                XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
+                SchemaCompiler compiler = new SchemaCompiler(compilerOptions);
+                compiler.compile(schemaCollection.read(new InputSource(xsdFile.toURI().toString())));
             }
+        } catch (SchemaCompilationException ex) {
+            throw new MojoExecutionException("An error occurred during 'xsd2java' processing: " + ex.getMessage(), ex);
         }
-
-        // add the XSD files
-        for (String xsdFile : xsdFiles) {
-            commandLineArguments.add(xsdFile);
-        }
-
-        // add the output path
-        commandLineArguments.add(outputFolder.getAbsolutePath());
-
-        final String[] args = commandLineArguments.toArray(new String[]{});
-
-        return args;
-
     }
-
 }

Modified: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/usage.md
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/usage.md?rev=1793357&r1=1793356&r2=1793357&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/usage.md (original)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/usage.md Mon May  1 15:43:40 2017
@@ -38,13 +38,16 @@ To run the plugin, add the following sec
               </goals>
             </execution>
             <configuration>
-              <outputFolder>${project.basedir}/target/generated-sources/java</outputFolder>
+              <outputFolder>${project.build.directory}/generated-sources/java</outputFolder>
               <xsdFiles>
-                  <xsdFile>${project.basedir}/src/main/resources/xsd/attribute.xsd</xsdFile>
+                <xsdFile>src/main/resources/xsd/attribute.xsd</xsdFile>
               </xsdFiles>
-              <namespace2Packages>
-                  <namespace2Package>http://www.example.org/schema/test=org.example.schema.test</namespace2Package>
-              </namespace2Packages>
+              <namespaceMappings>
+                <namespaceMapping>
+                  <uri>http://www.example.org/schema/test</uri>
+                  <packageName>org.example.schema.test</packageName>
+                </namespaceMapping>
+              </namespaceMappings>
             </configuration>
           </executions>
         </plugin>
@@ -60,6 +63,6 @@ running the command
 # The XSD2Java Goal
 
 The plugin reads the specified XSD files and creates the matching Axis2 ADB Java bean classes.  The mapping from
-XSD target-namespaces to Java packages is specified with the `namespace2Packages` configuration element above.
+XSD target-namespaces to Java packages is specified with the `namespaceMappings` configuration element above.
 
 See the detailed documentation on [properties](xsd2java-mojo.html) for how to configure the goal.