<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>
   <packaging>amp</packaging>
   <name>Alfresco Governance Services Community Repository AMP</name>
   <description>Alfresco Governance Services Repository Extension</description>

   <parent>
      <groupId>org.alfresco</groupId>
      <artifactId>alfresco-governance-services-community-repo-parent</artifactId>
      <version>23.3.1.4</version>
   </parent>

   <properties>
      <app.amp.client.war.folder>${project.build.directory}/${project.build.finalName}-war</app.amp.client.war.folder>

      <image.name>alfresco/alfresco-governance-repository-community-base</image.name>
      <base.image>alfresco/alfresco-community-repo-base</base.image>
      <scripts.directory>${project.parent.parent.parent.parent.basedir}/scripts</scripts.directory>
   </properties>

   <dependencies>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-data-model</artifactId>
         <version>${project.version}</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-remote-api</artifactId>
         <version>${project.version}</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-repository</artifactId>
         <version>${project.version}</version>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-repository</artifactId>
         <version>${project.version}</version>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-remote-api</artifactId>
         <version>${project.version}</version>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.alfresco</groupId>
         <artifactId>alfresco-core</artifactId>
         <version>${project.version}</version>
         <classifier>tests</classifier>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>jakarta.servlet</groupId>
         <artifactId>jakarta.servlet-api</artifactId>
      </dependency>
      <dependency>
         <groupId>jakarta.mail</groupId>
         <artifactId>jakarta.mail-api</artifactId>
      </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>com.epam.reportportal</groupId>
         <artifactId>agent-java-testng</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.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>
         <scope>test</scope>
      </dependency>
      <!-- swagger parser -->
      <dependency>
         <groupId>io.swagger</groupId>
         <artifactId>swagger-parser</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>com.networknt</groupId>
         <artifactId>json-schema-validator</artifactId>
         <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</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>
       <dependency>
           <groupId>org.projectlombok</groupId>
           <artifactId>lombok</artifactId>
           <scope>provided</scope>
       </dependency>
      <dependency>
         <groupId>org.awaitility</groupId>
         <artifactId>awaitility</artifactId>
         <version>${dependency.awaitility.version}</version>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <build>
      <sourceDirectory>source/java</sourceDirectory>
      <testSourceDirectory>test/java</testSourceDirectory>

      <resources>
         <resource>
            <directory>config</directory>
            <filtering>true</filtering>
         </resource>
      </resources>
      <testResources>
         <testResource>
            <directory>unit-test/resources</directory>
         </testResource>
         <testResource>
            <directory>test/resources</directory>
         </testResource>
         <testResource>
            <directory>src/test/properties/local</directory>
            <filtering>true</filtering>
         </testResource>
      </testResources>

      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
               <execution>
                  <id>add-source</id>
                  <phase>generate-sources</phase>
                  <goals>
                     <goal>add-source</goal>
                  </goals>
                  <configuration>
                     <sources>
                        <source>source/compatibility</source>
                     </sources>
                  </configuration>
               </execution>
               <execution>
                  <id>add-test-source</id>
                  <phase>generate-test-sources</phase>
                  <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}" />
                        <copy file="${project.build.directory}/generated-sources/license/THIRD-PARTY.txt" todir="${project.build.directory}/${project.build.finalName}/licenses/${artifactId}" />
                     </target>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
               <redirectTestOutputToFile>true</redirectTestOutputToFile>
               <runOrder>alphabetical</runOrder>
               <includes>
                  <include>**/AllUnitTestSuite.class</include>
               </includes>
            </configuration>
         </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>${db.name}</db.name>
                        <db.driver>${alfresco.db.datasource.class}</db.driver>
                        <db.url>${alfresco.db.url}</db.url>
                        <dir.root>${project.build.directory}/alf-data-test</dir.root>
                     </systemPropertyVariables>
                     <includes>
                        <include>${integrationTestSuite}</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-artefacts-for-docker-build</id>
                  <phase>prepare-package</phase>
                  <goals>
                     <goal>copy</goal>
                  </goals>
                  <configuration>
                     <artifactItems>
                        <artifactItem>
                           <groupId>org.alfresco</groupId>
                           <artifactId>alfresco-share-services</artifactId>
                           <version>${project.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>
            </executions>
         </plugin>

         <plugin>
            <groupId>org.alfresco.maven.plugin</groupId>
            <artifactId>alfresco-maven-plugin</artifactId>
         </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>
            <executions>
               <execution>
                  <id>first</id>
                  <phase>process-sources</phase>
                  <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>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

   <profiles>
       <profile>
           <id>agsAllTestSuitePt1</id>
           <properties>
               <integrationTestSuite>**/AllTestSuitePt1.class</integrationTestSuite>
           </properties>
       </profile>
       <profile>
           <id>agsAllTestSuitePt2</id>
           <properties>
               <integrationTestSuite>**/AllTestSuitePt2.class</integrationTestSuite>
           </properties>
       </profile>
       <profile>
           <id>agsAllTestSuitePt3</id>
           <properties>
               <integrationTestSuite>**/AllTestSuitePt3.class</integrationTestSuite>
           </properties>
       </profile>
       <profile>
           <id>agsAllTestSuitePt4</id>
           <properties>
               <integrationTestSuite>**/AllTestSuitePt4.class</integrationTestSuite>
           </properties>
       </profile>

      <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 used for running integration tests using postgres database -->
      <profile>
         <id>start-postgres</id>
         <properties>
            <db.name>${alfresco.test.db.name}</db.name>
            <alfresco.db.port>${postgresql.tests.port}</alfresco.db.port>
            <alfresco.db.master.url>jdbc:postgresql://${alfresco.db.host}:${alfresco.db.port}/${db.name}</alfresco.db.master.url>
            <alfresco.db.url>jdbc:postgresql://${alfresco.db.host}:${alfresco.db.port}/${db.name}</alfresco.db.url>
            <alfresco.db.datasource.class>org.postgresql.Driver</alfresco.db.datasource.class>
         </properties>
         <build>
            <plugins>
               <plugin>
                  <groupId>io.fabric8</groupId>
                  <artifactId>docker-maven-plugin</artifactId>
                  <configuration>
                     <images>
                        <image>
                           <name>postgres:15.4</name>
                           <run>
                              <ports>
                                 <port>${postgresql.tests.port}:${postgresql.port}</port>
                              </ports>
                              <env>
                                 <POSTGRES_PASSWORD>${alfresco.db.password}</POSTGRES_PASSWORD>
                                 <POSTGRES_USER>${alfresco.db.username}</POSTGRES_USER>
                                 <POSTGRES_DB>${alfresco.test.db.name}</POSTGRES_DB>
                              </env>
                              <cmd>
                                 <shell>-c max_connections=300</shell>
                              </cmd>
                              <wait>
                                 <log>database system is ready to accept connections</log>
                                 <time>20000</time>
                              </wait>
                           </run>
                        </image>
                        <image>
                           <name>alfresco/alfresco-activemq:${dependency.activemq.version}-jre17-rockylinux8</name>
                           <run>
                              <ports>
                                 <port>${activemq.port1}:${activemq.port1}</port>
                                 <port>${activemq.port2}:${activemq.port2}</port>
                              </ports>
                           </run>
                        </image>
                     </images>
                  </configuration>
                  <executions>
                     <execution>
                        <id>before-integration-tests</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                           <goal>stop</goal>
                           <goal>start</goal>
                        </goals>
                     </execution>
                     <execution>
                        <id>after-integration-tests</id>
                        <phase>post-integration-test</phase>
                        <goals>
                           <goal>stop</goal>
                        </goals>
                     </execution>
                  </executions>
               </plugin>
            </plugins>
         </build>
      </profile>

      <!-- Profile used for running integration tests using mysql database -->
      <profile>
         <id>start-mysql</id>
         <properties>
            <db.name>${alfresco.db.name}</db.name>
            <alfresco.db.port>${mysql.tests.port}</alfresco.db.port>
            <alfresco.db.master.url>jdbc:mysql://${alfresco.db.host}:${alfresco.db.port}/${db.name}</alfresco.db.master.url>
            <alfresco.db.url>jdbc:mysql://${alfresco.db.host}:${alfresco.db.port}/${db.name}</alfresco.db.url>
            <alfresco.db.datasource.class>com.mysql.cj.jdbc.Driver</alfresco.db.datasource.class>
         </properties>
         <build>
            <plugins>
               <plugin>
                  <groupId>io.fabric8</groupId>
                  <artifactId>docker-maven-plugin</artifactId>
                  <configuration>
                     <images>
                        <image>
                           <name>mysql:${dependency.mysql-image.version}</name>
                           <run>
                              <ports>
                                 <port>${mysql.tests.port}:${mysql.port}</port>
                              </ports>
                              <env>
                                 <MYSQL_ROOT_PASSWORD>${alfresco.db.password}</MYSQL_ROOT_PASSWORD>
                                 <MYSQL_PASSWORD>${alfresco.db.password}</MYSQL_PASSWORD>
                                 <MYSQL_USER>${alfresco.db.username}</MYSQL_USER>
                                 <MYSQL_DATABASE>${alfresco.db.name}</MYSQL_DATABASE>
                              </env>
                              <cmd>
                                 <arg>--transaction-isolation=READ-COMMITTED</arg>
                              </cmd>
                              <wait>
                                 <log>mysqld: ready for connections</log>
                                 <time>20000</time>
                              </wait>
                           </run>
                        </image>
                        <image>
                           <name>alfresco/alfresco-activemq:${dependency.activemq.version}-jre17-rockylinux8</name>
                           <run>
                              <ports>
                                 <port>${activemq.port1}:${activemq.port1}</port>
                                 <port>${activemq.port2}:${activemq.port2}</port>
                              </ports>
                           </run>
                        </image>
                     </images>
                  </configuration>
                  <executions>
                     <execution>
                        <id>before-integration-tests</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                           <goal>stop</goal>
                           <goal>start</goal>
                        </goals>
                     </execution>
                     <execution>
                        <id>after-integration-tests</id>
                        <phase>post-integration-test</phase>
                        <goals>
                           <goal>stop</goal>
                        </goals>
                     </execution>
                  </executions>
               </plugin>
            </plugins>
         </build>
      </profile>

      <profile>
         <id>build-docker-images</id>
         <!-- builds "image:latest" locally -->
         <build>
            <plugins>
               <plugin>
                  <groupId>io.fabric8</groupId>
                  <artifactId>docker-maven-plugin</artifactId>
                  <configuration>
                     <images>
                        <image>
                           <name>${image.name}:${image.tag}</name>
                           <build>
                              <args>
                                 <BASE_IMAGE>${base.image}:${image.tag}</BASE_IMAGE>
                              </args>
                              <contextDir>${project.basedir}</contextDir>
                           </build>
                        </image>
                     </images>
                  </configuration>
                  <executions>
                     <execution>
                        <id>build-image</id>
                        <phase>package</phase>
                        <goals>
                           <goal>build</goal>
                        </goals>
                     </execution>
                  </executions>
               </plugin>
            </plugins>
         </build>
      </profile>

       <profile>
          <id>build-multiarch-docker-images</id>
          <build>
             <plugins>
                <plugin>
                   <groupId>io.fabric8</groupId>
                   <artifactId>docker-maven-plugin</artifactId>
                   <configuration>
                      <images>
                         <image>
                            <name>${local.registry}/${image.name}:${image.tag}</name>
                            <build>
                               <buildx>
                                  <platforms>
                                     <platform>linux/amd64</platform>
                                     <platform>linux/arm64</platform>
                                  </platforms>
                                  <builderName>${builder.name}</builderName>
                               </buildx>
                               <contextDir>${project.basedir}</contextDir>
                               <args>
                                  <BASE_IMAGE>${local.registry}/${base.image}:${image.tag}</BASE_IMAGE>
                               </args>
                            </build>
                         </image>
                      </images>
                   </configuration>
                   <executions>
                      <execution>
                         <id>build-push-image</id>
                         <phase>package</phase>
                         <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                         </goals>
                      </execution>
                   </executions>
                </plugin>
                <plugin>
                   <artifactId>exec-maven-plugin</artifactId>
                   <groupId>org.codehaus.mojo</groupId>
                   <executions>
                      <execution>
                         <id>prepare-buildx</id>
                         <phase>generate-sources</phase>
                         <goals>
                            <goal>exec</goal>
                         </goals>
                         <configuration>
                            <executable>${scripts.directory}/prepare_buildx.sh</executable>
                            <arguments>
                               <argument>${builder.name}</argument>
                               <argument>${image.registry}</argument>
                               <argument>${image.name}</argument>
                               <argument>${image.tag}</argument>
                            </arguments>
                         </configuration>
                      </execution>
                   </executions>
                </plugin>
             </plugins>
          </build>
       </profile>

       <profile>
          <id>push-docker-images</id>
          <!-- publishes "image:latest" on Quay & DockerHub -->
          <build>
             <plugins>
                <plugin>
                   <groupId>io.fabric8</groupId>
                   <artifactId>docker-maven-plugin</artifactId>
                   <configuration>
                      <images>
                         <image>
                            <!-- Quay image -->
                            <name>${image.registry}/${image.name}:${image.tag}</name>
                            <build>
                               <buildx>
                                  <platforms>
                                     <platform>linux/amd64</platform>
                                     <platform>linux/arm64</platform>
                                  </platforms>
                                  <builderName>${builder.name}</builderName>
                               </buildx>
                               <args>
                                  <BASE_IMAGE>${local.registry}/${base.image}:${image.tag}</BASE_IMAGE>
                               </args>
                               <contextDir>${project.basedir}</contextDir>
                            </build>
                         </image>
                         <image>
                            <!-- DockerHub image -->
                            <name>${image.name}:${image.tag}</name>
                            <build>
                               <buildx>
                                  <platforms>
                                     <platform>linux/amd64</platform>
                                     <platform>linux/arm64</platform>
                                  </platforms>
                                  <builderName>${builder.name}</builderName>
                               </buildx>
                               <args>
                                  <BASE_IMAGE>${local.registry}/${base.image}:${image.tag}</BASE_IMAGE>
                               </args>
                               <contextDir>${project.basedir}</contextDir>
                            </build>
                         </image>
                      </images>
                   </configuration>
                   <executions>
                      <execution>
                         <id>build-push-image</id>
                         <phase>install</phase>
                         <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                         </goals>
                      </execution>
                   </executions>
                </plugin>
                 <plugin>
                     <artifactId>exec-maven-plugin</artifactId>
                     <groupId>org.codehaus.mojo</groupId>
                     <executions>
                        <execution>
                            <id>prepare-buildx</id>
                            <phase>generate-sources</phase>
                            <goals>
                               <goal>exec</goal>
                            </goals>
                            <configuration>
                               <executable>${scripts.directory}/prepare_buildx.sh</executable>
                               <arguments>
                                  <argument>${builder.name}</argument>
                                  <argument>${image.registry}</argument>
                                  <argument>${image.name}</argument>
                                  <argument>${image.tag}</argument>
                               </arguments>
                            </configuration>
                        </execution>
                     </executions>
                 </plugin>
             </plugins>
          </build>
       </profile>
   </profiles>
</project>
