<?xml version="1.0" encoding="UTF-8"?>
<!--
    The is the parent POM used by all scireum and sirius projects.
    This will enforce a sane build process and upload artifacts to sonatype
    or applications to SDS.
-->
<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>com.scireum</groupId>
    <artifactId>sirius-parent</artifactId>
    <version>5.1</version>
    <packaging>pom</packaging>

    <!-- Overwrite this block if necessary -->
    <name>Sirius Parent</name>
    <description>Provides a parent pom for all Sirius modules</description>
    <url>http://www.sirius-lib.net</url>
    <licenses>
        <license>
            <name>MIT License</name>
            <url>http://opensource.org/licenses/MIT</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <name>scireum</name>
            <email>info@scireum.de</email>
            <organization>scireum GmbH</organization>
            <organizationUrl>http://www.scireum.de</organizationUrl>
        </developer>
    </developers>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
        <build.number>${DRONE_BUILD_NUMBER}</build.number>
        <build.vcs.number>${DRONE_COMMIT}</build.vcs.number>

        <!-- You can lower the checkstyle checks by using checkstyle-basic.xml instead -->
        <checkstyle.file>checkstyle-strict.xml</checkstyle.file>

        <!-- Determines the IPL version used by applications -->
        <sirius.ipl.version>1.3</sirius.ipl.version>

        <!-- Contains a copy of the effective version of the parent pom as it is referenced
             to load certain resources -->
        <!-- Do not use ${project.version} here, as it is overwritten by the child pom! -->     
        <sirius.parent.version>4.0</sirius.parent.version>

        <!-- Settings to control the scm owner -->
        <project.owner>scireum</project.owner>
        <project.repository>${project.artifactId}</project.repository>

        <!-- By default we update the copyright to the sirius/scireum text -->
        <!-- As "real" companies also use this parent, the following can be set to exclude the enforces copyright -->
        <!-- <sirius.ideaExcludes>.idea/copyright/**</sirius.ideaExcludes> -->
    </properties>

    <!-- Adds the sonatype repositories - especially SNAPSHOTS -->
    <repositories>
        <repository>
            <id>snapshots-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
        <repository>
            <id>releases-repo</id>
            <url>https://oss.sonatype.org/content/repositories/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>bintray-palantir</id>
            <url>https://dl.bintray.com/palantir/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>snapshots-plugin-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>releases-plugin-repo</id>
            <url>https://oss.sonatype.org/content/repositories/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <!-- Determines the default upload repository for snapshots -->
    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <!-- Builds a SCM url for github based on the owner and artifact id -->
    <scm>
        <connection>scm:git:git@github.com:${project.owner}/${project.repository}.git</connection>
        <developerConnection>scm:git:git@github.com:${project.owner}/${project.repository}.git</developerConnection>
        <url>git@github.com:${project.owner}/${project.repository}.git</url>
    </scm>

    <profiles>
        <!-- This profile performs the bulk part of the build. (Compiling, Tests, ...)
             It is deactivated for the parent itself, as there is nothing to compile -->
        <profile>
            <id>build</id>
            <activation>
                <file>
                    <missing>nobuild.txt</missing>
                </file>
            </activation>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>true</filtering>
                        <includes>
                            <include>**/*.conf</include>
                        </includes>
                    </resource>
                    <resource>
                        <directory>src/main/resources</directory>
                        <filtering>false</filtering>
                        <excludes>
                            <exclude>**/*.conf</exclude>
                        </excludes>
                    </resource>
                </resources>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                    </testResource>
                    <testResource>
                        <directory>docs</directory>
                    </testResource>
                </testResources>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>2.4</version>
                        <configuration>
                            <excludes>
                                <exclude>**/*Test.*</exclude>
                                <exclude>**/*Spec.*</exclude>
                                <exclude>**/*Spec$*</exclude>
                                <exclude>**/*Test$*</exclude>
                                <exclude>**/test.conf</exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>test-jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <configuration>
                            <includes>
                                <include>TestSuite.java</include>
                            </includes>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-checkstyle-plugin</artifactId>
                        <version>2.16</version>
                        <executions>
                            <execution>
                                <id>validate</id>
                                <phase>validate</phase>
                                <configuration>
                                    <configLocation>${checkstyle.file}</configLocation>
                                    <encoding>UTF-8</encoding>
                                    <consoleOutput>true</consoleOutput>
                                    <failsOnError>false</failsOnError>
                                </configuration>
                                <goals>
                                    <goal>checkstyle</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>com.scireum</groupId>
                                <artifactId>sirius-parent</artifactId>
                                <version>${sirius.parent.version}</version>
                            </dependency>
                        </dependencies>
                    </plugin>

                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>groovyc</id>
                                <phase>test-compile</phase>
                                <configuration>
                                    <target>
                                        <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
                                            <classpath refid="maven.test.classpath"/>
                                        </taskdef>
                                        <mkdir dir="${project.build.testOutputDirectory}"/>
                                        <groovyc srcdir="${basedir}/src/test/java"
                                                 destdir="${project.build.testOutputDirectory}"
                                                 encoding="${project.build.sourceEncoding}">
                                            <classpath refid="maven.test.classpath"/>
                                        </groovyc>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.6.1</version>
                        <configuration>
                            <compilerVersion>${maven.compiler.source}</compilerVersion>
                            <fork>true</fork>
                            <source>${maven.compiler.source}</source>
                            <target>${maven.compiler.target}</target>
                            <debug>true</debug>
                            <optimize>true</optimize>
                            <showDeprecation>true</showDeprecation>
                            <showWarnings>true</showWarnings>
                            <compilerArgument>-Xlint:-options,unchecked,deprecation</compilerArgument>
                            <excludes>
                                <exclude>**/package-info.java</exclude>
                            </excludes>
                        </configuration>
                        <executions>
                            <execution>
                                <id>compile</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>testCompile</id>
                                <phase>test-compile</phase>
                                <goals>
                                    <goal>testCompile</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.10.4</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <links>
                                <link>http://sirius-lib.net/apidocs/sirius-kernel/</link>
                                <link>http://sirius-lib.net/apidocs/sirius-web/</link>
                                <link>http://sirius-lib.net/apidocs/sirius-db/</link>
                                <link>http://sirius-lib.net/apidocs/sirius-biz/</link>
                                <link>http://sirius-lib.net/apidocs/sirius-ipl/</link>
                                <link>http://netty.io/4.0/api/</link>
                            </links>
                            <failOnError>false</failOnError>
                            <breakiterator>true</breakiterator>
                            <version>false</version>
                            <author>false</author>
                            <keywords>true</keywords>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>versions-maven-plugin</artifactId>
                        <version>2.3</version>
                        <executions>
                            <execution>
                                <id>display-updates</id>
                                <phase>validate</phase>
                                <goals><goal>display-dependency-updates</goal></goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- This profile deploys libraries to sonatype nexus -->
        <profile>
            <id>deploy-nexus</id>
            <activation>
                <file>
                    <missing>src/main/resources/application.conf</missing>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.8</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- This profile bundles applications so that they can be bundled into docker images -->
        <profile>
            <id>build-app</id>
            <activation>
                <file>
                    <exists>src/main/resources/application.conf</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>unpack</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.scireum</groupId>
                                            <artifactId>sirius-ipl</artifactId>
                                            <version>${sirius.ipl.version}</version>
                                            <type>jar</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.build.directory}/ipl</outputDirectory>
                                            <excludes>META-INF</excludes>
                                        </artifactItem>
                                    </artifactItems>
                                    <outputDirectory>${project.build.directory}/ipl</outputDirectory>
                                    <overWriteReleases>true</overWriteReleases>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <configuration>
                            <descriptorRefs>
                                <descriptorRef>zip</descriptorRef>
                            </descriptorRefs>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>com.scireum</groupId>
                                <artifactId>sirius-parent</artifactId>
                                <version>${sirius.parent.version}</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- This is exlusively used to create the resources jar for the parent pom.
             This contains the checkstyle and IntelliJ settings -->
        <profile>
            <id>build-parent</id>
            <activation>
                <file>
                    <exists>nobuild.txt</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>2.6</version>
                        <configuration>
                            <descriptor>parent-jar.xml</descriptor>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                        <executions>
                            <execution>
                                <id>make-assembly</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Updates the IntelliJ IDEA project if present -->
        <profile>
            <id>idea</id>
            <activation>
                <file>
                    <exists>.idea</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>validate</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.scireum</groupId>
                                            <artifactId>sirius-parent</artifactId>
                                            <version>${sirius.parent.version}</version>
                                            <type>jar</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.basedir}</outputDirectory>
                                            <includes>.idea/**</includes>
                                            <excludes>${sirius.ideaExcludes}</excludes>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <!-- Updates the IntelliJ IDEA Project if present as parent project. -->
        <!-- Sometimes multiple artifacts are stored in one project... -->
        <profile>
            <id>idea-multi</id>
            <activation>
                <file>
                    <exists>../.idea</exists>
                </file>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>3.0.0</version>
                        <executions>
                            <execution>
                                <id>validate</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>com.scireum</groupId>
                                            <artifactId>sirius-parent</artifactId>
                                            <version>${sirius.parent.version}</version>
                                            <type>jar</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${project.basedir}/..</outputDirectory>
                                            <includes>.idea/**</includes>
                                            <excludes>${sirius.ideaExcludes}</excludes>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>
    <build>
        <plugins>
            <!-- We never use the classic maven deploy -->
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>

        <!-- Include JUnit for testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

        <!-- Include JUNIT-Toolbox for testing -->
        <dependency>
            <groupId>com.googlecode.junit-toolbox</groupId>
            <artifactId>junit-toolbox</artifactId>
            <version>2.2</version>
            <scope>test</scope>
        </dependency>

        <!-- Include Spock for testing -->
        <dependency>
            <groupId>org.spockframework</groupId>
            <artifactId>spock-core</artifactId>
            <version>1.1-groovy-2.4</version>
            <scope>test</scope>
        </dependency>

        <!-- Include cglib and objenesis for advanced mocking... -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.objenesis</groupId>
            <artifactId>objenesis</artifactId>
            <version>2.5.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>
