<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright (c) Codice Foundation
 *
 * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at
 * <http://www.gnu.org/licenses/lgpl.html>.
 *
 **/
-->
<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>
        <artifactId>itests</artifactId>
        <groupId>ddf.test.itests</groupId>
        <version>2.31.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>test-itests-ddf-core</artifactId>
    <name>DDF :: Core :: Integration :: Test</name>

    <properties>
        <solr.script.dir>${project.build.directory}/solr/bin/</solr.script.dir>
        <solr.port>9784</solr.port>
        <zookeeper.port>10784</zookeeper.port>
        <skipTests />
    </properties>

    <dependencies>
        <dependency>
            <groupId>ddf.test.itests</groupId>
            <artifactId>test-itests-common</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.karaf</groupId>
            <artifactId>karaf</artifactId>
            <version>${karaf.version}</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.codice.ddf</groupId>
            <artifactId>kernel</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ddf.test.itests</groupId>
            <artifactId>test-itests-dependencies-app</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ddf.features</groupId>
            <artifactId>install-profiles</artifactId>
            <version>${project.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ddf.test</groupId>
            <artifactId>features-xml</artifactId>
            <version>${project.version}</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>ddf</groupId>
            <artifactId>solr-distro</artifactId>
            <version>${project.version}</version>
            <type>zip</type>
            <classifier>assembly</classifier>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>Windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <properties>
                <solr.script.file>solr.cmd</solr.script.file>
                <solr.force />
            </properties>
        </profile>
        <profile>
            <id>Unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <solr.script.file>solr</solr.script.file>
                <solr.force>-force</solr.force>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <configuration>
                            <skip>${skipTests}</skip>
                            <longModulepath>false</longModulepath>
                        </configuration>
                        <executions>
                            <execution>
                                <id>make-solr-executable</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                                <configuration>
                                    <executable>chmod</executable>
                                    <arguments>
                                        <argument>+x</argument>
                                        <argument>${solr.script.dir}${solr.script.file}</argument>
                                    </arguments>
                                    <async>true</async>
                                    <asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <!-- Unpack Solr distribution -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-solr</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>ddf</groupId>
                                    <artifactId>solr-distro</artifactId>
                                    <version>${project.version}</version>
                                    <type>zip</type>
                                    <classifier>assembly</classifier>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <configuration>
                    <skip>${skipTests}</skip>
                    <longModulepath>false</longModulepath>
                </configuration>
                <executions>
                    <execution>
                        <id>stop-stale-solr</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>
                                ${solr.script.dir}${solr.script.file}
                            </executable>
                            <arguments>
                                <argument>stop</argument>
                                <argument>-p</argument>
                                <argument>${solr.port}</argument>
                            </arguments>
                            <!-- Maven waits for completion and treats both "stopped" (0) and "already stopped/not running" (1) as acceptable. -->
                            <successCodes>
                                <successCode>0</successCode>
                                <successCode>1</successCode>
                            </successCodes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>start-solr</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>
                                ${solr.script.dir}${solr.script.file}
                            </executable>
                            <arguments>
                                <argument>start</argument>
                                <argument>-c</argument>
                                <argument>-p</argument>
                                <argument>${solr.port}</argument>
                                <argument>-m</argument>
                                <argument>512m</argument>
                                <argument>${solr.force}</argument>
                            </arguments>
                            <async>true</async>
                            <asyncDestroyOnShutdown>true</asyncDestroyOnShutdown>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-solr</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>
                                ${solr.script.dir}${solr.script.file}
                            </executable>
                            <arguments>
                                <argument>stop</argument>
                                <argument>-p</argument>
                                <argument>${solr.port}</argument>
                            </arguments>
                            <!-- Maven waits for completion and treats both "stopped" (0) and "already stopped/not running" (1) as acceptable. -->
                            <successCodes>
                                <successCode>0</successCode>
                                <successCode>1</successCode>
                            </successCodes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.servicemix.tooling</groupId>
                <artifactId>depends-maven-plugin</artifactId>
                <version>${servicemix-depends.version}</version>
                <executions>
                    <execution>
                        <id>generate-depends-file</id>
                        <goals>
                            <goal>generate-depends-file</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*IT.java</include>
                    </includes>
                    <argLine>
                        -Dddf.version=${project.version}
                        -Djava.awt.headless=true
                        -noverify
                    </argLine>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
