<?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>org.jboss.qa</groupId>
    <artifactId>dballocator</artifactId>
    <version>1.0</version>

    <name>DB Allocator services</name>
    <description>
      Provision or use various databases either via Docker, or
      via custom provisioning URL.
    </description>
    <url>https://repository.jboss.org/nexus/content/repositories/public/</url>

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

    <developers>
      <developer>
          <id>npetridis</id>
          <name>Nikos Petridis</name>
          <organization>Red Hat</organization>
      </developer>
      <developer>
          <id>karm</id>
          <name>Michal Karm Babacek</name>
          <organization>Red Hat</organization>
      </developer>
    </developers>

    <scm>
        <connection>scm:git:git@github.com:web-servers/db-allocator.git</connection>
        <developerConnection>scm:git:git@github.com:web-servers/db-allocator.git</developerConnection>
        <url>https://github.com/web-servers/db-allocator</url>
        <tag>v1.0</tag>
    </scm>

    <distributionManagement>
        <repository>
            <id>jboss-public-repository</id>
            <name>Public JBoss release repository</name>
            <url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2</url>
        </repository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>${version.release-plugin}</version>
                <configuration>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                    <tagNameFormat>v@{project.version}</tagNameFormat>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <version.release-plugin>2.5.3</version.release-plugin>
        <version.com.github.docker-java>3.0.14</version.com.github.docker-java>
        <version.org.jboss.shrinkwrap.resolver>2.2.2</version.org.jboss.shrinkwrap.resolver>
        <version.org.sonatype.plugins.nexus-staging-maven-plugin>1.6.6</version.org.sonatype.plugins.nexus-staging-maven-plugin>
        <version.org.jboss.logging.jboss-logging>3.2.1.Final</version.org.jboss.logging.jboss-logging>
        <version.org.jboss.arquillian.container.tomcat>1.1.0.Final</version.org.jboss.arquillian.container.tomcat>
        <version.org.jboss.narayana>5.9.0.Final</version.org.jboss.narayana>
        <version.org.jboss.resteasy>3.1.4.Final</version.org.jboss.resteasy>
        <version.org.jboss.spec.javax.transaction>1.0.0.Final</version.org.jboss.spec.javax.transaction>
        <server.jvm.args>${jvm.args.byteman} ${jvm.args.debug}</server.jvm.args>
        <version.com.h2database>1.4.195</version.com.h2database>
        <version.postgresql>9.0-801.jdbc4</version.postgresql>

        <jvm.args.debug />
        <jvm.args.byteman>
            -Dorg.jboss.byteman.verbose -Djboss.modules.system.pkgs=org.jboss.byteman -Dorg.jboss.byteman.transform.all
            -javaagent:${project.build.directory}/lib/byteman.jar=script:${project.build.directory}/test-classes/scripts.btm,listener:true
        </jvm.args.byteman>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.github.docker-java</groupId>
            <artifactId>docker-java</artifactId>
            <version>${version.com.github.docker-java}</version>
            <exclusions>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jboss.shrinkwrap.resolver</groupId>
            <artifactId>shrinkwrap-resolver-impl-maven</artifactId>
            <version>${version.org.jboss.shrinkwrap.resolver}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>${version.org.jboss.logging.jboss-logging}</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${version.com.h2database}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-install-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>default-install</id>
                                <phase>install</phase>
                            </execution>
                        </executions>
                        <inherited>false</inherited>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-release-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>arq-tomcat</id>
            <activation>
                <property>
                  <name>!skipArqTomcat</name>
                </property>
            </activation>
            <properties>
                <!--
                    h2:
                      The integration test runs with "h2" database, platform independent and in-memory.
                    pgsql:
                      If selected, the TS runs against a remote, always present PostgreSQL database server available in the Narayana CI.
                    container:
                      It requires a running Docker daemon the user executing this TS has the rights to control
                      A database is started as a Docker container and it is discarded at the end of testing.
                    dballocator:
                      By default, it requires an instance of DBAllocator running in your infrastructure. It enables the TS to
                      lease various databases, including but not limited to Sybase, DB2, MS SQL, Maria, Postgress, Oracle...
                    external:
                      External database is used and the caller is responsible for running it and providing details how
                      to connect to it.
                -->
                <test.db.type>h2</test.db.type>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.jboss.arquillian.container</groupId>
                    <artifactId>arquillian-tomcat-managed-8</artifactId>
                    <version>${version.org.jboss.arquillian.container.tomcat}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <redirectTestOutputToFile>true</redirectTestOutputToFile>
                            <systemPropertyVariables>
                                <project.version>${project.version}</project.version>
                                <project.build.directory>${project.build.directory}</project.build.directory>
                                <version.org.jboss.narayana>${version.org.jboss.narayana}</version.org.jboss.narayana>
                                <version.org.jboss.resteasy>${version.org.jboss.resteasy}</version.org.jboss.resteasy>
                                <version.org.jboss.spec.javax.transaction>${version.org.jboss.spec.javax.transaction}</version.org.jboss.spec.javax.transaction>
                                <server.jvm.args>${server.jvm.args}</server.jvm.args>
                                <tomcat.user>arquillian</tomcat.user>
                                <tomcat.pass>arquillian</tomcat.pass>
                                <db.timeout.waiting.for.heartbeat.statement>120000</db.timeout.waiting.for.heartbeat.statement>
                                <db.timeout.heartbeat.statement>SELECT 1;</db.timeout.heartbeat.statement>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>test-compile</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <stripVersion>true</stripVersion>
                                    <includeGroupIds>org.jboss.byteman</includeGroupIds>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>externalDatabase</id>
            <activation>
                <property>
                    <name>test.db.type</name>
                    <value>external</value>
                </property>
            </activation>
            <properties>
                <datasource.classname>org.h2.jdbcx.JdbcDataSource</datasource.classname>
                <jdbc.driver.class>org.h2.Driver</jdbc.driver.class>
                <jdbc.db.name />
                <jdbc.db.port />
                <jdbc.db.server />
                <jdbc.driver.jar />
                <jdbc.username>sa</jdbc.username>
                <jdbc.password>sa</jdbc.password>
                <jdbc.url>jdbc:h2:tcp://localhost/${project.basedir}/target/test-db;MVCC=TRUE</jdbc.url>
                <jdbc.schema>public</jdbc.schema>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <systemPropertyVariables combine.children="append">
                                <datasource.classname>${datasource.classname}</datasource.classname>
                                <jdbc.driver.class>${jdbc.driver.class}</jdbc.driver.class>
                                <jdbc.db.name>${jdbc.db.name}</jdbc.db.name>
                                <jdbc.db.port>${jdbc.db.port}</jdbc.db.port>
                                <jdbc.db.server>${jdbc.db.server}</jdbc.db.server>
                                <jdbc.driver.jar>${jdbc.driver.jar}</jdbc.driver.jar>
                                <jdbc.username>${jdbc.username}</jdbc.username>
                                <jdbc.password>${jdbc.password}</jdbc.password>
                                <jdbc.url>${jdbc.url}</jdbc.url>
                                <jdbc.schema>${jdbc.schema}</jdbc.schema>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>h2Database</id>
            <activation>
                <property>
                    <name>test.db.type</name>
                    <value>h2</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <systemPropertyVariables combine.children="append">
                                <version.com.h2database>${version.com.h2database}</version.com.h2database>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>postgresql</id>
            <activation>
                <property>
                    <name>test.db.type</name>
                    <value>pgsql</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <systemPropertyVariables combine.children="append">
                                <version.postgresql>${version.postgresql}</version.postgresql>
                                <pgsql.user>dtf11</pgsql.user>
                                <pgsql.password>dtf11</pgsql.password>
                                <pgsql.servername>narayanaci1.eng.hst.ams2.redhat.com</pgsql.servername>
                                <pgsql.portnumber>5432</pgsql.portnumber>
                                <pgsql.databasename>jbossts</pgsql.databasename>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>container</id>
            <activation>
                <property>
                    <name>test.db.type</name>
                    <value>container</value>
                </property>
            </activation>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <systemPropertyVariables>
                                <container.database.image>postgres:10</container.database.image>
                                <container.database.driver.artifact>org.postgresql:postgresql:42.2.2</container.database.driver.artifact>
                                <container.database.driver.class>org.postgresql.Driver</container.database.driver.class>
                                <container.database.datasource.class.xa>org.postgresql.xa.PGXADataSource</container.database.datasource.class.xa>
                                <container.docker.daemon.api.url>tcp://127.0.0.1:2375</container.docker.daemon.api.url>
                                <container.name>narayana_db</container.name>
                                <container.database.username>narayana_user</container.database.username>
                                <container.database.password>narayana_pass</container.database.password>
                                <container.database.name>narayana_db</container.database.name>
                                <container.database.bind.host.ip>127.0.0.1</container.database.bind.host.ip>
                                <container.database.bind.host.port>5432</container.database.bind.host.port>
                                <!-- The undermentioned timeout accounts both for pulling image and starting container up to opened socket. -->
                                <container.timeout.waiting.for.tcp>1240000</container.timeout.waiting.for.tcp>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>dballocator</id>
            <activation>
                <property>
                  <name>!skipDefaultProfile</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M3</version>
                        <configuration>
                            <systemPropertyVariables combine.children="append">
                                <dballocator.host.port>http://your.db.allocator.example.com:8080</dballocator.host.port>
                                <dballocator.expression>postgresql94</dballocator.expression>
                                <dballocator.requestee>narayana-tomcat-ts</dballocator.requestee>
                                <dballocator.expiry.minutes>10</dballocator.expiry.minutes>
                                <dballocator.timeout.minutes>20</dballocator.timeout.minutes>
                                <dballocator.driver.url>http://your.fileserver.example.com/postgresql-42.1.1.jar</dballocator.driver.url>
                                <dballocator.driver.url.timeout.seconds>120</dballocator.driver.url.timeout.seconds>
                                <test.db.type>dballocator</test.db.type>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
