<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.rhq</groupId>
    <artifactId>rhq-plugins-parent</artifactId>
    <version>4.4.0</version>
  </parent>

  <groupId>org.rhq</groupId>
  <artifactId>rhq-jboss-as-7-plugin</artifactId>
  <packaging>jar</packaging>

  <name>RHQ JBossAS 7.x Plugin</name>
  <description>a plugin for monitoring and managing JBoss AS 7.x and JBoss platforms based on it (e.g. JBoss EAP 6.x)</description>


  <properties>
    <json.version>${project.json.version}</json.version>
    <jackson.version>1.9.5</jackson.version>
    <jboss.sasl.version>1.0.0.Final</jboss.sasl.version>
    <as7.version>7.1.2.Final-SNAPSHOT</as7.version>
    <as7.url>https://hudson.jboss.org/hudson/view/JBoss%20AS/job/JBoss-AS-7.0.x/lastSuccessfulBuild/artifact/build/target/jboss-7.0.x.zip</as7.url>
    <jboss-as-arquillian-container-managed.version>7.1.1.Final</jboss-as-arquillian-container-managed.version>
    <java.tieredCompilation>-Dxxx</java.tieredCompilation>
    <java.useCompressedOOPS>-Dxxx</java.useCompressedOOPS>
  </properties>


  <dependencies>

    <!-- === Provided Deps === -->

    <dependency>
      <groupId>org.rhq</groupId>
      <artifactId>rhq-jmx-plugin</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
      <!-- by the plugin container -->
    </dependency>

    <!-- === Compile Deps === -->

    <!-- NOTE: jackson 2.0.0 has moved to a new groupId - artifacts are under
               http://repo1.maven.org/maven2/com/fasterxml/jackson/ -->
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>${jackson.version}</version>
    </dependency>

    <!-- for the password hashing - we may want to copy the relevant stuff over ourselves -->
    <dependency>
      <groupId>org.jboss.sasl</groupId>
      <artifactId>jboss-sasl</artifactId>
      <version>${jboss.sasl.version}</version>
    </dependency>

    <!-- === Test Deps === -->

    <dependency>
      <groupId>${rhq.groupId}</groupId>
      <artifactId>rhq-core-plugin-test-api</artifactId>
      <version>${project.version}</version>
      <type>pom</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>${rhq.groupId}</groupId>
      <artifactId>rhq-core-plugin-test-util</artifactId>
      <version>${project.version}</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>


  <build>
    <plugins>

      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-libs</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <includeScope>runtime</includeScope>
              <excludeScope>plugin</excludeScope>
              <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <excludes>
            <!-- The surefire plugin only does the unit tests in src/test
            -  integration test are handled below in the *** as7-itest ** profile
            -->
            <exclude>org/rhq/modules/plugins/jbossas7/itest/**</exclude>
          </excludes>
        </configuration>
      </plugin>

    </plugins>
  </build>


  <profiles>

    <profile>
      <id>java7</id>
      <activation>
        <property>
          <name>java.specification.version</name>
          <value>1.7</value>
        </property>
      </activation>

      <properties>
        <java.tieredCompilation>-XX:+TieredCompilation</java.tieredCompilation>
      </properties>

    </profile>

    <profile>
      <id>java64bit</id>

      <activation>
        <property>
          <name>sun.arch.data.model</name>
          <value>64</value>
        </property>
      </activation>

      <properties>
        <java.useCompressedOOPS>-XX:+UseCompressedOops</java.useCompressedOOPS>
      </properties>
    </profile>

    <profile>
      <id>as700Final.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>7.0.0.Final</value>
        </property>
      </activation>

      <properties>
        <jboss-as-arquillian-container-managed.version>${as7.version}</jboss-as-arquillian-container-managed.version>
        <as7.url>https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/as/jboss-as-dist/${as7.version}/jboss-as-dist-${as7.version}.zip</as7.url>
      </properties>
    </profile>

    <profile>
      <id>as701Final.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>7.0.1.Final</value>
        </property>
      </activation>

      <properties>
        <jboss-as-arquillian-container-managed.version>${as7.version}</jboss-as-arquillian-container-managed.version>
        <as7.url>https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/as/jboss-as-dist/${as7.version}/jboss-as-dist-${as7.version}.zip</as7.url>
      </properties>
    </profile>

    <profile>
      <id>as710Final.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>7.1.0.Final</value>
        </property>
      </activation>

      <properties>
        <jboss-as-arquillian-container-managed.version>${as7.version}</jboss-as-arquillian-container-managed.version>
        <as7.url>https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/as/jboss-as-dist/${as7.version}/jboss-as-dist-${as7.version}.zip</as7.url>
      </properties>
    </profile>

    <profile>
      <id>as711Final.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>7.1.1.Final</value>
        </property>
      </activation>

      <properties>
        <jboss-as-arquillian-container-managed.version>${as7.version}</jboss-as-arquillian-container-managed.version>
        <as7.url>https://repository.jboss.org/nexus/content/repositories/releases/org/jboss/as/jboss-as-dist/${as7.version}/jboss-as-dist-${as7.version}.zip</as7.url>
      </properties>
    </profile>

    <profile>
      <id>eap600Beta1.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>6.0.0.Beta1</value>
        </property>
      </activation>

      <properties>
        <as7.url>Please set the as7.url system property to the location of the EAP ${as7.version} distribution zipfile.</as7.url>
        <jboss-as-arquillian-container-managed.version>7.1.1.Final</jboss-as-arquillian-container-managed.version>
      </properties>
    </profile>

    <profile>
      <id>eap600ER4.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>6.0.0.ER4</value>
        </property>
      </activation>

      <properties>
        <as7.url>Please set the as7.url system property to the location of the EAP ${as7.version} distribution zipfile.</as7.url>
        <jboss-as-arquillian-container-managed.version>7.1.1.Final</jboss-as-arquillian-container-managed.version>
      </properties>
    </profile>

    <profile>
      <id>eap600ER5.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>6.0.0.ER5</value>
        </property>
      </activation>

      <properties>
        <as7.url>Please set the as7.url system property to the location of the EAP ${as7.version} distribution zipfile.</as7.url>
        <jboss-as-arquillian-container-managed.version>7.1.1.Final</jboss-as-arquillian-container-managed.version>
      </properties>
    </profile>

    <profile>
      <id>eap600ER6.itest.setup</id>

      <activation>
        <property>
          <name>as7.version</name>
          <value>6.0.0.ER6</value>
        </property>
      </activation>

      <properties>
        <as7.url>Please set the as7.url system property to the location of the EAP ${as7.version} distribution zipfile.</as7.url>
        <jboss-as-arquillian-container-managed.version>7.1.1.Final</jboss-as-arquillian-container-managed.version>
      </properties>
    </profile>

    <!-- Activate this profile to run the integration tests (these can take a while to complete). -->
    <!-- activate with -Das7.itest. See also http://rhq-project.org/display/RHQ/Notes#Notes-IntegrationTests -->
    <profile>
      <id>as7.itest</id>

      <activation>
        <property>
          <name>as7.itest</name>
        </property>
      </activation>

      <properties>
        <jboss7.home>${java.io.tmpdir}/jboss-as-${as7.version}</jboss7.home>

        <jboss.standalone.bindAddress>127.0.0.1</jboss.standalone.bindAddress>
        <jboss.standalone.portOffset>40000</jboss.standalone.portOffset>
        <!-- IMPORTANT: The management port must be the port offset + 9999. -->
        <jboss.standalone.nativeManagementPort>49999</jboss.standalone.nativeManagementPort>

        <jboss.domain.bindAddress>127.0.0.1</jboss.domain.bindAddress>
        <jboss.domain.portOffset>50000</jboss.domain.portOffset>
        <!-- IMPORTANT: The native management port must be the port offset + 9999. -->
        <jboss.domain.nativeManagementPort>59999</jboss.domain.nativeManagementPort>
        <!-- IMPORTANT: The native management port must be the port offset + 9990. -->
        <jboss.domain.httpManagementPort>59990</jboss.domain.httpManagementPort>
        <!-- IMPORTANT: The native management port must be the port offset + 9943. -->
        <jboss.domain.httpsManagementPort>59943</jboss.domain.httpsManagementPort>
      </properties>

      <build>
        <plugins>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>downloadAndUnzip</id>
                <phase>initialize</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <condition property="as7.product" value="eap" else="as">
                      <matches pattern="^6\." string="${as7.version}"/>
                    </condition>
                    <property name="as7.zipfile"
                              location="${java.io.tmpdir}/jboss-${as7.product}-${as7.version}.zip"/>
                    <get src="${as7.url}" dest="${as7.zipfile}"
                         usetimestamp="true" verbose="true"/>
                    <unzip src="${as7.zipfile}" dest="${java.io.tmpdir}"/>
                    <move file="${java.io.tmpdir}/jboss-eap-6.0"
                          tofile="${java.io.tmpdir}/jboss-as-${as7.version}" failonerror="false"
                          overwrite="false"/>

                    <chmod perm="u+rx">
                      <fileset dir="${jboss7.home}/bin" includes="*.sh"/>
                    </chmod>
                    <replace dir="${jboss7.home}"
                             includes="standalone/configuration/standalone.xml, domain/configuration/host.xml"
                             token="&lt;inet-address " value="&lt;loopback-address "/>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- This is so we can reference the below properties in jbossas7-arquillian.xml. -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-2</version>
            <executions>
              <execution>
                <goals>
                  <goal>set-system-properties</goal>
                </goals>
                <configuration>
                  <properties>
                    <property>
                      <name>jboss7.home</name>
                      <value>${jboss7.home}</value>
                    </property>
                    <property>
                      <name>jboss.standalone.bindAddress</name>
                      <value>${jboss.standalone.bindAddress}</value>
                    </property>
                    <property>
                      <name>jboss.standalone.portOffset</name>
                      <value>${jboss.standalone.portOffset}</value>
                    </property>
                    <property>
                      <name>jboss.standalone.nativeManagementPort</name>
                      <value>${jboss.standalone.nativeManagementPort}</value>
                    </property>
                  </properties>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1.jbossorg-3</version>

            <executions>

              <execution>
                <id>start-as7-standalone</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <background>true</background>
                  <!-- test blocks until the port at backgroundPollingAddress is available (waiting for starting) -->
                  <!-- when maven jvm exits, this plugin will kill the running servers -->
                  <backgroundPollingAddress>${jboss.standalone.bindAddress}:${jboss.standalone.nativeManagementPort}
                  </backgroundPollingAddress>
                  <executable>${java.home}/bin/java</executable>
                  <arguments>
                    <!-- Process Controller Java options -->
                    <argument>-D[Standalone]</argument>
                    <argument>-server</argument>
                    <argument>${java.useCompressedOOPS}</argument>
                    <argument>${java.tieredCompilation}</argument>
                    <argument>-Xms64m</argument>
                    <argument>-Xmx512m</argument>
                    <argument>-XX:MaxPermSize=256m</argument>
                    <argument>-Djava.net.preferIPv4Stack=true</argument>
                    <argument>-Dorg.jboss.resolver.warning=true</argument>
                    <argument>-Dsun.rmi.dgc.client.gcInterval=3600000</argument>
                    <argument>-Dsun.rmi.dgc.server.gcInterval=3600000</argument>
                    <argument>-Djboss.modules.system.pkgs=org.jboss.byteman</argument>
                    <argument>-Djava.awt.headless=true</argument>
                    <argument>-Djboss.server.default.config=standalone.xml</argument>
                    <argument>-Dorg.jboss.boot.log.file=${jboss7.home}/standalone/log/boot.log</argument>
                    <argument>-Dlogging.configuration=file:${jboss7.home}/standalone/configuration/logging.properties</argument>
                    <argument>-jar</argument>
                    <argument>${jboss7.home}/jboss-modules.jar</argument>
                    <argument>-mp</argument>
                    <argument>${jboss7.home}/modules</argument>
                    <argument>-jaxpmodule</argument>
                    <argument>javax.xml.jaxp-provider</argument>
                    <argument>org.jboss.as.standalone</argument>
                    <argument>-Djboss.home.dir=${jboss7.home}</argument>
                    <argument>--server-config=standalone-full-ha.xml</argument>
                    <argument>-Djboss.bind.address.management=${jboss.standalone.bindAddress}</argument>
                    <argument>-Djboss.bind.address=${jboss.standalone.bindAddress}</argument>
                    <argument>-Djboss.bind.address.unsecure=${jboss.standalone.bindAddress}</argument>
                    <argument>-Djboss.socket.binding.port-offset=${jboss.standalone.portOffset}</argument>
                  </arguments>
                </configuration>
              </execution>

              <execution>
                <id>start-as7-domain</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <background>true</background>
                  <!-- test blocks until the port at backgroundPollingAddress is available (waiting for starting) -->
                  <!-- when maven jvm exits, this plugin will kill the running servers -->
                  <backgroundPollingAddress>${jboss.domain.bindAddress}:${jboss.domain.nativeManagementPort}
                  </backgroundPollingAddress>
                  <executable>${java.home}/bin/java</executable>
                  <arguments>
                    <!-- Process Controller Java options -->
                    <argument>-D[Process Controller]</argument>
                    <argument>-Xms64M</argument>
                    <argument>-Xmx512M</argument>
                    <argument>-XX:MaxPermSize=256M</argument>
                    <argument>-Djava.net.preferIPv4Stack=true</argument>
                    <argument>-Dorg.jboss.resolver.warning=true</argument>
                    <argument>-Dsun.rmi.dgc.client.gcInterval=3600000</argument>
                    <argument>-Dsun.rmi.dgc.server.gcInterval=3600000</argument>
                    <argument>-Djboss.modules.system.pkgs=org.jboss.byteman</argument>
                    <argument>-Djava.awt.headless=true</argument>
                    <argument>-Djboss.domain.default.config=domain.xml</argument>
                    <argument>-Djboss.host.default.config=host.xml</argument>
                    <argument>-Dorg.jboss.boot.log.file=${jboss7.home}/domain/log/process-controller.log</argument>
                    <argument>-Dlogging.configuration=file:${jboss7.home}/domain/configuration/logging.properties</argument>
                    <argument>-Djboss.bind.address.management=${jboss.domain.bindAddress}</argument>
                    <argument>-Djboss.bind.address=${jboss.domain.bindAddress}</argument>
                    <argument>-Djboss.bind.address.unsecure=${jboss.domain.bindAddress}</argument>
                    <argument>-Djboss.socket.binding.port-offset=${jboss.domain.portOffset}</argument>
                    <argument>-jar</argument>
                    <argument>${jboss7.home}/jboss-modules.jar</argument>
                    <argument>-mp</argument>
                    <argument>${jboss7.home}/modules</argument>
                    <argument>org.jboss.as.process-controller</argument>
                    <argument>-jboss-home</argument>
                    <argument>${jboss7.home}</argument>
                    <argument>-jvm</argument>
                    <argument>${java.home}/bin/java</argument>
                    <argument>-mp</argument>
                    <argument>${jboss7.home}/modules</argument>
                    <argument>--</argument>

                    <!-- Host Controller Java options to be inserted *before* the built-in options -->
                    <argument>-Xms64M</argument>
                    <argument>-Xmx512M</argument>
                    <argument>-XX:MaxPermSize=256M</argument>
                    <argument>-Djava.net.preferIPv4Stack=true</argument>
                    <argument>-Dorg.jboss.resolver.warning=true</argument>
                    <argument>-Dsun.rmi.dgc.client.gcInterval=3600000</argument>
                    <argument>-Dsun.rmi.dgc.server.gcInterval=3600000</argument>
                    <argument>-Djboss.modules.system.pkgs=org.jboss.byteman</argument>
                    <argument>-Djava.awt.headless=true</argument>
                    <argument>-Djboss.domain.default.config=domain.xml</argument>
                    <argument>-Djboss.host.default.config=host.xml</argument>
                    <argument>-Dorg.jboss.boot.log.file=${jboss7.home}/domain/log/host-controller.log</argument>
                    <argument>-Dlogging.configuration=file:${jboss7.home}/domain/configuration/logging.properties</argument>
                    <argument>--</argument>

                    <!-- Host Controller Java options to be inserted *after* the built-in options -->
                    <!-- (e.g. "-jar /tmp/jboss-as-6.0.0.ER5/jboss-modules.jar -mp /tmp/jboss-as-6.0.0.ER5/modules -jaxpmodule javax.xml.jaxp-provider") -->
                    <argument>-default-jvm</argument>
                    <argument>${java.home}/bin/java</argument>
                    <!-- The remaining props are all our custom options (the ones that would be passed to domain.sh) -->
                    <argument>-Djboss.bind.address.management=${jboss.domain.bindAddress}</argument>
                    <argument>-Djboss.bind.address=${jboss.domain.bindAddress}</argument>
                    <argument>-Djboss.bind.address.unsecure=${jboss.domain.bindAddress}</argument>
                    <argument>-Djboss.socket.binding.port-offset=${jboss.domain.portOffset}</argument>
                    <argument>-Djboss.management.native.port=${jboss.domain.nativeManagementPort}</argument>
                    <argument>-Djboss.management.http.port=${jboss.domain.httpManagementPort}</argument>
                    <argument>-Djboss.management.https.port=${jboss.domain.httpsManagementPort}</argument>
                  </arguments>
                </configuration>
              </execution>

            </executions>

          </plugin>

          <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <!-- failsafe plugin prevents a test failure to abort the build, so that the post-integration-test phase
            -  can still shut down the servers fired up.
            -->
            <configuration>
              <skipTests>false</skipTests>
              <skipITs>false</skipITs>
              <includes>
                <!-- only include integration tests; normal unit tests are handled above by surefire plugin -->
                <include>org/rhq/modules/plugins/jbossas7/itest/**/*Test.java</include>
              </includes>
              <properties>
                <property>
                  <name>listener</name>
                  <value>org.rhq.test.testng.StdoutReporter</value>
                </property>
              </properties>
              <systemPropertyVariables>
                <arquillian.xml>${project.build.testSourceDirectory}/../resources/itest/arquillian.xml</arquillian.xml>
                <jboss7.home>${jboss7.home}</jboss7.home>
                <as7.version>${as7.version}</as7.version>
                <jboss.standalone.bindAddress>${jboss.standalone.bindAddress}</jboss.standalone.bindAddress>
                <jboss.standalone.portOffset>${jboss.standalone.portOffset}</jboss.standalone.portOffset>
                <jboss.domain.bindAddress>${jboss.domain.bindAddress}</jboss.domain.bindAddress>
                <jboss.domain.portOffset>${jboss.domain.portOffset}</jboss.domain.portOffset>
                <jboss.domain.httpManagementPort>${jboss.domain.httpManagementPort}</jboss.domain.httpManagementPort>
                <settings.localRepository>${settings.localRepository}</settings.localRepository>
              </systemPropertyVariables>
            </configuration>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>

      <dependencies>

        <dependency>
          <groupId>${rhq.groupId}</groupId>
          <artifactId>rhq-core-plugin-test-api</artifactId>
          <version>${project.version}</version>
          <type>pom</type>
          <scope>test</scope>
        </dependency>

      </dependencies>

    </profile>

    <profile>
      <id>dev</id>

      <properties>
        <rhq.rootDir>../../..</rhq.rootDir>
        <rhq.containerDir>${rhq.rootDir}/${rhq.defaultDevContainerPath}</rhq.containerDir>
        <rhq.deploymentDir>${rhq.containerDir}/jbossas/server/default/deploy/${rhq.earName}/rhq-downloads/rhq-plugins</rhq.deploymentDir>
      </properties>

      <build>
        <plugins>

          <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>

              <execution>
                <id>deploy</id>
                <phase>compile</phase>
                <configuration>
                  <tasks>
                    <mkdir dir="${rhq.deploymentDir}"/>
                    <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar"/>
                    <echo>*** Updating ${deployment.file}...</echo>
                    <jar destfile="${deployment.file}" basedir="${project.build.outputDirectory}"/>
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>

              <execution>
                <id>deploy-jar-meta-inf</id>
                <phase>package</phase>
                <configuration>
                  <tasks>
                    <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar"/>
                    <echo>*** Updating META-INF dir in ${deployment.file}...</echo>
                    <unjar src="${project.build.directory}/${project.build.finalName}.jar"
                           dest="${project.build.outputDirectory}">
                      <patternset>
                        <include name="META-INF/**"/>
                      </patternset>
                    </unjar>
                    <jar destfile="${deployment.file}" manifest="${project.build.outputDirectory}/META-INF/MANIFEST.MF"
                         update="true">
                    </jar>
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>

              <execution>
                <id>undeploy</id>
                <phase>clean</phase>
                <configuration>
                  <tasks>
                    <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar"/>
                    <echo>*** Deleting ${deployment.file}...</echo>
                    <delete file="${deployment.file}"/>
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>

            </executions>
          </plugin>

        </plugins>
      </build>

    </profile>
  </profiles>

</project>
