<!-- ==================================================================== -->
<!-- R E A C T O R                                                        -->
<!-- ==================================================================== -->
<!-- This is a template for a reactor that will hopefully allow users     -->
<!-- to easily set up their own reactors. The best the reactor can do     -->
<!-- now is take a set of projects and process them according to their    -->
<!-- sorted dependencies.                                                 -->
<!--                                                                      -->
<!-- This particular reactor will take a set of projects and:             -->
<!--                                                                 	    -->
<!-- a) sort the order of processing based on dependencies                -->
<!-- b) clean                                                             -->
<!-- c) compile                                                           -->
<!-- d) run unit tests                                                    -->
<!-- e) build the project jar                                             -->
<!-- f) install the project jar in the local repository jar so the        -->
<!--    subsequent builds may use it.                                     -->
<!--                                                                      -->
<!-- In addition to the build, documentation for each of the projects     -->
<!-- will be produced and a front-end site will be produced using general -->
<!-- information about the parent project and information gleaned from    -->
<!-- each of the individual projects. The attempt is to try and           -->
<!-- alleviate the manual aggregation of specific project information     -->
<!-- that needs to be present on the front-end site. So you might want    -->
<!-- to glean the navigation or a short synopsis of each project          -->
<!-- automatically.                                                       -->
<!--                                                                      -->
<!-- The hope is to provide a model and a set of best practices for       -->
<!-- collaborative development. How to set up a multi-component project   -->
<!-- like the commons; how to perform meaningful CI on multi-component    -->
<!-- projects; how to produce meaningful documentation with minimal       -->
<!-- developer input; how to set up tests; how to manage dependencies;    -->
<!-- and who knows what else.                                             -->
<!--                                                                      -->
<!-- There are a few things coming in the near future that should make    -->
<!-- the reactor truly useful. We have made some Quartz Jelly tags so     -->
<!-- that we can schedule reactors using familiar cron-like semantics. We -->
<!-- also have Werkflow Jelly tags so that we can capture the various     -->
<!-- states of the reactor and perform arbitrary actions based any        -->
<!-- number and combination of conditions.                                -->
<!-- ==================================================================== -->
<!--
<project default="build"
-->
<project xmlns:reactor="reactor" xmlns:j="jelly:core" xmlns:u="jelly:util" xmlns:ant="jelly:ant" xmlns:maven="jelly:maven" xmlns:m="maven" xmlns:deploy="deploy" xmlns:texen="texen" xmlns:velocity="jelly:org.apache.commons.jelly.tags.velocity.VelocityTagLibrary" default="info">
	<!-- ================================================================== -->
	<!-- B U I L D                                                          -->
	<!-- ================================================================== -->
	<goal name="info">
		<!-- this is tell people which targets to use, if we could detect 
         the directory they are starting it in then we could automate this -->
		<echo>	
	Information on building GT2	
	Make sure you use 'maven build' in the top directory at least once in order to build all modules before working on individual ones.
		
      If building a single module use one of:
        maven jar:install
        maven test
        maven java:compile
        
      If bulding a war file (e.g. wmsserver module)
        maven war  
        
      If building everyting use:
        maven build       -- this will try to build all modules regardless
        maven build-fail  -- this will stop at the first failure
        maven allsite     -- this will build the site for all modules
        
      For more options use
        maven -g
    </echo>
	</goal>
        <preGoal name="checkstyle:init">
            <echo>preGoal in maven.xml is fudging checkstyle to use geotools config settings</echo>
            <j:set var="maven.checkstyle.properties" value="../../geotools_checks.xml"/>
        </preGoal>
        <goal name="mergeTestReports">
            <echo>merging test reports into higher directory</echo>
           <ant:copy todir="../../target/test-reports">
               <ant:fileset dir="target/test-reports">
               <ant:include name="*.xml"/>
      </ant:fileset>
    </ant:copy>
        </goal>        
	<goal name="build:log">
		<echo file="../../buildReport.txt" append="true">
    ${pom.id}</echo>
		<!-- < imageurl="file://${basedir}/xdocs/images/${pom.artifactId}.gif"/> -->
	</goal>
	<postGoal name="clean">
		<echo file="../../buildReport.txt" append="true">  cleaned</echo>
	</postGoal>
	<postGoal name="java:compile">
		<echo file="../../buildReport.txt" append="true">, compiled</echo>
	</postGoal>
	<postGoal name="test:test">
		<echo file="../../buildReport.txt" append="true">, tested</echo>
	</postGoal>
	<postGoal name="jar:install">
		<tstamp/>
		<echo file="../../buildReport.txt" append="true">, INSTALLED ${TSTAMP}</echo>
	</postGoal>
	<goal name="build">
		<tstamp/>
                <available classname="com.sun.media.imageio.stream.RawImageInputStream" property="imageio.present"/>
               
                       <ant:available classname="com.sun.media.imageio.stream.RawImageInputStream" property="imageio.present"/>
            
              
                        <fail unless="imageio.present" 
                        message="JAI ImageIO extention not found.  Please download and install it from:  http://java.sun.com/products/java-media/jai/downloads/download-iio.html"/>               
                <available file="geotools-src" property="geotools-src.present"/>
                <fail unless="geotools-src.present" message="'maven build' can not be used in this directory, for individual modules use 'maven java:compile', 'maven test' or 'maven jar:install' goals"/>        
		<j:set var="gt2home" value="${basedir}"/>
		<echo>
      looking for modules in: ${basedir}/geotools-src
      reporting progress to ${gt2home}
    </echo>
     <ant:delete dir="target/test-reports"/>
		<echo file="${basedir}/buildReport.txt" append="false">GeoTools2 module build report ${DSTAMP}</echo>
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" goals="build:log,clean,jar:install,mergeTestReports" banner="Building" postProcessing="true" ignoreFailures="true"/>
		<loadfile property="build.report" srcFile="${basedir}/buildReport.txt" failonerror="false"/>
		<echo>BUILD REPORT (from buildReport.txt):
      Sucessfull modules should read 'cleaned, compiled, tested, INSTALLED HHMM'
      ${build.report}
      If some modules failed to INSTALL, look for problems from the TOP DOWN as failures lower in the list will probaly be caused by ones higher up.
      If modules cleanded and compiled but were not tested look in geotools-src/modulename/target/test-reports for details.
      The next line of output will say 'Build Sucessful'  even if some/all modules failed, please check the above report.
      </echo>
	</goal>
	<goal name="build-fail">
		<echo>
      looking for modules in: ${basedir}/geotools-src

    </echo>
       <ant:delete dir="target/test-reports"/>  <!-- one report folder for convenience of CC -->
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" goals="clean,jar:install,mergeTestReports" banner="Building" postProcessing="true" ignoreFailures="false"/>
		<j:set var="ok" value="${reactorProjects}"/>
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" postProcessing="true" ignoreFailures="true"/>
		<j:forEach var="module" items="${reactorProjects}">
			<j:set var="status" value="failed"/>
			<j:forEach var="item" items="${ok}">
				<j:if test="${item == module}">
					<j:set var="status" value="installed"/>
				</j:if>
			</j:forEach>
			<echo>Module ${module} : ${status}</echo>
		</j:forEach>
	</goal>
	<goal name="snapshot">
		<echo>
      looking for modules in: ${basedir}/geotools-src
      
    </echo>
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" goals="clean,jar:deploy-snapshot" banner="Deploying" ignoreFailures="true"/>
		<echo>
      modules built and deployed:  ${reactorProjects}
    </echo>
	</goal>
	<!-- ================================================================== -->
	<!-- W E B S I T E                                                      -->
	<!-- ================================================================== -->
	<preGoal name="site:generate">
		<attainGoal name="pmd"/>
	</preGoal>
	<goal name="allsite">
		<!--
      ||
      || Generate the documentation for each of the commons projects.
      ||
    -->
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" goals="site:generate" banner="Generating site for" ignoreFailures="true"/>
		<j:set var="ok" value="${reactorProjects}"/>
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" postProcessing="true" ignoreFailures="true"/>
		<j:forEach var="module" items="${reactorProjects}">
			<j:set var="status" value="failed"/>
			<j:forEach var="item" items="${ok}">
				<j:if test="${item == module}">
					<j:set var="status" value="installed"/>
				</j:if>
			</j:forEach>
			<echo>Module ${module} : ${status}</echo>
		</j:forEach>
		<j:file name="${basedir}/xdocs/buildreport.xml" prettyPrint="true">
			<document>
				<properties>
					<title>Javadoc Report</title>
				</properties>
				<body>
					<section name="Javadoc Report">
						<p/>
						<source>
                        The following is a list of all modules and their current status.
