<?xml version="1.0" encoding="UTF-8"?>

<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>

    <parent>
        <groupId>com.atlassian.confluence.plugins.search</groupId>
        <artifactId>confluence-search-plugin-parent</artifactId>
        <version>3.1.1</version>
    </parent>

    <artifactId>confluence-search</artifactId>
    <packaging>atlassian-plugin</packaging>

    <name>Confluence Search Plugin</name>
    <description>This is the Confluence Search Plugin for Atlassian Confluence.</description>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.querylang</groupId>
            <artifactId>confluence-query-lang-spi</artifactId>
            <version>${cql.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-java-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence.plugins</groupId>
            <artifactId>confluence-aui-staging</artifactId>
            <version>${confluence.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence.plugins</groupId>
            <artifactId>confluence-soy</artifactId>
            <version>${confluence.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-rest-client</artifactId>
            <version>${confluence.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence-test-utils</artifactId>
            <version>2.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-confluence-plugin</artifactId>
                <configuration>
                    <enableQuickReload>true</enableQuickReload>
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                        <!-- Add package to export here -->
                        <Export-Package>
                            com.atlassian.confluence.plugins.search.api,
                            com.atlassian.confluence.plugins.search.api.*
                        </Export-Package>

                        <!-- Add package import here -->
                        <Import-Package>
                            *;;resolution:="optional"
                        </Import-Package>

                        <!-- Ensure plugin is spring powered - see https://extranet.atlassian.com/x/xBS9hQ  -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.atlassian.plugin</groupId>
                <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
                <version>${atlassian.spring.scanner.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>atlassian-spring-scanner</goal>
                        </goals>
                        <phase>process-classes</phase>
                    </execution>
                </executions>
                <configuration>
                    <verbose>false</verbose>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Profile for Karma unit testing. Skips all other tests -->
            <id>karma</id>
            <dependencies>
                <!-- Only exists for qunit -->
                <dependency>
                    <groupId>com.atlassian.aui</groupId>
                    <artifactId>auiplugin</artifactId>
                    <version>${aui.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.atlassian.aui</groupId>
                    <artifactId>aui-flat-pack</artifactId>
                    <version>${aui.version}</version>
                    <type>zip</type>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.atlassian.plugins</groupId>
                    <artifactId>jquery</artifactId>
                    <version>${jquery.version}</version>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.atlassian.soy</groupId>
                    <artifactId>soy-template-plugin</artifactId>
                    <scope>test</scope>
                </dependency>
                <dependency>
                    <groupId>com.atlassian.aui</groupId>
                    <artifactId>aui-soy</artifactId>
                    <version>${aui.version}</version>
                    <scope>test</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin><!-- Install npm modules first -->
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.2.1</version>
                        <executions>
                            <execution>
                                <id>install-npm-modules</id>
                                <phase>generate-test-sources</phase>
                                <goals>
                                    <goal>exec</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <executable>npm</executable>
                            <arguments>
                                <argument>install</argument>
                            </arguments>
                        </configuration>
                    </plugin>
                    <plugin><!-- Extract AUI for use in tests -->
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>extract-qunit-dependencies</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/qunit/dependencies</outputDirectory>
                                    <includeGroupIds>
                                        com.atlassian.aui,
                                        com.atlassian.soy,
                                        com.atlassian.plugins
                                    </includeGroupIds>
                                    <includeArtifactIds>
                                        jquery,
                                        auiplugin,
                                        soy-template-plugin,
                                        aui-flat-pack
                                    </includeArtifactIds>
                                    <includes>i18n/aui.properties</includes>
                                    <includes>**/*.js,**/*.soy,**/*.properties</includes>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <useJvmChmod>true</useJvmChmod>
                        </configuration>
                    </plugin>
                    <plugin><!-- Run the karma tests during test phase -->
                        <groupId>com.kelveden</groupId>
                        <artifactId>maven-karma-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <id>run-karma-tests</id>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <!-- Use Phantom for the automated build because I couldn't get Chrome to work on a Bamboo agent -->
                            <browsers>PhantomJS</browsers>
                            <karmaExecutable>node_modules/karma/bin/karma</karmaExecutable>
                            <reporters>junit,mocha</reporters>
                        </configuration>
                    </plugin>

                    <plugin><!-- TODO: Update this to use the new Atlassian Soy CLI.
                        See https://extranet.atlassian.com/display/~sharwood/2014/12/05/Introducing+Atlassian+Soy+Karma+Plugin -->
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>soy-to-js-maven-plugin</artifactId>
                        <version>1.8</version>
                        <dependencies>
                            <dependency>
                                <groupId>com.atlassian.confluence</groupId>
                                <artifactId>confluence-karma-testrunner-support</artifactId>
                                <version>0.0.6</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>generate-aui-js-from-soy</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/qunit/soy</outputDirectory>
                                    <resources>
                                        <directory>${project.build.directory}/qunit/dependencies/soy/</directory>
                                        <includes>
                                            <include>**/*.soy</include>
                                        </includes>
                                    </resources>
                                    <propertiesFile>${project.build.directory}/qunit/dependencies/i18n/aui.properties
                                    </propertiesFile>
                                </configuration>
                            </execution>
                            <execution>
                                <id>generate-js-from-soy</id>
                                <phase>generate-test-resources</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                                <configuration>
                                    <module>com.atlassian.confluence.test.support.karma.CustomFunctionTransformModule
                                    </module>
                                    <outputDirectory>${project.build.directory}/qunit/soy</outputDirectory>
                                    <resources>
                                        <directory>${project.basedir}/src/main/resources/</directory>
                                        <includes>
                                            <include>**/*.soy</include>
                                        </includes>
                                        <excludes>
                                            <!-- toString function used in this template is not supported by this plugin -->
                                            <exclude>templates/cql-search-result.soy</exclude>
                                        </excludes>
                                    </resources>
                                    <propertiesFile>${project.basedir}/src/main/resources/confluence-search.properties
                                    </propertiesFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <properties>
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
        <atlassian.spring.scanner.version>2.0.1</atlassian.spring.scanner.version>
        <cql.version>1.2.19</cql.version>
        <aui.version>5.8.13</aui.version>
        <jquery.version>1.7.2</jquery.version>
    </properties>
</project>
