<!-- -*- Mode: SGML; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- -->

<!-- ========================================================================= -->
<!-- Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC),        -->
<!-- 2003 Contributors                                                         -->
<!-- All rights reserved.                                                      -->
<!-- This program and the accompanying materials are made available            -->
<!-- under the terms of the Common Public License v1.0                         -->
<!-- which accompanies this distribution and is available at                   -->
<!-- http://www.eclipse.org/legal/cpl-v10.html                                 -->
<!--                                                                           -->
<!-- Contributors:                                                             -->
<!--     Xerox/PARC     initial implementation                                 -->
<!--     Adrian Colyer / George Harley eclipse plugin targets                  -->
<!-- ========================================================================= -->

<!DOCTYPE project [
<!ENTITY build-properties SYSTEM "build-properties.xml">
]>
<project name="build" default="all" basedir=".">

    <target name="all"     depends="aspectj,eclipse.plugins"/>
    <target name="rebuild" depends="clean,all"/>
    <target name="clean"   depends="clean-directories"/>


    <!-- ===================================================================== -->
    <!-- Init                                                                  -->
    <!-- ===================================================================== -->
    <!-- use this file to force prop values -->
    <property file="${basedir}/local.properties"/>
    
    &build-properties;

    <target name="init" depends="init-properties,init-directories">
      <property name="build.config" value="verbose"/> 
      <property name="trim.testing.default" value="true"/>
      <property name="aj.installer.jar" 
            location="${aj.dist.dir}/aspectj-${build.version.short}.jar"/>

      <available property="ant.lib.aspectjtools"
         file="${ant.home}/lib/aspectjtools.jar"
         value="Expect classpath errors from ${ant.home}/lib/aspectjtools.jar"/>

      <available property="ant.lib.aspectjrt"
         file="${ant.home}/lib/aspectjrt.jar"
         value="Expect classpath errors from ${ant.home}/lib/aspectjrt.jar"/>

      <available property="testing.drivers.all.available"
         file="${aj.jar.dir}/testing-drivers-all.jar"
         value="${aj.jar.dir}/testing-drivers-all.jar"/>

    </target>

    <target name="version-uptodate" depends="init,init-taskdefs"
         unless="version-uptodate.done">
         <!-- XXX change task to pre-check & avoid scan if dates uptodate -->
		 <versionuptodate
			version="${build.version}"
			versionSourceFile="${aspectj.modules.dir}/bridge/src/org/aspectj/bridge/Version.java"
			versionTagFile="${aj.temp.dir}/versionUptodate"/>
		 
		 <available file="${aj.temp.dir}/versionUptodate"
		       property="version.uptodate"/>
         <property name="version-uptodate.done" value="done"/>
    </target>

    <target name="init-version" depends="init,init-filters,version-uptodate" >
      <antcall target="init-filters"/>
      <copy file="${aspectj.modules.dir}/build/lib/BridgeVersion.java.txt"
          tofile="${aspectj.modules.dir}/bridge/src/org/aspectj/bridge/Version.java"
          overwrite="yes" filtering="yes"/>
      <property name="init.version.done" value="done"/>
      <!-- consider checking this in? -->
    </target>


    <!-- ===================================================================== -->
    <!-- Misc setup and warnings                                               -->
    <!-- ===================================================================== -->

    <target name="warn.ant.lib.aspectjrt" if="ant.lib.aspectjrt">
      <echo message="----- WARNING: ${ant.lib.aspectjrt}" /> 
    </target>

    <target name="warn.ant.lib.aspectjtools" if="ant.lib.aspectjtools">
      <echo message="----- WARNING: ${ant.lib.aspectjtools}" /> 
    </target>

	<target name="fail-unless-boot-libraries-uptodate" depends="init"
	 description="fail unless all boot libraries are up-to-date">
		
		<antcall target="verify-boot-lib">
			<param name="boot.lib"        value="test/aspectjrt.jar"/>
			<param name="vbl.module.name" value="runtime"/>
		</antcall>
		
		<antcall target="verify-boot-lib">
			<param name="boot.lib"        value="build/build.jar"/>
			<param name="vbl.module.name" value="build"/>
		</antcall>

		<antcall target="verify-boot-lib">
			<param name="boot.lib"        value="test/testing-client.jar"/>
			<param name="vbl.module.name" value="testing-client"/>
		</antcall>

		<echo message="fyi, bridge/util changes rarely mean client is invalid"/>
		<antcall target="verify-boot-lib">
			<param name="boot.lib"        value="test/testing-client.jar"/>
			<param name="vbl.module.name" value="util"/>
		</antcall>
		
		<antcall target="verify-boot-lib">
			<param name="boot.lib"        value="test/testing-client.jar"/>
			<param name="vbl.module.name" value="bridge"/>
		</antcall>

		<echo message="all boot libraries verified"/>		
	</target>

	<target name="update-tree" depends="init"
     description="update tree">
      <fail unless="CVSROOT" 
           message="required: {ant} -DCVSROOT=... ..."/>
      <cvs cvsRoot="${CVSROOT}"
              dest="${aspectj.modules.dir}"
             quiet="on" 
       failonerror="on" 
           command="update -dP" />
    </target>

    <!-- ===================================================================== -->
    <!-- test targets                                                          -->
    <!-- ===================================================================== -->	
	
	<target name="quicklook" >
	   <antcall target="clean"/>
	   <!-- todo: compile modules without test sources -->
	   <!-- todo: junit tests (compile with test sources) -->
	   <antcall target="aspectj"/>
	   <antcall target="ajcTests"/>
	   <!-- todo: product install and tests -->
	</target>
	
    <!-- ===================================================================== -->
    <!-- antcall targets                                                       -->
    <!-- ===================================================================== -->	
	
	<target name="build-product" depends="init,init-taskdefs,init-version"
	 description="build $${product.name}">
      <ajbuild jarDir="${aj.jar.dir}"
              baseDir="${aspectj.modules.dir}"
              distDir="${aj.dist.dir}"
           productDir="${aspectj.modules.dir}/build/products/${product.name}"
          trimTesting="${trim.testing.default}"
          buildConfig="${build.config}" 
              version="${build.version.long}"
              verbose="true"
          failonerror="true"/>		
	</target>

	<target name="build-module" depends="init,init-taskdefs,init-version">
      <ajbuild jarDir="${aj.jar.dir}"
              baseDir="${aspectj.modules.dir}"
              distDir="${aj.dist.dir}"
               module="${module.name}"              
          trimTesting="${trim.testing.default}"
          buildConfig="${build.config}" 
              version="${build.version.long}"
              verbose="true"
          failonerror="true"/>		
	</target>


	<target name="build-module-all" depends="init,init-taskdefs,init-version">
      <ajbuild module="${module.name}"
              baseDir="${aspectj.modules.dir}"
              distDir="${aj.dist.dir}"
               jarDir="${aj.jar.dir}"
          trimTesting="${trim.testing.default}"
          buildConfig="${build.config}" 
              version="${build.version.long}"
              verbose="true"
          assembleall="true"
          failonerror="true"/>		
	</target>


	<target name="create-installer" depends="init,init-taskdefs,init-filters"
	 description="create ${installer.file} from ${staging.dir} using ${htmlSrc.dir} and ${simpleClassName}">
        <!-- init-filters: filter on copy used by ajinstaller taskdef -->
        
        <delete quiet="on" file="${installer.file}"/>
        <ajinstaller zipfile="${installer.file}"
           installerclassjar="${aspectj.build.jar}"
                     basedir="${staging.dir}"
                   mainclass="$$installer$$.org.aspectj.${simpleClassName}"
                     htmlSrc="${htmlSrc.dir}"
                resourcesSrc="${aspectj.modules.build.dir}/installer-resources"/>
	</target>

	<target name="verify-boot-lib" depends="init"
	 description="fail if ${boot.lib} is out of date wrt ${vbl.module.name}">
      <uptodate property="lib-warning-${vbl.module.name}"
              targetfile="${aspectj.modules.dir}/lib/${boot.lib}">
      	<srcfiles dir="${aspectj.modules.dir}/${vbl.module.name}/src"
              includes="**/*.java"/>
      </uptodate>
      
      <fail unless="lib-warning-${vbl.module.name}"
        message="${boot.lib} out of date wrt module ${vbl.module.name}"/>

    </target>

    <!-- ===================================================================== -->
    <!-- custom targets                                                        -->
    <!-- ===================================================================== -->
	<target name="build-testing-drivers" depends="init-taskdefs,init"
	      unless="testing.drivers.all.available"> 
		<antcall target="any-module-all">
			<param name="module.name" value="testing-drivers"/>
		</antcall>
	</target>

	<target name="build-testing-jars" 
		depends="aspectjrt,build,ajbrowser-all"
		description="build testing jars.
		Use -Dtrim.testing.default=false to build junit tests">
		<antcall target="any-module">
			<param name="module.name" value="testing"/>
		</antcall>
		<antcall target="any-module">
			<param name="module.name" value="testing-drivers"/>
		</antcall>
		<antcall target="build-testing-drivers"/>
	</target>
	
	<target name="build-testing-client" depends="init-taskdefs,init">
	  <antcall target="build-module-all">
	    <param name="module.name" value="testing-client"/>
	  </antcall>
	  <echo>
