<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>
   <artifactId>alfresco-governance-services-community-repo</artifactId>
   <name>AGS Repo</name>
   <description>Alfresco Governance Services Repository Extension</description>
   <packaging>amp</packaging>

   <parent>
      <groupId>org.alfresco</groupId>
      <artifactId>alfresco-governance-services-community</artifactId>
      <version>3.5.a</version>
   </parent>

   <properties>

      <alfresco.data.location>${basedir}/target/alf_test_data</alfresco.data.location>
      <alfresco.db.hibernate.dialect>org.alfresco.repo.domain.dialect.MySQLInnoDBDialect</alfresco.db.hibernate.dialect>
      <alfresco.db.name>alfresco</alfresco.db.name>
      <alfresco.db.username>alfresco</alfresco.db.username>
      <alfresco.db.password>alfresco</alfresco.db.password>
      <alfresco.db.host>localhost</alfresco.db.host>
      <alfresco.test.db.name>alfresco-test</alfresco.test.db.name>
      <alfresco.repo.artifactId>alfresco-platform</alfresco.repo.artifactId>
      <alfresco.postgres.version>9.1-901.jdbc4</alfresco.postgres.version>
      <ags.artifactId>alfresco-governance-services-community-repo</ags.artifactId>
      <!-- 7.0.0 dependencies -->
      <!--  Alfresco Share version  -->
      <alfresco.alfresco-share-services.version>7.0.0-A18</alfresco.alfresco-share-services.version>
      <image.name>alfresco/alfresco-governance-repository-community</image.name>

      <maven.javadoc.skip>false</maven.javadoc.skip>

   </properties>

   <build>
      <sourceDirectory>source/java</sourceDirectory>
      <testSourceDirectory>test/java</testSourceDirectory>
      <resources>
         <resource>
            <directory>config</directory>
            <filtering>${app.filtering.enabled}</filtering>
         </resource>
      </resources>
      <testResources>
         <testResource>
            <directory>unit-test/resources</directory>
         </testResource>
         <testResource>
            <directory>test/resources</directory>
         </testResource>
      </testResources>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
               <execution>
                  <id>add-source</id>
                  <goals>
                     <goal>add-source</goal>
                  </goals>
                  <configuration>
                     <sources>
                        <source>source/compatibility</source>
                     </sources>
                  </configuration>
               </execution>
               <execution>
                  <id>add-test-source</id>
                  <goals>
                     <goal>add-test-source</goal>
                  </goals>
                  <configuration>
                     <sources>
                        <source>unit-test/java</source>
                     </sources>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
               <execution>
                  <phase>prepare-package</phase>
                  <goals>
                     <goal>run</goal>
                  </goals>
                  <configuration>
                     <target>
                        <move todir="${project.build.directory}/${project.build.finalName}/config/alfresco">
                           <fileset dir="${project.build.outputDirectory}/alfresco" />
                        </move>
                        <copy file="${project.build.directory}/${project.build.finalName}/config/alfresco/module/org_alfresco_module_rm/module.properties" todir="${project.build.directory}/${project.build.finalName}" />
                     </target>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <executions>
               <execution>
                  <phase>initialize</phase>
                  <goals>
                     <goal>read-project-properties</goal>
                  </goals>
                  <configuration>
                     <files>
                        <file>${basedir}/src/main/resources/local.properties</file>
                     </files>
                     <quiet>true</quiet>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
               <includes>
                  <include>**/AllUnitTestSuite.class</include>
               </includes>
            </configuration>
         </plugin>
         <!--Docker Maven Plugin-->
         <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
               <execution>
                  <id>integration-tests</id>
                  <phase>integration-test</phase>
                  <goals>
                     <goal>integration-test</goal>
                     <goal>verify</goal>
                  </goals>
                  <configuration>
                     <systemPropertyVariables>
                        <db.name>${alfresco.test.db.name}</db.name>
                        <db.driver>org.postgresql.Driver</db.driver>
                        <db.url>jdbc:postgresql://localhost:${database.port}/${alfresco.test.db.name}</db.url>
                        <dir.root>${project.build.directory}/alf-data-test</dir.root>
                     </systemPropertyVariables>
                     <skipTests>${skip.integrationtests}</skipTests>
                     <includes>
                        <include>**/AllTestSuite.class</include>
                     </includes>
                     <additionalClasspathElements>
                        <additionalClasspathElement>${project.build.directory}/${project.build.finalName}/config</additionalClasspathElement>
                     </additionalClasspathElements>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
               <execution>
                  <id>fetch-share-services-amp</id>
                  <phase>process-test-resources</phase>
                  <goals>
                     <goal>copy</goal>
                  </goals>
                  <configuration>
                     <artifactItems>
                        <artifactItem>
                           <groupId>org.alfresco</groupId>
                           <artifactId>alfresco-share-services</artifactId>
                           <version>${alfresco.alfresco-share-services.version}</version>
                           <type>amp</type>
                        </artifactItem>
                        <artifactItem>
                           <groupId>org.alfresco</groupId>
                           <artifactId>alfresco-governance-services-community-rest-api-explorer</artifactId>
                           <version>${project.version}</version>
                           <type>war</type>
                           <destFileName>gs-api-explorer-${project.version}.war</destFileName>
                        </artifactItem>
                     </artifactItems>
                     <outputDirectory>${project.build.directory}</outputDirectory>
                  </configuration>
               </execution>
               <execution>
                  <id>unpack-alfresco</id>
                  <phase>prepare-package</phase>
                  <goals>
                     <goal>unpack</goal>
                  </goals>
                  <configuration>
                     <outputDirectory>${app.amp.client.war.folder}</outputDirectory>
                     <artifactItems>
                        <artifactItem>
                           <groupId>${alfresco.groupId}</groupId>
                           <artifactId>content-services-community</artifactId>
                           <type>war</type>
                           <version>${alfresco-community-repo.version}</version>
                        </artifactItem>
                     </artifactItems>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.alfresco.maven.plugin</groupId>
            <artifactId>alfresco-maven-plugin</artifactId>
            <executions>
               <execution>
                  <id>attach-alfresco-governance-services-jar</id>
                  <goals>
                     <goal>amp</goal>
                  </goals>
                  <configuration>
                     <attachClasses>true</attachClasses>
                     <attachConfig>true</attachConfig>
                     <includeDependencies>true</includeDependencies>

                  </configuration>
               </execution>
               <execution>
                  <id>amps-to-war-overlay</id>
                  <phase>package</phase>
                  <goals>
                     <goal>install</goal>
                  </goals>
               </execution>
               <execution>
                  <id>install-share-services-amp</id>
                  <goals>
                     <goal>install</goal>
                  </goals>
                  <phase>prepare-package</phase>
                  <configuration>
                     <backup>true</backup>
                     <ampLocation>${project.build.directory}/alfresco-share-services-${alfresco.alfresco-share-services.version}.amp</ampLocation>
                     <warLocation>${app.amp.client.war.folder}</warLocation>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
               <execution>
                  <goals>
                     <goal>test-jar</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <excludes>
                  <exclude>**/alfresco-global.properties</exclude>
               </excludes>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>license-maven-plugin</artifactId>
            <configuration>
               <licenseName>alfresco_community</licenseName>
               <roots>
                  <root>source/java</root>
                  <root>unit-test/java</root>
                  <root>source/compatibility</root>
                  <root>config</root>
                  <root>test/java</root>
                  <root>test/resources</root>
               </roots>
            </configuration>
         </plugin>
      </plugins>
      <pluginManagement>
         <plugins>
            <plugin>
               <groupId>org.eclipse.m2e</groupId>
               <artifactId>lifecycle-mapping</artifactId>
               <configuration>
                  <lifecycleMappingMetadata>
                     <pluginExecutions>
                        <pluginExecution>
                           <pluginExecutionFilter>
                              <groupId>org.codehaus.mojo</groupId>
                              <artifactId>properties-maven-plugin</artifactId>
                              <versionRange>[1.0-alpha-2,)</versionRange>
                              <goals>
                                 <goal>read-project-properties</goal>
                              </goals>
                           </pluginExecutionFilter>
                           <action>
                              <ignore />
                           </action>
                        </pluginExecution>
                        <pluginExecution>
                           <pluginExecutionFilter>
                              <groupId>org.codehaus.mojo</groupId>
                              <artifactId>license-maven-plugin</artifactId>
                              <versionRange>[1.8,)</versionRange>
                              <goals>
                                 <goal>update-file-header</goal>
                              </goals>
                           </pluginExecutionFilter>
                           <action>
                              <ignore />
                           </action>
                        </pluginExecution>
                     </pluginExecutions>
                  </lifecycleMappingMetadata>
               </configuration>
            </plugin>
         </plugins>
      </pluginManagement>
   </build>

   <dependencies>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-data-model</artifactId>
         <version>${alfresco-community-repo.version}</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>${alfresco.groupId}</groupId>
         <artifactId>alfresco-remote-api</artifactId>
         <version>${alfresco-community-repo.version}</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>${alfresco.groupId}</groupId>
         <artifactId>alfresco-repository</artifactId>
         <version>${alfresco-community-repo.version}</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>${alfresco.groupId}</groupId>
         <artifactId>alfresco-repository</artifactId>
         <version>${alfresco-community-repo.version}</version>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>${alfresco.groupId}</groupId>
         <artifactId>alfresco-remote-api</artifactId>
         <version>${alfresco-community-repo.version}</version>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>${alfresco.groupId}</groupId>
         <artifactId>alfresco-core</artifactId>
         <version>${alfresco-community-repo.version}</version>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.alfresco.surf</groupId>
         <artifactId>spring-webscripts</artifactId>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>io.takari.junit</groupId>
         <artifactId>takari-cpsuite</artifactId>
         <version>1.2.7</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>postgresql</groupId>
         <artifactId>postgresql</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>org.reflections</groupId>
          <artifactId>reflections</artifactId>
          <version>0.9.12</version>
          <scope>test</scope>
      </dependency>
      <!-- swagger parser -->
      <dependency>
         <groupId>io.swagger</groupId>
         <artifactId>swagger-parser</artifactId>
         <version>1.0.52</version>
         <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/com.github.fge/json-schema-validator -->
     <dependency>
         <groupId>com.github.fge</groupId>
         <artifactId>json-schema-validator</artifactId>
         <version>2.2.6</version>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-all</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-core</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-annotations</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.core</groupId>
         <artifactId>jackson-databind</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.datatype</groupId>
         <artifactId>jackson-datatype-joda</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>com.fasterxml.jackson.dataformat</groupId>
         <artifactId>jackson-dataformat-yaml</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-test</artifactId>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <profiles>

      <profile>
         <id>use-mysql</id>
         <properties>
            <alfresco.db.name>${my.db.name}</alfresco.db.name>
            <alfresco.db.port>${my.db.port}</alfresco.db.port>
            <alfresco.db.hibernate.dialect>org.alfresco.repo.domain.dialect.MySQLInnoDBDialect</alfresco.db.hibernate.dialect>
            <alfresco.db.params />
            <alfresco.db.master.url>jdbc:mysql://${alfresco.db.host}:${alfresco.db.port}/${alfresco.db.name}</alfresco.db.master.url>
            <alfresco.db.url>jdbc:mysql://${alfresco.db.host}:${alfresco.db.port}/${alfresco.db.name}</alfresco.db.url>
            <alfresco.db.datasource.class>org.gjt.mm.mysql.Driver</alfresco.db.datasource.class>
         </properties>
      </profile>
      <profile>
         <id>use-postgres</id>
         <properties>
            <alfresco.db.name>${my.db.name}</alfresco.db.name>
            <alfresco.db.port>${my.db.port}</alfresco.db.port>
            <alfresco.db.hibernate.dialect>org.alfresco.repo.domain.dialect.PostgreSQLDialect</alfresco.db.hibernate.dialect>
            <alfresco.db.params />
            <alfresco.db.master.url>jdbc:postgresql:template1</alfresco.db.master.url>
            <alfresco.db.url>jdbc:postgresql:${alfresco.db.name}</alfresco.db.url>
            <alfresco.db.datasource.class>org.postgresql.Driver</alfresco.db.datasource.class>
         </properties>
      </profile>
      <profile>
         <id>start-repo</id>
         <build>
            <plugins>
               <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-dependency-plugin</artifactId>
                  <executions>
                     <execution>
                        <id>unpack-alfresco</id>
                        <phase>prepare-package</phase>
                        <goals>
                           <goal>unpack</goal>
                        </goals>
                        <configuration>
                           <outputDirectory>${app.amp.client.war.folder}</outputDirectory>
                           <artifactItems>
                              <artifactItem>
                                 <groupId>${alfresco.groupId}</groupId>
                                 <artifactId>content-services-community</artifactId>
                                 <type>war</type>
                                 <version>${alfresco-community-repo.version}</version>
                              </artifactItem>
                           </artifactItems>
                        </configuration>
                     </execution>
                  </executions>
               </plugin>
               <plugin>
                  <groupId>org.alfresco.maven.plugin</groupId>
                  <artifactId>alfresco-maven-plugin</artifactId>
                  <executions>
                     <execution>
                        <id>amps-to-war-overlay</id>
                        <phase>package</phase>
                        <goals>
                           <goal>install</goal>
                        </goals>
                     </execution>
                  </executions>
                  <configuration>
                     <includeWebResources>false</includeWebResources>
                  </configuration>
               </plugin>
               <plugin>
                  <groupId>org.apache.tomcat.maven</groupId>
                  <artifactId>tomcat7-maven-plugin</artifactId>
                  <executions>
                     <execution>
                        <id>run-embedded</id>
                        <goals>
                           <goal>run</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                           <useTestClasspath>false</useTestClasspath>
                           <ignorePackaging>true</ignorePackaging>
                           <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
                           <systemProperties>
                              <java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
                           </systemProperties>
                           <delegate>false</delegate>
                           <contextFile>${project.basedir}/tomcat/context.xml</contextFile>
                           <webapps>
                              <webapp>
                                 <groupId>org.alfresco</groupId>
                                 <artifactId>api-explorer</artifactId>
                                 <version>${api.explorer.version}</version>
                                 <contextPath>/api-explorer</contextPath>
                                 <type>war</type>
                                 <asWebapp>true</asWebapp>
                              </webapp>
                              <webapp>
                                 <groupId>org.alfresco</groupId>
                                 <artifactId>alfresco-governance-services-community-rest-api-explorer</artifactId>
                                 <version>${project.version}</version>
                                 <contextPath>/gs-api-explorer</contextPath>
                                 <type>war</type>
                                 <asWebapp>true</asWebapp>
                              </webapp>
                           </webapps>
                        </configuration>
                     </execution>
                  </executions>
                  <dependencies>
                     <dependency>
                        <groupId>postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${alfresco.postgres.version}</version>
                     </dependency>
                     <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>${mysql.version}</version>
                     </dependency>
                  </dependencies>
               </plugin>
            </plugins>
         </build>
      </profile>
      <profile>
         <id>wipeDB</id>
         <build>
            <plugins>
               <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>sql-maven-plugin</artifactId>
                  <configuration>
                     <autocommit>true</autocommit>
                     <driver>${alfresco.db.datasource.class}</driver>
                     <url>${alfresco.db.master.url}</url>
                     <username>${alfresco.db.username}</username>
                     <password>${alfresco.db.password}</password>
                  </configuration>
                  <dependencies>
                     <dependency>
                        <groupId>postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${alfresco.postgres.version}</version>
                     </dependency>
                     <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>${mysql.version}</version>
                     </dependency>
                  </dependencies>
                  <executions>
                     <execution>
                        <id>wipe-database</id>
                        <phase>process-test-resources</phase>
                        <goals>
                           <goal>execute</goal>
                        </goals>
                        <configuration>
                           <sqlCommand>drop database if exists alfresco</sqlCommand>
                        </configuration>
                     </execution>
                     <execution>
                        <id>create-database</id>
                        <phase>process-test-resources</phase>
                        <goals>
                           <goal>execute</goal>
                        </goals>
                        <configuration>
                           <sqlCommand>create database alfresco</sqlCommand>
                        </configuration>
                     </execution>
                  </executions>
               </plugin>
            </plugins>
         </build>
      </profile>
       <!--Docker profiles used to build specific docker images for community repo, defined in parent pom -->
       <profile>
           <id>buildDockerImage</id>
           <build>
               <plugins>
                   <plugin>
                       <groupId>io.fabric8</groupId>
                       <artifactId>docker-maven-plugin</artifactId>
                   </plugin>
               </plugins>
           </build>
       </profile>
       <profile>
           <id>publish-docker-latest</id>
           <build>
               <plugins>
                   <plugin>
                       <groupId>io.fabric8</groupId>
                       <artifactId>docker-maven-plugin</artifactId>
                   </plugin>
               </plugins>
           </build>
       </profile>
      <profile>
         <id>release-community</id>
         <build>
            <plugins>
               <plugin>
                  <groupId>io.fabric8</groupId>
                  <artifactId>docker-maven-plugin</artifactId>
               </plugin>
            </plugins>
         </build>
      </profile>
      <profile>
         <id>start-db</id>
         <activation>
            <property>
               <name>skip.integrationtests</name>
               <value>false</value>
            </property>
         </activation>
         <build>
            <plugins>
               <plugin>
                  <groupId>io.fabric8</groupId>
                  <artifactId>docker-maven-plugin</artifactId>
               </plugin>
            </plugins>
         </build>
      </profile>
   </profiles>
</project>
