<?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>

    <parent>
        <artifactId>stash-func-test-parent</artifactId>
        <groupId>com.atlassian.stash</groupId>
        <version>3.11.6-rc6</version>
    </parent>

    <artifactId>stash-func-test-installer</artifactId>
    <name>Atlassian Stash Functional Installer Tests</name>

    <properties>
        <install.service>false</install.service>
        <installer.bitness.classifier />
        <installer.type />
        <http.port>7990</http.port>
        <service.port>8006</service.port>
        <include.tests />
    </properties>

    <profiles>
        <profile>
            <id>test-docker</id>
            <properties>
                <include.tests>**/docker/*.java</include.tests>
            </properties>
        </profile>
        <profile>
            <id>test-host-unix</id>
            <properties>
                <include.tests>**/host/*.java</include.tests>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>setup-installation</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <chmod file="${project.build.directory}/stash-installer-${installer.bitness.classifier}.${installer.type}" perm="a+x" />
                                        <exec executable="${project.build.directory}/stash-installer-${installer.bitness.classifier}.${installer.type}">
                                            <arg value="-q" />
                                            <arg value="-Dinstaller.pingback.host=http://localhost:3000/pingback" />
                                            <arg value="-Dinstall4j.alternativeLogfile=${project.build.directory}/installer.log" />
                                            <arg value="-Dinstall4j.logToStderr=true" />
                                            <arg value="-Dinstall4j.debug=true" />
                                            <arg value="-varfile" />
                                            <arg value="${project.build.testOutputDirectory}/installer-varfile.properties" />
                                        </exec>
                                    </tasks>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-stash</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <exec executable="bin/stop-stash.sh" dir="${project.build.directory}/stash/${project.version}" />
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>test-host-windows</id>
            <properties>
                <include.tests>**/host/*.java</include.tests>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>setup-installation</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <exec executable="${project.build.directory}\stash-installer-${installer.bitness.classifier}.${installer.type}">
                                            <arg value="-q" />
                                            <arg value="-Dinstaller.pingback.host=http://localhost:3000/pingback" />
                                            <arg value="-Dinstall4j.alternativeLogfile=${project.build.directory}\installer.log" />
                                            <arg value="-Dinstall4j.logToStderr=true" />
                                            <arg value="-Dinstall4j.debug=true" />
                                            <arg value="-varfile" />
                                            <arg value="${project.build.testOutputDirectory}\installer-varfile.properties" />
                                        </exec>
                                    </tasks>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-stash</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <exec executable="cmd" dir="${project.build.directory}\stash\${project.version}">
                                            <arg value="/c" />
                                            <arg value="bin\stop-stash.bat" />
                                        </exec>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>${include.tests}</include>
                    </includes>
                    <systemPropertyVariables>
                        <installerPingbackLog>${project.basedir}/../../distribution/installer/target/pingback-test-log/pingback-test.log</installerPingbackLog>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-inception</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.atlassian.stash</groupId>
                                    <artifactId>stash-installer</artifactId>
                                    <type>bin</type>
                                    <classifier>x64</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <destFileName>stash-installer-x64.bin</destFileName>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.atlassian.stash</groupId>
                                    <artifactId>stash-installer</artifactId>
                                    <type>bin</type>
                                    <classifier>x32</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <destFileName>stash-installer-x32.bin</destFileName>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.atlassian.stash</groupId>
                                    <artifactId>stash-installer</artifactId>
                                    <type>exe</type>
                                    <classifier>x64</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <destFileName>stash-installer-x64.exe</destFileName>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.atlassian.stash</groupId>
                                    <artifactId>stash-installer</artifactId>
                                    <type>exe</type>
                                    <classifier>x32</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <destFileName>stash-installer-x32.exe</destFileName>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>com.atlassian.stash</groupId>
                                    <artifactId>stash-installer</artifactId>
                                    <type>dmg</type>
                                    <classifier>x64</classifier>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <destFileName>stash-installer-x64.dmg</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
	<dependency>
            <!-- Ensure we don't run until after the installer is built by declaring a dependency on the installer -->
            <groupId>com.atlassian.stash</groupId>
            <artifactId>stash-installer</artifactId>
            <type>bin</type>
            <classifier>x64</classifier>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash</groupId>
            <artifactId>stash-page-objects</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.stash</groupId>
            <artifactId>stash-func-test-common</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.docker-java</groupId>
            <artifactId>docker-java</artifactId>
            <version>1.0.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.atlassian.stash</groupId>
                <artifactId>stash-installer</artifactId>
                <version>${project.parent.version}</version>
                <type>exe</type>
                <classifier>x64</classifier>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.stash</groupId>
                <artifactId>stash-installer</artifactId>
                <version>${project.parent.version}</version>
                <type>exe</type>
                <classifier>x32</classifier>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.stash</groupId>
                <artifactId>stash-installer</artifactId>
                <version>${project.parent.version}</version>
                <type>bin</type>
                <classifier>x64</classifier>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.stash</groupId>
                <artifactId>stash-installer</artifactId>
                <version>${project.parent.version}</version>
                <type>bin</type>
                <classifier>x32</classifier>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.stash</groupId>
                <artifactId>stash-installer</artifactId>
                <version>${project.parent.version}</version>
                <type>dmg</type>
                <classifier>x64</classifier>
                <scope>test</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>
