<?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.nest</groupId>
    <artifactId>hawkular-nest-parent</artifactId>
    <version>1.0.0.Alpha8</version>
  </parent>

  <artifactId>hawkular-nest-distro</artifactId>
  <packaging>pom</packaging>
  <name>Hawkular: Nest Distribution</name>
  <inceptionYear>2015</inceptionYear>

  <properties>
    <nest.build.type>production</nest.build.type>
    <wildfly.dist.zip.root.dir>wildfly-${version.org.wildfly}</wildfly.dist.zip.root.dir>
    <assembly.dir>${project.build.directory}/assembly</assembly.dir>
    <checkstyle.suppressions.file>${basedir}/src/main/scripts/checkstyle-suppressions.xml</checkstyle.suppressions.file>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.hawkular.nest</groupId>
      <artifactId>hawkular-nest-wf-extension</artifactId>
      <version>1.0.0.Alpha8</version>
      <classifier>module</classifier>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.commons</groupId>
      <artifactId>cassandra-driver-wf-module</artifactId>
      <classifier>module</classifier>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.bus</groupId>
      <artifactId>hawkular-bus-broker-wf-extension</artifactId>
      <classifier>module</classifier>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>org.hawkular.bus</groupId>
      <artifactId>hawkular-bus-ra-wf-module</artifactId>
      <classifier>module</classifier>
      <type>zip</type>
    </dependency>

    <dependency>
      <groupId>org.wildfly</groupId>
      <artifactId>wildfly-dist</artifactId>
      <type>zip</type>
      <exclusions>
        <exclusion>
          <groupId>org.wildfly</groupId>
          <artifactId>wildfly-feature-pack</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>

    <plugins>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <excludes combine.children="append">
            <exclude>src/main/scripts/subsystem*.xml</exclude>
            <exclude>src/main/scripts/socketbinding*.xml</exclude>
          </excludes>
        </configuration>
      </plugin>

      <!-- unpack the wildfly distribution and copy our hawkular modules in a tmp location -->
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-wildfly</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${assembly.dir}</outputDirectory>
              <includeArtifactIds>wildfly-dist</includeArtifactIds>
              <excludes>*/appclient/**,*/docs/**,*/domain/**</excludes>
            </configuration>
          </execution>
          <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-nest-wf-extension,
                hawkular-bus-broker-wf-extension,
              </includeArtifactIds>
              <stripVersion>true</stripVersion>
              <stripClassifier>true</stripClassifier>
              <overWriteIfNewer>true</overWriteIfNewer>
              <excludeTransitive>true</excludeTransitive>
            </configuration>
          </execution>
          <execution>
            <id>unpack-ra-module</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${assembly.dir}/${wildfly.dist.zip.root.dir}/modules/</outputDirectory>
              <includeArtifactIds>
                hawkular-bus-ra-wf-module
              </includeArtifactIds>
              <excludeTransitive>true</excludeTransitive>
            </configuration>
          </execution>
          <execution>
            <id>unpack-cassandra-driver</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${assembly.dir}/${wildfly.dist.zip.root.dir}/modules/</outputDirectory>
              <includeArtifactIds>cassandra-driver-wf-module</includeArtifactIds>
              <excludeTransitive>true</excludeTransitive>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- put some custom files in the out-of-box wildfly we unpacked above -->
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-distro-resources-to-wildfly</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${assembly.dir}/${wildfly.dist.zip.root.dir}</outputDirectory>
              <resources>
                <resource>
                  <directory>src/main/distro-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- install our hawkular extension modules and customize standalone.xml -->
      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-extension-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>install-bus-broker-module</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <jbossHome>${assembly.dir}/${wildfly.dist.zip.root.dir}</jbossHome>
              <serverConfig>standalone/configuration/standalone.xml</serverConfig>
              <modulesHome>modules/</modulesHome>
              <moduleZip>${project.build.directory}/hawkular-modules/hawkular-bus-broker-wf-extension.zip</moduleZip>
              <subsystem>${basedir}/src/main/scripts/subsystem-hawkular-bus-broker-wf-extension.xml</subsystem>
              <socketBinding>${basedir}/src/main/scripts/socketbinding-hawkular-bus-broker-wf-extension.xml</socketBinding>
              <edit>
                <insert>
                  <select>/server/socket-binding-group[@name='standard-sockets']</select>
                  <xml><![CDATA[<socket-binding name="org.hawkular.bus.broker.discovery" port="0" multicast-address="224.0.0.4" multicast-port="63636" />]]></xml>
                  <attribute>name</attribute>
                </insert>
              </edit>
            </configuration>
          </execution>
          <execution>
            <id>install-nest-module</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>deploy</goal>
            </goals>
            <configuration>
              <jbossHome>${assembly.dir}/${wildfly.dist.zip.root.dir}</jbossHome>
              <serverConfig>standalone/configuration/standalone.xml</serverConfig>
              <!-- we do not care about this backup, so put it somewhere so it won't overwrite first backup -->
              <serverConfigBackup>${project.build.directory}/standalone.xml.out</serverConfigBackup>
              <modulesHome>modules/</modulesHome>
              <moduleZip>${project.build.directory}/hawkular-modules/hawkular-nest-wf-extension.zip</moduleZip>
              <subsystem>${basedir}/src/main/scripts/subsystem-hawkular-nest-wf-extension.xml</subsystem>
            </configuration>
          </execution>
        </executions>
      </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>
                <transformationSet>
                  <dir>${assembly.dir}/${wildfly.dist.zip.root.dir}/standalone/configuration</dir>
                  <stylesheet>src/main/scripts/standalone.xsl</stylesheet>
                  <includes>
                    <include>standalone.xml</include>
                  </includes>
                  <outputDir>${assembly.dir}/${wildfly.dist.zip.root.dir}/standalone/configuration</outputDir>
                  <parameters>
                    <parameter>
                      <name>nest.build.type</name>
                      <value>${nest.build.type}</value>
                    </parameter>
                  </parameters>
                </transformationSet>
              </transformationSets>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>assembly.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>distro-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

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