<?xml version="1.0"?>

<project name="vaadin-theme-compiler" basedir="." default="publish-local" xmlns:ivy="antlib:org.apache.ivy.ant" xmlns:antcontrib="antlib:net.sf.antcontrib">
    <description>
        Compiles build helpers used when building other modules.
    </description>
    <include file="../common.xml" as="common" />
    <include file="../build.xml" as="vaadin" />
    <include file="../gwt-files.xml" as="gwtfiles" />

    <!-- global properties -->
    <property name="module.name" value="vaadin-theme-compiler" />
    <property name="module.symbolic" value="com.vaadin.theme-compiler" />
    <property name="result.dir" value="result" />
    <property name="parser.src.dir" value="src/com/vaadin/sass/internal/parser" />
    <property name="generate.dir" value="${result.dir}/generated/${parser.src.dir}" />
    <property name="header.file" location="apache2header.txt" />

    <path id="classpath.compile.custom">
    </path>
    <path id="classpath.test.custom" />

    <!--<property name="classes.exclude" value="com/vaadin/buildhelpers/**" 
        /> -->

    <target name="parser">
        <!-- Copy javacc-5.0.jar to ${result.dir}/javacc/javacc.jar as the 
            javacc task requires the jar to be named javacc.jar -->
        <property name="javacc.home" location="${result.dir}/javacc" />
        <ivy:retrieve organisation="net.java.dev.javacc" module="javacc" revision="5.0" inline="true" type="jar" pattern="${javacc.home}/[artifact].[ext]" />
        <delete dir="${generate.dir}" />
        <mkdir dir="${generate.dir}" />
        <!-- Generate new parser files in another directory, this ensure
        they are always generated -->
        <copy file="${parser.src.dir}/Parser.jj" todir="${generate.dir}" />
        <javacc target="${generate.dir}/Parser.jj" javacchome="${javacc.home}">
        </javacc>
        <!-- Add headers to the generated files and copy back to src -->
        <antcontrib:foreach target="prepend.generated.file.header" param="path">
            <path>
                <fileset dir="${generate.dir}" includes="*.java" excludes="ParseException.java" />
            </path>
        </antcontrib:foreach>
    </target>

    <target name="prepend.generated.file.header">
        <basename property="file" file="${path}" />
        <concat destfile="${parser.src.dir}/${file}">
            <header filtering="no" trimleading="no" file="${header.file}" />
            <path path="${generate.dir}/${file}" />
        </concat>
    </target>

    <target name="jar" depends="parser">
        <antcall target="common.jar">
            <param name="import-package" value="org.apache.commons.jexl2;version=&quot;2.1.1&quot;,org.w3c.css.sac;version=&quot;1.3&quot;,org.w3c.flute.parser;version=&quot;1.3.0.gg2&quot;,org.w3c.flute.parser.selectors;version=&quot;1.3.0.gg2&quot;,org.w3c.flute.util;version=&quot;1.3.0.gg2&quot;" />
            <reference torefid="extra.jar.includes" refid="empty.reference" />
        </antcall>
    </target>
    <target name="publish-local" depends="jar">
        <antcall target="common.sources.jar">
            <reference torefid="extra.jar.includes" refid="empty.reference" />
        </antcall>
        <antcall target="common.javadoc.jar" />

        <antcall target="common.publish-local" />
    </target>

    <target name="clean">
        <antcall target="common.clean" />
    </target>

    <target name="checkstyle">
        <antcall target="common.checkstyle">
            <param name="cs.src" location="src" />
        </antcall>
    </target>

    <target name="test" depends="checkstyle">
        <antcall target="common.test.run" />
    </target>

</project>
