<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>io.apiman</groupId>
    <artifactId>apiman-tools</artifactId>
    <version>1.0.3.Final</version>
  </parent>
  <artifactId>apiman-tools-server-all</artifactId>
  <packaging>pom</packaging>
  <name>apiman-tools-server-all</name>

  <dependencies>
    <!-- The WildFly 8 version of APIMan -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>apiman-distro-wildfly8</artifactId>
      <type>zip</type>
      <classifier>overlay</classifier>
    </dependency>

    <!-- Some Basic Services for Testing -->
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>apiman-tools-services</artifactId>
      <type>war</type>
    </dependency>

    <!-- Data Source Dependencies -->
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
    </dependency>
    <dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
    </dependency>
  </dependencies>

  <profiles>
    <!-- Install on WildFly 8.2 -->
    <profile>
      <id>install-all-wildfly8</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <dependencies>
              <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant</artifactId>
                <version>1.8.2</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <id>run-wildfly8</id>
                <phase>install</phase>
                <configuration>
                  <tasks>
                    <antversion property="antversion" />
                    <echo>Ant Version: ${antversion}</echo>

                    <property name="appserver.id" value="wildfly8" />
                    <property name="apiman.wildfly.download.url"
                      value="http://download.jboss.org/wildfly/8.2.0.Final/wildfly-8.2.0.Final.zip" />
                    <property name="apiman.tempdir" value="${project.build.directory}/_tmp" />
                    <property name="apiman.install.dir" value="${project.build.directory}" />
                    <property name="apiman.appserver.dir" location="${apiman.install.dir}/wildfly-8.2.0.Final" />
                    <property name="apiman.wildfly.zip" location="${basedir}/wildfly-8.2.0.Final.zip" />
                    <property name="apiman.apiman-distro-wildfly8.zip" value="${maven.dependency.io.apiman.apiman-distro-wildfly8.overlay.zip.path}" />
                    <property name="apiman.apiman-tools-services.war" value="${maven.dependency.io.apiman.apiman-tools-services.war.path}" />
                    <property name="apiman.wildfly.home" location="${apiman.appserver.dir}" />
                    <property name="apiman.wildfly.webapps" location="${apiman.appserver.dir}/standalone/deployments" />
                    <property name="apiman.resources.dir" location="${basedir}/src/main/resources" />

                    <echo></echo>
                    <echo>********************************************************************</echo>
                    <echo>APIMan Dist: ${apiman.apiman-distro-wildfly8.zip}</echo>
                    <echo>Dev Services: ${apiman.apiman-tools-services.war}</echo>
                    <echo>-------</echo>
                    <echo>WildFly Home: ${apiman.wildfly.home}</echo>
                    <echo>********************************************************************</echo>
                    <echo></echo>

                    <mkdir dir="${apiman.tempdir}" />

                    <!-- Download and unpack WildFly 8.2 -->
                    <get src="${apiman.wildfly.download.url}" dest="${apiman.wildfly.zip}" usetimestamp="true" />
                    <unzip src="${apiman.wildfly.zip}" dest="${apiman.install.dir}" overwrite="false" />

                    <!-- Overlay APIMan on top of WildFly 8.2 -->
                    <unzip src="${apiman.apiman-distro-wildfly8.zip}" dest="${apiman.install.dir}/wildfly-8.2.0.Final" overwrite="true" />
                    
                    <!-- Make sure to chmod 755 the shell scripts -->
                    <chmod perm="a+x" dir="${apiman.appserver.dir}/bin">
                      <include name="*.sh" />
                    </chmod>

                    <!-- Deploy additional stuff -->
                    <copy file="${apiman.resources.dir}/wildfly8/deployments/authtest-ds.xml" todir="${apiman.wildfly.webapps}"
                      overwrite="true" />
                    <copy file="${apiman.resources.dir}/wildfly8/deployments/mysql-connector-java-5.1.33-bin.jar"
                      todir="${apiman.wildfly.webapps}" overwrite="true" />
                    <copy file="${apiman.resources.dir}/wildfly8/deployments/postgresql-9.3-1102.jdbc41.jar"
                      todir="${apiman.wildfly.webapps}" overwrite="true" />                      
                    <copy
                      file="../../distro/wildfly8/src/main/resources/overlay/standalone/configuration/standalone-apiman.xml"
                      tofile="${apiman.wildfly.home}/standalone/configuration/standalone.xml" overwrite="true" />
                    <copy file="${apiman.apiman-tools-services.war}" tofile="${apiman.wildfly.webapps}/services.war"
                      overwrite="true" />
                  </tasks>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>