Skip to content

Commit

Permalink
[#443] enable customization of target with specVersion mojo property …
Browse files Browse the repository at this point in the history
…and fix default value
  • Loading branch information
laurentschoelens authored and mattrpav committed Nov 22, 2023
1 parent 36652fc commit 5b8a6f5
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 7 deletions.
58 changes: 58 additions & 0 deletions jaxb-plugins-parent/tests/po-2.3/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-tests</artifactId>
<version>4.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>jaxb-plugins-test-po-2.3</artifactId>
<packaging>jar</packaging>
<name>JAXB Tools :: JAXB Plugins :: Test [po 2.3]</name>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins-runtime</artifactId>
</dependency>
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<extension>true</extension>
<specVersion>2.3</specVersion>
<args>
<arg>-XsimpleEquals</arg>
<arg>-XsimpleHashCode</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-plugins</artifactId>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:annotation>
<xsd:documentation xml:lang="en">
Purchase order schema for Example.com.
Copyright 2000 Example.com. All rights reserved.
</xsd:documentation>
</xsd:annotation>

<xsd:element name="purchaseOrder" type="PurchaseOrderType"/>

<xsd:element name="comment" type="xsd:string"/>

<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="shipTo" type="USAddress"/>
<xsd:element name="billTo" type="USAddress"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="items" type="Items"/>
</xsd:sequence>
<xsd:attribute name="orderDate" type="xsd:date"/>
</xsd:complexType>

<xsd:complexType name="USAddress">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zip" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:NMTOKEN"
fixed="US"/>
</xsd:complexType>

<xsd:complexType name="Items">
<xsd:sequence>
<xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="productName" type="xsd:string"/>
<xsd:element name="quantity">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="USPrice" type="xsd:decimal"/>
<xsd:element ref="comment" minOccurs="0"/>
<xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="partNum" type="SKU" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<!-- Stock Keeping Unit, a code for identifying products -->
<xsd:simpleType name="SKU">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{3}-[A-Z]{2}"/>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>
1 change: 1 addition & 0 deletions jaxb-plugins-parent/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<module>namespace</module>
<module>one</module>
<module>po</module>
<module>po-2.3</module>
<module>qa-simple</module>
<module>qa-strategic</module>
<module>simple-hashCode-equals-01</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,10 +1059,10 @@ public void setScanDependenciesForBindings(
}

/**
* Version of the JAXB specification (ex. 2.0, 2.1 or 2.2).
* Version of the JAXB specification (ex. 2.3, 3.0, LATEST).
*/
@Parameter(defaultValue = "2.2")
private String specVersion = "2.2";
@Parameter(defaultValue = "LATEST")
private String specVersion = "LATEST";

public String getSpecVersion() {
return specVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Options createOptions(OptionsConfiguration optionsConfiguration)

options.classpaths.addAll(optionsConfiguration.getPlugins());

options.target = SpecVersion.V3_0;
computeTarget(options, optionsConfiguration.getSpecVersion());

final String encoding = optionsConfiguration.getEncoding();

Expand Down Expand Up @@ -95,7 +95,18 @@ public Options createOptions(OptionsConfiguration optionsConfiguration)
return options;
}

private String createEncoding(String encoding)
private void computeTarget(Options options, String specVersion) throws MojoExecutionException {
if ("LATEST".equals(specVersion)) {
specVersion = SpecVersion.LATEST.getVersion();
}
try {
options.parseArgument(new String[]{ "-target", specVersion }, 0);
} catch (BadCommandLineException e) {
throw new MojoExecutionException(MessageFormat.format("Unsupported specVersion [{0}].", specVersion), e);
}
}

private String createEncoding(String encoding)
throws MojoExecutionException {
if (encoding == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Iterator;
import java.util.Map;

import com.sun.tools.xjc.Messages;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -59,6 +60,10 @@ protected Model loadModel(Options options) throws MojoExecutionException {
new LoggingErrorReceiver("Error while parsing schema(s).",
getLog(), getVerbose()));

for (Map.Entry<String, String> pair : options.classNameReplacer.entrySet()) {
model.codeModel.addClassNameReplacer(pair.getKey(), pair.getValue());
}

if (model == null)
throw new MojoExecutionException(
"Unable to parse input schema(s). Error messages should have been provided.");
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/tests/jt-306/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</bindingIncludes>
<readOnly>true</readOnly>
<episode>true</episode>
<specVersion>2.3</specVersion>
<specVersion>3.0</specVersion>
<extension>true</extension>
<removeOldOutput>true</removeOldOutput>
<locale>en</locale>
Expand Down
2 changes: 1 addition & 1 deletion maven-plugin/tests/p_o/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>4.0.1-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<name>JAXB Tools :: Maven Plugin :: Test [p o]</name>
<name>JAXB Tools :: Maven Plugin :: Test [po]</name>
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
Expand Down
9 changes: 9 additions & 0 deletions maven-plugin/tests/po-2.3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.8</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb</groupId>
<artifactId>jaxb-maven-plugin</artifactId>
<configuration>
<specVersion>2.3</specVersion>
</configuration>
</plugin>
</plugins>
</build>
Expand Down

0 comments on commit 5b8a6f5

Please sign in to comment.