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

    Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
    and other contributors as indicated by the @author tags.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<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.hawkular.accounts</groupId>
    <artifactId>hawkular-accounts-parent</artifactId>
    <version>2.0.34.Final</version>
  </parent>
  <artifactId>hawkular-accounts-feature-pack</artifactId>
  <packaging>pom</packaging>
  <name>Hawkular - Accounts - Feature Pack</name>

  <dependencies>

    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-keycloak-event-listener-rest</artifactId>
      <version>2.0.34.Final</version>
    </dependency>

    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-keycloak-event-listener-jms</artifactId>
      <version>2.0.34.Final</version>
    </dependency>

    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts</artifactId>
      <version>2.0.34.Final</version>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-events-backend</artifactId>
      <version>2.0.34.Final</version>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-secret-store</artifactId>
      <version>2.0.34.Final</version>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-keycloak-theme</artifactId>
      <version>2.0.34.Final</version>
      <type>jar</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>hawkular-nest-feature-pack</artifactId>
      <type>zip</type>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-server-feature-pack</artifactId>
      <type>zip</type>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-adapter-feature-pack</artifactId>
      <type>zip</type>
      <exclusions>
        <exclusion>
          <groupId>*</groupId>
          <artifactId>*</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

  </dependencies>

  <build>
    <plugins>

      <!-- Unpack the upstream artifacts that host standalone*.xml stubs that we want to adapt in the next steps -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-deps</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.hawkular.commons</groupId>
                  <artifactId>hawkular-nest-feature-pack</artifactId>
                  <type>zip</type>
                  <includes>**/*.xml</includes>
                  <outputDirectory>${project.build.directory}/feature-pack-resources-hawkular-nest</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.hawkular.commons</groupId>
                  <artifactId>hawkular-nest-feature-pack</artifactId>
                  <type>zip</type>
                  <includes>subsystem-templates/*.xml</includes>
                  <!-- It is probably a bug in the WF provisioning plugin that we need to unpack nest.xml
                    and effectivelly repack it in our FP. WF provisioning plugin should take care to
                    look for feature-pack-resources/*.xml also in FPs that the primary FP depends on -->
                  <outputDirectory>${project.build.directory}/feature-pack-resources</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.keycloak</groupId>
                  <artifactId>keycloak-server-feature-pack</artifactId>
                  <type>zip</type>
                  <includes>**/*.xml</includes>
                  <outputDirectory>${project.build.directory}/feature-pack-resources-keycloak-server</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.keycloak</groupId>
                  <artifactId>keycloak-adapter-feature-pack</artifactId>
                  <type>zip</type>
                  <includes>**/*.xml</includes>
                  <outputDirectory>${project.build.directory}/feature-pack-resources-keycloak-adapter</outputDirectory>
                </artifactItem>

                <artifactItem>
                  <groupId>org.wildfly</groupId>
                  <artifactId>wildfly-ejb3</artifactId>
                  <type>jar</type>
                  <version>${version.org.wildfly}</version>
                  <includes>subsystem-templates/*.xml</includes>
                  <outputDirectory>${project.build.directory}/upstream-subsystem-templates</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.wildfly</groupId>
                  <artifactId>wildfly-messaging-activemq</artifactId>
                  <includes>subsystem-templates/*.xml</includes>
                  <outputDirectory>${project.build.directory}/upstream-subsystem-templates</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.wildfly</groupId>
                  <artifactId>wildfly-security</artifactId>
                  <includes>subsystem-templates/*.xml</includes>
                  <outputDirectory>${project.build.directory}/upstream-subsystem-templates</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Enhance various *.xml files taken from our dependencies using XSL transformations -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>transform-xmls</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>transform</goal>
            </goals>
            <configuration>
              <transformationSets>
                <transformationSet>
                  <dir>${project.build.directory}/feature-pack-resources-hawkular-nest</dir>
                  <stylesheet>${basedir}/src/main/xsl/configuration/standalone/hawkular-accounts-subsystems.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>kc-adapter-subsystems-path</name>
                      <value>${project.build.directory}/feature-pack-resources-keycloak-adapter/configuration/standalone/subsystems.xml</value>
                    </parameter>
                    <parameter>
                      <name>kc-server-subsystems-path</name>
                      <value>${project.build.directory}/feature-pack-resources-keycloak-server/configuration/standalone/subsystems.xml</value>
                    </parameter>
                  </parameters>
                  <includes>
                    <include>configuration/standalone/hawkular-nest-subsystems.xml</include>
                  </includes>
                  <outputDir>${project.build.directory}/feature-pack-resources</outputDir>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^.*$</pattern>
                      <replacement>configuration/standalone/hawkular-accounts-subsystems.xml</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
                <transformationSet>
                  <dir>${project.build.directory}/feature-pack-resources-hawkular-nest</dir>
                  <stylesheet>${basedir}/src/main/xsl/configuration/standalone/hawkular-accounts-template.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>kc-adapter-template-path</name>
                      <value>${project.build.directory}/feature-pack-resources-keycloak-adapter/configuration/standalone/template.xml</value>
                    </parameter>
                    <parameter>
                      <name>kc-server-template-path</name>
                      <value>${project.build.directory}/feature-pack-resources-keycloak-server/configuration/standalone/template.xml</value>
                    </parameter>
                  </parameters>
                  <includes>
                    <include>configuration/standalone/hawkular-nest-template.xml</include>
                  </includes>
                  <outputDir>${project.build.directory}/feature-pack-resources</outputDir>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^.*$</pattern>
                      <replacement>configuration/standalone/hawkular-accounts-template.xml</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>

                <transformationSet>
                  <dir>${project.build.directory}/upstream-subsystem-templates</dir>
                  <stylesheet>${basedir}/src/main/xsl/subsystem-templates/hawkular-accounts-ejb3.xsl</stylesheet>
                  <includes>
                    <include>subsystem-templates/ejb3.xml</include>
                  </includes>
                  <outputDir>${project.build.directory}/feature-pack-resources</outputDir>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^subsystem-templates/(.*)\.xml$</pattern>
                      <replacement>subsystem-templates/hawkular-accounts-$1.xml</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
                <transformationSet>
                  <dir>${project.build.directory}/upstream-subsystem-templates</dir>
                  <stylesheet>${basedir}/src/main/xsl/subsystem-templates/hawkular-accounts-messaging-activemq.xsl</stylesheet>
                  <includes>
                    <include>subsystem-templates/messaging-activemq.xml</include>
                  </includes>
                  <outputDir>${project.build.directory}/feature-pack-resources</outputDir>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^subsystem-templates/(.*)\.xml$</pattern>
                      <replacement>subsystem-templates/hawkular-accounts-$1.xml</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
                <transformationSet>
                  <dir>${project.build.directory}/upstream-subsystem-templates</dir>
                  <stylesheet>${basedir}/src/main/xsl/subsystem-templates/hawkular-accounts-security.xsl</stylesheet>
                  <includes>
                    <include>subsystem-templates/security.xml</include>
                  </includes>
                  <outputDir>${project.build.directory}/feature-pack-resources</outputDir>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>^subsystem-templates/(.*)\.xml$</pattern>
                      <replacement>subsystem-templates/hawkular-accounts-$1.xml</replacement>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
              </transformationSets>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/feature-pack-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>
            <phase>compile</phase>
            <goals>
              <goal>build</goal>
            </goals>
            <configuration>
              <resources-dir>target/feature-pack-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>
              <appendAssemblyId>false</appendAssemblyId>
              <tarLongFileMode>gnu</tarLongFileMode>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>
