mojohaus / jaxb2-maven-plugin

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

Add a propertery to set the locale of the (xjc) generated files #9

Closed TheSnoozer closed 9 years ago

TheSnoozer commented 9 years ago

Hi, I think it would be really great if the plugin could offer a property to set the locale of the (xjc) generated files manually. I know that's not officially supported by xjc to set the language (so setting with -Duser.language=en -Duser.country=US or similar will have zero effect). I played around a bit and went on a big search how to conquer my problem. I figured out that we could change the locale of the generated files by invoking Locale.setDefault, then generating the files and then return to the local that was present before. I found this idea in a very similar maven-project (https://github.com/highsource/maven-jaxb2-plugin/blob/master/plugin-core/src/main/java/org/jvnet/jaxb2/maven2/RawXJC2Mojo.java#L306).

In case you'll close this as won't fix my current workaround is to invoke maven-antrun-plugin that overrides the default locale. In case someone is interested:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>setLocaleFixedToUS</id>
            <phase>initialize</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <target>
            <scriptdef name="setLocaleFixedToUS" language="javascript">
                <![CDATA[
                    importClass(java.util.Locale);
                    actualDefault = Locale.getDefault();
                    project.setProperty("actual-default-locale", actualDefault);
                    Locale.setDefault(Locale.US);
                ]]>
            </scriptdef>
            <setLocaleFixedToUS />
        </target>
    </configuration>
</plugin>

Similar issue: https://stackoverflow.com/questions/22408673/jaxb-how-to-generate-english-javadoc

lennartj commented 9 years ago

Added support for setting the locale explicitly for both SchemaGen and XJC. Added ITs.

Parameter used is locale, and commit id is 5c61455.

lennartj commented 9 years ago

Closing this issue. Feature will be released in the upcoming 2.2 release of the Jaxb2-Maven-Plugin.

TheSnoozer commented 9 years ago

@lennartj, awsome, thanks for the work done I highly appreciate it :-)