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

    <parent>
        <groupId>com.atlassian.servicedesk</groupId>
        <artifactId>servicedesk-tpm</artifactId>
        <version>3.2.0-OD-16-001-D20160607T045531</version>
    </parent>

    <artifactId>servicedesk-tpm-jirasetup</artifactId>
    <packaging>jar</packaging>

    <name>Service Desk TPM JIRA setup</name>
    <description>Ensures JIRA is properly setup and connected to the db</description>

    <properties>
        <jira.pageobjects.version>${jira.version}</jira.pageobjects.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-ui-test-utils</artifactId>
            <version>${jira.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.atlassian.crowd</groupId>
                    <artifactId>crowd-acceptance-test</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>atlassian-jira-pageobjects</artifactId>
            <version>${jira.pageobjects.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.atlassian.jira</groupId>
                    <artifactId>jira-func-tests</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira.tests</groupId>
            <artifactId>jira-testkit-client</artifactId>
            <version>${testkit.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-library</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.atlassian.selenium</groupId>
                <artifactId>atlassian-webdriver-core</artifactId>
                <version>${atlassian.selenium.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.selenium</groupId>
                <artifactId>atlassian-pageobjects-api</artifactId>
                <version>${atlassian.selenium.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.selenium</groupId>
                <artifactId>atlassian-pageobjects-elements</artifactId>
                <version>${atlassian.selenium.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>${httpclient.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.browsers</groupId>
                <artifactId>firefox</artifactId>
                <classifier>linux64</classifier>
                <version>8.0</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.browsers</groupId>
                <artifactId>firefox-profile</artifactId>
                <version>8.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <!-- By default don't run any tests -->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-build-environment</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <skip>true</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <!--
        We run everything in a profile to not execute during a normal mvn install cycle
    -->
    <profiles>

        <profile>
            <id>Jirasetup</id>
            <properties>
                <checkdeps.fail>false</checkdeps.fail>
            </properties>
            <build>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                        <filtering>true</filtering>
                    </testResource>
                    <testResource>
                        <directory>src/test/xml</directory>
                    </testResource>
                </testResources>
                <directory>../../integration-tests-parent/integration-tests/target</directory>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-jira-home</id>
                                <phase>generate-resources</phase>

                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>

                                <configuration>
                                    <includeArtifactIds>jira-plugin-test-resources</includeArtifactIds>
                                    <outputDirectory>${project.build.directory}/jira-home-orig</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>create-new-jira-home</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <!-- clean up existing jira-home from the dependency unpack because i'm a.r. and I don't always trust ant zip -->
                                        <delete file="${project.build.directory}/jira-home-orig/jira-home/dbconfig.xml"
                                                failonerror="true"/>
                                        <delete dir="${project.build.directory}/jira-home-orig/META-INF"
                                                failonerror="true"/>
                                        <!-- copy in our newly crafted dbconfig.xml -->
                                        <copy file="${basedir}/../dbconfig/target/dbconfig.xml"
                                              todir="${project.build.directory}/jira-home-orig/jira-home"
                                              failonerror="true"/>
                                        <!-- create a new jira home zipfile to be passed into the maven-jira-plugin as a productDataPath -->
                                        <zip destfile="${project.build.directory}/new-jira-home.zip">
                                            <!-- we need to add a directory in front of jira-home because amps expects one so use prefix in zipfileset-->
                                            <zipfileset dir="${project.build.directory}/jira-home-orig/jira-home"
                                                        prefix="amps-jira/jira-home"/>
                                        </zip>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>
</project>
