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 16:38:18 UTC
svn commit: r1793371 - in /axis/axis2/java/core/branches/AXIS2-5785/modules:
adb-tests/
tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/
tool/axis2-xsd2java-maven-plugin/src/site/
tool/axis2-xsd2java-maven-plugin/src/site...
Author: veithen
Date: Mon May 1 16:38:18 2017
New Revision: 1793371
URL: http://svn.apache.org/viewvc?rev=1793371&view=rev
Log:
Automatically add generated sources to the project. This requires introducing a separate Mojo that is intended to be executed in the generate-test-sources phase.
Added:
axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/AbstractXSD2JavaMojo.java
- copied, changed from r1793370, 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/main/java/org/apache/axis2/maven/xsd2java/GenerateSourcesMojo.java (with props)
axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateTestSourcesMojo.java (with props)
Removed:
axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java
Modified:
axis/axis2/java/core/branches/AXIS2-5785/modules/adb-tests/pom.xml
axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/index.md
axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/usage.md
axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/site.xml
Modified: axis/axis2/java/core/branches/AXIS2-5785/modules/adb-tests/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-5785/modules/adb-tests/pom.xml?rev=1793371&r1=1793370&r2=1793371&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/adb-tests/pom.xml (original)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/adb-tests/pom.xml Mon May 1 16:38:18 2017
@@ -90,9 +90,8 @@
<executions>
<execution>
<id>xsd2java</id>
- <phase>generate-test-sources</phase>
<goals>
- <goal>xsd2java</goal>
+ <goal>generate-test-sources</goal>
</goals>
<configuration>
<xsdFiles>
@@ -144,9 +143,8 @@
</execution>
<execution>
<id>xsd2java-nonamespace</id>
- <phase>generate-test-sources</phase>
<goals>
- <goal>xsd2java</goal>
+ <goal>generate-test-sources</goal>
</goals>
<configuration>
<xsdFiles>
@@ -158,9 +156,8 @@
</execution>
<execution>
<id>xsd2java-helper-mode</id>
- <phase>generate-test-sources</phase>
<goals>
- <goal>xsd2java</goal>
+ <goal>generate-test-sources</goal>
</goals>
<configuration>
<xsdFiles>
@@ -184,27 +181,6 @@
</configuration>
</execution>
</executions>
- <configuration>
- <outputDirectory>${project.build.directory}/schema/src</outputDirectory>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>add-test-source</id>
- <phase>process-test-resources</phase>
- <goals>
- <goal>add-test-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>${basedir}/target/schema/src</source>
- </sources>
- </configuration>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>${project.groupId}</groupId>
Copied: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/AbstractXSD2JavaMojo.java (from r1793370, 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/AbstractXSD2JavaMojo.java?p2=axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/AbstractXSD2JavaMojo.java&p1=axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/XSD2JavaMojo.java&r1=1793370&r2=1793371&rev=1793371&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/AbstractXSD2JavaMojo.java Mon May 1 16:38:18 2017
@@ -14,22 +14,14 @@ import org.apache.maven.project.MavenPro
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.xml.sax.InputSource;
-/**
- * Generates Java classes from the specified XSD schema files.
- *
- * @goal xsd2java
- * @phase generate-sources
- * @requiresDependencyResolution compile
- */
-public class XSD2JavaMojo extends AbstractMojo {
-
+public abstract class AbstractXSD2JavaMojo extends AbstractMojo {
/**
* The maven project.
* @parameter expression="${project}"
* @readonly
* @required
*/
- protected MavenProject project;
+ private MavenProject project;
/**
* The list of XSD files for which to generate the Java code.
@@ -39,13 +31,6 @@ public class XSD2JavaMojo extends Abstra
private File[] xsdFiles;
/**
- * The output directory for the generated Java code.
- * @parameter
- * @required true
- */
- private File outputDirectory;
-
- /**
* Mapping of namespaces to target Java packages.
* @parameter
*/
@@ -74,6 +59,7 @@ public class XSD2JavaMojo extends Abstra
private String packageName;
public void execute() throws MojoExecutionException, MojoFailureException {
+ File outputDirectory = getOutputDirectory();
outputDirectory.mkdirs();
CompilerOptions compilerOptions = new CompilerOptions();
compilerOptions.setOutputLocation(outputDirectory);
@@ -97,5 +83,9 @@ public class XSD2JavaMojo extends Abstra
} catch (SchemaCompilationException ex) {
throw new MojoExecutionException("An error occurred during 'xsd2java' processing: " + ex.getMessage(), ex);
}
+ addSourceRoot(project);
}
+
+ protected abstract File getOutputDirectory();
+ protected abstract void addSourceRoot(MavenProject project);
}
Added: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateSourcesMojo.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/GenerateSourcesMojo.java?rev=1793371&view=auto
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateSourcesMojo.java (added)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateSourcesMojo.java Mon May 1 16:38:18 2017
@@ -0,0 +1,48 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.axis2.maven.xsd2java;
+
+import java.io.File;
+
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Generates Java classes from the specified schema files.
+ *
+ * @goal generate-sources
+ * @phase generate-sources
+ */
+public class GenerateSourcesMojo extends AbstractXSD2JavaMojo {
+ /**
+ * The output directory for the generated Java code.
+ *
+ * @parameter default-value="${project.build.directory}/generated-sources/xsd2java"
+ */
+ private File outputDirectory;
+
+ @Override
+ protected File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ @Override
+ protected void addSourceRoot(MavenProject project) {
+ project.addCompileSourceRoot(outputDirectory.getPath());
+ }
+}
Propchange: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateSourcesMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateTestSourcesMojo.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/GenerateTestSourcesMojo.java?rev=1793371&view=auto
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateTestSourcesMojo.java (added)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateTestSourcesMojo.java Mon May 1 16:38:18 2017
@@ -0,0 +1,50 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.axis2.maven.xsd2java;
+
+import java.io.File;
+
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Generates Java classes from the specified schema files, for use in unit tests. This goal binds by
+ * default to the generate-test-sources phase and adds the sources to the test sources of the
+ * project; it is otherwise identical to the axis2-xsd2java:generate-sources goal.
+ *
+ * @goal generate-test-sources
+ * @phase generate-test-sources
+ */
+public class GenerateTestSourcesMojo extends AbstractXSD2JavaMojo {
+ /**
+ * The output directory for the generated Java code.
+ *
+ * @parameter default-value="${project.build.directory}/generated-test-sources/xsd2java"
+ */
+ private File outputDirectory;
+
+ @Override
+ protected File getOutputDirectory() {
+ return outputDirectory;
+ }
+
+ @Override
+ protected void addSourceRoot(MavenProject project) {
+ project.addTestCompileSourceRoot(outputDirectory.getPath());
+ }
+}
Propchange: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/main/java/org/apache/axis2/maven/xsd2java/GenerateTestSourcesMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/index.md
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/index.md?rev=1793371&r1=1793370&r2=1793371&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/index.md (original)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/markdown/index.md Mon May 1 16:38:18 2017
@@ -22,4 +22,4 @@ About
This plugin takes as input a one or more XSD schemas and generates Axis2 ADB Java Bean classes.
-The full description of goals is available [here](goals.html).
+The full description of goals is available [here](plugin-info.html).
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=1793371&r1=1793370&r2=1793371&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 16:38:18 2017
@@ -20,9 +20,11 @@
Usage
-----
-The XSD2Java plugin offers a single goal:
-
-* xsd2java (default): Reads one or more XSD-files class and generates the corresponding Java Axis2 ADB beans.
+axis2-xsd2java-maven-plugin offers two goals: `generate-sources` and `generate-test-sources`.
+Both read one or more XSD files and generate the corresponding ADB beans, but they differ in the phases in which they
+expect to be executed. Use `generate-sources` if the generated classes should become part of the
+artifact produced by the Maven module; use `generate-test-sources` if the generated code is only
+used by the unit tests.
To run the plugin, add the following section to your POM:
@@ -34,11 +36,10 @@ To run the plugin, add the following sec
<executions>
<execution>
<goals>
- <goal>xsd2java</goal>
+ <goal>generate-sources</goal>
</goals>
</execution>
<configuration>
- <outputDirectory>${project.build.directory}/generated-sources/java</outputDirectory>
<xsdFiles>
<xsdFile>src/main/resources/xsd/attribute.xsd</xsdFile>
</xsdFiles>
@@ -55,14 +56,9 @@ To run the plugin, add the following sec
</build>
The plugin will be invoked automatically in the generate-sources
-phase. You can also invoke it directly from the command line by
-running the command
-
- mvn xsd2java:xsd2java
-
-# The XSD2Java Goal
+phase.
-The plugin reads the specified XSD files and creates the matching Axis2 ADB Java bean classes. The mapping from
+It 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 `namespaceMappings` configuration element above.
-See the detailed documentation on [properties](xsd2java-mojo.html) for how to configure the goal.
+See the detailed documentation on [properties](generate-sources-mojo.html) for how to configure the goal.
Modified: axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/site.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/site.xml?rev=1793371&r1=1793370&r2=1793371&view=diff
==============================================================================
--- axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/site.xml (original)
+++ axis/axis2/java/core/branches/AXIS2-5785/modules/tool/axis2-xsd2java-maven-plugin/src/site/site.xml Mon May 1 16:38:18 2017
@@ -25,7 +25,8 @@
<item name="About" href="index.html"/>
<item name="Usage" href="usage.html"/>
<item name="Plugin Documentation" href="plugin-info.html">
- <item name="xsd2java" href="xsd2java-mojo.html"/>
+ <item name="generate-sources" href="generate-sources-mojo.html"/>
+ <item name="generate-test-sources" href="generate-test-sources-mojo.html"/>
</item>
</menu>
</body>