<!--
  JBoss, Home of Professional Open Source
  Copyright 2009, Red Hat Middleware LLC, and individual contributors
  as indicated by the @author tags.
  See the copyright.txt in the distribution for a
  full listing of individual contributors.
  This copyrighted material is made available to anyone wishing to use,
  modify, copy, or redistribute it subject to the terms and conditions
  of the GNU Lesser General Public License, v. 2.1.
  This program is distributed in the hope that it will be useful, but WITHOUT A
  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public License,
  v.2.1 along with this distribution; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA  02110-1301, USA.

  (C) 2007-2009,
  @author JBoss Inc. (jonathan.halliday@redhat.com)
-->
<!--
    build-release-pkgs.xml: Utility script for building JBossTS release artifacts.
    Probably only useful for JBossTS dev team. Everyone else should only need the
    regular build.xml.

    This script automates the some steps of the release build and packaging process
    to reduce the opportunities for users to get it wrong. For example, it works from
    a fresh svn checkout to ensure locally modified files in a dev's svn working copy
    don't sneak into the release bundle.

    usage:
      Tag the JBossTS release in svn.
        or you can do a snapshot release direct from trunk, see properties below.
      Check out the necessary bits of repository.jboss.org
        artifacts for use by other projects e.g. JBossAS get published here
        You don't need to check out JBossTS, the script does that.
      Check out the jbossts web pages project
        source and binary bundles for download by end users get published here
      Build or install a tagged release of JBossAS to build against. Set JBOSS_HOME.
        Use the oldest JBossAS release the JBossTS release is intended to support.
      Update the properties section below to suit your machine.
      Set JAVA_HOME to a jdk 1.5, since that's the version we currently support.
      ant -f build-release-pkgs.xml dist mvn-repository cms-repository
      check in the repository.jboss.org and the cms updates to publish the files.
      Update the project.xml in the cms to link the release bundles from the web pages.
      Update appropriate wiki pages, such as the 'which version to use' page.

      This version is for JBossTS 4.6 onwards. Don't use it for earlier releases, they are structured differently.
-->
<project name="JBossTS Release Packaging" default="dist" basedir=".">
    <description>
        package JBossTS binary + src files for upload to website and other repos.
    </description>

    <!-- you probably need to change these properties to suit your machine -->

    <!-- uncomment the block of properties below to do a snapshot release.
            you need permissions to webdav upload to the server for this to work
            http://www.jboss.org/community/docs/DOC-11381  -->

<!--
    <property name="svnbase" value="https://svn.jboss.org/repos/labs/labs/jbosstm"/>
    <property name="tag" value="trunk"/>
    <property name="filename" value="4.6.0-SNAPSHOT"/>
    <property name="mvn.repositoryId" value="snapshots.jboss.org"/>
    <property name="mvn.url" value="dav:https://snapshots.jboss.org/maven2"/>
