<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>7.4.0-A35</version>
    </parent>

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

        <tomcat.version>7.0.86</tomcat.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>
    </dependencies>

    <build>
        <finalName>alfresco</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <overlays>
                        <overlay>
                            <groupId>org.alfresco</groupId>
                            <artifactId>dev-community-repo-amps-overlay</artifactId>
                            <type>war</type>
                        </overlay>
                    </overlays>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-exploded-war</id>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <systemProperties>
                        <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>
                    <delegate>false</delegate>
                    <useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader>
                    <contextFile>${runtime.tomcat.conf.folder}/alfresco-context.xml</contextFile>
                    <tomcatUsers>${runtime.tomcat.conf.folder}/tomcat-users.xml</tomcatUsers>
                    <webapps>
                        <webapp>
                            <groupId>org.alfresco</groupId>
                            <artifactId>alfresco-server-root</artifactId>
                            <version>${dependency.alfresco-server-root.version}</version>
                            <contextPath>/</contextPath>
                            <type>war</type>
                            <asWebapp>true</asWebapp>
                            <!-- Workaround for https://issues.apache.org/jira/browse/MTOMCAT-269 -->
                            <!-- tomcat7-maven-plugin does not pick up the context.xml file from META-INF -->
                            <contextFile>
                                ${project.build.directory}/tomcat/webapps/alfresco-server-root/META-INF/context.xml
                            </contextFile>
                        </webapp>
                        <webapp>
                            <groupId>org.alfresco</groupId>
                            <artifactId>api-explorer</artifactId>
                            <version>${alfresco.api-explorer.version}</version>
                            <contextPath>/api-explorer</contextPath>
                            <type>war</type>
                            <asWebapp>true</asWebapp>
                        </webapp>
                        <webapp>
                            <groupId>org.alfresco</groupId>
                            <artifactId>dev-community-share-amps-overlay</artifactId>
                            <contextPath>/share</contextPath>
                            <version>${project.version}</version>
                            <type>war</type>
                            <asWebapp>true</asWebapp>
                        </webapp>
                    </webapps>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-core</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-util</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-coyote</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-api</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-jdbc</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-dbcp</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-servlet-api</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-jsp-api</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-jasper</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-jasper-el</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-el-api</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-catalina</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-tribes</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-catalina-ha</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-annotations-api</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat</groupId>
                        <artifactId>tomcat-juli</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-logging-juli</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-logging-log4j</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                    <!-- 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.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-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>
