Skip to content

Commit

Permalink
Merge pull request #330 from laurentschoelens/jap-9
Browse files Browse the repository at this point in the history
Fixing issue JAP-9
  • Loading branch information
mattrpav authored Aug 25, 2023
2 parents 0856045 + 6d23093 commit 810df43
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 19 deletions.
10 changes: 6 additions & 4 deletions jaxb-annotate-parent/samples/annotate/project-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<!-- XJC2 Task classpath -->
<classpath>
<fileset dir="${basedir}/lib">
<include name="commons-text-*.jar"/>
<include name="codemodel-*.jar"/>
<include name="istack-commons-*.jar"/>
<include name="jakarta.activation-*.jar"/>
Expand Down Expand Up @@ -119,14 +120,15 @@
<include name="commons-beanutils-*.jar"/>
<include name="commons-logging-*.jar"/>
<include name="commons-lang3-*.jar"/>
<include name="commons-text-*.jar"/>
</fileset>
</classpath>
</xjc>
</target>
<target name="compile" depends="generate-sources">
<mkdir dir="${basedir}/target/classes"/>
<javac
destdir="${basedir}/target/classes"
destdir="${basedir}/target/classes"
srcdir="${basedir}/src/main/java:${basedir}/target/generated-sources/xjc"
classpathref="compile.path"
includeantruntime="false"
Expand All @@ -143,7 +145,7 @@
<target name="test-compile" depends="compile">
<mkdir dir="${basedir}/target/test-classes"/>
<javac
destdir="${basedir}/target/test-classes"
destdir="${basedir}/target/test-classes"
srcdir="${basedir}/src/test/java:${basedir}/target/generated-sources/xjc"
classpathref="test-compile.path"
includeantruntime="false"
Expand Down Expand Up @@ -184,7 +186,7 @@
<target name="package" depends="test">
<mkdir dir="${basedir}/target"/>
<jar destfile="${basedir}/target/${artifactId}.jar"
basedir="${basedir}/target/classes"/>
basedir="${basedir}/target/classes"/>
</target>
<target name="install" depends="package"/>
</project>
</project>
43 changes: 38 additions & 5 deletions jaxb-annotate-parent/tests/annotate/src/main/resources/schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
-->
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net"
jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox"
xmlns:jl="http://annox.dev.java.net/java.lang">

Expand Down Expand Up @@ -96,7 +96,7 @@
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:simpleType>

<xsd:complexType name="issueJIIB39AType">
<xsd:annotation>
Expand Down Expand Up @@ -128,4 +128,37 @@
<xsd:attribute name="test" type="xsd:string" use="required"/>
</xsd:complexType>

</xsd:schema>
<xsd:complexType name="issueJAP9Type">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate >
<annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="literal"/>
</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="a" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate target="field">@javax.xml.bind.annotation.XmlMimeType(value = "[0-9]+\\.[0-9]{1,2}\\.[0-9]{4}\\.[0-9]+")</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="b" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate target="field">@javax.xml.bind.annotation.XmlMimeType(value = "[0-9]+\\\\.[0-9]{1,2}\\\\.[0-9]{4}\\\\.[0-9]+")</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="c" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate target="field">@javax.xml.bind.annotation.XmlMimeType(value = "NoEscapedBackSlashes\"/Here")</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jvnet.jaxb2_commons.tests.annotate;

import generated.IssueJAP9Type;
import org.junit.Assert;
import org.junit.Test;

import javax.xml.bind.annotation.XmlMimeType;
import java.lang.reflect.Field;

public class IssueJAP9TypeTest {

@Test
public void testIssueJAP9TypeAField() throws NoSuchFieldException {
String valueInXsd = "[0-9]+\\.[0-9]{1,2}\\.[0-9]{4}\\.[0-9]+";
IssueJAP9Type type = new IssueJAP9Type();
Field[] fields = type.getClass().getDeclaredFields();
XmlMimeType ann = type.getClass().getDeclaredField("a").getAnnotation(XmlMimeType.class);
Assert.assertEquals(valueInXsd, ann.value());
}

@Test
public void testIssueJAP9TypeBField() throws NoSuchFieldException {
String valueInXsd = "[0-9]+\\\\.[0-9]{1,2}\\\\.[0-9]{4}\\\\.[0-9]+";
IssueJAP9Type type = new IssueJAP9Type();
XmlMimeType ann = type.getClass().getDeclaredField("b").getAnnotation(XmlMimeType.class);
Assert.assertEquals(valueInXsd, ann.value());
}

@Test
public void testIssueJAP9TypeCField() throws NoSuchFieldException {
String valueInXsd = "EscapedQuote\"/Here";
IssueJAP9Type type = new IssueJAP9Type();
XmlMimeType ann = type.getClass().getDeclaredField("c").getAnnotation(XmlMimeType.class);
Assert.assertEquals(valueInXsd, ann.value());
}
}
6 changes: 5 additions & 1 deletion jaxb-annox-parent/jaxb-annox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.jvnet.jaxb.annox.model.annotation.value;

