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

  <groupId>org.rhq</groupId>
  <artifactId>rhq-cassandra-plugin</artifactId>
  <name>RHQ Cassandra Plugin</name>
  <description>An RHQ plugin for monitoring and managing a Cassandra cluster</description>

  <dependencies>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>rhq-core-domain</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>rhq-core-plugin-api</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>rhq-core-native-system</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>rhq-jmx-plugin</artifactId>
      <version>${project.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.apache.cassandra</groupId>
      <artifactId>cassandra-all</artifactId>
      <version>1.1.5</version>
    </dependency>
    <dependency>
      <groupId>org.apache.thrift</groupId>
      <artifactId>libthrift</artifactId>
      <version>0.7.0</version>
    </dependency>
    <dependency>
      <groupId>org.hectorclient</groupId>
      <artifactId>hector-core</artifactId>
      <version>1.1-1</version>
    </dependency>
    <dependency>
      <groupId>org.yaml</groupId>
      <artifactId>snakeyaml</artifactId>
      <version>1.10</version>
    </dependency>
    <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>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-libs</id>
            <phase>package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>
              <artifactItems>
                <artifactItem>
                  <groupId>org.hectorclient</groupId>
                  <artifactId>hector-core</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.cassandra</groupId>
                  <artifactId>cassandra-all</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.thrift</groupId>
                  <artifactId>libthrift</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>org.yaml</groupId>
                  <artifactId>snakeyaml</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-api</artifactId>
                  <version>1.6.0</version>
                </artifactItem>
                <artifactItem>
                  <groupId>org.slf4j</groupId>
                  <artifactId>slf4j-log4j12</artifactId>
                  <version>1.6.0</version>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.cassandra</groupId>
                  <artifactId>cassandra-thrift</artifactId>
                  <version>1.1.5</version>
                </artifactItem>
                <artifactItem>
                  <groupId>com.google.guava</groupId>
                  <artifactId>guava</artifactId>
                  <version>12.0</version>
                </artifactItem>
                <artifactItem>
                  <groupId>commons-pool</groupId>
                  <artifactId>commons-pool</artifactId>
                  <version>1.6</version>
                </artifactItem>
                <artifactItem>
                  <groupId>commons-lang</groupId>
                  <artifactId>commons-lang</artifactId>
                  <version>2.3</version>
                </artifactItem>
                <artifactItem>
                  <groupId>com.github.stephenc.eaio-uuid</groupId>
                  <artifactId>uuid</artifactId>
                  <version>3.2.0</version>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>pre-integration-test</phase>
            <configuration>
               <target>
                  <echo>Setting up plugin dependencies...</echo>
                  <property name="settings.localRepository" location="${user.home}/.m2/repository" />
                  <mkdir dir="target/testsetup" />

                  <mkdir dir="target/testsetup/plugins" />
                  <copy toDir="target/testsetup/plugins" flatten="true">
                     <fileset dir="${settings.localRepository}/">
                        <include name="org/rhq/rhq-jmx-plugin/${project.version}/rhq-jmx-plugin-${project.version}.jar" />
                     </fileset>
                     <fileset dir="${project.build.directory}" includes="${project.artifactId}-${project.version}.jar" />
                  </copy>

                  <mkdir dir="target/testsetup/lib" />
                  <unzip dest="target/testsetup/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/testsetup/lib" flatten="true">
                     <fileset dir="target/testsetup/lib">
                        <include name="**/lib/*" />
                     </fileset>
                  </move>
                  <delete dir="target/testsetup/lib/hyperic-sigar-${sigar.version}" />
               </target>
            </configuration>
            <goals>
               <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

       <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
           <skip>true</skip>
        </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>false</useSystemClassLoader>
                 <argLine>-Dorg.hyperic.sigar.path=${basedir}/target/testsetup/lib</argLine>
                 <systemProperties>
                    <property>
                       <name>project.artifactId</name>
                       <value>${project.artifactId}</value>
                    </property>
                    <property>
                       <name>project.version</name>
                       <value>${project.version}</value>
                    </property>
                 </systemProperties>
              </configuration>
           </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>dev</id>

      <properties>
        <rhq.rootDir>../../..</rhq.rootDir>
        <rhq.containerDir>${rhq.rootDir}/${rhq.defaultDevContainerPath}</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>package</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>
