<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.vmware.card-connectors</groupId>
    <artifactId>connectors-parent</artifactId>
    <version>2.2</version>
    <packaging>pom</packaging>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
    </parent>

    <properties>
        <connector.name>overrideme</connector.name>
        <nexus.staging.skip>false</nexus.staging.skip>
        <okhttp.version>3.14.1</okhttp.version>
        <pmd.version>6.13.0</pmd.version>
    </properties>

    <name>Workspace One Connectors Parent</name>
    <description>Connectors that have been developed for Workspace One Mobile Flows</description>
    <url>https://github.com/vmware/connectors-workspace-one</url>

    <licenses>
        <license>
            <name>BSD-2</name>
            <url>https://opensource.org/licenses/BSD-2-Clause</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/vmware/connectors-workspace-one</url>
    </scm>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ch.qos.logback.contrib</groupId>
                <artifactId>logback-jackson</artifactId>
                <version>0.1.5</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback.contrib</groupId>
                <artifactId>logback-json-classic</artifactId>
                <version>0.1.5</version>
                <scope>runtime</scope>
            </dependency>
            <dependency>
                <groupId>com.sun.activation</groupId>
                <artifactId>javax.activation</artifactId>
                <version>${javax-activation.version}</version>
            </dependency>
            <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>${javax-jaxb.version}</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
                <version>${javax-jaxb.version}</version>
            </dependency>
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-core</artifactId>
                <version>2.3.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.security.oauth.boot</groupId>
                <artifactId>spring-security-oauth2-autoconfigure</artifactId>
                <version>2.1.4.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <scope>compile</scope>
                <version>${junit-jupiter.version}</version>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-params</artifactId>
                <scope>test</scope>
                <version>${junit-jupiter.version}</version>
            </dependency>
            <dependency>
                <groupId>com.vmware.card-connectors</groupId>
                <artifactId>core</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.vmware.card-connectors</groupId>
                <artifactId>core-test</artifactId>
                <version>${project.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.vmware.card-connectors</groupId>
                <artifactId>connectors-config</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.vmware.card-connectors</groupId>
                <artifactId>connectors-test</artifactId>
                <version>${project.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>0.9.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>${commons-lang3.version}</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.6</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.datatype</groupId>
                <artifactId>jackson-datatype-jsr310</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>27.0.1-jre</version>
            </dependency>
            <dependency>
                <groupId>com.github.fge</groupId>
                <artifactId>json-schema-core</artifactId>
                <version>1.2.5</version>
            </dependency>
            <dependency>
                <groupId>com.github.fge</groupId>
                <artifactId>json-schema-validator</artifactId>
                <version>2.2.6</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>mockwebserver</artifactId>
                <version>${okhttp.version}</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>${okhttp.version}</version>
            </dependency>
            <dependency>
                <groupId>uk.co.datumedge</groupId>
                <artifactId>hamcrest-json</artifactId>
                <version>0.2</version>
            </dependency>
            <dependency>
                <groupId>io.projectreactor</groupId>
                <artifactId>reactor-test</artifactId>
                <version>3.2.8.RELEASE</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-core</artifactId>
                <version>${mockito.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-junit-jupiter</artifactId>
                <version>${mockito.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>${junit-jupiter.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <modules>
        <module>common</module>
        <module>connectors</module>
    </modules>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>io.fabric8</groupId>
                    <artifactId>docker-maven-plugin</artifactId>
                    <version>0.28.0</version>
                </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <profiles>
                            <profile>dev</profile>
                        </profiles>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>1.4.1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>enforce</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <requireReleaseDeps>
                                        <onlyWhenRelease>true</onlyWhenRelease>
                                    </requireReleaseDeps>
                                </rules>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>12</source>
                        <target>12</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>3.11.0</version>
                    <configuration>
                        <rulesets>
                            <ruleset>${project.parent.parent.basedir}/pmdrules.xml</ruleset>
                        </rulesets>
                        <!--
                          Using analysisCache introduces state from 1 build to
                          the next.  I ran into weird processing errors when
                          switching branches and had to build an extra time.
                          The time difference between analysisCache on and off
                          is negligible, so I would rather have consistent
                          builds that I can trust.
                          -->
                        <analysisCache>false</analysisCache>
                        <skipPmdError>false</skipPmdError>
                        <targetJdk>12</targetJdk>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>net.sourceforge.pmd</groupId>
                            <artifactId>pmd-java</artifactId>
                            <version>${pmd.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>net.sourceforge.pmd</groupId>
                            <artifactId>pmd-core</artifactId>
                            <version>${pmd.version}</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <goals>
                                <goal>check</goal>
                                <goal>cpd-check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.3</version>
                    <executions>
                        <execution>
                            <id>jacoco-initialize</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>jacoco-site</id>
                            <phase>package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.0.1</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>rpm-maven-plugin</artifactId>
                    <version>2.2.0</version>
                    <executions>
                        <execution>
                            <id>attached-rpm</id>
                            <goals>
                                <goal>attached-rpm</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <license>BSD-2</license>
                        <group>VMware AirWatch</group>
                        <provides>
                            <provide>${connector.name}-connector</provide>
                        </provides>
                        <requires>
                            <require>systemd >= 219</require>
                            <require>systemd-units >= 219</require>
                        </requires>
                        <mappings>
                            <!-- Create a systemd service file to be enabled in the post-install script -->
                            <mapping>
                                <directoryIncluded>false</directoryIncluded>
                                <directory>/usr/lib/systemd/system/</directory>
                                <filemode>660</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                                <sources>
                                    <source>
                                        <location>src/main/service/rhel/files/systemd/${connector.name}-connector.service</location>
                                    </source>
                                </sources>
                            </mapping>
                            <!-- Create the dir to hold jar and default config (with execute privilege or else spring might not find the conf files) -->
                            <mapping>
                                <directory>/opt/vmware/connectors/${connector.name}/</directory>
                                <filemode>770</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                            </mapping>
                            <!-- Include the actual jar to run -->
                            <mapping>
                                <directory>/opt/vmware/connectors/${connector.name}/</directory>
                                <filemode>660</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                                <artifact />
                            </mapping>
                            <!-- Give ops sensible default config files -->
                            <mapping>
                                <directory>/opt/vmware/connectors/${connector.name}/</directory>
                                <filemode>660</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                                <sources>
                                    <source>
                                        <location>src/main/service/rhel/files/default-conf/</location>
                                    </source>
                                </sources>
                            </mapping>
                            <!-- Include our README.md with instructions and notes -->
                            <mapping>
                                <directory>/opt/vmware/connectors/${connector.name}/</directory>
                                <filemode>660</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                                <sources>
                                    <source>
                                        <location>README.md</location>
                                    </source>
                                </sources>
                            </mapping>
                            <!-- Include our license file -->
                            <mapping>
                                <directory>/opt/vmware/connectors/${connector.name}/</directory>
                                <filemode>660</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                                <sources>
                                    <source>
                                        <location>../../LICENSE.txt</location>
                                    </source>
                                </sources>
                            </mapping>
                            <!-- Make an empty config dir for ops to put their overrides (with execute privilege or else spring might have problems) -->
                            <mapping>
                                <directory>/etc/opt/vmware/connectors/${connector.name}/</directory>
                                <filemode>770</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                            </mapping>
                            <!-- Make an empty dir for the logs (with execute privilege for easy ls'ing of files) -->
                            <mapping>
                                <directory>/var/log/vmware/connectors/${connector.name}/</directory>
                                <filemode>770</filemode>
                                <username>roswell</username>
                                <groupname>roswell</groupname>
                            </mapping>
                        </mappings>
                        <preinstallScriptlet>
                            <script>
                                # https://unix.stackexchange.com/questions/59228/recommended-procedure-to-create-a-user-group-during-rpm-install
                                # https://superuser.com/questions/168461/managing-service-accounts-in-an-rpm-spec
                                getent group roswell >/dev/null 2>&amp;1 || groupadd -r roswell
                                getent passwd roswell >/dev/null 2>&amp;1 || useradd -r -s /bin/false roswell -g roswell
                            </script>
                        </preinstallScriptlet>
                        <postinstallScriptlet>
                            <script>
                                systemctl daemon-reload

                                # Don't necessarily start the service because: https://fedoraproject.org/wiki/Packaging:Systemd

                                systemctl enable ${connector.name}-connector

                                # If this is an upgrade, then restart the service with the new code
                                if [ "$1" -gt 1 ]
                                then
                                systemctl restart ${connector.name}-connector
                                fi
                            </script>
                        </postinstallScriptlet>
                        <preremoveScriptlet>
                            <script>
                                # https://superuser.com/questions/513159/how-to-remove-systemd-services
                                # https://stackoverflow.com/questions/7398834/rpm-upgrade-uninstalls-the-rpm
                                # https://docs-old.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html

                                # If this is being removed instead of updated, stop and disable the service
                                if [ "$1" = 0 ]
                                then
                                systemctl stop ${connector.name}-connector
                                systemctl disable ${connector.name}-connector
                                fi

                                systemctl daemon-reload

                                systemctl reset-failed
                            </script>
                        </preremoveScriptlet>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jxr-plugin</artifactId>
                    <version>3.0.0</version>
                </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>
                            <configuration>
                                <keyname>0xAFCEE1CE</keyname>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.6.8</version>
                    <extensions>true</extensions>
                    <configuration>
                        <serverId>ossrhvmw</serverId>
                        <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                        <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        <skipRemoteStaging>${nexus.staging.skip}</skipRemoteStaging>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
            </plugin>
        </plugins>

    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrhvmw</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrhvmw</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <profiles>
        <profile>
            <id>check-rpm</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>io.fabric8</groupId>
                            <artifactId>docker-maven-plugin</artifactId>
                            <configuration>
                                <images>
                                    <image>
                                        <name>${connector.name}</name>
                                        <build>
                                            <from>centos/systemd:latest</from>
                                            <assembly>
                                                <inline>
                                                    <id>rpm</id>
                                                    <fileSets>
                                                        <fileSet>
                                                            <includes>
                                                                <include>target/**/*.rpm</include>
                                                            </includes>
                                                        </fileSet>
                                                    </fileSets>
                                                </inline>
                                            </assembly>
                                            <runCmds>
                                                <run>yum -y install wget</run>
                                                <run>wget https://download.java.net/java/GA/jdk12/GPL/openjdk-12_linux-x64_bin.tar.gz</run>
                                                <run>tar xvf openjdk-12*_bin.tar.gz</run>
                                                <run>ln -s /jdk-12/bin/java /usr/bin/java</run>
                                                <run>yum -y install /maven/target/rpm/${connector.name}-connector/RPMS/noarch/*.rpm</run>
                                                <run>
                                                    <![CDATA[
                                                echo "security.oauth2.resource.jwt.key-value=foo" \
                                                > /etc/opt/vmware/connectors/${connector.name}/application.properties
                                                ]]>
                                                </run>
                                            </runCmds>
                                            <cmd>
                                                <shell>/usr/sbin/init</shell>
                                            </cmd>
                                        </build>
                                        <run>
                                            <privileged>true</privileged>
                                            <ports>
                                                <port>connector.port:8080</port>
                                            </ports>
                                            <wait>
                                                <!-- Build will fail if not healthy within 60 seconds -->
                                                <time>60000</time>
                                                <http>
                                                    <url>http://localhost:${connector.port}/health</url>
                                                    <method>GET</method>
                                                    <status>200</status>
                                                </http>
                                            </wait>
                                        </run>
                                    </image>
                                </images>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>build</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>build</goal>
                                        <goal>start</goal>
                                        <goal>stop</goal>
                                        <goal>remove</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>aggregate-javadoc</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <configuration>
                            <doctitle>Workspace ONE Connectors API</doctitle>
                            <excludePackageNames>
                                com.vmware.connectors.airwatch*,
                                com.vmware.connectors.aws*,
                                com.vmware.connectors.bitbucket*,
                                com.vmware.connectors.concur*,
                                com.vmware.connectors.github*,
                                com.vmware.connectors.gitlab*,
                                com.vmware.connectors.hub*,
                                com.vmware.connectors.jira*,
                                com.vmware.connectors.salesforce*,
                                com.vmware.connectors.servicenow*,
                                com.vmware.connectors.common.web,
                                com.vmware.connectors.common.json,
                                com.vmware.connectors.common.config,
                                com.vmware.connectors.common.context,
                                com.vmware.connectors.common.model
                            </excludePackageNames>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>aggregate</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
