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

    Copyright 2015-2017 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.agent</groupId>
    <artifactId>hawkular-wildfly-agent-parent</artifactId>
    <version>0.26.0.Final</version>
  </parent>

  <artifactId>hawkular-wildfly-agent-dist</artifactId>
  <packaging>pom</packaging>

  <name>Hawkular Agent: WildFly + Agent Distro</name>
  <description>A WildFly distribution that includes an agent installed inside of it.</description>

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

  <build>
    <plugins>

      <!-- provision a plain WildFly server -->
      <plugin>
        <groupId>org.wildfly.build</groupId>
        <artifactId>wildfly-server-provisioning-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>provision-plain-wildfly</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>build</goal>
            </goals>
            <configuration>
              <config-file>server-provisioning-plain-wildfly.xml</config-file>
              <server-name>${project.build.finalName}</server-name>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Install the Hawkular WildFly Agent inside the WildFly server -->
      <!--
           The agent will be installed in standalone.xml file as well as host.xml and domain.xml.
           People typically will only use the agent distro in standalone mode, but we put it in
           host.xml/domain.xml just in case someone wants to use it that way.
      -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>install-agent-standalone</id>
            <phase>process-resources</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>org.hawkular.wildfly.agent.installer.AgentInstaller</mainClass>
              <arguments>
                <argument>--target-config=standalone/configuration/standalone.xml</argument>
                <argument>--target-location=${basedir}/target/${project.build.finalName}</argument>
                <argument>--module-dist=classpath:hawkular-wildfly-agent-wf-extension.zip</argument>
                <argument>--server-url=http://127.0.0.1:8080</argument>
                <argument>--username=jdoe</argument>
                <argument>--password=password</argument>
                <argument>--enabled=true</argument>
              </arguments>
              <systemProperties>
                <systemProperty>
                  <key>org.hawkular.wildfly.agent.installer.throw-exception-on-error</key>
                  <value>true</value>
                </systemProperty>
              </systemProperties>
            </configuration>
          </execution>
          <execution>
            <id>install-agent-host</id>
            <phase>process-resources</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>org.hawkular.wildfly.agent.installer.AgentInstaller</mainClass>
              <arguments>
                <argument>--target-config=domain/configuration/host.xml</argument>
                <argument>--target-location=${basedir}/target/${project.build.finalName}</argument>
                <argument>--module-dist=classpath:hawkular-wildfly-agent-wf-extension.zip</argument>
                <argument>--server-url=http://127.0.0.1:8080</argument>
                <argument>--username=jdoe</argument>
                <argument>--password=password</argument>
                <argument>--enabled=true</argument>
              </arguments>
              <systemProperties>
                <systemProperty>
                  <key>org.hawkular.wildfly.agent.installer.throw-exception-on-error</key>
                  <value>true</value>
                </systemProperty>
              </systemProperties>
            </configuration>
          </execution>
          <execution>
            <id>install-agent-domain</id>
            <phase>process-resources</phase>
            <goals>
              <goal>java</goal>
            </goals>
            <configuration>
              <mainClass>org.hawkular.wildfly.agent.installer.AgentInstaller</mainClass>
              <arguments>
                <argument>--target-config=domain/configuration/domain.xml</argument>
                <argument>--target-location=${basedir}/target/${project.build.finalName}</argument>
                <argument>--module-dist=classpath:hawkular-wildfly-agent-wf-extension.zip</argument>
                <argument>--server-url=http://127.0.0.1:8080</argument>
                <argument>--username=jdoe</argument>
                <argument>--password=password</argument>
                <argument>--enabled=true</argument>
              </arguments>
              <systemProperties>
                <systemProperty>
                  <key>org.hawkular.wildfly.agent.installer.throw-exception-on-error</key>
                  <value>true</value>
                </systemProperty>
              </systemProperties>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- assemble the WildFly + Agent into a distribution zip file -->
      <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>
              <finalName>${project.build.finalName}</finalName>
              <appendAssemblyId>false</appendAssemblyId>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>
