<?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.8.2</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.page.render.wait.time>6000</webdrone.page.render.wait.time>
        <enterprise.installer.version>4.2</enterprise.installer.version>
        <test.exclude>nonEnterprise</test.exclude>
    </properties>
    <repositories>
        <repository>
            <id>alfresco-public-snapshots</id>
            <releases>
                <enabled>false</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>never</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
             </snapshots>
             <name>Alfresco Public Snapshots Repository</name>
             <url>https://artifacts.alfresco.com/nexus/content/repositories/public-snapshots/</url>
        </repository>
        <repository>
            <id>alfresco-public</id>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
                <updatePolicy>never</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
             </snapshots>
             <name>Alfresco Public Releases Repository</name>
             <url>https://artifacts.alfresco.com/nexus/content/groups/public/</url>              
        </repository>
    </repositories>
    
    <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.39.0</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.4</version>
        </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>
	    <dependency>
		  <groupId>joda-time</groupId>
		  <artifactId>joda-time</artifactId>
		  <version>2.3</version>
	    </dependency>
    </dependencies>
    
    <scm>
        <connection>scm:svn:http://svn.alfresco.com/repos/alfresco-open-mirror/benchmark/webdrone/tags/V1.8.2</connection>
        <developerConnection>scm:svn:https://svn.alfresco.com/repos/alfresco-enterprise/benchmark/webdrone/tags/V1.8.2</developerConnection>
    </scm>

    <!-- Pacakge Application into a standalone  -->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${testng.xml}</suiteXmlFile>
                    </suiteXmlFiles>
                    <argLine>-Xms512m -Xmx1024m</argLine>
                    <excludedGroups>
                    	${test.exclude}
                    </excludedGroups>
                    <workingDirectory>target</workingDirectory>
                    <!-- parallel>classes</parallel-->
                    <systemPropertyVariables>
                        <webdrone.element.wait.time>${webdrone.element.wait.time}</webdrone.element.wait.time>
                    </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>
                        <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>
                                        <sshexec username="tomcat" host="pbld01.alfresco.com" keyfile="${user.home}/.ssh/id_rsa" outputproperty="installerPath" command="ls -rt /data/nightlybuilds/Enterprise?${enterprise.installer.version}/build*/ALL/alfresco-enterprise-*-installer-linux-x64.??? | tail -1 | tr ' ' '?' " />
                                        <scp remoteFile="tomcat@pbld01.alfresco.com:${installerPath}" 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 --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>enable-hybrid</id>
            <build>
                <plugins>
                    <!-- Enable hybrid in the installation -->
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>modify-properties</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                  <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <property name="alf.prop" location="target/alf-installation/tomcat/shared/classes/alfresco-global.properties" />
                                        <echo append="true" output="${alf.prop}" />
                                        <echo append="true" output="${alf.prop}">
hybridworkflow.enabled=true
sync.cloud.url=https://webdronehwa.alfresco.me/alfresco/a/{network}/
                                        </echo>
                                        <echo append="true" output="${alf.prop}" />
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>run-alfresco</id>
            <build>
                <plugins>
                    <!-- Fetch JaCoCo agent and set the argLine property accordingly -->
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.6.3.201306030806</version>
                        <executions>
                            <execution>
                                <id>prepare-jacoco</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includes>
                                <include>org.alfresco.*</include>
                            </includes>
                        </configuration>
                    </plugin>

                    <!-- Starts/stop the installed Alfresco -->
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <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" />
                                            <env key="CATALINA_OPTS" value="${argLine}" />
                                        </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>
