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

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

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

    <dependencies>

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

        <!-- 3rd Party Deps -->

        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <!-- NOTE: version defined in root pom dependencyManagement section -->
        </dependency>

        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <!-- NOTE: version defined in root pom dependencyManagement section -->
        </dependency>

        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-dist</artifactId>
            <!-- NOTE: version defined in root pom dependencyManagement section -->
            <type>zip</type>
        </dependency>

        <dependency>
            <groupId>org.opensymphony.quartz</groupId>
            <artifactId>quartz</artifactId>
            <!-- NOTE: version defined in root pom dependencyManagement section -->
        </dependency>

        <dependency>
            <groupId>org.opensymphony.quartz</groupId>
            <artifactId>quartz-oracle</artifactId>
            <!-- NOTE: version defined in root pom dependencyManagement section -->
        </dependency>

        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <!-- NOTE: version defined in root pom dependencyManagement section -->
        </dependency>

        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
        </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="jboss.eap.version"             value="${jboss.eap.version}"/>
                                    <property name="jboss.zip"                     location="${settings.localRepository}/org/jboss/as/jboss-as-dist/${jboss.version}/jboss-as-dist-${jboss.version}.zip" />
                                    <property name="ojdbc6.version"                value="${ojdbc6.version}" />
                                    <property name="postgresql.version"            value="${postgresql.version}" />
                                    <property name="jboss-javassist.version"       value="${javassist.version}" />
                                    <property name="jsf-api.version"               value="${jsf-api.version}" />
                                    <property name="jsf-impl.version"              value="${jsf-impl.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.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.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 (TODO: do we still need this?) -->
                                    <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}" />
                                </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>
            </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>

    </profiles>

</project>

