<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.13.0</version>
   </parent>

   <groupId>org.rhq</groupId>
   <artifactId>rhq-jmx-plugin</artifactId>
   <version>4.13.0</version>
   <packaging>jar</packaging>

   <name>RHQ JMX Plugin</name>
   <description>a plugin for managing a generic JMX-enabled application</description>

   <properties>
      <rhq.internal>false</rhq.internal>
      <rhq.jmxplugin.as7.artifact>org.jboss.as:jboss-as-dist:7.1.1.Final</rhq.jmxplugin.as7.artifact>
      <rhq.jmxplugin.as7.standalone.portOffset>37897</rhq.jmxplugin.as7.standalone.portOffset>
      <!-- IMPORTANT: The management port must be the port offset + 9999. -->
      <rhq.jmxplugin.as7.standalone.management.port>47896</rhq.jmxplugin.as7.standalone.management.port>
      <rhq.jmxplugin.as7.standalone.home>${project.build.directory}/jboss-as-run/jboss-as-7.1.1.Final</rhq.jmxplugin.as7.standalone.home>
      <rhq.jmxplugin.wildfly8.artifact>org.wildfly:wildfly-dist:8.1.0.Final</rhq.jmxplugin.wildfly8.artifact>
      <rhq.jmxplugin.wildfly8.standalone.portOffset>47897</rhq.jmxplugin.wildfly8.standalone.portOffset>
      <!-- IMPORTANT: The management port must be the port offset + 9990. -->
      <rhq.jmxplugin.wildfly8.standalone.management.port>57887</rhq.jmxplugin.wildfly8.standalone.management.port>
      <rhq.jmxplugin.wildfly8.standalone.home>${project.build.directory}/wildfly-run/wildfly-8.1.0.Final</rhq.jmxplugin.wildfly8.standalone.home>
   </properties>

  <dependencies>

      <dependency>
         <groupId>mc4j</groupId>
         <artifactId>org-mc4j-ems</artifactId>
         <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
      </dependency>

      <!-- needed for the JVM Attach API. NOTE: we do not package tools.jar in the plugin jar's lib dir, because if it
           is available at runtime, rhq-agent.sh/rhq-agent.bat will add it to the Agent's classpath. -->
      <dependency>
         <groupId>com.sun</groupId>
         <artifactId>tools</artifactId>
         <version>1.6.0</version>
         <scope>system</scope>
         <systemPath>${jdkToolsJar}</systemPath>
      </dependency>

      <!-- Test dependencies -->

      <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <scope>test</scope>
      </dependency>

   </dependencies>

   <build>
      <plugins>

         <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
               <execution>
                  <id>copy-ems-jar</id>
                  <phase>process-resources</phase>
                  <goals>
                     <goal>copy</goal>
                  </goals>
                  <configuration>
                     <artifactItems>
                        <artifactItem>
                           <groupId>mc4j</groupId>
                           <artifactId>org-mc4j-ems</artifactId>
                           <version>${ems.version}</version>
                        </artifactItem>
                     </artifactItems>
                     <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

   <profiles>

      <profile>
          <id>sun_jdk</id>
          <activation>
              <file>
                  <exists>${java.home}/../lib/tools.jar</exists>
              </file>
          </activation>
          <properties>
              <jdkToolsJar>${java.home}/../lib/tools.jar</jdkToolsJar>
          </properties>
      </profile>

      <profile>
          <id>osx_jdk</id>
          <activation>
              <file>
                  <exists>${java.home}/../Classes/classes.jar</exists>
              </file>
          </activation>
          <properties>
              <jdkToolsJar>${java.home}/../Classes/classes.jar</jdkToolsJar>
          </properties>
      </profile>

      <profile>
         <id>integration-tests</id>
         <activation>
            <property>
               <name>maven.test.skip</name>
               <value>!true</value>
            </property>
         </activation>

         <build>
            <plugins>

         <!-- Integration testing voodoo to load and test this plugin with its plugin dependencies -->
         <plugin>
           <artifactId>maven-surefire-plugin</artifactId>
           <configuration>
             <skip>true</skip>
             <properties>
               <property>
                 <name>listener</name>
                 <value>org.rhq.test.testng.StdoutReporter</value>
               </property>
             </properties>
           </configuration>
            <executions>
               <execution>
                  <id>surefire-it</id>
                  <phase>integration-test</phase>
                  <goals>
                     <goal>test</goal>
                  </goals>
                  <configuration>
                     <skip>${maven.test.skip}</skip>
                     <excludedGroups>${rhq.testng.excludedGroups}</excludedGroups>
                     <useSystemClassLoader>true</useSystemClassLoader>
                     <argLine>${jacoco.integration-test.args} -Dorg.hyperic.sigar.path=${basedir}/target/itest/lib</argLine>
                     <!--<argLine>${jacoco.integration-test.args} -Dorg.hyperic.sigar.path=${basedir}/target/itest/lib -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</argLine>-->
                     <systemProperties>
                        <property>
                           <name>project.artifactId</name>
                           <value>${project.artifactId}</value>
                        </property>
                        <property>
                           <name>project.version</name>
                           <value>${rhq-jmx-plugin.version}</value>
                        </property>
                        <property>
                          <name>rhq.jmxplugin.as7.standalone.management.port</name>
                          <value>${rhq.jmxplugin.as7.standalone.management.port}</value>
                        </property>
                        <property>
                          <name>rhq.jmxplugin.as7.standalone.home</name>
                          <value>${rhq.jmxplugin.as7.standalone.home}</value>
                        </property>
                        <property>
                          <name>rhq.jmxplugin.wildfly8.standalone.management.port</name>
                          <value>${rhq.jmxplugin.wildfly8.standalone.management.port}</value>
                        </property>
                        <property>
                          <name>rhq.jmxplugin.wildfly8.standalone.home</name>
                          <value>${rhq.jmxplugin.wildfly8.standalone.home}</value>
                        </property>
                     </systemProperties>
                  </configuration>
               </execution>
            </executions>
         </plugin>

              <plugin>
                <groupId>org.jboss.as.plugins</groupId>
                <artifactId>jboss-as-maven-plugin</artifactId>
                <version>7.5.Final</version>
                <configuration>
                  <artifact>${rhq.jmxplugin.as7.artifact}</artifact>
                  <jvmArgs>
                    -Xms64m -Xmx128m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true
                    -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000
                    -Dsun.rmi.dgc.server.gcInterval=3600000
                    -Djboss.socket.binding.port-offset=${rhq.jmxplugin.as7.standalone.portOffset}
                  </jvmArgs>
                  <port>${rhq.jmxplugin.as7.standalone.management.port}</port>
                </configuration>
                <executions>
                  <execution>
                    <id>start-as7-pre-integration-test</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                      <goal>start</goal>
                    </goals>
                  </execution>
                  <execution>
                    <id>shutdown-as7-post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                      <goal>shutdown</goal>
                    </goals>
                  </execution>
                </executions>
              </plugin>

              <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.2.Final</version>
                <configuration>
                  <artifact>${rhq.jmxplugin.wildfly8.artifact}</artifact>
                  <jvmArgs>
                    -Xms64m -Xmx128m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true
                    -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000
                    -Djboss.socket.binding.port-offset=${rhq.jmxplugin.wildfly8.standalone.portOffset}
                  </jvmArgs>
                  <port>${rhq.jmxplugin.wildfly8.standalone.management.port}</port>
                </configuration>
                <executions>
                  <execution>
                    <id>start-wfly8-pre-integration-test</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                      <goal>start</goal>
                    </goals>
                  </execution>
                  <execution>
                    <id>shutdown-wfly8-post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                      <goal>shutdown</goal>
                    </goals>
                  </execution>
                </executions>
              </plugin>

         <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
               <execution>
                  <phase>pre-integration-test</phase>
                  <configuration>
                     <target>
                        <echo>Setting up plugin dependencies for ${project.artifactId}-${rhq-jmx-plugin.version}.jar...</echo>
                        <property name="settings.localRepository" location="${user.home}/.m2/repository" />
                        <mkdir dir="target/itest" />
                        <mkdir dir="target/itest/plugins" />
                        <mkdir dir="target/itest/lib" />
                        <copy toDir="target/itest/plugins" flatten="true" verbose="true">
                           <fileset dir="${settings.localRepository}/">
                              <include name="org/rhq/rhq-platform-plugin/${rhq-platform-plugin.version}/rhq-platform-plugin-${rhq-platform-plugin.version}.jar" />
                           </fileset>
                           <fileset dir="${project.build.directory}">
                              <include name="${project.artifactId}-${rhq-jmx-plugin.version}.jar" />
                           </fileset>
                        </copy>
                        <unzip dest="target/itest/lib">
                           <fileset dir="${settings.localRepository}/org/hyperic/sigar-dist/${sigar.version}" includes="*.zip" />
                           <patternset>
                              <include name="**/lib/sigar.jar" />
                              <include name="**/lib/bcel*.jar" />
                              <include name="**/lib/*.so" />
                              <include name="**/lib/*.sl" />
                              <include name="**/lib/*.dll" />
                              <include name="**/lib/*.dylib" />
                           </patternset>
                        </unzip>
                        <move todir="target/itest/lib" flatten="true">
                           <fileset dir="target/itest/lib">
                              <include name="**/lib/*" />
                           </fileset>
                        </move>
                        <delete dir="target/itest/lib/hyperic-sigar-${sigar.version}" />
                     </target>
                  </configuration>
                  <goals>
                     <goal>run</goal>
                  </goals>
               </execution>
               <execution>
                 <id>install-as7-mgmt-user-pre-integration-test</id>
                 <phase>pre-integration-test</phase>
                 <configuration>
                   <tasks>
                     <ant antfile="add-user.xml"/>
                   </tasks>
                 </configuration>
                 <goals>
                   <goal>run</goal>
                 </goals>
               </execution>
            </executions>
         </plugin>

      </plugins>
   </build>
 </profile>

      <profile>
         <id>dev</id>

         <properties>
            <rhq.rootDir>../../..</rhq.rootDir>
            <rhq.containerDir>${rhq.rootDir}/${rhq.devContainerServerPath}</rhq.containerDir>
            <rhq.deploymentDir>${rhq.containerDir}/${rhq.agentPluginDir}</rhq.deploymentDir>
         </properties>

         <build>
            <plugins>

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

                     <execution>
                        <id>deploy</id>
                        <phase>compile</phase>
                        <configuration>
                          <target>
                            <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}" />
                          </target>
                        </configuration>
                        <goals>
                          <goal>run</goal>
                        </goals>
                     </execution>

                     <execution>
                        <id>deploy-jar-meta-inf</id>
                        <phase>package</phase>
                        <configuration>
                          <target>
                             <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>
                          </target>
                        </configuration>
                        <goals>
                          <goal>run</goal>
                        </goals>
                     </execution>

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

                   </executions>
               </plugin>

            </plugins>
         </build>
      </profile>
   </profiles>
</project>
