<project name="webdsl-build" default="help">

<import file="webdsl-build-command.xml"/>
<import file="webdsl-build-deploy.xml"/>
<import file="webdsl-build-new.xml"/>
<import file="webdsl-build-help.xml"/>
<import file="webdsl-build-check.xml"/>
<import file="webdsl-build-clean.xml"/>
<import file="webdsl-build-index.xml"/>

<property name="libdir" value="${templatedir}/template-java-servlet/lib"/>
<property name="testlibdir" value="${templatedir}/template-java-servlet/lib-test"/>
<property name="newprojectdir" value="${templatedir}/new_project"/>
<property name="javatemplatedir" value="${templatedir}/template-java-servlet"/>
<property name="webdslsrctemplatedir" value="${templatedir}/template-webdsl"/>


<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${testlibdir}/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

<taskdef name="TaskCopyAllDirsHavingName" classname="org.webdsl.ant.TaskCopyAllDirsHavingName"/>

<!--
<target name="check-servletapp-dir-exists">
<if>
<available file="${currentdir}/${generate-dir}" type="dir"/>
<then></then>
<else>
<property name="servletapp-dir-not-exists" value="y"/>
</else>
</if>
</target>
-->


<!-- this compiler daemon is used with application.ini option 'usecompileserver=true' -->
<target name="start-compiler-server">
<echo>
${testlibdir}/nailgun-server-0.9.2-SNAPSHOT.jar
${webdsl-java-cp}
</echo>
<java classname="com.martiansoftware.nailgun.NGServer" failonerror="true" fork="true">
<classpath>
<pathelement path="${testlibdir}/nailgun-server-0.9.2-SNAPSHOT.jar"/>
<pathelement path="${webdsl-java-cp}"/>
</classpath>
<jvmarg line="-Xmx2G -Xss12m "/>
</java>
</target>


<target name="stats">
<property name="show-app-statistics" value="true"/>
<antcall target="build"/>
</target>


<target name="setup-application-template" unless="stop-because-load-config-failed">
<antcall target="copy-template-files"/>
<antcall target="configure-build-properties"/>
<antcall target="extract-archives"/>
</target>


<target name="copy-template-files">

<fail unless="requestlogoption"/>
<fail unless="sessiontimeoutoption"/>
<fail unless="formatjavacodeoption"/>
<fail unless="statisticsoption"/>
<fail unless="debugoption"/>
<fail unless="debughibernate"/>
<fail unless="debuglog4j1"/>
<fail unless="verboseoption"/>
<fail unless="extratypecheckoption"/>
<fail unless="dbstorageoption"/>
<fail unless="dbfileoption"/>
<fail unless="tomcatmanager"/>
<fail unless="tomcatuser"/>
<fail unless="tomcatpassword"/>
<fail unless="appname"/>

<mkdir dir="${currentdir}/${generate-dir}"/>

<if>
<equals arg1="${passtestoption}" arg2="--test" />
<then>
<echo level="info">Copying template for tests</echo>
<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/WEB-INF/lib">
<fileset dir="${javatemplatedir}/lib-test"/>
</copy>
<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/tomcat">
<fileset dir="${javatemplatedir}/tomcat"/>
</copy>
</then>
<else>
<mkdir dir="${currentdir}/${generate-dir}/lib-test"/>
</else>
</if>

<echo level="info">Copying template for webdsl application</echo>

<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/">
<fileset dir="${javatemplatedir}/html"/>
</copy>
<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/images">
<fileset dir="${javatemplatedir}/images"/>
</copy>

<!--<copy preservelastmodified="true" failonerror="false" todir="${currentdir}/${generate-dir}/search/analyzerfiles">
<fileset dir="${javatemplatedir}/search/analyzerfiles"/>
</copy>-->
<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/javascript">
<fileset dir="${javatemplatedir}/javascript"/>
</copy>
<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/WEB-INF/lib">
<fileset dir="${javatemplatedir}/lib"/>
</copy>
<copy preservelastmodified="true" todir="${currentdir}/.servletapp/src-template">
<fileset dir="${javatemplatedir}/src-template"/>
</copy>
<copy preservelastmodified="true" todir="${currentdir}/.servletapp/src-template/utils">
<fileset dir="${javatemplatedir}/src-template/utils"/>
</copy>
<copy preservelastmodified="true" todir="${currentdir}/${generate-dir}/stylesheets">
<fileset dir="${javatemplatedir}/stylesheets"/>
</copy>

