<?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>
    <groupId>org.alfresco</groupId>
    <artifactId>alfresco-benchmark-webdrone</artifactId>
    <version>1.4.5</version>
    <parent>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-benchmark-common</artifactId>
        <version>1.6</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <sonar.jacoco.reportPath>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPath>
        <sonar.exclusions>org/alfresco/webdrone/WebDroneClient.java</sonar.exclusions>
        <webdrone.max.waitTime>6000</webdrone.max.waitTime>
        <webdrone.exclude>nonEnterprise</webdrone.exclude>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
            <scope>runtime</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.30.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-cli</groupId>
            <artifactId>commons-cli</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
    </dependencies>
    
    <scm>
        <connection>scm:svn:http://svn.alfresco.com/repos/alfresco-open-mirror/benchmark/webdrone/tags/V1.4.5</connection>
        <developerConnection>scm:svn:https://svn.alfresco.com/repos/alfresco-enterprise/benchmark/webdrone/tags/V1.4.5</developerConnection>
    </scm>

    <!-- Pacakge Application into a standalone  -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.13</version>
                <configuration>
                    <runOrder>alphabetical</runOrder>
                    <argLine>-Xms512m -Xmx1024m</argLine>
                    <excludedGroups>
                    	${webdrone.exclude}
                    </excludedGroups>
                    <workingDirectory>target</workingDirectory>
                    <!-- parallel>classes</parallel-->
                    <systemPropertyVariables>
                        <webdrone.max.waitTime>${webdrone.max.waitTime}</webdrone.max.waitTime>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <tagNameFormat>V@{project.version}</tagNameFormat>
                    <tagBase>https://svn.alfresco.com/repos/alfresco-enterprise/benchmark/webdrone/tags</tagBase>
                </configuration>
            </plugin>

            <plugin>
                <!-- Configuration triggered by mvn antrun:run, used by Bamboo to stop server -->
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                            <target>
                                <echo>Stopping Alfresco...</echo>
                                <exec executable="${basedir}/target/alf-installation/alfresco.sh" dir="target/alf-installation" failonerror="true">
                                    <arg value="stop" />
                                </exec>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>install-alfresco</id>
            <build>
                <plugins>
                    <!-- Download and install the latest enterprise alfresco installer -->
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>fetch-installer</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                  <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Recreating database...</echo>
                                        <sql driver="org.postgresql.Driver" url="jdbc:postgresql:template1" userid="alfresco" password="alfresco" autocommit="true">drop database if exists alfresco; create database alfresco</sql>
                                        <echo>Downloading Alfresco installer...</echo>
                                        <scp remoteFile="tomcat@pbld01.alfresco.com:/data/nightlybuilds/Enterprise?4.2/*/ALL/alfresco-enterprise-*-installer-linux-x64.???" localTofile="target/alf-installer.bin" keyfile="${user.home}/.ssh/id_rsa" />
                                        <chmod file="target/alf-installer.bin" perm="a+x" verbose="true" />
                                        <echo>Installing Alfresco...</echo>
                                        <exec executable="${basedir}/target/alf-installer.bin" dir="target" failonerror="true">
                                            <arg line="--mode unattended --alfresco_admin_password admin --disable-components postgres,alfrescowcmqs,openofficecomponent --jdbc_username alfresco --jdbc_password alfresco --prefix ${basedir}/target/alf-installation" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>org.apache.ant</groupId>
                                <artifactId>ant-jsch</artifactId>
                                <version>1.8.2</version>
                            </dependency>
                            <dependency>
                                <groupId>postgresql</groupId>
                                <artifactId>postgresql</artifactId>
                                <version>9.1-901-1.jdbc4</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>run-alfresco</id>
            <build>
                <plugins>
                    <!-- Starts/stop the installed Alfresco -->
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <id>start-alfresco</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Starting Alfresco...</echo>
                                        <exec executable="${basedir}/target/alf-installation/alfresco.sh" dir="target/alf-installation" failonerror="true">
                                            <arg value="start" />
                                        </exec>
                                        <sleep minutes="5" />
                                    </target>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-alfresco</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                  <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Stopping Alfresco...</echo>
                                        <exec executable="${basedir}/target/alf-installation/alfresco.sh" dir="target/alf-installation" failonerror="true">
                                            <arg value="stop" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
