IntershopCommunicationsAG/jaxb-gradle-plugin

Failed to read schema document (XJC cannot find path to xsd)

Closed this issue · 2 comments

When I am running the jaxbJavaGen task on a feature branch of my application I get the following error:

:my-project:jaxbJavaGenPayload[ant:xjc] [ERROR] schema_reference.4: Failed to read schema document 'file:/jenkins/workspace/BUILD_my-project/feature%2Fsome-feature-branch/my-project/src/main/resources/wsdl/myPayload.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
[ant:xjc] unknown location
[ant:xjc] 
 FAILED
Caused by: : unable to parse the schema. Error messages should have been provided
	at com.sun.tools.xjc.XJC2Task._doXJC(XJC2Task.java:520)
	at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:457)
	at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:380)

The reason seems to be that the path to the project (and therefore to the xsd) contains the URL encoded slash %2F, which is to the way that Jenkins checks out the branches.
This plugin passes the schema location to the XJC task using getSchemaFile().absolutePath.

But there seems to be an error in XJC. It says in the documentation that you can pass a file a URL or a directory, but when passing a file path it is converted to a URL. This conversion seems to be broken as special characters are not correctly handled.
When converting the file path .../feature%2Fsome-feature-branch/... to a URL the correct result should be file:.../feature%252Fsome-feature-branch/...
Maybe they are using the deprecated file.toURL() which returns a wrong URL, where the correct call should be file.toURI().toURL().

This gradle plugin could implement a simple workaround to avoid this bug in XJC, by calling getSchemaFile().toURI().toURL().toExternalForm().

Or maybe there is a fixed version of jaxb-jxc?

I tried to find out the code block where the wrong conversion from File to URL is made, but couldn't really make out the wrong code easily. It seems the XJC library, when called from Java, only accepts Files, no URLs.

Anyhow, I discovered more tools that have problems with such paths. Also I am not the only Jenkins user who complained about the % sign in the workspace path. Maybe they will fix this. In the meantime, I found a way to define a custom workspace path, so the problem does not happen any more.

From my understanding this issue can be closed as it is not caused directly by the plugin.

Only files are supported und tested by the plugin.