<!-- copy webdsl src templates -->
<copy preservelastmodified="true" todir="${currentdir}/.servletapp/src-webdsl-template">
<fileset dir="${webdslsrctemplatedir}/"/>
</copy>

</target>

<target name="configure-build-properties">

<echo level="info">Configuring .servletapp/build.properties</echo>
<propertyregex property="javatemplatedir"
input="${javatemplatedir}"
regexp="\\"
replace="/"
override="true" />
<echo level="info">template dir: ${javatemplatedir}</echo>
<propertyregex property="tomcatpath"
input="${tomcatpath}"
regexp="\\"
replace="/"
override="true" />
<echo level="info">tomcat dir: ${tomcatpath}</echo>
<propertyregex property="indexdir"
input="${indexdir}"
regexp="\\"
replace="/"
override="true" />
<propertyregex property="indexdir"
input="${indexdir}"
regexp="/$"
replace=""
override="true" />
<echo level="info">lucene index dir: ${indexdir}</echo>
<if>
<not><equals arg1="${ehcachediskstorepath}" arg2="$${ehcachediskstorepath}" /></not>
<then><echo level="info">EhCache diskstore dir: ${ehcachediskstorepathwithappname}</echo></then>
</if>
<if>
<and>
<equals arg1="${db}" arg2="postgres"/>
<equals arg1="${dbserver}" arg2="$${dbserver}"/>
</and>
<then><property name="dbserver" value="localhost:5432"/></then>
</if>
<copy overwrite="true" todir="${currentdir}/.servletapp">
<fileset dir="${javatemplatedir}/">
<include name="build.properties"/>
<include name="build.xml"/>
<include name="build.reindex.xml"/>
<include name="webdsl-reindex"/>
</fileset>
<filterchain>
<replacetokens>
<token key="APPNAME" value="${appname}"/>
<token key="TEMPLATEPATH" value="${javatemplatedir}"/>
<token key="DEBUGLOG4J1" value="${debuglog4j1}"/>
<token key="SMTPHOST" value="${smtphost}"/>
<token key="SMTPPORT" value="${smtpport}"/>
<token key="SMTPUSER" value="${smtpuser}"/>
<token key="SMTPPASS" value="${smtppass}"/>
<token key="SMTPAUTHENTICATE" value="${smtpauthenticate}"/>
<token key="SMTPPROTOCOL" value="${smtpprotocol}"/>
<token key="DB" value="${db}"/>
<token key="DBFILEOPTION" value="${dbfileoption}"/>
<token key="DEBUGHIBERNATE" value="${debughibernate}"/>
<token key="DBMODE" value="${dbmode}"/>
<token key="DBSTORAGEOPTION" value="${dbstorageoption}"/>
<token key="DBSERVER" value="${dbserver}"/>
<token key="DBNAME" value="${dbname}"/>
<token key="DBUSER" value="${dbuser}"/>
<token key="DBPASSWORD" value="${dbpassword}"/>
<token key="DBJNDIPATH" value="${dbjndipath}"/>
<token key="TOMCATMANAGER" value="${tomcatmanager}"/>
<token key="TOMCATUSER" value="${tomcatuser}"/>
<token key="TOMCATPASSWORD" value="${tomcatpassword}"/>
<token key="TOMCATPATH" value="${tomcatpath}"/>
<token key="HTTPSPORT" value="${httpsport}"/>
<token key="HTTPPORT" value="${httpport}"/>
<token key="WARFILENAME" value="${warfilename}"/>
<token key="GENERATEDIR" value="${generate-dir}"/>
<token key="INDEXDIR" value="${indexdir}"/>
<token key="SEARCHSTATS" value="${searchstats}"/>
<token key="EHCACHETIMEOUT" value="${ehcachetimeout}"/>
<token key="EHCACHEDISKSTORE" value="${ehcachediskstore}"/>
<token key="JAVACMEM" value="${javacmem}"/>
<token key="REQUESTLOG" value="${requestlogoption}"/>
<token key="APPURLFORRENDERWITHOUTREQUEST" value="${appurlforrenderwithoutrequest}"/>
<token key="WIKITEXT_HARDWRAPS" value="${wikitext-hardwraps}"/>
<token key="WIKITEXT_ANCHORS" value="${wikitext-anchors}"/>
<token key="NUMCACHEDPAGES" value="${numcachedpages}"/>
<token key="TRANSACTIONRETRIES" value="${transactionretries}"/>
</replacetokens>
</filterchain>
</copy>

