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

    Copyright (C) Posten Norge AS

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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>no.digipost.signature</groupId>
        <artifactId>signature-api-specification-parent</artifactId>
        <version>3.1.0</version>
    </parent>

    <name>Posten signering - API JAXB Classes</name>

    <artifactId>signature-api-specification-jaxb</artifactId>

    <properties>
        <xsd.directory>${project.build.directory}/generated-resources/xsd</xsd.directory>
        <xjc.build.directory>${project.build.directory}/generated-sources/xjc</xjc.build.directory>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.10.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>no.digipost</groupId>
                <artifactId>jaxb-resolver-com.sun.xml.bind-bom</artifactId>
                <version>1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>
        <dependency>
            <groupId>no.digipost</groupId>
            <artifactId>jaxb-resolver-com.sun.xml.bind</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.jvnet.jaxb</groupId>
            <artifactId>jaxb2-basics-runtime</artifactId>
            <version>2.0.9</version>
        </dependency>
        <dependency>
            <groupId>no.digipost.signature</groupId>
            <artifactId>signature-api-specification</artifactId>
            <version>${project.version}</version>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <version>2.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>uk.co.probablyfine</groupId>
            <artifactId>java-8-matchers</artifactId>
            <version>1.9</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>nl.jqno.equalsverifier</groupId>
            <artifactId>equalsverifier</artifactId>
            <version>3.15.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.javers</groupId>
            <artifactId>javers-core</artifactId>
            <version>6.14.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>no.digipost</groupId>
            <artifactId>digg</artifactId>
            <version>0.33</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.9</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>no.digipost</groupId>
            <artifactId>jul-to-slf4j-junit-extension</artifactId>
            <version>1.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jvnet.jaxb</groupId>
                    <artifactId>jaxb-maven-plugin</artifactId>
                    <version>2.0.9</version>
                    <configuration>
                        <specVersion>2.3</specVersion>
                        <schemaDirectory>${xsd.directory}</schemaDirectory>
                        <catalog>${xsd.directory}/catalog.xml</catalog>
                        <strict>false</strict>
                        <extension>true</extension>
                        <bindingDirectory>${project.basedir}/src/main/jaxb</bindingDirectory>
                        <args>
                            <arg>-Xxew</arg>
                            <arg>-Xxew:instantiate lazy</arg>
                            <arg>-Xxew:control ${project.basedir}/src/main/jaxb/xew-control.properties</arg>
                            <arg>-XtoString</arg>
                            <arg>-XtoString-toStringStrategyClass=no.digipost.signature.jaxb.basics.LessFuzzToStringStrategy</arg>
                            <arg>-Xjavadoc</arg>
                            <arg>-Xvalue-constructor</arg>
                            <arg>-Xfluent-api</arg>
                            <arg>-Xinheritance</arg>
                            <arg>-Xannotate</arg>
                        </args>
                        <plugins>
                            <plugin>
                                <groupId>org.jvnet.jaxb</groupId>
                                <artifactId>jaxb2-basics</artifactId>
                                <version>2.0.9</version>
                            </plugin>
                            <plugin>
                                <groupId>org.jvnet.jaxb</groupId>
                                <artifactId>jaxb-basics-annotate</artifactId>
                                <version>2.0.9</version>
                            </plugin>
                            <plugin>
                                <groupId>org.apache.cxf.xjcplugins</groupId>
                                <artifactId>cxf-xjc-javadoc</artifactId>
                                <version>3.3.2</version>
                            </plugin>
                            <plugin>
                                <groupId>com.github.jaxb-xew-plugin</groupId>
                                <artifactId>jaxb-xew-plugin</artifactId>
                                <version>1.11</version>
                            </plugin>
                        </plugins>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.6.0</version>
                    <configuration>
                        <detectOfflineLinks>false</detectOfflineLinks>
                        <doclint>all,-missing,-html</doclint>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-xsd-resources</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeArtifactIds>signature-api-specification</includeArtifactIds>
                            <outputDirectory>${xsd.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jvnet.jaxb</groupId>
                <artifactId>jaxb-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>xmldsig</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <bindingIncludes>bindings-xmldsig.xjb</bindingIncludes>
                            <generateDirectory>${xjc.build.directory}/xmldsig</generateDirectory>
                            <schemaIncludes>
                                <include>thirdparty/xmldsig-core-schema.xsd</include>
                            </schemaIncludes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>xades</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <bindingIncludes>bindings-xades.xjb</bindingIncludes>
                            <generateDirectory>${xjc.build.directory}/xades</generateDirectory>
                            <schemaIncludes>
                                <include>thirdparty/XAdES.xsd</include>
                            </schemaIncludes>
                            <args combine.children="append">
                                <arg>-b</arg>
                                <arg>${xjc.build.directory}/xmldsig/META-INF/sun-jaxb.episode</arg>
                            </args>
                        </configuration>
                    </execution>
                    <execution>
                        <id>asice</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <bindingIncludes>bindings-ts_102918v010201.xjb</bindingIncludes>
                            <generateDirectory>${xjc.build.directory}/asice</generateDirectory>
                            <schemaIncludes>
                                <include>thirdparty/ts_102918v010201.xsd</include>
                            </schemaIncludes>
                            <args combine.children="append">
                                <arg>-b</arg>
                                <arg>${xjc.build.directory}/xmldsig/META-INF/sun-jaxb.episode</arg>
                            </args>
                        </configuration>
                    </execution>
                    <execution>
                        <id>sign</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <bindingIncludes>bindings-sign.xjb</bindingIncludes>
                            <generateDirectory>${xjc.build.directory}/sign</generateDirectory>
                            <schemaIncludes>
                                <include>direct-and-portal.xsd</include>
                            </schemaIncludes>
                            <args combine.children="append">
                                <arg>-b</arg>
                                <arg>${xjc.build.directory}/asice/META-INF/sun-jaxb.episode</arg>
                                <arg>-b</arg>
                                <arg>${xjc.build.directory}/xades/META-INF/sun-jaxb.episode</arg>
                            </args>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <!-- This is a hack to remove excess ObjectFactory classes generated by xjc,
                                     even though the use of episodes are supposed to prevent that from happening.
                                     Seems like DigestValue, mapped to a Java byte[], is not included in the
                                     episode file generated from the compilation of xmldsig-core-schema, and are therefore
                                     regenerated in the compilation of xades.xsd and ts_102918v010201.xsd, resulting in a
                                     duplicate class error when compiling the generated Java code.
                                     See https://stackoverflow.com/a/32649545 -->
                                <delete dir="${xjc.build.directory}/asice/no/digipost/signature/api/xml/thirdparty/xmldsig"/>
                                <delete dir="${xjc.build.directory}/xades/no/digipost/signature/api/xml/thirdparty/xmldsig"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>