If you are the maintainer of a module which has failed and which is not dependent on a module
higher in the list which has also failed please try to resolve the issue.  <p/>
							<j:forEach var="module" items="${reactorProjects}">
								<j:set var="status" value="failed"/>
								<j:forEach var="item" items="${ok}">
									<j:if test="${item == module}">
										<j:set var="status" value="installed"/>
									</j:if>
								</j:forEach>
Module ${module} : ${status}
<p/>
							</j:forEach>
						</source>
					</section>
				</body>
			</document>
		</j:file>
	</goal>
	<goal name="deploy-allsite">
		<!--
      ||
      || Deploy the documentation for each of the commons projects.
      ||
    -->
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" goals="clean,site:deploy" banner="Deploying site for" ignoreFailures="true"/>
	</goal>
	<!-- ================================================================== -->
	<!-- F R O N T  E N D  W E B S I T E                                    -->
	<!-- ================================================================== -->
	<goal name="site-front-end">
		<echo>before reactor
</echo>
		<maven:reactor basedir="${basedir}/geotools-src" includes="*/project.xml" ignoreFailures="false" postProcessing="true"/>
		<echo>after reactor
</echo>
		<!--
      ||
      || Generate the documentation for the front-end site. First we will
      || generate the navigation based on the projects that we just
      || processed, then we will generate the front-end site itself.
      ||
    -->
		<echo>
      reactor list = ${reactorProjects}
    </echo>
		<velocity:merge name="xdocs/navigation.xml" basedir="${basedir}" template="navigation.vm"/>
		<attainGoal name="xdoc"/>
	</goal>
	<!-- ================================================================== -->
	<!-- F R O N T  E N D  W E B S I T E                                    -->
	<!-- ================================================================== -->
	<goal name="deploy-site-front-end">
		<m:user-check user="${maven.username}"/>
		<attainGoal name="site-front-end"/>
		<!-- This needs to taken from the project properties -->
		<property name="maven.homepage" value="/seis/raid1/Apache/htdocs/software/geotools/"/>
		<property name="maven.docs.dest" value="target/docs/"/>
		<echo>
      siteAddress = ${pom.siteAddress}
      siteDirectory = ${maven.homepage}
      maven.docs.dest = ${maven.docs.dest}
    </echo>
		<tar tarfile="${maven.final.name}-site.tar" basedir="${maven.docs.dest}"/>
		<gzip zipfile="${maven.final.name}-site.tar.gz" src="${maven.final.name}-site.tar"/>
		<delete file="${maven.final.name}-site.tar"/>
		<!-- Make sure the destination directory exists before trying to copy -->
		<exec dir="." executable="${maven.ssh.executable}">
			<arg line="${pom.siteAddress} -l ${maven.username} 'mkdir -p ${maven.homepage}'"/>
		</exec>
		<exec dir="." executable="${maven.scp.executable}">
			<arg value="${maven.final.name}-site.tar.gz"/>
			<arg value="${maven.username}@${pom.siteAddress}:${maven.homepage}"/>
		</exec>
		<exec dir="." executable="${maven.ssh.executable}">
			<arg line="${pom.siteAddress} -l ${maven.username} 'cd ${maven.homepage};gunzip ${maven.final.name}-site.tar.gz;tar xUvf ${maven.final.name}-site.tar;chmod -R g+u *;rm ${maven.final.name}-site.tar'"/>
		</exec>
		<delete file="${maven.final.name}-site.tar.gz"/>
	</goal>
	<goal name="deploy-srcdist">
		<m:user-check user="${maven.username}"/>
		<!-- This needs to taken from the project properties -->
		<property name="maven.homepage" value="/seis/raid1/Apache/htdocs/software/geotools/"/>
		<property name="maven.dist.dir" value="target"/>
		<echo>
      siteAddress = ${pom.siteAddress}
      siteDirectory = ${maven.homepage}
      maven.dist.dir = ${maven.dist.dir}
    </echo>
		<!-- Create a tar.gz file -->
		<ant:tar longfile="gnu" tarfile="${maven.dist.dir}/${maven.final.name}-src.tar" basedir=".." excludes="**/target/**, **/CVS" includes="geotools2/**">
    </ant:tar>
		<ant:gzip zipfile="${maven.dist.dir}/${maven.final.name}-src.tar.gz" src="${maven.dist.dir}/${maven.final.name}-src.tar"/>
		<ant:delete file="${maven.dist.dir}/${maven.final.name}-src.tar"/>
		<!-- Make sure the destination directory exists before trying to copy -->
		<exec dir="." executable="${maven.ssh.executable}">
			<arg line="${pom.siteAddress} -l ${maven.username} 'mkdir -p ${maven.homepage}'"/>
		</exec>
		<exec dir="." executable="${maven.scp.executable}">
			<arg value="${maven.dist.dir}/${maven.final.name}-src.tar.gz"/>
			<arg value="${maven.username}@${pom.siteAddress}:${maven.homepage}"/>
		</exec>
		<delete file="${maven.final.name}-src.tar.gz"/>
	</goal>

       <postGoal name="test:test">
            <echo>merging test reports into higher directory</echo>
           <ant:copy todir="../../target/test-reports">
               <ant:fileset dir="target/test-reports">
               <ant:include name="*.xml"/>
      </ant:fileset>
    </ant:copy>
        </postGoal>   

        <!-- ================================================================== -->
	<!-- Creates a geotools.jar of the core modules.                        -->
	<!-- Needs more work, this is just an initial stab to get it working.   -->
	<!-- ================================================================== -->
    <goal name="coreJar">
            <echo>Making core geotools.jar</echo>
            <echo>build must be run first or this will create an empty jar.</echo>
            <echo>We didn't want it automatically running every time you </echo>
             <echo>need a new jar.  TODO: figure a better way to do this. </echo>
              <ant:jar destfile="${basedir}/target/geotools.jar">
            <ant:fileset dir="${basedir}/geotools-src/core/target/classes"/>

             <ant:fileset dir="${basedir}/geotools-src/data/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/defaultcore/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/filter/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/cts-coordtrans/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/gcs-coverage/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/lite-rendering/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/resources/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/sldstyling/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/svgsupport/target/classes"/>
             <ant:fileset dir="${basedir}/geotools-src/opengis/target/classes"/>             
            </ant:jar>          
        </goal>
        
        <goal name="createRelease">
            <fail unless="release.version" message="release.version not set"/>
            <j:set var="release.report" value="releaseReport-${release.version}.txt"/>
            <echo message="release report is set to ${release.report}"/>
            <echo file="${release.report}" message="release is ${release.version}"/>
            <loadfile property="release.required" srcFile="requiredList.txt"/>
            <u:tokenize var="list" delim=",">${release.required}</u:tokenize>
            <j:set var="todo" value=""/>
            <j:set var="required" value=""/>	
            <j:forEach items="${list}" var="item">
                <j:set var="todo" value="${item}/project.xml,${todo}"/>
                <j:set var="required" value="${item}
