<?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.homeofthewizard</groupId>
    <artifactId>vault-maven-plugin</artifactId>
    <version>1.1.1</version>
    <packaging>maven-plugin</packaging>

    <name>Vault Maven Plugin</name>
    <description>A plugin that supports retrieving values from HashiCorp Vault.</description>
    <url>https://github.com/homeofthewizard/vault-maven-plugin</url>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <scm>
        <connection>scm:git:git@github.com:homeofthewizard/vault-maven-plugin</connection>
        <developerConnection>scm:git:git@github.com:homeofthewizard/vault-maven-plugin.git</developerConnection>
        <url>https://github.com/homeofthewizard/vault-maven-plugin</url>
      <tag>vault-maven-plugin-1.1.1</tag>
  </scm>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <developers>
        <developer>
            <name>Ozgun OZ</name>
            <email>ozgunn.oz@gmail.com</email>
        </developer>
    </developers>

    <properties>
        <docker.network>vault-maven-plugin-${maven.build.timestamp}</docker.network>
        <docker.nginx.host>nginx.docker</docker.nginx.host>
        <docker.vault.host>vault.docker</docker.vault.host>
        <docker.nginx.port>443</docker.nginx.port>
        <docker.vault.token>6edb70bd-3398-1f42-d67e-b9db377223cd</docker.vault.token>
        <docker.vault.github.token>${env.MY_GITHUB_PAT_FOR_VAULT_LOGIN}</docker.vault.github.token>
        <jacoco.integration.file>${project.build.directory}/jacoco-integration.exec</jacoco.integration.file>
        <jacoco.merged.file>${project.build.directory}/jacoco.exec</jacoco.merged.file>
        <jacoco.unit.file>${project.build.directory}/jacoco-unit.exec</jacoco.unit.file>
        <maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
        <maven.test.runOrder>hourly</maven.test.runOrder>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <version.bouncycastle.plugin>1.0.0</version.bouncycastle.plugin>
        <version.checkstyle.plugin>2.17</version.checkstyle.plugin>
        <version.compiler.plugin>3.8.1</version.compiler.plugin>
        <version.java.source>11</version.java.source>
        <version.java.target>11</version.java.target>
        <version.docker.plugin>0.38.0</version.docker.plugin>
        <version.failsafe.plugin>${version.surefire.plugin}</version.failsafe.plugin>
        <version.freemarker>2.3.23</version.freemarker>
        <version.guava>31.0.1-jre</version.guava>
        <version.jacoco>0.8.7</version.jacoco>
        <version.jacoco.plugin>${version.jacoco}</version.jacoco.plugin>
        <version.javadoc.plugin>3.2.0</version.javadoc.plugin>
        <version.junit>4.13.2</version.junit>
        <version.maven>3.8.1</version.maven>
        <version.moby>1.0.0</version.moby>
        <version.nginx>1.11</version.nginx>
        <version.plugin.api>3.8.1</version.plugin.api>
        <version.plugin.annotations>3.6.2</version.plugin.annotations>
        <version.plugin.testing>3.3.0</version.plugin.testing>
        <version.plugin.plugin>3.6.2</version.plugin.plugin>
        <version.source.plugin>3.0.1</version.source.plugin>
        <version.surefire.plugin>2.22.0</version.surefire.plugin>
        <version.vault>1.9.2</version.vault>
        <version.vault.driver>5.1.0</version.vault.driver>
        <mockito-core.version>5.2.0</mockito-core.version>
        <nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
        <maven-release-plugin.version>2.5.3</maven-release-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.bettercloud</groupId>
            <artifactId>vault-java-driver</artifactId>
            <version>${version.vault.driver}</version>
        </dependency>
        <dependency>
            <groupId>com.deciphernow</groupId>
            <artifactId>moby-dns</artifactId>
            <version>${version.moby}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${version.guava}</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava-testlib</artifactId>
            <version>${version.guava}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${version.junit}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito-core.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-artifact</artifactId>
            <version>${version.maven}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-compat</artifactId>
            <version>${version.maven}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>${version.maven}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>${version.plugin.api}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-testing</groupId>
            <artifactId>maven-plugin-testing-harness</artifactId>
            <version>${version.plugin.testing}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-tools-annotations</artifactId>
            <version>${version.plugin.annotations}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>${version.freemarker}</version>
        </dependency>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>org.jacoco.agent</artifactId>
            <classifier>runtime</classifier>
            <version>${version.jacoco}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${version.docker.plugin}</version>
                <configuration>
                    <autoCreateCustomNetworks>true</autoCreateCustomNetworks>
                    <images>
                        <image>
                            <alias>${docker.vault.host}</alias>
                            <name>vault:${version.vault}</name>
                            <run>
                                <capAdd>
                                    <capAdd>IPC_LOCK</capAdd>
                                </capAdd>
                                <env>
                                    <VAULT_DEV_ROOT_TOKEN_ID>${docker.vault.token}</VAULT_DEV_ROOT_TOKEN_ID>
                                    <VAULT_ADDR>http://127.0.0.1:8200</VAULT_ADDR>
                                </env>
                                <hostname>${docker.vault.host}</hostname>
                                <volumes>
                                    <bind>
                                        <volume>${project.basedir}/docker/vault:/home/vault</volume>
                                    </bind>
                                </volumes>
                                <network>
                                    <mode>custom</mode>
                                    <name>${docker.network}</name>
                                    <alias>${docker.vault.host}</alias>
                                </network>
                                <wait>
                                    <time>10000</time>
