mklemm / jaxb-rich-contract-plugin

Implements some JAXB plugins to generate advanced contract scenarios from XSD
MIT License
67 stars 33 forks source link

Group-contract fails with cxf-codegen-plugin #59

Closed waldeinburg closed 6 months ago

waldeinburg commented 4 years ago

When using group-contracts with Maven cxf-codegen-plugin the build fails with the following BadCommandLineException (included below with the first line of the stack trace with -X Maven option set):

Error setting up group-interface-plugin javax.xml.xpath.XPathExpressionException: java.io.FileNotFoundException: /path/to/working/directory/null (No such file or directory)
    at com.kscs.util.plugins.xjc.GroupInterfacePlugin.generateDummyGroupUsages (GroupInterfacePlugin.java:218)

The plugin seems to collide with a hack in org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding:

        if (context.get(ToolConstants.CFG_NO_ADDRESS_BINDING) == null
            || context.get(ToolConstants.CFG_XJC_ARGS) != null) {
            try {
                // keep parseArguments happy, supply dummy required command-line
                // opts
                opts.addGrammar(new InputSource("null"));

The CFG_NO_ADDRESS_BINDING value is null and the CFG_XJC_ARGS is of course not null because it contains -Xgroup-contract. This means that GroupInterfacePlugin::generateDummyGroupUsages will receive one input source, the dummy "null" value, and then findIncludeMappings will crash.

This is a quite puzzling hack. It's not that there's no input schemas; everything builds fine when removing groupt-contract from the plugin list (leaving other arguments to trig the conditional above). Will you implement a workaround or should I report this as a bug to Apache CXF, trying to make them make another workaround for the supposed issue with parseArgument?

aSemy commented 3 years ago

I have the same problem. Thank you for finding out the cause.

I've created an issue https://issues.apache.org/jira/browse/CXF-8580

Do you know if there's a workaround?

I'm using

Here's the basics from my pom.xml


  <dependencies>
    ...

    <dependency>
      <groupId>org.apache.cxf.xjc-utils</groupId>
      <artifactId>cxf-xjc-runtime</artifactId>
      <version>${apache-cxf-xjc.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
    </dependency>
  </dependencies>
  ...

      <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>${apache-cxf-plugin.version}</version>
        <executions>
          <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>
              <defaultOptions>
                <noAddressBinding>true</noAddressBinding>
              </defaultOptions>
              <wsdlOptions>
                <wsdlOption>
                  <wsdl>${project.basedir}/src/main/resources/schemas/simple-schema.wsdl</wsdl>
                  <extraargs>
                    <extraarg>-xjc-Xts</extraarg>

                    <!-- This arg causes an error -->
                    <extraarg>-xjc-Xgroup-contract</extraarg>

                    <extraarg>-impl</extraarg>
                    <extraarg>-verbose</extraarg>
                    <extraarg>-xjc-verbose</extraarg>
                    <extraarg>-keep</extraarg>
                  </extraargs>
                </wsdlOption>
              </wsdlOptions>
            </configuration>
            <goals>
              <goal>wsdl2java</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>net.codesup.util</groupId>
            <artifactId>jaxb2-rich-contract-plugin</artifactId>
            <version>2.1.0</version>
          </dependency>
          <dependency>
            <groupId>org.apache.cxf.xjcplugins</groupId>
            <artifactId>cxf-xjc-ts</artifactId>
            <version>${apache-cxf-xjc.version}</version>
          </dependency>
        </dependencies>
      </plugin>
mklemm commented 6 months ago

Should be looking for an alternative way to determine the output path of generated group interfaces... Maybe try to filer out "null" grammars when scanning the schema tree...

mklemm commented 6 months ago

The root cause seems to be than an InputSource passed to an XPathExpression MUST have a valid SystemID pointing to a file or URI where the content is located. The WSDL tool spoils that.

mklemm commented 6 months ago

Fixed in 4.0.1-SNAPSHOT