<?xml version="1.0"?>

<!-- $Id: build.xml 9428 2009-04-28 08:52:28Z rjubeh $ -->

<project name="Fujaba" default="all" basedir="../">

   <target name="updateLibs">
      <mkdir dir="libs/backup"/>
      <move overwrite="true" todir="libs/backup">
         <fileset dir="libs" includes="*.jar"/>
      </move>
      <antcall target="copy-dependencies"/>
   </target>

   <target name="copy-dependencies">
      <antcall target="mvn">
         <param name="goals" value="dependency:copy-dependencies"/>
      </antcall>
   </target>

   <target name="mvn">
      <property name="maven.home" value="build/maven" />
      <property name="maven.failonerror" value="true" />
      <java classname="org.codehaus.classworlds.Launcher" fork="yes"
            failonerror="${maven.failonerror}" dir="${basedir}">
         <jvmarg value="-Xmx384m"/>
         <classpath>
            <pathelement location="${maven.home}/boot/classworlds-1.1.jar"/>
         </classpath>
         <sysproperty key="classworlds.conf" value="${maven.home}/bin/m2.conf"/>
         <sysproperty key="maven.home" value="${maven.home}"/>
         <arg line="${goals}"/>
      </java>
   </target>

   <target name="init">
		<!-- gain access to system properties -->
		<property environment="env" />

		<!-- you can override properties here -->
		<property file="build/build.properties" />

		<property name="prj.dir" location="." />
		<property name="prj.builddir" value="${prj.dir}/build" />
		<property name="prj.sourcedir" value="${prj.dir}/src"/>
		<property name="prj.testsourcedir" value="${prj.dir}/testsrc"/>
		<property name="prj.classdir" value="${prj.dir}/target/classes"/>
		<property name="prj.testclassdir" value="${prj.dir}/target/test-classes"/>
		<property name="prj.compiler" value="modern"/>
		<property name="prj.apidir" value="${prj.dir}/target/doc/api"/>
      <property name="prj.junitdir" value="${prj.dir}/target/doc/junit"/>
		<property name="prj.libdir" value="${prj.dir}/libs"/>
		<property name="prj.name" value="Fujaba"/>
		<property name="prj.packages" value="de.*,javax.*"/>

		<property name="debug.value" value="on"/>
		<property name="deprecation.value" value="off"/>
		<property name="optimization.value" value="off"/>
		<property name="fork.value" value="yes"/>

		<property name="prj.instdir" location="../Fujaba_HEAD_RT/" />
   		<property name="prj.mainclass" value="de.uni_paderborn.fujaba.app.FujabaApp" />

      <path id="prj.classpath">
         <fileset dir="${prj.libdir}">
            <include name="*.jar"/>
         </fileset>
      </path>
   
		<!-- Loading jcoverage tasks. -->
		<taskdef classpath="${prj.dir}/antlibs/jcoverage.jar:${prj.dir}/libs/log4j.jar:${prj.dir}/antlibs/bcel.jar:${prj.dir}/antlibs/jakarta-oro.jar"
         resource="tasks.properties"
         />
		<tstamp/>

		<!-- create some directories -->
		<mkdir dir="${prj.classdir}"/>
	</target>

	<target name="all" depends="updateLibs, init">
		<mkdir dir="${prj.classdir}"/>
		<javac srcdir="${prj.sourcedir}"
         memoryInitialSize="128m"
         memoryMaximumSize="512m"
         destdir="${prj.classdir}"
         debug="${debug.value}"
         optimize="${optimization.value}"
         target="1.5"
         fork="${fork.value}"
         includes="de/**/*.java,test/de/**/*.java"
         deprecation="${deprecation.value}"
         >
			<classpath refid="prj.classpath">

			</classpath>
		</javac>
	</target>

	<target name="clean" depends="init">
		<delete>
			<fileset dir="${prj.classdir}"
            includes="de/**/*.class, javax/**/*.class,test/de/**/*.class"
            />
		</delete>
		<!-- hotfix -->
		<mkdir dir="${prj.testclassdir}"/>
		<delete>
			<fileset dir="${prj.testclassdir}" includes="test/de/**/*.class"/>
		</delete>
	</target>

	<target name="jar" depends="all">
		<pathconvert property="mf.classpath" pathsep=" " dirsep="/">
		    <path refid="prj.classpath" />
			<map from="${prj.libdir}" to="libs" />
		</pathconvert>
		<jar destfile="${prj.dir}/fujaba.jar">
			<manifest>
			      <attribute name="Class-Path" value="${mf.classpath}"/>
			      <attribute name="Main-Class" value="${prj.mainclass}"/>
			</manifest>
			<fileset dir="${prj.classdir}">
				<include name="de/**/*.class"/>
			</fileset>
			<fileset dir="${prj.sourcedir}">
				<include name="de/**/*.xml"/>
				<include name="version.xml"/>
				<include name="**/*.gif"/>
				<include name="**/propertyeditor.config"/>
				<include name="**/*.dtd" />
				<include name="**/*.xsd" />
				<include name="**/*.tpl" />
				<include name="**/*.png" />
				<include name="**/*.properties" />
				<include name="properties/dialog.xml" />
			</fileset>
		</jar>
	</target>

	<target name="run" depends="jar">
		<java classname="de.uni_paderborn.fujaba.app.FujabaApp"
         fork="${fork.value}"
         dir="${prj.dir}"
         >
			<jvmarg value="-mx512m"/>
			<arg value="-noabout"/>
			<classpath refid="prj.classpath"/>
			<classpath location="${prj.dir}/fujaba.jar"/>
		</java>
	</target>

	<target name="doc" depends="init">
		<mkdir dir="${prj.apidir}"/>
		<javadoc sourcepath="${prj.sourcedir}"
         destdir="${prj.apidir}"
         packagenames="${prj.packages}"
         windowtitle="${prj.name} API Specification (generated on ${DSTAMP} ${TSTAMP})"
         doctitle="${prj.name} API Specification"
         maxmemory="256m"
         classpathref="prj.classpath"
         private="true"
         version="true"
         author="true"
         header="${prj.name}"
         footer="${prj.name}"
      >
			<link href="http://java.sun.com/j2se/1.5.0/docs/api/" />
			<bottom>
				<![CDATA[
           <font size=-1>
				<a href=mailto:fujaba@uni-paderborn.de>Contact</a> the Fujaba group<br>Visit the <a href=http://www.uni-paderborn.de/fachbereich/AG/schaefer/ag_dt/PG/Fujaba/fujaba.html>Homepage</a> of the Fujaba group</font>
           ]]>
        </bottom>
		</javadoc>
	</target>

	<!--
   extensive test with jcoverage etc .
   -->
	<target name="exttest" depends="compiletest">
		<copy todir="${prj.classdir}-instrumented">
			<fileset dir="${prj.dir}">
				<include name="de/**/*.xml"/>
			</fileset>
		</copy>

		<instrument todir="${prj.classdir}-instrumented">
			<fileset dir="${prj.classdir}">
				<include name="**/*.class"/>
			</fileset>
		</instrument>
		<mkdir dir="${prj.junitdir}"/>
		<mkdir dir="${prj.junitdir}/jcoverage"/>
		<junit fork="true" dir="${prj.dir}">
			<classpath location="${prj.classdir}-instrumented"/>
			<classpath location="${prj.classdir}"/>
			<classpath location="${prj.dir}/antlibs/jcoverage.jar"/>
			<classpath refid="prj.classpath"/>
			<formatter type="brief" usefile="false"/>
			<formatter type="xml"/>

			<batchtest fork="yes" todir="${prj.junitdir}">
				<fileset dir="${prj.sourcedir}">
					<include name="test/**/*Test*.java"/>
					<exclude name="**/AllFujabaTest.java"/>
					<exclude name="**/FujabaDialogTest.java"/>
				</fileset>
			</batchtest>

		</junit>
		<junitreport todir="${prj.junitdir}">
			<fileset dir="${prj.junitdir}">
				<include name="TEST-*.xml"/>
			</fileset>
			<report format="frames" todir="${prj.junitdir}"/>
		</junitreport>
		<report srcdir="${prj.dir}"
         format="xml"
         destdir="${prj.builddir}/jcoverage"
         />
		<report srcdir="${prj.dir}" destdir="${prj.builddir}/jcoverage"/>
	</target>

	<!--
   compile all tests sources in ${prj.testsourcedir} to ${prj.testclassdir}
   -->
	<target name="compiletest" depends="updateLibs,jar,init,testSettings">
		<mkdir dir="${prj.testclassdir}"/>

		<javac srcdir="${prj.testsourcedir}"
         memoryInitialSize="128m"
         memoryMaximumSize="512m"
         destdir="${prj.testclassdir}"
         debug="${debug.value}"
         target="1.5"
         fork="${fork.value}"
         includes="**/*.java"
         deprecation="${deprecation.value}"
         >
			<classpath>
				<pathelement path="${prj.dir}/fujaba.jar"/>
				<fileset dir="${prj.libdir}">
					<include name="*.jar"/>
				</fileset>
			</classpath>
		</javac>
	</target>

	<!--
   'short' test without jcoverage
   -->
	<target name="test" depends="compiletest">
      <mkdir dir="${prj.junitdir}"/>
      <junit fork="yes" timeout="300000" dir="${prj.dir}" failureproperty="junit.failure" maxmemory="512m">
			<classpath path="${prj.dir}/fujaba.jar"/>
			<classpath refid="prj.classpath"/>
			<classpath path="${prj.testclassdir}"/>
			<classpath path="${prj.dir}/properties"/>
			<formatter type="xml"/>
			<formatter type="plain"/>

         <batchtest fork="yes" todir="${prj.junitdir}">
            <fileset dir="${prj.testsourcedir}">
               <include name="**/*Test.java"/>
            </fileset>
         </batchtest>
		</junit>

		<!-- create build.dir/junit/TESTS-TestSuites.xml -->
		<junitreport todir="${prj.junitdir}">
			<fileset dir="${prj.junitdir}">
				<include name="TEST-*.xml"/>
			</fileset>
			<report format="noframes" todir="${prj.junitdir}"/>
		</junitreport>

      <fail if="junit.failure"/>
   </target>

	<!--
      save properties for testcases
   -->
	<target name="testSettings" depends="init">

		<filter token="FUJABA_DIR" value="${prj.dir}"/>
		<filter token="JDK_FOLDER_DIR" value="${env.JAVA_HOME}"/>
		<copy file="${prj.dir}/properties/testsettings.properties_template"
         tofile="${prj.dir}/properties/testsettings.properties"
         filtering="true"
         overwrite="true"
         />

	</target>



	<!-- - - - - - - - - - - - - - - - - - 
          target: src-jar                      
         - - - - - - - - - - - - - - - - - -->
	<target name="src-jar" depends="init">
		<jar destfile="${prj.dir}/fujaba-src.jar">
			<fileset dir="${prj.sourcedir}">
				<include name="**/*.java" />
			</fileset>
		</jar>
	</target>

	<!-- 
    	install current fujaba version in dir prj.instdir
          -->
	<target name="inst" depends="jar,src-jar" description="--> install current version in the prj.instdir">

		<!-- create necessary directories -->
		<mkdir dir="${prj.instdir}" />
		<mkdir dir="${prj.instdir}/libs" />
		<mkdir dir="${prj.instdir}/build" />

		<!-- copy fujaba.jar -->
		<copy todir="${prj.instdir}" file="${prj.dir}/fujaba.jar" />

		<!-- copy fujaba-src.jar -->
		<copy todir="${prj.instdir}" file="${prj.dir}/fujaba-src.jar" />

		<!-- copy libs.dir -->
		<copy todir="${prj.instdir}/libs">
			<fileset dir="${prj.libdir}">
				<include name="**/**" />
			</fileset>
		</copy>

		<!-- copy build.xml -->
		<copy todir="${prj.instdir}/build" file="${prj.dir}/build/build.xml" />
	</target>

	<!-- 
		start FujabaApp without any build dependcy 
	-->
	<target name="run-alone" depends="init">
		<java classname="de.uni_paderborn.fujaba.app.FujabaApp" fork="yes" dir="${prj.dir}">
			<jvmarg value="-mx512m" />
			<arg value="-noabout" />
			<classpath refid="prj.classpath" />
			<classpath location="${prj.dir}/fujaba.jar" />
		</java>
	</target>

</project>