-->

    <!-- a working direrctory for the process. Can contain output from previous releases if you like to keep them archived locally. -->
    <property name="workdir" location="/tmp/packaged_builds"/>
    <!-- where to get the source -->
    <property name="svnbase" value="https://svn.jboss.org/repos/labs/labs/jbosstm/tags"/>
    <!-- The tag as it appears under svnbase -->
    <property name="tag" value="JBOSSTS_4_6_0_GA"/>
    <!-- The file name base for the user downloadable files. Derive it from the tag -->
    <property name="filename" value="4.6.0.GA"/>
    <!-- the location the JBossTS web site content svn is checked out to -->
    <property name="cmsdir" value="/home/jhalli/IdeaProjects/jboss/jbosstm-cms/"/>
    <!-- the location the maven repository svn is checked out to.
        Hint: checkout only the subtree you need, the full thing is huge -->
    <property name="mvn.repodir" value="/home/jhalli/IdeaProjects/jboss/repository.jboss.org/maven2"/>

    <!-- you probably don't need to change anything below here -->

    <property name="mvn.repositoryId" value="repository.jboss.org"/>
    <property name="mvn.url" value="file:///${mvn.repodir}"/>

    <target name="init">
        <tstamp/>
        <mkdir dir="${workdir}"/>
    </target>

    <target name="dist" depends="init" description="build the end-user release bundles (src and binary)">

        <!-- pull the source code from svn -->
        <exec executable="svn" dir="${workdir}">
            <arg value="export"/>
            <arg value="${svnbase}/${tag}"/>
        </exec>

        <!-- package the full source release (all src tree) -->
        <delete file="${workdir}/jbossts-full-${filename}-src.zip"/>
        <zip basedir="${workdir}" destfile="${workdir}/jbossts-full-${filename}-src.zip"
             includes="${tag}/**"/>

        <!-- package the JTA only src tree (no JTS, XTS) -->
        <delete file="${workdir}/jbossts-jta-${filename}-src.zip"/>
        <zip basedir="${workdir}" destfile="${workdir}/jbossts-jta-${filename}-src.zip"
             includes="${tag}/**"
             excludes="${tag}/ArjunaJTS/**, ${tag}/XTS/**"/>

        <!-- build the JTA only binary release -->
        <delete dir="${workdir}/build"/>
        <mkdir dir="${workdir}/build"/>
        <unzip src="${workdir}/jbossts-jta-${filename}-src.zip" dest="${workdir}/build"/>
        <ant dir="${workdir}/build/${tag}" antfile="build.xml" target="jbossjta">
            <property name="com.hp.mw.sourceid" value="${tag}"/>
        </ant>

        <!-- package the JTA only binary release -->
        <copy todir="${workdir}/build/${tag}/${tag}">
            <fileset dir="${workdir}/build/${tag}/install"/>
        </copy>
        <delete file="${workdir}/jbossts-jta-${filename}.zip"/>
        <zip basedir="${workdir}/build/${tag}" destfile="${workdir}/jbossts-jta-${filename}.zip"
             includes="${tag}/**"/>

        <!-- build the full release (assumes XTS builds against JTS) -->
        <delete dir="${workdir}/build"/>
        <mkdir dir="${workdir}/build"/>
        <unzip src="${workdir}/jbossts-full-${filename}-src.zip" dest="${workdir}/build"/>
        <ant dir="${workdir}/build/${tag}" antfile="build.xml" target="jbossjts">
            <property name="com.hp.mw.sourceid" value="${tag}"/>
        </ant>
        <ant dir="${workdir}/build/${tag}/XTS" antfile="build.xml" target="install">
            <!-- build the jbossxts.sar with 1.1 only, not 1.0 (which is unsupported) -->
            <property  name="sartype" value="sar-11"/>
            <property  name="testtype" value="tests-11"/>
        </ant>

        <!-- package the full release -->
        <copy todir="${workdir}/build/${tag}/${tag}">
            <fileset dir="${workdir}/build/${tag}/install"/>
        </copy>
        <copy todir="${workdir}/build/${tag}/${tag}/xts">
            <fileset dir="${workdir}/build/${tag}/XTS/xts-install"/>
        </copy>
        <delete file="${workdir}/jbossts-full-${filename}.zip"/>
        <zip basedir="${workdir}/build/${tag}" destfile="${workdir}/jbossts-full-${filename}.zip"
             includes="${tag}/**"/>
    </target>

    <!-- copy the release into the cms svn tree (http://www.jboss.org/jbosstm web site content) -->
    <target name="cms-repository" description="copy release bundles to JBossTS web site content">
        <mkdir dir="${cmsdir}/downloads/${filename}"/>
        <mkdir dir="${cmsdir}/downloads/${filename}/src"/>
        <mkdir dir="${cmsdir}/downloads/${filename}/binary"/>
        <mkdir dir="${cmsdir}/downloads/${filename}/notes"/>
        <copy todir="${cmsdir}/downloads/${filename}/src">
            <fileset dir="${workdir}" includes="jbossts-*-${filename}-src.zip"/>
        </copy>
        <copy todir="${cmsdir}/downloads/${filename}/binary">
            <fileset dir="${workdir}" includes="jbossts-*-${filename}.zip"/>
        </copy>
        <!-- TODO: notes dir, xml generation? project.xml edits -->
    </target>

    <!-- http://wiki.jboss.org/wiki/MavenReleaseRepository -->
    <target name="mvn-repository" description="copy the release artifacts to the maven repository">
        <delete dir="${workdir}/build"/>
        <mkdir dir="${workdir}/build"/>

        <!-- As we don't actually use maven as a build tool this requires a fair bit of black magic.
         We no longer release the jta jars to maven, just the jts ones plus the jta version of the properties file
         so that they can function as a jta. The jta and jts version of the config file have the same name
         so they need to be renamed going into maven and then again coming out. yuck.
         -->

        <!-- extract and save the JTA version of the config file -->
        <unzip src="${workdir}/jbossts-jta-${filename}.zip" dest="${workdir}/build"/>
        <mkdir dir="${workdir}/build/resources"/>
        <delete file="${workdir}/build/resources.jar"/>
        <copy file="${workdir}/build/${tag}/etc/jbossts-properties.xml"
                tofile="${workdir}/build/resources/jbossts-properties.xml-forJTA" />

        <!-- now package the JTS -->

        <delete dir="${workdir}/build/${tag}"/>
        <unzip src="${workdir}/jbossts-full-${filename}.zip" dest="${workdir}/build"/>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/lib/jbossjts.jar"/>
            <arg value="-Dpackaging=jar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossjts"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/lib/jbossjts-integration.jar"/>
            <arg value="-Dpackaging=jar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossjts-integration"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/lib/jbossjts-jacorb.jar"/>
            <arg value="-Dpackaging=jar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossjts-jacorb"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/lib/ext/jbossts-common.jar"/>
            <arg value="-Dpackaging=jar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossts-common"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <!-- take the object store browser from jts, it will work with jta too -->
        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/bin/jbossts-tools.sar"/>
            <arg value="-Dpackaging=sar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossts-tools"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <!-- the resources part appears to require a bit of a kludge: -->
        <!-- add to the same dir as the previously cached jta properties file, then jar up -->
        <copy file="${workdir}/build/${tag}/etc/jbossts-properties.xml"
                tofile="${workdir}/build/resources/jbossts-properties.xml-forJTS" />

        <jar basedir="${workdir}/build" includes="resources/*" destfile="${workdir}/build/resources.jar"/>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/resources.jar"/>
            <arg value="-Dpackaging=jar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=resources"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <!-- now we do XTS -->

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/xts/sar/jbossxts.sar"/>
            <arg value="-Dpackaging=sar"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossxts"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/xts/tests/jbossxts-tests.zip"/>
            <arg value="-Dpackaging=zip"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossxts-tests"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

        <exec executable="mvn" dir="${workdir}">
            <arg value="deploy:deploy-file"/>
            <arg value="-Dfile=${workdir}/build/${tag}/xts/tests/jbossxts-interop-tests.zip"/>
            <arg value="-Dpackaging=zip"/>
            <arg value="-Durl=${mvn.url}"/>
            <arg value="-DrepositoryId=${mvn.repositoryId}"/>
            <arg value="-DgroupId=jboss.jbossts"/>
            <arg value="-DartifactId=jbossxts-interop-tests"/>
            <arg value="-Dversion=${filename}"/>
            <arg value="-DgeneratePom=true"/>
        </exec>

    </target>

</project>
