<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

-->
<project name="log4php" default="compile">

    <property name="svnrepo.url" value="https://svn.apache.org/repos/asf"/>
	<property name="svnsite.url" value="${svnrepo.url}/incubator/log4php/site"/>
	<available property="svn-available" file="target/site-deploy/.svn"/>	

    <!--  Use Maven 2 to build or manually place ant-contrib (http://ant-contrib.sf.net) on path -->
    <taskdef name="foreach" classname="net.sf.antcontrib.logic.ForEach" />
        
    <target name="compile-file">
                <exec executable="php" failonerror="true">
                        <arg value="-l"/>
                        <arg value="${src.php}"/>
                </exec>
        </target>
        
        <target name="compile">
                <foreach target="compile-file" param="src.php">
                        <path>
                                <fileset dir="." includes="src/main/php/**/*.php"/>
                        </path>
                </foreach>
        </target>

        <target name="test-compile">
                <foreach target="compile-file" param="src.php">
                        <path>
                                <fileset dir="." includes="src/test/php/**/*.php"/>
                                <fileset dir="." includes="src/examples/php/**/*.php"/>
                        </path>
                </foreach>
        </target>

        <target name="php-file">
                <exec executable="php" failonerror="true" dir="target">
                        <arg value="-f"/>
                        <arg value="${src.php}"/>
                </exec>
        </target>

        <target name="test">
            <!--  PHPUnit3 must be installed for this to work.
                         See http://www.phpunit.de  -->
            <!-- TODO: change dir to "target", needs changes in some tests -->
            <mkdir dir="target"/>
            <exec executable="PHPUnit" failonerror="true" dir="src/test/php">
                        <arg value="AllTests"/>
                        <arg value="AllTests.php"/>
            </exec>
            <foreach target="php-file" param="src.php">
                 <path>
                      <fileset dir="." includes="src/examples/php/**/*.php" excludes="**/server.php"/>
                 </path>
            </foreach>
        </target>
        
        <target name="apidocs">
            <!--  PHPDoc must be installed for this to work.  -->
                <mkdir dir="target/site/apidocs"/>
                <exec executable="phpdoc" failonerror="true">
                        <arg value="-d"/>
                        <arg value="src/main/php"/>
                        <arg value="-t"/>
                        <arg value="target/site/apidocs"/>
                </exec>
        </target>


        <target name="fixcrlf">
           <fixcrlf srcdir="." includes="**/*.php, **/*.xml, **/*.properties, **/*.ini" tab="remove"/>
        </target>
        
	<target name="checkout-site" unless="svn-available">
		<exec executable="svn">
			<arg value="co"/>
			<arg value="${svnsite.url}"/>
			<arg value="target/site-deploy"/>
		</exec>
	</target>

	<target name="update-site" if="svn-available">
		<exec executable="svn" dir="target/site-deploy" failonerror="true">
			<arg value="update"/>
		</exec>
	</target>

	<target name="post-site" depends="checkout-site, update-site"/>

        <target name="mime=html">
            <exec executable="svn">
		<arg value="propset"/>
                <arg value="svn:mime-type"/>
                <arg value="text/html"/>
                <arg value="${src.html}"/>
            </exec>
        </target>

        <target name="mime=css">
            <exec executable="svn">
		<arg value="propset"/>
                <arg value="svn:mime-type"/>
                <arg value="text/css"/>
                <arg value="${src.css}"/>
            </exec>
        </target>
	
	<target name="site-deploy">
		<!-- Add any new files (and generate innocuous warnings for the existing content)  -->
                <delete file="target/site-deploy/svn-commit.tmp~"/>
		<exec executable="bash" dir="target/site-deploy" failonerror="true">
			<arg line='-c "svn add --force *"'/>
		</exec>
                <foreach target="mime=html" param="src.html">
                        <path>
                                <fileset dir="target/site-deploy" includes="**/*.html"/>
                        </path>
                </foreach>
                <foreach target="mime=css" param="src.css">
                        <path>
                                <fileset dir="target/site-deploy" includes="**/*.css"/>
                        </path>
                </foreach>
		<!--  requires that SVN_EDITOR, VISUAL or EDITOR being set to edit commit description -->
		<exec executable="svn" dir="target/site-deploy" failonerror="true">
		    <arg value="commit"/>
		</exec>
	</target>
        
</project>
