<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>alfresco-solr</artifactId>
    <name>Alfresco Solr</name>
    <packaging>war</packaging>
    
    <parent>
        <artifactId>alfresco-parent</artifactId>
        <groupId>org.alfresco</groupId>
        <version>5.2.b-EA</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>
    
    <properties>
        <maven.tomcat.path>/solr</maven.tomcat.path>
        <m2eclipse.wtp.contextRoot>${maven.tomcat.path}</m2eclipse.wtp.contextRoot>
        <maven.tomcat.port>${tomcat.default.solr.port}</maven.tomcat.port>
        <maven.tomcat.httpsPort>${tomcat.default.solr.ssl.port}</maven.tomcat.httpsPort>
        <solr.instance.source.folder>source/solr/instance</solr.instance.source.folder>
        <!-- This gets filtered in the solr-tomcat-context.xml and in solrcore.properties when running embedded -->
        <solr.instance.target.folder>${project.build.directory}/solr-instance</solr.instance.target.folder>
        <solr.nossl.instance.target.folder>${solr.instance.target.folder}-nossl</solr.nossl.instance.target.folder>
        <solr.war.target.folder>${project.build.directory}/${project.build.finalName}</solr.war.target.folder>
        <solr.nossl.war.target.folder>${solr.war.target.folder}-nossl</solr.nossl.war.target.folder>
        <!-- By default we selected the SSL enabled default Solr packaging  -->
        <solr.war.exploded.folder>${solr.war.target.folder}</solr.war.exploded.folder>
        <!-- By default we selected the SSL enabled default Solr config  -->
        <solr.config.folder>${solr.instance.target.folder}</solr.config.folder>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-legacy-lucene</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-analyzers</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.lucene</groupId>
                    <artifactId>lucene-snowball</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-solrclient</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!-- provided dependencies -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>2.9.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-regex</artifactId>
            <version>2.9.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-core</artifactId>
            <version>1.4.1</version>
            <exclusions>
                <exclusion>
                    <groupId>woodstox</groupId>
                    <artifactId>wstx-asl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.solr</groupId>
            <artifactId>solr-solrj</artifactId>
            <version>1.4.1</version>
            <exclusions>
                <exclusion>
                    <groupId>woodstox</groupId>
                    <artifactId>wstx-asl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.5.11</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.11</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
        </dependency>

        <!-- War dependency on the Alfresco patched WAR.
             Deployed at artifacts.alfresco.com because SOLR-1218 was closed in later versions  -->
        <dependency>
          <groupId>org.apache.solr</groupId>
          <artifactId>apache-solr</artifactId>
          <version>1.4.1-alfrescopatched-20141112</version>
          <type>war</type>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>solr</finalName>
        <plugins>
            <plugin>
                <!-- Only run a few test methods. All other tests fail, and are never run in the Ant build -->
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                        <test>AlfrescoSolrEventListenerTest#testAllMatch*</test>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>write-alfresco-version</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                            <replaceregexp
                                file="${solr.config.folder}/archive-SpacesStore/conf/solrcore.properties"
                                match="alfresco.version=.*$"
                                replace="alfresco.version=${version.major}.${version.minor}.${version.revision}${version.label} (${version.build})"
                                byline="true"/>
                            <replaceregexp
                                file="${solr.config.folder}/workspace-SpacesStore/conf/solrcore.properties"
                                match="alfresco.version=.*$"
                                replace="alfresco.version=${version.major}.${version.minor}.${version.revision}${version.label} (${version.build})"
                                byline="true"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                    <overlays>
                        <overlay>
                            <groupId>org.apache.solr</groupId>
                            <artifactId>apache-solr</artifactId>
                            <excludes>
                                <exclude>WEB-INF/lib/commons-codec-*.jar</exclude>
                                <exclude>WEB-INF/lib/slf4j-*.jar</exclude>
                                <exclude>WEB-INF/lib/log4j-*.jar</exclude>
                                <!-- MNT-11746 -->
                                <exclude>WEB-INF/classes/log4j.properties</exclude>
                            </excludes>
                        </overlay>
                    </overlays>
                </configuration>
                <!-- This allows overlays to be prepared on the FS for minification and faster run -->
                <executions>
                    <execution>
                        <id>prepare-exploded-war</id>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                        <phase>prepare-package</phase>
                    </execution>
                </executions> 
            </plugin>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-instance-resources</id>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <outputDirectory>${solr.instance.target.folder}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${solr.instance.source.folder}</directory>
                                    <excludes>
                                        <exclude>**/*.jar</exclude>
                                        <exclude>**/*.war*</exclude>
                                        <exclude>**/ssl.repo*</exclude>
                                    </excludes>
                                    <filtering>true</filtering>
                                </resource>
                                <resource>
                                    <directory>${solr.instance.source.folder}</directory>
                                    <includes>
                                        <include>**/ssl.repo*</include>
                                    </includes>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                            <useDefaultDelimiters>false</useDefaultDelimiters>
                            <delimiters>
                                <delimiter>@@</delimiter>
                            </delimiters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>package-config-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <attach>true</attach>
                            <descriptors>
                                <descriptor>
                                    source/assembly/solr-instance-zip.xml
                                </descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        
    </build>
    
    <profiles>
        <!-- Profile to disablesecurecomms  -->
        <profile>
            <id>solr-http</id>
            <properties>
                <!-- We configure the WAR exploded to point to the customized no-ssl folder -->
                <solr.war.exploded.folder>${solr.nossl.war.target.folder}</solr.war.exploded.folder>
                <!-- We configure the solr config to point to the customized no-ssl folder -->
                <solr.config.folder>${solr.nossl.instance.target.folder}</solr.config.folder>
                <ALFRESCO_SOLR_DIR>${solr.config.folder}</ALFRESCO_SOLR_DIR>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-instance-nossl</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <outputDirectory>${solr.nossl.instance.target.folder}</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${solr.instance.target.folder}</directory>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-war-nossl</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>generate-resources</phase>
                                <configuration>
                                    <outputDirectory>${solr.nossl.war.target.folder}</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>${solr.war.target.folder}</directory>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                            <execution>
                                <id>copy-context-config</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <outputDirectory>${solr.war.exploded.folder}/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>source/test-web/META-INF</directory>
                                            <includes>
                                                <include>context.xml</include>
                                            </includes>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                    <useDefaultDelimiters>false</useDefaultDelimiters>
                                    <delimiters>
                                        <delimiter>@@</delimiter>
                                    </delimiters>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <!-- Replaces web.xml where applicable, commenting out the security-constraints -->
                    <plugin>
                        <groupId>com.google.code.maven-replacer-plugin</groupId>
                        <artifactId>replacer</artifactId>
                        <executions>
                            <execution>
                                <id>replace-archive-SpacesStore</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>replace</goal>
                                </goals>
                                <configuration>
                                    <ignoreErrors>true</ignoreErrors>
                                    <file>${solr.config.folder}/archive-SpacesStore/conf/solrcore.properties</file>
                                    <replacements>
                                        <replacement>
                                            <token><![CDATA[alfresco.secureComms=https]]></token>
                                            <value><![CDATA[alfresco.secureComms=none]]></value>
                                        </replacement>
                                    </replacements>
                                </configuration>
                            </execution>
                            <execution>
                                <id>replace-workspace-SpacesStore</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>replace</goal>
                                </goals>
                                <configuration>
                                    <ignoreErrors>true</ignoreErrors>
                                    <file>${solr.config.folder}/workspace-SpacesStore/conf/solrcore.properties</file>
                                    <replacements>
                                        <replacement>
                                            <token><![CDATA[alfresco.secureComms=https]]></token>
                                            <value><![CDATA[alfresco.secureComms=none]]></value>
                                        </replacement>
                                    </replacements>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <executions>
                            <!-- This allows overlays to be prepared on the FS for minification and 
                                faster run -->
                            <execution>
                                <id>prepare-exploded-nossl-war</id>
                                <goals>
                                    <goal>exploded</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <webappDirectory>${solr.nossl.war.target.folder}</webappDirectory>
                                    <webResources>
                                        <!-- To include customized web.xml to disable comms -->
                                        <resource>
                                            <directory>source/test-web/WEB-INF</directory>
                                            <filtering>true</filtering>
                                            <targetPath>WEB-INF</targetPath>
                                        </resource>
                                    </webResources>
                                </configuration>
                            </execution>
                            <execution>
                                <id>package-nossl-war</id>
                                <goals>
                                    <goal>war</goal>
                                </goals>
                                <phase>package</phase>
                                <configuration>
                                    <webappDirectory>${solr.nossl.war.target.folder}</webappDirectory>
                                    <classifier>nossl</classifier>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>


                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>package-config-zip-nossl</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                                <configuration>
                                    <attach>true</attach>
                                    <descriptors>
                                        <descriptor>
                                            source/assembly/solr-instance-zip-nossl.xml
                                        </descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>             
                </plugins>
            </build>
        </profile>

        <!-- Profile to run the webapp on HTTP -->
        <profile>
            <id>run</id>
            <properties>
                <ALFRESCO_SOLR_DIR>${solr.config.folder}</ALFRESCO_SOLR_DIR>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-context-config</id>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <outputDirectory>${solr.war.exploded.folder}/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>source/test-web/META-INF</directory>
                                            <includes>
                                                <include>context.xml</include>
                                            </includes>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                    <useDefaultDelimiters>false</useDefaultDelimiters>
                                    <delimiters>
                                        <delimiter>@@</delimiter>
                                    </delimiters>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <configuration>
                            <webResources>
                                <!-- To add log4j.properties and other test run resources -->
                                <resource>
                                    <directory>source/test-resources</directory>
                                    <filtering>true</filtering>
                                    <targetPath>WEB-INF/classes</targetPath>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>run-exploded-webapp</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>run-war-only</goal>
                                </goals>
                                <configuration>
                                    <contextFile>${solr.war.exploded.folder}/META-INF/context.xml</contextFile>
                                    <warDirectory>${solr.war.exploded.folder}</warDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
