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

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.rhq</groupId>
        <artifactId>rhq-parent</artifactId>
        <version>4.12.0</version>
        <relativePath>../../../../pom.xml</relativePath>
    </parent>

    <artifactId>server-startup</artifactId>

    <name>RHQ Server Startup AS7 Subsystem</name>

    <properties>
        <!-- this is used to replace the variable in module.xml -->
        <moduleName>${project.groupId}.${project.artifactId}</moduleName>
        <moduleDir>org/rhq/${project.artifactId}</moduleDir>
    </properties>

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

        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-ear</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.rhq</groupId>
                                    <artifactId>rhq-enterprise-server-ear</artifactId>
                                    <type>ear</type>
                                    <outputDirectory>${project.build.directory}/deployments/${rhq.earName}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/scripts/module-assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>module-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.jboss.modules</groupId>
            <artifactId>jboss-modules</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-controller</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-server</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-ejb3</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>staxmapper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-ee</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- our startup subsystem will be deploying this -->
        <dependency>
            <groupId>org.rhq</groupId>
            <artifactId>rhq-enterprise-server-ear</artifactId>
            <version>${project.version}</version>
            <type>ear</type>
            <scope>provided</scope>
        </dependency>

        <!-- test deps -->
        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-subsystem-test-framework</artifactId>
            <version>${jboss.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

            <properties>
                <rhq.rootDir>../../../..</rhq.rootDir>
                <rhq.containerDir>${rhq.rootDir}/${rhq.devContainerServerPath}</rhq.containerDir>
                <rhq.deploymentName>${project.build.finalName}.zip</rhq.deploymentName>
                <rhq.deploymentDir>${rhq.containerDir}/modules/</rhq.deploymentDir>
            </properties>

            <build>
                <plugins>

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

                            <execution>
                                <id>deploy</id>
                                <phase>package</phase>
                                <configuration>
                                    <target>
                                        <echo>*** Deploying main EAR startup module to ${rhq.deploymentDir}</echo>
                                        <unzip src="target/${rhq.deploymentName}"
                                               dest="${rhq.deploymentDir}"/>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>

                            <execution>
                                <id>undeploy</id>
                                <phase>clean</phase>
                                <configuration>
                                    <target>
                                        <echo>*** Deleting main EAR startup module... ${rhq.deploymentDir}/${moduleDir}</echo>
                                        <delete dir="${rhq.deploymentDir}/${moduleDir}" />
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>

                        </executions>
                    </plugin>

                </plugins>
            </build>
        </profile>
    </profiles>

</project>
