<?xml version="1.0"?>

<project xmlns:antcontrib="antlib:net.sf.antcontrib" xmlns:artifact="antlib:org.apache.maven.artifact.ant" xmlns:ivy="antlib:org.apache.ivy.ant" name="Build script for IDE users" basedir=".." default="theme-and-default-widgetset">
    <property name="work.dir" location="work" />
    <property file="build.properties" />

    <ivy:resolve log="download-only" file="client-compiler/ivy.xml" conf="ide" />
    <ivy:cachepath pathid="client-compiler.deps" conf="ide" />
    <ivy:resolve log="download-only" file="server/ivy.xml" conf="ide" />
    <ivy:cachepath pathid="server.deps" conf="ide" />
    <ivy:resolve log="download-only" file="client/ivy.xml" conf="ide" />
    <ivy:cachepath pathid="client.deps" conf="ide" />
    <ivy:resolve log="download-only" file="shared/ivy.xml" conf="ide" />
    <ivy:cachepath pathid="shared.deps" conf="ide" />
    <ivy:resolve log="download-only" file="uitest/ivy.xml" conf="ide" />
    <ivy:cachepath pathid="uitest.deps" conf="ide" />
    <ivy:resolve log="download-only" file="buildhelpers/ivy.xml" />
    <ivy:cachepath pathid="buildhelpers.deps" />
    <ivy:resolve log="download-only" file="gwt/ivy.xml" conf="ide" />
    <ivy:cachepath pathid="gwt.deps" conf="ide" />

    <path id="classpath">
        <path location="bin" />
        <path location="build/classes" />
        <path refid="client-compiler.deps" />
        <path refid="server.deps" />
        <path refid="shared.deps" />
        <path refid="uitest.deps" />
        <path refid="client.deps" />
        <path refid="buildhelpers.deps" />
        <path refid="gwt.deps" />
        <path location="server/src" />
        <path location="shared/src" />
        <path location="uitest/src" />
        <path location="client/src" />
    </path>

    <target name="theme-and-default-widgetset" depends="default-widgetset, themes, vaadinPush.js">
    </target>
    <target name="themes">
        <antcall target="compile-theme">
            <param name="theme" value="base" />
        </antcall>
        <antcall target="compile-theme">
            <param name="theme" value="runo" />
        </antcall>
        <antcall target="compile-theme">
            <param name="theme" value="reindeer" />
        </antcall>
        <antcall target="compile-theme">
            <param name="theme" value="chameleon" />
        </antcall>
        <antcall target="compile-theme">
            <param name="theme" value="liferay" />
        </antcall>
    </target>

    <target name="compile-theme">
        <java classname="com.vaadin.buildhelpers.CompileTheme" failonerror="yes" fork="yes">
            <classpath refid="classpath" />
            <jvmarg value="-Djava.awt.headless=true" />
            <arg value="--theme" />
            <arg value="${theme}" />
            <arg value="--theme-folder" />
            <arg value="WebContent/VAADIN/themes" />
            <arg value="--version" />
            <arg value="${vaadin.version}" />
        </java>

    </target>


    <target name="default-widgetset">
        <antcall target="compile-widgetset">
            <param name="widgetset" value="com.vaadin.DefaultWidgetSet" />
        </antcall>
    </target>

    <target name="testing-widgetset">
        <antcall target="compile-widgetset">
            <param name="widgetset" value="com.vaadin.tests.widgetset.TestingWidgetSet" />
        </antcall>
    </target>

    <target name="compile-widgetset">
        <property name="module" value="${widgetset}" />
        <property name="module.output.dir" location="WebContent/VAADIN/widgetsets" />
        <property name="style" value="PRETTY" />
        <property name="localWorkers" value="2" />
        <property name="extraParams" value="" />

        <mkdir dir="${module.output.dir}" />

        <echo>Compiling ${module} to ${module.output.dir} with parameters -logLevel TRACE -style ${style} -localWorkers ${localWorkers} -strict ${extraParams}</echo>

        <!--<ivy:resolve log="download-only" inline="true" organisation="javax.validation" module="validation-api" 
            revision="1.0.0.GA"/> -->

        <!-- compile the module -->
        <java classname="com.google.gwt.dev.Compiler" classpathref="classpath" failonerror="yes" fork="yes" maxmemory="512m">
            <arg value="-workDir" />
            <arg value="${work.dir}" />
            <arg value="-logLevel" />
            <arg value="TRACE" />
            <arg value="-war" />
            <arg value="${module.output.dir}" />
            <arg value="-style" />
            <arg value="${style}" />

            <arg value="-localWorkers" />
            <arg value="${localWorkers}" />
            <arg value="-strict" />
            <arg line="${extraParams}" />
            <arg value="${module}" />

            <sysproperty key="vFailIfNotSerializable" value="true" />

            <jvmarg value="-Xss8M" />
            <jvmarg value="-XX:MaxPermSize=256M" />
            <jvmarg value="-Djava.awt.headless=true" />
            <jvmarg value="-Dgwt.usearchives=false" />
            <jvmarg value="-Dgwt.persistentunitcache=false" />
        </java>
    </target>
    <target name="vaadinPush.js">
        <ant antfile="${basedir}/push/build.xml" target="vaadinPush.js" dir="${basedir}/push" />
        <property name="js.output.dir" location="WebContent" />
        <property name="push.js.dir" location="${basedir}/push/result/js" />
        <copy todir="${js.output.dir}">
            <fileset dir="${push.js.dir}" includes="VAADIN/vaadinPush*">
            </fileset>
        </copy>
    </target>
</project>