<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<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>org.wildfly</groupId>
        <artifactId>wildfly-ee-feature-pack-parent</artifactId>
        <!--
        Maintain separation between the artifact id and the version to help prevent
        merge conflicts between commits changing the GA and those changing the V.
        -->
        <version>41.0.0.Final</version>
    </parent>

    <artifactId>wildfly-ee-galleon-pack</artifactId>

    <name>WildFly: EE Full Galleon Pack</name>
    <description>Galleon feature-pack providing full platform Jakarta functionality</description>
    <packaging>pom</packaging>

    <properties>
        <!-- Some paths below reference target/ directories from other Maven modules, bypassing Maven's dependency management. -->
        <!-- Any module referenced by these paths MUST be explicitly declared as a <dependency> in this POM to ensure the reactor schedules it to complete BEFORE this module's build starts! -->
        <galleon.shared.resources.directory>${basedir}/../galleon-shared/src/main/resources</galleon.shared.resources.directory>
        <galleon.shared.generated.resources.directory>${basedir}/../galleon-shared/target/index</galleon.shared.generated.resources.directory>
        <galleon.shared.legacy.resources.directory>${basedir}/../galleon-shared-legacy/src/main/resources</galleon.shared.legacy.resources.directory>
        <galleon.shared.preview.resources.directory>${basedir}/../galleon-shared-preview/src/main/resources</galleon.shared.preview.resources.directory>
        <galleon.local.resources.directory>${basedir}/../galleon-local/src/main/resources</galleon.local.resources.directory>
        <galleon.client.resources.directory>${basedir}/../../client/shade/target/resources</galleon.client.resources.directory>
        <license.directory>${project.build.directory}/resources/content/docs/licenses</license.directory>
    </properties>

    <build>
        <finalName>${server.output.dir.prefix}-galleon-pack-${server.output.dir.version}</finalName>
        <plugins>
            <plugin>
                <!-- Feature-pack generation is vulnerable to leftover files in the target
                     folder from previous builds, so always clean even if the clean lifecycle is not invoked -->
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <execution>
                        <id>auto-clean</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-core-common-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wildfly.core</groupId>
                                    <artifactId>wildfly-core-feature-pack-common</artifactId>
                                    <type>zip</type>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.wildfly.core</groupId>
                                    <artifactId>wildfly-core-feature-pack-galleon-common</artifactId>
                                    <type>zip</type>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.wildfly.core</groupId>
                                    <artifactId>wildfly-core-feature-pack-ee-10-api</artifactId>
                                    <type>zip</type>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.wildfly.core</groupId>
                                    <artifactId>wildfly-cli</artifactId>
                                    <classifier>shaded-model</classifier>
                                    <type>zip</type>
                                </artifactItem>
                                <artifactItem>
                                    <groupId>org.wildfly.core</groupId>
                                    <artifactId>wildfly-elytron-tool-wrapper</artifactId>
                                    <classifier>shaded-model</classifier>
                                    <type>zip</type>
                                </artifactItem>
                            </artifactItems>
                            <!-- The feature-pack build seems to ignore such things anyway, but to be
                                 robust exclude artifact metadata content -->
                            <excludes>**/pom.xml,META-INF,META-INF/**</excludes>
                            <outputDirectory>${basedir}/target/unpacked-wildfly-core-galleon-resources</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-unpacked-wildfly-core-galleon-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <escapeString>\</escapeString>
                            <resources>
                                <resource>
                                    <directory>${basedir}/target/unpacked-wildfly-core-galleon-resources</directory>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-galleon-shared-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${galleon.shared.resources.directory}</directory>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-galleon-shared-feature-pack-generated-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <!-- Just copy here rather than trying to get from the shared zip, since nothing else is using the zip -->
                            <outputDirectory>${basedir}/target/resources/packages/unstable-api-annotation-index.wildfly-ee-feature-pack/pm/wildfly</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${galleon.shared.generated.resources.directory}</directory>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-galleon-shared-legacy-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${galleon.shared.legacy.resources.directory}</directory>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-galleon-shared-preview-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${galleon.shared.preview.resources.directory}</directory>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-galleon-local-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${galleon.local.resources.directory}</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                            <!-- Limit build-time resource filtering to @xxx@ expressions to avoid ambiguity with runtime expressions -->
                            <delimiters>
                                <delimiter>@@</delimiter>
                            </delimiters>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-galleon-client-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${galleon.client.resources.directory}</directory>
                                </resource>
                            </resources>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.wildfly.maven.plugins</groupId>
                <artifactId>licenses-plugin</artifactId>
                <inherited>false</inherited>
                <executions>
                    <execution>
                        <id>update-licenses-xml</id>
                        <goals>
                            <goal>insert-versions</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <generateVersionProperty>true</generateVersionProperty>
                            <sortByGroupIdAndArtifactId>true</sortByGroupIdAndArtifactId>
                            <licensesConfigFiles>
                                <licensesConfigFile>${basedir}/target/resources/license/core-feature-pack-common-licenses.xml</licensesConfigFile>
                                <licensesConfigFile>${basedir}/target/resources/license/core-feature-pack-ee-10-api-licenses.xml</licensesConfigFile>
                                <licensesConfigFile>${galleon.shared.resources.directory}/license/licenses.xml</licensesConfigFile>
                            </licensesConfigFiles>
                            <licensesOutputFile>${license.directory}/wildfly-ee-feature-pack-licenses.xml</licensesOutputFile>
                            <excludedGroups>org.wildfly.galleon-plugins</excludedGroups>
                            <excludedArtifacts>wildfly-standard-ee-bom|wildfly-standard-legacy-ee-bom|wildfly-standard-preview-ee-bom|wildfly-ee-feature-pack-galleon-shared|wildfly-ee-feature-pack-galleon-local|wildfly-common-ee-dependency-management|wildfly-jar-boot|wildfly-core-feature-pack-common|wildfly-elytron\z</excludedArtifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.wildfly.galleon-plugins</groupId>
                <artifactId>wildfly-galleon-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>feature-pack-build</id>
                        <goals>
                            <goal>build-feature-pack</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <!-- Any dependency to a package that has a stability level
                                 lower than the minimum stability level will break the build.
                                 Note that package dependencies that are only valid for
                                 a minimum stability level are ignored. -->
                            <forbid-lower-stability-level-package-reference>true</forbid-lower-stability-level-package-reference>
                            <release-name>${ee.dist.product.release.name}</release-name>
                            <fork-embedded>${galleon.fork.embedded}</fork-embedded>
                            <generate-channel-manifest>true</generate-channel-manifest>
                            <deploy-channel-manifest>false</deploy-channel-manifest>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${ee.maven.groupId}</groupId>
                <artifactId>wildfly-standard-ee-bom</artifactId>
                <version>${ee.maven.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <!-- feature-pack dependencies -->

        <dependency>
            <groupId>org.wildfly.galleon-plugins</groupId>
            <artifactId>wildfly-galleon-plugins</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.wildfly.galleon-plugins</groupId>
            <artifactId>wildfly-config-gen</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Galleon universe dependencies (so that they are present in the channel manifest) -->

        <dependency>
            <groupId>org.jboss.universe</groupId>
            <artifactId>community-universe</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.universe.producer</groupId>
            <artifactId>wildfly-producers</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.galleon</groupId>
            <artifactId>galleon-core</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
            <scope>provided</scope>
        </dependency>

        <!--   module and copy artifact dependencies

               IMPORTANT: Place the pom imports in order of precedence,
               "winner" first. This is the opposite of the order of galleon resource
               copying, which is "winner" last (so the winner's file copies over
               any file from a lower precedence source. For these poms, maven
               uses the first value seen for any artifact, so we need it to see
               the value of the highest precedence pom first. This is particularly
               crucial with wildfly-core deps where full WF may need to override core.
               For other poms coming from this source tree the ordering is more a case
               of adding a safeguard for cases where the same artifact is declared
               in multiple poms. That's incorrect handling but can happen.

               The desired precedence:

               1) galleon-local
               2) galleon-shared-legacy
               3) galleon-shared-preview (lower than legacy because legacy is "standard WildFly")
               4) galleon-shared
               5) core
         -->

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-galleon-local</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-galleon-shared-legacy</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-galleon-shared-preview</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-galleon-shared</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.wildfly.core</groupId>
            <artifactId>wildfly-core-feature-pack-common</artifactId>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <!-- WFLY-19671. DO NOT include 'galleon content only' dependencies
        <dependency>
            <groupId>org.wildfly.core</groupId>
            <artifactId>wildfly-core-feature-pack-galleon-common</artifactId>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>-->

        <!-- n.b. Add at 'test' scope to ensure wildfly-client-all is built first but is NOT included in the artifact-list.txt or manifest. -->
        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-client-all</artifactId>
            <version>${ee.maven.version}</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <profiles>
        <profile>
            <!-- This profile should only be activated to download licenses from remote URLs
                 instead of copying the license files from the src/main/resources/content/docs/licences
                 directory -->
            <id>download-licenses</id>
            <activation>
                <property>
                    <name>download-licenses</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>license-maven-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>download-licenses</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <licensesOutputDirectory>${basedir}/target/resources/content/docs/licenses</licensesOutputDirectory>
                                    <licensesOutputFile>${basedir}/target/resources/content/docs/licenses/licenses.xml</licensesOutputFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>enforce</id>
            <activation>
                <property>
                    <name>!skip-enforce</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>ban-transitive-deps</id>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <banTransitiveDependencies>
                                            <excludes>
                                                <!-- Ignore the shared resource poms as those we want their
                                                     transitives. Those poms ban transitives at their level -->
                                                <exclude>org.wildfly.core:wildfly-core-feature-pack-common</exclude>
                                                <exclude>${ee.maven.groupId}:wildfly-ee-feature-pack-galleon-shared</exclude>
                                                <exclude>${ee.maven.groupId}:wildfly-ee-feature-pack-galleon-local</exclude>
                                            </excludes>
                                        </banTransitiveDependencies>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>

                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>enforce-product</id>
            <activation>
                <property>
                    <name>enforce-product</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-enforcer-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>org.jboss.maven.plugins.enforcer.rules</groupId>
                                <artifactId>version-enforcer-rule</artifactId>
                                <version>1.0.0</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>ban-non-product-deps</id>
                                <goals>
                                    <goal>enforce</goal>
                                </goals>
                                <configuration>
                                    <rules>
                                        <rule implementation="org.jboss.maven.plugins.enforcer.rules.version.BanVersionDependenciesRule">
                                          <versionPattern>^((?!redhat).)*$</versionPattern>
                                        </rule>
                                    </rules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>javadocDist</id>
            <properties>
                <javadoc.branding>WildFly public API - ${project.version}</javadoc.branding>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>${version.javadoc.plugin}</version>
                        <executions>
                            <execution>
                                <id>javadocs-dist</id>
                                <goals>
                                    <goal>aggregate-jar</goal>
                                </goals>
                                <phase>validate</phase>
                                <configuration>
                                    <verbose>true</verbose>
                                    <maxmemory>2400m</maxmemory>
                                    <!-- To prevent problems with author names written in non-UTF-8:
                                    -->
                                    <encoding>ISO-8859-1</encoding>

                                    <windowtitle>${javadoc.branding} public API</windowtitle>
                                    <doctitle>${javadoc.branding} public API</doctitle>
                                    <header>${javadoc.branding}</header>
                                    <footer>${javadoc.branding}</footer>

                                    <includeDependencySources>true</includeDependencySources>
                                    <dependencySourceIncludes>
                                        <!-- Filled by a script during creation of Javadoc. -->
                                    </dependencySourceIncludes>

                                    <dependencySourceExcludes>
                                        <!-- Filled by a script during creation of Javadoc. -->
                                    </dependencySourceExcludes>

                                    <groups>
                                        <!-- Filled by a script during creation of Javadoc. -->
                                    </groups>

                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
