<?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.jira</groupId>
        <artifactId>jira-plugins</artifactId>
        <version>8.18.2</version>
    </parent>

    <groupId>com.atlassian.jira.plugins</groupId>
    <artifactId>jira-post-upgrade-landing-page-plugin</artifactId>

    <name>Atlassian Jira - Plugins - Post-Upgrade Landing Page</name>
    <description>Implements the post-upgrade landing page (PULP).</description>
    <packaging>atlassian-plugin</packaging>

    <properties>
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
        <frontend.working.directory>src/main/frontend</frontend.working.directory>
        <!--
        When bumping node version:
        - change node.version/npm.version (without the 'v' prefix),
        - run ../../../bin/deploy-new-node-npm.sh script (in this directory!)
        -->
        <node.version>10.22.1</node.version>
        <node.atlassian.hosted.version>${node.version}-atlassian-hosted</node.atlassian.hosted.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-dmz-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.json</groupId>
            <artifactId>atlassian-json-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.applinks</groupId>
            <artifactId>applinks-plugin</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Test dependencies -->
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-tests</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-func-tests</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>atlassian-jira-pageobjects</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-webdriver-tests</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-core</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- Test dependency required by webwork action.ActionSupport -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <!--
            This profile allows frontend-maven-plugin to download yarn and node directly from internal maven repo
            instead of using github.
            -->
            <id>useMavenRestrictedRepoForYarn</id>
            <activation>
                <!--
                Activated on bamboo builds.
                Deactivate it (passing -P -useMavenRestrictedRepoForYarn as a build parameter) if there are issues
                when building without access to internal maven repo.
                -->
                <property>
                    <name>env.bamboo_planKey</name>
                </property>
            </activation>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>com.github.eirslett</groupId>
                            <artifactId>frontend-maven-plugin</artifactId>
                            <version>${frontend.maven.plugin.version}</version>
                            <configuration>
                                <nodeVersion>v${node.atlassian.hosted.version}</nodeVersion>
                                <yarnVersion>v${yarn.atlassian.hosted.version}</yarnVersion>
                                <installDirectory>${nodePath}</installDirectory>
                                <npmInheritsProxyConfigFromMaven>true</npmInheritsProxyConfigFromMaven>
                            </configuration>
                            <dependencies>
                                <dependency>
                                    <groupId>com.github.eirslett</groupId>
                                    <artifactId>yarn</artifactId>
                                    <version>${yarn.atlassian.hosted.version}</version>
                                    <type>tar.gz</type>
                                </dependency>
                                <dependency>
                                    <groupId>com.github.eirslett</groupId>
                                    <artifactId>node</artifactId>
                                    <version>${node.atlassian.hosted.version}</version>
                                    <classifier>linux-x64</classifier>
                                    <type>tar.gz</type>
                                </dependency>
                                <dependency>
                                    <groupId>com.github.eirslett</groupId>
                                    <artifactId>node</artifactId>
                                    <version>${node.atlassian.hosted.version}</version>
                                    <classifier>darwin-x64</classifier>
                                    <type>tar.gz</type>
                                </dependency>
                            </dependencies>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>${frontend.maven.plugin.version}</version>
                    <configuration>
                        <nodeVersion>v${node.version}</nodeVersion>
                        <installDirectory>${project.build.directory}</installDirectory>
                        <workingDirectory>${frontend.working.directory}</workingDirectory>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>jira-maven-plugin</artifactId>
                <configuration>
                    <enableQuickReload>true</enableQuickReload>
                    <extractDependencies>false</extractDependencies>
                    <productDataVersion>${atlassian.product.version}</productDataVersion>
                    <productVersion>${atlassian.product.version}</productVersion>
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <Spring-Context>*</Spring-Context>
                        <Export-Package/>
                        <Import-Package>
                            com.atlassian.jira.plugin.webfragment.conditions,
                            *
                        </Import-Package>
                        <Atlassian-Scan-Folders>META-INF/plugin-descriptors</Atlassian-Scan-Folders>
                    </instructions>
                    <skipManifestValidation>true</skipManifestValidation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.atlassian.plugin</groupId>
                <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
            </plugin>

            <!-- Integrate FrontEnd build process with Maven -->
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <executions>
                    <!-- Install node and yarn for frontend-maven-plugin -->
                    <execution>
                        <id>install node and yarn</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>
                        <phase>generate-resources</phase>
                    </execution>
                    <!-- Run `yarn install` as part of mvn install -->
                    <execution>
                        <id>install-dependencies-for-pulp-ui</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>${frontend.install.cmd.forDevelopment}</arguments>
                        </configuration>
                        <phase>generate-resources</phase>
                    </execution>
                    <!-- Run `yarn run build` as part of mvn build/package -->
                    <execution>
                        <id>run-build-for-pulp-ui</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                            <environmentVariables>
                                <NODE_ENV>production</NODE_ENV>
                                <SRC_DIR>${project.basedir}/${frontend.working.directory}</SRC_DIR>
                                <OUT_DIR>${project.build.outputDirectory}</OUT_DIR>
                                <PLUGIN_KEY>${atlassian.plugin.key}</PLUGIN_KEY>
                            </environmentVariables>
                        </configuration>
                        <phase>process-resources</phase>
                    </execution>
                    <!-- Override Gulp process from parent pom-->
                    <execution>
                        <id>gulp process-resources</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>

            <!-- Clear node_modules as part of running mvn clean -->
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>node_modules</directory>
                            <!-- The ghosts of Christmas past -->
                            <directory>src/main/resources/pulp-frontend</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <!-- provide version number to tests of PULP News content -->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <project.version>${project.version}</project.version>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
