diff --git a/.gitignore b/.gitignore index f91f853..8879387 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,65 @@ -build -*.class -.gradle \ No newline at end of file +## java specific +!.gitignore +*.iml +*.iws +*.ipr +*.lic +target +*/target +*/*/target + +## vim objects +*.swo +*.swp + +## Build helper scripts +*.bhs + +## Netbeans +catalog.xml +nbactions.xml + +## IntelliJ IDEA +*.iml +*.ipr +*.iws +.idea/ +local/ + +# Gradle bits from: https://github.com/github/gitignore/blob/master/Gradle.gitignore +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +## generic files to ignore +*~ +*.lock +*.DS_Store +*.swp +*.out +jmeter.log + +## rcman +rcman.conf +rcman.log +rsInstances +nodeNames +hosts.csv +automation/rcman/files/* +log.txt +/test/JavaApplication1/nbproject/private/ +/test/artifact-behavior-test/responseBody +/test/artifact-behavior-test/responseHeaders + +## Python +*.py[cod] +.Python + +## Eclipse +# eclipse specific git ignore +.project +.metadata +.classpath +.settings diff --git a/README.md b/README.md index 29f9fe1..7c818a0 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ new group id `com.github.jacobono` matches gradle plugin id. :boom: :collision: -## Using Gradle 2.1 plugins script block +## Using Gradle 2.10 plugins script block ```groovy plugins { id 'com.github.jacobono.jaxb' version '1.3.6' @@ -137,26 +137,25 @@ There are 4 overrideable defaults for this JAXB Plugin. These defaults are changed via the `jaxb` closure. * `xsdDir` - * **ALWAYS** relative to `project.rootDir` * Defined **by each** project to tell the plugin where to find the `.xsd` files to parse +* `xsdIncludes` + * the schemas to compile + * file name List of strings found in `xsdDir` + * The default glob pattern is `**/*.xsd` * `episodesDir` - * **ALWAYS** relative to `project.rootDir` - * i.e. _"episodes"_, _"schema/episodes"_, _"xsd/episodes"_, + * i.e. _"build/generated-resources/episodes"_, _"episodes"_, _"schema/episodes"_, _"xsd/episodes"_, _"XMLSchema/episodes"_ * **All** generated episode files go directly under here, no subfolders. * `bindingsDir` - * **ALWAYS** relative to `project.rootDir` - * i.e. "bindings", "schema/bindings", "xsd/bindings", + * i.e. "src/main/resources/schema", "bindings", "schema/bindings", "xsd/bindings", "XMLSchema/bindings" * User defined binding files to pass in to the `xjc` task * **All** files are directly under this folder, _no subfolders_. * `bindings` * customization files to bind with * file name List of strings found in `bindingsDir` - * if there are bindings present, xjc will be called once with the - glob pattern `**/*.xsd` to snag everything under `xsdDir`. Fixes - #27. + * The default glob pattern is `**/*.xjb` ## XJC Convention ## @@ -166,10 +165,10 @@ Several sensible defaults are defined to be passed into the | parameter | Description | default | type | | :--- | :---: | :---: | ---: | -|`destinationDir` _(R)_ | generated code will be written to this directory | `src/main/java` | `String` | +|`destinationDir` _(R)_ | generated code will be written to this directory | `${project.buildDir}/generated-sources/xjc` | `String` | |`extension` _(O)_ | Run XJC compiler in extension mode | `true` | `boolean` | |`header` _(O)_ | generates a header in each generated file | `true` | `boolean` | -|`producesDir` _(O)(NI)_ | aids with XJC up-to-date check | `src/main/java` | `String` | +|`producesDir` _(O)(NI)_ | aids with XJC up-to-date check | `${project.buildDir}/generated-sources/xjc` | `String` | |`generatePackage` _(O)_ | specify a package to generate to | **none** | `String` | |`args` _(O)_ | List of strings for extra arguments to pass that aren't listed | **none** | `List` | |`removeOldOutput` _(O)_ | Only used with nested `` elements, when _'yes'_ all files are deleted before XJC is run | _'yes'_ | `String` | @@ -185,9 +184,8 @@ substitute the version you are using. ### destinationDir ### -`destinationDir` is relative to `project.projectDir`. It is -defaulted to `src/main/java`, but can be set to anywhere in -`project.projectDir`. +`destinationDir` is relative to `project.rootDir`. It is defaulted to +`${project.buildDir}/generated-sources/xjc`, but can be set to anywhere. ### producesDir ### @@ -213,7 +211,7 @@ _(per project)_ is the `xsdDir`, and jaxb dependencies as described above. ```groovy jaxb { - xsdDir = "schema/folder1" + xsdDir = "${project.projectDir}/schema/folder1" } ``` @@ -231,7 +229,7 @@ dependencies { } jaxb { - xsdDir = "some/folder" + xsdDir = "${project.projectDir}/some/folder" xjc { taskClassname = "org.jvnet.jaxb2_commons.xjc.XJC2Task" generatePackage = "com.company.example" @@ -262,6 +260,23 @@ subproject { project -> applying the plugin to all schema projects. +Another way to do this is by adding a boolean property to the +`gradle.properties` file in the sub-projects. You can then use it this way: + +```groovy +subproject { project -> + if(Boolean.valueOf(project.getProperties().getOrDefault('doJAXB', 'false'))) { + apply plugin: 'com.github.jacobono.jaxb' + + dependencies { + jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.7-b41' + jaxb 'com.sun.xml.bind:jaxb-impl:2.2.7-b41' + jaxb 'javax.xml.bind:jaxb-api:2.2.7' + } + } +} +``` + Other Features ============== diff --git a/build.gradle b/build.gradle index 5569386..f4d93c7 100644 --- a/build.gradle +++ b/build.gradle @@ -36,7 +36,7 @@ test { groovydoc { docTitle = "Gradle XSD Plugin" link("http://groovy.codehaus.org/gapi/", "groovy.", "org.codehaus.groovy.") - link("http://doc.oracle.com/javase/7/docs/api/", "java.") + link("http://docs.oracle.com/javase/8/docs/api/", "java.") link("http://google-guice.googlecode.com/svn/trunk/javadoc/", "com.google.") link("http://www.gradle.org/docs/current/javadoc/", "org.gradle.", "org.gradle.api.") } diff --git a/examples/build.gradle b/examples/build.gradle index 03cef62..fe6b2cc 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -1,48 +1,49 @@ buildscript { - // uncomment for local testing - //********************************************************** - // repositories { - // flatDir { dirs '../build/libs' } - // mavenCentral() - // jcenter() - // } - - // dependencies { - // classpath ':gradle-jaxb-plugin-1.3.6' - // classpath 'com.google.inject:guice:3.0' - // classpath 'com.github.jacobono:gradle-xsd-wsdl-slurping:1.1.2' - // } - //********************************************************** - - // use artifacts from bintray - //****************************************************** + //******************************************************************************** + // uncomment for local testing + //-------------------------------------------------------------------------------- repositories { + flatDir { dirs '../build/libs' } // gradle unversionedJar + //flatDir { dirs "/${gradle.gradleHomeDir}/lib/plugins" } // gradle installPlugin jcenter() mavenCentral() } dependencies { - classpath 'com.github.jacobono.plugins:gradle-jaxb-plugin:1.3.6' + classpath ':gradle-jaxb-plugin' + classpath 'com.google.inject:guice:3.0' + classpath 'com.github.jacobono:gradle-xsd-wsdl-slurping:1.1.2' } + //******************************************************************************** + + //******************************************************************************** + // use artifacts from bintray + //-------------------------------------------------------------------------------- + //repositories { + // jcenter() + // mavenCentral() + //} + // + //dependencies { + // classpath 'com.github.jacobono:gradle-jaxb-plugin:1.3.6' + //} + //******************************************************************************** } allprojects { - - repositories { + repositories { mavenCentral() } - } subprojects { project -> - - if(project.name.endsWith("-schema")) { + if(project.name.endsWith("-schema")) { apply plugin: 'com.github.jacobono.jaxb' - - dependencies { - jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.7-b41' //jaxws 2.2.6 uses jaxb 2.2.5, but can't dL 2.2.5 from maven the pom is off TODO + dependencies { + // TODO: jaxws 2.2.6 uses jaxb 2.2.5, but can't dL 2.2.5 from maven the pom is off + jaxb 'com.sun.xml.bind:jaxb-xjc:2.2.7-b41' jaxb 'com.sun.xml.bind:jaxb-impl:2.2.7-b41' jaxb 'javax.xml.bind:jaxb-api:2.2.7' } } -} \ No newline at end of file +} diff --git a/examples/hello-world-bindings-schema/hello-world-bindings-schema.gradle b/examples/hello-world-bindings-schema/hello-world-bindings-schema.gradle index a9ed3fe..b460148 100644 --- a/examples/hello-world-bindings-schema/hello-world-bindings-schema.gradle +++ b/examples/hello-world-bindings-schema/hello-world-bindings-schema.gradle @@ -6,11 +6,12 @@ dependencies { } jaxb { - xsdDir = "schema/multiple" - bindingsDir = "schema/multiple/xjb" + xsdDir = "${project.rootDir}/schema/multiple" + bindingsDir = "${project.rootDir}/schema/multiple/xjb" bindings = ["xsd-bindings.xjb"] xjc { taskClassname = "org.jvnet.jaxb2_commons.xjc.XJC2Task" args = ["-Xannotate"] + destinationDir = "${project.buildDir}/generated-sources/xjc" } } \ No newline at end of file diff --git a/examples/hello-world-import-schema/hello-world-import-schema.gradle b/examples/hello-world-import-schema/hello-world-import-schema.gradle index 8d171b4..264a2f8 100644 --- a/examples/hello-world-import-schema/hello-world-import-schema.gradle +++ b/examples/hello-world-import-schema/hello-world-import-schema.gradle @@ -1,5 +1,8 @@ version = "0.1" jaxb { - xsdDir = "schema/Import" + xsdDir = "${project.rootDir}/schema/Import" + xjc { + destinationDir = "${project.buildDir}/generated-sources/xjc" + } } \ No newline at end of file diff --git a/examples/hello-world-schema/hello-world-schema.gradle b/examples/hello-world-schema/hello-world-schema.gradle index 324bdda..a5a3d5f 100644 --- a/examples/hello-world-schema/hello-world-schema.gradle +++ b/examples/hello-world-schema/hello-world-schema.gradle @@ -1,5 +1,8 @@ version = "0.1" jaxb { - xsdDir = "schema/HelloWorld" + xsdDir = "${project.rootDir}/schema/HelloWorld" + xjc { + destinationDir = "${project.buildDir}/generated-sources/xjc" + } } \ No newline at end of file diff --git a/examples/hello-world-spaces-dir-schema/hello-world-spaces-dir-schema.gradle b/examples/hello-world-spaces-dir-schema/hello-world-spaces-dir-schema.gradle index 6c31c19..d66637c 100644 --- a/examples/hello-world-spaces-dir-schema/hello-world-spaces-dir-schema.gradle +++ b/examples/hello-world-spaces-dir-schema/hello-world-spaces-dir-schema.gradle @@ -1,6 +1,9 @@ version = "0.1" jaxb { - xsdDir = "schema/HelloWorld" - episodesDir = "schema/space episodes" + xsdDir = "${project.rootDir}/schema/HelloWorld" + episodesDir = "${project.buildDir}/generated-resources/schema/space episodes" + xjc { + destinationDir = "${project.buildDir}/generated-sources/xjc" + } } \ No newline at end of file diff --git a/src/main/groovy/org/gradle/jacobo/plugins/JaxbPlugin.groovy b/src/main/groovy/org/gradle/jacobo/plugins/JaxbPlugin.groovy index b8b4db6..2889176 100644 --- a/src/main/groovy/org/gradle/jacobo/plugins/JaxbPlugin.groovy +++ b/src/main/groovy/org/gradle/jacobo/plugins/JaxbPlugin.groovy @@ -2,31 +2,27 @@ package org.gradle.jacobo.plugins import com.google.inject.Guice import com.google.inject.Injector - -import org.gradle.api.Project import org.gradle.api.Plugin - -import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.artifacts.Configuration -import org.gradle.api.logging.Logging import org.gradle.api.logging.Logger - -import org.gradle.jacobo.plugins.task.JaxbDependencyTree -import org.gradle.jacobo.plugins.task.JaxbXjc +import org.gradle.api.logging.Logging +import org.gradle.api.plugins.JavaPlugin +import org.gradle.jacobo.plugins.ant.AntXjc +import org.gradle.jacobo.plugins.converter.NamespaceToEpisodeConverter import org.gradle.jacobo.plugins.extension.JaxbExtension import org.gradle.jacobo.plugins.extension.XjcExtension -import org.gradle.jacobo.plugins.guice.JaxbPluginModule -import org.gradle.jacobo.schema.guice.DocSlurperModule - import org.gradle.jacobo.plugins.factory.XsdDependencyTreeFactory +import org.gradle.jacobo.plugins.guice.JaxbPluginModule +import org.gradle.jacobo.plugins.resolver.EpisodeDependencyResolver import org.gradle.jacobo.plugins.resolver.ExternalDependencyResolver import org.gradle.jacobo.plugins.resolver.NamespaceResolver -import org.gradle.jacobo.schema.factory.DocumentFactory -import org.gradle.jacobo.plugins.ant.AntXjc -import org.gradle.jacobo.plugins.converter.NamespaceToEpisodeConverter import org.gradle.jacobo.plugins.resolver.XjcResolver -import org.gradle.jacobo.plugins.resolver.EpisodeDependencyResolver +import org.gradle.jacobo.plugins.task.JaxbDependencyTree +import org.gradle.jacobo.plugins.task.JaxbXjc +import org.gradle.jacobo.schema.factory.DocumentFactory +import org.gradle.jacobo.schema.guice.DocSlurperModule /** * Defines the Jaxb Plugin. @@ -36,10 +32,11 @@ class JaxbPlugin implements Plugin { static final String JAXB_XSD_DEPENDENCY_TREE_TASK = 'xsd-dependency-tree' static final String JAXB_XJC_TASK = 'xjc' static final String JAXB_CONFIGURATION_NAME = 'jaxb' + static final String XJC_CONFIGURATION_NAME = 'xjc' static final Logger log = Logging.getLogger(JaxbPlugin.class) - private JaxbExtension extension + private JaxbExtension jaxbExtension /** * Entry point for plugin. @@ -51,8 +48,9 @@ class JaxbPlugin implements Plugin { Injector injector = Guice.createInjector([new JaxbPluginModule(), new DocSlurperModule()]) configureJaxbExtension(project) configureJaxbConfiguration(project) - JaxbDependencyTree jnt = configureJaxbDependencyTree(project, extension, injector) - configureJaxbXjc(project, extension, jnt, injector) + JaxbDependencyTree jnt = configureJaxbDependencyTree(project, jaxbExtension, injector) + configureXjcConfiguration(project) + configureJaxbXjc(project, jaxbExtension, jnt, injector) } /** @@ -62,22 +60,24 @@ class JaxbPlugin implements Plugin { * @see org.gradle.jacobo.plugins.extension.JaxbExtension * @see org.gradle.jacobo.plugins.extension.XjcExtension */ - private void configureJaxbExtension(final Project project) { - extension = project.extensions.create("jaxb", JaxbExtension, project) - extension.with { - xsdDir = "schema" - episodesDir = "schema/episodes" - bindingsDir = "schema/bindings" - bindings = [] + private void configureJaxbExtension(final Project project) { + jaxbExtension = project.extensions.create('jaxb', JaxbExtension, project) + jaxbExtension.with { + xsdDir = "${project.projectDir}/src/main/resources/schema" + xsdIncludes = ['**/*.xsd'] + episodesDir = "${project.buildDir}/generated-resources/episodes" + bindingsDir = "${project.projectDir}/src/main/resources/schema" + bindings = ['**/*.xjb'] } - def xjcExtension = project.jaxb.extensions.create("xjc", XjcExtension) + def xjcExtension = project.jaxb.extensions.create('xjc', XjcExtension) xjcExtension.with { - taskClassname = 'com.sun.tools.xjc.XJCTask' - destinationDir = "src/main/java" - producesDir = "src/main/java" + taskClassname = 'com.sun.tools.xjc.XJC2Task' + destinationDir = "${project.buildDir}/generated-sources/xjc" + producesDir = "${project.buildDir}/generated-sources/xjc" extension = true removeOldOutput = 'yes' header = true + accessExternalSchema = 'file' } } @@ -94,6 +94,19 @@ class JaxbPlugin implements Plugin { } } + /** + * Configures this plugins {@code xjc} configuration. + * + * @param project This plugins gradle project + */ + private void configureXjcConfiguration(final Project project) { + project.configurations.create(XJC_CONFIGURATION_NAME) { + visible = true + transitive = true + description = "The JAXB XJC plugin libraries to be used for this project." + } + } + /** * Adds a dependency on tasks with the specified name in other projects. The other projects are determined from * project lib dependencies using the specified configuration name. These may be projects this project depends on or @@ -133,9 +146,11 @@ class JaxbPlugin implements Plugin { "and find all unique namespaces, create a namespace graph and parse in " + "the graph order with jaxb" jnt.group = JAXB_TASK_GROUP - jnt.conventionMapping.xsds = { project.fileTree( dir: - new File(project.rootDir, - project.jaxb.xsdDir), include: '**/*.xsd') + jnt.conventionMapping.xsds = { + project.fileTree( + dir: new File((String)project.jaxb.xsdDir), + include: project.jaxb.xsdIncludes + ) } jnt.conventionMapping.docFactory = { injector.getInstance(DocumentFactory.class) @@ -161,7 +176,7 @@ class JaxbPlugin implements Plugin { * * @param project This plugins gradle project * @param jaxb This plugins extension - * @param jnt This plugins {@code xsd-dependency-tree} task (dependended upon) + * @param jnt This plugins {@code xsd-dependency-tree} task (depended upon) * @param injector This pluings Guice injector * @return this plugins xjc tree task, configured * @see org.gradle.jacobo.plugins.task.JaxbXjc @@ -176,26 +191,33 @@ class JaxbPlugin implements Plugin { xjc.dependsOn(jnt) xjc.conventionMapping.manager = { project.jaxb.dependencyGraph } xjc.conventionMapping.episodeDirectory = { - new File(project.rootDir, project.jaxb.episodesDir) } + new File((String)project.jaxb.episodesDir) + } xjc.conventionMapping.bindings = { // empty filecollection if no bindings listed, so that // files.files == empty set project.jaxb.bindings.isEmpty() ? project.files() : - project.fileTree(dir:new File(project.rootDir, project.jaxb.bindingsDir), - include: project.jaxb.bindings) + project.fileTree( + dir:new File((String)project.jaxb.bindingsDir), + include: project.jaxb.bindings + ) } // these two (generatedFilesDirectory and schemasDirectory) // are here so that gradle can check if anything // has changed in these folders and run this task again if so // they serve no other purpose than this xjc.conventionMapping.generatedFilesDirectory = { - new File(project.projectDir, project.jaxb.xjc.destinationDir) } + new File((String)project.jaxb.xjc.destinationDir) + } // this is here in case there are bindings present, in which case a dependency tree type // evaluation just won't work. xjc.conventionMapping.xsds = { - project.fileTree(dir: new File(project.rootDir, project.jaxb.xsdDir), include: '**/*.xsd') } - xjc.conventionMapping.schemasDirectory = { - new File(project.rootDir, project.jaxb.xsdDir) } + project.fileTree( + dir: new File((String)project.jaxb.xsdDir), + include: project.jaxb.xsdIncludes + ) + } + xjc.conventionMapping.schemasDirectory = { new File((String)project.jaxb.xsdDir) } xjc.conventionMapping.xjc = { injector.getInstance(AntXjc.class) } xjc.conventionMapping.episodeConverter = { injector.getInstance(NamespaceToEpisodeConverter.class) diff --git a/src/main/groovy/org/gradle/jacobo/plugins/ant/AntXjc.groovy b/src/main/groovy/org/gradle/jacobo/plugins/ant/AntXjc.groovy index 9c7b765..b566b16 100644 --- a/src/main/groovy/org/gradle/jacobo/plugins/ant/AntXjc.groovy +++ b/src/main/groovy/org/gradle/jacobo/plugins/ant/AntXjc.groovy @@ -35,26 +35,32 @@ class AntXjc implements AntExecutor { public void execute(AntBuilder ant, Object... arguments) { XjcExtension extension = arguments[0] def classpath = arguments[1] - def xsds = arguments[2] - def bindings = arguments[3] - def episodes = arguments[4] - def episodeFile = arguments[5] + def pluginsPath = arguments[2] + def xsds = arguments[3] + def bindings = arguments[4] + def episodes = arguments[5] + def episodeFile = arguments[6] - log.info("xjc task is being passed these arguments: Plugin Extension '{}', classpath '{}', xsds '{}', bindings '{}', episodes '{}', episodeFile '{}'", - arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5]) + log.info("xjc task is being passed these arguments: Plugin Extension '{}', classpath '{}', pluginsPath '{}', xsds '{}', bindings '{}', episodes '{}', episodeFile '{}'", + extension, classpath, pluginsPath, xsds, bindings, episodes, episodeFile) ant.taskdef (name : 'xjc', classname : extension.taskClassname, classpath : classpath) def args = [destdir : extension.destinationDir, - extension : extension.extension, + extension : extension.extension, removeOldOutput : extension.removeOldOutput, header : extension.header] if (extension.generatePackage) { args << [package : extension.generatePackage] } log.info("xjc ant task is being passed these arguments: '{}'", args) + if(extension.accessExternalSchema == null) { + System.clearProperty('javax.xml.accessExternalSchema') + } else { + System.setProperty('javax.xml.accessExternalSchema', extension.accessExternalSchema) + } ant.xjc(args) { //TODO maybe should put the produces in there? //produces (dir : destinationDirectory) @@ -62,6 +68,8 @@ class AntXjc implements AntExecutor { bindings.addToAntBuilder(ant, 'binding', FileCollection.AntType.FileSet) episodes.addToAntBuilder(ant, 'binding', FileCollection.AntType.FileSet) // ant's arg line is space delimited, won't work with spaces + arg(value : "-classpath") + arg(value : "$pluginsPath") arg(value : "-episode") arg(value : "$episodeFile") for (String val : extension.args) { diff --git a/src/main/groovy/org/gradle/jacobo/plugins/extension/JaxbExtension.groovy b/src/main/groovy/org/gradle/jacobo/plugins/extension/JaxbExtension.groovy index 52f217b..ddb6223 100644 --- a/src/main/groovy/org/gradle/jacobo/plugins/extension/JaxbExtension.groovy +++ b/src/main/groovy/org/gradle/jacobo/plugins/extension/JaxbExtension.groovy @@ -18,6 +18,11 @@ class JaxbExtension { */ String xsdDir + /** + * User defined list of RegEx strings to include from the {@code xsdDir}. + */ + List xsdIncludes + /** * Folder name (under {@link org.gradle.api.Project#getRootDir()}) containing * user defined binding files to bind during the {@code xjc} task. diff --git a/src/main/groovy/org/gradle/jacobo/plugins/extension/XjcExtension.groovy b/src/main/groovy/org/gradle/jacobo/plugins/extension/XjcExtension.groovy index fe6c313..034901c 100644 --- a/src/main/groovy/org/gradle/jacobo/plugins/extension/XjcExtension.groovy +++ b/src/main/groovy/org/gradle/jacobo/plugins/extension/XjcExtension.groovy @@ -13,8 +13,8 @@ class XjcExtension { /** * Destination directory for the generated output from the {@code xjc} task. - * Path is relative to this individual projects directory NOT the root - * directory. + * If the Path is not absolute, then it is assumed to be relative to this + * projects root directory. * See jaxb ant task */ String destinationDir @@ -56,4 +56,9 @@ class XjcExtension { */ List args = [] + /** + * The value to be used for the JVM System property {@code javax.xml.accessExternalSchema} + * See JAXP Properties + */ + String accessExternalSchema } diff --git a/src/main/groovy/org/gradle/jacobo/plugins/task/JaxbXjc.groovy b/src/main/groovy/org/gradle/jacobo/plugins/task/JaxbXjc.groovy index efdb7ff..467e6fa 100644 --- a/src/main/groovy/org/gradle/jacobo/plugins/task/JaxbXjc.groovy +++ b/src/main/groovy/org/gradle/jacobo/plugins/task/JaxbXjc.groovy @@ -37,7 +37,7 @@ class JaxbXjc extends DefaultTask { /** * Directory where the generated java files from xjc would go - * Usually {@code /src/main/java} + * Usually {@code /build/generated-sources/xjc} */ @OutputDirectory File generatedFilesDirectory @@ -126,9 +126,11 @@ class JaxbXjc extends DefaultTask { def xjc(xsds, episodes, episodeFile) { def jaxbConfig = project.configurations[JaxbPlugin.JAXB_CONFIGURATION_NAME] + def xjcConfig = project.configurations[JaxbPlugin.XJC_CONFIGURATION_NAME] log.debug("episodes are '{}' is empty '{}'", episodes, episodes.isEmpty()) - getXjc().execute(ant, project.jaxb.xjc, jaxbConfig.asPath, project.files(xsds), - getBindings(), project.files(episodes), episodeFile) + new File((String)project.jaxb.xjc.destinationDir).mkdirs() + getXjc().execute(ant, project.jaxb.xjc, jaxbConfig.asPath, xjcConfig.asPath, project.files(xsds), + getBindings(), project.files(episodes), episodeFile) } def getEpisodeFile(xsdNamespace) { diff --git a/src/test/groovy/org/gradle/jacobo/plugins/JaxbPluginSpec.groovy b/src/test/groovy/org/gradle/jacobo/plugins/JaxbPluginSpec.groovy index 83c075b..e761d62 100644 --- a/src/test/groovy/org/gradle/jacobo/plugins/JaxbPluginSpec.groovy +++ b/src/test/groovy/org/gradle/jacobo/plugins/JaxbPluginSpec.groovy @@ -10,38 +10,40 @@ import org.gradle.jacobo.plugins.task.JaxbXjc class JaxbPluginSpec extends ProjectTaskSpecification { - def rootFolder = getFileFromResourcePath("/test-project") + def rootFolder = getFileFromResourcePath('/test-project') def setupSpec() { - def resourcesRoot = getFileFromResourcePath("/") - def rootFolder = new File(resourcesRoot, "test-project") + def resourcesRoot = getFileFromResourcePath('/') + def rootFolder = new File(resourcesRoot, 'test-project') rootFolder.mkdir() } def cleanupSpec() { - def rootFolder = getFileFromResourcePath("/test-project") + def rootFolder = getFileFromResourcePath('/test-project') rootFolder.delete() } def "applies Java plugin and adds extension object"() { expect: - project.plugins.getPlugin("java") instanceof JavaPlugin + project.plugins.getPlugin('java') instanceof JavaPlugin with(project.jaxb) { it instanceof JaxbExtension - xsdDir == "schema" - episodesDir == "schema/episodes" - bindingsDir == "schema/bindings" - bindings == [] + xsdDir == "${project.projectDir}/src/main/resources/schema" + xsdIncludes == ['**/*.xsd'] + episodesDir == "${project.buildDir}/generated-resources/episodes" + bindingsDir == "${project.projectDir}/src/main/resources/schema" + bindings == ['**/*.xjb'] with(xjc) { - destinationDir == "src/main/java" - producesDir == "src/main/java" - extension == 'true' - removeOldOutput == 'yes' - header == true + destinationDir == "${project.buildDir}/generated-sources/xjc" + producesDir == "${project.buildDir}/generated-sources/xjc" + extension == 'true' + removeOldOutput == 'yes' + header == true + accessExternalSchema == 'file' } } } - def "adds confiugration to this project"() { + def "adds configuration to this project"() { when: def jaxb = project.configurations.getByName( JaxbPlugin.JAXB_CONFIGURATION_NAME) @@ -49,7 +51,7 @@ class JaxbPluginSpec extends ProjectTaskSpecification { then: jaxb.visible == true jaxb.transitive == true - jaxb.description == "The JAXB XJC libraries to be used for this project." + jaxb.description == 'The JAXB XJC libraries to be used for this project.' } def "contains 2 tasks, xjc task depends on tree graph task"() { @@ -58,7 +60,7 @@ class JaxbPluginSpec extends ProjectTaskSpecification { def dependencyTask = project.tasks['xsd-dependency-tree'] then: - [xjcTask, dependencyTask]*.group == ["parse", "parse"] + [xjcTask, dependencyTask]*.group == ['parse', 'parse'] dependencyTask instanceof JaxbDependencyTree xjcTask instanceof JaxbXjc xjcTask.taskDependencies.getDependencies(xjcTask)*.path as Set == @@ -73,8 +75,8 @@ class JaxbPluginSpec extends ProjectTaskSpecification { rootProject).build() def lastProject = ProjectBuilder.builder().withName('last').withParent( rootProject).build() - commonProject.apply(plugin: "com.github.jacobono.jaxb") - lastProject.apply(plugin: "com.github.jacobono.jaxb") + commonProject.apply(plugin: 'com.github.jacobono.jaxb') + lastProject.apply(plugin: 'com.github.jacobono.jaxb') lastProject.dependencies { compile commonProject diff --git a/src/test/groovy/org/gradle/jacobo/plugins/factory/XsdDependencyTreeFactorySpec.groovy b/src/test/groovy/org/gradle/jacobo/plugins/factory/XsdDependencyTreeFactorySpec.groovy index 2dbaef3..7e5e113 100644 --- a/src/test/groovy/org/gradle/jacobo/plugins/factory/XsdDependencyTreeFactorySpec.groovy +++ b/src/test/groovy/org/gradle/jacobo/plugins/factory/XsdDependencyTreeFactorySpec.groovy @@ -80,7 +80,7 @@ class XsdDependencyTreeFactorySpec extends NamespaceFixture { and: "get expecations for tree root and addChildren" def noDeps = getBaseNamespaces(baseNamespaces) - def expectations = addChildrenExpectations(addChildrenExpectations) + def expectations = addChildrenExpectations(addChildrenExpectationValues) and: "stub out manager getter calls" stubManagerGetCurrentRow(currentRows) @@ -110,7 +110,7 @@ class XsdDependencyTreeFactorySpec extends NamespaceFixture { "RelatedAncestorDependencyScheme", "UnRelatedAncestorDependencyScheme"] baseNamespaces = ["xsd1", "xsd2"] - addChildrenExpectations << [ + addChildrenExpectationValues << [ [["xsd3":["xsd1"],"xsd4":["xsd2"]], ["xsd5":["xsd3"],"xsd6":["xsd4"]]], [["xsd3":["xsd1"], "xsd4":["xsd1", "xsd2"], "xsd5":["xsd2"]], ["xsd6":["xsd3"], "xsd7":["xsd3"], "xsd8":["xsd4", "xsd5"], diff --git a/src/test/groovy/org/gradle/jacobo/plugins/resolver/EpisodeDependencyResolverSpec.groovy b/src/test/groovy/org/gradle/jacobo/plugins/resolver/EpisodeDependencyResolverSpec.groovy index fce3426..00cf088 100644 --- a/src/test/groovy/org/gradle/jacobo/plugins/resolver/EpisodeDependencyResolverSpec.groovy +++ b/src/test/groovy/org/gradle/jacobo/plugins/resolver/EpisodeDependencyResolverSpec.groovy @@ -12,7 +12,7 @@ class EpisodeDependencyResolverSpec extends TreeFixture { def resolver = new EpisodeDependencyResolver() - def episodesDir = new File("/schemas/episodes") + def episodesDir = new File('/build/generated-resources/episodes') def externalNamespaces = ["E1", "E2", "E3", "E4"] def converter = Mock(NamespaceToEpisodeConverter)