Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify the FQCN of the XJC Ant task #24

Closed
henning-meinhardt opened this issue Jan 7, 2021 · 6 comments
Closed

Allow to specify the FQCN of the XJC Ant task #24

henning-meinhardt opened this issue Jan 7, 2021 · 6 comments

Comments

@henning-meinhardt
Copy link

It would be nice to have the FQCN of the XJC Ant task to be adjustable. Currently the plugin is hard wired to "com.sun.tools.xjc.XJCTask". I'd like to switch to "org.jvnet.jaxb2_commons.xjc.XJC2Task" instead to allow using modern plugins.

The plugin's task has a variable to check for already definied Ant task, preventing re-definition. But imho this is broken as the variable is never properly initialized. If that would work as expected I'd be able to define the XJC Ant task upfront and could adjust the FQCN on my own.

Anyway, a better approach seems to be adding a new property to the extension:
xjcGeneration {
xjcTaskClass = "org.jvnet.jaxb2_commons.xjc.XJC2Task"
schemas { ... }
}

Kind regards
Henning

@edeandrea
Copy link
Owner

Hi @henning-meinhardt thanks for the note and for using the plugin!

It isn't as simple as just adjusting the FQCN of the XJC ant task. The com.sun.tools.xjc.XJCTask has particular inputs that the plugin understands how to "wire" from the exposed DSL into those arguments that the task expects.

I'm not familiar with the jvnet XJC2Task and whether or not it has the same "contract" as the com.sun.tools one does. If it does, then yes this is easy. If not, then I'd have to figure out a way to make it work. I don't really want to get into the business of "wrapping" each and every implementation of an XJC task thats available out there on the internet.

Let me do some research & think about it a bit.

@henning-meinhardt
Copy link
Author

Hi, thanks for quick reply. For me, it did the job. I just added a parameter to set the FQCN and added the required dependencies to "xjr". The contract of the XJC task is compatible (maybe there are some edge cases, but commonly used params work exactly the same). I'm using the following:

xjc (
	"org.glassfish.jaxb:jaxb-xjc:${jaxbVersion}",
	"org.glassfish.jaxb:jaxb-runtime:${jaxbVersion}",
	"javax.xml.bind:jaxb-api:${jaxbVersion}",
	"javax.activation:activation:1.1.1",
	"commons-logging:commons-logging:1.1.1",
	"org.slf4j:slf4j-simple:${slf4jVersion}",

	// required at codegen time for JAXB2 XJC Ant Task as well as basic plugins (copyable, toString etc.)
	"org.jvnet.jaxb2_commons:jaxb2-basics:1.11.1",
	"org.jvnet.jaxb2_commons:jaxb2-basics-ant:1.11.1",

	// required at codegen time for namespace-prefix plugin (https://github.com/javaee/jaxb2-commons/tree/master/namespace-prefix)
	"org.jvnet.jaxb2_commons:jaxb2-namespace-prefix:1.3",

	// required at codegen time for fluent-api plugin (https://github.com/javaee/jaxb2-commons/tree/master/fluent-api)
	"net.java.dev.jaxb2-commons:jaxb-fluent-api:2.1.8",

	// required at codegen time for XEW plugin (https://github.com/dmak/jaxb-xew-plugin)
	"com.github.jaxb-xew-plugin:jaxb-xew-plugin:1.10",
	"org.jvnet.jaxb2_commons:jaxb2-basics-annotate:1.1.0",

	// required at codegen time for JSR 305 (@Nullable, @Nonnull) annotation support
	"com.google.code.findbugs:jsr305:3.0.2",
	"com.github.acmi:jaxb2-jsr305-plugin:1.0.0"
)

xjcGeneration {
	defaultAdditionalXjcOptions = [
		"encoding": "UTF-8",
		"extension": "true"
	]
	xjcTaskClass = "org.jvnet.jaxb2_commons.xjc.XJC2Task"      <---- added by me
	schemas {
		configuration {
			taskName = "xjcConfiguration"
			schemaRootDir = projectDir
			generatedOutputRootDir = file (generatedSourcesDir)
			schemaFile = "webapp/WEB-INF/res/configuration.xsd"
			bindingFile = "webapp/WEB-INF/res/configuration.xjb"
			additionalXjcCommandLineArgs = [
				"-Xjsr305": "", "-Xnamespace-prefix": "", "-Xxew": "", "-Xxew:instantiate": "lazy", "-Xfluent-api": "", "-Xcopyable": "",
			]
		}

As you can see there are quite some plugins involved, all of them working just as expected.

Or course it does not make sense to support each and every implementation, but i think the one mentioned is by far the most commonly used because most modern plugins are only compatible to this implementation but not the default one. For details see first answer to this issue: https://stackoverflow.com/questions/50669567/unrecognized-parameter-xsomeplugin-error-when-using-jaxb-xjc-plugins

@edeandrea
Copy link
Owner

Thanks for the detail! I will take a look over the next few days and see what I can do!

One thing - you shouldn't need to set "extension": "true" in the defaultAdditionalXjcOptions. The plugin does that by default (https://github.com/edeandrea/xjc-generation-gradle-plugin/blob/master/src/main/kotlin/com/github/edeandrea/xjcplugin/type/Xjc.kt#L164)

@edeandrea
Copy link
Owner

edeandrea commented Jan 7, 2021

Hi @henning-meinhardt I've published version 1.6 of this plugin which contains this capability. Please read the README for details on how to use it.

TL;DR;
It's pretty much exactly as you explained in your note - inside the xjcGeneration task is an attribute called xjcTaskClassName.

You can see an example in src/intTest/resources/com/github/edeandrea/xjcplugin/plugin/XjcPluginIntegrationTests/build.gradle

@henning-meinhardt
Copy link
Author

Hi Eric,

wow, thanks a lot for fixing this within the same day! checked it out and can confirm it's working perfectly!

kind regards
Henning

@edeandrea
Copy link
Owner

You're welcome! Glad it's working! You caught me on a day I had a few free cycles!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants