<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>dev-acs-community-amps-overlay</artifactId>
    <name>Run Tomcat</name>
    <packaging>war</packaging>

    <parent>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-dev-community-tomcat-env</artifactId>
        <version>25.2.0</version>
    </parent>

    <properties>
        <dependency.sis.version>1.3</dependency.sis.version>

        <tomcat.default.solr6.port>8983</tomcat.default.solr6.port>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>dev-community-repo-amps-overlay</artifactId>
            <version>${project.version}</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- Provided dependencies to satisfy Cargo requirement, but not include in built WAR -->
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-server-root</artifactId>
            <version>${dependency.alfresco-server-root.version}</version>
            <type>war</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>api-explorer</artifactId>
            <version>${alfresco.api-explorer.version}</version>
            <type>war</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>dev-community-share-amps-overlay</artifactId>
            <version>${project.version}</version>
            <type>war</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>alfresco</finalName>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven3-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>tomcat10x</containerId>
                        <type>embedded</type>
                        <log>target/cargo.log</log>
                        <systemProperties>
                            <cargo.tomcat.ajp.port>-1</cargo.tomcat.ajp.port>

                            <index.subsystem.name>solr6</index.subsystem.name>
                            <solr.port>${tomcat.default.solr6.port}</solr.port>
                            <dir.root>${runtime.data.folder}/alf_data</dir.root>
                            <solr.host>localhost</solr.host>
                            <solr.base.url>/solr</solr.base.url>
                            <solr.secureComms>secret</solr.secureComms>
                            <solr.sharedSecret>secret</solr.sharedSecret>
                            <encryption.keystore.type>pkcs12</encryption.keystore.type>
                            <encryption.cipherAlgorithm>AES/CBC/PKCS5Padding</encryption.cipherAlgorithm>
                            <encryption.keyAlgorithm>AES</encryption.keyAlgorithm>
                            <metadata-keystore.password>mp6yc0UD9e</metadata-keystore.password>
                            <metadata-keystore.aliases>metadata</metadata-keystore.aliases>
                            <metadata-keystore.metadata.password>mp6yc0UD9e</metadata-keystore.metadata.password>
                            <metadata-keystore.metadata.algorithm>AES</metadata-keystore.metadata.algorithm>
                        </systemProperties>
                    </container>
                    <configuration>
                        <configfiles>
                            <configfile>
                                <file>${runtime.tomcat.conf.folder}/alfresco-context.xml</file>
                                <todir>conf</todir>
                                <tofile>context.xml</tofile>
                            </configfile>
                            <configfile>
                                <file>${runtime.tomcat.conf.folder}/tomcat-users.xml</file>
                                <todir>conf</todir>
                                <tofile>tomcat-users.xml</tofile>
                            </configfile>
                        </configfiles>
                        <files>
                            <file>
                                <file>${runtime.tomcat.conf.folder}/shared</file>
                                <todir>shared</todir>
                            </file>
                        </files>
                    </configuration>
                    <deployables>
                        <deployable>
                            <groupId>org.alfresco</groupId>
                            <artifactId>alfresco-server-root</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>org.alfresco</groupId>
                            <artifactId>api-explorer</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/api-explorer</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>org.alfresco</groupId>
                            <artifactId>dev-community-share-amps-overlay</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/share</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>org.alfresco</groupId>
                            <artifactId>dev-acs-community-amps-overlay</artifactId>
                            <type>war</type>
                            <properties>
                                <context>/alfresco</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
                <dependencies>
                    <!-- Workaround required to make Share work after Tika upgrade -->
                    <dependency>
                        <groupId>org.apache.sis.core</groupId>
                        <artifactId>sis-utility</artifactId>
                        <version>${dependency.sis.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.sis.core</groupId>
                        <artifactId>sis-metadata</artifactId>
                        <version>${dependency.sis.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.sis.storage</groupId>
                        <artifactId>sis-storage</artifactId>
                        <version>${dependency.sis.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <!-- Download and unpack the tomcat config zip file -->
                    <execution>
                        <id>unpack-tomcat-config</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/tomcat-conf</outputDirectory>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.alfresco</groupId>
                                    <artifactId>alfresco-dev-community-tomcat</artifactId>
                                    <version>${project.version}</version>
                                    <classifier>config</classifier>
                                    <overWrite>true</overWrite>
                                    <type>zip</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <!-- Copy tomcat config from build directory to correct location -->
                    <!--
                        Q. Why not unpack directly to ${runtime.tomcat.conf.folder} ?
                        A. There is no way of telling maven NOT to overwrite the directory if it is already there.
                           overWrite doesn't work, overWriteIfNewer doesn't work either. The plugin uses marker files
                           to determine whether the zip has already been unpacked, rather than using the actual folder
                           where the contents are being unpacked - so if a clean is performed the marker files disappear
                           and the zip is unpacked regardless (overwriting your customised tomcat config). Whilst you
                           can change the location of the marker files, doing things this way really is going to be more
                           reliable, since the existing directory will be respected properly.
                     -->
                    <execution>
                        <id>copy-tomcat-config</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath" />
                                <if>
                                    <available file="${runtime.tomcat.conf.folder}" type="dir" />
                                    <then>
                                        <echo message="Skipping creation of tomcat configuration, already exists: ${runtime.tomcat.conf.folder}" />
                                    </then>
                                    <else>
                                        <echo message="Creating tomcat runtime configuration: ${runtime.tomcat.conf.folder}" />
                                        <copy todir="${runtime.tomcat.conf.folder}">
                                            <fileset dir="${project.build.directory}/tomcat-conf" />
                                        </copy>
                                    </else>
                                </if>
                            </target>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>ant-contrib</groupId>
                        <artifactId>ant-contrib</artifactId>
                        <version>20020829</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>license-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>third-party-licenses</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>run</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven3-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>run-exploded-webapp</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
