<project>

	<property file="local_build.properties"/>
	<property file="build.properties"/>

	<!-- Task 'de.unkrig.ant-contrib.swing-dialog'. -->
	<taskdef
		classpath="lib/de.unkrig.ant-contrib.jar"
		resource="de/unkrig/antcontrib/ant.properties"
	/>

	<!-- Task 'ftp2' which adds supprt for FTP proxies. -->
	<taskdef
		classpath="lib/ant_issue_54883.jar"
		resource="ant_issue_54883.properties"
	/>

	<target name="build" description="Builds download site in './mirror'">
		<delete dir="mirror"/>
		<mkdir dir="mirror/download"/>

		<!-- Build 'build/commons-compiler.jar'. -->
		<delete dir="build/bin-commons-compiler"/>
		<mkdir dir="build/bin-commons-compiler"/>
		<javac
			fork="yes"
			source="1.6"
			target="1.6"
			srcdir="../commons-compiler/src"
			destdir="build/bin-commons-compiler"
			debug="true"
			debuglevel="lines,vars,source"
			includeantruntime="false"
		>
			<compilerarg value="-Xlint:none"/>
			<compilerarg value="-Xlint:deprecation"/>
		</javac>
		<copy todir="build/bin-commons-compiler">
			<fileset dir="../commons-compiler/src" excludes="**/*.java,**/package.html"/>
		</copy>
		<jar jarfile="build/commons-compiler.jar" filesonly="true">
			<manifest>
				<attribute name="Specification-Version" value="${version}"/>
			</manifest>
			<fileset dir="build/bin-commons-compiler"/>
		</jar>
		<signjar
			keystore="dummy-keystore"
			storepass="storepass"
			keypass="keypass"
			jar="build/commons-compiler.jar"
			alias="dummy"
		/>

		<!-- Build 'build/janino.jar'. -->
		<delete dir="build/bin-janino"/>
		<mkdir dir="build/bin-janino"/>
		<javac
			fork="yes"
			source="1.6"
			target="1.6"
			srcdir="../janino/src"
			destdir="build/bin-janino"
			classpath="${ant.jar}:build/bin-commons-compiler:../de.unkrig.jdisasm/bin"
			debug="true"
			debuglevel="lines,vars,source"
			includeantruntime="false"
		>
			<compilerarg value="-Xlint:none"/>
			<compilerarg value="-Xlint:deprecation"/>
		</javac>
		<copy todir="build/bin-janino">
			<fileset dir="../janino/src" excludes="**/*.java,**/package.html"/>
		</copy>
		<jar jarfile="build/janino.jar" filesonly="true">
			<manifest>
				<attribute name="Implementation-Version" value="${version}"/>
				<attribute name="Implementation-URL"     value="http://janino.net"/>
			</manifest>
			<fileset dir="build/bin-janino"/>
		</jar>
		<signjar
			keystore="dummy-keystore"
			storepass="storepass"
			keypass="keypass"
			jar="build/janino.jar"
			alias="dummy"
		/>

		<!-- Build 'build/commons-compiler-jdk.jar'. -->
		<delete dir="build/bin-de.unkrig.commons.nullanalysis"/>
		<mkdir dir="build/bin-de.unkrig.commons.nullanalysis"/>
		<javac
			fork="yes"
			source="1.6"
			target="1.6"
			srcdir="../de.unkrig.commons.nullanalysis/src"
			destdir="build/bin-de.unkrig.commons.nullanalysis"
			debug="true"
			debuglevel="lines,vars,source"
			includeantruntime="false"
		>
			<compilerarg value="-Xlint:none"/>
			<compilerarg value="-Xlint:deprecation"/>
		</javac>
		<delete dir="build/bin-commons-compiler-jdk"/>
		<mkdir dir="build/bin-commons-compiler-jdk"/>
		<javac
			fork="yes"
			source="1.6"
			target="1.6"
			srcdir="../commons-compiler-jdk/src"
			destdir="build/bin-commons-compiler-jdk"
			classpath="build/bin-commons-compiler:build/bin-de.unkrig.commons.nullanalysis"
			debug="true"
			debuglevel="lines,vars,source"
			includeantruntime="false"
		>
			<compilerarg value="-Xlint:none"/>
			<compilerarg value="-Xlint:deprecation"/>
		</javac>
		<copy todir="build/bin-commons-compiler-jdk">
			<fileset dir="../commons-compiler-jdk/src" excludes="**/*.java,**/package.html"/>
		</copy>
		<jar jarfile="build/commons-compiler-jdk.jar" filesonly="true">
			<manifest>
				<attribute name="Implementation-Version" value="${version}"/>
				<attribute name="Implementation-URL"     value="http://janino.net"/>
			</manifest>
			<fileset dir="build/bin-commons-compiler-jdk"/>
			<fileset dir="build/bin-de.unkrig.commons.nullanalysis"/>
		</jar>
		<signjar
			keystore="dummy-keystore"
			storepass="storepass"
			keypass="keypass"
			jar="build/commons-compiler-jdk.jar"
			alias="dummy"
		/>

		<!-- Build source ZIP files. -->
		<zip destfile="build/commons-compiler-src.zip" filesonly="true">
			<zipfileset dir="../commons-compiler/src"/>
		</zip>
		<zip destfile="build/janino-src.zip" filesonly="true">
			<zipfileset dir="../janino/src"/>
		</zip>
		<zip destfile="build/commons-compiler-jdk-src.zip" filesonly="true">
			<zipfileset dir="../commons-compiler-jdk/src"/>
		</zip>

		<!-- Build 'mirror/download/janino-VERSION.zip' file. -->
		<zip destfile="mirror/download/janino-${version}.zip" filesonly="true">
			<zipfileset file="build/commons-compiler.jar"     prefix="janino-${version}"/>
			<zipfileset file="build/janino.jar"               prefix="janino-${version}"/>
			<zipfileset file="build/commons-compiler-jdk.jar" prefix="janino-${version}"/>

			<zipfileset file="build/commons-compiler-src.zip"     prefix="janino-${version}"/>
			<zipfileset file="build/janino-src.zip"               prefix="janino-${version}"/>
			<zipfileset file="build/commons-compiler-jdk-src.zip" prefix="janino-${version}"/>

			<zipfileset file="README.txt"                         prefix="janino-${version}"/>
			<zipfileset file="new_bsd_license.txt"                prefix="janino-${version}"/>
		</zip>

		<!-- Build 'mirror/pad_file.xml'. -->
		<length file="mirror/download/janino-${version}.zip" property="janino-zip-size"/>
		<copy file="pad_file-template.xml" tofile="mirror/pad_file.xml" encoding="ISO-8859-1">
			<filterchain>
				<replacestring from="@VERSION@" to="${version}"/>
				<replacestring from="@SIZE@"    to="${janino-zip-size}"/>
			</filterchain>
		</copy>

		<!-- Build 'mirror/javadoc/'. -->
		<delete dir="mirror/javadoc"/>
		<mkdir dir="mirror/javadoc"/>
		<javadoc
			header="&lt;a href=&quot;http://janino.net/&quot; target=&quot;_top&quot;&gt;janino.net&lt;/a&gt;"
			splitindex="true"
			doctitle="Janino ${version}"
			windowtitle="Janino ${version}"
			overview="overview.html"
			sourcepath="../commons-compiler/src;../janino/src;../commons-compiler-jdk/src;../de.unkrig.commons.nullanalysis/src"
			classpath="${ant.jar}"
			destdir="mirror/javadoc"
			packagenames="${javadoc-packages}"
		>
			<link offline="true" href="${javadoc-jdk-href}" packagelistloc="${javadoc-jdk-packagelistloc}"/>
			<link offline="true" href="${javadoc-ant-href}" packagelistloc="${javadoc-ant-packagelistloc}"/>
		</javadoc>

		<!-- Copy auxiliary files to 'mirror/'. -->
		<copy todir="mirror">
			<fileset file="favicon.ico"/>
			<fileset file="new_bsd_license.txt"/>
			<fileset file="changelog.html"/>
			<fileset file="README.txt"/>
			<fileset dir="../janino/src/org/codehaus/janino" includes="samples/*.java"/>
			<fileset dir="../commons-compiler/src/org/codehaus/commons/compiler" includes="samples/*.java"/>
		</copy>
	</target>

	<target name="publish" description="Uploads './mirror' to 'unkrig.de/janino'">

		<!-- Have the FTP parameters entered/confirmed by the user. -->
		<de.unkrig.ant-contrib.swing-dialog title="FTP upload of update site">
			<label text="Server:"                   /><text property="ftp.server"         defaultvalue="${ftp.server}"/>
			<label text="Port (optional):"          /><text property="ftp.port"           defaultvalue="${ftp.port}"/>
			<label text="User ID:"                  /><text property="ftp.userid"         defaultvalue="${ftp.userid}"/>
			<label text="Password:"                 /><text property="ftp.password"       defaultvalue="${ftp.password}" secure="true"/>
			<label text="Proxy server (optional):"  /><text property="ftp.proxy.server"   defaultvalue="${ftp.proxy.server}"/>
			<label text="Proxy port (optional):"    /><text property="ftp.proxy.port"     defaultvalue="${ftp.proxy.port}"/>
			<label text="Proxy user ID (optional):" /><text property="ftp.proxy.userid"   defaultvalue="${ftp.proxy.userid}"/>
			<label text="Proxy password (optional):"/><text property="ftp.proxy.password" defaultvalue="${ftp.proxy.password}" secure="true"/>
			<label text="Remote directory:"         /><text property="ftp.remotedir"      defaultvalue="${ftp.remotedir}"/>
			<checkbox text="Use passive FTP"   property="ftp.passive" defaultvalue="true"/>
			<checkbox text="Verbose reporting" property="ftp.verbose" defaultvalue="true"/>
		</de.unkrig.ant-contrib.swing-dialog>

		<ftp2
			server        ="${ftp.server}"
			port          ="${ftp.port}"
			userid        ="${ftp.userid}"
			password      ="${ftp.password}"
			proxyServer   ="${ftp.proxy.server}"
			proxyPort     ="${ftp.proxy.port}"
			proxyUserid   ="${ftp.proxy.userid}"
			proxyPassword ="${ftp.proxy.password}"
			remotedir     ="${ftp.remotedir}"
			passive       ="${ftp.passive}"
			verbose       ="${ftp.verbose}"
			action        ="put"
			depends="no"
			retriesAllowed="10"
		>
			<fileset dir="mirror"/>
		</ftp2>
	</target>

	<target name="tag" description="Tags all projects as 'janino_${version}'">

		<!-- Compose the tag name from the feature name and the version. -->

		<property name="tag" value="janino_${version}"/>
		<echo message="Tagging relevant projects as '${tag}'..."/>

		<fail unless="eclipse.running" message="Please select the ECLIPSE external tool configuration option 'Run in the same JRE as the workspace'."/>
		<condition property="de.unkrig.subclipse.svn.exists"><typefound name="de.unkrig.subclipse.svn"/></condition>
		<fail unless="de.unkrig.subclipse.svn.exists" message="Please install the 'de.unkrig.subclipse' feature from 'http://subclipse.unkrig.de/update'."/>

		<!--
			Currently it is only possible to copy the WORKING COPY, and not the BASE version - due to a limitation in
			svnClientAdapter. See http://subclipse.tigris.org/issues/show_bug.cgi?id=1505
		-->
		<property name="d1" value="https://svn.codehaus.org/janino/tags/${tag}"/>
		<de.unkrig.subclipse.svn>
			<mkdir                                    url="${d1}"/>
			<copy srcpath="../commons-compiler"       desturl="${d1}"/>
			<copy srcpath="../commons-compiler-jdk"   desturl="${d1}"/>
			<copy srcpath="../commons-compiler-tests" desturl="${d1}"/>
			<copy srcpath="../de.unkrig.jdisasm"      desturl="${d1}"/>
			<copy srcpath="../janino"                 desturl="${d1}"/>
			<copy srcpath="../janino-dist"            desturl="${d1}"/>
			<copy srcpath="../janino-tests"           desturl="${d1}"/>
		</de.unkrig.subclipse.svn>
		<property name="d2" value="https://svn.code.sf.net/p/loggifier/code/tags/${tag}"/>
		<de.unkrig.subclipse.svn>
			<mkdir                                                url="${d2}"/>
			<copy srcpath="../de.unkrig.checkstyle-configuration" desturl="${d2}"/>
			<copy srcpath="../de.unkrig.commons.nullanalysis"     desturl="${d2}"/>
		</de.unkrig.subclipse.svn>
	</target>
</project>
