<?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>11.0.11</version>
    </parent>

    <artifactId>confluence-previews</artifactId>
    <version>11.0.11</version>
    <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>
        <npm.cmd>npm</npm.cmd>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.confluence</groupId>
            <artifactId>confluence</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins.rest</groupId>
            <artifactId>atlassian-rest-common</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jwt</groupId>
            <artifactId>jwt-plugin</artifactId>
            <version>${atlassian.jwt.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.confluence.plugins</groupId>
            <artifactId>confluence-previews-api</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>node_modules</directory>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>confluence-maven-plugin</artifactId>
                <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>
                        <Export-Package>
                            com.atlassian.confluence.plugins.previews.api
                        </Export-Package>
                        <Import-Package>
                            com.atlassian.confluence.plugin.descriptor.web.urlreadingconditions,
                            *
                        </Import-Package>
                    </instructions>

                    <containerId>${container}</containerId>
                    <productVersion>${confluence.version}</productVersion>
                    <productDataVersion>${confluence.data.version}</productDataVersion>
                    <output>${project.build.directory}/output.log</output>
                    <!-- 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>
                    <enablePde>false</enablePde>
                    <extractDependencies>false</extractDependencies>
                    <extractTestDependencies>false</extractTestDependencies>
                </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>
                    <!-- Enable this to get build-time logging of annotations atlassian-spring-scanner-maven-plugin has noticed -->
                    <verbose>true</verbose>
                </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.cmd}</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}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/node_modules/@atlassian</directory>
                                    <includes>
                                        <include>mediaviewer/lib/*</include>
                                        <include>mediaviewer/analytics-whitelist.json</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>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.lesscss</groupId>
                <artifactId>lesscss-maven-plugin</artifactId>
                <version>4.0.0</version>
                <executions>
                    <execution>
                        <id>compile-less</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <properties>
                <npm.cmd>npm.cmd</npm.cmd>
            </properties>
        </profile>
        <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>

            <build>
                <plugins>
                    <!-- 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.9</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>
                                <phase>test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <karmaExecutable>node_modules/.bin/karma</karmaExecutable>
                        </configuration>
                    </plugin>
                    <!--Exclude webdriver tests when running the Karma test profile-->
                    <plugin>
                        <groupId>com.atlassian.maven.plugins</groupId>
                        <artifactId>confluence-maven-plugin</artifactId>
                        <configuration>
                            <skipUTs>true</skipUTs>
                            <skipTests>true</skipTests>
                            <skipITs>true</skipITs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
