<?xml version="1.0"?>

<project name="ext-impl-parent" xmlns:antelope="antlib:ise.antelope.tasks">
	<import file="../build-common.xml" />

	<property name="jar.file" value="${ant.project.name}" />
	<property name="service.file" value="service.xml" />

	<target name="clean">
		<delete dir="classes" />
		<delete file="${jar.file}.jar" failonerror="false" />
	</target>

	<target name="compile">
		<mkdir dir="classes" />

		<trycatch property="exception.message">
			<try>
				<if>
					<equals arg1="${javac.compiler}" arg2="modern" />
					<then>
						<javac
							classpathref="project.classpath"
							compiler="${javac.compiler}"
							debug="${javac.debug}"
							deprecation="${javac.deprecation}"
							destdir="classes"
							fork="${javac.fork}"
							memoryMaximumSize="${javac.memoryMaximumSize}"
							nowarn="${javac.nowarn}"
							srcdir="src"
						/>
					</then>
					<else>
						<javac
							classpathref="project.classpath"
							compiler="${javac.compiler}"
							debug="${javac.debug}"
							deprecation="${javac.deprecation}"
							destdir="classes"
							nowarn="${javac.nowarn}"
							srcdir="src"
						/>
					</else>
				</if>
			</try>
			<catch>
				<antelope:stringutil string="${exception.message}" property="exception.message.index">
					<indexof string="java.lang.reflect.InvocationTargetException" fromindex="0" />
				</antelope:stringutil>

				<if>
					<not>
						<equals arg1="${exception.message.index}" arg2="-1" />
					</not>
					<then>
						<fail>
.

${exception.message}

A compilation error occurred because ECJ does not have enough memory.

To fix this, set the environment variable ANT_OPTS to the recommended value of
"-Xms256m -Xmx512m".
						</fail>
					</then>
					<else>
						<fail>
.

