<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="makeall">

    <taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask">
        <classpath>
            <pathelement location="../res/compiler.jar" />
        </classpath>
    </taskdef>
    <taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="../res/ant-contrib.jar"/>
        </classpath>
    </taskdef>
    <delete dir="${basedir}/../../build" />
    <mkdir  dir="${basedir}/../../build" />
    
    <target name="makeall" depends="concatenate" />

    <target name="concatenate">
        <concat encoding="UTF-8" outputencoding="UTF-8" destfile="../../build/renkan.js">
            <filelist dir="../../client/js" files="header.js main.js models.js defaults.js i18n.js paper-renderer.js full-json.js ldtjson-bin.js list-bin.js wikipedia-bin.js" />
            <filterchain>
                <deletecharacters chars="&#xFEFF;" />
            </filterchain>
        </concat>
    </target>
    
    <target name="minify" depends="concatenate">
        <jscomp compilationLevel="simple" warning="quiet" debug="false"
        output="../../build/renkan.min.raw.js">
            <externs dir="${basedir}/../../client/lib">
                <file name="jquery.js" />
                <file name="jquery-ui.js" />
                <file name="backbone.js" />
            	<file name="backbone-relational.js" />
            	<file name="jquery.mousewheel.js" />
            	<file name="paper.js" />
            	<file name="underscore.js" />
            </externs>
            <sources dir="${basedir}/../../build">
                <file name="renkan.js" />
            </sources>
        </jscomp>
        <concat destfile="../../build/renkan.min.js"
        append="false">
            <filelist dir="../../client/js/" files="header.js" />
            <filelist dir="../../build/" files="renkan.min.raw.js" />
        </concat>
        <delete file="../../build/renkan.min.raw.js" />
    </target>
    <property name="rhino.jar" value="${basedir}/../res/rhino.jar"/>
    <property name="jslint-wrapper.js" value="${basedir}/../res/jslint-wrapper.js"/>
    <property name="jslint.js" value="${basedir}/../res/jslint.js"/>
    <target name="jslint" description="Run jslint on the files" depends="concatenate">
        <apply executable="java" parallel="false">
            <filelist dir="../../build">
                <file name="renkan.js"/>
            </filelist>
            <arg line="-jar"/>
            <arg path="${rhino.jar}"/>
            <arg path="${jslint-wrapper.js}"/>
            <arg path="${jslint.js}"/>
        </apply>
    </target>
</project>