import org.apache.commons.text.StringEscapeUtils;

public class XStringAnnotationValue extends XStaticAnnotationValue<String> {

public XStringAnnotationValue(String value) {
super(value);
// fix JAP-9 issue : \ needs to be espaced for javaparser to work
// but will then be escaped again by codemodel to generate annotation
super(StringEscapeUtils.unescapeJava(value));
}

@Override
Expand Down
17 changes: 10 additions & 7 deletions jaxb-annox-parent/samples/po/project-build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<path id="compile.path">
<fileset dir="${basedir}/lib">
<include name="commons-lang3-*.jar"/>
<include name="commons-text-*.jar"/>
<include name="codemodel-*.jar"/>
<include name="istack-commons-*.jar"/>
<include name="jakarta.xml.bind-api-*.jar"/>
Expand All @@ -13,7 +14,7 @@
<include name="rngom-*.jar"/>
<include name="txw2-*.jar"/>
<include name="xsom-*.jar"/>

<include name="jaxb-annox-*.jar"/>
<include name="javaparser-*.jar"/>
</fileset>
Expand All @@ -32,13 +33,14 @@
<include name="codemodel-*.jar"/>
<include name="commons-io-*.jar"/>
<include name="commons-lang3-*.jar"/>
<include name="commons-text-*.jar"/>
<include name="slf4j-*.jar"/>
<include name="jcl-over-slf4j-*.jar"/>
<include name="relaxng-datatype-*.jar"/>
<include name="rngom-*.jar"/>
<include name="txw2-*.jar"/>
<include name="xsom-*.jar"/>

<include name="jaxb-annox-*.jar"/>
<include name="javaparser-*.jar"/>
</fileset>
Expand All @@ -58,13 +60,14 @@
<include name="codemodel-*.jar"/>
<include name="commons-io-*.jar"/>
<include name="commons-lang3-*.jar"/>
<include name="commons-text-*.jar"/>
<include name="slf4j-*.jar"/>
<include name="jcl-over-slf4j-*.jar"/>
<include name="relaxng-datatype-*.jar"/>
<include name="rngom-*.jar"/>
<include name="txw2-*.jar"/>
<include name="xsom-*.jar"/>

<include name="jaxb-annox-*.jar"/>
<include name="javaparser-*.jar"/>
</fileset>
Expand All @@ -79,7 +82,7 @@
<target name="compile" depends="generate-sources">
<mkdir dir="${basedir}/target/classes"/>
<javac
destdir="${basedir}/target/classes"
destdir="${basedir}/target/classes"
srcdir="${basedir}/src/main/java"
classpathref="compile.path"
source="1.8"
Expand All @@ -92,7 +95,7 @@
<target name="test-compile" depends="compile">
<mkdir dir="${basedir}/target/test-classes"/>
<javac
destdir="${basedir}/target/test-classes"
destdir="${basedir}/target/test-classes"
srcdir="${basedir}/src/test/java"
classpathref="test-compile.path"
source="1.8"
Expand Down Expand Up @@ -125,7 +128,7 @@
<target name="package" depends="test">
<mkdir dir="${basedir}/target"/>
<jar destfile="${basedir}/target/${artifactId}.jar"
basedir="${basedir}/target/classes"/>
basedir="${basedir}/target/classes"/>
</target>
<target name="install" depends="package"/>
</project>
</project>
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<commons-beanutils.version>1.9.4</commons-beanutils.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-text.version>1.10.0</commons-text.version>
<joda-time.version>2.5</joda-time.version>
<junit4.version>4.13.2</junit4.version>
<slf4j.version>1.7.36</slf4j.version>
Expand Down Expand Up @@ -375,7 +376,12 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
Expand Down

0 comments on commit 810df43

Please sign in to comment.