<project name="jedit"
	 default="build"
	 xmlns:mod="antlib:de.masters_of_disaster.ant.tasks"
	 xmlns:contrib="antlib:net.sf.antcontrib"
	 xmlns:launch4j="antlib:net.sf.launch4j.ant"
	 xmlns:jarbundler="antlib:net.sourceforge.jarbundler"
	 xmlns:fop="antlib:org.apache.fop.tools.anttasks"
	 xmlns:ivy="antlib:org.apache.ivy.ant">
	<description>
		This is an ant build.xml file for building jEdit - Programmer's Text Editor.
	</description>

	<property file="build.properties"
		  prefix="config"/>

	<!-- Target Java Versions -->
	<property name="target.java.version"
		  value="1.7"/>
	<property name="mac.target.java.version"
		  value="1.7+"/>
	<!-- based on http://packages.slackverse.org/?v=1&p=92 -->
	<property name="slackware.target.java.version"
		  value="1_7_0"/>

	<!-- Various Paths -->
	<property name="config.lib.dir"
		  value="lib"/>
	<property name="config.build.dir"
		  value="build"/>
	<property name="config.dist.dir"
		  value="dist"/>
	<property name="lib.dir"
		  location="${config.lib.dir}"/>
	<property name="build.dir"
		  location="${config.build.dir}"/>
	<property name="dist.dir"
		  location="${config.dist.dir}"/>
	<property name="classes.dir"
		  location="${build.dir}/classes"/>
	<property name="jar.location"
		  location="${build.dir}"/>
	<property name="textAreaPackage"
		  location="../textarea"/>

	<!-- Ivy Properties -->
	<property name="config.ivy.version"
		  value="2.2.0"/>
	<property name="ivy.jar.dir"
		  location="${lib.dir}/ivy"/>
	<property name="ivy.jar.filename"
		  value="ivy-${config.ivy.version}.jar"/>
	<property name="ivy.jar.file"
		  location="${ivy.jar.dir}/${ivy.jar.filename}"/>

	<!-- Miscellaneous -->
	<property name="jar.filename"
		  value="${ant.project.name}.jar"/>
	<property name="config.build.debuglevel"
		  value="lines,vars,source"/>
	<property name="config.build.nowarn"
		  value="false"/>
	<property name="config.build.deprecation"
		  value="true"/>
	<property name="config.build.compilerarg"
		  value="-Xlint:unchecked"/>

	<target name="init"
		unless="init.done">
		<echo message="Buildfile for ${ant.project.name} (${ant.file})"
		      level="info"/>
		<fail message="Ant 1.8.2 or newer is needed for jEdit to build, please install it and rerun">
			<condition>
				<not>
					<antversion atleast="1.8.2"/>
				</not>
			</condition>
		</fail>
		<fail message="The ant-optional package is needed for jEdit to build, please install it and rerun">
			<condition>
				<not>
					<and>
						<available classname="org.apache.tools.ant.taskdefs.optional.depend.Depend"/>
						<available classname="org.apache.tools.ant.taskdefs.optional.TraXLiaison"/>
					</and>
				</not>
			</condition>
		</fail>
		<property name="init.done"
			  value="true"/>
	</target>

	<target name="check-ivy"
		depends="init">
		<available property="ivy.jar.present"
			   file="${ivy.jar.file}"
			   type="file"/>
	</target>

	<target name="download-ivy"
		depends="init,check-ivy"
		unless="ivy.jar.present">
		<mkdir dir="${ivy.jar.dir}"/>
		<get src="http://repo2.maven.org/maven2/org/apache/ivy/ivy/${config.ivy.version}/ivy-${config.ivy.version}.jar"
		     dest="${ivy.jar.file}"
		     usetimestamp="true"/>
	</target>

	<target name="init-ivy"
		depends="init,download-ivy"
		unless="ivy.done">
		<property name="ivy.retrieve.pattern"
			  value="${lib.dir}/[conf]/[artifact](-[classifier]).[ext]"/>
		<taskdef resource="org/apache/ivy/ant/antlib.xml"
			 classpath="${ivy.jar.file}"
			 loaderref="ivy.loader"
			 uri="antlib:org.apache.ivy.ant"/>
		<ivy:settings file="ivysettings.xml"/>
	</target>

	<target name="retrieve"
		description="retrieve the dependencies"
		depends="init,init-ivy"
		unless="ivy.done">
		<ivy:retrieve sync="true"/>
		<ivy:retrieve pattern="${lib.dir}/ivy/[artifact]-[revision].[ext]"
			      organisation="org.apache.ivy"
			      module="ivy"
			      revision="${config.ivy.version}"
			      conf="default"
			      inline="true"/>
		<property name="ivy.done"
			  value="true"/>
	</target>

	<target name="setup"
		depends="init,retrieve">
		<taskdef resource="net/sf/antcontrib/antlib.xml"
			 uri="antlib:net.sf.antcontrib">
			<classpath>
				<fileset dir="${lib.dir}/ant-contrib"
					 includes="*.jar"/>
			</classpath>
		</taskdef>

		<script language="beanshell">
			<classpath>
				<fileset dir="${lib.dir}/scripting"
					 includes="*.jar"/>
			</classpath>

			import java.util.regex.Pattern;
			file = new File(basedir, "org/gjt/sp/jedit/jEdit.java");
			fileChars = new char[file.length()];
			reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
			reader.read(fileChars, 0, fileChars.length);
			pattern = Pattern.compile("public static String getBuild\\(\\)[^}]+return \"([^\"]{11})\"");
			matcher = pattern.matcher(new String(fileChars));
			matcher.find();
			build = matcher.group(1);
			major = Integer.parseInt(build.substring(0,2));
			minor = Integer.parseInt(build.substring(3,5));
			beta = Integer.parseInt(build.substring(6,8));
			micro = Integer.parseInt(build.substring(9,11));
			version = major
			          + "." + minor
			          + (beta != 99 ? "pre" + beta : "." + micro);
			project.setUserProperty("jedit.version", version);
			project.setUserProperty("jedit.build.number", build);
			project.setUserProperty("jedit.version.final", Boolean.toString(beta == 99));
		</script>
		<property name="dist.jar.filename"
			  value="jedit${jedit.version}install.jar"/>
		<property name="manual.filename.prefix"
			  value="jedit${jedit.version}manual-"/>
		<property name="src.archive.filename"
			  value="jedit${jedit.version}source.tar.bz2"/>
		<property name="win.filename"
			  value="jedit${jedit.version}install"/>
		<property name="mac.disk.image.filename"
			  value="jedit${jedit.version}install.dmg"/>
	</target>

	<target name="clean"
		depends="init"
		description="clean up intermediate files">
		<delete includeemptydirs="true"
			failonerror="false">
			<fileset dir="${build.dir}/classes"
				 defaultexcludes="false"/>
			<fileset dir="${dist.dir}/classes"
				 defaultexcludes="false"/>
		</delete>
	</target>

	<target name="clean-all"
		depends="init"
		description="clean up lib.dir, build.dir and dist.dir completely">
		<delete includeemptydirs="true"
			failonerror="false">
			<fileset dir="${lib.dir}"
				 defaultexcludes="false"/>
			<fileset dir="${build.dir}"
				 defaultexcludes="false"/>
			<fileset dir="${dist.dir}"
				 defaultexcludes="false"/>
			<fileset dir="${textAreaPackage}/build"
				 defaultexcludes="false"/>
		</delete>
	</target>

	<target name="compile"
		depends="init">
		<mkdir dir="${classes.dir}/core"/>
		<depend srcDir="${basedir}"
			destDir="${classes.dir}/core"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<targetfileset dir="${classes.dir}/core"/>
		</dependset>
		<javac srcdir="${basedir}"
		       destdir="${classes.dir}/core"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="${target.java.version}"
		       target="${target.java.version}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="false">
			<classpath id="classpath.compile">
				<fileset dir="${lib.dir}/compile"
					 includes="*.jar"/>
			</classpath>
			<include name="org/**"/>
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="compile-test"
		depends="init,retrieve,compile">
		<mkdir dir="${classes.dir}/test"/>
		<depend srcDir="${basedir}/test"
			destDir="${classes.dir}/test"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<srcfilelist files="ivy.xml"/>
			<targetfileset dir="${classes.dir}/test"/>
		</dependset>
		<javac srcdir="test"
		       destdir="${classes.dir}/test"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="${target.java.version}"
		       target="${target.java.version}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="false">
			<classpath id="classpath.test">
				<fileset dir="${lib.dir}/test"
					 includes="*.jar"/>
				<pathelement location="${classes.dir}/core"/>
			</classpath>
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="prepare-textArea"
		depends="init">
		<delete includeemptydirs="true"
			failonerror="false">
			<fileset dir="${textAreaPackage}/src"/>
		</delete>

		<mkdir dir="${textAreaPackage}/src"/>
		<copy todir="${textAreaPackage}/src">
			<fileset dir="${basedir}">
				<include name="modes/*"/>
				<include name="keymaps/*"/>
				<include name="org/gjt/sp/jedit/bsh/*"/>
				<include name="org/gjt/sp/jedit/bsh/**/*"/>

				<include name="org/gjt/sp/jedit/buffer/BufferAdapter.java"/>
				<include name="org/gjt/sp/jedit/buffer/BufferListener.java"/>
				<include name="org/gjt/sp/jedit/buffer/BufferSegment.java"/>
				<include name="org/gjt/sp/jedit/buffer/ContentManager.java"/>
				<include name="org/gjt/sp/jedit/buffer/DefaultFoldHandlerProvider.java"/>
				<include name="org/gjt/sp/jedit/buffer/DummyFoldHandler.java"/>
				<include name="org/gjt/sp/jedit/buffer/ExplicitFoldHandler.java"/>
				<include name="org/gjt/sp/jedit/buffer/FoldHandler.java"/>
				<include name="org/gjt/sp/jedit/buffer/FoldHandlerProvider.java"/>
				<include name="org/gjt/sp/jedit/buffer/IndentFoldHandler.java"/>
				<include name="org/gjt/sp/jedit/buffer/JEditBuffer.java"/>
				<include name="org/gjt/sp/jedit/buffer/KillRing.java"/>
				<include name="org/gjt/sp/jedit/buffer/LineManager.java"/>
				<include name="org/gjt/sp/jedit/buffer/PositionManager.java"/>
				<include name="org/gjt/sp/jedit/buffer/UndoManager.java"/>

				<include name="org/gjt/sp/jedit/bufferio/IoTask.java"/>

				<include name="org/gjt/sp/jedit/gui/KeyEventTranslator.java"/>
				<include name="org/gjt/sp/jedit/gui/KeyEventWorkaround.java"/>
				<include name="org/gjt/sp/jedit/gui/MutableListModel.java"/>
				<include name="org/gjt/sp/jedit/gui/ShortcutPrefixActiveEvent.java"/>
				<include name="org/gjt/sp/jedit/gui/HistoryModel.java"/>
				<include name="org/gjt/sp/jedit/gui/HistoryModelSaver.java"/>

				<include name="org/gjt/sp/jedit/indent/*.java"/>

				<include name="org/gjt/sp/jedit/input/AbstractInputHandler.java"/>
				<include name="org/gjt/sp/jedit/input/DefaultInputHandlerProvider.java"/>
				<include name="org/gjt/sp/jedit/input/InputHandlerProvider.java"/>
				<include name="org/gjt/sp/jedit/input/TextAreaInputHandler.java"/>

				<include name="org/gjt/sp/jedit/syntax/*.java"/>
				<include name="org/gjt/sp/jedit/syntax/xmode.dtd"/>

				<include name="org/gjt/sp/jedit/datatransfer/JEditDataFlavor.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/JEditRichText.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/JEditTransferable.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/JEditTransferableService.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/RichJEditTextTransferableService.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/RichTextTransferable.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/StringTransferableService.java"/>
				<include name="org/gjt/sp/jedit/datatransfer/TransferHandler.java"/>

				<include name="org/gjt/sp/jedit/textarea/Anchor.java"/>
				<include name="org/gjt/sp/jedit/textarea/AntiAlias.java"/>
				<include name="org/gjt/sp/jedit/textarea/BufferHandler.java"/>
				<include name="org/gjt/sp/jedit/textarea/ChunkCache.java"/>
				<include name="org/gjt/sp/jedit/textarea/ColumnBlock.java"/>
				<include name="org/gjt/sp/jedit/textarea/ColumnBlockLine.java"/>
				<include name="org/gjt/sp/jedit/textarea/DisplayManager.java"/>
				<include name="org/gjt/sp/jedit/textarea/ElasticTabStopBufferListener.java"/>
				<include name="org/gjt/sp/jedit/textarea/ElasticTabstopsTabExpander.java"/>
				<include name="org/gjt/sp/jedit/textarea/ExtensionManager.java"/>
				<include name="org/gjt/sp/jedit/textarea/FastRepaintManager.java"/>
				<include name="org/gjt/sp/jedit/textarea/FirstLine.java"/>
				<include name="org/gjt/sp/jedit/textarea/FoldPainter.java"/>
				<include name="org/gjt/sp/jedit/textarea/Gutter.java"/>
				<include name="org/gjt/sp/jedit/textarea/GutterPopupHandler.java"/>
				<include name="org/gjt/sp/jedit/textarea/InputMethodSupport.java"/>
				<include name="org/gjt/sp/jedit/textarea/MouseActions.java"/>
				<include name="org/gjt/sp/jedit/textarea/MouseActionsProvider.java"/>
				<include name="org/gjt/sp/jedit/textarea/Node.java"/>
				<include name="org/gjt/sp/jedit/textarea/RangeMap.java"/>
				<include name="org/gjt/sp/jedit/textarea/Selection.java"/>
				<include name="org/gjt/sp/jedit/textarea/SelectionManager.java"/>
				<include name="org/gjt/sp/jedit/textarea/ScreenLineManager.java"/>
				<include name="org/gjt/sp/jedit/textarea/ScrollLayout.java"/>
				<include name="org/gjt/sp/jedit/textarea/ScrollLineCount.java"/>
				<include name="org/gjt/sp/jedit/textarea/ScrollListener.java"/>
				<include name="org/gjt/sp/jedit/textarea/StandaloneTextArea.java"/>
				<include name="org/gjt/sp/jedit/textarea/StatusListener.java"/>
				<include name="org/gjt/sp/jedit/textarea/StructureMatcher.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextArea.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextAreaBorder.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextAreaDropHandler.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextAreaException.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextAreaExtension.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextAreaMouseHandler.java"/>
				<include name="org/gjt/sp/jedit/textarea/TextAreaPainter.java"/>
				<include name="org/gjt/sp/jedit/textarea/textarea.actions.xml"/>
				<include name="org/gjt/sp/jedit/textarea/TriangleFoldPainter.java"/>

				<include name="org/gjt/sp/jedit/ActionListHandler.java"/>
				<include name="org/gjt/sp/jedit/BeanShellFacade.java"/>
				<include name="org/gjt/sp/jedit/Debug.java"/>
				<include name="org/gjt/sp/jedit/IPropertyManager.java"/>
				<include name="org/gjt/sp/jedit/JEditAbstractEditAction.java"/>
				<include name="org/gjt/sp/jedit/JEditActionSet.java"/>
				<include name="org/gjt/sp/jedit/JEditActionContext.java"/>
				<include name="org/gjt/sp/jedit/JEditBeanShellAction.java"/>
				<include name="org/gjt/sp/jedit/Mode.java"/>
				<include name="org/gjt/sp/jedit/OperatingSystem.java"/>
				<include name="org/gjt/sp/jedit/RegistersListener.java"/>
				<include name="org/gjt/sp/jedit/Registers.java"/>
				<include name="org/gjt/sp/jedit/RegisterSaver.java"/>
				<include name="org/gjt/sp/jedit/SelectionManager.java"/>
				<include name="org/gjt/sp/jedit/TextUtilities.java"/>
				<include name="org/gjt/sp/jedit/actions.dtd"/>
				<include name="org/gjt/sp/jedit/jedit.props"/>
				<include name="modes/*"/>
				<include name="org/gjt/sp/util/Log*.java"/>
				<include name="org/gjt/sp/util/IntegerArray.java"/>
				<include name="org/gjt/sp/util/IOUtilities.java"/>
				<include name="org/gjt/sp/util/ProgressObserver.java"/>
				<include name="org/gjt/sp/util/SegmentCharSequence.java"/>
				<include name="org/gjt/sp/util/StandardUtilities.java"/>
				<include name="org/gjt/sp/util/Task.java"/>
				<include name="org/gjt/sp/util/TaskManager.java"/>
				<include name="org/gjt/sp/util/TaskListener.java"/>
				<include name="org/gjt/sp/util/AwtRunnableQueue.java"/>
				<include name="org/gjt/sp/util/ThreadUtilities.java"/>
				<include name="org/gjt/sp/util/SyntaxUtilities.java"/>
				<include name="org/gjt/sp/util/XMLUtilities.java"/>
			</fileset>
		</copy>

	</target>

	<target name="compile-textArea"
		depends="init,prepare-textArea">
		<mkdir dir="${textAreaPackage}/build"/>
		<javac srcdir="${textAreaPackage}/src"
		       destdir="${textAreaPackage}/build"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="${target.java.version}"
		       target="${target.java.version}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="false">
			<classpath id="classpath.compile">
				<fileset dir="${lib.dir}/compile" includes="*.jar"/>
			</classpath>
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="test"
		depends="init,retrieve,compile,compile-test"
		description="run unit tests">
		<delete dir="${build.dir}/test/raw-reports"/>
		<mkdir dir="${build.dir}/test/raw-reports"/>
		<junit fork="true"
		       forkmode="once"
		       printsummary="true"
		       failureproperty="tests.failed"
		       includeantruntime="false"
		       showoutput="true"
		       enabletestlistenerevents="true">
			<classpath refid="classpath.test"/>
			<classpath location="${classes.dir}/test"/>
			<classpath location="${ant.library.dir}/ant.jar"/>
			<classpath location="${ant.library.dir}/ant-junit.jar"/>
			<classpath location="${ant.library.dir}/ant-junit4.jar"/>
			<formatter type="xml"/>
			<batchtest todir="${build.dir}/test/raw-reports">
				<fileset dir="test"/>
			</batchtest>
		</junit>
		<mkdir dir="${build.dir}/test/merged-reports"/>
		<junitreport todir="${build.dir}/test/merged-reports">
			<fileset dir="${build.dir}/test/raw-reports"/>
			<report todir="${build.dir}/test/reports"/>
		</junitreport>
		<fail message="Unit test(s) failed! See reports at ${build.dir}/test/reports/index.html"
		      if="tests.failed"/>
	</target>

	<target name="build"
		depends="init,retrieve,setup,compile,test"
		description="build the jEdit JAR-file with full debug-information">
		<mkdir dir="${jar.location}"/>
		<jar destfile="${jar.location}/${jar.filename}"
		     basedir="${classes.dir}/core"
		     compress="false"
		     manifest="org/gjt/sp/jedit/jedit.manifest"
		     duplicate="fail"
		     index="true">
			<fileset dir="${basedir}">
				<include name="org/gjt/sp/jedit/bsh/commands/*.bsh"/>
				<include name="org/gjt/sp/jedit/**/*.dtd"/>
				<include name="org/gjt/sp/jedit/default.abbrevs"/>
				<include name="org/gjt/sp/jedit/*.props"/>
				<include name="org/gjt/sp/jedit/*.xml"/>
				<include name="org/gjt/sp/jedit/textarea/*.xml"/>
				<include name="org/gjt/sp/jedit/icons/**/*.gif"/>
				<include name="org/gjt/sp/jedit/icons/**/*.jpg"/>
				<include name="org/gjt/sp/jedit/icons/**/*.png"/>
				<include name="org/jedit/localization/*.props"/>
			</fileset>
		</jar>
		<loadfile srcfile="keymaps/jEdit_keys.props"
			  property="jEdit.keymap"
			  encoding="ISO-8859-1"/>
		<fail message="jEdit keymap must not contain A+[a-z] shortcuts, those may conflict with main menu mnemonics in localizations">
			<condition>
				<matches string="${jEdit.keymap}"
					 pattern="=A\+[a-z]"/>
			</condition>
		</fail>
		<copy todir="${jar.location}">
			<fileset dir="${basedir}">
				<include name="keymaps/**"/>
				<include name="macros/**"/>
				<include name="modes/**"/>
				<include name="properties/**"/>
				<include name="startup/**"/>
			</fileset>
		</copy>
		<copy todir="${jar.location}/jars">
			<fileset dir="${lib.dir}/default-plugins">
				<exclude name="MacOSX.jar"/>
			</fileset>
		</copy>
		<contrib:if>
			<os family="mac"/>
			<contrib:then>
				<copy todir="${jar.location}/jars">
					<fileset dir="${lib.dir}/default-plugins">
						<include name="MacOSX.jar"/>
					</fileset>
				</copy>
			</contrib:then>
		</contrib:if>
	</target>

	<target name="build-exe-launcher"
		depends="init,retrieve,setup,filter-package-files"
		description="build the EXE launcher">
		<contrib:if>
			<os family="windows"/>
			<contrib:then>
				<property name="osfamily"
					  value="windows"/>
			</contrib:then>
		</contrib:if>
		<contrib:if>
			<os family="mac"/>
			<contrib:then>
				<property name="osfamily"
					  value="mac"/>
			</contrib:then>
		</contrib:if>
		<contrib:if>
			<os family="unix"/>
			<contrib:then>
				<property name="osfamily"
					  value="unix"/>
			</contrib:then>
		</contrib:if>
		<contrib:switch value="${osfamily}">
			<contrib:case value="windows">
				<unjar src="${lib.dir}/launch4j/launch4j-workdir-win32.jar"
				       dest="${build.dir}/launch4j"/>
				<copy todir="${lib.dir}/launch4j">
					<fileset dir="${build.dir}/launch4j/launch4j-3.5.0-workdir-win32/"/>
				</copy>
			</contrib:case>
			<contrib:case value="unix">
				<unjar src="${lib.dir}/launch4j/launch4j-workdir-linux.jar"
				       dest="${build.dir}/launch4j/"/>
				<copy todir="${lib.dir}/launch4j">
					<fileset dir="${build.dir}/launch4j/launch4j-3.5.0-workdir-linux/"/>
				</copy>
				<chmod dir="${lib.dir}/launch4j/bin"
				       perm="+x"
				       includes="**"/>
			</contrib:case>
			<contrib:case value="mac">
				<unjar src="${lib.dir}/launch4j/launch4j-workdir-mac.jar"
				       dest="${build.dir}/launch4j/"/>
				<copy todir="${lib.dir}/launch4j">
					<fileset dir="${build.dir}/launch4j/launch4j-3.5.0-workdir-mac/"/>
				</copy>
				<chmod dir="${lib.dir}/launch4j/bin"
				       perm="+x"
				       includes="**"
				       osfamily="mac"/>
			</contrib:case>
			<contrib:default>
				<fail message="Unsupported OS family (${osfamily}). If you are on Windows, *nix or MacOS, please report this as bug, if not, please report it as a feature request"/>
			</contrib:default>
		</contrib:switch>
		<taskdef name="create"
			 classname="net.sf.launch4j.ant.Launch4jTask"
			 uri="antlib:net.sf.launch4j.ant">
			<classpath>
				<fileset dir="${lib.dir}/launch4j"
					 includes="*.jar"/>
			</classpath>
		</taskdef>
		<launch4j:create configFile="${classes.dir}/package-files/windows/jedit.launch4j.xml"
				 outfile="${jar.location}/jedit.exe"/>
	</target>

	<target name="build-textArea"
		depends="init,compile-textArea"
		description="build the textArea JAR-file with full debug-information">
		<mkdir dir="${jar.location}"/>
		<jar destfile="${jar.location}/${ant.project.name}-textArea.jar"
		     compress="true"
		     duplicate="fail"
		     index="true">
			<fileset dir="${textAreaPackage}/build/"/>
			<fileset dir="${textAreaPackage}/src">
				<include name="org/gjt/sp/jedit/textarea/*.xml"/>
				<include name="org/gjt/sp/jedit/syntax/xmode.dtd"/>
				<include name="org/gjt/sp/jedit/actions.dtd"/>
				<include name="org/gjt/sp/jedit/jedit.props"/>
				<include name="keymaps/*.props"/>
				<include name="modes/*"/>
			</fileset>
			<manifest>
				<attribute name="Main-Class"
					   value="org.gjt.sp.jedit.textarea.StandaloneTextArea"/>
			</manifest>
		</jar>
	</target>

	<target name="run"
		depends="init,build"
		description="run jEdit">
		<java jar="${jar.location}/${jar.filename}"
		      fork="true"
		      spawn="true">
			<arg value="-settings=${build.dir}/settings"/>
		</java>
	</target>

	<target name="run-debug"
		depends="init,build"
		description="run jEdit with debug listening enabled">
		<java jar="${jar.location}/${jar.filename}"
		      fork="true"
		      spawn="true">
			<jvmarg value="-agentlib:jdwp=transport=dt_socket,server=y,address=localhost:5005,timeout=60000"/>
			<arg value="-settings=${build.dir}/settings"/>
		</java>
	</target>

	<target name="unpack-docbook-xsl"
		depends="init,retrieve">
		<unzip src="${lib.dir}/docbook/docbook-xsl-resources.zip"
		       dest="${build.dir}/docbook-xsl/"/>
	</target>

	<presetdef name="dependset.build">
		<dependset>
			<srcfilelist dir="${basedir}">
				<file name="build.xml"/>
				<file name="ivy.xml"/>
				<file name="ivysettings.xml"/>
			</srcfilelist>
		</dependset>
	</presetdef>

	<presetdef name="dependset.html">
		<dependset.build>
			<srcfileset dir="${lib.dir}/docbook"/>
			<srcfilelist files="doc/jedithtml.xsl"/>
		</dependset.build>
	</presetdef>

	<presetdef name="xslt.doc">
		<xslt>
			<classpath>
				<fileset dir="${lib.dir}/docbook"
					 includes="*.jar"/>
			</classpath>
			<!-- ant 1.9 compatibility: explicitly set the processor to Saxon (see bug #3818) -->
			<factory name="com.icl.saxon.TransformerFactoryImpl"/>
			<xmlcatalog>
				<entity publicid="http://docbook.sourceforge.net/release/xsl/current/html/chunk.xsl"
					location="${build.dir}/docbook-xsl/docbook/html/chunk.xsl"/>
				<entity publicid="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl"
					location="${build.dir}/docbook-xsl/docbook/fo/docbook.xsl"/>
			</xmlcatalog>
			<sysproperty key="javax.xml.parsers.DocumentBuilderFactory"
				     value="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
			<sysproperty key="javax.xml.parsers.SAXParserFactory"
				     value="org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
			<sysproperty key="org.apache.xerces.xni.parser.XMLParserConfiguration"
				     value="org.apache.xerces.parsers.XIncludeParserConfiguration"/>
		</xslt>
	</presetdef>

	<target name="generate-doc-faq"
		depends="init,retrieve,setup,unpack-docbook-xsl">
		<dependset.html>
			<srcfileset dir="doc/FAQ"/>
			<targetfileset dir="${jar.location}/doc/FAQ"/>
		</dependset.html>
		<contrib:if>
			<available file="${jar.location}/doc/FAQ/toc.xml"
				   type="file"/>
			<contrib:then>
				<echo message="FAQ is up-to-date"
				      level="info"/>
			</contrib:then>
			<contrib:else>
				<xslt.doc style="doc/jedithtml.xsl"
					  in="doc/FAQ/faq.xml"
					  out="${jar.location}/doc/FAQ/index.html">
					<param name="base.dir"
					       expression="${jar.location}/doc/FAQ/"/>
				</xslt.doc>
			</contrib:else>
		</contrib:if>
	</target>

	<target name="generate-doc-news"
		depends="init,retrieve,setup,unpack-docbook-xsl">
		<dependset.html>
			<srcfileset dir="doc/whatsnew"/>
			<targetfileset dir="${jar.location}/doc/whatsnew"/>
		</dependset.html>
		<contrib:if>
			<available file="${jar.location}/doc/whatsnew/toc.xml"
				   type="file"/>
			<contrib:then>
				<echo message="News is up-to-date"
				      level="info"/>
			</contrib:then>
			<contrib:else>
				<xslt.doc style="doc/jedithtml.xsl"
					  in="doc/whatsnew/news.xml"
					  out="${jar.location}/doc/whatsnew/index.html">
					<param name="base.dir"
					       expression="${jar.location}/doc/whatsnew/"/>
				</xslt.doc>
			</contrib:else>
		</contrib:if>
	</target>

	<target name="generate-doc-users-guide"
		depends="init,retrieve,setup,unpack-docbook-xsl">
		<dependset.html>
			<srcfileset dir="doc/users-guide"/>
			<targetfileset dir="${jar.location}/doc/users-guide"/>
		</dependset.html>
		<contrib:if>
			<available file="${jar.location}/doc/users-guide/toc.xml"
				   type="file"/>
			<contrib:then>
				<echo message="User's Guide is up-to-date"
				      level="info"/>
			</contrib:then>
			<contrib:else>
				<xslt.doc style="doc/jedithtml.xsl"
					  in="doc/users-guide/users-guide.xml"
					  out="${jar.location}/doc/users-guide/index.html">
					<param name="base.dir"
					       expression="${jar.location}/doc/users-guide/"/>
				</xslt.doc>
			</contrib:else>
		</contrib:if>
	</target>

	<target name="docs-html"
		depends="init,generate-doc-faq,generate-doc-news,generate-doc-users-guide"
		description="generate HTML docs">
		<copy todir="${jar.location}/doc">
			<fileset dir="doc">
				<include name="*.txt"/>
				<include name="*.html"/>
				<include name="*.png"/>
				<include name="tips/**"/>
			</fileset>
		</copy>
	</target>

	<target name="generate-javadoc"
		depends="init,setup,compile">
		<dependset>
			<srcfileset dir="${basedir}">
				<include name="build.xml"/>
				<include name="doclet/**/*.java"/>
				<include name="org/**/*.java"/>
				<include name="org/**/package.html"/>
			</srcfileset>
			<targetfileset dir="${classes.dir}/javadoc"/>
		</dependset>
		<contrib:if>
			<available file="${classes.dir}/javadoc/api/toc.xml"
				   type="file"/>
			<contrib:then>
				<echo message="JavaDoc is up-to-date"
				      level="info"/>
			</contrib:then>
			<contrib:else>
				<mkdir dir="${classes.dir}/javadoc"/>
				<javac srcdir="${basedir}"
				       destdir="${classes.dir}/javadoc"
				       includes="doclet/**"
				       debug="true"
				       debuglevel="${config.build.debuglevel}"
				       nowarn="${config.build.nowarn}"
				       deprecation="${config.build.deprecation}"
				       source="${target.java.version}"
				       target="${target.java.version}"
				       compiler="modern"
				       encoding="UTF-8"
				       includeAntRuntime="true">
					<compilerarg line="${config.build.compilerarg}"/>
				</javac>
				<javadoc locale="en"
					 sourcepath="${basedir}"
					 destdir="${classes.dir}/javadoc/api"
					 packagenames="org.*"
					 doclet="doclet.GenerateTocXML"
					 docletpath="${classes.dir}/javadoc"
					 version="true"
					 use="true"
					 author="true"
					 splitindex="true"
					 windowtitle="jEdit API Documentation"
					 doctitle="jEdit API"
					 failonerror="true"
					 source="${target.java.version}"
					 encoding="UTF-8"
					 docencoding="UTF-8"
					 charset="UTF-8">
					<group title="jEdit 5 API"
					       packages="org.jedit.*"/>
					<group title="jEdit 4 API"
					       packages="org.gjt.sp.*"/>
					<group title="BeanShell"
					       packages="org.gjt.sp.jedit.bsh*"/>
					<tag name="todo" scope="all" description="To do:"/>
					<tag name="example" scope="all" description="Example:"/>
					<classpath id="classpath.javadoc">
						<path refid="classpath.compile"/>
						<pathelement location="${classes.dir}/core"/>
					</classpath>
				</javadoc>
			</contrib:else>
		</contrib:if>
	</target>

	<target name="docs-javadoc"
		depends="init,generate-javadoc"
		description="generate JavaDoc API docs">
		<copy todir="${jar.location}/doc">
			<fileset dir="${classes.dir}/javadoc"
				 includes="api/**"
				 excludes="api/**/*.html"/>
		</copy>
		<copy todir="${jar.location}/doc">
			<fileset dir="${classes.dir}/javadoc"
				 includes="api/**/*.html"/>
			<filterchain>
				<tokenfilter>
					<replacestring from="&lt;TD BGCOLOR=&quot;#FFFFFF&quot; CLASS=&quot;NavBarCell1Rev&quot;&gt;"
						       to="&lt;TD BGCOLOR=&quot;#00008B&quot; CLASS=&quot;NavBarCell1Rev&quot;&gt;"/>
				</tokenfilter>
				<tokenfilter>
					<filetokenizer/>
					<replaceregex pattern="(&lt;SCRIPT type=&quot;text/javascript&quot;&gt;.*?&lt;/SCRIPT&gt;|onload=&quot;.*?&quot;)"
						      flags="gs"/>
				</tokenfilter>
			</filterchain>
		</copy>
		<copy file="${basedir}/doc/stylesheet.css"
		      todir="${jar.location}/doc/api"
		      overwrite="true"/>
	</target>

	<target name="generate-pdf-users-guide"
		depends="init,retrieve,setup,unpack-docbook-xsl">
		<fail message="Please set the property &quot;paper.type&quot;"
		      unless="paper.type"/>
		<contrib:switch value="${paper.type}">
			<contrib:case value="A4">
				<property name="manual.filename.paper.type"
					  value="a4"/>
			</contrib:case>
			<contrib:case value="USletter">
				<property name="manual.filename.paper.type"
					  value="letter"/>
			</contrib:case>
			<contrib:default>
				<property name="manual.filename.paper.type"
					  value="${paper.type}"/>
			</contrib:default>
		</contrib:switch>
		<dependset.build>
			<srcfileset dir="${lib.dir}/docbook"/>
			<srcfileset dir="${lib.dir}/fop"/>
			<srcfilelist files="doc/jeditfo.xsl"/>
			<srcfileset dir="doc/users-guide"/>
			<targetfileset file="${classes.dir}/docs-pdf/${manual.filename.prefix}${manual.filename.paper.type}.fot"/>
			<targetfileset file="${jar.location}/${manual.filename.prefix}${manual.filename.paper.type}.pdf"/>
		</dependset.build>
		<contrib:if>
			<available file="${jar.location}/${manual.filename.prefix}${manual.filename.paper.type}.pdf"
				   type="file"/>
			<contrib:then>
				<echo message="${paper.type} PDF User's Guide is up-to-date"
				      level="info"/>
			</contrib:then>
			<contrib:else>
				<xslt.doc style="doc/jeditfo.xsl"
					  in="doc/users-guide/users-guide.xml"
					  out="${classes.dir}/docs-pdf/${manual.filename.prefix}${manual.filename.paper.type}.fot">
					<param name="paper.type"
					       expression="${paper.type}"/>
				</xslt.doc>
				<taskdef name="transform"
					 classname="org.apache.fop.tools.anttasks.Fop"
					 uri="antlib:org.apache.fop.tools.anttasks">
					<classpath>
						<fileset dir="${lib.dir}/fop"
							 includes="*.jar"/>
					</classpath>
				</taskdef>
				<fop:transform fofile="${classes.dir}/docs-pdf/${manual.filename.prefix}${manual.filename.paper.type}.fot"
					       outfile="${jar.location}/${manual.filename.prefix}${manual.filename.paper.type}.pdf"
					       format="application/pdf"
					       messagelevel="info"/>
			</contrib:else>
		</contrib:if>
	</target>

	<target name="docs-pdf-a4"
		depends="init"
		description="generate PDF users-guide with A4 paper size">
		<antcall target="generate-pdf-users-guide">
			<param name="paper.type"
			       value="A4"/>
		</antcall>
	</target>

	<target name="docs-pdf-USletter"
		depends="init"
		description="generate PDF users-guide with US letter paper size">
		<antcall target="generate-pdf-users-guide">
			<param name="paper.type"
			       value="USletter"/>
		</antcall>
	</target>

	<target name="docs-upload"
		depends="init,docs-html,docs-javadoc"
		description="upload generated documentation to public website (needs rsync)">
		<fail message="Please set the property &quot;rsync.executable&quot; in build.properties, you may find example values in build.properties.sample"
		      unless="config.rsync.executable"/>
		<exec executable="${config.rsync.executable}"
		      dir="${jar.location}/doc/"
		      failonerror="true">
			<arg value="-avz"/>
			<arg value="--delete"/>
			<arg value="--progress"/>
			<arg value="api"/>
			<arg value="FAQ"/>
			<arg value="users-guide"/>
			<arg value="web.sourceforge.net:/home/project-web/jedit/htdocs"/>
		</exec>
	</target>

	<target name="compile-installer"
		depends="init">
		<mkdir dir="${classes.dir}/installer"/>
		<depend srcDir="${basedir}"
			destDir="${classes.dir}/installer"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<targetfileset dir="${classes.dir}/installer"/>
		</dependset>
		<javac srcdir="${basedir}"
		       destdir="${classes.dir}/installer"
		       includes="installer/**"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="false">
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="dist-java"
		depends="init,setup,prepare-dist-files"
		description="build the Java-installer">
		<tar destfile="${dist.dir}/jedit-macros.tar.bz2"
		     longfile="gnu"
		     compression="bzip2">
			<tarfileset id="jedit-macros"
				    dir="${dist.dir}"
				    includes="macros/**"/>
		</tar>
		<tar destfile="${dist.dir}/jedit-program.tar.bz2"
		     longfile="gnu"
		     compression="bzip2">
			<tarfileset id="jedit-program"
				    dir="${dist.dir}"
				    includes="doc/**
					      jars/**
					      keymaps/**
					      modes/**
					      properties/**
					      startup/**
					      ${jar.filename}"
				    excludes="doc/api/**
					      jars/MacOSX.jar"/>
		</tar>
		<tar destfile="${dist.dir}/jedit-windows.tar.bz2"
		     longfile="gnu"
		     compression="bzip2">
			<tarfileset id="jedit-windows"
				    dir="${dist.dir}"
				    includes="jedit.exe"/>
		</tar>
		<tar destfile="${dist.dir}/jedit-mac.tar.bz2"
		     longfile="gnu"
		     compression="bzip2">
			<tarfileset id="jedit-mac"
				    dir="${dist.dir}"
				    includes="jars/MacOSX.jar"/>
		</tar>
		<tar destfile="${dist.dir}/jedit-api.tar.bz2"
		     longfile="gnu"
		     compression="bzip2">
			<tarfileset id="jedit-api"
				    dir="${dist.dir}"
				    includes="doc/api/**"/>
		</tar>
		<tar destfile="${dist.dir}/jedit-os2.tar.bz2"
		     compression="bzip2">
			<tarfileset id="jedit-os2"
				    dir="${dist.dir}/classes/package-files/os2"
				    includes="jedit.cmd"/>
		</tar>
		<antcall target="compile-installer">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<antcall target="compile-calculatesize">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<taskdef name="calculatesize"
			 classname="de.masters_of_disaster.ant.tasks.calculatesize.CalculateSize"
			 classpath="${dist.dir}/classes/calculatesize"
			 uri="antlib:de.masters_of_disaster.ant.tasks"/>
		<mod:calculatesize realsizeproperty="jedit-macros.realsize"
				   disksizeproperty="jedit-macros.disksize">
			<fileset refid="jedit-macros"/>
		</mod:calculatesize>
		<mod:calculatesize realsizeproperty="jedit-program.realsize"
				   disksizeproperty="jedit-program.disksize">
			<fileset refid="jedit-program"/>
		</mod:calculatesize>
		<mod:calculatesize realsizeproperty="jedit-windows.realsize"
				   disksizeproperty="jedit-windows.disksize">
			<fileset refid="jedit-windows"/>
		</mod:calculatesize>
		<mod:calculatesize realsizeproperty="jedit-mac.realsize"
				   disksizeproperty="jedit-mac.disksize">
			<fileset refid="jedit-mac"/>
		</mod:calculatesize>
		<mod:calculatesize realsizeproperty="jedit-api.realsize"
				   disksizeproperty="jedit-api.disksize">
			<fileset refid="jedit-api"/>
		</mod:calculatesize>
		<mod:calculatesize realsizeproperty="jedit-os2.realsize"
				   disksizeproperty="jedit-os2.disksize">
			<fileset refid="jedit-os2"/>
		</mod:calculatesize>
		<copy todir="${dist.dir}/classes/installer/installer"
		      encoding="UTF-8"
		      overwrite="true">
			<fileset file="installer/install.props"/>
			<filterset>
				<filter token="jedit.version"
					value="${jedit.version}"/>
				<filter token="jedit-macros.realsize"
					value="${jedit-macros.realsize}"/>
				<filter token="jedit-macros.disksize"
					value="${jedit-macros.disksize}"/>
				<filter token="jedit-program.realsize"
					value="${jedit-program.realsize}"/>
				<filter token="jedit-program.disksize"
					value="${jedit-program.disksize}"/>
				<filter token="jedit-windows.realsize"
					value="${jedit-windows.realsize}"/>
				<filter token="jedit-windows.disksize"
					value="${jedit-windows.disksize}"/>
				<filter token="jedit-mac.realsize"
					value="${jedit-mac.realsize}"/>
				<filter token="jedit-mac.disksize"
					value="${jedit-mac.disksize}"/>
				<filter token="jedit-api.realsize"
					value="${jedit-api.realsize}"/>
				<filter token="jedit-api.disksize"
					value="${jedit-api.disksize}"/>
				<filter token="jedit-os2.realsize"
					value="${jedit-os2.realsize}"/>
				<filter token="jedit-os2.disksize"
					value="${jedit-os2.disksize}"/>
			</filterset>
		</copy>
		<jar destfile="${dist.dir}/${dist.jar.filename}"
		     basedir="${dist.dir}/classes/installer"
		     compress="true"
		     manifest="installer/install.mf"
		     duplicate="fail"
		     index="true">
			<fileset dir="${basedir}">
				<include name="installer/*.html"/>
			</fileset>
			<fileset dir="${dist.dir}/classes/package-files/linux">
				<include name="jedit.1"/>
			</fileset>
			<zipfileset dir="${dist.dir}"
				    includes="jedit-api.tar.bz2
					      jedit-mac.tar.bz2
					      jedit-macros.tar.bz2
					      jedit-os2.tar.bz2
					      jedit-windows.tar.bz2
					      jedit-program.tar.bz2"
				    prefix="installer"/>
		</jar>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="dist-manuals"
		depends="init,setup"
		description="build the PDF-manuals">
		<antcall target="docs-pdf-a4">
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
			<param name="jar.location"
			       location="${dist.dir}"/>
		</antcall>
		<antcall target="docs-pdf-USletter">
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
			<param name="jar.location"
			       location="${dist.dir}"/>
		</antcall>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="dist-src"
		depends="init,setup"
		description="build the src-archive">
		<mkdir dir="${dist.dir}"/>
		<tar destfile="${dist.dir}/${src.archive.filename}"
		     longfile="gnu"
		     compression="bzip2">
			<tarfileset dir="${basedir}"
				    excludes="${config.lib.dir}/**
					      ${config.build.dir}/**
					      ${config.dist.dir}/**
					      **/build.properties"
				    prefix="jEdit/"/>
		</tar>
	</target>

	<target name="compile-jarbundler"
		depends="init,retrieve">
		<mkdir dir="${classes.dir}/jarbundler"/>
		<depend srcDir="${basedir}"
			destDir="${classes.dir}/jarbundler"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<targetfileset dir="${classes.dir}/jarbundler"/>
		</dependset>
		<javac srcdir="${basedir}"
		       destdir="${classes.dir}/jarbundler"
		       includes="net/**"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="1.6"
		       target="1.6"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="true">
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="dist-mac-finish"
		depends="init,retrieve,setup"
		description="finish building the Mac OS X disk image (DMG-file) on Mac OS X">
		<fail message="The disk image (DMG-file) for easy distribution on Mac OS X can only be built on Mac OS X currently">
			<condition>
				<not>
					<os family="mac"/>
				</not>
			</condition>
		</fail>
		<taskdef name="create"
			 classname="net.sourceforge.jarbundler.JarBundler"
			 classpath="${dist.dir}/classes/jarbundler"
			 uri="antlib:net.sourceforge.jarbundler">
		</taskdef>
		<tstamp>
			<format property="current.year"
				pattern="yyyy"/>
		</tstamp>
		<mkdir dir="${dist.dir}/classes/mac"/>
		<jarbundler:create dir="${dist.dir}/classes/mac"
				   name="jEdit"
				   mainclass="org.gjt.sp.jedit.jEdit"
				   jar="${dist.dir}/${jar.filename}"
				   arguments="-background"
				   build="${jedit.build.number}"
				   bundleid="org.gjt.sp.jedit"
				   developmentregion="English"
				   extraclasspath="/System/Library/Java"
				   icon="icons/icon.icns"
				   infostring="jEdit ${jedit.version}, Copyright &#169; 1998-${current.year} Contributors"
				   copyright="Copyright &#169; 1998-${current.year} Contributors"
				   jvmversion="${mac.target.java.version}"
				   shortname="jEdit"
				   signature="JESP"
				   stubfile="package-files/osx/jedit"
				   version="${jedit.version}"
				   antialiasedgraphics="true"
				   antialiasedtext="true"
				   screenmenu="true">
			<javafileset dir="${dist.dir}"
				     includes="doc/**
					       jars/**
					       keymaps/**
					       macros/**
					       modes/**
					       properties/**
					       startup/**"/>
			<documenttype name="jEdit TEXT Document"
				      extensions="*"
				      ostypes="TEXT ****"
				      utis="public.text"
				      iconfile="icons/file.icns"
				      role="Editor"/>
		</jarbundler:create>
		<delete failonerror="false">
			<fileset dir="${dist.dir}"
				 includes="*${mac.disk.image.filename}"/>
		</delete>
		<exec executable="hdiutil"
		      failonerror="true">
			<arg value="create"/>
			<arg value="-volname"/>
			<arg value="jEdit"/>
			<arg value="-srcfolder"/>
			<arg file="${dist.dir}/classes/mac/jEdit.app"/>
			<arg value="-srcfolder"/>
			<arg file="package-files/osx/.background"/>
			<arg file="${dist.dir}/orig-${mac.disk.image.filename}"/>
		</exec>
		<exec executable="hdiutil"
		      failonerror="true">
			<arg value="convert"/>
			<arg file="${dist.dir}/orig-${mac.disk.image.filename}"/>
			<arg value="-format"/>
			<arg value="UDRW"/>
			<arg value="-o"/>
			<arg file="${dist.dir}/udrw-${mac.disk.image.filename}"/>
		</exec>
		<exec executable="hdiutil"
		      failonerror="true">
			<arg value="attach"/>
			<arg file="${dist.dir}/udrw-${mac.disk.image.filename}"/>
		</exec>
		<exec executable="ln"
		      failonerror="true">
			<arg value="-sF"/>
			<arg file="/Applications"/>
			<arg file="/Volumes/jEdit/"/>
		</exec>
		<copy file="package-files/osx/DS_Store"
		      tofile="/Volumes/jEdit/.DS_Store"
		      overwrite="true"/>
		<exec executable="hdiutil"
		      failonerror="true">
			<arg value="detach"/>
			<arg file="/Volumes/jEdit"/>
			<arg value="-force"/>
		</exec>
		<exec executable="hdiutil"
		      failonerror="true">
			<arg value="convert"/>
			<arg file="${dist.dir}/udrw-${mac.disk.image.filename}"/>
			<arg value="-format"/>
			<arg value="UDZO"/>
			<arg value="-imagekey"/>
			<arg value="zlib-level=9"/>
			<arg value="-o"/>
			<arg file="${dist.dir}/${mac.disk.image.filename}"/>
		</exec>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="dist-mac"
		depends="init,retrieve,setup,prepare-dist-files"
		description="build the Mac OS X disk image (DMG-file)">
		<antcall target="compile-jarbundler">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<contrib:if>
			<os family="mac"/>
			<contrib:then>
				<antcall target="dist-mac-finish">
					<param name="wipe.dist.files"
					       value="false"/>
				</antcall>
			</contrib:then>
			<contrib:else>
				<tar destfile="${dist.dir}/jedit${jedit.version}-dist-mac-finish.tar.bz2"
				     basedir="${basedir}"
				     longfile="gnu"
				     includes="build.xml
					       ivy.xml
					       ivysettings.xml
					       icons/file.icns
					       icons/icon.icns
					       org/gjt/sp/jedit/jEdit.java
					       package-files/osx/**
					       ${config.dist.dir}/${jar.filename}
					       ${config.dist.dir}/classes/jarbundler/**
					       ${config.dist.dir}/doc/**
					       ${config.dist.dir}/jars/**
					       ${config.dist.dir}/keymaps/**
					       ${config.dist.dir}/macros/**
					       ${config.dist.dir}/modes/**
					       ${config.dist.dir}/properties/**
					       ${config.dist.dir}/startup/**"
				     compression="bzip2"/>
			</contrib:else>
		</contrib:if>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="filter-package-files"
		depends="init,setup">
		<fail message="Please set the property &quot;winepath.executable&quot; in build.properties, you may find example values in build.properties.sample">
			<condition>
				<and>
					<istrue value="${config.innosetup.via.wine}"/>
					<not>
						<isset property="config.winepath.executable"/>
					</not>
				</and>
			</condition>
		</fail>
		<contrib:if>
			<and>
				<istrue value="${config.innosetup.via.wine}"/>
				<isset property="config.winepath.executable"/>
			</and>
			<contrib:then>
				<exec executable="${config.winepath.executable}"
				      outputproperty="basedir.for.innosetup"
				      failonerror="true">
					<arg value="-w"/>
					<arg value="${basedir}"/>
				</exec>
				<exec executable="${config.winepath.executable}"
				      outputproperty="dist.dir.for.innosetup"
				      failonerror="true">
					<arg value="-w"/>
					<arg value="${dist.dir}"/>
				</exec>
			</contrib:then>
			<contrib:else>
				<property name="basedir.for.innosetup"
					  value="${basedir}"/>
				<property name="dist.dir.for.innosetup"
					  value="${dist.dir}"/>
			</contrib:else>
		</contrib:if>
		<tstamp>
			<format property="current.year"
				pattern="yyyy"/>
		</tstamp>
		<copy todir="${classes.dir}/package-files"
		      encoding="UTF-8"
		      overwrite="true">
			<fileset dir="package-files"/>
			<filterset id="package-files-filter">
				<filter token="base.dir"
					value="${basedir}"/>
				<filter token="base.dir.for.innosetup"
					value="${basedir.for.innosetup}"/>
				<filter token="current.year"
					value="${current.year}"/>
				<filter token="dist.dir.for.innosetup"
					value="${dist.dir.for.innosetup}"/>
				<filter token="jar.filename"
					value="${jar.filename}"/>
				<filter token="jedit.build.number"
					value="${jedit.build.number}"/>
				<filter token="jedit.version"
					value="${jedit.version}"/>
				<filter token="slackware.target.java.version"
					value="${slackware.target.java.version}"/>
				<filter token="target.java.version"
					value="${target.java.version}"/>
				<filter token="win.filename"
					value="${win.filename}"/>
			</filterset>
		</copy>
	</target>

	<target name="prepare-dist-files"
		depends="init,retrieve,setup">
		<antcall target="build">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
			<param name="jar.location"
			       location="${dist.dir}"/>
		</antcall>
		<antcall target="docs-html">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
			<param name="jar.location"
			       location="${dist.dir}"/>
		</antcall>
		<antcall target="docs-javadoc">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
			<param name="jar.location"
			       location="${dist.dir}"/>
		</antcall>
		<copy todir="${dist.dir}/jars">
			<fileset dir="${lib.dir}/default-plugins"/>
		</copy>
		<antcall target="filter-package-files">
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<antcall target="build-exe-launcher">
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
			<param name="jar.location"
			       location="${dist.dir}"/>
		</antcall>
		<gzip src="${dist.dir}/classes/package-files/linux/jedit.1"
		      destfile="${dist.dir}/classes/package-files/linux/jedit.1.gz"/>
	</target>

	<target name="dist-slackware"
		depends="init,setup,prepare-dist-files"
		description="build the Slackware Package">
		<tar destfile="${dist.dir}/jedit-${jedit.version}-noarch-1sao.tgz"
		     longfile="gnu"
		     compression="gzip">
			<tarfileset file="${basedir}"
				    username="root"
				    group="root"
				    fullpath="./"/>
			<tarfileset dir="${dist.dir}/classes/package-files/linux/slackware"
				    includes="doinst.sh
					      slack-desc
					      slack-required"
				    username="root"
				    group="root"
				    prefix="install/"/>
			<tarfileset file="${dist.dir}/classes/package-files/linux/jedit"
				    mode="755"
				    username="root"
				    group="bin"
				    fullpath="usr/bin/jedit"/>
			<tarfileset dir="${dist.dir}/doc"
				    includes="*.txt"
				    username="root"
				    group="root"
				    prefix="usr/doc/jedit-${jedit.version}/"/>
			<tarfileset file="${dist.dir}/classes/package-files/linux/jedit.1.gz"
				    username="root"
				    group="root"
				    fullpath="usr/man/man1/jedit.1.gz"/>
			<tarfileset file="${dist.dir}/classes/package-files/linux/slackware/jEdit.desktop"
				    username="root"
				    group="root"
				    fullpath="usr/share/applications/jEdit.desktop"/>
			<tarfileset dir="${dist.dir}"
				    includes="doc/**
					      jars/**
					      keymaps/**
					      macros/**
					      modes/**
					      properties/**
					      startup/**
					      ${jar.filename}"
				    excludes="jars/MacOSX.jar"
				    username="root"
				    group="root"
				    prefix="usr/share/jedit-${jedit.version}/"/>
			<tarfileset dir="icons"
				    includes="jedit-file48.png
					      jedit-icon48.png"
				    username="root"
				    group="root"
				    prefix="usr/share/pixmaps/"/>
		</tar>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="compile-ar"
		depends="init">
		<mkdir dir="${classes.dir}/ar"/>
		<depend srcDir="${basedir}"
			destDir="${classes.dir}/ar"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<targetfileset dir="${classes.dir}/ar"/>
		</dependset>
		<javac srcdir="${basedir}"
		       destdir="${classes.dir}/ar"
		       includes="de/masters_of_disaster/ant/tasks/ar/**"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="${target.java.version}"
		       target="${target.java.version}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="true">
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="compile-deb"
		depends="init">
		<mkdir dir="${classes.dir}/deb"/>
		<depend srcDir="${basedir}"
			destDir="${classes.dir}/deb"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<targetfileset dir="${classes.dir}/deb"/>
		</dependset>
		<javac srcdir="${basedir}"
		       destdir="${classes.dir}/deb"
		       includes="de/masters_of_disaster/ant/tasks/deb/**"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="${target.java.version}"
		       target="${target.java.version}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="true">
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="compile-calculatesize"
		depends="init">
		<mkdir dir="${classes.dir}/calculatesize"/>
		<depend srcDir="${basedir}"
			destDir="${classes.dir}/calculatesize"
			cache="${classes.dir}"/>
		<dependset>
			<srcfilelist files="build.xml"/>
			<targetfileset dir="${classes.dir}/calculatesize"/>
		</dependset>
		<javac srcdir="${basedir}"
		       destdir="${classes.dir}/calculatesize"
		       includes="de/masters_of_disaster/ant/tasks/calculatesize/**"
		       debug="true"
		       debuglevel="${config.build.debuglevel}"
		       nowarn="${config.build.nowarn}"
		       deprecation="${config.build.deprecation}"
		       source="${target.java.version}"
		       target="${target.java.version}"
		       compiler="modern"
		       encoding="UTF-8"
		       includeAntRuntime="true">
			<compilerarg line="${config.build.compilerarg}"/>
		</javac>
	</target>

	<target name="dist-deb"
		depends="init,retrieve,setup,prepare-dist-files"
		description="build the DEB Package">
		<antcall target="compile-ar">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<antcall target="compile-deb">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<taskdef name="deb"
			 classname="de.masters_of_disaster.ant.tasks.deb.Deb"
			 classpath="${dist.dir}/classes/deb"
			 uri="antlib:de.masters_of_disaster.ant.tasks"/>
		<antcall target="compile-calculatesize">
			<param name="config.build.debuglevel"
			       value="lines,source"/>
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<taskdef name="calculatesize"
			 classname="de.masters_of_disaster.ant.tasks.calculatesize.CalculateSize"
			 classpath="${dist.dir}/classes/calculatesize"
			 uri="antlib:de.masters_of_disaster.ant.tasks"/>
		<mod:calculatesize realsizeproperty="deb.installed.size">
			<fileset dir="${dist.dir}/doc"
				 includes="*.txt"/>
			<fileset dir="${dist.dir}"
				 includes="classes/package-files/linux/jedit
					   classes/package-files/linux/deb/jedit
					   classes/package-files/linux/deb/jedit.desktop
					   classes/package-files/linux/jedit.1.gz
					   doc/**
					   jars/**
					   keymaps/**
					   macros/**
					   modes/**
					   properties/**
					   startup/**
					   ${jar.filename}"
				 excludes="jars/MacOSX.jar"/>
		</mod:calculatesize>
		<copy todir="${dist.dir}/classes/package-files/linux/deb"
		      encoding="UTF-8"
		      overwrite="true">
			<fileset file="package-files/linux/deb/control"/>
			<filterset>
				<filter token="jedit.build.number"
					value="${jedit.build.number}"/>
				<filter token="deb.installed.size"
					value="${deb.installed.size}"/>
			</filterset>
		</copy>
		<mod:deb destfile="${dist.dir}/jedit_${jedit.version}_all.deb"
			 tempDir="${dist.dir}/classes/deb"
			 deleteTempFiles="false"
			 includeMd5sums="true">
			<controlfileset file="${dist.dir}/classes/package-files/linux/deb/control"/>
			<controlfileset dir="${dist.dir}/classes/package-files/linux/deb"
					includes="postinst
						  postrm"
					mode="755"/>
			<datafileset file="."
				     fullpath="usr/"/>
			<datafileset file="."
				     fullpath="usr/bin/"/>
			<datafileset file="${dist.dir}/classes/package-files/linux/jedit"
				     fullpath="usr/bin/jedit"
				     mode="755"/>
			<datafileset file="."
				     fullpath="usr/lib/"/>
			<datafileset file="."
				     fullpath="usr/lib/menu/"/>
			<datafileset file="${dist.dir}/classes/package-files/linux/deb/jedit"
				     fullpath="usr/lib/menu/jedit"/>
			<datafileset file="."
				     fullpath="usr/share/"/>
			<datafileset file="."
				     fullpath="usr/share/applications/"/>
			<datafileset file="${dist.dir}/classes/package-files/linux/deb/jedit.desktop"
				     fullpath="usr/share/applications/jedit.desktop"/>
			<datafileset file="."
				     fullpath="usr/share/doc/"/>
			<datafileset file="."
				     fullpath="usr/share/doc/jEdit/"/>
			<datafileset dir="${dist.dir}/doc"
				     includes="*.txt"
				     prefix="usr/share/doc/jEdit/"/>
			<datafileset file="."
				     fullpath="usr/share/jEdit/"/>
			<datafileset dir="${dist.dir}"
				     includes="doc/**
					       keymaps/**
					       macros/**
					       modes/**
					       properties/**
					       startup/**
					       ${jar.filename}"
				     prefix="usr/share/jEdit/"/>
			<datafileset file="."
				     fullpath="usr/share/jEdit/jars/"/>
			<datafileset dir="${dist.dir}/jars"
				     excludes="MacOSX.jar"
				     prefix="usr/share/jEdit/jars/"/>
			<datafileset file="."
				     fullpath="usr/share/man/"/>
			<datafileset file="."
				     fullpath="usr/share/man/man1/"/>
			<datafileset file="${dist.dir}/classes/package-files/linux/jedit.1.gz"
				     fullpath="usr/share/man/man1/jedit.1.gz"/>
		</mod:deb>
		<contrib:if>
			<istrue value="${jedit.version.final}"/>
			<contrib:then>
				<length property="deb.size"
					file="${dist.dir}/jedit_${jedit.version}_all.deb"/>
				<checksum file="${dist.dir}/jedit_${jedit.version}_all.deb"
					  algorithm="MD5"
					  property="deb.md5"/>
				<checksum file="${dist.dir}/jedit_${jedit.version}_all.deb"
					  algorithm="SHA1"
					  property="deb.sha1"/>
				<checksum file="${dist.dir}/jedit_${jedit.version}_all.deb"
					  algorithm="SHA-256"
					  property="deb.sha256"/>
				<copy todir="${dist.dir}"
				      encoding="UTF-8"
				      overwrite="true">
					<fileset file="package-files/linux/deb/Packages"/>
					<filterset>
						<filter token="jedit.build.number"
							value="${jedit.build.number}"/>
						<filter token="deb.installed.size"
							value="${deb.installed.size}"/>
						<filter token="deb.repository.file"
							value="jedit/${jedit.version}/jedit_${jedit.version}_all.deb"/>
						<filter token="deb.size"
							value="${deb.size}"/>
						<filter token="deb.md5"
							value="${deb.md5}"/>
						<filter token="deb.sha1"
							value="${deb.sha1}"/>
						<filter token="deb.sha256"
							value="${deb.sha256}"/>
					</filterset>
				</copy>
				<gzip src="${dist.dir}/Packages"
				      destfile="${dist.dir}/Packages.gz"/>
				<bzip2 src="${dist.dir}/Packages"
				       destfile="${dist.dir}/Packages.bz2"/>
				<length property="packages.size"
					file="${dist.dir}/Packages"/>
				<checksum file="${dist.dir}/Packages"
					  algorithm="MD5"
					  property="packages.md5"/>
				<checksum file="${dist.dir}/Packages"
					  algorithm="SHA1"
					  property="packages.sha1"/>
				<checksum file="${dist.dir}/Packages"
					  algorithm="SHA-256"
					  property="packages.sha256"/>
				<length property="packages.gz.size"
					file="${dist.dir}/Packages.gz"/>
				<checksum file="${dist.dir}/Packages.gz"
					  algorithm="MD5"
					  property="packages.gz.md5"/>
				<checksum file="${dist.dir}/Packages.gz"
					  algorithm="SHA1"
					  property="packages.gz.sha1"/>
				<checksum file="${dist.dir}/Packages.gz"
					  algorithm="SHA-256"
					  property="packages.gz.sha256"/>
				<length property="packages.bz2.size"
					file="${dist.dir}/Packages.bz2"/>
				<checksum file="${dist.dir}/Packages.bz2"
					  algorithm="MD5"
					  property="packages.bz2.md5"/>
				<checksum file="${dist.dir}/Packages.bz2"
					  algorithm="SHA1"
					  property="packages.bz2.sha1"/>
				<checksum file="${dist.dir}/Packages.bz2"
					  algorithm="SHA-256"
					  property="packages.bz2.sha256"/>
				<script language="beanshell">
					<classpath>
						<fileset dir="${lib.dir}/scripting"
							 includes="*.jar"/>
					</classpath>

					new Formatter(new File(project.getProperty("dist.dir"), "Release"), "UTF-8", Locale.ENGLISH)
						.format("Date: %1$ta, %1$td %1$tb %1$tY %1$tT %1$tZ\n", new Object[] {
							Calendar.getInstance(TimeZone.getTimeZone("UTC")) })
						.format("MD5Sum:\n", new Object[0])
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.md5"),
							project.getProperty("packages.size"),
							"Packages" })
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.bz2.md5"),
							project.getProperty("packages.bz2.size"),
							"Packages.bz2" })
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.gz.md5"),
							project.getProperty("packages.gz.size"),
							"Packages.gz" })
						.format("SHA1:\n", new Object[0])
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.sha1"),
							project.getProperty("packages.size"),
							"Packages" })
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.bz2.sha1"),
							project.getProperty("packages.bz2.size"),
							"Packages.bz2" })
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.gz.sha1"),
							project.getProperty("packages.gz.size"),
							"Packages.gz" })
						.format("SHA256:\n", new Object[0])
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.sha256"),
							project.getProperty("packages.size"),
							"Packages" })
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.bz2.sha256"),
							project.getProperty("packages.bz2.size"),
							"Packages.bz2" })
						.format(" %s %16s %s\n", new Object[] {
							project.getProperty("packages.gz.sha256"),
							project.getProperty("packages.gz.size"),
							"Packages.gz" })
						.close()
				</script>
				<contrib:runtarget target="dist-sign-deb-Release"/>
			</contrib:then>
		</contrib:if>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="dist-sign-deb-Release"
		depends="init,retrieve,setup"
		description="sign the DEB Release file">
		<contrib:if>
			<not>
				<or>
					<isset property="config.gpg.secring"/>
					<istrue value="${config.gpg.ignore.missing.secring}"/>
				</or>
			</not>
			<contrib:then>
				<input>
WARN: The property "gpg.secring" is not set in build.properties, you may find example values in build.properties.sample.
WARN: The debian repository metadata will not be signed (Release.gpg) unless you define that property.
WARN: Set the property "gpg.ignore.missing.secring" to "true" in build.properties to suppress this message.

Press Return key to continue...
				</input>
			</contrib:then>
		</contrib:if>
		<contrib:if>
			<isset property="config.gpg.secring"/>
			<contrib:then>
				<input addproperty="config.gpg.secring.password">
					<handler type="secure"/>
	Please enter the secring password and press Return key.
	You can also set the property "gpg.secring.password" in build.properties instead.

	Password: </input>
			</contrib:then>
		</contrib:if>
		<script language="beanshell">
			<classpath>
				<fileset dir="${lib.dir}/scripting"
					 includes="*.jar"/>
			</classpath>

			import java.security.Security;
			import org.bouncycastle.bcpg.ArmoredOutputStream;
			import org.bouncycastle.bcpg.BCPGOutputStream;
			import org.bouncycastle.jce.provider.BouncyCastleProvider;
			import org.bouncycastle.openpgp.PGPUtil;
			import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
			import org.bouncycastle.openpgp.PGPSignatureGenerator;
			import org.bouncycastle.openpgp.PGPSignature;

			if (project.getProperty("config.gpg.secring") == null)
			{
				return;
			}
			Security.addProvider(new BouncyCastleProvider());
			fIn = null;
			out = null;
			keyIn = null;
			try
			{
				keyIn = new BufferedInputStream(new FileInputStream(project.getProperty("config.gpg.secring")));
				pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyIn));
				if (pgpSec == null)
				{
					System.out.println("Secring could not be decoded");
					return;
				}
			outer:	for (keyRing : pgpSec.getKeyRings())
				{
					for (key : keyRing.getSecretKeys())
					{
						if (key.isSigningKey())
						{
							pgpSec = key;
							break outer;
						}
					}
				}
				if (pgpSec == null)
				{
					System.out.println("No signing key found");
					return;
				}
				pgpPrivKey = pgpSec.extractPrivateKey(project.getProperty("config.gpg.secring.password").toCharArray(), "BC");
				sGen = new PGPSignatureGenerator(pgpSec.getPublicKey().getAlgorithm(), PGPUtil.SHA1, "BC");
				sGen.initSign(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
				fIn = new BufferedInputStream(new FileInputStream(new File (project.getProperty("dist.dir"), "Release")));
				while ((ch = fIn.read()) >= 0)
				{
					sGen.update((byte)ch);
				}
				out = new BCPGOutputStream(new ArmoredOutputStream(new BufferedOutputStream(new FileOutputStream(new File (project.getProperty("dist.dir"), "Release.gpg")))));
				sGen.generate().encode(out);
			} finally {
				if (fIn != null)
				{
					fIn.close();
				}
				if (out != null)
				{
					out.close();
				}
				if (keyIn != null)
				{
					keyIn.close();
				}
			}
		</script>
	</target>

	<target name="dist-win-finish"
		depends="init,setup"
		description="finish building the Windows installer (EXE-file) on Windows or via wine">
		<fail message="The Windows installer (EXE-file) can only be built on Windows or via wine currently">
			<condition>
				<not>
					<or>
						<os family="windows"/>
						<istrue value="${config.innosetup.via.wine}"/>
					</or>
				</not>
			</condition>
		</fail>
		<fail message="Please set the property &quot;innosetup.compiler.executable&quot; in build.properties, you may find example values in build.properties.sample"
		      unless="config.innosetup.compiler.executable"/>
		<fail message="Please set the property &quot;wine.executable&quot; in build.properties, you may find example values in build.properties.sample">
			<condition>
				<and>
					<istrue value="${config.innosetup.via.wine}"/>
					<not>
						<isset property="config.wine.executable"/>
					</not>
				</and>
			</condition>
		</fail>
		<antcall target="filter-package-files">
			<param name="classes.dir"
			       location="${dist.dir}/classes"/>
		</antcall>
		<contrib:if>
			<istrue value="${config.innosetup.via.wine}"/>
			<contrib:then>
				<exec executable="${config.wine.executable}"
				      dir="${dist.dir}"
				      failonerror="true">
					<arg value="${config.innosetup.compiler.executable}"/>
					<arg value="classes/package-files/windows/win32installer.iss"/>
				</exec>
			</contrib:then>
			<contrib:else>
				<exec executable="${config.innosetup.compiler.executable}"
				      dir="${dist.dir}"
				      failonerror="true">
					<arg value="classes/package-files/windows/win32installer.iss"/>
				</exec>
			</contrib:else>
		</contrib:if>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="dist-win"
		depends="init,setup,prepare-dist-files"
		description="build the Windows installer (EXE-file)">
		<contrib:if>
			<or>
				<os family="windows"/>
				<istrue value="${config.innosetup.via.wine}"/>
			</or>
			<contrib:then>
				<antcall target="dist-win-finish">
					<param name="wipe.dist.files"
					       value="false"/>
				</antcall>
			</contrib:then>
			<contrib:else>
				<tar destfile="${dist.dir}/jedit${jedit.version}-dist-win-finish.tar.bz2"
				     basedir="${basedir}"
				     longfile="gnu"
				     includes="build.properties.sample
					       build.xml
					       ivy.xml
					       ivysettings.xml
					       icons/jedit.ico
					       icons/WindowsInstallerSmallImage.bmp
					       icons/WindowsInstallerImage.bmp
					       org/gjt/sp/jedit/jEdit.java
					       package-files/windows/win32installer.iss
					       ${config.dist.dir}/jedit.exe
					       ${config.dist.dir}/${jar.filename}
					       ${config.dist.dir}/classes/package-files/windows/**
					       ${config.dist.dir}/doc/**
					       ${config.dist.dir}/jars/**
					       ${config.dist.dir}/keymaps/**
					       ${config.dist.dir}/macros/**
					       ${config.dist.dir}/modes/**
					       ${config.dist.dir}/properties/**
					       ${config.dist.dir}/startup/**"
				     excludes="${config.dist.dir}/jars/MacOSX.jar"
				     compression="bzip2"/>
			</contrib:else>
		</contrib:if>
		<property name="wipe.dist.files"
			  value="true"/>
		<contrib:runtarget target="dist-cleanup"/>
	</target>

	<target name="dist"
		depends="init,setup"
		description="build all distribution files">
		<property name="wipe.dist.files"
			  value="false"/>
		<contrib:runtarget target="dist-java"/>
		<contrib:runtarget target="dist-manuals"/>
		<contrib:runtarget target="dist-src"/>
		<contrib:runtarget target="dist-slackware"/>
		<contrib:runtarget target="dist-deb"/>
		<contrib:runtarget target="dist-mac"/>
		<contrib:runtarget target="dist-win"/>
		<antcall target="dist-cleanup">
			<param name="wipe.dist.files"
			       value="true"/>
		</antcall>
	</target>

	<target name="dist-cleanup"
		depends="init,setup">
		<contrib:if>
			<istrue value="${wipe.dist.files}"/>
			<contrib:then>
				<delete includeemptydirs="true">
					<fileset dir="${dist.dir}">
						<or>
							<filename name="macros/**"/>
							<filename name="doc/**"/>
							<filename name="jars/**"/>
							<filename name="keymaps/**"/>
							<filename name="modes/**"/>
							<filename name="properties/**"/>
							<filename name="startup/**"/>
							<filename name="${jar.filename}"/>
							<filename name="jedit.exe"/>
							<and>
								<filename name="*.tar.bz2"/>
								<filename name="${src.archive.filename}"
									  negate="true"/>
								<filename name="jedit${jedit.version}-dist-mac-finish.tar.bz2"
									  negate="true"/>
								<filename name="jedit${jedit.version}-dist-win-finish.tar.bz2"
									  negate="true"/>
							</and>
							<filename name="classes/**"/>
							<filename name="*-${mac.disk.image.filename}"/>
						</or>
					</fileset>
				</delete>
			</contrib:then>
		</contrib:if>
	</target>
</project>
