<?xml version="1.0"?>
<?rename tofile="portal.war"?>
<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.gatein.portal</groupId>
    <artifactId>exo.portal.packaging.tomcat</artifactId>
    <version>3.7.0.Final</version>
  </parent>
  <artifactId>exo.portal.packaging.tomcat.tomcat7</artifactId>
  <packaging>jar</packaging>
  <name>GateIn for Tomcat 7 packaging</name>

  <properties>
    <version.apache.tomcat>7.0.37</version.apache.tomcat>
    <tomcat.archive.name>apache-tomcat-${version.apache.tomcat}</tomcat.archive.name>
    <server.name>${tomcat.archive.name}</server.name>
    <tomcat.dir>${servers.dir}/${server.name}</tomcat.dir>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.gatein.wci</groupId>
      <artifactId>wci-tomcat7</artifactId>
    </dependency>
    <dependency>
      <groupId>org.gatein.portal</groupId>
      <artifactId>exo.portal.packaging.common</artifactId>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.kernel</groupId>
      <artifactId>exo.kernel.commons</artifactId>
    </dependency>
    <dependency>
      <groupId>org.exoplatform.kernel</groupId>
      <artifactId>exo.kernel.container</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-catalina</artifactId>
      <version>${version.apache.tomcat}</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
        <excludes>
          <exclude>tomcat/**</exclude>
        </excludes>
      </resource>
    </resources>  

    <plugins>
      <!-- Ensure your environment is correctly setup -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <executions>
          <execution>
            <id>check-servers-dir-specified</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireProperty>
                  <property>servers.dir</property>
                  <message>"
                    You need to specify 'servers.dir' directory where you store your application servers
                    (-Dservers.dir=PATH).
                    "
                  </message>
                </requireProperty>
              </rules>
            </configuration>
          </execution>

          <execution>
            <id>check-server-dir-exists</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireFilesExist>
                  <files>
                    <file>${servers.dir}/${server.name}/</file>
                  </files>
                  <message>"
                    The following Tomcat directory doesn't exist {servers.dir}/{server.name}:
                    ${servers.dir}/${server.name}

                    Make Tomcat instance available at that location, or use -Dservers.dir=PATH to point to the correct
                    location of servers directory
                    and/or -Dserver.name=NAME (alternatively use -Dtomcat7.name=NAME) to point to the correct directory
                    under the servers directory.
                    You can also use -Ddownload to automatically provide Tomcat instance.
                    "
                  </message>
                </requireFilesExist>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <executions>
          <execution>
            <id>auto-clean</id>
            <phase>initialize</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>      
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>prepare-package</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <ant antfile="${project.basedir}/package.xml" inheritRefs="true">
                  <target name="package" />
                  <property name="maven.project.basedir" value="${project.basedir}" />
                  <property name="maven.project.build.directory" value="${project.build.directory}" />
                </ant>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>

    <profile>
      <id>tc7.name.spec</id>
      <activation>
        <property>
          <name>tomcat7.name</name>
        </property>
      </activation>

      <properties>
        <server.name>${tomcat7.name}</server.name>
        <jbossas.dir>${servers.dir}/${server.name}</jbossas.dir>
      </properties>
    </profile>

    <profile>
      <id>download</id>
      <activation>
        <property>
          <name>download</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
              <execution>
                <id>check-server-dir-exists</id>
                <phase>none</phase>
              </execution>
            </executions>
          </plugin>          
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>              
              <execution>
                <id>prepare-package</id>
                <phase>package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <ant antfile="${project.basedir}/package.xml" inheritRefs="true">
                      <target name="prepare" />
                      <property name="maven.project.basedir" value="${project.basedir}" />
                      <property name="maven.project.build.directory" value="${project.build.directory}" />
                    </ant>
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>bundle</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>package</id>
                <phase>package</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <zip destfile="${project.build.directory}/tomcat7.zip" basedir="${project.build.directory}/tomcat" />
                    <attachartifact file="${project.build.directory}/tomcat7.zip" classifier="bundle" type="zip" />
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
