Project: [fleXive]
Code Location: http://svn.flexive.org/repository/flexive/trunk/trunk
Browse
/
Download File
build.macros.xml
<?xml version="1.0" encoding="UTF-8"?>
<project>

    <macrodef name="javac-call" description="Invokes the Java compiler for flexive sources. The classpath can be set with nested classpath elements.">
		<attribute name="srcdir"/>
		<attribute name="destdir"/>
		<attribute name="excludes" default="NONE"/>
		<attribute name="includes" default="**/*.java"/>
		<element name="args" optional="true" implicit="true"/>
		<sequential>
			<mkdir dir="@{destdir}"/>
			<javac  srcdir="@{srcdir}"
                    destdir="@{destdir}"
                    debug="${compiler.debug}"
                    deprecation="${compiler.deprecation}"
                    optimize="${compiler.optimize}"
                    includes="@{includes}"
                    excludes="@{excludes}"
                    source="${compiler.source}"
                    target="${compiler.target}"
                    includeantruntime="false"
                    fork="${compiler.fork}">
				<args/>
			</javac>
		</sequential>
	</macrodef>


    <!-- ==================== Some common macros ==================== -->
    <macrodef name="replaceBuildProperties" description="Replaces build properties of the current build (subversion number, build user, timestamp) in a text file.">
        <attribute name="file" description="The text file to be processed."/>
        <attribute name="buildnumber" description="The build number to be inserted"/>
        <attribute name="buildtime" description="The build time to be inserted"/>
        <sequential>
            <replace file="@{file}">
                <replacefilter token="@@@build.number@@@" value="@{buildnumber}"/>
                <replacefilter token="@@@build.user@@@" value="${user.name}"/>
                <replacefilter token="@@@build.date@@@" value="@{buildtime}"/>
            </replace>
        </sequential>
    </macrodef>

    <macrodef name="buildScriptIndex">
        <attribute name="dir" description="The scripts base directory. Should include subfolders runonce, startup and library."/>
        <sequential>
            <scriptIndexBuilder indexFile="@{dir}/runonce/scriptindex.flexive" scriptDir="@{dir}/runonce"/>
            <scriptIndexBuilder indexFile="@{dir}/library/scriptindex.flexive" scriptDir="@{dir}/library"/>
            <scriptIndexBuilder indexFile="@{dir}/startup/scriptindex.flexive" scriptDir="@{dir}/startup"/>
        </sequential>
    </macrodef>

    <!-- ==================== UI plugin/component macros ==================== -->

    <macrodef name="buildPluginJar" description="Package a plugin JAR file">
        <attribute name="name"/>
        <attribute name="srcdir"/>
        <attribute name="builddir"/>
        <attribute name="jarfile"/>
        <element name="jar-elements" optional="true"/>
        <sequential>
            <makeMessages srcdir="@{srcdir}/resources/messages" dest="@{builddir}/PluginMessages"/>
            <copy todir="@{builddir}/component-config/@{name}">
                <fileset dir="@{srcdir}/resources" includes="META-INF/**,templates/**/*,flexive-application.properties" excludes="META-INF/resources/**"/>
                <fileset dir="@{builddir}" includes="*.properties"/>
                <filterset >
                    <filter token="FLEXIVE_VERSION" value="${flexive.version}"/>
                </filterset>
            </copy>
            <mkdir dir="@{srcdir}/resources/scripts"/>  <!-- ensure script exists for zipfileset -->
            <jar jarfile="@{jarfile}">
                <fileset dir="@{builddir}/component-config/@{name}" includes="**/*"/>
                <fileset dir="@{builddir}/classes"/>
                <fileset dir="@{srcdir}/resources/weblets" includes="**/*"/>
                <fileset dir="@{srcdir}/web" includes="**/*"/>
                <zipfileset dir="@{srcdir}/resources/META-INF/resources" prefix="META-INF/resources" includes="**/*"/>

                <zipfileset dir="@{srcdir}/resources/scripts" prefix="scripts" includes="**/*"/>
                <jar-elements/>
            </jar>
        </sequential>
    </macrodef>

    <macrodef name="compilePlugin" description="Compile the plugin sources">
        <attribute name="srcdir"/>
        <attribute name="builddir"/>
        <attribute name="classpathref"/>
        <sequential>
            <mkdir dir="@{builddir}/classes"/>
            <javac-call
                srcdir="@{srcdir}/src/java"
                destdir="@{builddir}/classes">
                <classpath refid="@{classpathref}"/>
            </javac-call>
        </sequential>
    </macrodef>

    <macrodef name="buildStorage" description="Compile storage sources and package them">
        <attribute name="vendor" description="Name of the vendor"/>
        <attribute name="srcdir" description="Base directory of the storage"/>
        <attribute name="builddir" description="Directory to generate the artifacts at"/>
        <attribute name="classpathref" description="Reference to the [fleXive] classpath"/>
        <attribute name="jarfile" description="Resulting jar file"/>
        <sequential>
            <mkdir dir="@{builddir}/classes"/>
            <javac-call
                srcdir="@{srcdir}/java"
                destdir="@{builddir}/classes">
                <classpath refid="@{classpathref}"/>
            </javac-call>
            <scriptIndexBuilder indexFile="@{builddir}/resources/patch-@{vendor}/resourceindex.flexive"
                            scriptDir="@{srcdir}/resources/patch"
                            copyFiles="true"/>
            <copy todir="@{builddir}/resources">
                <fileset dir="@{srcdir}/resources" includes="**/*" excludes="patch, patch/**/*"/>
            </copy>
            <scriptIndexBuilder indexFile="@{builddir}/resources/storageindex-@{vendor}.flexive"
                            scriptDir="@{builddir}/resources"
                            recursive="true" copyFiles="false"/>
            <jar jarfile="@{jarfile}">
                <fileset dir="@{builddir}/classes"/>
                <zipfileset dir="@{srcdir}/resources" includes="**/*properties"/>
                <zipfileset dir="@{builddir}/resources" prefix="resources" includes="**/*"/>
            </jar>
        </sequential>
    </macrodef>

    <!-- ========================= Deployment ========================== -->
    <macrodef name="deployToJetty" description="Deploy an EAR file to a Jetty installation">
        <attribute name="earfile"/>
        <attribute name="jettydir"/>
        <sequential >
            <!-- Clear EJB deployment directory -->
            <delete  dir="@{jettydir}/lib/ext/flexive"/>
            
            <!-- Unzip EJBs and libraries to lib/ext -->
            <unzip dest="@{jettydir}/lib/ext/flexive" overwrite="true" src="@{earfile}">
                <patternset>
                    <include name="lib/**"/>
                    <include name="*-ejb.jar"/>
                    <include name="lib/*-ejb.jar"/>
                </patternset>
            </unzip>

            <!-- Install WAR applications to webapps -->
            <unzip dest="@{jettydir}/webapps" overwrite="true" src="@{earfile}">
                <patternset>
                    <include name="*.war"/>
                </patternset>
            </unzip>

            <!-- Install JSF runtime -->
            <copy todir="@{jettydir}/lib/ext/flexive-environment">
                <fileset dir="${dist.basedir}/extlib" includes="jsf-api.jar,jsf-impl.jar,el-api.jar,el-ri.jar"/>
            </copy>
            
        </sequential>
    </macrodef>

    <macrodef name="runJetty" description="Launch Jetty with OpenEJB">
        <attribute name="jettydir"/>
        <sequential >
            <java dir="@{jettydir}" fork="true" jar="@{jettydir}/start.jar">
                <!-- Don't force -server because default Java installations may not have the server VM -->
                <!--<jvmarg value="-server"/>-->
                <jvmarg value="-Xmx200m"/>
                <jvmarg value="-Dopenejb.configuration=openejb.conf.xml"/>
            </java>
        </sequential>
    </macrodef>

    <macrodef name="createFlatStorage" description="Create a new flat storage table">
        <attribute name="jar" description="Path to flatStorageCreator.jar"/>
        <attribute name="lib" description="Path to the folder containing the shared flexive libraries (flexive-shared.jar)"/>
        <attribute name="extlib" description="Path to external library directory containing the dependencies for FlatStorageCreator.java"/>
        <attribute name="connectionUrl" description="The database connection URL"/>
        <attribute name="schema" description="Database schema (not applicable to all DB vendors)"/>
        <attribute name="tableName" description="Name of the table to be created"/>
        <attribute name="overwrite" default="false" description="If an existing table should be overwritten (true or false)"/>
        <attribute name="user" description="The database user"/>
        <attribute name="password" description="The database password"/>
        <attribute name="nstring" default="20" description="Number of STRING columns"/>
        <attribute name="ntext" default="10" description="Number of TEXT columns"/>
        <attribute name="nbigint" default="10" description="Number of BIGINT columns"/>
        <attribute name="ndouble" default="10" description="Number of DOUBLE columns"/>
        <attribute name="nselect" default="10" description="Number of SELECT columns"/>
        <sequential >
            <path id="createFlatStorage.classpath">
                <fileset file="@{jar}"/>
                <fileset dir="@{extlib}" includes="*.jar"/>
                <fileset dir="@{lib}" includes="*.jar"/>
            </path>
            <java fork="true" classpathref="createFlatStorage.classpath" classname="com.flexive.tools.FlatStorageCreator">
                <arg line="-u @{user}"/>
                <arg line="--password=@{password}"/>
                <arg value="-o"/>
                <arg line="-nstring @{nstring}"/>
                <arg line="-ntext @{ntext}"/>
                <arg line="-nbigint @{nbigint}"/>
                <arg line="-ndouble @{ndouble}"/>
                <arg line="-nselect @{nselect}"/>
                <arg value="@{connectionUrl}"/>
                <arg value="@{schema}"/>
                <arg value="@{tableName}"/>
                <jvmarg value="-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger"/>
                <jvmarg value="-Dlog4j.configuration=flatStorageLog4j.xml"/>
            </java>
        </sequential>
    </macrodef>
</project>