<?xml version="1.0"?>

<project name="ext-parent">
	<import file="build-common.xml" />

	<target name="clean">
		<ant dir="ext-service" target="clean" inheritAll="false" />
		<ant dir="ext-impl" target="clean" inheritAll="false" />
		<ant dir="ext-web" target="clean" inheritAll="false" />

		<delete includeemptydirs="true" failonerror="false">
			<fileset
				dir="${app.server.bin.dir}"
				includes="*.log*"
			/>
		</delete>

		<delete failonerror="false">
			<fileset
				dir="${app.server.dir}/../data/hsql"
				includes="${database.name}.*"
			/>
		</delete>

		<delete failonerror="false">
			<fileset
				dir="${app.server.classes.portal.dir}"
				includes="portal-*.properties,system-*.properties"
			/>
		</delete>

		<delete includeemptydirs="true" failonerror="false">
			<fileset
				dir="${app.server.deploy.dir}"
				includes="*-ext/**,*-hook/**,*-layouttpl/**,*-portlet/**,*-theme/**,*-web/**"
			/>
		</delete>

		<delete failonerror="false">
			<fileset
				dir="${app.server.lib.global.dir}"
				excludes="${jdbc.drivers}"
			/>
		</delete>

		<delete failonerror="false">
			<fileset
				dir="${app.server.lib.portal.dir}"
				excludes="${jdbc.drivers}"
			/>
		</delete>

		<if>
			<equals arg1="${clean.log.dir}" arg2="true" />
			<then>
				<delete dir="${app.server.log.dir}" />
			</then>
		</if>

		<delete dir="${app.server.portal.dir}" />
		<delete file="${app.server.portal.dir}" />

		<if>
			<equals arg1="${clean.temp.dir}" arg2="true" />
			<then>
				<delete dir="${app.server.temp.dir}" />
			</then>
		</if>

		<if>
			<equals arg1="${clean.work.dir}" arg2="true" />
			<then>
				<delete dir="${app.server.work.dir}" />
			</then>
		</if>

		<antcall target="print-current-time" />
	</target>

	<target name="java2html">
		<delete dir="api" />

		<ant dir="ext-impl" target="java2html" inheritAll="false" />
	</target>

	<target name="javadoc">
		<ant dir="ext-impl" target="javadoc" inheritAll="false" />
	</target>

	<target name="deploy">
		<if>
			<equals arg1="${app.server.type}" arg2="glassfish" />
			<then>
				<delete dir="${app.server.portal.dir}" />
				<delete file="${app.server.portal.dir}" />
			</then>
		</if>

		<ant dir="ext-service" target="deploy" inheritAll="false" />
		<ant dir="ext-impl" target="deploy" inheritAll="false" />
		<ant dir="ext-web" target="deploy" inheritAll="false" />
		<ant dir="modules" target="deploy" inheritAll="false" />

		<copy todir="${app.server.dir}/../data/hsql">
			<fileset dir="sql">
				<include name="${database.name}.properties" />
				<include name="${database.name}.script" />
			</fileset>
		</copy>

		<antcall target="deploy-properties" />

		<copy todir="${app.server.lib.global.dir}">
			<fileset dir="ext-lib/global" />
			<fileset dir="lib/development" includes="hsql.jar,jtds.jar,mysql.jar,postgresql.jar" />
			<fileset dir="lib/global" />
		</copy>

		<if>
			<not>
				<equals arg1="${jdbc.drivers.optional.dir}" arg2="$${jdbc.drivers.optional.dir}" />
			</not>
			<then>
				<copy todir="${app.server.lib.global.dir}">
					<fileset
						dir="${jdbc.drivers.optional.dir}"
						includes="*.jar"
					/>
				</copy>
			</then>
		</if>

		<copy todir="${app.server.lib.portal.dir}">
			<fileset dir="ext-lib/portal" />
			<fileset dir="lib/portal" />
		</copy>

		<if>
			<equals arg1="${app.server.type}" arg2="glassfish" />
			<then>
				<copy todir="${app.server.lib.global.dir}">
					<fileset
						dir="lib/portal"
						includes="ccpp.jar,log4j.jar"
					/>
				</copy>
			</then>
		</if>

		<if>
			<equals arg1="${app.server.type}" arg2="geronimo-tomcat" />
			<then>
				<copy todir="${app.server.lib.portal.dir}">
					<fileset
						dir="lib/development"
						includes="saxpath.jar"
					/>
				</copy>

				<delete>
					<fileset
						dir="${app.server.lib.portal.dir}"
						includes="commons-logging.jar"
					/>
				</delete>
			</then>
		</if>

		<if>
			<equals arg1="${app.server.type}" arg2="jboss-tomcat" />
			<then>
				<delete>
					<fileset
						dir="${app.server.lib.portal.dir}"
						includes="jaxrpc.jar,stax.jar,xercesImpl.jar,xml-apis.jar"
					/>
				</delete>
			</then>
		</if>

		<if>
			<equals arg1="${app.server.type}" arg2="jetty" />
			<then>
				<copy todir="${app.server.lib.global.dir}">
					<fileset
						dir="lib/development"
						includes="jta.jar"
					/>
				</copy>
			</then>
		</if>

		<if>
			<or>
				<equals arg1="${app.server.type}" arg2="jonas-jetty" />
				<equals arg1="${app.server.type}" arg2="jonas-tomcat" />
			</or>
			<then>
				<copy todir="${app.server.lib.portal.dir}">
					<fileset
						dir="lib/development"
						includes="mail.jar"
					/>
				</copy>
			</then>
		</if>

		<if>
			<equals arg1="${app.server.type}" arg2="resin" />
			<then>
				<copy todir="${app.server.lib.global.dir}">
					<fileset
						dir="lib/development"
						includes="saxpath.jar"
					/>
				</copy>

				<delete>
					<fileset
						dir="${app.server.dir}/lib"
						includes="portlet-10.jar"
					/>
				</delete>
			</then>
		</if>

		<if>
			<equals arg1="${app.server.type}" arg2="tomcat" />
			<then>
				<copy file="classes/log4j.properties" todir="${app.server.classes.portal.dir}" />
				<copy file="classes/logging.properties" todir="${app.server.classes.portal.dir}" />

				<copy todir="${app.server.lib.support.dir}">
					<fileset
						dir="lib/development"
						includes="support-tomcat.jar"
					/>
				</copy>

				<copy todir="${app.server.lib.endorsed.dir}" flatten="true">
					<fileset
						dir="lib"
						includes="${endorsed.libraries}"
					/>
				</copy>

				<delete failonerror="false">
					<fileset
						dir="${app.server.lib.portal.dir}"
						includes="ccpp.jar"
					/>
				</delete>

				<copy todir="${app.server.lib.global.dir}">
					<fileset
						dir="lib/development"
						includes="activation.jar,jms.jar,jta.jar,mail.jar"
					/>
				</copy>

				<if>
					<equals arg1="${app.server.version}" arg2="5.5" />
					<then>

						<!--
						LEP-2981
						-->

						<copy todir="${app.server.dir}/common/lib">
							<fileset
								dir="lib/development"
								includes="naming-factory.jar"
							/>
						</copy>
					</then>
				</if>

				<copy todir="${app.server.temp.dir}/liferay/com/liferay/portal/deploy/dependencies">
					<fileset
						dir="lib/development"
						includes="quercus.jar,resin-util.jar,script-10.jar"
					/>
				</copy>
			</then>
		</if>

		<mkdir dir="${app.server.log.dir}" />
		<mkdir dir="${app.server.temp.dir}" />
		<mkdir dir="${app.server.work.dir}" />

		<if>
			<equals arg1="${app.server.type}" arg2="glassfish" />
			<then>
				<tstamp>
					<format property="tstamp.value" pattern="yyyyMMddkkmmssSSS" />
				</tstamp>

				<jar
					basedir="${app.server.portal.dir}"
					jarfile="${tstamp.value}"
				/>

				<delete dir="${app.server.portal.dir}" />

				<move file="${tstamp.value}" tofile="${app.server.portal.dir}" />
			</then>
		</if>

		<antcall target="print-current-time" />
	</target>

	<target name="deploy-properties">
		<copy todir="${app.server.classes.portal.dir}" overwrite="yes">
			<fileset dir="ext-impl/src" includes="portal-*.properties,system-*.properties" />
		</copy>
	</target>

	<target name="build-ext-dir" unless="lp.ext.dir.available">
		<copy todir="${lp.ext.dir}" filtering="true" preservelastmodified="true">
			<fileset dir="." />
		</copy>
	</target>

	<target name="upgrade-ext">
		<available file="${lp.ext.dir}/modules" type="dir" property="lp.ext.dir.available" />

		<antcall target="build-ext-dir" />

		<if>
			<not>
				<available file="${lp.ext.dir}/ext-service" type="dir" />
			</not>
			<then>
				<mkdir dir="${lp.ext.dir}/ext-service" />

				<copy todir="${lp.ext.dir}/ext-service" filtering="true">
					<fileset dir="ext-service" />
				</copy>
			</then>
		</if>

		<copy todir="${lp.ext.dir}" preservelastmodified="true">
			<fileset
				dir="."
				includes="app.server.properties"
			/>
			<fileset
				dir="."
				includes=".classpath,.project,build.properties,**/build-common*.xml,**/build-parent.xml"
			/>
		</copy>

		<mkdir dir="${lp.ext.dir}/ext-lib" />
		<mkdir dir="${lp.ext.dir}/ext-lib/development" />
		<mkdir dir="${lp.ext.dir}/ext-lib/global" />
		<mkdir dir="${lp.ext.dir}/ext-lib/portal" />

		<copy file="lib/readme.txt" todir="${lp.ext.dir}/ext-lib" />

		<sync includeemptydirs="true" todir="${lp.ext.dir}/lib" verbose="true">
			<fileset dir="lib" />
			<preserveintarget>
				<include name="**/.svn" />
				<include name="**/.svn/**" />
			</preserveintarget>
		</sync>

		<copy todir="${lp.ext.dir}/modules" preservelastmodified="true">
			<fileset dir="modules" />
		</copy>

		<copy todir="${lp.ext.dir}/sql" overwrite="yes">
			<fileset dir="sql">
				<exclude name="**/log/**" />
			</fileset>
		</copy>

		<copy todir="${lp.ext.dir}/tools" overwrite="yes">
			<fileset dir="tools" includes="javadoc.css" />
		</copy>
	</target>
</project>