<!--
Copyright 2004 The Apache Software Foundation
Licensed  under the  Apache License,  Version 2.0  (the "License");
you may not use  this file  except in  compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed  under the  License is distributed on an "AS IS" BASIS,
WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
implied.

See the License for the specific language governing permissions and
limitations under the License.
-->
<project default="multiproject:artifact"
         xmlns:j="jelly:core"
         xmlns:maven="jelly:maven"
         xmlns:ant="jelly:ant">

  <preGoal name="xdoc:jelly-transform">
    <attainGoal name="faq"/>
  </preGoal>

  <preGoal name="clean">
    <attainGoal name="multiproject:clean"/>
  </preGoal>

  <preGoal name="fullDeployment">
    <attainGoal name="multiproject:install"/>
  </preGoal>

  <goal name="fullDeployment">
    <maven:reactor
            basedir="${basedir}"
            includes="portal/project.xml"
            goals="tomcat:deploy"
            banner="Deploying Portal"
            postProcessing="false"
            ignoreFailures="false"/>
    <maven:reactor
            basedir="${basedir}"
            includes="testsuite/project.xml"
            goals="deployTestsuite"
            banner="Deploying Test Suite to Pluto"
            postProcessing="false"
            ignoreFailures="false"/>
  </goal>

  <goal name="deploy">
    <echo>
************************************************
* Please ensure that a fullDeployment has      *
* previously been run if this deploy attempt   *
* fails.  It is the fullDeployment that        *
* deploys pluto container and portal driver.   *
************************************************
    </echo>
       <maven:reactor
               basedir="${basedir}"
               includes="deploy/project.xml"
               goals="deploy"
               banner="Deploy a portlet"
               postProcessing="false"
               ignoreFailures="false"/>
  </goal>

  <goal name="website">
    <!-- this creates the website in "target/docs" -->
    <attainGoal name="multiproject:site"/>

    <!-- deploy the website to our server -->
    <attainGoal name="site:sshdeploy"/>

  </goal>

<!-- ========================= -->
<!-- Pluto Distributions Goals -->
<!-- ========================= -->

  <goal name="distribute:all">
    <attainGoal name="distribute:binary"/>
    <attainGoal name="distribute:source"/>
    <attainGoal name="distribute:container"/>
    <attainGoal name="distribute:optional"/>
    <attainGoal name="distribute:tools"/>
  </goal>


  <goal name="distribute:init">
    <j:set var="maven.dist.dir" value="${basedir}/target/distributions"/>
    <ant:mkdir dir="${maven.dist.dir}"/>
  </goal>

