<?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.pom</groupId>
        <artifactId>central-pom</artifactId>
        <version>6.2.2</version>
    </parent>

    <version>2.4.2</version>
    <groupId>com.atlassian.plugins</groupId>
    <artifactId>atlassian-clientside-extensions-parent</artifactId>
    <name>Atlassian Plugins - Client-side Extensions - Parent</name>
    <packaging>pom</packaging>
    <licenses>
        <license>
            <name>BSD License</name>
            <url>https://opensource.org/licenses/BSD-3-Clause</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <connection>scm:git:ssh://git@bitbucket.org/atlassian/atlassian-clientside-extensions.git</connection>
        <developerConnection>scm:git:ssh://git@bitbucket.org/atlassian/atlassian-clientside-extensions.git</developerConnection>
        <url>https://bitbucket.org/atlassian/atlassian-clientside-extensions</url>
        <tag>v2.4.2</tag>
    </scm>

    <modules>
        <module>atlassian-clientside-extensions-runtime</module>
        <module>atlassian-clientside-extensions-page-bootstrapper</module>
        <module>environments/refapp</module>
        <!-- last module so that it can aggregate jacoco reports and push them to Sonar -->
        <module>atlassian-clientside-extensions-sonar</module>
    </modules>

    <properties>
        <!-- the minimum supported versions of the plugin system modules -->
        <atlassian.ozymandias.version>1.0.0</atlassian.ozymandias.version>
        <platform.version>5.2.7</platform.version>
        <webfragments.version>5.0.0</webfragments.version>
        <!-- keep in sync with platform pom version-->
        <webresources.version>4.3.6</webresources.version>
        <soytemplaterenderer.version>5.0.0</soytemplaterenderer.version>
        <jsonapi.version>0.11</jsonapi.version>
        <gson.libversion>2.8.8</gson.libversion>

        <!-- the product versions we test in -->
        <refapp.version>5.3.0</refapp.version>

        <!-- the build tools we use -->
        <amps.version>8.3.1</amps.version>
        <atlassian.spring.scanner.version>2.2.3</atlassian.spring.scanner.version>
        <frontend.maven.plugin.version>1.12.0</frontend.maven.plugin.version>

        <!-- keep in sync with .nvmrc -->
        <node.version>12.22.4</node.version>
        <yarn.version>1.22.10</yarn.version>

        <!-- if true, skip running Yarn install during build (intended to be overridden via the command line) -->
        <skipYarnInstall>false</skipYarnInstall>

        <!-- Third party dependencies -->
        <jackson.version>1.9.14-atlassian-6</jackson.version>

        <!-- Sonar multi-module configuration -->
        <jacoco.report>coverage/jacoco</jacoco.report>
        <jacoco.report.file>${jacoco.report}/jacoco.xml</jacoco.report.file>
        <jest.report>coverage/jest</jest.report>
        <jest.report.file>${jest.report}/lcov.info</jest.report.file>
        <eslint.report.paths>coverage/eslint/report.json</eslint.report.paths>
        <sonar.testExecutionReportPaths>${jest.report}/sonar-report.xml</sonar.testExecutionReportPaths>
        <gpg.keyname>${env.GPG_KEY_NAME}</gpg.keyname>
        <gpg.passphrase>${env.GPG_PASS_PHRASE}</gpg.passphrase>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- Platform POMs -->
            <dependency>
                <groupId>com.atlassian.platform</groupId>
                <artifactId>platform</artifactId>
                <version>${platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.atlassian.platform</groupId>
                <artifactId>third-party</artifactId>
                <version>${platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!-- Project modules -->
            <dependency>
                <groupId>com.atlassian.plugins</groupId>
                <artifactId>atlassian-clientside-extensions-page-bootstrapper</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.plugins</groupId>
                <artifactId>atlassian-clientside-extensions-runtime</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.plugins</groupId>
                <artifactId>atlassian-clientside-extensions-demo</artifactId>
                <version>${project.version}</version>
            </dependency>
            <!-- Third party -->
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-core-asl</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
                <version>${jackson.version}</version>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>osgi.core</artifactId>
                <version>6.0.0</version>
            </dependency>
            <!-- Refapp demo project -->
            <dependency>
                <groupId>com.atlassian.plugins</groupId>
                <artifactId>atlassian-plugins-webresource-api</artifactId>
                <version>${webresources.version}</version>
            </dependency>
            <dependency>
                <groupId>com.atlassian.json</groupId>
                <artifactId>atlassian-json-api</artifactId>
                <version>${jsonapi.version}</version>
            </dependency>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>${gson.libversion}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <profiles>
        <profile>
            <id>build-mode-is-set-by-node-env</id>
            <activation>
                <property>
                    <name>env.NODE_ENV</name>
                </property>
            </activation>
            <properties>
                <frontend.build.mode>${env.NODE_ENV}</frontend.build.mode>
            </properties>
        </profile>
        <profile>
            <id>build-mode-is-production-by-default</id>
            <activation>
                <property>
                    <name>!env.NODE_ENV</name>
                </property>
            </activation>
            <properties>
                <frontend.build.mode>production</frontend.build.mode>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <activation>
                <property>
                    <name>!report</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>step-4-run-frontend-unit-tests</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipTests}</skip>
                                    <arguments>test:packages</arguments>
                                    <workingDirectory>${project.basedir}</workingDirectory>
                                    <environmentVariables>
                                        <NODE_ENV>development</NODE_ENV>
                                    </environmentVariables>
                                </configuration>
                                <phase>test</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>test-and-lint-with-report</id>
            <activation>
                <property>
                    <name>report</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>step-4-run-frontend-unit-tests-report</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipTests}</skip>
                                    <arguments>test:ci</arguments>
                                    <workingDirectory>${project.basedir}</workingDirectory>
                                    <environmentVariables>
                                        <NODE_ENV>development</NODE_ENV>
                                    </environmentVariables>
                                </configuration>
                                <phase>test</phase>
                            </execution>
                            <execution>
                                <id>step-5-generate-frontend-lint-report</id>
                                <goals>
                                    <goal>yarn</goal>
                                </goals>
                                <configuration>
                                    <skip>${skipTests}</skip>
                                    <arguments>lint:eslint:report</arguments>
                                    <workingDirectory>${project.basedir}</workingDirectory>
                                    <environmentVariables>
                                        <NODE_ENV>development</NODE_ENV>
                                    </environmentVariables>
                                </configuration>
                                <phase>test</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </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>
                        <yarnVersion>v${yarn.version}</yarnVersion>
                        <installDirectory>${project.build.outputDirectory}</installDirectory>
                        <workingDirectory>${project.basedir}</workingDirectory>
                        <npmInheritsProxyConfigFromMaven>true</npmInheritsProxyConfigFromMaven>
                        <environmentVariables>
                            <NODE_ENV>${frontend.build.mode}</NODE_ENV>
                        </environmentVariables>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.9.0.2155</version>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.7</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>step-1-set-up-environment</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>
                        <configuration>
                            <workingDirectory>${project.basedir}</workingDirectory>
                        </configuration>
                        <phase>initialize</phase>
                    </execution>
                    <execution>
                        <id>step-2-install-frontend-dependencies</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <skip>${skipYarnInstall}</skip>
                            <workingDirectory>${project.basedir}</workingDirectory>
                            <arguments>install --frozen-lockfile --ignore-optional --mutex=network</arguments>
                            <environmentVariables>
                                <!-- Must always be development so that we get our dev dependencies -->
                                <NODE_ENV>development</NODE_ENV>
                            </environmentVariables>
                        </configuration>
                        <phase>initialize</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
