<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2015-2017 Hewlett Packard Enterprise Development LP.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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">
    <parent>
        <groupId>com.github.cafdataprocessing</groupId>
        <artifactId>boilerplate-service-aggregator</artifactId>
        <version>2.2.0-72</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>util-boilerplate-creation</artifactId>

    <properties>
        <cafBoilerplateDbName>boilerplate</cafBoilerplateDbName>
        <cafBoilerplateDbPass>root</cafBoilerplateDbPass>
        <cafBoilerplateDbUser>postgres</cafBoilerplateDbUser>
        <cafBoilerplateApiUrl>http://${docker.host.address}:${cafBoilerplateAdminPort}/boilerplateapi</cafBoilerplateApiUrl>
    </properties>

    <dependencies>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
        </dependency>
        <dependency>
            <groupId>com.hpe.caf.boilerplate</groupId>
            <artifactId>boilerplate-web-caller</artifactId>
            <version>1.14.1-68</version>
            <exclusions>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.fasterxml.jackson.core</groupId>
                    <artifactId>jackson-annotations</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <!-- Logging -->
        <dependency>
            <!--Required at runtime for log4j output-->
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.0</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <!--Required at runtime for log4j output-->
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.0</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <!--ADAPTER (not bridge) that allows slf4j api to route to the log4j implm-->
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
            <version>2.0-rc2</version>
            <exclusions>
                <exclusion>
                    <artifactId>log4j-api</artifactId>
                    <groupId>org.apache.logging.log4j</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.hpe.caf.util.boilerplate.creation.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- plugins to enable integration testing -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <executions>
                    <execution>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${maven.resources.version}</version>
                <executions>
                    <execution>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testResources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${maven.failsafe.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <!-- boilerplate setup specific properties -->
                        <boilerplateapi.url>${cafBoilerplateApiUrl}</boilerplateapi.url>
                        <docker.host.address>${docker.host.address}</docker.host.address>
                        <postgres.db.port>${cafPostgresDbPort}</postgres.db.port>
                    </systemPropertyVariables>
                    <!--<debugForkedProcess>true</debugForkedProcess>-->
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${fabric8.docker.maven.version}</version>
                <configuration>
                    <verbose>true</verbose>
                    <autoPull>true</autoPull>
                    <logDate>default</logDate>
                    <images>
                        <!-- Begin Boilerplate Database image -->
                        <image>
                            <alias>boilerplate-integrationtests-postgres</alias>
                            <name>postgres:9.4</name>
                            <run>
                                <ports>
                                    <port>${cafPostgresDbPort}:5432</port>
                                </ports>
                                <env>
                                    <POSTGRES_DB>${cafBoilerplateDbName}</POSTGRES_DB>
                                    <POSTGRES_PASSWORD>${cafBoilerplateDbPass}</POSTGRES_PASSWORD>
                                    <POSTGRES_USER>${cafBoilerplateDbUser}</POSTGRES_USER>
                                </env>
                                <wait>
                                    <log>PostgreSQL init process complete</log>
                                    <time>50000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                            </run>
                        </image>
                        <!-- End Boilerplate Database image -->

                        <!-- Begin Boilerplate db install image -->
                        <image>
                            <alias>boilerplate-liquibase-container</alias>
                            <name>${cafBoilerplateDbInstallerContainerName}</name>
                            <run>
                                <links>
                                    <link>boilerplate-integrationtests-postgres</link>
                                </links>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                                <cmd>java -jar /boilerplate-db.jar -fd -db.user ${cafBoilerplateDbUser} -db.pass ${cafBoilerplateDbPass} -db.name ${cafBoilerplateDbName} -db.connection jdbc:postgresql://boilerplate-integrationtests-postgres:5432 -log debug
                                </cmd>
                                <wait>
                                    <log>DB update finished.</log>
                                    <time>60000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                            </run>
                        </image>
                        <!-- End Boilerplate db install image -->

                        <!-- Begin Boilerplate API image -->
                        <image>
                            <alias>boilerplate-api</alias>
                            <name>${cafBoilerplateApiContainerName}</name>
                            <run>
                                <ports>
                                    <port>${cafBoilerplateAdminPort}:8080</port>
                                </ports>
                                <env>
                                    <hibernate.connectionstring>
                                        jdbc:postgresql://boilerplate-integrationtests-postgres:5432/${cafBoilerplateDbName}
                                    </hibernate.connectionstring>
                                    <hibernate.user>${cafBoilerplateDbUser}</hibernate.user>
                                    <hibernate.password>${cafBoilerplateDbPass}</hibernate.password>
                                </env>
                                <links>
                                    <link>boilerplate-integrationtests-postgres</link>
                                </links>
                                <log>
                                    <enabled>true</enabled>
                                </log>
                                <wait>
                                    <http>
                                        <url>
                                            http://${docker.host.address}:${cafBoilerplateAdminPort}/boilerplateapi/boilerplate/checkhealth?project_id=1
                                        </url>
                                    </http>
                                    <time>50000</time>
                                    <shutdown>500</shutdown>
                                </wait>
                            </run>
                        </image>
                        <!-- End Boilerplate API image -->
                    </images>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>integration-test</id>
            <activation>
                <property>
                    <name>RE_BUILD_TYPE</name>
                    <value>continuous</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${fabric8.docker.maven.version}</version>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>build</goal>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>nightly-test</id>
            <activation>
                <property>
                    <name>RE_BUILD_TYPE</name>
                    <value>release</value>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>${fabric8.docker.maven.version}</version>
                        <executions>
                            <execution>
                                <id>start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>build</goal>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>use-default-fixed-ports</id>
            <properties>
                <cafBoilerplateAdminPort>5555</cafBoilerplateAdminPort>
                <cafPostgresDbPort>5432</cafPostgresDbPort>
            </properties>
        </profile>
    </profiles>
</project>