${exception.message}
						</fail>
					</else>
				</if>
			</catch>
		</trycatch>

		<copy todir="classes">
			<fileset dir="src" excludes="**/*.java" />
		</copy>
	</target>

	<target name="jar" depends="compile">
		<jar
			basedir="classes"
			excludes="portal-*.properties,system-*.properties"
			jarfile="${jar.file}.jar"
		/>
	</target>

	<target name="java2html">
		<java
			classname="com.liferay.util.Java2Html"
			classpathref="project.classpath"
			fork="true"
		>
			<arg value="java -classpath ${project.dir}/lib/development/j2h.jar j2h" />
			<arg value="src" />
			<arg value="${java2html.dir}" />
		</java>

		<move file="${java2html.dir}/stylesheet.css" tofile="${java2html.dir}/java2html.css" />

		<antcall target="javadoc" />

		<replace dir="${java2html.dir}">
			<include name="**/package-summary.html" />
			<replacefilter
				token="/\"
				value="/"
			/>
		</replace>
	</target>

	<target name="javadoc">
		<mkdir dir="${javadoc.dir}" />

		<javadoc
			additionalparam="-J-Xmx128m"
			breakiterator="yes"
			classpathref="project.classpath"
			destdir="${javadoc.dir}"
			packagenames="*.*"
			sourcepath="src"
			stylesheetfile="${project.dir}/tools/javadoc.css"
		/>
	</target>

	<target name="deploy" depends="jar">
		<ant dir="../ext-service" target="deploy" inheritAll="false" />

		<antcall target="deploy-properties" />

		<antcall target="deploy-impl-jar" />
	</target>

	<target name="deploy-properties">
		<ant dir=".." target="deploy-properties" inheritAll="false" />
	</target>

	<target name="build-lang">
		<antcall target="build-lang-cmd">
			<param name="lang.dir" value="src/content" />
			<param name="lang.file" value="Language-ext" />
		</antcall>
	</target>

	<target name="build-lang-cmd">
		<if>
			<isset property="lang.code" />
			<then>
				<antcall target="build-lang-native2ascii" />
			</then>
			<else>
				<antcall target="build-lang-native2ascii-all" />
			</else>
		</if>

		<java
			classname="com.liferay.portal.tools.LangBuilder"
			classpathref="project.classpath"
			fork="true"
			newenvironment="true"
		>
			<jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
			<jvmarg value="-Dfile.encoding=UTF-8" />
			<jvmarg value="-Duser.country=US" />
			<jvmarg value="-Duser.language=en" />
			<arg value="${lang.dir}" />
			<arg value="${lang.file}" />
			<arg value="${lang.code}" />
		</java>

		<if>
			<isset property="lang.code" />
			<then>
				<antcall target="build-lang-native2ascii" />
			</then>
			<else>
				<antcall target="build-lang-native2ascii-all" />

				<copy file="${lang.dir}/${lang.file}.properties" tofile="${lang.dir}/${lang.file}_en.properties" />
			</else>
		</if>
	</target>

	<target name="build-lang-native2ascii">
		<delete file="${lang.dir}/${lang.file}_${lang.code}.properties" failonerror="false" />

		<exec dir="${lang.dir}" executable="cmd.exe" os="${os.windows}">
			<arg line="/c '${env.JAVA_HOME}'/bin/native2ascii -encoding UTF-8 ${lang.file}_${lang.code}.properties.native ${lang.file}_${lang.code}.properties" />
		</exec>

		<exec dir="${lang.dir}" executable="${env.JAVA_HOME}/bin/native2ascii" os="${os.unix}">
			<arg line="-encoding UTF-8 ${lang.file}_${lang.code}.properties.native ${lang.file}_${lang.code}.properties" />
		</exec>

		<exec dir="${lang.dir}" executable="/usr/bin/native2ascii" os="${os.apple}">
			<arg line="-encoding UTF-8 ${lang.file}_${lang.code}.properties.native ${lang.file}_${lang.code}.properties" />
		</exec>
	</target>

	<target name="build-lang-native2ascii-all">
		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="ar" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="eu" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="ca" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="zh_CN" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="zh_TW" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="cs" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="nl" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="fi" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="fr" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="de" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="el" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="hu" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="it" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="ja" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="ko" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="nb" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="fa" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="pl" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="pt_BR" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="pt_PT" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="ru" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="sk" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="es" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="sv" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="tr" />
		</antcall>

		<antcall target="build-lang-native2ascii">
			<param name="lang.code" value="vi" />
		</antcall>
	</target>

	<target name="build-service">
		<java
			classname="com.liferay.portal.tools.servicebuilder.ServiceBuilder"
			classpathref="project.classpath"
			fork="true"
			maxmemory="256m"
			newenvironment="true"
		>
			<jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
			<jvmarg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger" />
			<jvmarg value="-Dservice.input.file=${service.file}" />
			<jvmarg value="-Dservice.hbm.file=src/META-INF/ext-hbm.xml" />
			<jvmarg value="-Dservice.model.hints.file=src/META-INF/ext-model-hints.xml" />
			<jvmarg value="-Dservice.spring.file=src/META-INF/ext-spring.xml" />
			<jvmarg value="-Dservice.api.dir=${project.dir}/ext-service/src" />
			<jvmarg value="-Dservice.impl.dir=src" />
			<jvmarg value="-Dservice.json.file=${project.dir}/ext-web/docroot/html/js/liferay/ext_service.js" />
			<jvmarg value="-Dservice.remoting.file=${project.dir}/ext-web/docroot/WEB-INF/remoting-servlet-ext.xml" />
			<jvmarg value="-Dservice.sql.dir=../sql" />
			<jvmarg value="-Dservice.sql.file=portal-tables.sql" />
			<jvmarg value="-Dservice.sql.indexes.file=indexes.sql" />
			<jvmarg value="-Dservice.sql.indexes.properties.file=indexes.properties" />
			<jvmarg value="-Dservice.sql.sequences.file=sequences.sql" />
			<jvmarg value="-Dservice.bean.locator.util=com.liferay.portal.kernel.bean.PortalBeanLocatorUtil" />
			<jvmarg value="-Dservice.props.util=com.liferay.portal.util.PropsUtil" />
		</java>

		<delete file="ServiceBuilder.temp" />

		<ant dir="../ext-service" target="compile" inheritAll="false" />
	</target>

	<target name="build-service-portlet-reports">
		<antcall target="build-service">
			<param name="service.file" value="src/com/ext/portlet/reports/service.xml" />
		</antcall>
	</target>

	<target name="build-services">
		<antcall target="build-service-portlet-reports" />
	</target>

	<target name="build-wsdd" depends="compile">
		<java
			classname="com.liferay.portal.tools.WSDDBuilder"
			classpathref="project.classpath"
			fork="true"
			maxmemory="256m"
			newenvironment="true"
		>
			<jvmarg value="-Dexternal-properties=com/liferay/portal/tools/dependencies/portal-tools.properties" />
			<jvmarg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger" />
			<arg value="${service.file}" />
			<arg value="../ext-web/docroot/WEB-INF/server-config.wsdd" />
		</java>
	</target>
</project>