<!-- ========================= -->
<!-- GeoTools 2.0 build script -->
<!-- ========================= -->
<project xmlns:j="jelly:core" xmlns:u="jelly:util" xmlns:ant="jelly:ant" xmlns:maven="jelly:maven" xmlns:deploy="deploy" default="info">
<!-- ==================================================================
     I N F O
     this is tell people which targets to use, if we could detect
     the directory they are starting it in then we could automate this
     ================================================================== -->
	<goal name="info">
		<echo>  
      Information on Building Geotools 2.1
      -----------------------   
      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 everything use:
        maven build         -- this will try to build all modules regardless
        maven xjavadoc      -- generate a javadoc set from all modules
        maven createRelease -- uses argument: -Drelease.version=2.1
                
      If building a single module use one of:
        maven java:compile -- compile java files in src/
        maven test          -- run unit on test/ results in target/test-resutls
        maven jar:install   -- Install generated jar in repository for other modules


      For more options use:
        maven -g            -- a lot more options
    </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="${basedir}/../../geotools_checks.xml"/>
	</preGoal>

	
	<postGoal name="clean">
		<echo file="../../buildReport.txt" append="true">
    ${pom.id}  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>

	<!-- ==================================================================
     B U I L D
     Uses maven:multiproject to clean and install modules.
     ================================================================== -->
	<goal name="build">
		<tstamp/>
		
		<available file="module" property="module.present"/>
		<fail unless="module.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 that match 
      ${maven.multiproject.includes}
      but not 
      ${maven.multiproject.excludes} 
    </echo>
		<ant:delete dir="target/test-reports"/>
         
		<echo file="${basedir}/buildReport.txt" append="false">GeoTools2 module build report ${DSTAMP}</echo>
                <j:set var="ignoreFailures" value="true"/>
                <j:set var="goal" value="clean,jar:install"/>
                <attainGoal name="multiproject:goal"/>
		<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 the
  /target/test-reports direcotry of your module for details.
  For more information see http://geotools.codehaus.org/2+Build
  
  Maven always says 'Build Sucessful', please check the above report.
      </echo>
	</goal>

	<!-- goal to do a multiproject clean -->
	<goal name="cleanAll">
  	<j:set var="ignoreFailures" value="true"/>
    <j:set var="goal" value="clean"/>
    <attainGoal name="multiproject:goal"/>
	</goal>

	<!-- override of test goal which is allows use of online/offline tests -->
  <goal name="test:test">
		<j:choose>
			<!-- dont run tests if maven.test.skip is set -->
			<j:when test="${maven.test.skip}">
				<j:set var="testmatchpattern" value=""/>
				<attainGoal name="test:match"/>
			</j:when>
			<j:otherwise>
				<j:set var="testmatchpattern" value="**/*Test.*"/>
				<j:set var="excludes" value=""/>
		 		<j:forEach var="exclude" items="${pom.build.unitTest.excludes}">
					<j:set var="excludes" value="${excludes},${exclude}"/>
				</j:forEach>
		    <!-- determine if we are on/offline -->
		    <j:choose>
		      <j:when test="${maven.mode.online}">
		        <!-- online, run all tests -->
		      </j:when>
		      <j:otherwise>
		        <!-- offline, exclude OnlineTests -->
		          <j:set var="excludes" value="${excludes},**/*OnlineTest.*,**/*StressTest.*"/>
		      </j:otherwise>
		    </j:choose>
				<j:set var="testnotmatchpattern" value="${excludes}"/>
		     <attainGoal name="test:match"/>
			</j:otherwise>
		</j:choose>
  </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>
       
	<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>
        
	<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}"/>

                <ant:delete dir="${basedir}/target/temp/alldeps"/>
                <ant:mkdir dir="${basedir}/target/binRelease/module"/>
                
		
		<ant:property name="maven.dist.dir" value="${maven.build.dir}/distributions"/>
		<ant:mkdir dir="${maven.dist.dir}"/>
		
		<attainGoal name="moveBuildFiles"/>
		<j:set var="ignoreFailures" value="false"/>
                
                <j:set var="goal" value="findSharedDeps"/>
                <attainGoal name="multiproject:goal"/>
                
               <j:set var="goal" value="clean,jar:install,moveBin,moveLib,moveSrc,updateList"/>
              
                <attainGoal name="multiproject:goal"/>
  
                <loadfile property="pluginList" srcFile="${release.version}-plugin-list.txt"/>
                <loadfile property="moduleList" srcFile="${release.version}-module-list.txt"/>
                <loadfile property="demoList" srcFile="${release.version}-demo-list.txt"/>
                <loadfile property="extList" srcFile="${release.version}-ext-list.txt"/>
                
                 <ant:copy todir="${basedir}/target/binRelease">
			<ant:fileset dir=".">
				<ant:include name="LICENSE.txt"/>
				<ant:include name="README.txt"/>
                                <ant:include name="README.html"/>
			</ant:fileset>
			<ant:filterset>
				<ant:filter token="DATE" value="${TODAY}"/>
				<ant:filter token="VERSION" value="${release.version}"/>
				<ant:filter token="REQUIRED" value="${moduleList}"/>
				<ant:filter token="PLUGIN" value="${pluginList}"/>
				<ant:filter token="EXTENTION" value="${extList}"/>
                                <ant:filter token="DEMO" value="${demoList}"/>
			</ant:filterset>
		</ant:copy>
                <ant:copy todir="${basedir}/target/srcRelease">
			<ant:fileset dir=".">
				<ant:include name="${basedir}/target/srcRelease/LICENSE.txt"/>
				<ant:include name="${basedir}/target/srcRelease/README.txt"/>
                                <ant:include name="${basedir}/target/srcRelease/README.html"/>
			</ant:fileset>
		</ant:copy>
                
                <attainGoal name="xjavadoc"/>
                <ant:zip longfile="gnu" destfile="${maven.dist.dir}/geotools-javadoc-${release.version}.zip">
			<zipfileset dir="${basedir}/target/docs" prefix="geotools" filemode="755" includes="**/*"/>
		</ant:zip>
                
                <echo message="dist directory is ${maven.dist.dir}"/>
		<ant:zip longfile="gnu" destfile="${maven.dist.dir}/geotools-bin-${release.version}.zip">
			<zipfileset dir="${basedir}/target/binRelease" prefix="geotools" filemode="755" includes="**/*"/>
		</ant:zip>
		<ant:zip longfile="gnu" destfile="${maven.dist.dir}/geotools-src-${release.version}.zip">
			<zipfileset dir="${basedir}/target/srcRelease" prefix="geotools" filemode="755" includes="**/*"/>
		</ant:zip>
                
                
                
	</goal>
	<goal name="updateList">
             <property file="../release.properties"/>
           
             <echo file="../../${release.version}-${type}-list.txt" append="true"> ${pom.artifactId}</echo>
        </goal>
        <goal name="moveLib">
         <property file="../release.properties"/>
          <echo>Type for this release is : ${type}</echo>
		<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.groupId !='gt2'}">
				<j:if test="${dep.type =='jar'}">
					<echo message="testing ${dep.artifactId}-${dep.version}.${dep.type} to see if shared"/>
					<j:set var="shareddep" value=""/>
					<u:available file="${basedir}/../../target/binRelease/shared/${dep.artifactId}-${dep.version}.${dep.type}">
						<ant:copy todir="../../target/binRelease/shared" file="${lib.path}"/>
                                                <j:set var="shareddep" value="found"/>
					</u:available>
					<j:if test="${shareddep != 'found'}">
						<echo message="copy type = ${type} jar"/>
						<ant:copy todir="../../target/binRelease/${type}/${pom.artifactId}/lib" file="${lib.path}"/>
					</j:if>
				</j:if>
			</j:if>
		</j:forEach>
		<echo file="../../${release.report}" append="true">  OK</echo>
	</goal>
        
         <goal name="findSharedDeps">
		<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.groupId !='gt2'}">
                                
				<j:if test="${dep.type =='jar'}">
                                <echo message="testing ${dep.artifactId}-${dep.version}.${dep.type} to see if shared"/>
					<j:set var="shareddep" value=""/>
					<u:available file="${basedir}/../../target/temp/alldeps/${dep.artifactId}-${dep.version}.${dep.type}">
						<j:set var="shareddep" value="found"/>
                                                <ant:copy todir="../../target/binRelease/shared" file="${lib.path}"/>
					</u:available>
					<ant:copy todir="../../target/temp/alldeps" file="${lib.path}"/>
				</j:if>
			</j:if>
		</j:forEach>
		<echo file="../../${release.report}" append="true">  OK</echo>
	</goal>
        
	<goal name="moveBin">
                 <property file="../release.properties"/>
          <echo>Type for this release is : ${type}</echo>
		<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/${type}/${pom.artifactId}/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>
		<j:set var="release.report" value="releaseReport-${release.version}.txt"/>
		<echo file="../../${release.report}" append="true">
            ${pom.id}</echo>
		
		<echo file="../../target/binRelease/${type}/${pom.artifactId}/readme.txt">
