Source

jummp / build.xml

<project name="jummp" default="test-app">
    <property environment="env"/>
    <property name="grailsWorkdir" value="${basedir}/grailswork"/>
    <import file="${env.GRAILS_HOME}/src/grails/grails-macros.xml" />
    <!-- Sets the gant environment -->
    <taskdef name="gant" classname="org.codehaus.gant.ant.Gant">
        <classpath>
            <pathelement location="${env.GRAILS_HOME}/lib/org.codehaus.gant/gant_groovy1.8/jars/gant_groovy1.8-1.9.6.jar"/>
            <pathelement location="${env.GRAILS_HOME}/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-1.8.6.jar"/>
        </classpath>
    </taskdef>

    <!--Task Definition to invoke Groovy compile-->
    <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
        <classpath>
            <pathelement location="${env.GRAILS_HOME}/lib/org.codehaus.gant/gant_groovy1.8/jars/gant_groovy1.8-1.9.6.jar"/>
            <pathelement location="${env.GRAILS_HOME}/lib/org.codehaus.groovy/groovy-all/jars/groovy-all-1.8.6.jar"/>
            <pathelement location="${env.GRAILS_HOME}/dist/grails-web-2.0.1.jar"/>
            <pathelement location="${env.GRAILS_HOME}/dist/grails-plugin-converters-2.0.1.jar"/>
        </classpath>
    </taskdef>

<!-- Target to execute the testing of one plugin. Used by antcall from test-plugins -->
    <target name="test-plugin">
        <echo message="Running tests for Plugin ${plugin}"/>
        <grails command="test-app" args="-xml ${coverage}" cwd="${basedir}/jummp-plugins/jummp-plugin-${plugin}">
            <sysprops>
                <sysproperty key="grails.work.dir" value="${grailsWorkdir}"/>
            </sysprops>
        </grails>
        <copy todir="${basedir}/target/test-reports">
            <fileset dir="${basedir}/jummp-plugins/jummp-plugin-${plugin}/target/test-reports">
                <include name="TEST-*.xml"/>
            </fileset>
        </copy>
    </target>

<!-- Runs test-app in all plugins (except JMS) -->
    <target name="test-plugins">
        <antcall target="test-plugin">
            <param name="plugin" value="configuration"/>
        </antcall>
        <antcall target="test-plugin">
            <param name="plugin" value="core-api"/>
        </antcall>
        <antcall target="test-plugin">
            <param name="plugin" value="git"/>
        </antcall>
        <antcall target="test-plugin">
            <param name="plugin" value="sbml"/>
        </antcall>
        <antcall target="test-plugin">
            <param name="plugin" value="security"/>
        </antcall>
        <antcall target="test-plugin">
            <param name="plugin" value="subversion"/>
        </antcall>
<!-- Do not test jms plugin as it requires an instance of jummp running   -->
    </target>

<!-- Runs test-app in the core application -->
    <target name="test-core">
        <grails command="test-app" args="-xml ${coverage}" cwd="${basedir}">
            <sysprops>
                <sysproperty key="grails.work.dir" value="${grailsWorkdir}"/>
            </sysprops>
        </grails>
    </target>

<!-- Generates the test reports for all tests -->
    <target name="generate-report">
        <junitreport todir="${basedir}/target/test-reports">
            <fileset dir="${basedir}/target/test-reports">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${basedir}/target/test-reports/html"/>
        </junitreport>
    </target>

<!-- Sets the required properties for normal test runs -->
    <target name="prepare-test-app">
        <property name="coverage" value=""/>
    </target>

<!-- Runs all tests (without code coverage)  -->
    <target name="test-app" depends="prepare-test-app, test-core, test-plugins, generate-report">
    </target>

<!-- Sets the required properties for code coverage generation -->
    <target name="prepare-coverage">
        <property name="coverage" value="-coverage"/>
    </target>

<!-- Runs all tests with code coverage -->
    <target name="coverage" depends="prepare-coverage, test-core, test-plugins, generate-report">
        <grails command="coverage-report" cwd="${basedir}"/>
    </target>

    <target name="packagePlugin">
        <grails command="clean" cwd="${pluginBaseDir}/jummp-plugins/jummp-plugin-${plugin}"/>
        <grails command="jummp-plugin" cwd="${pluginBaseDir}/jummp-plugins/jummp-plugin-${plugin}"/>
    </target>

    <target name="packagePlugins">
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="security"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="core-api"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="sbml"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="simple-logging"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="configuration"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="git"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="subversion"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="remote"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="dbus"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="bives"/>
        </antcall>
        <antcall target="packagePlugin">
            <param name="pluginBaseDir" value="${basedir}"/>
            <param name="plugin" value="web-application"/>
        </antcall>
    </target>

    <!-- Copies the sources to a build directory excluding not needed files and directories -->
    <target name="copy">
        <property name="builddir" value="${basedir}/build"/>
        <delete dir="${builddir}"/>
        <mkdir dir="${builddir}"/>
        <copy todir="${builddir}">
            <fileset dir="${basedir}">
                <exclude name="**/out/"/>
                <exclude name="**/target/"/>
                <exclude name="**/test/"/>
                <exclude name="**/doc/"/>
                <exclude name="**/build/"/>
                <exclude name="**/activemq-data/"/>
                <exclude name="jummp-plugins/**/grails-app/views/error.gsp"/>
                <exclude name="jummp-plugins/**/grails-app/views/layouts/"/>
                <exclude name="jummp-plugins/**/web-app/"/>
                <exclude name="**/*.iml"/>
                <exclude name="**/cobertura.ser"/>
                <exclude name="**/*.orig"/>
                <exclude name="**/*~"/>
            </fileset>
        </copy>
    </target>

    <!-- Performs the actual removal of grails plugins not needed in productive environment. -->
    <target name="perform-remove-grails-plugins">
        <propertyfile file="${propertyfile}">
            <entry key="plugins.code-coverage" operation="del"/>
            <entry key="plugins.codenarc" operation="del"/>
        </propertyfile>
    </target>

    <!-- Removes grails plugins not needed in productive environment from core app and all plugins-->
    <target name="remove-grails-plugins" depends="copy">
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-configuration/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-core-api/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-git/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-jms/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-sbml/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-security/application.properties"/>
        </antcall>
        <antcall target="perform-remove-grails-plugins">
            <param name="propertyfile" value="${builddir}/jummp-plugins/jummp-plugin-subversion/application.properties"/>
        </antcall>
    </target>

