• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

rackerlabs/gradle-jaxb-plugin: Gradle plugin to ease projects that use xsds and ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

rackerlabs/gradle-jaxb-plugin

开源软件地址(OpenSource Url):

https://github.com/rackerlabs/gradle-jaxb-plugin

开源编程语言(OpenSource Language):

Groovy 100.0%

开源软件介绍(OpenSource Introduction):

gradle-jaxb-plugin

IMPORTANT PLUGIN ID CHANGES

This plugin is an update to the original project this was forked from. We acknowledge and are grateful to these developers for their contributions to open source. You can find the source code of their original using the forked from link of this project. In compliance with the license chosen by the original author, we are publishing this modified version since they have not kept up with the maintenance needs of the community.

To prevent possible collisions and/or confusion if the original author decides to accept our PR’s or to simply begin anew, we have changed the id and package names.

In compliance with the gradle plugin submission guidelines, the plugin’s id was changed from com.github.jacobono.jaxb to org.openrepose.gradle.plugins.jaxb. This affects how you apply the plugin (apply plugin: 'org.openrepose.gradle.plugins.jaxb').

This Gradle plugin defines some conventions for XSD projects and provides some processing to ease some of the maintenance of these projects by:

  • Hooking in ant tasks to parse the XSD’s with the xjc task.

  • Generates code from XSD’s per unique namespace.

  • Generates an xsd dependency tree, to parse namespaces in their order of dependencies, from the base namespaces up.

  • Generating an episode file for every unique namespace in a set of xsd files.

  • Defining a convention to optionally generate episode files.

  • Ability to define xsd projects to depend on one another, so that when parsing, what a project depends on is also parsed.

Using The Plugin

See this plugin’s page in the gradle plugins repo.

Setting Up The JAXB Configurations

You need the jaxb configuration to run the xjc task, but that is the only task that requires an external dependency. If an XJC plugin is used, then simply add it to the dependencies to have it included.

Any version of jaxb that you care to use will work.

dependencies {
  jaxb 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
  jaxb 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
  xjc  'com.example:xjc-plugin:0.0.0'
}

Plugin Tasks

There are only two tasks.

  • xjc

    • runs xjc ant task on each .xsd in the dependency tree.

    • needs to be run manually.

  • xsd-dependency-tree

    • Builds a dependency tree from all .xsd files configured to be parsed.

    • Finds each unique namespace and groups files containing that namespace.

    • Analyzes xsd dependencies and places them in the correct place in the dependency tree. This ensures the namespaces can be parsed in order using the optionally generated episode files to bind. If the episode files generated, then other projects can bind to them from the namespace in the tree.

    • This keeps all namespaces decoupled and prevents a big episode blob containing everything that was parsed.

xjc depends on xsd-dependency-tree so you don’t need to run the tree task at all.

Plugin Conventions

There are two conventions that can be overridden and one is nested in the other.

The jaxb convention defines the conventions for the whole plugin, and the xjc convention defines the conventions for the xjc ant task.

You can change these defaults with a closure in your build script.

jaxb {
  ...
  xjc {
    ...
  }
}

JAXB Plugin Convention

These are the configurable parameters for the JAXB Plugin.

Table 1. JAXB Plugin Parameters

Parameter

Description

Default

Type

xsdDir

Defined by each project to tell the plugin where to find the .xsd files to parse.

${project.projectDir}/src/main/resources/schema

String

xsdIncludes

RegEx used to produce a List of files found in xsdDir to compile.

*/.xsd

String

episodesDir

All generated episode files go directly under here, no subfolders. (i.e. "build/generated-resources/episodes", "episodes", "schema/episodes", "xsd/episodes", "XMLSchema/episodes")

${project.buildDir}/generated-resources/episodes

String

bindingsDir

User defined binding files to pass into the xjc task. All files are directly under this folder, no subfolders. (i.e. "src/main/resources/schema", "bindings", "schema/bindings", "xsd/bindings", "XMLSchema/bindings")

${project.projectDir}/src/main/resources/schema

