Commit 4d722561 authored by Jochen Sprickerhof's avatar Jochen Sprickerhof

New upstream version 0.13.3

parents
/.idea
*.iml
/err
/std
**/.classpath
**/.project
**/.settings
\ No newline at end of file
Copyright (c) 2006-2014, Alexey Valikov.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# JAXB2 Maven Plugin #
Welcome to the `org.jvnet.jaxb2.maven2:maven-jaxb2-plugin`, the most advanced and feature-full Maven plugin for XML Schema compilation.
This Maven plugin wraps and enhances the [JAXB](https://jaxb.java.net/) [Schema Compiler (XJC)](http://docs.oracle.com/javase/6/docs/technotes/tools/share/xjc.html) and allows
compiling XML Schemas (as well as WSDL, DTDs, RELAX NG) into Java classes in Maven builds.
> If you are interested in the Mojohaus JAXB2 Maven Plugin (`org.codehaus.mojo:jaxb2-maven-plugin`),
> please follow [this link](https://github.com/mojohaus/jaxb2-maven-plugin) to the corresponding website.
## Quick start ##
* Put your schemas (`*.xsd`) and bindings (`*.xjb`) into the `src/main/resources` folder.
* Add the plugin to your `pom.xml`:
```xml
<project ...>
...
<build>
<plugins>
...
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
```
## [Documentation](https://github.com/highsource/maven-jaxb2-plugin/wiki) ##
Please refer to the [wiki](https://github.com/highsource/maven-jaxb2-plugin/wiki) for the full documentation.
* [User Guide](https://github.com/highsource/maven-jaxb2-plugin/wiki/User-Guide)
* Maven Documentation (Work in progress)
* [Configuration Cheat Sheet](https://github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet)
* [Common Pitfalls and Problems](https://github.com/highsource/maven-jaxb2-plugin/wiki/Common-Pitfalls-and-Problems) (Work in progress)
* [Best Practices](https://github.com/highsource/maven-jaxb2-plugin/wiki/Best-Practices) (Work in progress)
* [FAQ](https://github.com/highsource/maven-jaxb2-plugin/wiki/FAQ)
* [Sample Projects](https://github.com/highsource/maven-jaxb2-plugin/wiki/Sample-Projects)
* [Support](https://github.com/highsource/maven-jaxb2-plugin/wiki/Support)
* [License](https://github.com/highsource/maven-jaxb2-plugin/blob/master/LICENSE)
## Disclaimer ##
This project is not developed, supported or in any other way affiliated with Apache. The `org.jvnet.jaxb2.maven2:maven-jaxb2-plugin` is not an Apache product (and does not pretend to be one), it is a completely independent development.
This project is also *not* developed by or affiliated with Oracle or Sun. Even if it is featured on [https://jaxb.java.net/](https://jaxb.java.net) pages,
**This plugin is in no way _official_ JAXB2 Maven plugin by Oracle.**
This is a completely indepentent development. [I](https://github.com/highsource) am *not* an Oracle employee.
setlocal
set JAVA_HOME=%JAVA5_HOME%
call mvn -X clean install >std 2>err
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA6_HOME%
call mvn -X clean install >std 2>err
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA7_HOME%
call mvn -X clean install >std 2>err
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA8_HOME%
call mvn -X clean install >std 2>err
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA5_HOME%
call mvn -X -P samples,templates clean install >std 2>err
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA6_HOME%
call mvn -DperformRelease -Psonatype-oss-release clean deploy
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA5_HOME%
call mvn -X clean install >std 2>err
call mvn -X -DprepareRelease -DcontinuousIntegrationDeploy clean deploy &>std 2&>err
endlocal
\ No newline at end of file
/target/
/files/
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-dist</artifactId>
<packaging>pom</packaging>
<name>Maven JAXB 2.x Plugin Dist</name>
<parent>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-project</artifactId>
<version>0.13.3</version>
</parent>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-sample-catalog</artifactId>
<type>zip</type>
<classifier>maven-src</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-sample-dtd</artifactId>
<type>zip</type>
<classifier>maven-src</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-sample-episode</artifactId>
<type>zip</type>
<classifier>maven-src</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-sample-jaxbplugins</artifactId>
<type>zip</type>
<classifier>maven-src</classifier>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-sample-po</artifactId>
<type>zip</type>
<classifier>maven-src</classifier>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>files</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
setlocal
echo Setting JAVA_HOME to %JAVA6_HOME%.
set JAVA_HOME=%JAVA6_HOME%
call mvn clean install -Pall -DperformRelease
endlocal
\ No newline at end of file
setlocal
echo Setting JAVA_HOME to %JAVA7_HOME%.
set JAVA_HOME=%JAVA7_HOME%
call mvn clean install -Pall -DperformRelease
endlocal
\ No newline at end of file
setlocal
echo Setting JAVA_HOME to %JAVA8_HOME%.
set JAVA_HOME=%JAVA8_HOME%
call mvn clean install -Pall -DperformRelease
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA5_HOME%
call mvn -X -Dsamples,templates,tests clean install >std 2>err
endlocal
\ No newline at end of file
setlocal
set JAVA_HOME=%JAVA6_HOME%
call mvn -DperformRelease -Psonatype-oss-release,samples,tests clean install
endlocal
\ No newline at end of file
/target/
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-jaxb20-plugin</artifactId>
<packaging>maven-plugin</packaging>
<name>Maven JAXB 2.0.x Plugin</name>
<parent>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-project</artifactId>
<version>0.13.3</version>
</parent>
<prerequisites>
<maven>${maven.version}</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin-core</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb20.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxb20.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
/**
*
*/
package org.jvnet.mjiip.v_2_0;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import org.apache.maven.plugin.logging.Log;
import com.sun.codemodel.CodeWriter;
import com.sun.codemodel.JPackage;
import com.sun.codemodel.writer.FilterCodeWriter;
public class LoggingCodeWriter extends FilterCodeWriter {
private final boolean verbose;
private final Log log;
public LoggingCodeWriter(CodeWriter output, Log log, boolean verbose) {
super(output);
this.log = log;
this.verbose = verbose;
}
public Writer openSource(JPackage pkg, String fileName) throws IOException {
if (verbose) {
if (pkg.isUnnamed())
log.info("XJC writing: " + fileName);
else
log.info("XJC writing: "
+ pkg.name().replace('.', File.separatorChar)
+ File.separatorChar + fileName);
}
return core.openSource(pkg, fileName);
}
public OutputStream openBinary(JPackage pkg, String fileName)
throws IOException {
if (verbose) {
if (pkg.isUnnamed())
log.info("XJC writing: " + fileName);
else
log.info("XJC writing: "
+ pkg.name().replace('.', File.separatorChar)
+ File.separatorChar + fileName);
}
return core.openBinary(pkg, fileName);
}
@Override
public void close() throws IOException {
core.close();
}
}
\ No newline at end of file
/**
*
*/
package org.jvnet.mjiip.v_2_0;
import org.apache.maven.plugin.logging.Log;
import org.xml.sax.SAXParseException;
import com.sun.tools.xjc.ErrorReceiver;
public class LoggingErrorReceiver extends ErrorReceiver {
private final Log log;
private final boolean verbose;
private final String messagePrefix;
public LoggingErrorReceiver(String messagePrefix, Log log, boolean verbose) {
this.log = log;
this.verbose = verbose;
this.messagePrefix = messagePrefix;
}
public void warning(SAXParseException saxex) {
log.warn(getMessage(saxex), saxex);
}
public void error(SAXParseException saxex) {
log.error(getMessage(saxex), saxex);
}
public void fatalError(SAXParseException saxex) {
log.error(getMessage(saxex), saxex);
}
public void info(SAXParseException saxex) {
if (verbose)
log.info(getMessage(saxex));
}
private String getMessage(SAXParseException ex) {
final int row = ex.getLineNumber();
final int col = ex.getColumnNumber();
final String sys = ex.getSystemId();
final String pub = ex.getPublicId();
return messagePrefix + "Location [" + (sys != null ? " " + sys : "")
+ (pub != null ? " " + pub : "")
+ (row > 0 ? "{" + row + (col > 0 ? "," + col : "") + "}" : "")
+ "].";
}
}
\ No newline at end of file
package org.jvnet.mjiip.v_2_0;
import java.text.MessageFormat;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.jvnet.jaxb2.maven2.OptionsConfiguration;
import org.jvnet.jaxb2.maven2.util.StringUtils;
import org.xml.sax.InputSource;
import com.sun.tools.xjc.BadCommandLineException;
import com.sun.tools.xjc.Language;
import com.sun.tools.xjc.Options;
public class OptionsFactory implements
org.jvnet.jaxb2.maven2.OptionsFactory<Options> {
/**
* Creates and initializes an instance of XJC options.
*
*/
public Options createOptions(OptionsConfiguration optionsConfiguration)
throws MojoExecutionException {
final Options options = new Options();
options.verbose = optionsConfiguration.isVerbose();
options.debugMode = optionsConfiguration.isDebugMode();
options.classpaths.addAll(optionsConfiguration.getPlugins());
options.setSchemaLanguage(createLanguage(optionsConfiguration
.getSchemaLanguage()));
options.entityResolver = optionsConfiguration.getEntityResolver();
for (InputSource grammar : optionsConfiguration.getGrammars()) {
options.addGrammar(grammar);
}
for (InputSource bindFile : optionsConfiguration.getBindFiles()) {
options.addBindFile(bindFile);
}
// Setup Other Options
options.defaultPackage = optionsConfiguration.getGeneratePackage();
options.targetDir = optionsConfiguration.getGenerateDirectory();
options.strictCheck = optionsConfiguration.isStrict();
options.readOnly = optionsConfiguration.isReadOnly();
options.packageLevelAnnotations = optionsConfiguration
.isPackageLevelAnnotations();
options.noFileHeader = optionsConfiguration.isNoFileHeader();
// options.enableIntrospection =
// optionsConfiguration.isEnableIntrospection();
// options.disableXmlSecurity =
// optionsConfiguration.isDisableXmlSecurity();
if (optionsConfiguration.getAccessExternalSchema() != null) {
System.setProperty("javax.xml.accessExternalSchema",
optionsConfiguration.getAccessExternalSchema());
}
if (optionsConfiguration.getAccessExternalDTD() != null) {
System.setProperty("javax.xml.accessExternalDTD",
optionsConfiguration.getAccessExternalDTD());
}
// options.contentForWildcard =
// optionsConfiguration.isContentForWildcard()
if (optionsConfiguration.isExtension()) {
options.compatibilityMode = Options.EXTENSION;
}
final List<String> arguments = optionsConfiguration.getArguments();
try {
options.parseArguments(arguments.toArray(new String[arguments
.size()]));
}
catch (BadCommandLineException bclex) {
throw new MojoExecutionException("Error parsing the command line ["
+ arguments + "]", bclex);
}
return options;
}
private Language createLanguage(String schemaLanguage)
throws MojoExecutionException {
if (StringUtils.isEmpty(schemaLanguage)) {
return null;
} else if ("AUTODETECT".equalsIgnoreCase(schemaLanguage))
return null; // nothing, it is AUTDETECT by default.
else if ("XMLSCHEMA".equalsIgnoreCase(schemaLanguage))
return Language.XMLSCHEMA;
else if ("DTD".equalsIgnoreCase(schemaLanguage))
return Language.DTD;
else if ("RELAXNG".equalsIgnoreCase(schemaLanguage))
return Language.RELAXNG;
else if ("RELAXNG_COMPACT".equalsIgnoreCase(schemaLanguage))
return Language.RELAXNG_COMPACT;
else if ("WSDL".equalsIgnoreCase(schemaLanguage))
return Language.WSDL;
else {
throw new MojoExecutionException(MessageFormat.format(
"Unknown schemaLanguage [{0}].", schemaLanguage));
}
}
}
package org.jvnet.mjiip.v_2_0;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.jvnet.jaxb2.maven2.RawXJC2Mojo;
import com.sun.codemodel.CodeWriter;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JPackage;
import com.sun.tools.xjc.ModelLoader;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.model.Model;
import com.sun.tools.xjc.outline.Outline;
/**
* JAXB 2.x Mojo.
*
* @author Aleksei Valikov (valikov@gmx.net)
*/
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
public class XJC20Mojo extends RawXJC2Mojo<Options> {