<?xml version="1.0" encoding="UTF-8"?>
<!--
 ! Licensed to the Apache Software Foundation (ASF) under one
 ! or more contributor license agreements.  See the NOTICE file
 ! distributed with this work for additional information
 ! regarding copyright ownership. 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.
 !-->
<project name="common" default="" basedir=".">

    <!-- Root of the River source distribution -->
    <property name="root" location="." />

    <!-- User specific settings -->
    <property file="${root}/build.properties" />

    <!-- Product version info -->
    <property name="version" value="trunk"/>
    <property name="product.name" value="apache-river-${version}"/>
    <property name="product.title" value="Apache River v${version}"/>

    <!-- Standard directory names -->
    <property name="doc" value="doc"/>
    <property name="src" value="src"/>
    <property name="src-doc" value="src-doc"/>
    <property name="poms" value="poms"/>
    <property name="configentry" value="configentry"/>
    <property name="lib" value="lib"/>
    <property name="lib-dl" value="lib-dl"/>
    <property name="lib-ext" value="lib-ext"/>
    <property name="doc.spec.api" value="${doc}/specs/api"/>
    <property name="doc.api" value="${doc}/api"/>
    <property name="build" value="build"/>
    <property name="build.classes" value="${build}/classes"/>
    <property name="dist" value="dist"/>
    <property name="test" value="test"/>
    <property name="test.src" value="${test}/src"/>
    <property name="test.lib" value="${test}/lib"/>
    <property name="test.classes" value="${test}/classes"/>
    <property name="test.results" value="${test}/results"/>

    <!-- Standard directory locations -->
    <property name="doc.dir" location="${doc}"/>
    <property name="doc.api.dir" location="${doc.api}"/>
    <property name="doc.spec.api.dir" location="${doc.spec.api}"/>
    <property name="src.dir" location="${src}"/>
    <property name="src.manifest.dir" location="${src}/manifest"/>
    <property name="src.configentry.dir" location="${src}/configentry"/>

    <property name="src-extra.dir" location="src-extra"/>
    <property name="src-doc.dir" location="src-doc"/>

    <property name="poms.dir" location="${poms}"/>
    <property name="build.dir" location="${build}"/>
    <property name="build.classes.dir" location="${build.classes}"/>
    <property name="build.deps.dir" location="${build.dir}/deps"/>
    <property name="configentry.dir" location="${configentry}"/>
    <property name="dist.dir" location="dist"/>

    <property name="lib.dir" location="${lib}"/>
    <property name="lib-dl.dir" location="${lib-dl}"/>
    <property name="lib-ext.dir" location="${lib-ext}"/>

    <property name="test.dir" value="${test}"/>
    <property name="test.src.dir" value="${test.src}"/>
    <property name="test.lib.dir" value="${test.lib}"/>
    <property name="test.classes.dir" value="${test.classes}"/>
    <property name="test.results.dir" value="${test.results}"/>

    <!-- Standard javadoc options and settings -->
    <property name="jdk.doc.url" value="http://docs.oracle.com/javase/6/docs/api"/>
    <property name="jdk.packages" location="${root}/${src-doc}/j2se"/>
    <property name="api.copyright" value="Copyright 2007-2010, multiple authors.&lt;br&gt;Licensed under the &lt;a href=&quot;http://www.apache.org/licenses/LICENSE-2.0&quot; target=&quot;child&quot; &gt;Apache License, Version 2.0&lt;/a&gt;, see the &lt;a href=&quot;{@docRoot}/doc-files/NOTICE&quot; target=&quot;child&quot; &gt;NOTICE&lt;/a&gt; file for attributions."/>

    <!--## Private package inclusions for use with classdep; the
        ## classes in these packages are both not part of the JSK
        ## platform and not public (have generated javadoc).
        ## The -skip for logging classes is because LogManager is in
        ## jsk-platform.jar and Levels is in jsk-lib.jar.
        ## The -in com.sun.jini.outrigger is there in order to catch
        ## any use of the following deprecated APIs:
        ##       com.sun.jini.outrigger.AdminIterator
        ##       com.sun.jini.outrigger.ConstrainableJavaSpaceAdmin
        ##       com.sun.jini.outrigger.JavaSpaceAdmin
        ## Once these APIs have been removed, the outrigger include
        ## can be removed -->
    <property name="jskprivate.include" value="-in com.sun.jini.action -in com.sun.jini.collection -in com.sun.jini.constants -in com.sun.jini.system -in com.sun.jini.logging -skip com.sun.jini.logging.LogManager -skip com.sun.jini.logging.Levels -in com.sun.jini.outrigger"/>
    <!-- Common packages to exclude within ClassDep -->
    <property name="jskplatform.exclude" value="-out com.sun.jini.discovery -out net.jini.activation -out net.jini.config -out net.jini.constraint -out net.jini.core -out net.jini.export -out net.jini.id -out net.jini.iiop -out net.jini.io -out net.jini.jeri -out net.jini.jrmp -out net.jini.loader -out net.jini.security -out net.jini.url -out org.apache.river.api -skip net.jini.discovery.ConstrainableLookupLocator -skip net.jini.discovery.ConstrainableLookupLocatorTrustVerifier -skip com.sun.jini.config.ConfigUtil -skip com.sun.jini.config.KeyStores -skip com.sun.jini.logging.LogManager"/>

    <property name="river.home" location="${root}"/>
    <property name="river.lib.dir" location="${river.home}/${lib}"/>
    <property name="river.lib-ext.dir" location="${river.home}/${lib-ext}"/>
    <property name="river.classes.dir" location="${river.home}/${build.classes}"/>
    <property name="river.src.dir" location="${river.home}/${src}"/>

    <property name="debug" value="true"/>
    <property name="verbose" value="false"/>
    <!-- Possible values for 'debuglevel': none or combination of lines,source,vars -->
    <property name="debuglevel" value="lines,source,vars"/>
    <property name="nowarn" value="true"/>
    <property name="deprecation" value="false"/>

    <patternset id="java.source">
        <include name="**/*.java"/>
    </patternset>

    <!-- classpath containing River distribution -->
    <!-- TODO: split into multiple paths -->
    <path id="river.jars">
        <fileset dir="${river.lib.dir}" includes="**/*.jar" excludes="${asm.jars.pattern}" />
    </path>

    <path id="river.classes">
        <pathelement path="${river.classes.dir}"/>
    </path>

    <fileset id="asm.jars" dir="${root}/dep-libs/asm">
        <include name="asm-3.2.jar" />
        <include name="asm-commons-3.2.jar" />
    </fileset>

    <fileset id="velocity.jars" dir="${root}/dep-libs/velocity">
        <include name="velocity-1.7.jar" />
    </fileset>
    
    <fileset id="high-scale-lib.jars" dir="${root}/dep-libs/high-scale-lib">
        <include name="high-scale-lib.jar" />
    </fileset>
    
    <fileset id="reference-collections.jar" dir="${root}/dep-libs/rc-libs">
        <include name="reference-collections-1.0.1.jar" />
    </fileset>
    
    <fileset id="dnsjava.jar" dir="${root}/dep-libs/dnsjava">
        <include name="dnsjava-2.1.3.jar" />
    </fileset>
    

    <path id="compile.classpath" >
        <fileset refid="asm.jars" />
        <fileset refid="velocity.jars" />
        <fileset refid="high-scale-lib.jars" />
        <fileset refid="reference-collections.jar" />
    </path>


    <path id="asm.classpath">
        <fileset refid="asm.jars" />
    </path>

    <path id="classdep.classes.classpath">
        <path refid="river.classes"/>
        <path refid="asm.classpath"/>
    </path>
   
    <path id="classdep.jar.classpath">
        <pathelement location="${river.lib.dir}/classdep.jar"/>
        <!--<path refid="asm.classpath" />-->
    </path>

    <path id="classdep.classpath">
        <path refid="classdep.jar.classpath" />
    </path>

    <path id="jarwrapper.classes.classpath">
        <path refid="river.classes"/>
    </path>

    <path id="jarwrapper.jar.classpath">
        <pathelement location="${river.lib.dir}/jarwrapper.jar"/>
    </path>

    <path id="jarwrapper.classpath">
        <path refid="jarwrapper.jar.classpath" />
    </path>

    <path id="test.compile.classpath">
        <path location="${build.classes.dir}"/>
        <fileset dir="${test.lib.dir}">
            <include name="*.jar"/>
        </fileset>
    </path>

    <path id="test.classpath">
        <path location="${test.classes.dir}"/>
        <path refid="test.compile.classpath"/>
    </path>

    <property name="jre.ext.dir" location="${java.home}/lib/ext"/>

    <macrodef name="javac-cmd" description="Run javac">
        <attribute name="source.pat" default="java.source"/>
        <attribute name="source.dir"/>
        <attribute name="dest.dir"/>
        <attribute name="debug" default="${debug}"/>
        <attribute name="debuglevel" default="${debuglevel}"/>
        <attribute name="source" default="6"/>
        <attribute name="target" default="6"/>
        <attribute name="deprecation" default="${deprecation}"/>
        <attribute name="verbose" default="${verbose}"/>
        <attribute name="nowarn" default="${nowarn}"/>
        <element name="javac-cmd-elements" implicit="true" optional="true"/>
        <sequential>
            <javac fork="yes"
                    debug="@{debug}"
                    debuglevel="@{debuglevel}"
                    deprecation="@{deprecation}"
                    destdir="@{dest.dir}"
                    nowarn="@{nowarn}"
                    source="@{source}"
                    srcdir="@{source.dir}"
                    target="@{target}"
                    verbose="@{verbose}"
                    includeantruntime="false">
                <patternset refid="@{source.pat}"/>
                <javac-cmd-elements/>
            </javac>
        </sequential>
    </macrodef>

    <macrodef name="preferredlistgen" description="Run PreferredListGen">
        <element name="plg-elements" implicit="true"/>
        <sequential>
            <java classname="com.sun.jini.tool.PreferredListGen"
                    fork="true" failonerror="true" >
                <plg-elements/>
            </java>
        </sequential>
    </macrodef>

    <macrodef name="classdep" description="Run ClassDep">
        <attribute name="output"/>
        <attribute name="classpathref" default="classdep.classpath" />
        <element name="cd-elements" implicit="yes" />
        <sequential>
            <java classname="com.sun.jini.tool.ClassDep" 
                  fork="true" failonerror="true"
                  logError="true" output="@{output}">
                <classpath refid="@{classpathref}"/>
                <cd-elements />
            </java>
        </sequential>
    </macrodef>

    <macrodef name="jarwrapper" description="Run JarWrapper">
        <attribute name="classpathref" default="jarwrapper.classpath" />
        <element name="jw-elements" implicit="yes" />
        <sequential>
            <java classname="com.sun.jini.tool.JarWrapper"
                    fork="true" failonerror="true">
                <classpath refid="@{classpathref}"/>
                <jw-elements />
            </java>
        </sequential>
    </macrodef>

    <macrodef name="truststore">
        <attribute name="target" />
        <attribute name="dir" default="trust" />
        <sequential>
            <exec executable="keytool" failonerror="true">
                <arg value="-import"/>
                <arg value="-alias" />
                <arg value="@{target}" />
                <arg value="-keystore" />
                <arg value="@{dir}/truststore" />
                <arg value="-keypass" />
                <arg value="trustpw" />
                <arg value="-storepass"/>
                <arg value="trustpw" />
                <arg value="-noprompt"/>
                <arg value="-file"/>
                <arg value="@{dir}/@{target}.cert" />
            </exec>
        </sequential>
    </macrodef>

    <macrodef name="keystore">
        <attribute name="target" />
        <attribute name="dname" />
        <attribute name="dir" default="trust" />
        <sequential>
            <genkey keypass="@{target}pw" keystore="@{dir}/@{target}.keystore"
                validity="1800" alias="@{target}" storepass="@{target}pw"
                dname="CN=@{dname}" />
            <exec executable="keytool" failonerror="true">
                <arg value="-export"/>
                <arg value="-alias" />
                <arg value="@{target}" />
                <arg value="-keystore" />
                <arg value="@{dir}/@{target}.keystore" />
                <arg value="-keypass" />
                <arg value="@{target}" />
                <arg value="-dname"/>
                <arg value="@{dname}" />
                <arg value="-storepass"/>
                <arg value="@{target}pw" />
                <arg value="-file"/>
                <arg value="@{dir}/@{target}.cert" />
            </exec>
        </sequential>
    </macrodef>

    <target name="diagnostics" description="Run Ant Diagnostics">
        <diagnostics/>
    </target>

</project>