GeoTools Plugin/Extention : ${pom.description}

To use this plugin/extention ensure that gt2-${pom.artifactId}.jar is on your classpath.
If this directory contains a lib folder then the jars it contains must also be included.

Please report bugs and feature requests using ${pom.issueTrackingUrl}.                
</echo>
		<echo file="../../${release.report}" append="true">  Libs Copied</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="geotools_checks.xml"/>
				<ant:include name="run-maven.xml"/>
				<ant:include name="maven.xml"/>
				<ant:include name="README.txt"/>
                                <ant:include name="README.html"/>
                                <ant:include name="LICENSE.txt"/>
                                <ant:include name="**/release.properties"/>
			</ant:fileset>
		</ant:copy>
	</goal>
        
	
        <goal name="moveSrc">
         <property file="../release.properties"/>
        <echo>type is ${type}</echo>
           <ant:copy todir="../../target/srcRelease/${type}/${pom.artifactId}/">
			<ant:fileset dir=".">
				<ant:include name="src/**"/>
				<ant:include name="test/**"/>
				<ant:include name="project.xml"/>
				<ant:include name="maven.xml"/>
				<ant:include name="build.properties"/>
				<ant:include name="run-maven.xml"/>
			</ant:fileset>
		</ant:copy>
         </goal>
	
        
        <!--
  ==============================================================================
  build the consolidated javadoc
  ==============================================================================
  -->

  <goal name="xjavadoc">
    <echo>${basedir}</echo>
    <maven:reactor basedir="."
      includes="*/*/project.xml"
      excludes="**/target/**,**/test/project.xml,project.xml,site/**"
      banner="Site Prep:"
      ignoreFailures="false"
      postProcessing="true" />

    <ant:path id="template.classpath">
      <j:forEach var="child" items="${reactorProjects}">
        <j:set var="deps" value="${child.dependencies}"/>
        <j:forEach var="dep" items="${deps}">
          <ant:pathelement 
            path="${maven.repo.local}/${dep.getArtifactDirectory()}/jars/${dep.getArtifact()}"/>
        </j:forEach>
      </j:forEach>
    </ant:path>

    <ant:mkdir dir="${maven.build.dir}/docs/api" />
    <ant:property name="copyright"
      value="Copyright &amp;copy; ${year} ${pom.organization.name}. All Rights Reserved." />
    <ant:property name="title" value="${pom.name} ${pom.currentVersion} API"/>

    <ant:javadoc destdir="${maven.build.dir}/docs/api" 
	doctitle="&lt;h1&gt;${title}&lt;/h1&gt;" 
      noindex="false" author="true" use="true"
	windowtitle="${title}" 
      bottom="${copyright}"
      source="1.4"
      additionalparam="-breakiterator -J-Xmx128m "
      packagenames="*,org.*">

        <classpath>
          <path refid="template.classpath"/>
	  </classpath>

        <j:forEach var="child" items="${reactorProjects}">
          <sourcepath path="${child.file.parentFile}/src"/>
        </j:forEach>

       

        <j:forEach var="packageGroup" items="${pom.packageGroups}">
          <group title="${packageGroup.title}" packages="${packageGroup.packages}"/>
        </j:forEach>

	  <link href="${sun.j2se.link}" />
	

        <u:tokenize 
          var="listOfTags" 
          delim=" ">${maven.javadoc.customtags}</u:tokenize>
        <j:forEach var="someTag" items="${listOfTags}">
          <j:set var="nameVar" value="${someTag}.name"/>
          <j:set var="name" value="${context.findVariable(nameVar)}"/>
          <j:set var="descriptionVar" value="${someTag}.description"/>
          <j:set var="description" value="${context.findVariable(descriptionVar)}"/>
          <j:set var="enabledVar" value="${someTag}.enabled"/>
          <j:set var="enabled" value="${context.findVariable(enabledVar)}"/>
          <j:set var="scopeVar" value="${someTag}.scope"/>
          <j:set var="scope" value="${context.findVariable(scopeVar)}"/>
          <ant:tag name="${name}" description="${description}"
               enabled="${enabled}" scope="${scope}"/>
        </j:forEach>

    </ant:javadoc>
  </goal>
 

	<!-- multiproject goal for running eclipse in all module directories -->
	<goal name="eclipseAll">
		<j:set var="ignoreFailures" value="true"/>
		<j:set var="goal" value="eclipse"/>
		<attainGoal name="multiproject:goal"/>
	</goal>

</project>
