<?xml version="1.0" encoding="UTF-8"?>
<!--

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 2013-2017 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://oss.oracle.com/licenses/CDDL+GPL-1.1
    or LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

<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>

    <parent>
        <groupId>com.sun.xml.bind.mvn</groupId>
        <artifactId>jaxb-osgi</artifactId>
        <version>2.3.0.1</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-osgi</artifactId>

    <packaging>jar</packaging>
    <name>JAXB OSGI</name>
    <description>JAXB OSGI bundle</description>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jaxb-core</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jaxb-xjc</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jaxb-impl</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>jaxb-jxc</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.jvnet.staxex</groupId>
            <artifactId>stax-ex</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.fastinfoset</groupId>
            <artifactId>FastInfoset</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <generated.sources.dir>${project.build.directory}/generated-sources</generated.sources.dir>
    </properties>

    <build>
        <plugins>
            <plugin> <!-- we don't want to fix javadocs in external libs (e.g. relaxngDatatype) -->
                <artifactId>maven-javadoc-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <additionalparam>-Xdoclint:none</additionalparam>
                            <sourceFileExcludes>
                                <sourceFileExclude>META-INF/versions/**</sourceFileExclude>
                                <sourceFileExclude>module-info.java</sourceFileExclude>
                            </sourceFileExcludes>
                            <includeDependencySources>false</includeDependencySources>
                            <additionalJOptions>
                                <additionalJOption>--add-modules</additionalJOption>
                                <additionalJOption>java.activation,java.xml.bind</additionalJOption>
                                <additionalJOption>--add-exports</additionalJOption>
                                <additionalJOption>java.xml/com.sun.org.apache.xml.internal.resolver.tools=ALL-UNNAMED</additionalJOption>
                                <additionalJOption>--add-exports</additionalJOption>
                                <additionalJOption>java.xml/com.sun.org.apache.xml.internal.resolver=ALL-UNNAMED</additionalJOption>
                            </additionalJOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
            
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <configuration>
                    <skip>${findbugs.skip}</skip>
                    <threshold>${findbugs.threshold}</threshold>
                    <findbugsXmlWithMessages>true</findbugsXmlWithMessages>
                    <!-- Use all excludes used for rebundled artifacts --> 
                    <excludeFilterFile>
                        exclude-common.xml,
                        ${project.basedir}/exclude.xml,
                        ${project.basedir}/../../../runtime/impl/exclude-runtime.xml,
                        ${project.basedir}/../../../jxc/exclude-jxc.xml
                    </excludeFilterFile>
                    <fork>true</fork>
                    <jvmArgs>-Xms64m -Xmx256m</jvmArgs>
                </configuration>
            </plugin>

            <!--    Can be used to build everything from sources
                  <plugin>
                      <groupId>org.glassfish.build</groupId>
                      <artifactId>glassfishbuild-maven-plugin</artifactId>
                      <executions>
                          <execution>
                              <id>unpack-sources</id>
                              <phase>process-resources</phase>
                              <goals>
                                  <goal>unpack-sources</goal>
                              </goals>
                              <configuration>
                                  <attachSources>true</attachSources>
                                  <excludes>*.java</excludes>
                                  <excludeTransitive>true</excludeTransitive>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
            -->

            <plugin> <!-- want to unpack sources from individual modules -->
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>get-binary-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                <configuration>
                    <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                    <includeArtifactIds>jaxb-core,jaxb-impl,jaxb-jxc,jaxb-xjc,stax-ex,FastInfoset</includeArtifactIds>
                </configuration>
                    </execution>
                <execution>
                        <id>unpack-sources</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <skip>${skipSources}</skip>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.sun.xml.bind</groupId>
                                    <artifactId>jaxb-core</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${generated.sources.dir}</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.sun.xml.bind</groupId>
                                    <artifactId>jaxb-xjc</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${generated.sources.dir}</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.sun.xml.bind</groupId>
                                    <artifactId>jaxb-impl</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${generated.sources.dir}</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.sun.xml.bind</groupId>
                                    <artifactId>jaxb-jxc</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${generated.sources.dir}</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.jvnet.staxex</groupId>
                                    <artifactId>stax-ex</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${generated.sources.dir}</outputDirectory>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.sun.xml.fastinfoset</groupId>
                                    <artifactId>FastInfoset</artifactId>
                                    <classifier>sources</classifier>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${generated.sources.dir}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                        <configuration>
                            <instructions>
                                <Export-Package>
                                    com.sun.codemodel;version=${jaxb.osgiVersion},
                                    com.sun.codemodel.*;version=${jaxb.osgiVersion},
                                    com.sun.istack;version=${istack.version},
                                    com.sun.istack.*;version=${istack.version},
                                    com.sun.tools.*;version=${jaxb.osgiVersion},
                                    com.sun.xml.bind;version=${jaxb.osgiVersion},
                                    com.sun.xml.bind.*;version=${jaxb.osgiVersion},
                                    com.sun.xml.dtdparser;version=${dtd-parser.version},
                                    com.sun.xml.dtdparser.*;version=${dtd-parser.version},
                                    com.sun.xml.fastinfoset;version=${fastinfoset.version},
                                    com.sun.xml.fastinfoset.*;version=${fastinfoset.version},
                                    com.sun.xml.txw2;version=${jaxb.osgiVersion},
                                    com.sun.xml.txw2.*;version=${jaxb.osgiVersion},
                                    com.sun.xml.xsom;version=${jaxb.osgiVersion},
                                    com.sun.xml.xsom.*;version=${jaxb.osgiVersion},
                                    org.jvnet.fastinfoset;version=${fastinfoset.version},
                                    org.jvnet.fastinfoset.*;version=${fastinfoset.version},
                                    org.jvnet.staxex;version=${stax-ex.version},
                                    org.jvnet.staxex.util;version=${stax-ex.version},
                                    org.kohsuke.rngom.*;version=${jaxb.osgiVersion},
                                    org.relaxng.datatype;version=${relaxngDatatype.version},
                                    org.relaxng.datatype.*;version=${relaxngDatatype.version}
                                </Export-Package>
                                <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
                                <Import-Package>
                                    javax.xml.bind;version=${jaxb-api-osgi.version},
                                    javax.xml.bind.annotation;version=${jaxb-api-osgi.version},
                                    javax.xml.bind.annotation.adapters;version=${jaxb-api-osgi.version},
                                    javax.xml.bind.attachment;version=${jaxb-api-osgi.version},
                                    javax.xml.bind.helpers;version=${jaxb-api-osgi.version},
                                    javax.activation,
                                    javax.annotation.processing,
                                    javax.imageio,
                                    javax.imageio.stream,
                                    javax.lang.model,
                                    javax.lang.model.element,
                                    javax.lang.model.type,
                                    javax.lang.model.util,
                                    javax.swing,
                                    javax.swing.border,
                                    javax.swing.tree,
                                    javax.tools,
                                    javax.xml.datatype,
                                    javax.xml.namespace,
                                    javax.xml.parsers,
                                    javax.xml.stream,
                                    javax.xml.stream.events,
                                    javax.xml.stream.util,
                                    javax.xml.transform,
                                    javax.xml.transform.dom,
                                    javax.xml.transform.sax,
                                    javax.xml.transform.stream,
                                    javax.xml.validation,
                                    javax.xml.xpath,
                                    org.w3c.dom,
                                    org.w3c.dom.ls,
                                    org.xml.sax,
                                    org.xml.sax.ext,
                                    org.xml.sax.helpers,
                                    com.sun.org.apache.xml.internal.resolver;resolution:=optional,
                                    com.sun.org.apache.xml.internal.resolver.tools;resolution:=optional,
                                    com.sun.source.tree,
                                    com.sun.source.util,
                                    org.apache.tools.ant;resolution:=optional,
                                    org.apache.tools.ant.taskdefs;resolution:=optional,
                                    org.apache.tools.ant.taskdefs.compilers;resolution:=optional,
                                    org.apache.tools.ant.types;resolution:=optional,
                                </Import-Package>
                            </instructions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${generated.sources.dir}</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
              </plugin>

            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <includes>
                                    <include>com.sun.xml.bind:jaxb-core</include>
                                    <include>com.sun.xml.bind:jaxb-xjc</include>
                                    <include>com.sun.xml.bind:jaxb-impl</include>
                                    <include>com.sun.xml.bind:jaxb-jxc</include>
                                    <include>org.jvnet.staxex:stax-ex</include>
                                    <include>com.sun.xml.fastinfoset:FastInfoset</include>
                                </includes>
                                <excludes>
                                    <exclude>org.glassfish.jaxb:jaxb-runtime</exclude>
                                    <exclude>org.glassfish.jaxb:jaxb-core</exclude>
                                    <exclude>javax.xml.bind:jaxb-api</exclude>
                                    <exclude>org.glassfish.jaxb:txw2</exclude>
                                    <exclude>com.sun.istack:istack-commons-runtime</exclude>
                                    <exclude>relaxngDatatype:relaxngDatatype</exclude>
                                </excludes>
                            </artifactSet>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Major-Version>${jaxb.majorVersion}.${jaxb.minorVersion}.${jaxb.incrementalVersion}</Major-Version>
                                        <Specification-Version>${jaxb-api.majorVersion}.${jaxb-api.minorVersion}</Specification-Version>
                                        <Git-Revision>${buildNumber}</Git-Revision>
                                        <Class-Path>jaxb-api.jar</Class-Path>
                                        <Multi-Release>true</Multi-Release>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <skip>false</skip>
                            <systemProperties>
                                <jaxb.spec.version>${jaxb-api.version}</jaxb.spec.version>
                                <osgi.dist>${project.build.directory}/${project.build.finalName}</osgi.dist>
                            </systemProperties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

   <profiles>
        <profile>
            <id>jdk9-setup</id>
            <activation>
                <jdk>9</jdk>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <configuration>
                            <sourceFileExcludes>
                                <sourceFileExclude>META-INF/versions/**</sourceFileExclude>
                            </sourceFileExcludes>
                            <additionalJOptions>
                                <additionalJOption>--add-modules</additionalJOption>
                                <additionalJOption>java.activation</additionalJOption>
                                <additionalJOption>--add-exports</additionalJOption>
                                <additionalJOption>java.xml/com.sun.org.apache.xml.internal.resolver.tools=ALL-UNNAMED</additionalJOption>
                                <additionalJOption>--add-exports</additionalJOption>
                                <additionalJOption>java.xml/com.sun.org.apache.xml.internal.resolver=ALL-UNNAMED</additionalJOption>
                            </additionalJOptions>
                            <additionalDependencies>
                                <additionalDependency>
                                    <groupId>org.apache.ant</groupId>
                                    <artifactId>ant</artifactId>
                                    <version>${ant.version}</version>
                                </additionalDependency>
                            </additionalDependencies>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
   </profiles>
</project>