<!-- =========================== -->
<!-- pluto-src-x.x distributions -->
<!-- =========================== -->

  <goal name="distribute:source" prereqs="distribute:init">
    <j:set var="plutosrc.dist.name" value="pluto-src-${pom.currentVersion}"/>
	<ant:zip zipfile="${maven.dist.dir}/${plutosrc.dist.name}.zip" basedir="${basedir}">
	  <ant:patternset dir="${basedir}" defaultexcludes="on">
        <ant:include name="container/**/*"/>
        <ant:include name="descriptors/**/*"/>
        <ant:include name="deploy/**/*"/>
        <ant:include name="portal/**/*"/>
        <ant:include name="portlet-deploy/**/*"/>
        <ant:include name="testsuite/**/*"/>
        <ant:include name="xdocs/**/*"/>
        <ant:include name="LICENSE*"/>
        <ant:include name="GETTING-STARTED.html"/>
        <ant:include name="maven.xml"/>
        <ant:include name="project.xml"/>
        <ant:include name="project.properties"/>
        <ant:include name="build.properties.sample"/>
        <ant:include name="README"/>
        <ant:exclude name="**/target/**"/>
      </ant:patternset>
	</ant:zip>

	<ant:tar longfile="gnu" tarfile="${maven.dist.dir}/${plutosrc.dist.name}.tar" basedir="${basedir}">
	  <ant:patternset dir="${basedir}" defaultexcludes="on">
        <ant:include name="container/**/*"/>
        <ant:include name="deploy/**/*"/>
        <ant:include name="portal/**/*"/>
        <ant:include name="portlet-deploy/**/*"/>
        <ant:include name="testsuite/**/*"/>
        <ant:include name="xdocs/**/*"/>
        <ant:include name="LICENSE*"/>
        <ant:include name="GETTING-STARTED.html"/>
        <ant:include name="maven.xml"/>
        <ant:include name="project.xml"/>
        <ant:include name="project.properties"/>
        <ant:include name="build.properties.sample"/>
        <ant:include name="README"/>
        <ant:exclude name="**/target/**"/>
      </ant:patternset>
    </ant:tar>

    <ant:gzip
      zipfile="${maven.dist.dir}/${plutosrc.dist.name}.tar.gz"
      src="${maven.dist.dir}/${plutosrc.dist.name}.tar"
    />
  </goal>

  <goal name="distribute:binary" prereqs="distribute:init,multiproject:install,multiproject:site">
    <!-- Set Some Default Properties -->
    <j:set var="dist.tomcat"
           value="http://archive.apache.org/dist/tomcat/tomcat-5/archive/v5.5.9/bin/jakarta-tomcat-5.5.9.tar.gz"/>
    <j:set var="plutobin.dist.name" value="pluto-${pom.currentVersion}"/>

    <j:set var="plutobin.tomcatgz" value="${maven.dist.dir}/plutobin-tomcat.tar.gz"/>
    <j:set var="plutobin.tomcattar" value="${maven.dist.dir}/plutobin-tomcat.tar"/>

    <!-- Retrieve the Tomcat Release -->
    <j:if test="${context.getVariable('maven.proxy.host') != null}">
        <setproxy proxyhost="${maven.proxy.host}" proxyport="${maven.proxy.port}"/>
    </j:if>
    <get src="${dist.tomcat}" dest="${plutobin.tomcatgz}"/>
    <gunzip src="${plutobin.tomcatgz}" dest="${plutobin.tomcattar}"/>
    <untar src="${plutobin.tomcattar}" dest="${maven.dist.dir}"/>

    <!-- Cleanup Unecessary Archives -->
    <delete file="${plutobin.tomcatgz}"/>
    <delete file="${plutobin.tomcattar}"/>

    <!-- Rename the Distribution -->
    <move todir="${maven.dist.dir}/${plutobin.dist.name}">
      <fileset dir="${maven.dist.dir}/jakarta-tomcat-5.5.9"/>
    </move>

    <!-- Rename tomcat's license -->
    <move file="${maven.dist.dir}/${plutobin.dist.name}/LICENSE" tofile="LICENSE.tomcat"/>

    <!-- Add emptySessionPath="true" to Connector element in server.xml -->
    <ant:replace file="${maven.dist.dir}/${plutobin.dist.name}/conf/server.xml"
    	token="connectionTimeout=&quot;20000&quot; disableUploadTimeout=&quot;true&quot; /&gt;" 
    	value="connectionTimeout=&quot;20000&quot; disableUploadTimeout=&quot;true&quot; emptySessionPath=&quot;true&quot; /&gt;" 
    	summary="true"/>

    <ant:replace file="${maven.dist.dir}/${plutobin.dist.name}/conf/tomcat-users.xml"
    	token="&lt;/tomcat-users&gt;" 
    	value="&lt;user name=&quot;manager&quot; password=&quot;manager&quot; roles=&quot;manager&quot; /&gt;&lt;/tomcat-users&gt;" 
    	summary="true"/>

    <!-- Cleanup the tomcat distribution; purge unwanted examples. -->
    <delete>
      <fileset dir="${maven.dist.dir}/${plutobin.dist.name}/webapps" includes="**"/>
      <fileset dir="${maven.dist.dir}/${plutobin.dist.name}/webapps" includes="**/*.*"/>
      <!-- fileset dir="${maven.dist.dir}/${plutobin.dist.name}/conf/Catalina/localhost" includes="**/*"/ -->
    </delete>


    <!-- Deploy Pluto (and it's licenses)! -->
    <copy todir="${maven.dist.dir}/${plutobin.dist.name}">
      <fileset dir="${basedir}" includes="LICENSE*"/>
      <fileset dir="${basedir}" includes="README"/>
    </copy>

    <!-- Pluto Documentation -->
    <copy todir="${maven.dist.dir}/${plutobin.dist.name}/webapps/ROOT">
      <fileset dir="${basedir}/target/docs" includes="**/*.*"/>
    </copy>

    <j:invokeStatic className="java.lang.System" method="setProperty">
      <j:arg type="java.lang.String" value="maven.tomcat.home"/>
      <j:arg type="java.lang.String" value="${maven.dist.dir}/${plutobin.dist.name}"/>
    </j:invokeStatic>

    <j:invokeStatic className="java.lang.System" method="setProperty">
      <j:arg type="java.lang.String" value="maven.tomcat.version.major"/>
      <j:arg type="java.lang.String" value="5"/>
    </j:invokeStatic>

    <ant:property name="maven.tomcat.override.ant" value="HAHA"/>

    <maven:reactor
            basedir="${basedir}"
            includes="portal/project.xml"
            goals="tomcat:deploy"
            banner="Deploying Portal to Binary Distribution"
            postProcessing="false"
            ignoreFailures="false"/>

    <maven:reactor
            basedir="${basedir}"
            includes="testsuite/project.xml"
            goals="deployTestsuite"
            banner="Deploying Test Suite to Binary Distribution"
            postProcessing="false"
            ignoreFailures="false"/>

    <!-- Make the Archives -->
	<ant:zip zipfile="${maven.dist.dir}/${plutobin.dist.name}.zip">
	  <ant:zipfileset
		dir="${maven.dist.dir}"
        includes="${plutobin.dist.name}/**/*"/>
	</ant:zip>

	<ant:tar longfile="gnu" tarfile="${maven.dist.dir}/${plutobin.dist.name}.tar">
	  <ant:tarfileset dir="${maven.dist.dir}"
	      includes="${plutobin.dist.name}/**/*"/>
    </ant:tar>

    <ant:gzip
      zipfile="${maven.dist.dir}/${plutobin.dist.name}.tar.gz"
      src="${maven.dist.dir}/${plutobin.dist.name}.tar"
    />

  </goal>

<!-- ======================= -->
<!-- pluto-x.x distributions -->
<!-- ======================= -->

  <goal name="distribute:container" prereqs="distribute:init">
    <j:set var="pluto.dist.name" value="pluto-${pom.currentVersion}"/>
    <maven:reactor
            basedir="${basedir}"
            includes="container/project.xml"
			goals="dist:build"
            banner="Creating Pluto Container Distributions"
            postProcessing="false"
            ignoreFailures="false"/>
	<ant:copy
      tofile="${maven.dist.dir}/pluto-lib-core-${pom.currentVersion}.zip"
	  file="${basedir}/container/target/distributions/${pluto.dist.name}.zip"/>
	<ant:copy
      tofile="${maven.dist.dir}/pluto-lib-core-${pom.currentVersion}.tar.gz"
	  file="${basedir}/container/target/distributions/${pluto.dist.name}.tar.gz"/>
  </goal>

<!-- ================================ -->
<!-- pluto-optional-x.x distributions -->
<!-- ================================ -->
  <goal name="distribute:optional">
    <j:set var="plutooptional.dist.name"
           value="pluto-lib-optional-${pom.currentVersion}"/>
    <!-- None Yet! -->
  </goal>

<!-- ============================ -->
<!-- pluto-tools-x.x distribution -->
<!-- ============================ -->
  <goal name="distribute:tools" prereqs="distribute:init">
    <j:set var="plutotools.dist.name"
           value="pluto-lib-tools-${pom.currentVersion}"/>
    <!-- STEP #1: Create archives and docs for each -->
    <maven:reactor
            basedir="${basedir}"
			includes="portal/project.xml"
			goals="war:war,javadoc:generate"
            banner="Creating Tools-Portal Distribution"
            postProcessing="false"
            ignoreFailures="false"/>
    <maven:reactor
            basedir="${basedir}"
			includes="testsuite/project.xml"
			goals="war:war,javadoc:generate"
            banner="Creating Tools-TestSuite Distribution"
            postProcessing="false"
            ignoreFailures="false"/>
    <maven:reactor
            basedir="${basedir}"
			includes="deploy/project.xml"
			goals="jar:jar,javadoc:generate"
            banner="Creating Tools-Deploy Distribution"
            postProcessing="false"
            ignoreFailures="false"/>

    <!-- -->
	<ant:copy todir="${maven.dist.dir}/${plutotools.dist.name}/">
      <ant:fileset dir="${basedir}" includes="LICENSE*"/>
      <ant:fileset dir="${basedir}" includes="README"/>
	</ant:copy>

	<!-- STEP #2: Copy all to our dist dist dir -->
	<!--          First the driver. -->
	<ant:copy
      tofile="${maven.dist.dir}/${plutotools.dist.name}/pluto-driver-${pom.currentVersion}.war"
      file="${basedir}/portal/target/pluto.war"/>

	<ant:copy todir="${maven.dist.dir}/${plutotools.dist.name}/docs/pluto-driver-${pom.currentVersion}">
      <ant:fileset dir="${basedir}/portal/target/docs" includes="apidocs/**/*"/>
	</ant:copy>

	<!--          Now the testsuite. -->
	<ant:copy
			tofile="${maven.dist.dir}/${plutotools.dist.name}/pluto-testsuite-${pom.currentVersion}.war"
      file="${basedir}/testsuite/target/testsuite.war"/>

	<ant:copy todir="${maven.dist.dir}/${plutotools.dist.name}/docs/pluto-testsuite-${pom.currentVersion}">
      <ant:fileset dir="${basedir}/testsuite/target/docs" includes="apidocs/**/*"/>
	</ant:copy>

	<!--          What do we do for the deployer? -->

	<!-- STEP #3: Create the Distributions -->
	<ant:zip zipfile="${maven.dist.dir}/${plutotools.dist.name}.zip">
	  <ant:zipfileset
		dir="${maven.dist.dir}"
        includes="${plutotools.dist.name}/**/*"/>
	</ant:zip>

	<ant:tar longfile="gnu" tarfile="${maven.dist.dir}/${plutotools.dist.name}.tar">
	  <ant:tarfileset dir="${maven.dist.dir}"
	      includes="${plutotools.dist.name}/**/*"/>
    </ant:tar>

    <ant:gzip
      zipfile="${maven.dist.dir}/${plutotools.dist.name}.tar.gz"
      src="${maven.dist.dir}/${plutotools.dist.name}.tar"
    />

  </goal>
</project>