</target>


<target name="extract-archives">
<antcall target="extract-archives-in-dir"><param name="dir-of-archives-to-extract" value="javascript"/></antcall>
<antcall target="extract-archives-in-dir"><param name="dir-of-archives-to-extract" value="stylesheets"/></antcall>
</target>


<target name="extract-archives-in-dir">
<fail unless="dir-of-archives-to-extract"/>
<fail unless="generate-dir"/>

<untar overwrite="false" dest="${currentdir}/${generate-dir}/${dir-of-archives-to-extract}" compression="gzip">
<fileset dir="${currentdir}/${generate-dir}/${dir-of-archives-to-extract}">
<include name="**/*.tar.gz"/>
</fileset>
</untar>
</target>


<target name="copy-application-files-for-build">
<echo level="info">Copying your application files</echo>

<!-- name="lib" also matches names ending with lib (e.g. elib), use name="/lib" for exact dir name -->
<TaskCopyAllDirsHavingName basedir="${currentdir}" name="/lib" extension="class,jar" to="${currentdir}/${generate-dir}/WEB-INF/lib/" exclude="WebContent, .servletapp, images, stylesheets, search, html"/>

<TaskCopyAllDirsHavingName basedir="${currentdir}" name="/javascript" to="${currentdir}/${generate-dir}/javascript/" exclude="WebContent, .servletapp, images, stylesheets, search, html"/>

<TaskCopyAllDirsHavingName basedir="${currentdir}" name="/images" to="${currentdir}/${generate-dir}/images/" exclude="WebContent, .servletapp, javascript, stylesheets, search, html"/>

<TaskCopyAllDirsHavingName basedir="${currentdir}" name="/search/analyzerfiles" to="${currentdir}/${generate-dir}/analyzerfiles/" exclude="WebContent, .servletapp, javascript, images, stylesheets, html"/>

<TaskCopyAllDirsHavingName basedir="${currentdir}" name="/stylesheets" to="${currentdir}/${generate-dir}/stylesheets/" exclude="WebContent, .servletapp, javascript, images, search, html"/>

<TaskCopyAllDirsHavingName basedir="${currentdir}" name="/html" to="${currentdir}/${generate-dir}/" exclude="WebContent, .servletapp, javascript, images, stylesheets, search"/>


<copy failonerror="false" overwrite="true" todir="${currentdir}/.servletapp/src-template">
<fileset dir="${currentdir}/">
<include name="*.ctree"/>
</fileset>
<fileset dir="${currentdir}/">
<include name="*.tbl"/>
</fileset>
</copy>
</target>


<target name="invoke-webdslc" unless="stop-because-load-config-failed">
<antcall target="copy-application-files-for-build"/>
<antcall target="invoke-webdslc-compile"/>
</target>

<taskdef name="taskjavawebdslused" classname="org.webdsl.ant.TaskJavaWebDSLUsed"/>

<condition property="skip-webdsl-compile">
<or>
<isset property="stop-because-load-config-failed"/>
<isset property="skip-webdsl-compile-because-no-app-file-changed"/>
</or>
</condition>

<target name="invoke-webdslc-compile" unless="skip-webdsl-compile">
<echo level="info">Building application</echo>

<if><equals arg1="${passtestoption}" arg2="$${passtestoption}"/>
<then><property name="passtestoption" value=""/></then>
</if>
<if><equals arg1="${build-id}" arg2="$${build-id}"/>
<then><property name="build-id-option" value=""/></then>
<else><property name="build-id-option" value="--build-id ${build-id}"/></else>
</if>
<if><equals arg1="${compilebuiltins}" arg2="$${compilebuiltins}"/>
<then><property name="compilebuiltins-option" value=""/></then>
<else><property name="compilebuiltins-option" value="--compile-built-ins"/></else>
</if>
<if><equals arg1="${show-app-statistics}" arg2="$${show-app-statistics}"/>
<then><property name="appstatistics-option" value=""/></then>
<else><property name="appstatistics-option" value="--app-statistics"/></else>
</if>

