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

  <parent>
    <groupId>org.hawkular.apm</groupId>
    <artifactId>hawkular-apm</artifactId>
    <version>0.9.2.Final</version>
  </parent>

  <artifactId>hawkular-apm-dist</artifactId>
  <packaging>pom</packaging>
  <name>Hawkular APM::Distribution</name>
  <description>Hawkular APM distribution.</description>

  <properties>
    <build.dir>build/wildfly-${version.org.wildfly}</build.dir>
  </properties>

  <dependencies>

    <dependency>
      <groupId>org.wildfly</groupId>
      <artifactId>wildfly-dist</artifactId>
      <type>zip</type>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.hawkular.apm</groupId>
      <artifactId>hawkular-apm-server</artifactId>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.hawkular.apm</groupId>
      <artifactId>hawkular-apm-agent-rest</artifactId>
    </dependency>
    <dependency>
      <groupId>org.hawkular.apm</groupId>
      <artifactId>hawkular-apm-instrumentation-jvm</artifactId>
    </dependency>

    <dependency>
      <groupId>org.hawkular.apm</groupId>
      <artifactId>hawkular-apm-ui</artifactId>
      <type>war</type>
    </dependency>

  </dependencies>

  <build>

    <plugins>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <configuration>
          <excludes combine.children="append">
            <exclude>**/*.sh</exclude>
          </excludes>
        </configuration>
      </plugin>
      <!-- unpack the wildfly distribution to get its configuration that we need to customize -->
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack-wildfly</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/build</outputDirectory>
              <includeArtifactIds>wildfly-dist</includeArtifactIds>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <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>${basedir}/target/${build.dir}/standalone/configuration</dir>
                  <stylesheet>src/main/scripts/standalone.xsl</stylesheet>
                  <includes>
                    <include>standalone-full.xml</include>
                  </includes>
                  <outputDir>${basedir}/target/${build.dir}/standalone/configuration</outputDir>
                </transformationSet>
                <transformationSet>
                  <dir>${basedir}/target/${build.dir}/standalone/configuration</dir>
                  <stylesheet>src/main/scripts/standalone.xsl</stylesheet>
                  <includes>
                    <include>standalone-full-ha.xml</include>
                  </includes>
                  <outputDir>${basedir}/target/${build.dir}/standalone/configuration</outputDir>
                </transformationSet>
              </transformationSets>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <tasks>
                <copy file="${basedir}/src/main/security/application-roles.properties" todir="${basedir}/target/${build.dir}/standalone/configuration" overwrite="true" />
                <copy file="${basedir}/src/main/security/application-users.properties" todir="${basedir}/target/${build.dir}/standalone/configuration" overwrite="true" />

                <!-- Overwrite the standalone.xml with the modified standalone-full.xml, so that
                     it becomes the new default, and the standalone-ha.xml with the modified
                     standalone-ha-full.xml to be consistent -->
                <move file="${basedir}/target/${build.dir}/standalone/configuration/standalone-full.xml" tofile="${basedir}/target/${build.dir}/standalone/configuration/standalone.xml" overwrite="true" />
                <move file="${basedir}/target/${build.dir}/standalone/configuration/standalone-full-ha.xml" tofile="${basedir}/target/${build.dir}/standalone/configuration/standalone-ha.xml" overwrite="true" />

                <replace token="Xms64m" value="Xms256m" file="${basedir}/target/${build.dir}/bin/standalone.conf" />
                <replace token="Xmx512m" value="Xmx2048m" file="${basedir}/target/${build.dir}/bin/standalone.conf" />
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptors>
            <descriptor>src/main/scripts/distro-assembly.xml</descriptor>
          </descriptors>
          <appendAssemblyId>false</appendAssemblyId>
        </configuration>
        <executions>
          <execution>
            <id>distro-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