${required}"/>
            </j:forEach>
            <echo message="reactor list = ${todo}"/>
             <ant:delete dir="${basedir}/target/forMerge"/>
            <maven:reactor basedir="${basedir}/geotools-src" includes="${todo}" goals="moveLib, moveForMerge, moveSrc" banner="binary release" ignoreFailures="true" postProcessing="true"/>
            <ant:mkdir dir="${basedir}/target/binRelease/jars"/>
            <ant:jar destfile="${basedir}/target/binRelease/jars/gt2-main.jar">
                <ant:fileset dir="${basedir}/target/forMerge"/>
            </ant:jar>
            <ant:property name="requiredList" value="${required}"/>
            <echo message="requiredList = ${requiredList}"/>
            <ant:property name="maven.dist.dir" value="${maven.build.dir}/distributions"/>
            <ant:mkdir dir="${maven.dist.dir}"/>
            
            <echo message="dist directory is ${maven.dist.dir}"/>
            <ant:zip longfile="gnu" basedir="${basedir}/target/binRelease" destfile="${maven.dist.dir}/geotools-bin-${release.version}.zip"/>
            <ant:zip longfile="gnu" basedir="${basedir}/target/srcRelease" destfile="${maven.dist.dir}/geotools-src-${release.version}.zip"/>
            
            <!-- add optional modules seperatly -->
            <loadfile property="release.optional" srcFile="optionalList.txt"/>
            <u:tokenize var="list2" delim=",">${release.optional}</u:tokenize>
            <j:set var="todo" value=""/>	
            <j:forEach items="${list2}" var="item">
                <j:set var="todo" value="${item}/project.xml,${todo}"/>
            </j:forEach>
            <echo message="reactor list = ${todo}"/>
            <attainGoal name="moveBuildFiles"/>
            <maven:reactor basedir="${basedir}/geotools-src" includes="${todo}" goals="moveLib, moveBin, moveSrc" banner="binary release" ignoreFailures="true" postProcessing="true"/>
            
            
            
        </goal>
        
        <goal name="moveForMerge">
            
                <echo message="working on ${pom.id} for merge"/>
                
                <ant:copy todir="../../target/forMerge">
                   <ant:fileset dir="./target/classes">
                     <ant:include name="**/*"/>
                   </ant:fileset>
                </ant:copy> 
          </goal>
        
        <goal name="moveLib">
            <j:set var="release.report" value="releaseReport-${release.version}.txt"/>
            <echo file="../../${release.report}" append="true">
            ${pom.id}</echo>
                <echo message="working on ${pom.id} to find 3rd party jars to include"/>
                <j:forEach var="lib" items="${pom.artifacts}">
                      <j:set var="dep" value="${lib.dependency}"/>
                    <!--  <j:if test="${dep.getProperty('release.bundle')=='true'}"> -->     
                        <j:if test="${dep.groupId !='gt2'}"> 
                         <j:if test="${dep.type =='jar'}"> 
                              <ant:copy todir="../../target/binRelease/lib" file="${lib.path}"/>
                         </j:if>
                        </j:if>  
                  <!--  </j:if>  -->   
                </j:forEach>
                 <echo file="../../${release.report}" append="true">  OK</echo>   
        </goal>
        
        <goal name="moveBin">
            <j:set var="release.report" value="releaseReport-${release.version}.txt"/>
            <echo file="../../${release.report}" append="true">
            add ${pom.id} jar - </echo>
                <echo message="working on ${pom.id} for binary release"/>
                <attainGoal name="jar:jar"/> 
                <ant:copy tofile="../../target/binRelease/jars/gt2-${pom.artifactId}.jar">
                   <ant:fileset dir="./target">
                     <ant:include name="${pom.artifactId}-${pom.currentVersion}.jar"/>
                   </ant:fileset>
                </ant:copy>
                 <echo file="../../${release.report}" append="true">  OK</echo>   
        </goal>
        
        <goal name="moveBuildFiles">
      
            <ant:tstamp/>
            <ant:copy todir="${basedir}/target/srcRelease">
               <ant:fileset dir=".">
                 <ant:include name="project.xml"/>
                 <ant:include name="build.properties"/>
                 <ant:include name="run-maven.xml"/>
                 <ant:include name="maven.xml"/>
                 <ant:include name="README.txt"/>
               </ant:fileset>
               <ant:filterset>
                 <ant:filter token="DATE" value="${TODAY}"/>
                 <ant:filter token="VERSION" value="${release.version}"/>
                 <ant:filter token="REQUIRED" value="${requiredList}"/>
               </ant:filterset>  
            </ant:copy>          
        </goal>
        
        <goal name="moveSrc">
           <!-- <j:set var="stable" value="${maven.module.stable}"/>
            <j:if test="${stable == true}">
             <echo message="${pom.id} is stable"/> -->
             <ant:copy todir="../../target/srcRelease/geotools-src/${pom.artifactId}/">
               <ant:fileset dir=".">
                 <ant:include name="src/**"/>
                 <ant:include name="project.xml"/>
                 <ant:include name="build.properties"/>
                 <ant:include name="run-maven.xml"/>
               </ant:fileset>
             </ant:copy>
            <!-- </j:if> -->
    </goal>

</project>
 