<fail unless="webdslexec"/>
<fail unless="appname"/>
<fail unless="sessiontimeoutoption"/>
<fail unless="statisticsoption"/>
<fail unless="formatjavacodeoption"/>
<fail unless="verboseoption"/>
<fail unless="cachingoption"/>
<fail unless="debugoption"/>
<fail unless="passtestoption"/>
<fail unless="extratypecheckoption"/>
<fail unless="build-id-option"/>
<fail unless="custom-compile-units-option"/>
<fail unless="compile-units-cache-option"/>
<fail unless="jrebel-option"/>
<fail unless="postgres-option"/>
<fail unless="inlinetemplates-option"/>
<fail unless="appstatistics-option"/>

<property name="webdsl-args" value="--servlet -i ../${appname}.app ${sessiontimeoutoption} ${statisticsoption}
${formatjavacodeoption} ${verboseoption} ${debugoption} ${passtestoption} ${extratypecheckoption} ${cachingoption}
${build-id-option} --dir &quot;${currentdir}/.servletapp&quot; ${compilebuiltins-option} --indexdir ${indexdir}
${custom-compile-units-option} ${compile-units-cache-option} ${jrebel-option} ${showoptimizationwarningsoption}
${printoptimizationsoption} ${queryoptimizationoption} ${postgres-option} ${debugac-option} ${inlinetemplates-option}
${appstatistics-option}"/>
<property name="webdsl-workdir" value="${currentdir}/.servletapp"/>
<antcall target="invoke-webdsl-core" />
</target>

<target name="invoke-webdsl-core">
<fail unless="webdsl-args"/>
<fail unless="webdsl-workdir"/>

<echo level="info">webdsl arguments: ${webdsl-args}</echo>

<taskjavawebdslused/>

<if>
<equals arg1="${using-webdsl-java}" arg2="true"/>
<then>
<property name="webdsl-java-options" value="-Xmx2G -Xss12m"/>
<if>
<equals arg1="${webdsl-java-cp}" arg2="$${webdsl-java-cp}"/>
<then>
<property name="webdsl-java-cp" value="${templatedir}/bin/webdsl.jar"/>
</then>
</if>
<if>
<equals arg1="${stratego-jar-cp}" arg2="$${stratego-jar-cp}"/>
<then>
<property name="stratego-jar-cp" value="strategoxt.jar"/>
</then>
</if>
<echo level="info">Directory: ${currentdir}/${generate-dir}</echo>

<!--
When runnning from Eclipse in the plugin, the classpatch should not be set,
that way the already loaded stratego and webdsl jars will be used,
instead of loading an additional jar from the filesystem each build.
-->
<if>
<isset property="eclipse.running"/>
<then>
<java classname="org.webdsl.webdslc.Main" failonerror="true">
<arg line="${webdsl-args}"/>
<classpath>
<pathelement path="${externaljarx}" />
<pathelement path="${eclipse.spoofaximp.strategojar}" />
<pathelement path="${plugindir}/include/webdsl.jar" />
</classpath>
</java>
</then>
<else>
<if>
<isset property="usecompileserver"/>
<then>
<exec executable="ng" failonerror="true" dir="${webdsl-workdir}">
<arg value="org.webdsl.webdslc.Main"/>
<arg line="${webdsl-args}"/>
</exec>
</then>
<else>
<echo level="info">Java options: ${webdsl-java-options}</echo>
<echo level="info">Classpath: ${webdsl-java-cp}, ${stratego-jar-cp}</echo>
<java classname="org.webdsl.webdslc.Main" failonerror="true" dir="${webdsl-workdir}" fork="true">
<classpath>
<pathelement path="${webdsl-java-cp}"/>
<pathelement path="${stratego-jar-cp}"/>
</classpath>
<jvmarg line="${webdsl-java-options}"/>
<arg line="${webdsl-args}"/>
</java>
</else>
</if>
</else>
</if>
</then>
<else>
<exec executable="${webdslexec}" dir="${webdsl-workdir}" failonerror="true">
<arg line="${webdsl-args}"/>
</exec>
</else>
</if>
</target>


