<?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.soy</groupId>
        <artifactId>soy-templates-parent</artifactId>
        <version>9.0.0</version>
    </parent>

    <artifactId>soy-template-plugin</artifactId>

    <name>Atlassian Soy - Plugin</name>

    <packaging>atlassian-plugin</packaging>

    <properties>
        <atlassian.plugin.key>com.atlassian.soy.soy-template-plugin</atlassian.plugin.key>
    </properties>

    <build>
        <plugins>
            <!-- SOY-1 Moving the soy util javascript into our folders so we can minify it-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.google.template.soy</groupId>
                                    <artifactId>soycompiler</artifactId>
                                    <version>${soy.libversion}</version>
                                    <type>jar</type>
                                    <outputDirectory>${project.basedir}/src/main/frontend/unpacked/</outputDirectory>
                                    <includes>**/soyutils.js,META-INF/fe-module-manifests/package.json,META-INF/fe-module-manifests/package-lock.json</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-soyutils-flat</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <echo>
                                    Copying unpacked soyutils js library to src/main/frontend/closure-templates
                                    with flat file structure to use like unhosted npm dependency
                                </echo>
                                <copy todir="${project.basedir}/src/main/frontend/closure-templates" flatten="true">
                                    <fileset dir="${project.basedir}/src/main/frontend/unpacked" />
                                </copy>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install-node</id>
                        <goals>
                            <goal>install-node-and-corepack</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>yarn-install</id>
                        <goals>
                            <goal>corepack</goal>
                        </goals>
                        <configuration>
                            <arguments>yarn install</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yarn-build</id>
                        <goals>
                            <goal>corepack</goal>
                        </goals>
                        <configuration>
                            <arguments>yarn run build</arguments>
                            <environmentVariables>
                                <NODE_ENV>production</NODE_ENV>
                            </environmentVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>amps-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <!-- Extracting dependencies prevents com.atlassian.soy.renderer from being imported and exported -->
                    <extractDependencies>false</extractDependencies>
                    <banningExcludes>
                        <exclude>com.atlassian.soy:soy-template-renderer-api</exclude>
                        <exclude>com.atlassian.soy:soy-template-renderer-plugin-api</exclude>
                        <exclude>com.atlassian.soy:atlassian-soy-core</exclude>
                        <exclude>com.google.code.findbugs:jsr305</exclude>
                    </banningExcludes>
                    <instructions>
                        <Bundle-SymbolicName>${atlassian.plugin.key}</Bundle-SymbolicName>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <Private-Package>
                            com.atlassian.soy.impl*,
                            com.google.template.soy*,
                            <!-- Must be Private-Package for soy to work correctly -->
                            javax.annotation*
                        </Private-Package>
                        <Export-Package>
                            com.atlassian.soy.renderer,
                        </Export-Package>
                        <Import-Package>
                            !com.google.inject.internal.asm.util,
                            !javax.annotation*,
                            jakarta.inject,
                            org.aopalliance*,
                            com.atlassian.soy.renderer,
                            jakarta.servlet*,
                            com.atlassian.analytics.api.annotations;resolution:=optional,
                            com.atlassian.event.api*,
                            com.atlassian.sal.api*,
                            com.atlassian.plugin.webresource*,
                            com.atlassian.webresource*,
                            com.atlassian.plugin*,
                            com.atlassian.plugin.osgi.external,
                            com.atlassian.plugin.osgi.bridge.external;,
                            com.google.common.*,
                            io.atlassian.util.concurrent,
                            org.slf4j,
                            org.apache.commons.lang3,
                            org.apache.commons.logging,
                            org.xml.sax,
                            org.xml.sax.helpers,
                            org.dom4j*,
                            com.atlassian.util.profiling.*
                        </Import-Package>
                        <Spring-Context>*</Spring-Context>
                    </instructions>
                    <includedFeModuleManifests>
                        <includedFeModuleManifest>${project.basedir}/package.json</includedFeModuleManifest>
                        <includedFeModuleManifest>${project.basedir}/yarn.lock</includedFeModuleManifest>
                    </includedFeModuleManifests>
                    <feManifestAssociations>
                        <feManifestAssociation>
                            <packageName>@atlassian/dc.atlassian-soy-templates.soy-template-plugin</packageName>
                            <manuallyVerifiedEveryFileHasItsDependenciesDeclaredInTheManifest>
                                <outputDirectoryFiles>
                                    js/atlassian-deps.js,
                                    js/atlassian-deps-min.js,
                                    js/soyutils.js
                                </outputDirectoryFiles>
                            </manuallyVerifiedEveryFileHasItsDependenciesDeclaredInTheManifest>
                        </feManifestAssociation>
                    </feManifestAssociations>
                </configuration>
                <executions>
                    <execution>
                        <id>js-enforcement</id>
                        <goals>
                            <goal>verify-fe-manifest-associations</goal>
                        </goals>
                        <phase>verify</phase>
                        <configuration>
                            <verifyFeManifestAssociationsInputEntrypoint>
                                ${project.build.directory}/${project.build.finalName}.jar
                            </verifyFeManifestAssociationsInputEntrypoint>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce-compile-scope-dependencies</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <bannedDependencies>
                                    <excludes>
                                        <exclude>*:*:*:*:compile</exclude>
                                        <exclude>*:*:*:*:runtime</exclude>
                                    </excludes>
                                    <includes>
                                        <!-- API and Core is allowed -->
                                        <include>com.atlassian.soy:soy-template-renderer-api</include>
                                        <include>com.atlassian.soy:soy-template-renderer-plugin-api</include>
                                        <include>com.atlassian.soy:atlassian-soy-core</include>
                                        <!-- The Soy compiler -->
                                        <include>com.google.template.soy:soycompiler</include>
                                        <!-- Guice which is required by the Soy compiler -->
                                        <include>com.google.inject:guice</include>
                                        <include>javax.inject:javax.inject</include> <!-- Guice 6 requires javax.inject-->
                                        <include>com.google.inject.extensions:guice-assistedinject</include>
                                        <!-- Other Soy compiler's dependencies not provided by the plugin framework -->
                                        <include>com.ibm.icu:icu4j</include>
                                        <include>aopalliance:aopalliance</include>
                                        <include>com.google.code.findbugs:jsr305</include>
                                    </includes>
                                    <message>Only dependencies explicitly included can be compile/runtime scope</message>
                                    <searchTransitive>true</searchTransitive>
                                </bannedDependencies>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>${jvm.opens}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.atlassian.soy</groupId>
            <artifactId>soy-template-renderer-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.soy</groupId>
            <artifactId>soy-template-renderer-plugin-api</artifactId>
        </dependency>
        <dependency>
            <groupId>com.atlassian.soy</groupId>
            <artifactId>atlassian-soy-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-core</artifactId>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>commons-io</groupId>
                    <artifactId>commons-io</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi</artifactId>
            <scope>provided</scope>
            <exclusions>
                <exclusion>
                    <groupId>commons-io</groupId>
                    <artifactId>commons-io</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi-bridge</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-webresource-common</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-webresource</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-webfragment</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.sal</groupId>
            <artifactId>sal-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.atlassian.util.concurrent</groupId>
            <artifactId>atlassian-util-concurrent</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <!-- This must be compile scope for soy to work correctly -->
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.template.soy</groupId>
            <artifactId>soycompiler</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.inject</groupId>
            <artifactId>jakarta.inject-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.analytics</groupId>
            <artifactId>analytics-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.atlassian.event</groupId>
            <artifactId>atlassian-event</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

</project>
