mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
106 stars 77 forks source link

Missing XSD includes/excludes pattern for xjc goal #58

Closed dmak closed 6 years ago

dmak commented 7 years ago

Suppose in xsd folder I have several XSD files, plus XML files. The following configuration causes problem:

<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3</version>
...
<configuration>
    <sources>
        <source>xsd</source>
    </sources>

The output is:

[DEBUG] Accepted configured sources [D:\test-plugin\xsd]
[DEBUG]  [1 existing sources] ...
[DEBUG]    1/1: D:\test-plugin\xsd
[DEBUG]  ... End [1 existing sources]
[DEBUG] Accepted file [D:\test-plugin\xsd\different-namespaces-entries.xsd]
[DEBUG] CandidateString [D:\test-plugin\xsd\different-namespaces.xml] matched pattern [(\p{javaLetterOrDigit}|\p{Punct})+\.xml]
[DEBUG] Accepted file [D:\test-plugin\xsd\different-namespaces.xml]
[DEBUG] Accepted file [D:\test-plugin\xsd\different-namespaces.xsd]
[DEBUG] 
+=================== [Filtered sources]
|
| 2 Exclude patterns:
| [1/2]: Filter [PatternFileFilter]
|        Accept on match: [true]
|        Initialized    : [true]
|        3 regularExpressions :
|         [1/3]: (\p{javaLetterOrDigit}|\p{Punct})+README.*
|         [2/3]: (\p{javaLetterOrDigit}|\p{Punct})+\.xml
|         [3/3]: (\p{javaLetterOrDigit}|\p{Punct})+\.txt
| [2/2]: Filter [PatternFileFilter]
|
| 5 Results:
| [1/3]: file:/D:/test-plugin/xsd/different-namespaces-entries.xsd
| [2/3]: file:/D:/test-plugin/xsd/different-namespaces.xml
| [3/3]: file:/D:/test-plugin/xsd/different-namespaces.xsd

XML file is included for compilation (even thought it is supposed to be filtered out by build-in exclusion pattern) and compilation fails. The goal does not support <schemaSourceExcludeFilters> which should help. However the best is that <source> supports patterns (<source>xsd/*.xsd</source>).

davidmoten commented 7 years ago

I'm encountering this also with 2.3. Our jenkins server uses an older version of svn that adds .svn directories on checkout of a project that uses jaxb2-maven-plugin to every folder including my jaxb source folder. I've added .svn to the excludes but it doesn't work.

lennartj commented 6 years ago

This is actually a user exception, in that xml files are normally ignored when placed under the src/main/xsd directory.

Standard / Default settings

The following settings are used by default.

  1. The src/main/xsd directory (including subdirectories) is expected to contain XSD files.
  2. By default, some files under the src/main/xsd directory are ignored. These are files whose file names match any of the Java RegExp patterns "README.*", "\.xml", "\.txt", "\.java", "\.scala", "\.mdo".

These settings can be modified as described below.

Modifying standard / default settings.

The standard behavior can be overridden by a sources and / or xjcSourceExcludeFilters element given within the plugin configuration.

  1. Should a sources element be present, only the files or directories given as source sub-elements are scanned.
  2. Should an xjcSourceExcludeFilters element be present only the given Filters should be used to exclude found files from being included within the XJC compilation.

This is illustrated in the plugin documentation - but copied below for clarity:

                <configuration>
                    <!--
                        Include the sources from 3 locations:
                        1) a directory (including recursively finding all files in it)
                        2) an explicitly named file
                        3) a non-existent path, which is silently ignored
                    -->
                    <sources>
                        <source>src/main/some/other/xsds</source>
                        <source>src/main/foo/gnat.xsd</source>
                        <source>src/main/a/nonexistent/path</source>
                    </sources>
                    <!--
                        When providing xjcSourceExcludeFilters, the default exclude
                        Filter definitions are overridden by the Patterns supplied.

                        Any filter whose path ends with any of the Java Regular Expression Patterns
                        supplied will be excluded from the XJC sources. In this example,
                        files found under any of the source directories will be excluded from XJC
                        processing if their full paths end with '.xsd' or '.foo'
                    -->
                    <xjcSourceExcludeFilters>
                        <filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
                            <patterns>
                                <pattern>\.xsd</pattern>
                                <pattern>\.foo</pattern>
                            </patterns>
                        </filter>
                    </xjcSourceExcludeFilters>
                </configuration>