<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">
    <name>webgoat-release</name>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>webgoat-release</artifactId>
    <packaging>war</packaging>
    <parent>
        <groupId>org.owasp.webgoat</groupId>
        <artifactId>webgoat-parent</artifactId>
        <version>7.0-SNAPSHOT</version>
    </parent>

    <!-- Shared version number properties -->
    <properties>
        <tiles.version>2.2.2</tiles.version>
        <!-- If run from Bamboo this will be replaced with the bamboo build number -->
        <build.number>local</build.number>
        <lessons.version>1.0</lessons.version>
        <war.output.dir>${project.build.directory}/war/</war.output.dir>
        <lessons.output.dir>${war.output.dir}/plugin_lessons</lessons.output.dir>
    </properties>

    <!--
        Step 1: Unpack the container WAR file
        Step 2: Use the zip file and unpack it
        Step 3: Build a new WAR file and install it in the repository
    -->

    <build>
        <plugins>
            <!-- Unpack the container.war and dist-plugins.jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>unpack-war</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.owasp.webgoat</groupId>
                                    <artifactId>webgoat-container</artifactId>
                                    <version>${project.version}</version>
                                    <type>war</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${war.output.dir}</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>unpack-lessons-zip</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                            <artifactItems>
                                <artifactItem>
                                    <includes>**/*.jar</includes>
                                    <groupId>org.owasp.webgoat.lesson</groupId>
                                    <artifactId>dist</artifactId>
                                    <version>${lessons.version}</version>
                                    <type>zip</type>
                                    <classifier>plugins</classifier>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${lessons.output.dir}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- Create the war -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>${war.output.dir}</warSourceDirectory>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Specification-Title>${project.name}</Specification-Title>
                            <Specification-Version>${project.version}</Specification-Version>
                            <Implementation-Version>${build.number}</Implementation-Version>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>
            <!-- Create the executable jar -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <url>http://localhost:8080/manager</url>
                    <path>/WebGoat</path>
                    <attachArtifactClassifier>exec</attachArtifactClassifier>
                </configuration>
                <executions>
                    <execution>
                        <id>tomcat-run</id>
                        <goals>
                            <goal>exec-war-only</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>