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

  <groupId>org.rhq</groupId>
  <artifactId>rhq-netservices-plugin</artifactId>
  <packaging>jar</packaging>

  <name>RHQ Network Services Plugin</name>
  <description>A plugin for monitoring network services.</description>

  <dependencies>

    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>${apache.httpcomponents.version}</version>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-codec</groupId>
          <artifactId>commons-codec</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>commons-codec</groupId>
      <artifactId>commons-codec</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpmime</artifactId>
      <version>${apache.httpcomponents.version}</version>
    </dependency>

    <!-- Test dependencies -->

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

    <dependency>
      <groupId>org.eclipse.jetty.aggregate</groupId>
      <artifactId>jetty-all</artifactId>
      <version>8.1.8.v20121106</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>
    <plugins>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>org/rhq/plugins/netservices/itest/**</exclude>
          </excludes>
          <properties>
            <property>
              <name>listener</name>
              <value>org.rhq.test.testng.StdoutReporter</value>
            </property>
          </properties>
          <useSystemClassLoader>false</useSystemClassLoader>
          <argLine>${jacoco.unit-test.args}</argLine>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>pre-integration-test</phase>
            <configuration>
              <target>
                <echo>Setting up itest plugin container...</echo>
                <property name="settings.localRepository" location="${user.home}/.m2/repository" />
                <mkdir dir="target/itest/plugins" />
                <copy toDir="target/itest/plugins" flatten="true" verbose="true">
                  <fileset dir="${settings.localRepository}/">
                    <include name="org/rhq/rhq-platform-plugin/${project.version}/rhq-platform-plugin-${project.version}.jar" />
                  </fileset>
                  <fileset dir="${project.build.directory}">
                    <include name="${project.artifactId}-${project.version}.jar" />
                  </fileset>
                </copy>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <includes>
            <!-- only include integration tests; normal unit tests are handled above by surefire plugin -->
            <include>org/rhq/plugins/netservices/itest/**/*Test.java</include>
          </includes>
          <properties>
            <property>
              <name>listener</name>
              <value>org.rhq.test.testng.StdoutReporter</value>
            </property>
          </properties>
          <useSystemClassLoader>false</useSystemClassLoader>
          <argLine>${jacoco.integration-test.args}</argLine>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependency-jars</id>
            <phase>process-resources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>org.apache.httpcomponents</groupId>
                  <artifactId>httpcore</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.httpcomponents</groupId>
                  <artifactId>httpclient</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>org.apache.httpcomponents</groupId>
                  <artifactId>httpmime</artifactId>
                </artifactItem>
                <artifactItem>
                  <groupId>commons-codec</groupId>
                  <artifactId>commons-codec</artifactId>
                </artifactItem>
              </artifactItems>
              <outputDirectory>${project.build.outputDirectory}/lib</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

  <profiles>

    <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>
