<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>composer</groupId>
    <artifactId>PV_Web_Builder</artifactId>
    <version>${env.PVIEWVERSION}</version>
    <relativePath>../PV_Web_Builder/pom.xml</relativePath>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>PV_Web</artifactId>
  <packaging>war</packaging>
  <name>PV_Web</name>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <outputDirectory>${output.dir}\PV_Web</outputDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>nl.allshare.web/**</exclude>
          <exclude>**/*.java</exclude>
          <exclude>**/composer/**</exclude>
          <exclude>**/scriptacalous/**</exclude>
          <exclude>**/internal/**</exclude>
          <exclude>**/webgui/**</exclude>
          <exclude>index.html</exclude>
        </excludes>
      </resource>
      <resource>
        <directory>Config</directory>
      </resource>
    </resources>
    <directory>${output.war.dir}</directory>
    <finalName>PV_Web-${pview.version}_${BUILD_NUMBER}</finalName>
  </build>
  <profiles>

    <!-- LOAD PROPERTIES -->
    <profile>
      <id>properties</id>
      <activation>
        <property>
          <name>load_properties</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-1</version>
            <executions>
              <execution>
                <phase>validate</phase>
                <goals>
                  <goal>read-project-properties</goal>
                </goals>
                <configuration>
                  <files>
                    <file>${server.property.file}</file>
                  </files>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>


    <!-- REBUILD WAR -->
    <profile>
      <id>rebuild_war_id</id>
      <activation>
        <property>
          <name>rebuild_war</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.3</version>
            <configuration>
              <tasks>

                <echo message="" />
                <echo message="DELETE KERNEL PVMETA DIRECTORIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Delete pv50" />
                <delete includeemptydirs="true" quiet="true">
                  <fileset dir="${SVN_WORKINGDIRECTORY__PV50}" includes="**/*" />
                </delete>
                <echo message="Delete pv50_interface" />
                <delete includeemptydirs="true" quiet="true">
                  <fileset dir="${SVN_WORKINGDIRECTORY__PV50_INTERFACE}" includes="**/*" />
                </delete>
                <echo message="Delete pv50_selfservice" />
                <delete includeemptydirs="true" quiet="true">
                  <fileset dir="${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE}" includes="**/*" />
                </delete>
                <echo message="Delete pv50_unittest" />
                <delete includeemptydirs="true" quiet="true">
                  <fileset dir="${SVN_WORKINGDIRECTORY__PV50_UNITTEST}" includes="**/*" />
                </delete>

                <echo message="" />
                <echo message="CHECKOUT KERNEL PVMETA DIRECTORIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Checkout pv50" />
                <exec executable="svn">
                  <arg
                    line="checkout ${SVN_URL}/kernel/ontwikkelen/pvmeta/pv50/ ${SVN_WORKINGDIRECTORY__PV50} --force -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Checkout pv50_interface" />
                <exec executable="svn">
                  <arg
                    line="checkout ${SVN_URL}/kernel/ontwikkelen/pvmeta/pv50_interface/ ${SVN_WORKINGDIRECTORY__PV50_INTERFACE} --force -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Checkout pv50_selfservice" />
                <exec executable="svn">
                  <arg
                    line="checkout ${SVN_URL}/kernel/ontwikkelen/pvmeta/pv50_selfservice/ ${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE} --force -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Checkout pv50_unittest" />
                <exec executable="svn">
                  <arg
                    line="checkout ${SVN_URL}/kernel/ontwikkelen/pvmeta/pv50_unittest/ ${SVN_WORKINGDIRECTORY__PV50_UNITTEST} --force -q -r ${SVN_REVISION}" />
                </exec>

                <echo message="" />
                <echo message="UPDATE KERNEL PVMETA DIRECTORIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Update pv50" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY__PV50} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update pv50_interface" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY__PV50_INTERFACE} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update pv50_selfservice" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update pv50_unittest" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY__PV50_UNITTEST} -q -r ${SVN_REVISION}" />
                </exec>


                <echo message="" />
                <echo message="UPDATE VERSION.TXT FILES WITH CORRECT BUILD ID" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Copy version.txt template to _work directory..." />
                <copy file="${VERSION_TEMPLATE}" tofile="${output.work.dir}/version.txt" />

                <echo message="Edit version.txt to reflect current build id..." />
                <replace file="${output.work.dir}/version.txt" token="@@@" value="${pview.build.id}" />

                <echo message="Overwrite new version.txt in pvmeta kernel directories..." />
                <copy file="${output.work.dir}/version.txt" todir="${SVN_WORKINGDIRECTORY__PV50}" overwrite="true" />
                <copy file="${output.work.dir}/version.txt" todir="${SVN_WORKINGDIRECTORY__PV50_INTERFACE}" overwrite="true" />
                <copy file="${output.work.dir}/version.txt" todir="${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE}" overwrite="true" />


                <echo message="" />
                <echo message="COMMIT VERSION.TXT FILES IN PVMETA DIRECTORIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <exec executable="svn">
                  <arg line="commit ${SVN_WORKINGDIRECTORY__PV50} -m 'Automatically generated for: ${pview.build.id}'" />
                </exec>
                <exec executable="svn">
                  <arg line="commit ${SVN_WORKINGDIRECTORY__PV50_INTERFACE} -m 'Automatically generated for: ${pview.build.id}'" />
                </exec>
                <exec executable="svn">
                  <arg line="commit ${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE} -m 'Automatically generated for: ${pview.build.id}'" />
                </exec>
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE}" />
                </exec>


                <echo message="" />
                <echo message="RETRIEVE LATEST SVN REVISION NUMBER" />
                <echo message="-----------------------------------------------------------------------------------" />
                <exec executable="svnversion" outputproperty="svn.revision">
                  <arg line="-n ${SVN_WORKINGDIRECTORY__PV50_SELFSERVICE}" />
                </exec>
                <echo message="Revision = ${svn.revision} [stored in property svn.revision]" />

                <echo message="" />
                <echo message="RECREATE WAR TO ADD ALL PV_WEB/LIBRARIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Unwar current WAR file..." />
                <unzip src="${output.war.dir}/PV_Web-${pview.version}_${BUILD_NUMBER}.war" dest="${output.work.dir}" />

                <echo message="Edit manifest file to reflect correct svn revision number" />
                <replace file="${output.work.dir}/META-INF/MANIFEST.MF" token="@@SVN@@" value="${svn.revision}" />

                <!-- 
                <echo message="Alter web.xml to remove dwr-test.xml.." />
                <replace file="${output.work.dir}/WEB-INF/web.xml">
                  <replacetoken><![CDATA[<init-param>
      <description></description>
      <param-name>config-test</param-name>
      <param-value>WEB-INF/classes/dwr-test.xml</param-value>
    </init-param>]]></replacetoken>
                  <replacevalue></replacevalue>
                </replace>
                  <replacetoken>config-test</replacetoken>
                  <replacevalue></replacevalue>
                </replace>
                <replace file="${output.work.dir}/WEB-INF/web.xml">
                  <replacetoken>WEB-INF/classes/dwr-test.xml</replacetoken>
                  <replacevalue></replacevalue>
                </replace>
                -->
                

                <echo message="Copy all library files into WAR file...." />
                <copy todir="${output.work.dir}/WEB-INF/lib/" flatten="true">
                  <fileset dir="${pview.library.dir}">
                    <include name="**/Commons/*.jar" />
                    <include name="**/CXF/*.jar" />
                    <include name="**/Database/*.jar" />
                    <include name="**/DWR/*.jar" />
                    <include name="**/EHCache/*.jar" />
                    <include name="**/JFreeChart/*.jar" />
                    <include name="**/JUnit/*.jar" />
                    <include name="**/Mail/*.jar" />
                    <include name="**/NTLM/*.jar" />
                    <include name="**/PDF/*.jar" />
                    <include name="**/Quartz/*.jar" />
                    <include name="**/SmartXLS/*.jar" />
                    <include name="**/Spring/*.jar" />
                    <include name="**/SVNKit/*.jar" />
                    <include name="**/XMLBeans/*.jar" />
                  </fileset>
                </copy>

                <echo message="Zip all files and build new PV_Web.war...." />
                <zip destfile="${output.war.dir}/PV_Web-${pview.version}_${BUILD_NUMBER}.war">
                  <zipfileset dir="${output.work.dir}"
                    excludes="**/WEB-INF/lib/maven-*.jar, **/WEB-INF/lib/wagon-*.jar, **/WEB-INF/lib/classworlds-*.jar, **/WEB-INF/lib/doxia-sink-api*.jar, 
                              **/WEB-INF/lib/iText*.jar, **/WEB-INF/lib/plexus*.jar, **/WEB-INF/lib/velocity*.jar, **/WEB-INF/lib/surefire*.jar, 
                              **/WEB-INF/lib/commons-cli*.jar, **/WEB-INF/lib/commons-dbcp*.jar, **/WEB-INF/lib/commons-logging-1.0.4.jar, **/WEB-INF/lib/commons-codec*.jar,
                              **/WEB-INF/lib/properties-maven*.jar, **/WEB-INF/lib/jboss-maven-plugin*.jar, **/WEB-INF/lib/mail-*.jar,
                              **/WEB-INF/lib/jsch*.jar, **/WEB-INF/lib/jta*.jar, **/WEB-INF/lib/jtidy-*.jar, **/WEB-INF/lib/junit-*.jar, 
                              **/WEB-INF/lib/saaj-*.jar, **/WEB-INF/lib/servlet-api*.jar, **/WEB-INF/lib/xml-apis*.jar" />
                </zip>


                <echo message="" />
                <echo message="UPDATE INNOSETUP DIRECTORIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Update pv50" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY_INNOSETUP__PV50} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update pv50_interface" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY_INNOSETUP__PV50_INTERFACE} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update pv50_selfservice" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY_INNOSETUP__PV50_SELFSERVICE} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update docs/DatabaseSchema" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY_INNOSETUP__DOCS} -q -r ${SVN_REVISION}" />
                </exec>
                <echo message="Update innosetup" />
                <exec executable="svn">
                  <arg line="update ${SVN_WORKINGDIRECTORY_INNOSETUP__SETUP} -q -r ${SVN_REVISION}" />
                </exec>

                <echo message="" />
                <echo message="PREPARE INNOSETUP" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Copy PV_Web.war to innosetup directory" />
                <copy file="${output.war.dir}/PV_Web-${pview.version}_${BUILD_NUMBER}.war" tofile="${WORKINGDIRECTORY_INNOSETUP}/PV_Web.war" overwrite="true" preservelastmodified="true" />
                <echo message="Alter composer5.iss to point to correct innosetup directory" />
                <replace file="${WORKINGDIRECTORY_INNOSETUP}/composer5.iss" token="${INNOSETUP__TOKEN}" value="${WORKINGDIRECTORY_INNOSETUP}" />
                
                <echo message="" />
                <echo message="RUN INNOSETUP" />
                <echo message="-----------------------------------------------------------------------------------" />
                <exec executable="cmd">
                  <arg value="/c" />
                  <arg value="${INNOSETUP__CMD}" />
                  <arg value="SetupComposer-${pview.version}_${BUILD_NUMBER}" />
                </exec>

                
                <echo message="" />
                <echo message="BUILD ZIP FILE WITH PVMETA DIRECTORIES AND WAR FILE" />
                <echo message="-----------------------------------------------------------------------------------" />
                <zip destfile="${output.base.dir}/PV_Web-${pview.version}_${BUILD_NUMBER}.zip">
                  <zipfileset dir="${pview.composer.dir}/pv50/" prefix="PVMeta/kernel/pv50" />
                  <zipfileset dir="${pview.composer.dir}/pv50_interface/" prefix="PVMeta/kernel/pv50_interface" />
                  <zipfileset dir="${pview.composer.dir}/pv50_selfservice/" prefix="PVMeta/kernel/pv50_selfservice" />
                  <zipfileset file="${output.war.dir}/PV_Web-${pview.version}_${BUILD_NUMBER}.war" />
                  <zipfileset file="${WORKINGDIRECTORY_INNOSETUP}/SetupComposer*.exe" />
                  <zipfileset file="${output.work.dir}/META-INF/MANIFEST.MF" prefix="BuildInfo" />
                  <zipfileset file="${SVN_WORKINGDIRECTORY__PV50}/version.txt" prefix="BuildInfo" />
                </zip>
                
                
                <echo message="" />
                <echo message="HANDLE ZIP/WAR FILE ROTATION [remove files older than 2 days]" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Remove files in build directory" />
                <exec executable="cmd">
                  <arg value="/c" />
                  <arg value="${ROTATION__CMD}" />
                  <arg value="${ROTATION__ZIP_DIR}" />
                  <arg value="${ROTATION__DAYS}" />
                </exec>
                <echo message="Remove files in build/war directory" />
                <exec executable="cmd">
                  <arg value="/c" />
                  <arg value="${ROTATION__CMD}" />
                  <arg value="${ROTATION__WAR_DIR}" />
                  <arg value="${ROTATION__DAYS}" />
                </exec>
                
                
                <echo message="" />
                <echo message="CLEANUP DIRECTORIES" />
                <echo message="-----------------------------------------------------------------------------------" />
                <echo message="Remove all files in ${output.work.dir}...." />
                <delete includeemptydirs="true">
                  <fileset dir="${output.work.dir}" includes="**/*" />
                </delete>

                <echo message="Remove temp WAR directory...." />
                <delete includeemptydirs="true">
                  <fileset dir="${output.war.dir}/PV_Web-${pview.version}_${BUILD_NUMBER}" />
                </delete>

                <echo message="Remove SetupComposer exe file" />
                <delete>
                  <fileset dir="${WORKINGDIRECTORY_INNOSETUP}" includes="SetupComposer*.exe"/>
                </delete>

                <!-- Dit werkt nog niet... 
                  <echo message="Purge old WAR files...."/>
                  <taskdef name="purge" classname="com.dallaway.ant.Purge"/>
                  <purge keep="5">
                  <fileset dir="${output.war.dir}/"/>
                  </purge>
                -->
                
                <delete file="/lib/ant.jar"/>

                <echo message="" />

              </tasks>
            </configuration>
            <executions>
              <execution>
                <id>rebuild_war</id>
                <phase>verify</phase>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- RUN DUMMY JUNIT TESTS -->
    <profile>
      <id>run_dummy_test_id</id>
      <activation>
        <property>
          <name>run_dummy_test</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>true</skip>
              <includes>
                <include>**/TestDateUtility.java</include>
              </includes>
            </configuration>
            <executions>
              <execution>
                <id>test_execution</id>
                <phase>package</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <skip>true</skip>
                  <includes>
                    <include>**/TestDateUtility.java</include>
                  </includes>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- RUN ACTUAL JUNIT TESTS -->
    <profile>
      <id>run_tests_id</id>
      <activation>
        <property>
          <name>run_tests</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0-beta-2</version>

            <configuration>
              <!-- Container configuration -->
              <container>
                <containerId>jboss42x</containerId>
                <home>${JBOSS__HOME}</home>
              </container>
              <!-- Configuration to use with the container -->
              <configuration>
                <type>standalone</type>
                <home>${JBOSS__HOME}/server/default</home>
                <properties>
                  <!--<cargo.rmi.port>${JBOSS_PORT__RMI}</cargo.rmi.port>-->
                  <cargo.jvmargs>${VMARGS__TEST_PROPERTY_FILE}</cargo.jvmargs>
                </properties>
              </configuration>
            </configuration>

          </plugin>
          <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
              <skip>false</skip>
              <argLine>${VMARGS__TEST_PROPERTY_FILE}</argLine>
              <testFailureIgnore>false</testFailureIgnore>
            </configuration>
          </plugin>

          <plugin>
            <groupId>org.twdata.maven</groupId>
            <artifactId>maven-itblast-plugin</artifactId>
            <version>0.5</version>
            <executions>
              <execution>
                <phase>verify</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <containers>jboss42x</containers>
                  <httpPort>${JBOSS_PORT__HTTP}</httpPort>
                  <rmiPort>${JBOSS_PORT__RMI}</rmiPort>
                  <functionalTestPattern>${JUNIT__TEST_PATTERN}</functionalTestPattern>
                  <systemProperties></systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>

  <dependencies>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Framework</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Base1_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Base2_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Base3_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Services</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_DAO_TO</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Interview_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_WorkUnit_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Tools_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_DataManager1</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Interview</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Tools</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_WorkUnit</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Base1_Manager</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Base2_Manager</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Base3_Manager</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_PPL</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_PPL_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Soap</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_WebGUI</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Koppeling_Class</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_Koppeling</artifactId>
    </dependency>
    <dependency>
      <groupId>${pview.group}</groupId>
      <artifactId>PV_UnitTest</artifactId>
    </dependency>
  </dependencies>
</project>
