<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>rhq-helpers</artifactId>
        <groupId>org.rhq.helpers</groupId>
        <version>4.2.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.rhq.helpers</groupId>
    <artifactId>bundleGen</artifactId>
    <version>4.2.0</version>

    <build>
     <plugins>

         <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>2.2</version>
         <configuration>
           <archive>
             <manifest>
               <mainClass>org.rhq.helpers.bundleGen.BundleGen</mainClass>
               <packageName>org.rhq.helpers.bundleGen</packageName>
             </manifest>
           </archive>
         </configuration>
       </plugin>

       <plugin>
         <artifactId>maven-assembly-plugin</artifactId>
         <configuration>
           <descriptorRefs>
             <descriptorRef>jar-with-dependencies</descriptorRef>
           </descriptorRefs>
           <archive>
             <manifest>
               <mainClass>org.rhq.helpers.bundleGen.BundleGen</mainClass>
             </manifest>
           </archive>
         </configuration>
         <executions>
           <execution>
             <id>make-assembly</id>     <!-- this is used for inheritance merges -->
             <phase>package</phase>     <!-- append to the packaging phase. -->
             <goals>
               <goal>attached</goal>  <!-- goals == mojos -->
             </goals>
           </execution>
         </executions>
       </plugin>
     </plugins>

     </build>

     <dependencies>
         <dependency>
             <groupId>commons-logging</groupId>
             <artifactId>commons-logging</artifactId>
             <version>${commons-logging.version}</version>
         </dependency>

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

  <profiles>
     <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>pre-integration-test</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>post-integration-test</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>
</project>