<!--                                    <http>-->
<!--                                        <url>http://127.0.0.1:8200/v1/sys/health</url>-->
<!--                                        <method>GET</method>-->
<!--                                        <status>200..399</status>-->
<!--                                    </http>-->
                                    <exec>
                                        <postStart>sh /home/vault/enable-github-auth.sh</postStart>
                                    </exec>
                                </wait>
                            </run>
                        </image>
                        <image>
                            <alias>${docker.nginx.host}</alias>
                            <name>nginx:${version.nginx}-alpine</name>
                            <run>
                                <hostname>${docker.nginx.host}</hostname>
                                <network>
                                    <mode>custom</mode>
                                    <name>${docker.network}</name>
                                    <alias>${docker.nginx.host}</alias>
                                </network>
                                <ports>
                                    <port>docker.nginx.port:443</port>
                                </ports>
                                <volumes>
                                    <bind>
                                        <volume>${project.basedir}/docker/nginx/etc/ssl:/etc/ssl</volume>
                                        <volume>${project.basedir}/docker/nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf</volume>
                                    </bind>
                                </volumes>
                            </run>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${version.checkstyle.plugin}</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <consoleOutput>true</consoleOutput>
                    <encoding>UTF-8</encoding>
                    <linkXRef>false</linkXRef>
                </configuration>
                <executions>
                    <execution>
                        <id>checkstyle</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${version.compiler.plugin}</version>
                <configuration>
                    <source>${version.java.source}</source>
                    <target>${version.java.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${version.failsafe.plugin}</version>
                <configuration>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <runOrder>${maven.test.runOrder}</runOrder>
                    <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine>
                    <includes>
                        <include>**/IntTest*.class</include>
                        <include>**/IntSpec*.class</include>
                    </includes>
                    <systemPropertyVariables>
                        <vault.host>localhost</vault.host>
                        <vault.port>${docker.nginx.port}</vault.port>
                        <vault.token>${docker.vault.token}</vault.token>
                        <vault.github.token>${docker.vault.github.token}</vault.github.token>
                        <sun.net.spi.nameservice.provider.1>dns,moby</sun.net.spi.nameservice.provider.1>
                        <sun.net.spi.nameservice.provider.2>default</sun.net.spi.nameservice.provider.2>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>${version.plugin.plugin}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${version.surefire.plugin}</version>
                <configuration>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <runOrder>${maven.test.runOrder}</runOrder>
                    <includes>
                        <include>**/Test*.class</include>
                        <include>**/Spec*.class</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${version.jacoco.plugin}</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${jacoco.unit.file}</destFile>
                            <sessionId>${project.artifactId}-unit-${maven.build.timestamp}</sessionId>
                        </configuration>
                    </execution>
                    <execution>
                        <id>prepare-agent-integration</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent-integration</goal>
                        </goals>
                        <configuration>
                            <destFile>${jacoco.integration.file}</destFile>
                            <sessionId>${project.artifactId}-integration-${maven.build.timestamp}</sessionId>
                        </configuration>
                    </execution>
                    <execution>
                        <id>merge</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>merge</goal>
                        </goals>
                        <configuration>
                            <destFile>${jacoco.merged.file}</destFile>
                            <fileSets>
                                <fileSet>
                                    <directory>${project.build.directory}</directory>
                                    <includes>
                                        <include>*.exec</include>
                                    </includes>
                                </fileSet>
                            </fileSets>
                        </configuration>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${jacoco.merged.file}</dataFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>check</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <rule>
                                    <element>BUNDLE</element>
                                    <limits>
                                        <limit>
                                            <counter>COMPLEXITY</counter>
                                            <value>COVEREDRATIO</value>
                                            <minimum>0.50</minimum>
                                        </limit>
                                    </limits>
                                </rule>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>${nexus-staging-maven-plugin.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>${maven-release-plugin.version}</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <useReleaseProfile>false</useReleaseProfile>
                    <releaseProfiles>release</releaseProfiles>
                    <goals>deploy</goals>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.deciphernow</groupId>
                        <artifactId>bouncycastle-maven-plugin</artifactId>
                        <version>${version.bouncycastle.plugin}</version>
                        <configuration>
                            <passphrase>${env.PGP_PASSPHRASE}</passphrase>
                            <rings>${env.PGP_RINGS}</rings>
                            <userId>${env.PGP_USER_ID}</userId>
                        </configuration>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>${version.javadoc.plugin}</version>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>${version.source.plugin}</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
