<?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>com.rackspace.papi.core</groupId>
        <artifactId>core-support</artifactId>
        <version>1.2.1</version>
    </parent>

    <groupId>com.rackspace.papi.core</groupId>
    <artifactId>web-application</artifactId>

    <name>Power API Core - Root Web Application</name>
    
    <description>
        This is the ROOT.war application project for Power API. This is a simple
        integration artifact that allows a client to let an application container
        deploy this application and therefore host and start Power API. This model
        is essential for existing Java API projects only.
    </description>

    <packaging>war</packaging>
    
    <dependencies>
        <dependency>
            <groupId>com.rackspace.papi.commons</groupId>
            <artifactId>classloader</artifactId>
        </dependency>

        <dependency>
            <groupId>com.rackspace.papi.commons</groupId>
            <artifactId>utilities</artifactId>
        </dependency>
        
        <dependency>
            <groupId>com.rackspace.papi.commons</groupId>
            <artifactId>configuration</artifactId>
        </dependency>
        
        <dependency>
            <groupId>com.rackspace.papi.core</groupId>
            <artifactId>core-lib</artifactId>
        </dependency>
    </dependencies>

    <build>
        <finalName>ROOT</finalName>
    </build>
    
    <profiles>
        <profile>
            <id>Build ROOT Web Application RPM</id>
                        
            <activation>
                <property>
                    <name>build-system-packages</name>
                </property>
            </activation>
        
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>rpm-maven-plugin</artifactId>
                
                        <configuration>                    
                            <mappings>
                                <mapping>
                                    <directory>/var/lib/tomcat7/webapps</directory>
                                    <username>tomcat7</username>
                                    <groupname>tomcat7</groupname>
                                    <filemode>755</filemode>
                            
                                    <sources>
                                        <source>
                                            <location>./target/ROOT.war</location>
                                        </source>
                                    </sources>
                                </mapping>
                        
                                <mapping>
                                    <directory>/etc/powerapi/</directory>
                                    <username>tomcat7</username>
                                    <groupname>tomcat7</groupname>
                                    <filemode>755</filemode>
                            
                                    <sources>
                                        <source>
                                            <location>../core-lib/src/main/resources/META-INF/schema/examples/container.cfg.xml</location>
                                        </source>
                                        <source>
                                            <location>../core-lib/src/main/resources/META-INF/schema/examples/power-proxy.cfg.xml</location>
                                        </source>
                                    </sources>
                                </mapping>
                            </mappings>
                    
                            <postinstallScriptlet>
                                <script>
                                    mkdir "/var/powerapi/logs/" -p -m 765;
                                    mkdir "/usr/share/powerapi/filters" -p -m 755;
                                    chown tomcat7:tomcat7 /var/powerapi /usr/share/powerapi -R;
                                </script>
                            </postinstallScriptlet>
                    
                            <postremoveScriptlet>
                                <script>
                                    rm -rf /var/powerapi /usr/share/powerapi/;
                                </script>
                            </postremoveScriptlet>
                    
                            <requires>
                                <require>java-1.6.0-openjdk</require>
                            </requires>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>        
    </profiles>
</project>
