build.xml 17.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
<?xml version="1.0"?>
<project name="seamTestInAction" default="deploy" basedir=".">

    <!-- Give user a chance to override without editing this file or typing -D -->
    <property file="${basedir}/build.properties" />

    <property name="profile" value="dev" />
    <property file="build-${profile}.properties" />

    <!-- set global properties for this build -->
    <property name="project.name" value="seamTestInAction"/>
    <property name="dist.dir" value="dist" />
    <property name="src.model.dir" value="src/main" />
    <property name="src.action.dir" value="src/hot" />
    <property name="src.test.dir" value="src/test" />
    <property name="lib.dir" value="lib" />
    <property name="endorsed.dir" value="${lib.dir}/endorsed" />
    <property name="war.dir" value="exploded-archives/${project.name}.war" />
    <property name="classes.model.dir" value="${war.dir}/WEB-INF/classes" />
    <property name="action.dir" value="WEB-INF/classes" />
    <property name="classes.action.dir" value="${war.dir}/${action.dir}" />
    <property name="test.dir" value="test-build" />
    <property name="bootstrap.dir" value="${basedir}/bootstrap" />
    <property name="jboss.domain" value="default"/>
    <property name="deploy.dir" value="${jboss.home}/server/${jboss.domain}/deploy" />
    <property name="war.deploy.dir" value="${deploy.dir}/${project.name}.war" />
    <property name="testng.jar" value="${basedir}/lib/testng.jar" />
    <property name="javac.debug" value="true" />
    <property name="javac.deprecation" value="false" />
    <property name="debug" value="false" />

    <!--Properties for validating configuration files -->
    <property name="validate.resources.dir" value="${basedir}/exploded-archives"/>
    <property name="schema.dir" value="${basedir}/exploded-archives/schemas"/>
    <property name="src.schema.dir" value="${schema.dir}/org/jboss/seam"/>
    <property name="schema.version" value="2.1"/>
    
    <fileset id="lib" dir="${lib.dir}">
        <include name="*.jar" />
    </fileset>
    
    <path id="build.classpath">
        <fileset refid="lib" />
    </path>

    <target name="init" description="Initialize the build">

        <taskdef name="groovyc"
            classname ="org.codehaus.groovy.ant.Groovyc"
            classpathref="build.classpath"/> <!-- really only the groovy jar is necessary -->

        <mkdir dir="${classes.model.dir}" />
        <mkdir dir="${classes.action.dir}" />
        <mkdir dir="${dist.dir}" />
        <!-- if a .groovy file is in model or action, set groovy.present -->
        <available property="groovy.present" value="true" file="" searchparents="true">
            <filepath>
                <fileset dir="${src.action.dir}">
                    <include name="**/*.groovy"/>
                </fileset>
                <fileset dir="${src.model.dir}">
                  <include name="**/*.groovy"/>
                </fileset>
            </filepath>
        </available>
        <condition property="groovy.test.present" value="true">
            <or>
                <isset property="groovy.present"/>
                <available file="" searchparents="true">
                    <filepath>
                        <fileset dir="${src.test.dir}">
                            <include name="**/*.groovy"/>
                        </fileset>
                    </filepath>
                </available>
            </or>
        </condition>
        <condition property="groovy.dynamic" value="true">
            <and>
                <isset property="groovy.present"/>
                <istrue value="${debug}"/>
            </and>
        </condition>
        <condition property="groovy.static" value="true">
            <and>
                <isset property="groovy.present"/>
                <isfalse value="${debug}"/>
            </and>
        </condition>
    </target>
    
    <target name="compilemodel" depends="init,groovy.compilemodel"
            description="Compile the Java source code"
            unless="eclipse.running">
        <javac classpathref="build.classpath" 
               destdir="${classes.model.dir}" 
               debug="${javac.debug}" 
               deprecation="${javac.deprecation}" 
               nowarn="on">
            <src path="${src.model.dir}" />
        </javac>
    </target>

    <target name="groovy.compilemodel" if="groovy.present">
        <!-- model is always compiled -->
        <groovyc classpathref="build.classpath"
               destdir="${classes.model.dir}"
               srcdir="${src.model.dir}" >
        </groovyc>
    </target>
    
    <target name="compileactions" depends="init,groovy.compileactions,groovy.copyactions"
            description="Compile the Java source code"
            unless="eclipse.running">
        <javac classpathref="build.classpath" 
               destdir="${classes.action.dir}"
               debug="${javac.debug}" 
               deprecation="${javac.deprecation}" 
               nowarn="on">
            <classpath path="${classes.model.dir}"/>
            <src path="${src.action.dir}" />
        </javac>
    </target>

    <target name="groovy.compileactions" if="groovy.static">
        <path id="groovy.action.classpath">
            <path refid="build.classpath"/>
            <dirset dir="${classes.model.dir}"/>
        </path>
        <groovyc classpathref="groovy.action.classpath"
               destdir="${classes.action.dir}"
               srcdir="${src.action.dir}" >
        </groovyc>
    </target>

    <target name="groovy.copyactions" if="groovy.dynamic">
        <!-- copy the action groovy files into action if not compiled -->
        <copy todir="${classes.action.dir}">
            <fileset dir="${src.action.dir}">
                <include name="**/*.groovy"/>
            </fileset>
        </copy>
    </target>
    
    <target name="copyclasses" depends="init,groovy.copyactions"
            description="Copy the classes that were compiled by eclipse"
            if="eclipse.running">
        <!-- TODO check how the groovy eclipse plugin works, does it compile? -->
        <copy todir="${classes.model.dir}">
            <fileset dir="classes/main">
                <include name="**/*.class"/>
            </fileset>
        </copy>
        <copy todir="${classes.action.dir}">
            <fileset dir="classes/hot">
                <include name="**/*.class"/>
            </fileset>
        </copy>
    </target>

    <target name="compile" depends="compilemodel,compileactions,copyclasses"
            description="Compile the various source paths"/>
    
    <target name="war" depends="compile" 
            description="Build the WAR structure in a staging directory">
        
        <copy todir="${war.dir}/WEB-INF/classes">
            <fileset dir="${basedir}/resources">
                <include name="seam.properties" />
                <include name="*.drl" />
            </fileset>
            <fileset dir="${src.model.dir}">
                <include name="**/*.component.xml" />
            </fileset>
        </copy>

        <copy tofile="${war.dir}/WEB-INF/classes/components.properties" 
              file="${basedir}/resources/components-${profile}.properties"
              overwrite="true"/>

        <copy tofile="${war.dir}/WEB-INF/classes/META-INF/persistence.xml" 
              file="${basedir}/resources/META-INF/persistence-${profile}-war.xml"
              overwrite="true"/>
        
        <copy tofile="${war.dir}/WEB-INF/classes/import.sql" 
              file="${basedir}/resources/import-${profile}.sql"
              overwrite="true"/>
        
        <copy todir="${war.dir}">
            <fileset dir="${basedir}/view" />
        </copy>
        
        <copy todir="${war.dir}/WEB-INF">
            <fileset dir="${basedir}/resources/WEB-INF">
                <include name="*.*"/>
                <include name="classes/**/*.*"/>
                <exclude name="classes/**/*.class"/>
                <exclude name="classes/**/*.groovy"/>
            </fileset>
        </copy>
        
        <copy todir="${war.dir}/WEB-INF">
            <fileset dir="${basedir}/resources/WEB-INF">
                <include name="lib/*.*"/>
                <include name="classes/**/*.class"/>
            </fileset>
        </copy>
        
        <copy todir="${war.dir}/WEB-INF/lib">
            <fileset dir="${lib.dir}">
                <includesfile name="deployed-jars.list"/>
                <exclude name="jboss-seam-gen.jar"/>
                <include name="groovy-*.jar" if="groovy.present"/>
            </fileset>
        </copy>

        <copy todir="${war.dir}/WEB-INF/classes">
            <fileset dir="${basedir}/resources"> 
                <include name="**/*.xcss"/>
            </fileset>
            <!-- move XCSS into classpath for now
                 loading from web context only works in JBoss AS 4 -->
            <fileset dir="${basedir}/view"> 
                <include name="**/*.xcss"/>
            </fileset>
        </copy>
        
        <copy todir="${war.dir}/WEB-INF/classes">
            <fileset dir="${basedir}/resources"> 
                <include name="messages*.properties"/>
                <include name="*.skin.properties"/>
                <include name="*_theme.properties"/>
            </fileset>
        </copy>
        
        <copy todir="${war.dir}/WEB-INF/classes">
            <fileset dir="${basedir}/resources">
                <include name="*jpdl.xml" />
                <include name="*hibernate.cfg.xml" />
                <include name="jbpm.cfg.xml" />
                <include name="META-INF/orm.xml" />
            </fileset>
        </copy>
        
    </target>

    <target name="stage" depends="war"/>
    
    <target name="archive" depends="stage" 
            description="Package the WAR archive">
        <jar jarfile="${dist.dir}/${project.name}.war" basedir="${war.dir}"/>
    </target>
    
    <target name="datasource">
        <fail unless="jboss.home">jboss.home not set</fail>
        <copy file="${basedir}/resources/${project.name}-${profile}-ds.xml"
            tofile="${deploy.dir}/${project.name}-ds.xml"
            overwrite="true"/>
    </target>
    
    <target name="explode" depends="stage,datasource" 
            description="Deploy the exploded archive">
        <fail unless="jboss.home">jboss.home not set</fail>
        
        <mkdir dir="${war.deploy.dir}"/>
        <copy todir="${war.deploy.dir}">
            <fileset dir="${war.dir}"/>
        </copy>
    </target>
    
    <target name="unexplode" description="Undeploy the exploded archive">
        <delete failonerror="no">
            <fileset dir="${war.deploy.dir}">
                <exclude name="**/*.jar"/>
            </fileset>
        </delete>
        <delete file="${deploy.dir}/${project.name}-ds.xml" failonerror="no"/>
        <delete dir="${war.deploy.dir}" failonerror="no"/>
    </target>

    <target name="reexplode" depends="unexplode,clean,explode"
        description="Undeploy the exploded archive, clean, then deploy the exploded archive"/>
    
    <target name="check-deployed" description="Check to see if packaged archive is currently deployed">
        <fail unless="jboss.home">jboss.home not set</fail>
        <condition property="archive.deployed" value="true">
            <available file="${war.deploy.dir}" type="file"/>
        </condition>
    </target>

    <target name="restart-exploded" unless="archive.deployed" description="Deploy exploded archive if not deployed as packaged archive">
        <antcall target="explode"/>
        <touch file="${war.deploy.dir}/WEB-INF/web.xml"/>
    </target>

    <target name="restart-deployed" if="archive.deployed" description="Deploy packaged archive if deployed as packaged archive">
        <antcall target="deploy"/>
    </target>
    
    <target name="restart" depends="check-deployed,restart-exploded,restart-deployed" description="Restart the exploded archive"/>
    
    <target name="deploy" depends="archive,datasource" description="Deploy the packaged archive">
        <fail unless="jboss.home">jboss.home not set</fail>
        <copy todir="${deploy.dir}" file="${dist.dir}/${project.name}.war" />
    </target>
    
    <target name="undeploy" description="Undeploy the packaged archive">
        <delete file="${deploy.dir}/${project.name}.war" />
        <delete file="${deploy.dir}/${project.name}-ds.xml" />
    </target>

    <target name="redeploy" depends="undeploy,clean,deploy"
        description="Undeploy the packaged archive, clean, then deploy the packaged archive"/>
    
    <target name="clean" description="Clean out the staging directory">
        <delete dir="${dist.dir}"/>
        <delete dir="${basedir}/exploded-archives"/>
        <delete dir="${basedir}/test-report"/>
        <delete dir="${basedir}/test-output"/>
        <delete failonerror="no" includeemptydirs="true">
            <fileset dir="${test.dir}">
                <exclude name="**/*.class" if="eclipse.running"/>
            </fileset>
        </delete>
    </target>
    
    <target name="compiletest" depends="groovy.compiletest" unless="eclipse.running" description="Compile the Java source code for the tests">
        <mkdir dir="${test.dir}"/>
        <javac classpathref="build.classpath"
               destdir="${test.dir}"
               debug="${javac.debug}"
               deprecation="${javac.deprecation}"
               nowarn="on">
            <src path="${src.action.dir}" />
            <src path="${src.model.dir}" />
            <src path="${src.test.dir}" />
        </javac>
    </target>

    <target name="groovy.compiletest" if="groovy.test.present" description="Compile the Groovy source code for the tests">
        <mkdir dir="${test.dir}"/>
        <groovyc classpathref="build.classpath"
               destdir="${test.dir}">
            <src path="${src.action.dir}"/>
            <src path="${src.model.dir}"/>
            <src path="${src.test.dir}"/>
        </groovyc>
    </target>
    
    <target name="copytestclasses" if="eclipse.running" description="Copy classes compiled by eclipse to the test dir">
        <mkdir dir="${test.dir}"/>
        <copy todir="${test.dir}">
            <fileset dir="classes/main">
                <include name="**/*.class"/>
            </fileset>
        </copy>
        <copy todir="${test.dir}">
            <fileset dir="classes/hot">
                <include name="**/*.class"/>
            </fileset>
        </copy>
        <copy todir="${test.dir}">
            <fileset dir="classes/test">
                <include name="**/*.class"/>
            </fileset>
        </copy>
    </target>
    
    <target name="buildtest" depends="init,compiletest,copytestclasses" description="Build the tests">
        <copy todir="${test.dir}">
            <fileset dir="${basedir}/resources">
                <exclude name="META-INF/persistence*.xml"/>
                <exclude name="import*.sql"/>
                <exclude name="${project.name}-*-ds.xml"/>
                <exclude name="components-*.properties"/>
            </fileset>
            <fileset dir="${basedir}/view"/>
        </copy>
        <copy tofile="${test.dir}/META-INF/persistence.xml" 
              file="${basedir}/resources/META-INF/persistence-test-war.xml"
              overwrite="true"/>
        <copy tofile="${test.dir}/import.sql" 
              file="${basedir}/resources/import-test.sql"
              overwrite="true"/>
        <copy tofile="${test.dir}/components.properties" 
              file="${basedir}/resources/components-test.properties"
              overwrite="true"/>
        <copy todir="${test.dir}" flatten="true">
            <fileset dir="${src.test.dir}">
                <include name="**/*Test.xml" />
            </fileset>
        </copy>
    </target>
    
    <target name="test" depends="buildtest" description="Run the tests">            
        <condition property="incompatible.jdk">
            <and>
                <equals arg1="${ant.java.version}" arg2="1.6"/>
                <not><available classname="javax.xml.bind.JAXB"/></not>
            </and>
        </condition>
        <fail if="incompatible.jdk">You are using an incompatible JDK 6. Please use Sun JDK 6 Update 4 (1.6.0_04) or newer or use Open JDK 6.</fail>
        <taskdef resource="testngtasks" classpath="${testng.jar}" />
        <path id="test.path">
            <path path="${test.dir}" />
            <fileset dir="${lib.dir}/test">
                <include name="*.jar"/>
            </fileset>
            <path path="${bootstrap.dir}" />
            <path refid="build.classpath" />
        </path>
        <testng outputdir="${basedir}/test-report">
            <jvmarg line="-Djava.endorsed.dirs=${endorsed.dir}"/>
            <jvmarg line="-Dsun.lang.ClassLoader.allowArraySyntax=true"/>
            <classpath refid="test.path" />
            <xmlfileset dir="${test.dir}" includes="*Test.xml" />
        </testng>
    </target>

    <target name="javadoc" depends="compile">
        <mkdir dir="${dist.dir}/apidoc" />
        <javadoc classpathref="build.classpath" destdir="${dist.dir}/apidoc" use="true" protected="true" version="true" windowtitle="${project.name} API Documentation" doctitle="${project.name} API Documentation" link="http://java.sun.com/j2se/5.0/docs/api">

            <packageset dir="${src.action.dir}" defaultexcludes="yes">
                <include name="*/**" />
            </packageset>

            <packageset dir="${src.model.dir}" defaultexcludes="yes">
                <include name="*/**" />
            </packageset>

        </javadoc>
    </target>

    <target name="validate" depends="stage" description="Validate the XML configuration files">
        <mkdir dir="${schema.dir}"/>
        <unjar src="${lib.dir}/jboss-seam.jar" dest="${schema.dir}">
            <patternset>
                <include name="org/jboss/seam/*.xsd"/>
                <include name="org/jboss/seam/*.dtd"/>
            </patternset>
        </unjar>
        <ant antfile="validate.xml" target="validateConfiguration"/>
    </target>
    
</project>