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

  <groupId>org.rhq</groupId>
  <artifactId>rhq-enterprise-server-container</artifactId>
  <packaging>pom</packaging>

  <name>RHQ Enterprise Server Container</name>
  <description>The full RHQ container build, including the JBossAS server and all config/deploy files</description>

  <properties>
    <!-- dependency versions -->
    <jboss-faces.version>4.2.3.GA</jboss-faces.version>
    <rhq.webappsReloadable>false</rhq.webappsReloadable>
  </properties>

  <dependencies>

    <!-- Internal Deps -->

    <dependency>
      <groupId>org.rhq</groupId>
      <artifactId>safe-invoker</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.rhq</groupId>
      <artifactId>rhq-container-lib</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- 3rd Party Deps -->

    <dependency>
      <groupId>javax.faces</groupId>
      <artifactId>jsf-api</artifactId>
      <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
    </dependency>

    <dependency>
      <groupId>javax.faces</groupId>
      <artifactId>jsf-impl</artifactId>
      <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
    </dependency>

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

    <dependency>
      <groupId>jgroups</groupId>
      <artifactId>jgroups-all</artifactId>
      <version>2.2.9.1</version>
    </dependency>

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

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

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

    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>net.sourceforge.jtds</groupId>
      <artifactId>jtds</artifactId>
      <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
      <scope>test</scope>
    </dependency>

    <dependency>
	  <groupId>org.jboss.jbossws</groupId>
	  <artifactId>jbossws-native-dist</artifactId>
	  <type>zip</type>
      <!-- NOTE: The version is defined in the root POM's dependencyManagement section. -->
    </dependency>
    <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7.3</version>
     </dependency>

  </dependencies>

  <build>
    <finalName>rhq-server-${project.version}</finalName>
    <outputDirectory>target/${project.build.finalName}</outputDirectory>

    <resources>

      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>

      <resource>
        <directory>src/main/bin-resources</directory>
        <filtering>false</filtering>
      </resource>

    </resources>

    <plugins>

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>move-src</id>
            <phase>process-resources</phase>
            <goals>
              <goal>resources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

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

          <execution>
            <id>prepare-container</id>
            <phase>generate-resources</phase>
            <configuration>
              <target>
                <echo>settings.localRepository=${settings.localRepository}</echo>
                <echo>project.build.outputDirectory=${project.build.outputDirectory}</echo>
                <ant antfile="src/main/scripts/rhq-container.build.xml" target="prepare-container">
                  <property name="settings.localRepository" value="${settings.localRepository}" />
                  <property name="project.build.outputDirectory" value="${project.build.outputDirectory}" />
                  <property name="project.version" value="${project.version}" />
                  <property name="dev.profile.active" value="${dev.profile.active}" />
                  <property name="developer" value="${developer}" />
                  <property name="rhq.earName" value="${rhq.earName}" />

                  <!-- dependency versions -->
                  <property name="rhq.version" value="${project.version}" />
                  <property name="jboss.version" value="${jboss.version}" />
                  <property name="ojdbc6.version" value="${ojdbc6.version}" />
                  <property name="postgresql.version" value="${postgresql.version}" />
                  <property name="h2.version" value="${h2.version}" />
                  <property name="jboss-javassist.version" value="${jboss-javassist.version}" />
                  <property name="jtds.version" value="${jtds.version}" />
                  <property name="jsf-api.version" value="${jsf-api.version}" />
                  <property name="jsf-impl.version" value="${jsf-impl.version}" />
                  <property name="hibernate3.version" value="${hibernate3.version}" />
                  <property name="quartz.version" value="${quartz.version}" />
                  <property name="xercesImpl.version" value="${xercesImpl.version}" />

                  <!-- dev DB settings (used to init rhq-server.properties if dev profile is active or developer prop is set) -->
                  <property name="rhq.dev.ds.connection-url" value="${rhq.dev.ds.connection-url}" />
                  <property name="rhq.dev.ds.driver-class" value="${rhq.dev.ds.driver-class}" />
                  <property name="rhq.dev.ds.xa-datasource-class" value="${rhq.dev.ds.xa-datasource-class}" />
                  <property name="rhq.dev.ds.user-name" value="${rhq.dev.ds.user-name}" />
                  <property name="rhq.dev.ds.password.encrypted" value="${rhq.dev.ds.password.encrypted}" />
                  <property name="rhq.dev.ds.type-mapping" value="${rhq.dev.ds.type-mapping}" />
                  <property name="rhq.dev.ds.server-name" value="${rhq.dev.ds.server-name}" />
                  <property name="rhq.dev.ds.port" value="${rhq.dev.ds.port}" />
                  <property name="rhq.dev.ds.db-name" value="${rhq.dev.ds.db-name}" />
                  <property name="rhq.dev.ds.hibernate-dialect" value="${rhq.dev.ds.hibernate-dialect}" />
                  <property name="rhq.dev.quartz.driverDelegateClass" value="${rhq.dev.quartz.driverDelegateClass}" />
                  <property name="rhq.dev.quartz.selectWithLockSQL" value="${rhq.dev.quartz.selectWithLockSQL}" />
                  <property name="rhq.dev.quartz.lockHandlerClass" value="${rhq.dev.quartz.lockHandlerClass}" />

                  <!-- default server settings used by installer -->
                  <property name="rhq.server.http.port" value="${rhq.server.http.port}" />
                  <property name="rhq.server.https.port" value="${rhq.server.https.port}" />

                  <property name="rhq.server.enable.ws" value="${rhq.server.enable.ws}" />
                  <property name="jbossws-native-dist.version" value="${jbossws-native-dist.version}" />

                  <property name="rhq.sync.endpoint-address" value="${rhq.sync.endpoint-address}" />
                </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>

          <execution>
            <id>prepare-release</id>
            <phase>prepare-package</phase>
            <configuration>
              <target>
                <echo>Preparing the release at ${project.build.outputDirectory}...</echo>
                <ant antfile="src/main/scripts/rhq-container.build.xml" target="prepare-release">
                  <property name="project.build.outputDirectory" value="${project.build.outputDirectory}" />

                  <!-- the 'dev.profile.active' prop is set to true by the root POM if the dev profile is active; -->
                  <!-- if 'dev.profile.active' != "true", the container will be made packageable -->
                  <!-- (i.e. running the installer first will be required); -->
                  <!-- if 'dev.profile.active' == "true", the ear, datasource and JMS backend will be predeployed; -->
                  <!-- developers will normally want to do this to avoid having to run the installer -->
                  <!-- [mazz] added the ability to say -Ddeveloper to also predeploy, even if not in dev profile -->
                  <property name="dev.profile.active" value="${dev.profile.active}" />
                  <property name="developer" value="${developer}" />
                  <property name="rhq.earName" value="${rhq.earName}" />

                  <!-- dev/test DB type (needed to init rhq-ds.xml) -->
                  <property name="rhq.test.ds.type-mapping" value="${rhq.test.ds.type-mapping}" />
                  <property name="rhq.dev.ds.type-mapping" value="${rhq.dev.ds.type-mapping}" />
                  <property name="rhq.server.enable.web.services" value="${rhq.server.enable.ws}" />
                </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>

        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archiverConfig>
            <!-- permissions for archiver configuration are in decimal (not octal) -->
            <!-- 493 (decimal) = 755 (octal)-->
            <defaultDirectoryMode>493</defaultDirectoryMode>
          </archiverConfig>
          <descriptors>
            <descriptor>src/main/scripts/rhq-container.assembly.xml</descriptor>
          </descriptors>
          <finalName>${project.build.finalName}</finalName>
        </configuration>
        <executions>
          <execution>
            <id>assemble-server-container-zip</id>
            <phase>package</phase>
            <goals>
              <goal>attached</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!--
      We skip the API checking in this module, because there is no new
      code to check. This module merely composes classes from other modules
      which have already been checked.
      Also, enabling the API checks in this module causes some weird problems
      for the animal sniffer, because it most probably cannot figure out
      the full set of dependencies for classes of the web apps contained in the
      EAR were creating here.
      -->
      <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>animal-sniffer-maven-plugin</artifactId>
          <configuration>
              <skip>true</skip>
          </configuration>
        </plugin>
    </plugins>
  </build>

   <profiles>

      <profile>
         <id>dev</id>

         <properties>
            <rhq.rootDir>../../../..</rhq.rootDir>
            <rhq.containerDir>${rhq.rootDir}/${rhq.defaultDevContainerPath}</rhq.containerDir>

            <rhq.webappsReloadable>true</rhq.webappsReloadable>
         </properties>

         <build>
            <plugins>

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

                     <execution>
                        <id>deploy</id>
                        <phase>package</phase>
                        <configuration>
                          <target>
                            <property name="deployment.dir" location="${rhq.containerDir}" />
                            <echo>*** Copying updated files from target${file.separator}${project.build.finalName}${file.separator} to ${deployment.dir}${file.separator}...</echo>
                            <copy todir="${deployment.dir}" verbose="${rhq.verbose}">
                               <fileset dir="${basedir}/target/${project.build.finalName}" />
                            </copy>
                            <!-- Make sure shell scripts are readable and executable. -->
                            <chmod perm="ug+x" verbose="true">
                               <fileset dir="${deployment.dir}/bin" includes="*.sh" />
                               <fileset dir="${deployment.dir}/jbossas/bin" includes="*.sh" />
                            </chmod>
                          </target>
                        </configuration>
                        <goals>
                          <goal>run</goal>
                        </goals>
                     </execution>

                     <execution>
                        <id>undeploy</id>
                        <phase>clean</phase>
                        <configuration>
                          <target>
                            <property name="deployment.dir" location="${rhq.containerDir}" />
                            <echo>*** Deleting ${deployment.dir}${file.separator}...</echo>
                            <delete dir="${deployment.dir}" />
                          </target>
                        </configuration>
                        <goals>
                          <goal>run</goal>
                        </goals>
                     </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>1.9.4.1</version>
               </dependency>
             </dependencies>
             <executions>
              <execution>
               <id>cobertura-merge</id>
               <phase>pre-integration-test</phase>
                 <configuration>
                   <target>
                   <!-- prepare directory structure for cobertura-->
                   <mkdir dir="target/cobertura" />
                   <taskdef classpathref="maven.plugin.classpath" resource="tasks.properties" />
                   <!-- instrument all classes in target/classes directory -->
                   <cobertura-merge datafile="${project.build.directory}/cobertura/cobertura.ser">
                     <fileset dir="../../../../">
                        <include name="**/cobertura.ser" />
                      </fileset>
                    </cobertura-merge>
                  </target>
                 </configuration>
               <goals>
                 <goal>run</goal>
               </goals>
              </execution>
            </executions>
           </plugin>
           <plugin>
           <groupId>org.codehaus.groovy.maven</groupId>
           <artifactId>gmaven-plugin</artifactId>
           <executions>
             <execution>
              <phase>post-integration-test</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                import java.util.regex.Pattern
                import java.util.regex.Matcher

                def repClos
                def list = new ArrayList()

                Pattern sourceCodeFolder = Pattern.compile(".*/src/main/java")
                Pattern sourceCodeFile = Pattern.compile('.*/src/main/java/(.*.java)')

                list.add("--format")
                list.add("xml")
                list.add("--datafile")
                list.add("${project.build.directory}/cobertura/cobertura.ser")
                list.add("--destination")
                list.add("${project.build.directory}/site/cobertura")

                repClosFile = {
                  Matcher matcher = sourceCodeFile.matcher(it.canonicalPath)
                   if (matcher.matches()){
                      list.add(matcher[0][1])
                      }

                    if (it.isDirectory()){
                      it.eachFile(repClosFile)
                    }
                 }

                repClosDir = {
                   Matcher matcher = sourceCodeFolder.matcher(it.canonicalPath)
                   if (matcher.matches()){
                      list.add("--basedir")
                      list.add(it.canonicalPath)
                      it.eachFile(repClosFile)
                      }
                   it.eachDir(repClosDir);
                 }

                def ear = new File("${project.build.directory}/../../../../")
                repClosDir(ear)

                net.sourceforge.cobertura.reporting.Main.main((String[]) list)
                </source>
               </configuration>
              </execution>
             </executions>
           </plugin>
          </plugins>
       </build>
     </profile>
  </profiles>

</project>

