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

    <groupId>org.vivoweb</groupId>
    <artifactId>vitro-installer-webapp</artifactId>
    <version>1.14.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.vivoweb</groupId>
        <artifactId>vitro-installer</artifactId>
        <version>1.14.1-SNAPSHOT</version>
        <relativePath>..</relativePath>
    </parent>

    <name>Vitro Install Web App</name>

    <profiles>
        <profile>
            <id>package</id>
            <activation>
                <property><name>app-name</name></property>
            </activation>
            <build>
                <finalName>${app-name}</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                            <archiveClasses>false</archiveClasses>
                            <overlays>
                                <overlay>
                                    <groupId>org.vivoweb</groupId>
                                    <artifactId>vitro-webapp</artifactId>
                                    <type>war</type>
                                </overlay>
                            </overlays>
                            <webResources>
                                <resource>
                                    <directory>src/main/webResources</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </webResources>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>install</id>
            <activation>
                <property><name>tomcat-dir</name></property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>remove-webapp</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <target>
                                        <delete dir="${tomcat-dir}/webapps/${project.build.finalName}" />
                                    </target>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>install</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>unpack</goal>
                                </goals>
                                <configuration>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>${project.artifactId}</artifactId>
                                            <version>${project.version}</version>
                                            <type>war</type>
                                            <overWrite>true</overWrite>
                                            <outputDirectory>${tomcat-dir}/webapps/${project.build.finalName}</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-install-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>overlays</directory>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.vivoweb</groupId>
            <artifactId>vitro-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.vivoweb</groupId>
            <artifactId>vitro-webapp</artifactId>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</project>
