<project name="SimpleBlogLogic" default="build" basedir=".">
	<target name="build" depends="init.build,build.woframework,javaclient,package" />

	<target name="install" depends="init.install,build.woframework,javaclient" />

	<target name="clean" depends="init.properties">
		<delete dir="bin" />
		<delete dir="dist" />
	</target>

	<!-- property determination  -->
	<target name="init.properties">
		<property file="build.properties" />

		<property name="wolips.properties" value="${user.home}${file.separator}Library${file.separator}Application Support${file.separator}WOLips${file.separator}wolips.properties" />
		<property file="${wolips.properties}" />
		<condition property="wo.properties.check.failed">
			<not>
				<and>
					<isset property="wo.system.frameworks" />
					<isset property="wo.local.frameworks" />
				</and>
			</not>
		</condition>
		<fail message="The properties 'wo.system.frameworks' and 'wo.local.frameworks' must be set. Check that your ${wolips.properties} is correct." if="wo.properties.check.failed" />

		<property name="wo.install.root" value="${wo.local.frameworks}" />
		<property name="build.framework.name" value="${project.name}" />
		<property name="build.framework.name.lowercase" value="${project.name.lowercase}" />
	</target>

	<!-- basic initializations  -->
	<target name="init.install" depends="init.properties">
		<tstamp />
		<property name="dest.dir" value="${wo.install.root}" />
	</target>

	<target name="init.build" depends="init.properties">
		<tstamp />
		<property name="dest.dir" value="dist" />
	</target>

  <target name="package">
    <tar destfile="${dest.dir}/${build.framework.name}.tar.gz"
        compression="gzip"
        longfile="gnu">
      <tarfileset dir="${dest.dir}">
        <include name="${build.framework.name}.framework/**"/>
      </tarfileset>
    </tar>
	</target>

	<!-- woproject tasks -->
	<target name="build.woframework" depends="compile">
		<taskdef name="woframework" classname="org.objectstyle.woproject.ant.WOFramework"/>

		<woframework name="${build.framework.name}" destDir="${dest.dir}" customInfoPListContent="${customInfoPListContent}" principalClass="${principalClass}" eoAdaptorClassName="${eoAdaptorClassName}" javaVersion="${javaVersion}" cfbundleversion="${cfBundleVersion}" cfbundleshortversion="${cfBundleShortVersion}" cfbundleID="${cfBundleID}">
			<classes dir="${classes.dir}">
				<includesfile name="woproject/classes.include.patternset" />
				<excludesfile name="woproject/classes.exclude.patternset" />
				<exclude if="javaClient" name="**/client/**/*.*"/>
			</classes>

			<wsresources dir=".">
				<includesfile name="woproject/wsresources.include.patternset" />
				<excludesfile name="woproject/wsresources.exclude.patternset" />
			</wsresources>

			<resources dir=".">
				<includesfile name="woproject/resources.include.patternset" />
				<excludesfile name="woproject/resources.exclude.patternset" />
				<exclude if="javaClient" name="**/client/**/*.*"/>
			</resources>

			<lib dir="Libraries">
				<include name="*.jar" />
			</lib>
		</woframework>
	</target>
	
	<target name="javaclient" if="javaClient" depends="build.woframework">
		<mkdir dir="${dest.dir}/${build.framework.name}.framework/WebServerResources/Java" />
		<jar basedir="${classes.dir}" excludes="**/server/**/*.*, **/server/**/" jarfile="${dest.dir}/${build.framework.name}.framework/WebServerResources/Java/${build.framework.name}.jar"/>
	</target>

	<target name="compile" depends="init.build">
		<taskdef name="wocompile" classname="org.objectstyle.woproject.ant.WOCompile" />

		<mkdir dir="bin" />
		<wocompile srcdir="Sources" destdir="bin">
			<frameworks root="ProjectLocal" embed="false" eclipse="true" />
			<frameworks root="External" embed="false" eclipse="true" />
			<frameworks root="Local" embed="false" eclipse="true" />
			<frameworks root="User" embed="false" eclipse="true" />
			<frameworks root="System" embed="false" eclipse="true" />
			<frameworks root="Network" embed="false" eclipse="true" />
			<classpath>
				<fileset dir="Libraries">
					<include name="*.jar" />
				</fileset>
				<fileset dir="${wo.extensions}">
					<include name="*.jar" />
				</fileset>
			</classpath>
		</wocompile>
		<java jar="Documentation/eomodeldoc.jar"
		      fork="true"
		      maxmemory="256m">
		    <arg value="-templates" />
		    <arg value="Documentation/EOModelDocTemplates" />
			<arg value="-model" />
			<arg value="Resources/SimpleBlog.eomodeld" />
		    <arg value="-output" />
		    <arg value="Documentation/ModelDoc" />
		    <arg value="-modelgroup" />
		    <arg value="." />
		</java>
		<java jar="Documentation/eomodeldoc.jar"
		      fork="true"
		      maxmemory="256m">
		    <arg value="-templates" />
		    <arg value="Documentation/EORuleModelDocTemplates" />
			<arg value="-model" />
			<arg value="Resources/SimpleBlog.eomodeld" />
		    <arg value="-output" />
		    <arg value="Documentation/RuleModelDoc" />
		    <arg value="-modelgroup" />
		    <arg value="." />
		</java>
	</target>
</project>
