alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Glassfish example source code file (build.xml)

This example Glassfish source code file (build.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Glassfish tags/keywords

cddl, copyright, creates, gpl, gpl, header, if, license, license, oracle, testng, testng, version, version

The Glassfish build.xml source code

<?xml version="1.0" encoding="UTF-8"?>
<!--

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
    or packager/legal/LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at packager/legal/LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

<project name="GlassFish-V3-CommunityTests" default="default" basedir=".">
    <property file="build.properties"/>
     <property file="${basedir}/gfproject/derby.properties"/>
     <import file="${basedir}/gfproject/db-targets.xml"/>
    
    <description>Builds, tests, and runs the project V3 Quicklook
    <target name="all" depends="clean">
        <record name="allrun.output" action="start"/>
	<!-- resolveArtifact artifactId="testng" property="testng.jar"/>
        <echo message="testng jar value: ${testng.jar}"/ -->
        <!-- antcall target="setup.toplink"/ -->
        <antcall target="start-server"/>
        <antcall target="startDerby"/>        
        <antcall target="build"/>
        <antcall target="deploy"/>
        <antcall target="runtest"/>
        <antcall target="undeploy"/>
        <antcall target="stop-server"/>
        <antcall target="stopDerby"/>
        <!-- antcall target="report"/ -->        
        <record name="allrun.output" action="stop"/>
    </target>
        
    <!-- 
    
    <target name="copyJARS">
        <echo message="Copying testng.jar to ${ant.home}/lib"/>
        <copy todir="${ant.home}/lib" verbose="true">
            <fileset dir="${basedir}/lib">
                <include name="**/testng*.*"/>
            </fileset>
        </copy>      
    </target>
    <target name="default">
        <echo message="ANT.HOME is ${ant.home}"/>
        <antcall target="copyJARS"/>
        <echo message="ant build (Compiles and Packages testsuites)"/>
        <echo message="ant deploy (Deploys test to GlassFish server)"/>
        <echo message="ant compile-tests (Compiles TestNG test)"/>
        <echo message="ant runtest (Runs TestNG test)"/>
        <echo message="ant report (Creates TestNG Report)"/>
        <echo message="ant archive (Creates zip of testbase}"/>
        <echo message=""/>
    </target>
    
    <target name="build">  
        <record name="build.output" action="start"/>
        <echo message="ANT PROJECT ${ant.project.name}"/>
        <ant dir="web/helloworld" target="build"/>
        <ant dir="web/jsfastrologer" target="build"/>
        <ant dir="web/jsfinjection" target="build"/>
        <ant dir="jdbc/jdbcusertx" target="build"/>
        <!-- ant dir="web/strutsbasic" target="build"/ -->
        <!-- ant dir="persistence/servlet-jpa-app" target="build"/ -->
        <!--
        <record name="build.output" action="stop"/>
    </target>
    
    
    <target name="compile-tests">            
        <record name="compiletests.output" action="start"/>
        <ant dir="web/helloworld" target="compile-tests"/>
        <ant dir="web/jsfastrologer" target="compile-tests"/>
        <ant dir="web/jsfinjection" target="compile-tests"/>
        <ant dir="jdbc/jdbcusertx" target="compile-tests"/>
        <!-- ant dir="web/strutsbasic" target="compile-tests"/ -->
        <!-- ant dir="persistence/servlet-jpa-app" target="compile-tests"/ -->
        <record name="compiletests.output" action="stop"/>
    </target>
    
    <target name="deploy">
        <record name="deploy.output" action="start"/>
        <ant dir="web/helloworld" target="deploy"/>
        <ant dir="web/jsfastrologer" target="deploy"/>
        <ant dir="web/jsfinjection" target="deploy"/>
        <ant dir="jdbc/jdbcusertx" target="deploy"/>
        <!-- ant dir="web/strutsbasic" target="deploy"/ -->
        <!-- ant dir="persistence/servlet-jpa-app" target="deploy"/ -->   
        <record name="deploy.output" action="stop"/>
    </target>
    
    <target name="undeploy">
        <record name="undeploy.output" action="start"/>
        <ant dir="web/helloworld" target="undeploy"/>
        <ant dir="web/jsfastrologer" target="undeploy"/>
        <ant dir="web/jsfinjection" target="undeploy"/>
        <ant dir="jdbc/jdbcusertx" target="undeploy"/>
        <!-- ant dir="web/strutsbasic" target="undeploy"/ -->
        <!-- ant dir="persistence/servlet-jpa-app" target="undeploy"/ -->   
        <record name="undeploy.output" action="stop"/>
    </target>

    <target name="noproject">
	    <delete includeemptydirs="true">
		<fileset dir="${basedir}">
			<include name="**/nbproject"/>
		</fileset>
	</delete>
    </target>
    
   
    <!-- Target is re-definted here as didn't want to specify ws.root property -->
    <target name="clean">
        <delete dir="${basedir}/classes"/>
	<delete verbose="true" includeemptydirs="true">
		<fileset dir="${basedir}" includes="**/classes"/>
	</delete>
        <delete dir="${basedir}/test-output" includeemptydirs="true"/>
        <delete dir="${basedir}/dist" includeemptydirs="true"/>
	<delete includeemptydirs="true">
		<fileset dir="${basedir}">
			<include name="**/*.output"/>
			<include name="**/*.log"/>
		</fileset>
	</delete>
        <delete>
            <fileset dir="${basedir}" includes="*.zip"/>
        </delete>
        <echo message="Deleting all WAR/EAR in local testsuite directories!!!"/>
        <echo message="There should not be any WAR file checked in."/>
        <delete>
            <fileset dir="." includes="**/*.war"/>
        </delete>
    </target>
        
    
    <target name="-post-test-run">
        <loadfile property="startserver.log" srcFile="${glassfish.home}/domains/domain1/logs/server.log"/>
        <echo message="${startserver.log}"/>
    </target>
    
    <path id="path2testng">
        <pathelement location="./lib/testng-5.0-jdk15.jar"/>
    </path>
    
    <taskdef name="testng" classname="org.testng.TestNGAntTask">
        <classpath>
	    <pathelement path="${plugin_classpath}"/>
        </classpath>
    </taskdef>
    
    <!-- Target is re-definted here as didn't want to specify ws.root property -->
    <target  name="runtest" depends="compile-tests,initprops">    
        <record name="runtestng.output" action="start"/>
        <echo message="=============Starting TestNG functional tests from testng.xml ============"/>    
        <property name="hasTestNGXML" value="true"/>
        
        <mkdir dir="${test.report}"/>    
        <testng outputdir="${test.report}"
                classpathref="run.testng.classpath">
            <jvmarg value="-Djava.compiler=NONE"/>
            <jvmarg value="-Dhttp.host=${glassfish.http.host}"/>
            <jvmarg value="-Dhttp.port=${glassfish.http.port}"/>
            <sysproperty key="basedir" value="${basedir}"/>
            <!--         
            <xmlfileset dir="." includes="testng.xml"/>
            
        </testng>
        
        <record name="runtestng.output" action="stop"/>
        
        
        <!-- 
        
    </target>  
    
    
    <!-- Generate the TestNG report -->
    <target name="report" depends="initprops">        
        <echo message="Generating report at ${test.report}"/>
        <junitreport todir="${test.report}">
            <fileset dir=".">
                <include name="**/test-output/**/*.xml"/>
                <!--
            </fileset>
            <report format="noframes" todir="${test.report}"/>
        </junitreport>
        <echo message="Test Report available at ${test.report}/index.html"/>
    </target>
    
    <target name="initprops">
        <property name="build.class.dir" value="${basedir}/classes/test"/>
        <property name="test.report" value="${basedir}/test-output"/>
        <mkdir dir="${test.report}"/>
        <path id="run.testng.classpath">
            <!-- fileset dir="${basedir}/lib">
                <include name="**/*.jar"/>
            </fileset -->
	    <pathelement path="${plugin_classpath}"/>
            <pathelement location="${build.class.dir}"/>
        </path>
    </target>
    
    
    <target name="archive" depends="initprops,clean">
        <tstamp>
            <!--
        </tstamp>
        <property name="final.src.name" value="glassfish_testng_${DSTAMP}.zip"/>
        <delete>
            <fileset dir="${basedir}" includes="*.zip"/>
        </delete>
        <delete file="{final.src.name}" failonerror="false"/>
        
        <zip zipfile="${final.src.name}" basedir=".">
            
            <exclude name="${test.report}/**"/>
            <exclude name="${build.class.dir}/**"/>
            <exclude name="**/*.log"/>
            <exclude name="**/*.output"/>
            <exclude name="**/*.war"/>
            <exclude name="**/*.class"/>
            <exclude name="**/CVS"/>
            <exclude name="**/nbproject"/>
            
        </zip>
        
    </target>

<target name="setOSConditions">
  <condition property="isUnix">
    <os family="unix"/>
  </condition>
  <condition property="isWindows">
    <os family="windows" />
  </condition>
</target>

<target name="start-server" depends="setOSConditions" if="v3">
   
    <echo>+-----------------------------+
    <echo>|                             |
    <echo>| S T A R T I N G   GLASSFISH |
    <echo>|                             |
    <echo>+-----------------------------+
    
    <antcall target="start-server-unix"/>
    <antcall target="start-server-windows"/>
</target>

<target name="start-server-windows" if="isWindows">
    <exec executable="cmd" spawn="true">	
        <arg value="/c"/>
        <arg value="${glassfish.home}/bin/asadmin.bat"/>
        <arg value="start-domain"/>
    </exec>
</target>
    
<target name="start-server-unix" if="isUnix">
    <exec executable="${glassfish.home}/bin/asadmin">        
        <arg value="start-domain"/>
    </exec>
</target>

<target name="stop-server" depends="setOSConditions">
    <echo message="stopping server"/>
    <antcall target="stop-server-unix"/>
    <antcall target="stop-server-windows"/>
</target>
    
<target name="stop-server-windows" if="isWindows">
     <exec executable="cmd">	
         <arg value="/c"/>
         <arg value="${glassfish.home}/bin/asadmin.bat"/>
         <arg value="stop-domain"/>
     </exec>
</target>
         
<target name="stop-server-unix" if="isUnix">
     <exec executable="${glassfish.home}/bin/asadmin">        
        <arg value="stop-domain"/>
    </exec>
</target>

</project>

Other Glassfish examples (source code examples)

Here is a short list of links related to this Glassfish build.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.