String

bindings

RegEx used to produce a List of customization files found in bindingsDir to bind with.

*/.xjb

String

XJC Convention

These are the configurable parameters for the JAXB Plugin’s XJC interactions.

Table 2. XJC Plugin Parameters

Parameter

Description

Default

Type

taskClassname

Enables a custom task classname to run the XJC task if something other than JAXB is desired. Useful if JAXB2 is required to be used.

com.sun.tools.xjc.XJCTask

String

destinationDir

The directory relative to project.rootDir where generated code will be written to.

In order to automatically remove previously generated sources, this directory is deleted whenever the Up To Date check fails. This should never point to a location under the main source directory.

${project.buildDir}/generated-sources/xjc

String

producesDir

This parameter has never been used by this plugin. It remains only for the purposes of backwards compatibility. Consider it deprecated and that it will be removed in a future release.

${project.buildDir}/generated-sources/xjc

String

generateEpisodeFiles

Enables the creation of the Episode files

true

boolean

extension

Run XJC compiler in extension mode

true

boolean

removeOldOutput

Only used with nested <produces> elements, when yes all files are deleted before XJC is run

yes

String

header

generates a header in each generated file

true

boolean

generatePackage

specify a package to generate to

Not Defined

String

args

List of extra String arguments to pass the xjc ant task. This is useful when activating JAXB2 plugins.

Empty String

List<String>

accessExternalSchema

Enables setting the new javax.xml.accessExternalSchema system property that causes the plugin to not work as expected under JSE8.

Implementation Specific

String

For more in depth description please see the XJC Ant Task documentation.

Examples

Default Example using JAXB

If the default conventions are used, then there is nothing to configure.

Default Example using JAXB2

Customized to use xjc plugins.

dependencies {
    jaxb "org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1"
    jaxb 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:1.11.1'
    jaxb 'org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.0.4'
    jaxb 'org.slf4j:slf4j-log4j12:1.7.25'
}

jaxb {
  xsdDir = "${project.projectDir}/some/folder"
  xjc {
    generateEpisodeFiles = false
    taskClassname        = "org.jvnet.jaxb2_commons.xjc.XJC2Task"
    generatePackage      = "com.company.example"
    args                 = ["-Xinheritance", "-Xannotate"]
  }
}

Defining The Plugin For All Projects

Create a convention for xsd projects to have a suffix of -schema, then it is easy to write:

subprojects { project ->
  if(project.name.endsWith("-schema")) {
    apply plugin: 'org.openrepose.gradle.plugins.jaxb'

    dependencies {
      jaxb 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
      jaxb 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
    }
  }
}

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:

subprojects { project ->
  if(Boolean.valueOf(project.getProperties().getOrDefault('doJAXB', 'false'))) {
    apply plugin: 'org.openrepose.gradle.plugins.jaxb'

    dependencies {
      jaxb 'org.glassfish.jaxb:jaxb-xjc:2.2.11'
      jaxb 'org.glassfish.jaxb:jaxb-runtime:2.2.11'
    }
  }
}

Other Features

Depend On Another Project

This lets gradle know that the xjc task of a project is dependent on the xjc task of another project. This can be achieved with:

dependencies {
  jaxb project(path: ':common', configuration: 'jaxb')
}

This expresses that xsd’s definitely depend on other xsd’s outside of their parent folder xsdDir.

This will run the xjc task on common before running the xjc task of of the project this is defined in.

Examples

You can find some small example projects using this plugin in the examples folder. Simply issue ../gradlew clean build from within it to run them all.

For a basic example of using this plugin with multiple sub-projects that have interactions, please see this test project.

For a real world example of this plugin, please visit the main Repose project.

Improvements

If you have an idea that would make something a little easier, we’d love to hear about it. If you think you can make this plugin better, then simply fork it like we did and submit a pull request.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
novoda/gradle-build-properties-plugin: Keep your secrets secret. External build ...发布时间:2022-06-12
下一篇:
palantir/gradle-gitsemver发布时间:2022-06-12
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap