<?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</groupId>
        <artifactId>confluence-previews-parent</artifactId>
        <version>5.0.6</version>
    </parent>

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

    <name>Confluence Previews</name>
    <description>Adds preview lightbox for files and images</description>

    <properties>
        <atlassian.plugin.key>com.atlassian.confluence.plugins.confluence-previews</atlassian.plugin.key>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>node_modules</directory>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-confluence-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <!-- Ensure plugin is spring powered - see https://extranet.atlassian.com/x/xBS9hQ -->
                        <Spring-Context>*</Spring-Context>
                    </instructions>

                    <containerId>${containerId}</containerId>
                    <productVersion>${confluence.version}</productVersion>
                    <productDataVersion>${confluence.data.version}</productDataVersion>
                    <output>${project.build.directory}/output.log</output>
                    <systemPropertyVariables>
                        <confluence.version>${confluence.version}</confluence.version>
                        <xvfb.enable>${xvfb.enable}</xvfb.enable>
                        <xvfb.display>${xvfb.display}</xvfb.display>
                        <http.port>${http.confluence.port}</http.port>
                        <baseurl.confluence>${baseurl.confluence}</baseurl.confluence>
                        <context.path>${context.confluence.path}</context.path>
                        <atlassian.dev.mode>${atlassian.dev.mode}</atlassian.dev.mode>
                    </systemPropertyVariables>
                    <!-- Prevent amps from minifiying our resources, we'll do this ourselves so we can exclude pdfjs -->
                    <compressJs>false</compressJs>
                    <allowGoogleTracking>false</allowGoogleTracking>
                    <skipAllPrompts>true</skipAllPrompts>
                    <enableDevToolbox>false</enableDevToolbox>
                    <enableFastdev>false</enableFastdev>
                    <enablePde>false</enablePde>
                    <extractDependencies>false</extractDependencies>
                    <extractTestDependencies>false</extractTestDependencies>
                </configuration>
            </plugin>
            <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>initialize</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>npm</executable>
                    <arguments>
                        <argument>install</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.outputDirectory}/mediaviewer</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/node_modules/@atlassian/mediaviewer</directory>
                                    <includes>
                                        <include>**/*</include>
                                    </includes>
                                </resource>
                            </resources>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.4.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <suffix>-min</suffix>
                    <jswarn>false</jswarn>
                    <excludes>
                        <exclude>**/pdf.worker.js</exclude>
                        <exclude>**/*min.js</exclude>
                        <exclude>**/mediaviewer/**</exclude>
                        <exclude>**/node_modules/**</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.lesscss</groupId>
                <artifactId>lesscss-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>compile-less</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Profile for Karma unit testing. -->
            <!-- TODO - should be removed in future when the Karma tests are launched by node and not Maven -->
            <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.plugins</groupId>
                    <artifactId>jquery</artifactId>
                    <version>${jquery.version}</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <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.plugins,com.atlassian.soy</includeGroupIds>
                                    <includeArtifactIds>auiplugin,jquery,soy-template-plugin</includeArtifactIds>
                                    <includes>**/*.js</includes>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <useJvmChmod>true</useJvmChmod>
                        </configuration>
                    </plugin>
                    <!-- Compiles js from soy -->
                    <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-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/templates/</directory>
                                        <includes>
                                            <include>**/*.soy</include>
                                        </includes>
                                    </resources>
                                    <propertiesFile>${project.basedir}/src/main/resources/confluence-previews.properties</propertiesFile>
                                </configuration>
                            </execution>
                        </executions>
                    </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>
                            <karmaExecutable>node_modules/karma/bin/karma</karmaExecutable>
                            <browsers>PhantomJS</browsers>
                        </configuration>
                    </plugin>
                    <!--Exclude webdriver tests when running the Karma test profile-->
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>maven-confluence-plugin</artifactId>
                        <version>${amps.version}</version>
                        <extensions>true</extensions>
                        <configuration>
                            <skipTests>true</skipTests>
                            <skipITs>true</skipITs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

            <properties>
                <!-- Skips unit tests -->
                <maven.test.unit.skip>true</maven.test.unit.skip>
            </properties>
        </profile>
    </profiles>
</project>
