<?xml version="1.0" encoding="UTF-8"?>
<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.paremus.build</groupId>
    <artifactId>product-parent</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    
    <name>Paremus build parent</name>
    <description>The common parent pom for Paremus components</description>
    <url>https://github.com/paremus/build</url>

    <inceptionYear>2016</inceptionYear>
    <organization>
        <name>Paremus Ltd</name>
        <url>https://www.paremus.com</url>
    </organization>
    
    <licenses>
        <license>
            <name>Fair Source License, version 0.9</name>
            <url>https://fair.io/#license</url>
            <comments>
                As users do not typically interact directly with Paremus components
                the User limit of the Fair Source License is interpreted by Paremus 
                as applying to the number of running processes.
            </comments>
        </license>
    </licenses>
    
    
    <developers>
        <developer>
            <id>tward</id>
            <name>Tim Ward</name>
            <email>tim.ward@paremus.com</email>
            <organization>Paremus</organization>
            <organizationUrl>https://paremus.com</organizationUrl>
        </developer>
        <developer>
            <id>derek</id>
            <name>Derek Baum</name>
            <email>derek.baum@paremus.com</email>
            <organization>Paremus</organization>
            <organizationUrl>https://paremus.com</organizationUrl>
        </developer>
    </developers>
    
    <scm>
        <connection>scm:git:https://github.com/paremus/build.git</connection>
        <developerConnection>scm:git:https://github.com/paremus/build.git</developerConnection>
        <url>https://github.com/paremus/build</url>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <bnd.maven.version>4.2.0</bnd.maven.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.core</artifactId>
                <version>7.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.cmpn</artifactId>
                <version>7.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.annotation</artifactId>
                <version>7.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
            </dependency>

            <!-- TEST -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>2.18.3</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>biz.aQute.bnd</groupId>
                    <artifactId>bnd-maven-plugin</artifactId>
                    <version>${bnd.maven.version}</version>
                    <configuration>
                        <bnd><![CDATA[
# Generate an OSGi Contract Requirement for bundles that depend on the Servlet API
# (see https://www.osgi.org/portable-java-contract-definitions/)
-contract: JavaServlet

# Force Declarative Services bundles to declare a requirement for DS version 1.3
# even when they only use features from a previous version
-dsannotations-options: extender, inherit

# Add Git Descriptor and commit information to the bundles so that we can see
# which commit/tag the bundle was released from

Git-Descriptor:       ${system-allow-fail;git describe --dirty --always}
Git-SHA:              ${system-allow-fail;git rev-list -1 HEAD}
            ]]>
                        </bnd>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-bnd-process</id>
                            <goals>
                                <goal>bnd-process</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Create indexes for test projects -->
                <plugin>
                    <groupId>biz.aQute.bnd</groupId>
                    <artifactId>bnd-indexer-maven-plugin</artifactId>
                    <version>${bnd.maven.version}</version>
                    <configuration>
                        <attach>false</attach>
                        <includeGzip>false</includeGzip>
                        <includeJar>true</includeJar>
                        <indexName>test</indexName>
                        <scopes>
                            <scope>compile</scope>
                            <scope>runtime</scope>
                            <scope>test</scope>
                        </scopes>
                        <localURLs>REQUIRED</localURLs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>index</id>
                            <goals>
                                <goal>index</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>biz.aQute.bnd</groupId>
                    <artifactId>bnd-baseline-maven-plugin</artifactId>
                    <version>${bnd.maven.version}</version>
                    <configuration>
                        <fullReport>true</fullReport>
                    </configuration>
                    <executions>
                        <execution>
                            <id>baseline</id>
                            <goals>
                                <goal>baseline</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>biz.aQute.bnd</groupId>
                    <artifactId>bnd-testing-maven-plugin</artifactId>
                    <version>${bnd.maven.version}</version>
                    <configuration>
                        <resolve>true</resolve>
                        <failOnChanges>true</failOnChanges>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>testing</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <archive>
                            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                        </archive>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>
        <plugins>
            <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-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>include-license-files</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}</directory>
                                    <includes>
                                        <include>LICENSE*</include>
                                        <include>NOTICE*</include>
                                    </includes>
                                </resource>
                            </resources>
                            <outputDirectory>${project.build.outputDirectory}/META-INF</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>javad-c</id>
                        <phase>package</phase>
                        <goals>
                            <goal>javadoc-no-fork</goal>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4.1</version>
                <dependencies>
                    <dependency>
                        <groupId>com.paremus.build</groupId>
                        <artifactId>no-sources-in-jar</artifactId>
                        <version>1.0.0</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>enforce-no-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <myCustomRule
                                    implementation="com.paremus.build.rule.nosources.NoSourcesInJarRule" />
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <configLocation>google_checks.xml</configLocation>
                </configuration>
                <executions>
                    <execution>
                        <id>check-sources</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <phase>prepare-package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <version>2.0.0</version>
                <configuration>
                    <licenseName>fair_source_license</licenseName>
                    <licenseResolver>classpath://com/paremus/build/license</licenseResolver>
                    <failOnMissingHeader>true</failOnMissingHeader>
                    <extraTemplateParameters>
                        <useLimit>3</useLimit>
                    </extraTemplateParameters>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.paremus.build</groupId>
                        <artifactId>fair-source-license-resources</artifactId>
                        <version>1.0.0</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>check-sources</id>
                        <goals>
                            <goal>check-file-header</goal>
                        </goals>
                        <phase>prepare-package</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>3.0.0-M1</version>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>JDK 9+</id>
            <activation>
                <jdk>!1.8</jdk>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.7.0</version>
                            <configuration>
                                <release>8</release>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>lenient-license-check</id>
            <activation>
                <activeByDefault/>
            </activation>
            <properties>
                <deploy.skip>true</deploy.skip>
                <license.failOnNotUptodateHeader>false</license.failOnNotUptodateHeader>
            </properties>
        </profile>
        <profile>
            <id>strict-license-check</id>
            <properties>
                <license.failOnNotUptodateHeader>true</license.failOnNotUptodateHeader>
            </properties>
        </profile>
        <profile>
            <id>generate-licenses</id>
            <properties>
                <license.failOnNotUptodateHeader>true</license.failOnNotUptodateHeader>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>license-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>generate-licenses</id>
                                <goals>
                                    <goal>update-file-header</goal>
                                    <goal>update-project-license</goal>
                                </goals>
                                <phase>process-sources</phase>
                                <configuration>
                                    <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