<target name="suggest-to-create-application-ini">
<input
message="Cannot find application.ini. This file is necessary to build the application for you. Want to create an application.ini now? [y/n]:"
addproperty="loadconfig.createini"
defaultvalue="n"
/>
<if>
<equals arg1="${loadconfig.createini}" arg2="y" />
<then>
<basename property="loadconfig.dirname" file="${currentdir}"/>
<input
message="Application name, also the name of the main .app file (without .app extension):"
addproperty="new.appname"
defaultvalue="${loadconfig.dirname}"
/>
<antcall target="create-config">
<param name="dir-for-application-ini" value="${currentdir}" />
</antcall>
<echo level="info">Created application.ini.</echo>
</then>
<else>
<property name="stop-because-load-config-failed" value="y"/>
</else>
</if>
</target>

<taskdef name="taskconvertapplicationini" classname="org.webdsl.ant.TaskConvertApplicationIni"/>

<!-- to be used in the 'depends' property of a target, so you don't have to list all the vars -->
<target name="load-config" unless="${config-loaded}">
<if>
<available file="${currentdir}/application.ini"/>
<then>
<echo level="info">Loading application settings (application.ini)</echo>
<loadproperties srcFile="${currentdir}/application.ini"/>
<if>
<equals arg1="${appname}" arg2="$${appname}"/>
<then>
<echo level="info">Updating application.ini to new syntax</echo>

<taskconvertapplicationini/>

<echo level="info">Retry loading application settings (application.ini)</echo>
<loadproperties srcFile="${currentdir}/application.ini"/>
</then>
</if>
</then>
<else>
<antcallback target="suggest-to-create-application-ini" return="stop-because-load-config-failed"/>
<if>
<equals arg1="${stop-because-load-config-failed}" arg2="$${stop-because-load-config-failed}"/>
<then>
<echo level="info">Loading application settings (application.ini)...</echo>
<loadproperties srcFile="${currentdir}/application.ini"/>
</then>
</if>
</else>
</if>

<fail unless="appname" message="Build stopped because no 'appname' was specified in application.ini"/>
<available file="${currentdir}/${appname}.app" property="does-main-app-file-exist"/>
<fail unless="does-main-app-file-exist" message="Build stopped because the main ${appname}.app file does not exist."/>

