I think we should standardize the OpenSymphony build process. Here is my
first cut at it, please comment:

- attached is a build script for OSCore, but as you can see, it's very
generic. We should use this as a base and not add much more to it, mostly
instructions on how to package files like ejb-jar.xml in to the jar itself.

-the directory structure of CVS would look like:

project/
project/docs
project/lib
project/lib/build
project/lib/build/jalopy
project/lib/core
project/lib/optional
project/src/etc
project/src/java
project/src/test
project/src/example [if needed]

There would be build.bat and build.sh scripts to build the project, meaning
CVS is self-contained (no ant install needed). So that means that ant and
all the optional tasks would be in lib/build.

- distribution structure:

project.zip/
project.zip/project.jar
project.zip/docs/
project.zip/docs/api
project.zip/docs/clover
project.zip/docs/junit
project.zip/docs/lib
project.zip/docs/src

- if you see in the script, there would be three extra tasks built in to the
build script:
 * jalopy (code formatting)
 * junit (unit tests)
 * clover (test coverage reports)

- Documentation is assumed to be HTML right now, but pending Ken's final
thoughts, this would change. Also, the junit and clover reports could be run
through XSLs as well.
<project default="jar" basedir=".">
    <path id="cp">
        <fileset dir="lib">
            <include name="**/*.jar" />
        </fileset>
    </path>

    <path id="clover.classpath">
        <pathelement path="lib/build/clover.jar"/>
        <pathelement path="lib/build/velocity.jar"/>
    </path>

    <taskdef name="jalopy" classname="de.hunsicker.jalopy.plugin.ant.AntPlugin"/>

    <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>

    <target name="init">
        <property file="build.properties"/>

        <property name="lib" value="lib"/>
        <property name="lib.core" value="${lib}/core"/>
        <property name="lib.build" value="${lib}/build"/>
        <property name="lib.optional" value="${lib}/optional"/>

        <property name="src" value="src"/>
        <property name="src.java" value="${src}/java"/>
        <property name="src.test" value="${src}/test"/>
        <property name="src.etc" value="${src}/etc"/>

        <property name="build" value="build"/>
        <property name="build.test" value="${build}/test"/>
        <property name="build.java" value="${build}/java"/>

        <property name="dist" value="dist"/>

        <property name="docs" value="docs"/>

        <property name="clover.initstring" location="testcoverage.db"/>

        <property name="packages" value="com.opensymphony.*" />
    </target>

    <target name="clean" depends="init">
        <delete dir="${tmp}" />
        <delete dir="${build}" />
        <delete dir="${dist}" />
        <delete>
            <fileset dir="." includes="testcoverage.db*"/>
        </delete>
    </target>

    <target name="java" depends="init">
        <mkdir dir="${build.java}"/>
        <javac srcdir="${src.java}" destdir="${build.java}" classpathref="cp" debug="on"/>
    </target>

    <target name="test" depends="init">
        <mkdir dir="${build.test}"/>
        <javac srcdir="${src.java}" destdir="${build.test}" classpathref="cp" debug="on" compiler="org.apache.tools.ant.taskdefs.CloverCompilerAdapter"/>
        <javac srcdir="${src.test}" destdir="${build.test}" classpathref="cp" debug="on"/>

        <mkdir dir="${dist}/docs/junit"/>
        <junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">
            <classpath>
                <pathelement location="${build.test}"/>
                <path refid="cp"/>
            </classpath>

            <formatter type="xml"/>

            <batchtest todir="${dist}/docs/junit">
                  <fileset dir="${src.test}">
                      <include name="**/*Test.java"/>
                  </fileset>
            </batchtest>
        </junit>
    </target>

    <target name="format" depends="java">
        <jalopy fileformat="unix"
                convention="src/etc/jalopy.xml"
                history="file"
                historymethod="adler32"
                loglevel="info"
                threads="2"
                classpathref="cp">
            <fileset dir="${src.java}">
                <include name="**/*.java" />
            </fileset>
            <fileset dir="${src.test}">
                <include name="**/*.java" />
            </fileset>
        </jalopy>
    </target>

    <target name="jar" depends="format">
        <mkdir dir="${dist}"/>
        <jar basedir="${build.java}" jarfile="${dist}/${name}-${version}.jar" />
    </target>

    <target name="javadocs" depends="init">
        <mkdir dir="${dist}/docs/api" />
        <javadoc sourcepath="${src.java}"
            destdir="${docs}/api"
            packagenames="${packages}"
            classpathref="cp"
            author="true"
            version="true"
            windowTitle="${name} ${version} API"
            doctitle="${name}"
            footer="See &lt;a href=&quot;http://www.opensymphony.com&quot;&gt;www.opensymphony.com&lt;/a&gt; for more information."
            use="true"
            verbose="false" />
        <copy overwrite="yes" file="${docs}/main.css" tofile="${docs}/api/stylesheet.css"/>
    </target>

    <target name="clover.report" depends="test">
        <java classname="com.cortexeb.tools.clover.reporters.html.HtmlReporter" fork="true">
            <arg line="--outputdir ${dist}/docs/clover --showSrc --initstring ${clover.initstring} --title '${name}'"/>
            <classpath refid="cp"/>
        </java>
    </target>

    <target name="junit.report" depends="test">
        <junitreport todir="${dist}/docs/junit">
            <fileset dir="${dist}/docs/junit">
                <include name="TEST-*.xml"/>
            </fileset>
            <report format="frames" todir="${dist}/docs/junit"/>
        </junitreport>
    </target>

    <target name="docs" depends="javadocs, clover.report, junit.report">
        <copy todir="${dist}/docs">
            <fileset dir="${docs}"/>
        </copy>
    </target>

    <target name="dist" depends="jar, docs">
        <mkdir dir="${dist}/zip"/>
        <mkdir dir="${dist}/zip/docs"/>
        <mkdir dir="${dist}/zip/src"/>
        <mkdir dir="${dist}/zip/lib"/>

        <copy todir="${dist}/zip/docs">
            <fileset dir="${dist}/docs"/>
        </copy>

        <copy todir="${dist}/zip/src">
            <fileset dir="src"/>
        </copy>

        <copy todir="${dist}/zip/lib">
            <fileset dir="${lib.core}"/>
        </copy>

        <copy file="${dist}/${name}-${version}.jar" todir="${dist}/zip"/>

        <zip zipfile="${dist}/${name}-${version}.zip" basedir="${dist}/zip"/>

        <delete dir="${dist}/zip"/>
    </target>
</project>

Reply via email to