From d6712d59836cb6d0b71f33eca83ef29b4f5843b5 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Tue, 17 Jan 2012 18:22:24 +0100 Subject: [PATCH] Generate spring-oxm test classes and bindings - Generate castor test classes with genCastor task - Generate xmlbeans test classes with genXmlbeans task - Generate JAXB2 test classes with genJaxb task - Generate JiBX bindings by extending existing compileTestJava task Test classes are written into their own dedicated output folders and tied into the spring-oxm classpath using the files(...).builtBy(...) directive. Incremental build works as expected across all of these customizations. `gradle eclipse` and `gradle idea` generate correct .project / .iml metadata respectively, i.e., these special cases do not cause a problem in the IDE (as they used to prior to the move to Gradle). --- build.gradle | 8 +- org.springframework.oxm/build.xml | 105 -------------- org.springframework.oxm/oxm.gradle | 130 ++++++++++++++++++ .../oxm/jibx/JibxMarshallerTests.java | 7 +- .../oxm/jibx/JibxUnmarshallerTests.java | 4 +- 5 files changed, 143 insertions(+), 111 deletions(-) delete mode 100644 org.springframework.oxm/build.xml create mode 100644 org.springframework.oxm/oxm.gradle diff --git a/build.gradle b/build.gradle index fd4f66bce7..cae83ec5f8 100644 --- a/build.gradle +++ b/build.gradle @@ -227,6 +227,7 @@ project('spring-tx') { project('spring-oxm') { description = 'Spring Object/XML Marshalling' + apply from: 'oxm.gradle' dependencies { compile project(":spring-context") compile "commons-lang:commons-lang:2.5" @@ -238,10 +239,9 @@ project('spring-oxm') { testCompile "org.codehaus.jettison:jettison:1.0.1" testCompile "xmlunit:xmlunit:1.2" testCompile "xmlpull:xmlpull:1.1.3.4a" - // this is a workaround until we have xjc/etc generation plugged in - // in order for this to work, you must FIRST run `ant test` within the - // .oxm module. that will create/populate the target/test-classes dir - testCompile(files("target/test-classes")) + testCompile(files(genCastor.classesDir).builtBy(genCastor)) + testCompile(files(genJaxb.classesDir).builtBy(genJaxb)) + testCompile(files(genXmlbeans.classesDir).builtBy(genXmlbeans)) } } diff --git a/org.springframework.oxm/build.xml b/org.springframework.oxm/build.xml deleted file mode 100644 index f1acbfae3b..0000000000 --- a/org.springframework.oxm/build.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.springframework.oxm/oxm.gradle b/org.springframework.oxm/oxm.gradle new file mode 100644 index 0000000000..c8dceea4a3 --- /dev/null +++ b/org.springframework.oxm/oxm.gradle @@ -0,0 +1,130 @@ +configurations { + castor + xjc + xmlbeans + jibx +} +dependencies { + castor "org.codehaus.castor:castor-anttasks:1.2" + castor "velocity:velocity:1.5" + xjc "com.sun.xml:com.springsource.com.sun.tools.xjc:2.1.7" + xmlbeans "org.apache.xmlbeans:com.springsource.org.apache.xmlbeans:2.4.0" + jibx "org.jibx:jibx-bind:1.1.5" + jibx "bcel:bcel:5.1" +} + +genSourcesDir = "${buildDir}/generated-sources" +flightSchema = "${projectDir}/src/test/resources/org/springframework/oxm/flight.xsd" + +task genCastor { + orderSchema = "${projectDir}/src/test/resources/org/springframework/oxm/order.xsd" + castorBuilderProperties = "${projectDir}/src/test/castor/castorbuilder.properties" + + sourcesDir = "${genSourcesDir}/castor" + classesDir = "${buildDir}/classes/castor" + + inputs.files flightSchema, orderSchema, castorBuilderProperties + outputs.dir classesDir + + doLast() { + project.ant { + taskdef name: "castor", classname: "org.castor.anttask.CastorCodeGenTask", + classpath: configurations.castor.asPath + mkdir(dir: sourcesDir) + mkdir(dir: classesDir) + + castor(types: "j2", warnings: false, file: flightSchema, todir: sourcesDir, + package: "org.springframework.oxm.castor", properties: castorBuilderProperties) + + castor(types: "j2", warnings: false, file: orderSchema, todir: sourcesDir, + package: "org.springframework.oxm.castor", properties: castorBuilderProperties) + + javac(destdir: classesDir, source: 1.5, target: 1.5, debug: true, + debugLevel: "lines,vars,source", classpath: configurations.castor.asPath) { + src(path: sourcesDir) + include(name: "**/*.java") + include(name: "*.java") + } + + copy(todir: classesDir) { + fileset(dir: sourcesDir, erroronmissingdir: false) { + exclude(name: "**/*.java") + } + } + } + } +} + +task genJaxb { + sourcesDir = "${genSourcesDir}/jaxb" + classesDir = "${buildDir}/classes/jaxb" + + inputs.files flightSchema + outputs.dir classesDir + + doLast() { + project.ant { + taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask", + classpath: configurations.xjc.asPath + mkdir(dir: sourcesDir) + mkdir(dir: classesDir) + + xjc(destdir: sourcesDir, schema: flightSchema, + package: "org.springframework.oxm.jaxb.test") { + produces(dir: sourcesDir, includes: "**/*.java") + } + + javac(destdir: classesDir, source: 1.5, target: 1.5, debug: true, + debugLevel: "lines,vars,source", + classpath: configurations.castor.asPath) { + src(path: sourcesDir) + include(name: "**/*.java") + include(name: "*.java") + } + + copy(todir: classesDir) { + fileset(dir: sourcesDir, erroronmissingdir: false) { + exclude(name: "**/*.java") + } + } + } + } +} + +task genXmlbeans { + classesDir = "${buildDir}/classes/xmlbeans" + + inputs.files flightSchema + outputs.dir classesDir + + doLast() { + project.ant { + taskdef name: "xmlbeans", + classname: "org.apache.xmlbeans.impl.tool.XMLBean", + classpath: configurations.xmlbeans.asPath + + xmlbeans(classgendir: classesDir, schema: flightSchema, + compiler: "modern", verbose: "false", + classpath: configurations.xmlbeans.asPath) + } + } +} + +// add jibx binding to the normal test compilation process +compileTestJava { + bindingXml = "${projectDir}/src/test/resources/org/springframework/oxm/jibx/binding.xml" + + doLast() { + project.ant { + taskdef(name: "jibx", + classname: "org.jibx.binding.ant.CompileTask", + classpath: configurations.jibx.asPath) + + jibx(verbose: true, load: true, binding: bindingXml) { + classpathset(dir: sourceSets.test.output.classesDir) { + include(name: "**/jibx/**/*") + } + } + } + } +} diff --git a/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTests.java b/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTests.java index 70bd3375df..42c25f9b31 100644 --- a/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTests.java +++ b/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxMarshallerTests.java @@ -29,7 +29,12 @@ import static org.custommonkey.xmlunit.XMLAssert.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -@org.junit.Ignore // TODO fix this issue https://gist.github.com/1174579 +/** + * @author Arjen Poutsma + * + * NOTE: These tests fail under Eclipse/IDEA because JiBX binding does + * not occur by default. The Gradle build should succeed, however. + */ public class JibxMarshallerTests extends AbstractMarshallerTests { @Override diff --git a/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxUnmarshallerTests.java b/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxUnmarshallerTests.java index a6a8315cdf..3b19ec620c 100644 --- a/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxUnmarshallerTests.java +++ b/org.springframework.oxm/src/test/java/org/springframework/oxm/jibx/JibxUnmarshallerTests.java @@ -25,8 +25,10 @@ import org.springframework.oxm.Unmarshaller; /** * @author Arjen Poutsma + * + * NOTE: These tests fail under Eclipse/IDEA because JiBX binding does + * not occur by default. The Gradle build should succeed, however. */ -@org.junit.Ignore // TODO fix this issue https://gist.github.com/1174575 public class JibxUnmarshallerTests extends AbstractUnmarshallerTests { @Override