<!--
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 xmlns:j="jelly:core" xmlns:m="jelly:maven"
    xmlns:castor="castor">
    <property file="../../local-project.properties"/>
    <property file="../../common-project.properties"/>
    <!-- ================================================================== -->
    <!-- D I S T R I B U T I O N   G O A L S                                -->
    <!-- ================================================================== -->
    <goal name="dist:prepare-bin-filesystem"
        description="Builds the binary distribution file system.">
        <!--
    This is the directory where everything is copied to so that it can
    be archived.
    -->
        <delete dir="${maven.dist.bin.assembly.dir}"/>
        <mkdir dir="${maven.dist.bin.assembly.dir}"/>
        <copy todir="${maven.dist.bin.assembly.dir}">
            <fileset dir=".">
                <include name="NOTES"/>
                <include name="LICENSE"/>
                <include name="WARNING"/>
                <include name="README"/>
                <include name="INSTALL"/>
                <include name="FIXES.html"/>
                <include name="project.xml"/>
            </fileset>
        </copy>
        <attainGoal name="war"/>
        <copy todir="${maven.dist.bin.assembly.dir}">
            <fileset dir="${maven.build.dir}">
                <include name="*.war"/>
            </fileset>
        </copy>
    </goal>
    <goal name="dist:prepare-src-filesystem"
        description="Builds the source distribution file system.">
        <!-- S O U R C E  D I S T R I B U T I O N -->
        <delete dir="${maven.dist.src.assembly.dir}"/>
        <mkdir dir="${maven.dist.src.assembly.dir}"/>
        <attainGoal name="xdoc:init"/>
        <attainGoal name="jar:jar"/>
        <attainGoal name="javadoc:generate"/>
        <copy todir="${maven.dist.src.assembly.dir}">
            <fileset dir=".">
                <!--include name="**/plugin/**"/-->
                <exclude name="**/target/**"/>
                <exclude name="**/plugin/target/**"/>
                <exclude name="**/tutorial/target/**"/>
                <exclude name="**/build/**"/>
                <exclude name="**/bin/**"/>
                <exclude name="**/lib/**"/>
                <exclude name="**/temp/**"/>
                <exclude name="**/*.log"/>
                <exclude name="**/*.log.1"/>
                <exclude name="**/marshalled.psml"/>
                <exclude name="**/*.generation"/>
            </fileset>
        </copy>
    </goal>
    <!-- ================================================================== -->
    <!-- I N S T A L L  I N  L O C A L  R E P O S I T O R Y   G O A L       -->
    <!-- ================================================================== -->
    <goal name="dist:install" prereqs="dist:build"
        description="Install the distributions into the local repository">
        <property name="distdir__"
            value="${maven.repo.local}/${pom.artifactId}/distributions"/>
        <mkdir dir="${distdir__}"/>
        <copy todir="${distdir__}">
            <fileset dir="${maven.dist.dir}">
                <include name="**"/>
            </fileset>
        </copy>
        <attainGoal name="jar:install"/>
    </goal>
    <goal name="jar:install" prereqs="java:jar"
        description="Install the jar into the local repository">
        <property name="jardir__"
            value="${maven.repo.local}/${pom.artifactId}/jars"/>
        <mkdir dir="${jardir__}"/>
        <copy todir="${jardir__}">
            <fileset dir="${maven.build.dir}">
                <include name="*.jar"/>
            </fileset>
        </copy>
    </goal>
    <!-- ================================================================== -->
    <!--C O P Y  L O C A L I Z A T I O N   R E S O U R C E S                -->
    <!-- ================================================================== -->
    <postGoal name="java:jar-resources">
        <property name="base.package"
            value="org/apache/jetspeed/modules/localization"/>
        <copy todir="${maven.build.dest}/${base.package}" overwrite="true">
            <fileset dir="${pom.build.sourceDirectory}/${base.package}">
                <include name="**.properties*"/>
            </fileset>
        </copy>
    </postGoal>
    <!-- ================================================================== -->
    <!-- H O T D E P L O Y   W E B A P P                                    -->
    <!-- ================================================================== -->
    <goal name="hotdeploy" prereqs="java:compile"
        description="Hot deploys webapp classes on a local server">
        <!--echo>[DEBUG] maven.src.dir = ${maven.src.dir}</echo>
		<echo>[DEBUG] maven.war.src = ${maven.war.src}</echo>
		<echo>[DEBUG] maven.build.dir = ${maven.build.dir}</echo>
		<echo>[DEBUG] maven.war.build.dir = ${maven.war.build.dir}</echo-->
        <copy
            todir="${maven.war.appserver.home}/webapps/${pom.artifactId}/WEB-INF/classes">
            <fileset dir="${maven.build.dir}/classes">
                <!-- Do not include test files in the runtime jar -->
                <exclude name="**/Test*.*"/>
                <exclude name="**/test*.*"/>
                <!-- Also exclude the test cactus.properties file -->
                <exclude name="cactus.properties"/>
            </fileset>
        </copy>
        <copy todir="${maven.war.appserver.home}/webapps/${pom.artifactId}">
            <fileset dir="./webapp">
                <exclude name="**/*.properties.merge"/>
            </fileset>
        </copy>
    </goal>
    <!-- ================================================================== -->
    <!-- C R E A T E   T O R Q U E   O M                                    -->
    <!-- ================================================================== -->
    <preGoal name="java:compile">
        <!--
			This requires Castor 0.9.5.
			But using this version of Castor causes the registry to lock up.
			This version of Castor is not the problem, but causes it to appear.
			JIRA #JS1-405 deals with this issue.
		-->
        <!--
	    <attainGoal name="castor:prepare-filesystem"/>
		<castor:generate
			schema="${maven.src.dir}/xml/jetspeed-portal-content.xsd"
			package="org.apache.jetspeed.xml.api.jcm"
			marshal="true"/>
		-->
        <attainGoal name="prepare.apis"/>
        <!--<attainGoal name="torque:om"/>-->
    </preGoal>
    <!-- ================================================================== -->
    <!-- C L E A N - U P   T O R Q U E   O M                                -->
    <!-- ================================================================== -->
    <preGoal name="clean">
        <delete failonerror="false">
            <fileset dir="${maven.src.dir}/java" includes="**/*.generation"/>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/apps/coffees">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/apps/coffees/map">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/apps/email">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <exclude name="EmailInbox.java"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/apps/email/map">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/apps/turbine">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/apps/turbine/map">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/security/turbine">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <exclude name="TurbineGroup.java"/>
                <exclude name="TurbineRole.java"/>
                <exclude name="TurbinePermission.java"/>
                <exclude name="TurbineUserPeer.java"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/security/turbine/map">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/om/dbpsml/map">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <include name="**.java"/>
            </fileset>
            <fileset dir="${maven.src.dir}/java/org/apache/jetspeed/om/dbpsml">
                <exclude name="CVS"/>
                <exclude name="**.html"/>
                <exclude name="JetspeedGroupProfilePeer.java"/>
                <exclude name="JetspeedRoleProfilePeer.java"/>
                <exclude name="JetspeedUserProfilePeer.java"/>
                <include name="**.java"/>
            </fileset>
            <fileset
                dir="${maven.src.dir}/java/org/apache/jetspeed/xml/api/jcm">
                <include name="**/*.java"/>
                <exclude name="CVS"/>
                <exclude name="package.html"/>
            </fileset>
        </delete>
        <!-- Also, need to delete selected sources from security/turbine and dbpsml folders -->
    </preGoal>
    <!-- =================================================================== -->
    <!-- Remove unwanted items before the .war is created                    -->
    <!-- =================================================================== -->
    <postGoal name="jar" >
        <attainGoal name="jar:install" />
        <available file="${basedir}/../../${project.aipowhite.dirname}/lib" property="existsflag"/>
            <j:if test="${existsflag}">
                <m:reactor basedir="${basedir}/../../${project.aipowhite.dirname}/lib" includes="*/project.xml"
                    goals="merge" banner="Build" ignoreFailures="false"/>
            </j:if>
        <m:reactor basedir="${basedir}/../../${project.aipowhite.dirname}/portlets" includes="*/project.xml"
            goals="merge" banner="Build" ignoreFailures="false"/>
    </postGoal>
    <preGoal name="war:war">
        <attainGoal name="jar"/>
        <echo>Deleting uneeded resources from ${maven.war.webapp.dir}...</echo>
        <delete failonerror="false">
            <fileset dir="${maven.war.webapp.dir}" includes="**/*.log"/>
            <fileset dir="${maven.war.webapp.dir}" includes="**/*.log.1"/>
            <fileset dir="${maven.war.webapp.dir}"
                includes="**/WEB-INF/classes/**"/>
        </delete>
        <echo>Copying ${maven.final.name}.jar to
            ${maven.war.webapp.dir}...</echo>
        <copy todir="${maven.war.webapp.dir}/WEB-INF/lib">
            <fileset dir="${maven.build.dir}">
                <include name="${maven.final.name}.jar"/>
            </fileset>
        </copy>
    </preGoal>
    <goal name="deploy" description="Deploys jetspeed.war on a local server">
        <delete dir="${maven.war.appserver.home}/webapps/${pom.artifactId}"/>
        <copy file="${maven.build.dir}/${pom.artifactId}.war"
            todir="${maven.war.appserver.home}/webapps/">
        </copy>
        <unwar src="${maven.war.appserver.home}/webapps/${pom.artifactId}.war"
            dest="${maven.war.appserver.home}/webapps/${pom.artifactId}"/>
    </goal>
    <goal name="prepare.apis">
        <uptodate property="apis.uptodate"
            targetfile="${maven.build.dir}/${pom.artifactId}-${pom.currentVersion}.jar"
            >
            <srcfiles dir="${maven.src.dir}/xml" includes="**/*.xsd"/>
        </uptodate>
        <j:set var="castorflag" value="${apis.uptodate}"/>
        <j:if test="${castorflag != 'true'}">
            <echo>Generating Jetspeed XML bindings</echo>
            <java classname="org.exolab.castor.builder.SourceGenerator"
                fork="yes">
                <classpath refid="maven.dependency.classpath"/>
                <arg value="-i"/>
                <arg value="${maven.src.dir}/xml/jetspeed-portal-content.xsd"/>
                <arg value="-f"/>
                <arg value="-dest"/>
                <arg value="${maven.src.dir}/java"/>
                <arg value="-package"/>
                <arg value="org.apache.jetspeed.xml.api.jcm"/>
            </java>
        </j:if>
    </goal>
    <!-- =================================================================== -->
    <!-- PSML Importer                                                       -->
    <!-- =================================================================== -->
    <goal name="import" prereqs="java:compile" description="Import PSML">
        <java fork="true"
            classname="org.apache.jetspeed.services.psmlmanager.PsmlImporter" >
            <!-- comment this out to preserve existing profiles -->
            <arg value="false"/>
            <classpath>
                <path refid="maven.dependency.classpath"/>
                <pathelement path="${maven.build.dest}"/>
            </classpath>
        </java>
    </goal>
</project>
