<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">

  <parent>
    <groupId>org.jboss.jsfunit</groupId>
    <artifactId>jboss-jsfunit-examples-hellojsf</artifactId>
    <version>1.2.0.Final</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>
  <artifactId>jboss-jsfunit-examples-hellojsf-ant</artifactId>
  <packaging>war</packaging>
  <name>HelloJSF Ant Task Test</name>

  <profiles>
    <profile>
      <id>test</id>        
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            
            <executions>
              <execution>
                <id>surefire-it</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <skip>false</skip>
                  <systemProperties>
                    <property>
                      <name>cactus.contextURL</name>
                      <value>http://localhost:8080/mywar</value>
                    </property>
                  </systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
          
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <configuration>
              <wait>false</wait>  
              <configuration>                  
                <deployables>
                  <deployable>
                    <location>${project.build.directory}/mywar.war</location>
                    <type>war</type>
                  </deployable>
                </deployables>
              </configuration>
            </configuration>
            <executions>
              <execution>
                <id>start-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
              </execution>
              <execution>
                <id>stop-container</id>
                <phase>post-integration-test</phase>
                <goals>
                  <goal>stop</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
      <activation>
        <property>
           <name>jsfunit-test-profile</name>
        </property>
      </activation>
    </profile>
    
    <profile>
       <id>jboss5x</id>
       <properties>
         <containerId>jboss5x</containerId>
      </properties>
    </profile>
  </profiles>
  
  <dependencies>
    <dependency>
      <groupId>org.jboss.jsfunit</groupId>
      <artifactId>jboss-jsfunit-core</artifactId>
      <version>${project.version}</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.faces</groupId>
      <artifactId>jsf-api</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>      

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <configuration>
              <tasks>
                <property name="target" location="./target" />
                
                <property name="dest.war.dir" location="${target}" />
                <property name="dest.war" location="${dest.war.dir}/mywar.war" />

                <property name="classes.test" location="${target}/test-classes" />
                
                <property name="ant.lib.dir" location="./ant-lib" />
                <property name="jsfunit.lib.dir" location="${target}/jsfunitwar-lib" />
                <property name="src.war" location="${jsfunit.lib.dir}/jboss-jsfunit-examples-hellojsf-webapp-${project.version}.war" />

                <path id="maven-ant-tasks.classpath" path="${ant.lib.dir}/maven-ant-tasks-2.0.7.jar" />
                      
                <typedef resource="org/apache/maven/artifact/ant/antlib.xml" classpathref="maven-ant-tasks.classpath" />
                         
                <dependencies filesetId="dependency.fileset" pathId="jsfunit.classpath">
                   <dependency groupId="net.sourceforge.htmlunit" artifactId="htmlunit" version="2.7" />
                   <dependency groupId="cactus" artifactId="cactus" version="13-1.7.1" />
                   <dependency groupId="org.jboss.jsfunit" artifactId="jboss-jsfunit-core" version="${project.version}" />
                   <dependency groupId="org.jboss.jsfunit" artifactId="jboss-jsfunit-ant" version="${project.version}" />
                   <dependency groupId="org.jboss.jsfunit" artifactId="jboss-jsfunit-examples-hellojsf-webapp" version="${project.version}" type="war" />
                </dependencies>

                <!-- Copy the above dependencies into the target lib dir -->
                <copy todir="${jsfunit.lib.dir}">
                  <fileset refid="dependency.fileset" />
                  <mapper type="flatten" />
                </copy>
                         
                <taskdef name="jsfunitwar" classname="org.jboss.jsfunit.ant.JSFUnitWarTask">  
                  <classpath>
                     <fileset dir="${jsfunit.lib.dir}">
                        <include name="**/*.jar" />
                     </fileset>
                  </classpath>
                </taskdef>

                <!-- Xerces is required for Tomcat, but not Jetty -->
                <!-- We will always bundle it anyway -->
                <property name="xercesImpl.jar" location="${jsfunit.lib.dir}/xercesImpl-2.6.2.jar" />
                
                <!-- Xalan needed by htmlunit, but often included in app server -->
                <property name="xalan.jar" location="${jsfunit.lib.dir}/xalan-2.7.0.jar" />
                
                <delete file="${dest.war}" />
                <jsfunitwar srcfile="${src.war}" destfile="${dest.war}" autoaddjars="true" container="${containerId}">
                  <TestRunner />
                  <classes dir="${classes.test}" includes="**/*.class" />
                  <lib file="${xercesImpl.jar}" />
                  <lib file="${xalan.jar}" />
                </jsfunitwar>	
                
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>  
       
  </build>
</project>