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

    Copyright 2015 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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.hawkular</groupId>
    <artifactId>hawkular</artifactId>
    <version>1.0.0.Alpha7</version>
  </parent>

  <artifactId>hawkular-dist</artifactId>
  <packaging>pom</packaging>
  <name>Hawkular: Distribution</name>
  <description>Hawkular distribution that integrates all components into a single server.</description>

  <properties>
    <kettle.build.type>production</kettle.build.type>
    <checkstyle.suppressions.file>checkstyle-suppressions.xml</checkstyle.suppressions.file>
    <assembly.dir>${project.build.directory}/assembly</assembly.dir>
    <wildfly.dist.zip.root.dir>wildfly-${version.org.wildfly}</wildfly.dist.zip.root.dir>
    <hawkular.dist.zip.root.dir>hawkular-${project.version}</hawkular.dist.zip.root.dir>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.hawkular.nest</groupId>
      <artifactId>hawkular-nest-distro</artifactId>
      <version>1.0.0.Alpha7</version>
      <classifier>distribution</classifier>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.agent</groupId>
      <artifactId>hawkular-wildfly-agent-wf-extension</artifactId>
      <type>zip</type>
      <!-- for some reason, the assembly plugin barfs if we don't exclude this -->
      <exclusions>
        <exclusion>
          <groupId>org.hawkular.agent</groupId>
          <artifactId>hawkular-wildfly-agent-feature-pack</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.hawkular.agent</groupId>
      <artifactId>hawkular-wildfly-agent-installer</artifactId>
      <version>${version.org.hawkular.agent}</version>
    </dependency>

    <dependency>
      <groupId>org.hawkular.inventory</groupId>
      <artifactId>hawkular-inventory-dist</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.cmdgw</groupId>
      <artifactId>hawkular-command-gateway-war</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular</groupId>
      <artifactId>hawkular-wildfly-agent-download</artifactId>
      <version>1.0.0.Alpha7</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular</groupId>
      <artifactId>hawkular-pinger</artifactId>
      <version>1.0.0.Alpha7</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular</groupId>
      <artifactId>hawkular-avail-creator</artifactId>
      <version>1.0.0.Alpha7</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.alerts</groupId>
      <artifactId>hawkular-alerts-rest</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.alerts</groupId>
      <artifactId>hawkular-alerts-actions-email</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.metrics</groupId>
      <artifactId>hawkular-metrics-component</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>hawkular-commons-embedded-cassandra-ear</artifactId>
      <type>ear</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular</groupId>
      <artifactId>hawkular-console</artifactId>
      <version>1.0.0.Alpha7</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-events-backend</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-secret-store</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular</groupId>
      <artifactId>hawkular-redhat-access-integration-backend</artifactId>
      <version>1.0.0.Alpha7</version>
      <type>war</type>
    </dependency>

    <!-- Keycloak-related dependencies -->
    <dependency>
      <groupId>org.keycloak</groupId>
      <artifactId>keycloak-wf9-modules</artifactId>
      <version>${version.org.keycloak}</version>
      <type>zip</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-keycloak-theme</artifactId>
      <version>${version.org.hawkular.accounts}</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-keycloak-event-listener-jms</artifactId>
      <version>${version.org.hawkular.accounts}</version>
      <classifier>module</classifier>
      <type>zip</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.accounts</groupId>
      <artifactId>hawkular-accounts-keycloak-event-listener-rest</artifactId>
      <version>${version.org.hawkular.accounts}</version>
      <classifier>module</classifier>
      <type>zip</type>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.keycloak</groupId>
                  <artifactId>keycloak-server-overlay</artifactId>
                  <type>zip</type>
                  <version>${version.org.keycloak}</version>
                  <outputDirectory>${project.build.directory}/keycloak</outputDirectory>
                </artifactItem>
                <artifactItem>
                  <groupId>org.keycloak</groupId>
                  <artifactId>keycloak-wf9-modules</artifactId>
                  <type>zip</type>
                  <outputDirectory>${project.build.directory}/keycloak/modules/system/layers/base</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
          <execution>
            <id>unpack-wildfly</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/wildfly</outputDirectory>
              <includeArtifactIds>hawkular-nest-distro</includeArtifactIds>
              <!-- In */domain, we remove everything except for /configuration/*.properties that are need because of HAWKULAR-430 -->
              <excludes>*/appclient/**,*/docs/**,*/domain/data/**,*/domain/tmp/**,*/domain/configuration/*.xml</excludes>
            </configuration>
          </execution>
          <!-- copies any extension modules we want to later add to the kettle -->
          <execution>
            <id>copy-hawkular-modules</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/hawkular-modules</outputDirectory>
              <includeArtifactIds>
                hawkular-wildfly-agent-wf-extension
              </includeArtifactIds>
              <stripVersion>true</stripVersion>
              <stripClassifier>true</stripClassifier>
              <overWriteIfNew>true</overWriteIfNew>
              <excludeTransitive>true</excludeTransitive>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- use the agent installer to install the agent extension module -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>install-agent-module</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <includePluginDependencies>true</includePluginDependencies>
              <mainClass>org.hawkular.wildfly.agent.installer.AgentInstaller</mainClass>
              <arguments>
                <argument>--target-location=${project.build.directory}/wildfly/${wildfly.dist.zip.root.dir}</argument>
                <argument>--module=${project.build.directory}/hawkular-modules/hawkular-wildfly-agent-wf-extension.zip</argument>
                <argument>--server-url=http://localhost:8080</argument>
                <argument>--username=jdoe</argument>
                <argument>--password=password</argument>
              </arguments>
              <systemProperties>
                <systemProperty>
                  <key>log4j.configuration</key>
                  <value>file:${basedir}/log4j.xml</value>
                </systemProperty>
                <systemProperty>
                  <key>org.hawkular.wildfly.agent.installer.throw-exception-on-error</key>
                  <value>true</value>
                </systemProperty>
              </systemProperties>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.hawkular.agent</groupId>
            <artifactId>hawkular-wildfly-agent-installer</artifactId>
            <version>${version.org.hawkular.agent}</version>
          </dependency>
          <dependency>
            <groupId>org.hawkular.agent</groupId>
            <artifactId>wildfly-module-installer</artifactId>
            <version>${version.org.hawkular.agent}</version>
          </dependency>
        </dependencies>
      </plugin>

      <!-- further customize standalone.xml -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xml-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>transform-standalone-xml</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>transform</goal>
            </goals>
            <configuration>
              <transformationSets>
                <!-- standalone.xml -->
                <transformationSet>
                  <dir>${project.build.directory}/wildfly/${wildfly.dist.zip.root.dir}/standalone/configuration</dir>
                  <stylesheet>src/main/resources/wildfly/patches/standalone.xsl</stylesheet>
                  <includes>
                    <include>standalone.xml</include>
                  </includes>
                  <outputDir>${assembly.dir}/${hawkular.dist.zip.root.dir}/standalone/configuration</outputDir>
                  <parameters>
                    <parameter>
                      <name>kettle.build.type</name>
                      <value>${kettle.build.type}</value>
                    </parameter>
                    <parameter>
                      <name>uuid.hawkular.accounts.backend</name>
                      <value>${uuid.hawkular.accounts.backend}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
                <!-- standalone-itest.xml -->
                <transformationSet>
                  <dir>${project.build.directory}/wildfly/${wildfly.dist.zip.root.dir}/standalone/configuration</dir>
                  <stylesheet>src/main/resources/wildfly/patches/standalone.xsl</stylesheet>
                  <fileMappers>
                    <fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                      <pattern>\.xml$</pattern>
                      <replacement>-itest.xml</replacement>
                    </fileMapper>
                  </fileMappers>
                  <includes>
                    <include>standalone.xml</include>
                  </includes>
                  <outputDir>${assembly.dir}/${hawkular.dist.zip.root.dir}/standalone/configuration</outputDir>
                  <parameters>
                    <parameter>
                      <name>kettle.build.type</name>
                      <value>dev</value>
                    </parameter>
                    <parameter>
                      <name>uuid.hawkular.accounts.backend</name>
                      <value>${uuid.hawkular.accounts.backend}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
              </transformationSets>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <finalName>hawkular-${project.version}</finalName>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>assembly.xml</descriptor>
          </descriptors>
          <formats>
            <format>zip</format>
            <format>tar.gz</format>
          </formats>
        </configuration>
        <executions>
          <execution>
            <id>distro-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.spotify</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.2.12</version>
        <configuration>
          <imageName>hawkular:snapshot</imageName>
          <dockerDirectory>docker</dockerDirectory>
          <resources>
            <resource>
              <targetPath>/</targetPath>
              <directory>${project.build.directory}</directory>
              <include>hawkular-${project.version}.zip</include>
            </resource>
          </resources>
        </configuration>
      </plugin>

      <!-- Generate some keys for Keycloak integration, so that we don't ship with default credentials -->
      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.5</version>
        <executions>
          <execution>
            <id>set-custom-property</id>
            <phase>initialize</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <source>
                import java.util.UUID
                def uuidBackend = UUID.randomUUID().toString()
                def uuidUi = UUID.randomUUID().toString()
                project.properties.setProperty('uuid.hawkular.accounts.backend', uuidBackend.toString())
                project.properties.setProperty('uuid.hawkular.ui', uuidUi.toString())
              </source>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <excludes combine.children="append">
            <exclude>**/product.conf</exclude>
          </excludes>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <id>dev</id>
      <properties>
        <kettle.build.type>dev</kettle.build.type>
      </properties>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
              <formats>
                <format>dir</format>
              </formats>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>dozip</id>
      <properties>
        <kettle.build.type>dev</kettle.build.type>
      </properties>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
              <formats>
                <format>dir</format>
                <format>zip</format>
                <format>tar.gz</format>
              </formats>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>
</project>
