<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-parent</artifactId>
    <version>4.2.0</version>
    <relativePath>../../../pom.xml</relativePath>
  </parent>

  <groupId>org.rhq</groupId>
  <artifactId>rhq-core-native-system</artifactId>
  <packaging>jar</packaging>

  <name>RHQ Native System API</name>
  <description>
     Java API that wraps the native library used to access low-level system resources natively.
  </description>

  <scm>
    <connection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/core/native-system</connection>
    <developerConnection>scm:git:ssh://git.fedorahosted.org/git/rhq.git/modules/core/native-system</developerConnection>
  </scm>

  <properties>
    <scm.module.path>modules/core/native-system/</scm.module.path>
  </properties>

  <dependencies>

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

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

    <dependency>
      <groupId>org.hyperic</groupId>
      <artifactId>sigar-dist</artifactId>
      <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
      <type>zip</type>
    </dependency>
  </dependencies>

  <build>
    <plugins>

      <!-- need to copy/unzip the native libraries to the target directory and tell SystemInfoFactory where they are -->
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-test-resources</phase>
            <configuration>
              <tasks>
                 <echo>SIGAR Java library version used is ${sigar.version}.</echo>
                 <echo>Copying/unzipping SIGAR native libraries (version ${sigar.version}) to local build directory...</echo>
                 <mkdir dir="${project.build.directory}/jboss-sigar" />
                 <copy toDir="${project.build.directory}/jboss-sigar">
                    <fileset dir="${settings.localRepository}/org/hyperic/sigar-dist/${sigar.version}" includes="*.zip" />
                 </copy>
                 <unzip dest="${project.build.directory}/jboss-sigar">
                    <fileset dir="${project.build.directory}/jboss-sigar" 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="${project.build.directory}/jboss-sigar" flatten="true">
                    <fileset dir="${project.build.directory}/jboss-sigar">
                       <include name="**/lib/*" />
                    </fileset>
                 </move>
                 <delete dir="${project.build.directory}/jboss-sigar/hyperic-sigar-${sigar.version}" />
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <excludedGroups>${rhq.testng.excludedGroups}</excludedGroups>
          <!-- need to point the library path to the location of the native libraries -->
          <argLine>-Dorg.hyperic.sigar.path=${project.build.directory}/jboss-sigar</argLine>
          <!--
          <argLine>-Dorg.hyperic.sigar.path=${project.build.directory}/jboss-sigar -Dsigar.nativeLogging=true -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y</argLine>
           -->
        </configuration>
      </plugin>

       <plugin>
          <artifactId>maven-javadoc-plugin</artifactId>

          <executions>
             <execution>
                <id>system-api</id>
                <phase>compile</phase>
                <goals>
                   <goal>javadoc</goal>
                </goals>
                <configuration>
                   <doctitle>RHQ ${project.version} System API</doctitle>
                   <reportOutputDirectory>${javadoc.outputDirectory}</reportOutputDirectory>
                   <author>false</author>
                   <breakiterator>true</breakiterator>
                </configuration>
             </execution>
          </executions>
       </plugin>

    </plugins>
  </build>

  <profiles>

      <profile>
         <id>javadoc</id>
         <activation>
            <property>
               <name>javadoc.outputDirectory</name>
            </property>
         </activation>

         <build>
            <plugins>

               <plugin>
                  <artifactId>maven-javadoc-plugin</artifactId>

                  <executions>
                     <execution>
                        <id>system-api</id>
                        <phase>compile</phase>
                        <goals>
                           <goal>javadoc</goal>
                        </goals>
                        <configuration>
                           <doctitle>RHQ ${project.version} System API</doctitle>
                           <windowtitle>RHQ ${project.version} System API</windowtitle>
                           <reportOutputDirectory>${javadoc.outputDirectory}</reportOutputDirectory>
                           <destDir>system</destDir>
                           <author>false</author>
                           <breakiterator>true</breakiterator>
                        </configuration>
                     </execution>
                  </executions>
               </plugin>
            </plugins>
         </build>
      </profile>

    <profile>
      <id>cobertura</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
        <build>
         <plugins>
           <plugin>
             <artifactId>maven-antrun-plugin</artifactId>
              <dependencies>
               <dependency>
                 <groupId>net.sourceforge.cobertura</groupId>
                 <artifactId>cobertura</artifactId>
                 <version>${cobertura.version}</version>
               </dependency>
             </dependencies>
             <executions>
              <execution>
               <id>cobertura-instrument</id>
               <phase>process-test-classes</phase>
                 <configuration>
                   <tasks>
                   <!-- prepare directory structure for cobertura-->
                   <mkdir dir="target/cobertura" />
                   <mkdir dir="target/cobertura/backup" />
                   <!-- backup all classes so that we can instrument the original classes-->
                   <copy toDir="target/cobertura/backup" verbose="true" overwrite="true">
                      <fileset dir="target/classes">
                         <include name="**/*.class" />
                      </fileset>
                   </copy>
                   <!-- create a properties file and save there location of cobertura data file-->
                   <touch file="target/classes/cobertura.properties" />
                   <echo file="target/classes/cobertura.properties">net.sourceforge.cobertura.datafile=${project.build.directory}/cobertura/cobertura.ser</echo>

                   <taskdef classpathref="maven.plugin.classpath" resource="tasks.properties" />
                   <!-- instrument all classes in target/classes directory -->
                   <cobertura-instrument datafile="${project.build.directory}/cobertura/cobertura.ser" todir="${project.build.directory}/classes">
                     <fileset dir="${project.build.directory}/classes">
                        <include name="**/*.class" />
                      </fileset>
                    </cobertura-instrument>
                   </tasks>
                 </configuration>
               <goals>
                 <goal>run</goal>
               </goals>
              </execution>
              <execution>
               <id>cobertura-report</id>
               <phase>prepare-package</phase>
                 <configuration>
                   <tasks>
                     <taskdef classpathref="maven.plugin.classpath" resource="tasks.properties" />
                     <!-- prepare directory structure for cobertura-->
                     <mkdir dir="target/cobertura" />
                     <mkdir dir="target/site/cobertura" />
                     <!-- restore classes from backup folder to classes folder -->
                     <copy toDir="target/classes" verbose="true" overwrite="true">
                      <fileset dir="target/cobertura/backup">
                         <include name="**/*.class" />
                      </fileset>
                     </copy>
                     <!-- delete backup folder-->
                     <delete dir="target/cobertura/backup" />
                     <!-- create a code coverage report -->
                     <cobertura-report format="html" datafile="${project.build.directory}/cobertura/cobertura.ser" destdir="${project.build.directory}/site/cobertura">
                      <fileset dir="${basedir}/src/main/java">
                         <include name="**/*.java" />
                      </fileset>
                     </cobertura-report>
                     <!-- delete cobertura.properties file -->
                     <delete file="target/classes/cobertura.properties" />
                   </tasks>
                 </configuration>
               <goals>
                 <goal>run</goal>
               </goals>
               </execution>
            </executions>
           </plugin>
          </plugins>
       </build>
     </profile>
  </profiles>
  <repositories>
     <!-- This is for SIGAR 1.6.4. -->
     <repository>
          <id>jboss-thirdparty-uploads</id>
          <name>JBoss Third Party Uploads</name>
          <url>https://repository.jboss.org/nexus/content/repositories/thirdparty-uploads/</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
     </repository>
  </repositories>

</project>

