<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  The ASF licenses this file to You
  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.  For additional information regarding
  copyright in this work, please see the NOTICE file in the top level
  directory of this distribution.
-->
<project name="Roller Core" default="build" basedir=".">
    
    <description>Build core Roller utils.</description>

    <property file="build.properties" />
    
    <!-- core properties -->
    <property name="build"            value="${basedir}/build" />
    <property name="dist"             value="${basedir}/dist" />
    <property name="src"              value="${basedir}/src/java" />
    <property name="test"             value="${basedir}/test/java" />
    <property name="tools"            value="${basedir}/../../tools" />
    
    <!-- build properties -->
    <property name="build.compile"          value="${build}/compile"/>
    <property name="build.compile.business" value="${build.compile}/business"/>
    <property name="build.compile.test"     value="${build.compile}/test"/>
    <property name="build.lib"              value="${build}/lib"/>
    <property name="build.test"             value="${build}/test"/>
    <property name="build.test.reports"     value="${build.test}/reports"/>
    
    
    <fileset id="core-jars" dir="${tools}">
        <include name="lib/commons-lang-2.1.jar"/>
        <include name="lib/commons-codec-1.3.jar"/>
    </fileset>
    
    <path id="core.path">
        <fileset refid="core-jars" />
    </path>    
    
    <path id="test.path">
        <!-- testing jars -->
        <pathelement location="${tools}/buildtime/junit-4.1.jar"/>
        
        <!-- plus normal jars -->
        <path refid="core.path"/>
        
        <!-- compiled code -->
        <pathelement location="${build.lib}/roller-core.jar"/>
    </path>
    
    
    <!-- ============================================== -->
    <!-- clean out any contents from last build -->
    <target name="clean" description="Clean (i.e. remove) build and dist dirs">
        <delete dir="${build}" />
        <delete dir="${dist}" />
    </target>
    
    
    <!-- ============================================== -->
    <!-- build all code -->
    <target name="build">
        
        <!-- compile core classes -->
        <mkdir dir="${build.compile.business}"/>
        <javac destdir="${build.compile.business}"
               debug="${build.debug}" 
               source="${build.sourcelevel}"
               deprecation="${build.deprecation}">
            
            <src path="${src}" />
            
            <classpath>
                <path refid="core.path"/>
            </classpath>
        </javac>
        
        <!-- Copy resources -->
        <copy todir="${build.compile.business}">
            <fileset dir="${src}" excludes="**/*.java, **/*.html, **/*.png" />
        </copy>
        
        <!-- Jar it up -->
        <mkdir dir="${build.lib}"/>
        <jar basedir="${build.compile.business}"
             jarfile="${build.lib}/roller-core.jar"/>
        
    </target>
    
    
    <!-- ============================================== -->
    <!-- create distributable components -->
    <target name="dist" depends="build" >
        
        <!-- distributable libraries -->
        <mkdir dir="${dist}/lib" />
        <copy todir="${dist}/lib" >
            <fileset dir="${build.lib}" />
        </copy>
        
    </target>
    
    
    <!-- ============================================== -->
    <!-- build code used for unit testing -->
    <target name="build-tests" depends="build" >
    
        <!-- compile all test classes -->
        <mkdir dir="${build.compile.test}" />
        <javac destdir="${build.compile.test}"
            includeantruntime="false"
            debug="${build.debug}" 
            source="${build.sourcelevel}"
            deprecation="${build.deprectation}">
            
            <src path="${test}" />
            
            <classpath>
                <!-- testing jars -->
                <path refid="test.path"/>
                
                <!-- plus our compiled classes -->
                <pathelement location="${build.compile.business}"/>
            </classpath>
        </javac>
        
        <!-- Copy test resources -->
        <copy todir="${build.compile.test}">
            <fileset dir="${test}" excludes="**/*.java, **/*.html, **/*.png" />
        </copy>
        
    </target>
    
    
    <!-- ===================================== -->
    <!-- test core functionality -->
    <target name="test" depends="build-tests" >
        
        <mkdir dir="${build.test.reports}/business/xml"/>
        <mkdir dir="${build.test.reports}/business/html"/>
        
        <junit dir="${build.test}" fork="${junit.fork}" printsummary="on" showOutput="true">
            <classpath>
                <!-- testing jars -->
                <path refid="test.path"/>
                
                <!-- plus our compiled test classes -->
                <pathelement location="${build.compile.test}"/>
            </classpath>
            
            <!-- needed to satisfy ref in log4j.properties -->
            <jvmarg value="-Dcatalina.base=${build.test}"/> 
            <jvmarg value="-Dbuild=${build}"/>
            <formatter type="xml"/>
            <batchtest toDir="${build.test.reports}/business/xml" haltonerror="${junit.haltonerror}">
                <fileset dir="${build.compile.test}">
                    <include name="org/apache/roller/util/UtilitiesTestSuite.class"/>
                </fileset>
            </batchtest>
        </junit>
        
        <junitreport todir="${build.test.reports}/business/xml">
            <fileset dir="${build.test.reports}/business/xml">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="noframes" toDir="${build.test.reports}/business/html"/>
        </junitreport>
    
    </target>
    
</project>
