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

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2010, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -->

<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>23.0.2.Final</version>
    </parent>

    <artifactId>wildfly-feature-pack</artifactId>

    <name>WildFly: Full Feature Pack</name>
    <description>Legacy (i.e. pre-Galleon) feature pack providing full platform Jakarta EE functionality</description>
    <packaging>pom</packaging>

    <properties>
        <project.version>${project.version}</project.version>
        <license.directory>${project.build.directory}/${project.build.finalName}/content/docs/licenses</license.directory>
        <common.resources.directory>${basedir}/../common/src/main/resources</common.resources.directory>
        <ee-8-api.resources.directory>${basedir}/../ee-8-api/src/main/resources</ee-8-api.resources.directory>
        <pruned.resources.directory>${basedir}/../pruned/src/main/resources</pruned.resources.directory>
    </properties>

    <build>
        <finalName>${server.output.dir.prefix}-${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-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-pruned-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${pruned.resources.directory}</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-common-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${common.resources.directory}</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-ee8-api-feature-pack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${ee-8-api.resources.directory}</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/resources</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/resources</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.wildfly.build</groupId>
                <artifactId>wildfly-feature-pack-build-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>feature-pack-build</id>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <phase>compile</phase>
                        <configuration>
                            <config-file>feature-pack-build.xml</config-file>
                            <resources-dir>target/resources</resources-dir>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>assemble</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <finalName>${project.build.finalName}</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                            <workDirectory>${project.build.directory}/assembly/work</workDirectory>
                            <tarLongFileMode>gnu</tarLongFileMode>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>

        <!-- feature pack dependencies -->

        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>wildfly-servlet-feature-pack</artifactId>
            <type>zip</type>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- module and copy artifact dependencies -->

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-common</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-ee-8-api</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-feature-pack-pruned</artifactId>
            <version>${ee.maven.version}</version>
            <type>pom</type>
        </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>${project.build.directory}/${project.build.finalName}/content/docs/licenses</licensesOutputDirectory>
                                    <licensesOutputFile>${project.build.directory}/${project.build.finalName}/content/docs/licenses/licenses.xml</licensesOutputFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>


        <profile>
            <id>update-licenses-xml</id>
            <activation>
                <property>
                    <name>!skip-update-licenses-xml</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.maven.plugins</groupId>
                        <artifactId>licenses-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>generate-licenses-xml</id>
                                <goals>
                                    <goal>insert-versions</goal>
                                </goals>
                                <phase>prepare-package</phase><!-- TODO why not generate-resources phase?-->
                                <configuration>
                                    <sortByGroupIdAndArtifactId>true</sortByGroupIdAndArtifactId>
                                    <licensesConfigFiles>
                                        <licensesConfigFile>${basedir}/target/resources/license/ee-feature-pack-common-licenses.xml</licensesConfigFile>
                                        <licensesConfigFile>${basedir}/target/resources/license/ee-feature-pack-ee-8-api-licenses.xml</licensesConfigFile>
                                        <licensesConfigFile>${basedir}/target/resources/license/ee-feature-pack-legacy-licenses.xml</licensesConfigFile>
                                    </licensesConfigFiles>
                                    <licensesOutputFile>${license.directory}/full-feature-pack-licenses.xml</licensesOutputFile>
                                    <excludedArtifacts>infinispan-hibernate-cache-v51|jboss-ejb-client-legacy|wildfly-core-feature-pack|wildfly-servlet-feature-pack|wildfly-ee-feature-pack-common|wildfly-ee-feature-pack-ee-8-api|wildfly-ee-feature-pack-pruned</excludedArtifacts>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>generate-licenses-html</id>
            <activation>
                <property>
                    <name>!skip-generate-licenses-html</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>xml-maven-plugin</artifactId>
                        <inherited>false</inherited>
                        <executions>
                            <execution>
                                <id>generate-licenses-html</id>
                                <goals>
                                    <goal>transform</goal>
                                </goals>
                                <phase>prepare-package</phase>
                                <configuration>
                                    <transformationSets>
                                        <transformationSet>
                                            <dir>${license.directory}</dir>
                                            <includes>
                                                <include>*licenses.xml</include>
                                            </includes>
                                            <stylesheet>target/resources/content/docs/licenses/licenses.xsl</stylesheet>
                                            <outputDir>${license.directory}</outputDir>
                                            <fileMappers>
                                                <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                                    <targetExtension>.html</targetExtension>
                                                </fileMapper>
                                            </fileMappers>
                                            <parameters>
                                                <parameter>
                                                    <name>version</name>
                                                    <value>${ee.dist.product.release.version}</value>
                                                </parameter>
                                                <parameter>
                                                    <name>product.release.name</name>
                                                    <value>${ee.dist.product.release.name}</value>
                                                </parameter>
                                            </parameters>
                                        </transformationSet>
                                    </transformationSets>
                                </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 jdk jars because they are system scope -->
                                                <exclude>com.sun:tools</exclude>
                                                <exclude>sun.jdk:jconsole</exclude>
                                                <!-- Ignore the shared resource poms as those we want their
                                                     transitives. Those poms ban transitives at their level -->
                                                <exclude>${ee.maven.groupId}:wildfly-ee-feature-pack-common</exclude>
                                                <exclude>${ee.maven.groupId}:wildfly-ee-feature-pack-ee-8-api</exclude>
                                                <exclude>${ee.maven.groupId}:wildfly-ee-feature-pack-pruned</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>