<!--  Interactively ask for each plugin not necessarily required by JUMMP core to be included in the build    -->
    <target name="ask-for-plugins" depends="remove-grails-plugins">
        <input message="Include Plugin Subversion, required to store model files in a Subversion repository?" validargs="y,n" addproperty="plugin.svn" defaultvalue="y"/>
        <input message="Include Plugin Git, required to store model files in a git repository?" validargs="y,n" addproperty="plugin.git" defaultvalue="y"/>
        <input message="Include Plugin Configuration, required to configure the core application?" validargs="y,n" addproperty="plugin.configuration" defaultvalue="y"/>
        <input message="Include Plugin SBML, required to handle SBML files?" validargs="y,n" addproperty="plugin.sbml" defaultvalue="y"/>
        <input message="Include Plugin JMS, required to communicate with a Web Application through JMS?" validargs="y,n" addproperty="plugin.jms" defaultvalue="y"/>
        <input message="Include Plugin D-Dbus, required to export the Application Interface to D-Bus?" validargs="y,n" addproperty="plugin.dbus" defaultvalue="y"/>
        <condition property="plugin.persist.svn">
            <equals arg1="${plugin.svn}" arg2="y"/>
        </condition>
        <condition property="plugin.persist.git">
            <equals arg1="${plugin.git}" arg2="y"/>
        </condition>
        <condition property="plugin.persist.configuration">
            <equals arg1="${plugin.configuration}" arg2="y"/>
        </condition>
        <condition property="plugin.persist.sbml">
            <equals arg1="${plugin.sbml}" arg2="y"/>
        </condition>
        <condition property="plugin.persist.jms">
            <equals arg1="${plugin.jms}" arg2="y"/>
        </condition>
        <condition property="plugin.persist.dbus">
            <equals arg1="${plugin.dbus}" arg2="y"/>
        </condition>
        <property name="plugin.persist.svn" value="false"/>
        <property name="plugin.persist.git" value="false"/>
        <property name="plugin.persist.configuration" value="false"/>
        <property name="plugin.persist.sbml" value="false"/>
        <property name="plugin.persist.jms" value="false"/>
        <property name="plugin.persist.dbus" value="false"/>
        <propertyfile file="${builddir}/jummpPlugins.properties">
            <entry key="subversion" value="${plugin.persist.svn}"/>
            <entry key="git" value="${plugin.persist.git}"/>
            <entry key="configuration" value="${plugin.persist.configuration}"/>
            <entry key="sbml" value="${plugin.persist.sbml}"/>
            <entry key="jms" value="${plugin.persist.jms}"/>
            <entry key="dbus" value="${plugin.persist.dbus}"/>
        </propertyfile>
        <gant file="${builddir}/scripts/Build.groovy" target="deleteJummpPlugins">
            <definition name="builddir" value="${builddir}"/>
        </gant>
    </target>

<!-- Performs the actual building of war file using grails war. Cleans before building -->
    <target name="build-war" depends="remove-grails-plugins">
        <grails command="clean" cwd="${builddir}">
            <sysprops>
                <sysproperty key="grails.work.dir" value="${grailsWorkdir}"/>
            </sysprops>
        </grails>
        <grails command="war ${builddir}/target/jummp.war" cwd="${builddir}">
            <sysprops>
                <sysproperty key="grails.work.dir" value="${grailsWorkdir}"/>
            </sysprops>
        </grails>
    </target>
    <target name="build-webapplication-war" depends="remove-grails-plugins">
        <grails command="clean" cwd="${builddir}/jummp-web-application">
            <sysprops>
                <sysproperty key="grails.work.dir" value="${grailsWorkdir}"/>
            </sysprops>
        </grails>
        <grails command="war ${builddir}/target/jummp-web-application.war" cwd="${builddir}/jummp-web-application">
            <sysprops>
                <sysproperty key="grails.work.dir" value="${grailsWorkdir}"/>
            </sysprops>
        </grails>
    </target>

<!-- Build war with all plugins -->
    <target name="war" depends="build-war,build-webapplication-war">
    </target>

<!-- Build war with asking for plugins to include     -->
    <target name="interactive-war" depends="ask-for-plugins, build-war,build-webapplication-war">
    </target>
</project>