<?xml version="1.0" encoding="iso-8859-1"?>
<project name="ForrestLogAnalyser build file" default="all" basedir="">

    <description>
        This is a common Ant build file for projects. Version 1.1
    </description>

	<target name="project_init" description="Initialize environment">
	    <property name="component.name" value="ForrestLogAnalyser"/>
	    <property name="component.package" value="uy.edu.udelar.forrest.forrestloganalyser"/>
	    <property name="component.title" value="Forrest Log Analyser"/>
	    <property name="component.version" value="1.0"/>
    </target>
	
    <target name="init" depends="project_init" description="Initialize environment">
        <property name="path.bin" value="bin"/>
        <property name="path.metainf" value="bin/META-INF"/>
        <property name="path.dist" value="dist"/>
        <property name="path.dist.classes" value="bin"/>
        <property name="path.dist.lib" value="dist/lib"/>
        <property name="path.dist.bin" value="dist/bin"/>
        <property name="path.dist.cfg" value="dist/cfg"/>
        <property name="path.dist.log" value="dist/log"/>
        <property name="path.lib" value="lib"/>
        <property name="path.src" value="src"/>
        <property name="path.cfg" value="cfg"/>
        <property name="path.log" value="log"/>
        <property name="compile.debug" value="true"/>
        <property name="compile.deprecation" value="true"/>
        <property name="compile.jdk-version.source" value="1.4"/>
        <property name="compile.jdk-version.target" value="1.4"/>
        <property name="compile.optimize" value="true"/>
        <property file="${basedir}/build.properties"/>

        <path id="compile.classpath">
            <fileset dir="${path.dist.lib}">
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${path.lib}">
                <include name="*.jar"/>
            </fileset>
        </path>

    </target>

    <target name="project_prepare" description="Project-level prepare phase"/>

    <target name="make_directories" description="Creates all project directories" depends="init">
        <mkdir dir="${path.bin}"/>
        <mkdir dir="${path.metainf}"/>
        <mkdir dir="${path.dist}"/>
        <mkdir dir="${path.dist.log}"/>
        <mkdir dir="${path.dist.classes}"/>
        <mkdir dir="${path.dist.lib}"/>
        <mkdir dir="${path.dist.bin}"/>
        <mkdir dir="${path.dist.cfg}"/>
        <mkdir dir="${path.lib}"/>
        <mkdir dir="${path.src}"/>
        <mkdir dir="${path.cfg}"/>
        <mkdir dir="${path.log}"/>
    </target>

    <target name="prepare" depends="init, make_directories, project_prepare" description="Prepare build directory">
    </target>

    <target name="compile" depends="prepare" description="Compile source">
        <javac debug="${compile.debug}" deprecation="${compile.deprecation}" destdir="${path.dist.classes}" target="${compile.jdk-version.target}" source="${compile.jdk-version.source}" optimize="${compile.optimize}" srcdir="${path.src}">
            <classpath refid="compile.classpath"/>
        </javac>
    </target>

    <target name="project_clean" description="Project-level prepare phase"/>

    <target name="clean" depends="init,project_clean" description="Wipeout all generated files">
        <delete dir="${path.dist.classes}"/>
        <delete dir="${path.dist.bin}"/>
        <delete dir="${path.dist.lib}"/>
        <delete dir="${path.dist.cfg}"/>
        <delete dir="${path.dist.log}"/>
    </target>

    <target name="all" depends="clean,compile,jar" description="Clean and compile all components"/>

    <target name="jar" depends="compile" description="Create binary distribution">
		<manifest file="${path.metainf}/MANIFEST.MF">
			<attribute name="Built-By" value="${user.name}"/>
			<section name="common">
				<attribute name="Specification-Title" value="ForrestLogAnalyser"/>
				<attribute name="Specification-Version" value="${component.version}"/>
				<attribute name="Specification-Vendor" value="FING-UDELAR"/>
				<attribute name="Implementation-Title" value="common"/>
				<attribute name="Implementation-Version" value="${component.version}"/> 
				<attribute name="Implementation-Vendor" value="FING-UDELAR"/>
			</section>
			<attribute name="Main-Class" value="uy.edu.udelar.forrest.forrestloganalyser.Main"/>
		</manifest>
        <jar basedir="${path.dist.classes}" jarfile="${path.dist.bin}/${component.name}-${component.version}.jar" manifest="${path.metainf}/MANIFEST.MF">
            <include name="**/*.class"/>
            <fileset dir="${path.lib}">
                <include name="**/*.jar"/>
            </fileset>
        </jar>
		<copy overwrite="true" todir="${path.dist.lib}" >
            <fileset dir="${path.lib}">
                <include name="*.jar"/>
            </fileset>
		</copy>
		<copy overwrite="true" todir="${path.dist.cfg}" >
            <fileset dir="${path.cfg}">
                <include name="*"/>
            </fileset>
		</copy>
		<copy overwrite="true" todir="${path.dist.log}" >
            <fileset dir="${path.log}">
                <include name="*"/>
            </fileset>
		</copy>
		<copy overwrite="true" todir="${path.dist}" >
            <fileset dir="${path.src}">
                <include name="startup.sh"/>
            </fileset>
		</copy>
        <delete>
            <fileset dir="${path.dist.classes}">
                <include name="LICENSE"/>
            </fileset>
        </delete>
    </target>

    <target name="src-zip" depends="compile" description="Creates source distribution">
        <delete>
            <fileset dir="${path.dist.lib}" includes="*-src.zip"/>
        </delete>
        <zip basedir="." destfile="${path.dist.lib}/${component.name}-${component.version}-src.zip" whenempty="fail">
            <include name="**/*.*"/>
            <include name="*"/>
            <include name="**/*"/>
            <exclude name="${path.dist}/**/*.*"/>
            <exclude name="*.*~"/>      <!-- JEdit backups -->
            <exclude name=".nbattrs"/>  <!-- Netbeans filesystem attributes -->
            <exclude name="*.old"/>
        </zip>
    </target>

    <target name="dist" depends="jar,src-zip"/>

    <target name="zip" depends="compile" description="Creates source distribution">
        <delete>
            <fileset dir="${path.dist}" includes="*.zip"/>
        </delete>
        <zip basedir="${path.dist}" destfile="${path.dist}/${component.name}-${component.version}.zip" whenempty="fail">
            <include name="startup.sh"/>
            <include name="bin/*"/>
            <include name="cfg/*"/>
            <include name="lib/*"/>
            <include name="log/*"/>
        </zip>
    </target>


</project>