<if>
<equals arg1="${requestlog}" arg2="$${requestlog}" />
<then><property name="requestlogoption" value="false"/></then>
<else><property name="requestlogoption" value="${requestlog}"/></else>
</if>
<if>
<equals arg1="${sessiontimeout}" arg2="$${sessiontimeout}" />
<then><property name="sessiontimeoutoption" value="--session-timeout 1440"/></then>
<else><property name="sessiontimeoutoption" value="--session-timeout ${sessiontimeout}"/></else>
</if>
<if>
<equals arg1="${formatjavacode}" arg2="true" />
<then><property name="formatjavacodeoption" value="--format-java-code"/></then>
<else><property name="formatjavacodeoption" value=""/></else>
</if>
<if>
<equals arg1="${statistics}" arg2="true" />
<then><property name="statisticsoption" value="--statistics"/></then>
<else><property name="statisticsoption" value=""/></else>
</if>
<if>
<equals arg1="${debug}" arg2="true" />
<then>
<property name="debugoption" value="--debug"/>
<property name="debughibernate" value="hibernate.show_sql=true"/>
<property name="debuglog4j1" value="debug"/>
</then>
<else>
<property name="debugoption" value=""/>
<property name="debughibernate" value=""/>
<property name="debuglog4j1" value="error"/>
</else>
</if>
<if>
<equals arg1="${verbose}" arg2="$${verbose}" />
<then><property name="verboseoption" value=""/></then>
<else><property name="verboseoption" value="--verbose ${verbose}"/></else>
</if>
<if>
<equals arg1="${caching}" arg2="false" />
<then><property name="cachingoption" value=""/></then>
<else>
<property name="cachingoption" value="--enable-caching 1"/>
<property name="caching" value="1"/>
</else>
</if>
<if>
<equals arg1="${extratypecheck}" arg2="true" />
<then><property name="extratypecheckoption" value="--extra-typecheck"/></then>
<else><property name="extratypecheckoption" value=""/></else>
</if>
<if>
<equals arg1="${dbstorage}" arg2="myisam" />
<then><!--<property name="dbstorageoption" value="utils.MySQLMyISAMDialectUTF8"/>-->
<echo>dbstorage=MyISAM is no longer allowed, lack of database transactions causes incorrect behavior.</echo>
<fail message="dbstorage=MyISAM no longer allowed"/>
</then>
<else><property name="dbstorageoption" value="utils.MySQL5InnoDBDialectUTF8"/></else>
</if>
<if>
<equals arg1="${dbfile}" arg2="$${dbfile}" />
<then><property name="dbfileoption" value="/dev/null"/></then>
<else><property name="dbfileoption" value="${dbfile}"/></else>
</if>
<if>
<equals arg1="${db}" arg2="postgres" />
<then><property name="postgres-option" value="--postgres"/></then>
<else><property name="postgres-option" value=""/></else>
</if>
<if>
<equals arg1="${tomcatmanager}" arg2="$${tomcatmanager}" />
<then><property name="tomcatmanager" value="http://localhost:8080/manager"/></then>
</if>
<if>
<equals arg1="${tomcatuser}" arg2="$${tomcatuser}" />
<then><property name="tomcatuser" value="tomcat"/></then>
</if>
<if>
<equals arg1="${tomcatpassword}" arg2="$${tomcatpassword}" />
<then><property name="tomcatpassword" value="tomcat"/></then>
</if>
<if>
<equals arg1="${rootapp}" arg2="true" />
<then><property name="warfilename" value="ROOT"/></then>
<else><property name="warfilename" value="${appname}"/></else>
</if>
<if>
<equals arg1="${httpsport}" arg2="$${httpsport}" />
<then><property name="httpsport" value="443"/></then>
</if>
<if>
<equals arg1="${httpport}" arg2="$${httpport}" />
<then><property name="httpport" value="80"/></then>
</if>
<if>
<equals arg1="${indexdir}" arg2="$${indexdir}" />
<then><property name="indexdir" value="/var/indexes"/></then>
</if>
<if>
<equals arg1="${optimizationwarnings}" arg2="true" />
<then><property name="showoptimizationwarningsoption" value="--show-optimization-warnings"/></then>
<else><property name="showoptimizationwarningsoption" value=""/></else>
</if>
<if>
<equals arg1="${printoptimizations}" arg2="true" />
<then><property name="printoptimizationsoption" value="--print-optimizations"/></then>
<else><property name="printoptimizationsoption" value=""/></else>
</if>
<if>
<equals arg1="${queryoptimization}" arg2="$${queryoptimization}" />
<then><property name="queryoptimizationoption" value="--enable-query-optimization 0"/></then>
<else><property name="queryoptimizationoption" value="--enable-query-optimization ${queryoptimization}"/></else>
</if>
<if>
<equals arg1="${debugac}" arg2="true" />
<then><property name="debugac-option" value="--debugac"/></then>
<else><property name="debugac-option" value=""/></else>
</if>
<if>
<equals arg1="${searchstats}" arg2="$${searchstats}" />
<then><property name="searchstats" value="false"/></then>
</if>
<if>
<equals arg1="${ehcachetimeout}" arg2="$${ehcachetimeout}" />
<then><property name="ehcachetimeout" value="900"/></then>
<else><property name="ehcachetimeout" value="${ehcachetimeout}"/></else>
</if>
<if>
<equals arg1="${ehcachediskstorepath}" arg2="$${ehcachediskstorepath}" />
<then><property name="ehcachediskstore" value=""/></then>
<else>
<propertyregex property="ehcachediskstorepath"
input="${ehcachediskstorepath}"
regexp="\\"
replace="/"
override="true" />
<propertyregex property="ehcachediskstorepath"
input="${ehcachediskstorepath}"
regexp="/$"
replace=""
override="true" />
<property name="ehcachediskstorepathwithappname" value="${ehcachediskstorepath}/${appname}"/>
<property name="ehcachediskstore" value="utils.ehcache.diskstore.path=${ehcachediskstorepathwithappname}"/>
</else>
</if>
<if>
<equals arg1="${javacmem}" arg2="$${javacmem}" />
<then><property name="javacmem" value="1550m"/></then>
</if>
<if>
<equals arg1="${custom-compile-units}" arg2="true" />
<then><property name="custom-compile-units-option" value="--custom-compile-units"/></then>
<else><property name="custom-compile-units-option" value=""/></else>
</if>
<if>
<equals arg1="${compile-units-cache}" arg2="false" />
<then><property name="compile-units-cache-option" value=""/></then>
<else><property name="compile-units-cache-option" value="--compile-units-cache"/></else>
</if>
<if>
<equals arg1="${jrebel}" arg2="true" />
<then><property name="jrebel-option" value="--jrebel"/></then>
<else><property name="jrebel-option" value=""/></else>
</if>
<if>
<equals arg1="${appurlforrenderwithoutrequest}" arg2="$${appurlforrenderwithoutrequest}" />
<then><property name="appurlforrenderwithoutrequest" value=""/></then>
</if>
<if>
<equals arg1="${wikitext-hardwraps}" arg2="$${wikitext-hardwraps}" />
<then><property name="wikitext-hardwraps" value="false"/></then>
</if>
<if>
<equals arg1="${wikitext-anchors}" arg2="$${wikitext-anchors}" />
<then><property name="wikitext-anchors" value="false"/></then>
</if>
<if>
<equals arg1="${inlinetemplates}" arg2="false" />
<then><property name="inlinetemplates-option" value=""/></then>
<else><property name="inlinetemplates-option" value="--inlinetemplates"/></else>
</if>

