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

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2021, 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>
        <artifactId>keycloak-distribution-parent</artifactId>
        <groupId>org.keycloak</groupId>
        <version>16.0.0</version>
    </parent>

    <artifactId>keycloak-server-dist</artifactId>

    <name>Keycloak Server Galleon Based Distribution</name>
    <description/>

    <packaging>pom</packaging>

    <dependencies>
         <dependency>
             <groupId>${ee.maven.groupId}</groupId>
             <artifactId>wildfly-ee-galleon-pack</artifactId>
             <version>${ee.maven.version}</version>
             <type>pom</type>
             <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>${ee.maven.groupId}</groupId>
            <artifactId>wildfly-ee-galleon-pack</artifactId>
            <type>zip</type>
            <version>${ee.maven.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-server-galleon-pack</artifactId>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-server-galleon-pack</artifactId>
            <type>zip</type>
            <exclusions>
                <exclusion>
                    <groupId>*</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jboss.galleon</groupId>
                <artifactId>galleon-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>server-provisioning</id>
                        <goals>
                            <goal>provision</goal>
                        </goals>
                        <phase>compile</phase>
                        <configuration>
                            <install-dir>${basedir}/target/${server.output.dir.prefix}-${server.output.dir.version}</install-dir>
                            <record-state>false</record-state>
                            <log-time>${galleon.log.time}</log-time>
                            <offline>${galleon.offline}</offline>
                            <plugin-options>
                                <jboss-fork-embedded>${galleon.fork.embedded}</jboss-fork-embedded>
                            </plugin-options>
                            <feature-packs>
                                <feature-pack>
                                    <transitive>true</transitive>
                                    <groupId>${ee.maven.groupId}</groupId>
                                    <artifactId>wildfly-ee-galleon-pack</artifactId>
                                    <version>${ee.maven.version}</version>
                                    <included-packages>
                                        <name>welcome-content</name>
                                    </included-packages>
                                    <excluded-packages>
                                        <name>product.conf</name>
                                        <name>appclient</name>
                                        <name>bin.appclient</name>
                                    </excluded-packages>
                                </feature-pack>
                                <!-- feature-pack>
                                    <transitive>true</transitive>
                                    <groupId>${ee.maven.groupId}</groupId>
                                    <artifactId>wildfly-galleon-pack</artifactId>
                                    <version>${ee.maven.version}</version>
                                    <included-packages>
                                        <name>bin</name>
                                        <name>bin.domain</name>
                                        <name>docs.examples.configs</name>
                                    </included-packages>
                                    <excluded-packages>
                                        <name>product.conf</name>
                                        <name>appclient</name>
                                        <name>bin.appclient</name>
                                    </excluded-packages>
                                </feature-pack -->
                                <feature-pack>
                                    <groupId>org.keycloak</groupId>
                                    <artifactId>keycloak-server-galleon-pack</artifactId>
                                    <version>${project.version}</version>
                                    <included-packages>
                                        <name>identity</name>
                                        <name>client-cli</name>
                                        <name>core-tools</name>
                                        <name>themes</name>
                                        <name>welcome-content-keycloak</name>
                                    </included-packages>
                                    <excluded-packages>
                                    </excluded-packages>
                                </feature-pack>
                            </feature-packs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin> <!-- TODO: remove this in favour of proper Galleon Licenses Generation -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-and-inject-keycloak-server-feature-pack-licenses</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.keycloak</groupId>
                                    <artifactId>keycloak-server-feature-pack</artifactId>
                                    <type>zip</type>
                                    <outputDirectory>${basedir}/target/${server.output.dir.prefix}-${server.output.dir.version}/docs</outputDirectory>
                                    <includes>content/docs/licenses-${product.slot}/**</includes>
                                    <fileMappers>
                                        <org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                            <pattern>^\Qcontent/docs/\E</pattern>
                                            <replacement>./</replacement>
                                        </org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
                                    </fileMappers>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- remove unwanted files from wildfly distribution (too complicated/not possible via galleon packages) -->
                        <id>post-provision-cleanup</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                        <configuration>
                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
                            <filesets>
                                <fileset>
                                    <directory>${basedir}/target/${server.output.dir.prefix}-${server.output.dir.version}</directory>
                                    <includes>
                                        <include>README.txt</include>
                                        <include>copyright.txt</include>
                                    </includes>
                                </fileset>
                                <fileset>
                                    <directory>${basedir}/target/${server.output.dir.prefix}-${server.output.dir.version}/welcome-content</directory>
                                    <excludes>
                                        <exclude>robots.txt</exclude>
                                        <exclude>index.html</exclude>
                                    </excludes>
                                </fileset>
                                <fileset>
                                    <directory>${basedir}/target/${server.output.dir.prefix}-${server.output.dir.version}/modules/system/layers/keycloak/org/jboss/as/product</directory>
                                    <excludes>
                                        <exclude>${product.slot}/**/*</exclude>
                                    </excludes>
                                </fileset>
                            </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>verifications-configuration</id>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <phase>process-classes</phase>
                        <configuration>
                            <overwrite>true</overwrite>
                            <outputDirectory>${basedir}/target/verifier</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/verifier</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-verifier-plugin</artifactId>
            </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>
                            <recompressZippedFiles>true</recompressZippedFiles>
                            <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>

    <profiles>
        <profile>
            <id>community</id>
            <activation>
                <property>
                    <name>!product</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-galleon-pack</artifactId>
                    <type>pom</type>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-galleon-pack</artifactId>
                    <type>zip</type>
                    <exclusions>
                        <exclusion>
                            <groupId>*</groupId>
                            <artifactId>*</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
            <build>
                <finalName>keycloak-${project.version}</finalName>
            </build>
        </profile>
        <profile>
            <id>product</id>
            <activation>
                <property>
                    <name>product</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>${ee.maven.groupId}</groupId>
                    <artifactId>wildfly-ee-galleon-pack</artifactId>
                    <type>pom</type>
                    <version>${ee.maven.version}</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>${ee.maven.groupId}</groupId>
                    <artifactId>wildfly-ee-galleon-pack</artifactId>
                    <type>zip</type>
                    <version>${ee.maven.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>*</groupId>
                            <artifactId>*</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
            <build>
                <finalName>${product.name}-${product.filename.version}</finalName>
                <plugins>
                    <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-zip-only.xml</descriptor>
                                    </descriptors>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
