<!--
    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="Compress JavaScript" default="compress" basedir=".">

<!-- ============================================================================ -->
<!--
    This ant file creates compressed versions of Validator's JavaScript
    files using the Dojo compressor.

    See http://dojotoolkit.org/docs/compressor_system.html for further information.

    $Id: build-javascript.xml 1229415 2012-01-09 23:11:33Z sebb $
 -->
<!-- ============================================================================ -->

    <property file="build-javascript.properties"/>

    <property name="build.dir"           value="target"/>
    <property name="dist.dir"            value="${build.dir}"/>
    <property name="output.dir"          value="${build.dir}/classes"/>
    <property name="source.dir"          value="src/javascript"/>
    <property name="javascript.input"    value="${source.dir}/org/apache/commons/validator/javascript"/>
    <property name="javascript.output"   value="${output.dir}/org/apache/commons/validator/javascript"/>
    <property name="compressor.lib"      value="lib"/>
    <property name="customrhino.version" value="0.4.3"/>
    <property name="download.location"   value="http://repo1.maven.org/maven2/org/dojotoolkit/custom_rhino/${customrhino.version}"/>
    <property name="download.jar"        value="custom_rhino-${customrhino.version}.jar"/>
    <property name="final.name"          value="commons-validator"/>
    
    <!-- ======================================================================== -->
    <!--                 Get the JavaScript Compressor                            -->
    <!-- ======================================================================== -->
    <target name="compress">
        <available file="${compressor.jar}" property="compressor.found"/>
        <antcall target="compressor-specified" />
        <antcall target="download-compressor-check" />
    </target>

    <target name="compressor-specified" if="compressor.found">
        <antcall target="compress-files" />
    </target>

    <!-- Download the Compressor jar (unless its already been done) -->
    <target name="download-compressor-check" unless="compressor.found">
        <mkdir dir="${compressor.lib}" />
        <property name="compressor.jar"  value="${compressor.lib}/${download.jar}"/>
        <available file="${compressor.jar}" property="download.done"/> 
        <antcall target="download-compressor" />
        <antcall target="compress-files" />
    </target>

    <!-- Download the Compressor jar -->
    <target name="download-compressor" unless="download.done">
        <echo message="Downloading JavaScript Compressor...."/>
        <get dest="${compressor.jar}"
            usetimestamp="true" ignoreerrors="true"
            src="${download.location}/${download.jar}"/>
    </target>

    <!-- ======================================================================== -->
    <!--                        Compress Files                                    -->
    <!-- ======================================================================== -->
    <target name="compress-files">
        <echo message="Compressing JavaScript files using ${compressor.jar}"/>
        <mkdir dir="${dist.dir}" />
        <mkdir dir="${javascript.output}" />

        <concat destfile="${dist.dir}/${final.name}.js">
            <fileset dir="${javascript.input}" includes="*.js"/>
        </concat>
        <echo message="Compressing ${final.name}.js"/>
        <java jar="${compressor.jar}" fork="true" output="${dist.dir}/${final.name}-compress.js">
            <arg value="-c"/> 
            <arg value="${dist.dir}/${final.name}.js"/>
        </java>

        <antcall target="compress-file">
            <param name="jsfilename" value="validateByte"/>
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateCreditCard"/>
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateDate"/>
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateEmail"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateFloat"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateFloatRange"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateInteger"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateIntRange"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateMask"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateMaxLength"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateMinLength"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateRequired"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateShort"/> 
        </antcall>
        <antcall target="compress-file">
            <param name="jsfilename" value="validateUtilities"/> 
        </antcall>
    </target>

    <target name="compress-file">
        <echo message="Compressing ${jsfilename}.js"/>
        <java jar="${compressor.jar}" fork="true" output="${javascript.output}/${jsfilename}-compress.js">
            <arg value="-c"/> 
            <arg value="${javascript.input}/${jsfilename}.js"/>
        </java>
    </target>

</project>