To use testing client jar in tests, 
  mv ../aj-build/jars/testing-client-all.jar ../lib/tests/testing-client.jar
</echo>
	</target>
	
	<!-- remove as unused - see release/build.xml test-sources -->
	<target name="ajcTests" depends="init,build-testing-drivers">
      <java fork="true" jar="${aj.jar.dir}/testing-drivers-all.jar"
            dir="${aspectj.modules.tests.dir}"
          output="${aj.results.dir}/ajcTests.out.txt">
        <arg value="-traceTestsMin"/>
        <arg value="-logFail"/>
        <arg value="-hideStreams"/>
        <arg value="-loud"/>
        <arg value="-ajctestSkipKeywords=purejava,knownLimitations"/>
        <arg value="ajcTests.xml"/>
      </java>
      <echo message="find result in ${aj.results.dir}/ajcTests.out.txt"/>
	</target>
	
	<target name="aspectj" depends="init,aspectjtools-dist,docs-dist" 
	  description="create installer from local distributions">
	  <property name="installer.staging.dir"
            location="${aj.temp.dir}/installer-staging"/>
	  <mkdir dir="${installer.staging.dir}"/>
	  <delete dir="${installer.staging.dir}"/>
	  <mkdir dir="${installer.staging.dir}"/>
	  <copy todir="${installer.staging.dir}">
	    <fileset dir="${aj.dist.dir}/tools"/>
	    <fileset dir="${aj.dist.dir}/docs"/>
	  </copy>
	  
	  <antcall target="create-installer">
	    <param name="installer.file" 
	       location="${aj.installer.jar}"/>
	    <param name="staging.dir" 
	       location="${installer.staging.dir}"/>
	    <param name="htmlSrc.dir" 
	       location="${aspectj.modules.build.dir}/products/aspectj/install"/>
	    <param name="simpleClassName" value="ToolsInstaller"/>
	  </antcall>
	  <delete dir="${installer.staging.dir}"/> 
	</target>
	
	<target name="docs-dist" depends="init">
	   <ant dir="${aspectj.modules.dir}/docs"
	    antfile="build.xml"
	    target="local-dist"
	    inheritAll="false"/> <!-- true? -->
	</target>
	
	<target name="aspectjrt" depends="init"
	 description="build aspectjrt.jar (differently than release)">
	  <antcall target="build-module-all">
	    <param name="module.name" value="runtime"/>
	  </antcall>
	  <copy file="${aj.jar.dir}/runtime.jar"
	      tofile="${aj.jar.dir}/aspectjrt.jar"/>
	</target>
	
    <!-- ===================================================================== -->
    <!-- boilerplate antcalls                                                  -->
    <!-- ===================================================================== -->

	<!-- for any-[module|product], define [module|product].name -->
	<target name="any-module" depends="init">
	  <fail unless="module.name" message="use -Dmodule.name=... to define"/>
	  <antcall target="build-module">
	    <param name="module.name" value="${module.name}"/>
	  </antcall>
	</target>

	<target name="any-module-all" depends="init">
	  <fail unless="module.name" message="use -Dmodule.name=... to define"/>
	  <antcall target="build-module-all">
	    <param name="module.name" value="${module.name}"/>
	  </antcall>
	</target>

	<target name="any-product" depends="init">
	  <fail unless="product.name" message="use -Dproduct.name=... to define"/>
	  <antcall target="build-product">
	    <param name="product.name" value="${product.name}"/>
	  </antcall>
	</target>

	<!-- literal targets -->
	<target name="eajc" depends="init">
	  <antcall target="build-module-all">
	    <param name="module.name" value="org.aspectj.ajdt.core"/>
	  </antcall>
	  <echo message="use org.aspectj.ajdt.core-all.jar for eajc.jar"/>
	</target>

	<target name="ajbrowser-all" >
	  <antcall target="build-module-all">
	    <param name="module.name" value="ajbrowser"/>
	  </antcall>
    </target>

	<target name="ajdoc-all">
	  <antcall target="build-module-all">
	    <param name="module.name" value="ajdoc"/>
	  </antcall>
    </target>

	<target name="build">
	  <antcall target="build-module">
	    <param name="module.name" value="build"/>
	  </antcall>
    </target>

	<target name="aspectjtools-dist" depends="init"
	 description="build local distribution">
	  <antcall target="build-product">
	    <param name="product.name" value="tools"/>
	  </antcall>
	  <!-- TODO : remove call -->
	  <antcall target="filter-tools-jar" />
    </target>
    
    <target name="filter-tools-jar">
    	<!--
    		TODO : get rid of this!
    		Temp hack ahoy. Open up the aspectjtools.jar to a temp
    		location and then do a re-jar of it including only the 
    		stuff we want to be in there.
    	-->
    	<mkdir dir="${aj.dist.dir}/tools_tmp"/>
    	<unjar dest="${aj.dist.dir}/tools_tmp"
    		   src="${aj.dist.dir}/tools/lib/aspectjtools.jar"/>
    	<!-- Ant 1.5.1 doesn't overwrite the jar, even with update set to false -->
    	<delete file="${aj.dist.dir}/tools/lib/aspectjtools.jar" />
		<jar manifest="${aj.dist.dir}/tools_tmp/META-INF/MANIFEST.MF" 
			destfile="${aj.dist.dir}/tools/lib/aspectjtools.jar">
    		<fileset dir="${aj.dist.dir}/tools_tmp">
    			<include name="javax/**"/>
    			<include name="org/**"/>
    			<include name="copyright.txt"/>
    			<include name="META-INF/**"/>
    		</fileset>
  		</jar>    		   
    	<delete dir="${aj.dist.dir}/tools_tmp" />
    </target>

    <!-- ===================================================================== -->
    <!-- eclipse plugins                                                       -->
    <!-- ===================================================================== -->

	<target name="eclipse.plugins" depends="org.aspectj.ajde.source,
	                                        org.aspectj.ajde.doc,
	                                        org.aspectj.ajde,
	                                        org.aspectj.aspectjrt"
     	    description="create the Eclipse distribution plugins"/>	  

	<target name="org.aspectj.ajde.source" depends="init"
	  description="build the AspectJ source distribution plugin">
	  <copy todir="${aj.plugin.org.aspectj.ajde.source.dir}">
	    <fileset dir="${aspectj.modules.dir}/eclipse.plugin/org.aspectj.ajde.source"/>
	  </copy>	  
	  <replace file="${aj.plugin.org.aspectj.ajde.source.dir}/plugin.xml"
	           token="build.version.eclipse.plugins"
	           value="${build.version.eclipse.plugins}"/>
	  <copy file="${aspectj.modules.dir}/org.eclipse.jdt.core/jdtcore-for-aspectj-src.zip"
	        todir="${aj.plugin.org.aspectj.ajde.source.dir}/src"/> 
	  <zip destfile="${aj.plugin.org.aspectj.ajde.source.dir}/src/aspectjsrc.zip">
	    <fileset dir="${aspectj.modules.dir}/ajbrowser/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/ajdoc/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/ajde/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/asm/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/bridge/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/org.aspectj.ajdt.core/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/runtime/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/taskdefs/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/util/src" includes="**"/>
	    <fileset dir="${aspectj.modules.dir}/weaver/src" includes="**"/>
	  </zip>
	  <jar destfile="${aj.plugin.org.aspectj.ajde.source.dir}/../org.aspectj.ajde.source_${build.version.eclipse.plugins}.jar">
	    <fileset dir="${aj.plugin.org.aspectj.ajde.source.dir}" includes="**"/>	    
	  </jar>
	</target>

	<target name="org.aspectj.ajde.doc" depends="init,docs-dist"
	  description="build the AspectJ documentation plugin for Eclipse">
	  <copy todir="${aj.plugin.org.aspectj.ajde.doc.dir}">
	    <fileset dir="${aspectj.modules.dir}/eclipse.plugin/org.aspectj.ajde.doc"/>
	  </copy>
	  <copy todir="${aj.plugin.org.aspectj.ajde.doc.dir}/doc">
	    <fileset dir="${aj.dist.dir}/docs/doc" includes="**"/>	    	  
	  </copy>
	  <replace file="${aj.plugin.org.aspectj.ajde.doc.dir}/plugin.xml"
	           token="build.version.eclipse.plugins"
	           value="${build.version.eclipse.plugins}"/>
	  <jar destfile="${aj.plugin.org.aspectj.ajde.doc.dir}/../org.aspectj.ajde.doc_${build.version.eclipse.plugins}.jar">
	    <fileset dir="${aj.plugin.org.aspectj.ajde.doc.dir}" includes="**"/>	    
	  </jar>
	</target>

	<target name="org.aspectj.ajde" depends="init,aspectj"
	  description="build the AspectJ library plugin for Eclipse">
	  <copy todir="${aj.plugin.org.aspectj.ajde.dir}">
	    <fileset dir="${aspectj.modules.dir}/eclipse.plugin/org.aspectj.ajde"/>
	  </copy>	  
	  <replace file="${aj.plugin.org.aspectj.ajde.dir}/plugin.xml"
	           token="build.version.eclipse.plugins"
	           value="${build.version.eclipse.plugins}"/>
	  <copy file="${aj.dist.dir}/tools/lib/aspectjrt.jar"
	        todir="${aj.plugin.org.aspectj.ajde.dir}"/> 
	  <copy file="${aj.dist.dir}/tools/lib/aspectjtools.jar"
	        todir="${aj.plugin.org.aspectj.ajde.dir}"/>
	  <jar destfile="${aj.plugin.org.aspectj.ajde.dir}/ajde.jar">
	  	<zipfileset src="${aj.dist.dir}/tools/lib/aspectjtools.jar"
	  	   includes="org/aspectj/**"/>
	  </jar> 	  
	  <jar destfile="${aj.plugin.org.aspectj.ajde.dir}/../org.aspectj.ajde_${build.version.eclipse.plugins}.jar">
	    <fileset dir="${aj.plugin.org.aspectj.ajde.dir}" includes="**"/>	    
	  </jar>
	</target>

	<target name="org.aspectj.aspectjrt" depends="init,aspectj"
	  description="build the AspectJ runtime library plugin for Eclipse">
	  <copy todir="${aj.plugin.org.aspectj.aspectjrt.dir}">
	    <fileset dir="${aspectj.modules.dir}/eclipse.plugin/org.aspectj.aspectjrt"/>
	  </copy>	  
	  <replace file="${aj.plugin.org.aspectj.aspectjrt.dir}/plugin.xml"
	           token="build.version.eclipse.plugins"
	           value="${build.version.eclipse.plugins}"/>
	  <copy file="${aj.dist.dir}/tools/lib/aspectjrt.jar"
	        todir="${aj.plugin.org.aspectj.aspectjrt.dir}"/> 
	  <jar destfile="${aj.plugin.org.aspectj.aspectjrt.dir}/../org.aspectj.aspectjrt_${build.version.eclipse.plugins}.jar">
	    <fileset dir="${aj.plugin.org.aspectj.aspectjrt.dir}" includes="**"/>	    
	  </jar>
	</target>

</project>