<property name="config-loaded" value="1" />
<echo level="info">${appname}</echo>

</target>

<target name="make-app-code-without-template-copy">
<fail unless="config-loaded"/>
<echo level="info">appname: ${appname}</echo>
<antcall target="configure-build-properties"/>
<antcall target="invoke-webdslc" />
</target>

<target name="make-app-code">
<fail unless="config-loaded"/>
<echo level="info">appname: ${appname}</echo>
<antcall target="setup-application-template"/>
<antcall target="invoke-webdslc" />
</target>


<target name="make-app">
<antcallback target="make-app-code" return="appname"/>
<if>
<equals arg1="${show-app-statistics}" arg2="$${show-app-statistics}" />
<then>
<echo level="info">Now compiling generated Java code</echo>
<ant dir="${currentdir}/.servletapp" antfile="${currentdir}/${generate-dir}/build.xml" target="compile"/>
</then>
</if>
</target>


<target name="build" depends="load-config, clean-if-needed">
<antcall target="make-app"/>
<if>
<equals arg1="${show-app-statistics}" arg2="$${show-app-statistics}" />
<then>
<echo level="info">Build done. Run 'webdsl deploy' or 'webdsl tomcatdeploy' to deploy (also creates a war file).</echo>
</then>
</if>
</target>


<target name="clean-if-needed" depends="load-config">
<if>
<not><equals arg1="${caching}" arg2="1" /></not>
<then><echo>full clean ++++++++++++</echo>
<antcall target="clean-generated-java" />
</then>
</if>
</target>


<target name="rebuild" depends="load-config, clean-if-needed">
<antcall target="invoke-webdslc-compile" />
<ant dir="${currentdir}/.servletapp" antfile="${currentdir}/${generate-dir}/build.xml" target="compile"/>
</target>


<target name="rebuilddeploy" depends="load-config, clean-if-needed">
<antcall target="invoke-webdslc-compile" />
<ant dir="${currentdir}/.servletapp" antfile="${currentdir}/${generate-dir}/build.xml" target="compile"/>
<ant dir="${currentdir}/.servletapp" antfile="${currentdir}/${generate-dir}/build.xml" target="tomcatdeploy"/>
</target>


<target name="build-without-java-compile" depends="load-config, clean-if-needed">
<antcall target="make-app-code"/>
</target>

<target name="build-without-java-compile-without-template-copy" depends="load-config, clean-if-needed">
<antcall target="make-app-code-without-template-copy"/>
</target>

<target name="build-without-java-compile-code-only" depends="load-config, clean-if-needed">
<echo level="info">appname: ${appname}</echo>
<antcall target="invoke-webdslc-compile" />
</target>

<target name="version">
<echo level="info">Invoking WebDSL compiler</echo>
<property name="webdsl-args" value="--version"/>
<property name="webdsl-workdir" value="${currentdir}"/>
<antcall target="invoke-webdsl-core" />
</target>

</project>