<?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>2.2</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>
        <webdriver.browser>firefox</webdriver.browser>
        <xvfb.enable>true</xvfb.enable>
        <jira.pageobjects.version>${jira.test.version}</jira.pageobjects.version>
        <maven.jira.plugin.version>${amps.version}</maven.jira.plugin.version>
    </properties>

	<dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-ui-test-utils</artifactId>
            <version>${jira.test.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>4.2.3</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>
            <build>
                <testResources>
                    <testResource>
                         <directory>src/test/resources</directory>
                         <filtering>true</filtering>
                    </testResource>
                    <testResource>
                         <directory>src/test/xml</directory>
                    </testResource>
                </testResources>
                <directory>../../integration-tests/target</directory>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.0-alpha-4</version>
                        <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>
                        <version>1.4</version>
                        <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>
                    <plugin>
                        <!-- Amps is not able to handle non hsql database types so we need
                            to pass in a jira-home zip with our dbconfig.xml
                        -->
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-jira-plugin</artifactId>
                        <version>${maven.jira.plugin.version}</version>
                        <executions>
                            <execution>
                                <id>tpm-amps-dbconfig-run</id>
                                <goals>
                                    <goal>integration-test</goal>
                                </goals>
                                <configuration>
                                    <productDataPath>${project.build.directory}/new-jira-home.zip</productDataPath>
                                </configuration>
                                <phase>integration-test</phase>
                            </execution>
                        </executions>

                        <configuration>
                            <systemPropertyVariables>
                                <!-- Trying this out to see if it increases build speed -->
                                <atlassian.dev.mode>false</atlassian.dev.mode>
                                <atlassian.mail.senddisabled>true</atlassian.mail.senddisabled>
                                <atlassian.mail.fetchdisabled>true</atlassian.mail.fetchdisabled>

                                <!-- we run on XVFB, since that's the way the build engineers would
                                    like to go, as opposed to VNC server (according to Min'an) -->
                                <xvfb.enable>${xvfb.enable}</xvfb.enable>

                                <!-- By default, we don't like to deal with websudo, it's just an annoyance -->
                                <jira.websudo.is.disabled>true</jira.websudo.is.disabled>

                                <webdriver.browser>${webdriver.browser}</webdriver.browser>
                                <jira.qunit.testoutput.location>${project.build.directory}/group-webdriver_tests/tomcat6x/surefire-reports</jira.qunit.testoutput.location>
                            </systemPropertyVariables>

                            <!-- amps replaces localhost by the hostname, unless we specify the server here -->
                            <server>localhost</server>

                            <jvmArgs>${jira.jvm.args}</jvmArgs>
                            <skipManifestValidation>true</skipManifestValidation>
                            <!-- Defining the product version and data version. These configurations control
                                the version which starts when you run jira:run. These do NOT control the
                                version used the integration tests-->
                            <productVersion>${jira.test.version}</productVersion>
                            <productDataVersion>${jira.test.version}</productDataVersion>

                            <!-- install the database driver as defined by the profile - hack alert - lib goes into WEB-INF/lib -->
                            <libArtifacts>
                                <libArtifact>
                                    <groupId>${db.artifactGroup}</groupId>
                                    <artifactId>${db.artifactId}</artifactId>
                                    <version>${db.artifactVersion}</version>
                                </libArtifact>
                            </libArtifacts>

                            <!-- We need testkit for the restore - true? -->
                            <bundledArtifacts>
                                <bundledArtifact>
                                    <groupId>com.atlassian.jira.tests</groupId>
                                    <artifactId>jira-testkit-plugin</artifactId>
                                    <version>${testkit.version}</version>
                                </bundledArtifact>
                            </bundledArtifacts>
                            <products>
                                <product>
                                    <id>jira</id>
                                    <version>${jira.test.version}</version>
                                    <dataVersion>${jira.test.version}</dataVersion>
                                </product>
                            </products>
                            <testGroups>
                                <testGroup>
                                    <id>jirasetup-tests</id>
                                    <productIds>
                                        <productId>jira</productId>
                                    </productIds>
                                    <includes>
                                        <include>it/**</include>
                                    </includes>
                                </testGroup>
                            </testGroups>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
