<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>
    <artifactId>dataprep</artifactId>
    <packaging>jar</packaging>
    <name>Alfresco Dataprep</name>
    <description>Alfresco dataprep, collection of helpers to prepare and load Alfresco test data</description>
    <groupId>org.alfresco.test</groupId>
    <version>2.5</version>
    <organization>
        <name>Alfresco Software</name>
        <url>http://www.alfresco.com/</url>
    </organization>
    <developers>
        <developer>
            <name>Michael Suzuki</name>
            <roles>
                <role>Lead Engineer</role>
            </roles>
        </developer>
    </developers>
    <licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
    <scm>
        <connection>scm:git:https://github.com/AlfrescoTestAutomation/dataprep.git</connection>
        <url>https://github.com/AlfrescoTestAutomation/dataprep</url>
        <developerConnection>scm:git:https://github.com/AlfrescoTestAutomation/dataprep.git</developerConnection>
        <tag>dataprep-2.5</tag>
    </scm>
    <properties>
        <spring.version>4.1.7.RELEASE</spring.version>
        <testNG.version>6.9.10</testNG.version>
        <chemistry-opencmis-commons-api>1.1.0</chemistry-opencmis-commons-api>
        <apache.commons>3.5</apache.commons>
        <apache.httpcomponents.httpclient>4.5.6</apache.httpcomponents.httpclient>
        <commons-httpclient>3.1</commons-httpclient>
        <com.googlecode.json-simple>1.1.1</com.googlecode.json-simple>
        <org.json>20170516</org.json>
        <commons-io>2.5</commons-io>
        <joda-time>2.9.9</joda-time>
        <java.version>11</java.version>
        <enterprise.installer.path>/data/bamboo/artifacts/${enterprise.build.plan}/ALL/alfresco-enterprise-*-installer-linux-x64.???</enterprise.installer.path>
        <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testNG.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${apache.commons}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${apache.httpcomponents.httpclient}</version>
        </dependency>

        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>${commons-httpclient}</version>
        </dependency>

        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>${com.googlecode.json-simple}</version>
        </dependency>

        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>${org.json}</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${commons-io}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        
        <dependency>
            <groupId>org.apache.chemistry.opencmis</groupId>
            <artifactId>chemistry-opencmis-commons-api</artifactId>
            <version>${chemistry-opencmis-commons-api}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.chemistry.opencmis</groupId>
            <artifactId>chemistry-opencmis-client-impl</artifactId>
            <version>${chemistry-opencmis-commons-api}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.chemistry.opencmis</groupId>
            <artifactId>chemistry-opencmis-client-api</artifactId>
            <version>${chemistry-opencmis-commons-api}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.chemistry.opencmis</groupId>
            <artifactId>chemistry-opencmis-client-bindings</artifactId>
            <version>${chemistry-opencmis-commons-api}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.chemistry.opencmis</groupId>
            <artifactId>chemistry-opencmis-commons-impl</artifactId>
            <version>${chemistry-opencmis-commons-api}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.chemistry.opencmis</groupId>
            <artifactId>chemistry-opencmis-commons-api</artifactId>
            <version>${chemistry-opencmis-commons-api}</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>${joda-time}</version>
        </dependency>
    </dependencies>

    <distributionManagement>
        <repository>
            <id>alfresco-internal</id>
            <name>Alfresco Releases Repository</name>
            <url>https://artifacts.alfresco.com/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>alfresco-internal-snapshots</id>
            <name>Alfresco Snapshots Repository </name>
            <url>https://artifacts.alfresco.com/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.3</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.1</version>
            </plugin>
            <plugin>
                <!-- Configuration triggered by mvn antrun:run, used by Bamboo 
                    to stop server -->
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <id>default-cli</id>
                        <configuration>
                            <target>
                                <echo>Stopping Alfresco...</echo>
                                <exec dir="target/alf-installation" executable="${basedir}/target/alf-installation/alfresco.sh" failonerror="true">
                                    <arg value="stop" />
                                </exec>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M2</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
			    <groupId>org.apache.maven.plugins</groupId>
			    <artifactId>maven-compiler-plugin</artifactId>
			    <version>${maven-compiler-plugin.version}</version>
			    <configuration>
			        <source>${java.version}</source>
                    <target>${java.version}</target>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
			    </configuration>			    		   
			</plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <additionalOptions>
                    	<additionalOption>-Xdoclint:none</additionalOption>
                	</additionalOptions>
                </configuration>
            </plugin>
            <plugin>
			  <groupId>org.apache.maven.plugins</groupId>
			  <artifactId>maven-enforcer-plugin</artifactId>
			  <version>3.0.0-M2</version>
			  <executions>
			    <execution>
			      <id>enforce-maven</id>
			      <goals>
			        <goal>enforce</goal>
			      </goals>
			      <configuration>
			        <rules>
			          <requireMavenVersion>
			            <version>3.3</version>
			          </requireMavenVersion>
			        </rules>
			      </configuration>
			    </execution>
			  </executions>
			</plugin>  
            <plugin>
			    <groupId>org.codehaus.mojo</groupId>
			    <artifactId>versions-maven-plugin</artifactId>
			    <version>2.7</version>
			    <configuration>
			        <generateBackupPoms>false</generateBackupPoms>
			    </configuration>
			</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.8</version>
                        <executions>
                            <execution>
                                <id>fetch-installer</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Recreating database...</echo>
                                        <sql autocommit="true" driver="org.postgresql.Driver" password="alfresco" url="jdbc:postgresql:template1" userid="alfresco">drop
                                            database if
                                            exists alfresco; create
                                            database alfresco</sql>
                                        <echo>Downloading Alfresco
                                            installer...</echo>
                                        <sshexec command="ls -rt ${enterprise.installer.path} | tail -1 | tr ' ' '?' " host="pbam01.alfresco.com" keyfile="${user.home}/.ssh/id_rsa" outputproperty="installerPath" username="tomcat" />
                                        <scp keyfile="${user.home}/.ssh/id_rsa" localTofile="target/alf-installer.bin" remoteFile="tomcat@pbam01.alfresco.com:${installerPath}" />
                                        <chmod file="target/alf-installer.bin" perm="a+x" verbose="true" />
                                        <echo>Installing Alfresco...</echo>
                                        <exec dir="target" executable="${basedir}/target/alf-installer.bin" 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>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.8.1</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>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>start-alfresco</id>
                                <phase>process-test-classes</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Starting Alfresco...</echo>
                                        <exec dir="target/alf-installation" executable="${basedir}/target/alf-installation/alfresco.sh" 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 dir="target/alf-installation" executable="${basedir}/target/alf-installation/alfresco.sh" failonerror="true">
                                            <arg value="stop" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>docker-compose</id>
            <build>
                <plugins>                                	                   
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>acs-up</id>
                                <phase>process-resources</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Starting ACS with docker-compose!...</echo>                                                                                
                                       <exec dir="target/classes/docker" executable="docker-compose" failonerror="true">
                                            <arg line="config" />
                                        </exec>
                                        <exec dir="target/classes/docker" executable="docker-compose" failonerror="true">
                                            <arg line="up -d" />
                                        </exec>
                                        <chmod file="target/classes/docker/wait-service-to-start.sh" perm="a+x" verbose="true" />
                                        <exec dir="target/classes/docker" executable="bash" failonerror="true">
                                            <arg line="wait-service-to-start.sh http://localhost:8081/alfresco" />
                                        </exec>
                                    </target>
                                </configuration>
                            </execution>
                            <execution>
                                <id>acs-down</id>
                                <phase>pre-clean</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <echo>Stopping ACS from docker-compose!...</echo>
                                        <exec dir="target/classes/docker" executable="docker-compose" failonerror="true">
                                            <arg value="kill" />
                                        </exec>                                                                               
                                    </target>
                                </configuration>
                            </execution>
                        </executions>                        
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
