Hi,

I am using ant for build and test our java application. We run into 
'java.lang.OutOfMemory' problems when running junit tests.
I have made a number of changes without any luck:

- Unset classpath
- increase ANT Xms and Xmx via ANT_OPTS env. variable.
- Using fork in javac.
- Increase Xmx in javac.
- Increased Xmx in junit-target.

I am now willing to try to find out where most of my memory is comsumed using a 
profiler ( if possible).

I am using netbeans and their profiler.

Q: Is it possible to profile a jar file? 

Q2: Anyone tried that on Ant?

Q3: I am using 1.6 features. Could that slow down my build and generate 
java.lang.OutOfMemory?

I atttach my common.xml

 <<common.xml>>  

All hints are very much appreciated!

//Mikael
<?xml version="1.0" encoding="UTF-8"?>
<!-- History:										  -->
<!-- 2005-03-30 eraonel removed duplicate names for same tasks.                           -->
<!-- 2005-03-08 eraonel split test:compile into, compile:unit & compile:tests 		  -->
<!-- 2005-03-04 eraonel format-target only and with only dep. to init.			  -->
<!-- 2005-02-10 eraonel remove fileset in target 'clean'	                          -->
<!-- 2005-01-26 eraonel add source tag for junitreport.                                   -->
<!-- 2004-12-17 eraonel 'clean' now also deletes the jar file from the cimsello/mp_lm dir.-->
<!-- 2005-03-02 eraonel updated with new target for junit tests - test:compile            -->
<!-- 2004-12-17 eraonel 'clean' now also deletes the jar file from the cimsello/mp_lm dir.-->
<!-- 2004-11-02 eraonel correct exclude tb in compile target.                             -->
<!-- 2004-07-14 eraonel Initial version of common tasks. The file contains generic tasks. -->
<!-- 		The same task name could be used in importing file. Then this             -->
<!--            generic task will be overidden.                                           -->


<project basedir="." default="init" name="common">

<!--  load the global properties  --> 
  <property file="build.properties" />    

  <!-- ==================================================================== -->
  <!-- initialize properties                                                -->
  <!-- ==================================================================== -->
  <target name="init" description="initialize params and tasks">
   <!-- create the timestamp -->
   <tstamp/>
   <!-- build directories -->
   <property name="classes.dir" value="./classes"/>
   <property name="test.classes.dir" value="./sut_classes"/>	
   <property name="dist.dir" value="./dist"/>
   <property name="src.dir" value="./src"/>
   <!-- test source dir functional tests ( target compile:tests) ONLY TEMPORARY should be same as src.dir -->
   <property name="src.test.dir" value="/home/eraonel/tmp/junit" />
   <property name="test.reports.dir" value="./test/reports"/>
   <!-- output directory used for EMMA coverage reports: -->
   <property name="coverage.dir" value="${basedir}/coverage" />

   <mkdir dir="${classes.dir}"/>
   <mkdir dir="${dist.dir}"/>
   <mkdir dir="${test.classes.dir}"/>
   <mkdir dir="${test.reports.dir}"/>
   <mkdir dir="${coverage.dir}"/>

   <!-- jalopy directories -->
   <property name="jalopy.ant.dir" value="${JALOPY.ANT.DIR}"/>
   <property name="jalopy.dir" value="${JALOPY.DIR}"/>

   <!-- EXTERNAL TOOLS USED IN BUILD -->

   <!-- JALOPY -->
   <taskdef name="jalopy" 
             classname="de.hunsicker.jalopy.plugin.ant.AntPlugin">
    <classpath>
     <fileset dir="${JALOPY.ANT.DIR}/lib">
      <include name="*.jar" />
     </fileset>
    </classpath>
   </taskdef>
      
   <!-- EMMA -->
   <!-- path element used by EMMA taskdef below: -->
   <path id="emma.lib" >
    <pathelement location="${EMMA.CODECOV.LIB.DIR}/${EMMA.JAR}" />
    <pathelement location="${EMMA.CODECOV.LIB.DIR}/${EMMA.ANT.JAR}" />
   </path>

   <!-- this loads <emma> and <emmajava> custom tasks: -->
   <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
   
   <!-- FINDBUGS -->
   <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
    <classpath>
     <fileset file="${FINDBUGS.LIB.DIR}/${FINDBUGS.ANT.JAR}"/>     
    </classpath> 
   </taskdef>
   <!-- Echoing version information -->
    <echo message="Java JVM is ${ant.java.version}"/>
    <echo message="${ant.version}"/>
    <echo message="Running on os ${os.name}"/>
    <echo message="Work done on ${ant.project.name}"/>
    <echo message="Building with java compiler  ${BUILD.COMPILER}"/>
  </target>

  <!-- ==================================================================== -->
  <!-- Setup for target. MUST BE IMPLEMENTED in inherited buildfile         -->
  <!-- ==================================================================== -->
  <target name="setup" description="setup classpath for target">
    <echo message="using target classpath"/>
   <path id="common.classpath">
    <pathelement location="${CELLO.DIR}/${CMA.JAR}"/>
    <pathelement location="${CELLO.DIR}/${FOUNDATION.JAR}"/>
    <pathelement location="${CELLO.DIR}/${OMS.JAR}"/>
    <pathelement location="${CELLO.DIR}/${VBJORB.JAR}"/>
    <pathelement location="${CELLO.DIR}/${ASMS.JAR}"/>
   </path>
  
  </target>

  <!-- ==================================================================== -->
  <!-- Setup for test.  MUST BE IMPLEMENTED in inherited buildfile          -->
  <!-- ==================================================================== -->
  <target name="test:setup" description="setup classpath for test">
  
  </target>
  <!-- ==================================================================== -->
  <!-- emma code coverage tool setup.                                       -->
  <!-- ==================================================================== -->
  <target name="emma" description="turns on EMMA's instrumentation/reporting" >
    <property name="emma.enabled" value="true" />
    <!-- EMMA instr class output directory (it is important to create
         this property only when EMMA is enabled:
    -->
    <property name="out.instr.dir" value="outinstr" />
    <mkdir dir="${out.instr.dir}" />
    <!-- this property, if overriden via -Demma.filter=<list of filter specs>
         on ANT's command line, will set the coverage filter; by default,
         all classes found in 'run.classpath' pathref will be instrumented:
    -->
    <property name="emma.filter" value="" />
  </target>
  
  <!-- ==================================================================== -->
  <!-- Executes FindBugs on source code                                     -->
  <!-- ==================================================================== --> 
  <target name="findbugs" depends="jar">
    <findbugs home="${FINDBUGS.LIB.DIR}"
              output="xml"
              outputFile="${ant.project.name}-fb.xml" jvmargs="-Xmx512M" >
      <auxClasspath>
       <path refid="test.classpath"/>
      </auxClasspath>
      <sourcePath path="${src.dir}" />
      <class location="./dist/${ant.project.name}.jar" />
    </findbugs>
  </target>
  

  <!-- ==================================================================== -->
  <!-- Compiles the project sources - target                                -->
  <!-- ==================================================================== -->
    <target name="compile" depends="init,setup" description="compile product src code">
	<depend srcdir="${src.dir}" destdir="${classes.dir}" cache="depcache" 
        closure="yes"/>
        <!-- Both srcdir and destdir should be package roots. -->
       	 <javac  debug="true" deprecation="true" destdir="${classes.dir}" 
         srcdir="${src.dir}" source="${BUILD.COMPILER}" nowarn="${NO.WARN}" fork="true" memoryMaximumSize="768m">
	 <classpath refid="common.classpath"/>
         <!-- No test classes -->
	 <exclude name="**/tb/**"/> 
	 <exclude name="**/upfwk/**"/>
	 <exclude name="test/**"/> 
	</javac>
   </target>

  <!-- ==================================================================== -->
  <!-- Compiles the project sources for unit under test                     -->
  <!-- ==================================================================== -->
   <target name="compile:unit" depends="init,test:setup" description="compile product src code">
	<depend srcdir="${src.dir}" destdir="${classes.dir}" cache="depcache" 
        closure="yes"/>
        <!-- Both srcdir and destdir should be package roots. -->
       	 <javac  debug="true" deprecation="true" destdir="${classes.dir}" 
         srcdir="${src.dir}" source="${BUILD.COMPILER}" nowarn="${NO.WARN}" fork="true" memoryMaximumSize="768m">
	 <classpath refid="test.classpath"/>
         <!-- No test classes -->
	 <exclude name="**/tb/**"/> 
	 <exclude name="**/upfwk/**"/>
	 <exclude name="test/**"/> 
	</javac>
   </target>	

  <!-- ==================================================================== -->
  <!-- Compiles the project test classes (junit)                            -->
  <!-- ==================================================================== --> 
  <target name="compile:tests" depends="init,test:setup" 
          description="compile test src code">
	<depend srcdir="${src.dir}" destdir="${classes.dir}" cache="depcache" 
        closure="yes"/>
        <!-- Both srcdir and destdir should be package roots. -->
       	 <javac  debug="true" deprecation="true" destdir="${test.classes.dir}" 
         srcdir="${src.dir}" source="${BUILD.COMPILER}" nowarn="${NO.WARN}" fork="true" memoryMaximumSize="768m">
         <classpath>
         <pathelement location="${classes.dir}"/>
	  <path refid="test.classpath"/>	
         </classpath>
	 <!-- Only vaild for boam -->
	 <exclude name="se/ericsson/wcdma/rbs/boam/upfwk/"/>
	 <include name="**/tb/mock/**"/>
         <include name="**/tb/sut/*Test*.java"/>
	 <include name="/vobs/rbs/sw/rbssw1/boam_subsys/boam_swb/boam_bldu/ant_build/src/se/ericsson/wcdma/rbs/boam/common/tb/sut"/>
	 
	</javac>
   </target>
   
  <!-- ==================================================================== -->
  <!-- Emma code coverage , instrument classes (probing classes)    -->
  <!-- ==================================================================== -->
  <target name="test:postcompile" depends="compile:unit" description="probing classes">
  <emma enabled="${emma.enabled}" >
      <instr instrpath="${classes.dir}"
             destdir="${out.instr.dir}"	       
             metadatafile="${coverage.dir}/metadata.emma"
             merge="false">
        <!-- note that coverage filters can be set through nested <filter>
             elements as well: many of EMMA setting are 'mergeable' in the
             sense that they can be specified multiple times and the result
             is a union of all such values. Here we are not merging several
             filters together but merely demonstrating that it is possible:
        -->
	<!--<filter excludes="*Test*" />-->
      </instr>
    </emma>
   </target>

  <!-- ==================================================================== -->
  <!-- Run unit tests with JUnit                                            -->
  <!-- ==================================================================== -->
  <target  name="test:test" depends="test:postcompile" description="run all tests">
  <junit printsummary="on" haltonfailure="no" fork="true" forkmode="once">
    <jvmarg value="-Xmx1256M" />
    <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.emma" /> 
    <jvmarg value="-Demma.coverage.out.merge=true" /> 
    <classpath>
     <pathelement location="${out.instr.dir}"/>
     <pathelement location="${test.classes.dir}"/>
     <pathelement location="${classes.dir}"/>
     <path refid="test.classpath"/>
     <path refid="emma.lib" />
   </classpath>
   <formatter type="brief" usefile="false"/>
   <formatter type="xml"/>
    <batchtest todir="${coverage.dir}">
     <fileset dir="${test.classes.dir}">
      <!--<include name="**/*Test*.java"/>-->
      <!--<exclude name="**/mock/**"/>-->
     </fileset>
    </batchtest>
   </junit>
   </target>
   
  <!-- ==================================================================== -->
  <!-- Generate reports for code coverage.                                  -->
  <!-- ==================================================================== -->
   <target name="test:emma:report" depends="test:test" description="generate code cov. reports">
   <!-- if enabled, generate coverage report(s): -->
    <emma enabled="${emma.enabled}" >
      <report sourcepath="${src.dir}"
              sort="+block,+name,+method,+class"
              metrics="method:70,block:80,line:80,class:100">
        <!-- collect all EMMA data dumps (metadata and runtime)
             [this can be done via nested <fileset> fileset elements
             or <file> elements pointing to a single file]:
        -->
        <fileset dir="${coverage.dir}" >
          <include name="*.emma" />
        </fileset>

        <!-- for every type of report desired, configure a nested
             element; various report parameters
             can be inherited from the parent <report>
             and individually overridden for each report type:
        -->
        <txt outfile="${coverage.dir}/coverage.txt"
             depth="package"
             columns="class,method,block,line,name"
        />
        <xml outfile="${coverage.dir}/coverage.xml"
             depth="package"
        />
        <html outfile="${coverage.dir}/coverage.html"
             depth="method"
             columns="name,class,method,block,line"
        />
      </report>
    </emma>
  </target>
  
  <!-- ==================================================================== -->
  <!-- Generate junit reports                                               -->
  <!-- ==================================================================== -->
  <target name="test:junit:report" depends="test:test" description="generate junit reports">
   <junitreport todir="${test.reports.dir}">
    <!--<fileset dir="${test.reports.dir}">-->
        <fileset dir="${coverage.dir}">
	<include name="TEST-*.xml"/>
    </fileset>
    <report format="frames" todir="${test.reports.dir}/html"/>
  </junitreport>
  </target>

  <!-- ==================================================================== -->
  <!-- Formats all checkout source files                                   -->
  <!-- ==================================================================== -->

  <target name="format" depends="init" description="format source code">
   <jalopy fileformat="unix" convention="${JALOPY.DIR}/cfg/sun.xml" 
	       history="file" historymethod="adler32" 
	       threads="2"
               loglevel="error">
        <fileset dir="${src.dir}">
        	<include name="**/*.java" />
      	</fileset>
   </jalopy>
  </target>
 
  <!-- ==================================================================== -->
  <!-- Make a jar container for sorouce files                               -->
  <!-- ==================================================================== -->
  <target name="jar" depends="init,compile" description="create jar">
     <jar basedir="${classes.dir}" compress="true" 
          jarfile="${dist.dir}/${ant.project.name}.jar">
      <exclude name="**/*.java"/>
      <exclude name="${jar.dir}"/>
     </jar>
  </target>	
  
  <!-- ==================================================================== -->
  <!-- clean all class and jar files                                        -->
  <!-- ==================================================================== -->	
  <target name="clean" depends="init" description="Clean all build products.">
   <echo message="cleaning ..."/> 
   <delete quiet="false" failonerror="false" file="${dist.dir}/${ant.project.name}.jar"/>
   <delete quiet="false" failonerror="false" file="${SIMCELLO.DIR}/${ant.project.name}.jar"/>
   <delete quiet="false" failonerror="false" dir="${classes.dir}"/>
  </target>

 
  <!-- ==================================================================== -->
  <!-- clean all class and jar files                                        -->
  <!-- ==================================================================== -->	
  <target name="test:clean" depends="init" description="clean all build products.">
   <echo message="cleaning test ..."/> 
   <delete quiet="false" failonerror="false">
    <fileset dir="${classes.dir}"/>
    <fileset dir="${out.instr.dir}"/>
    <fileset dir="${test.classes.dir}"/>
    <fileset dir="${coverage.dir}"/>
    <fileset dir="${test.reports.dir}"/>
   </delete>
  </target>
 
  <!-- ==================================================================== -->
  <!-- copy jar                                                             -->
  <!-- ==================================================================== -->
  <target name="copy" depends="jar">
    <copy file="${dist.dir}/${ant.project.name}.jar" todir="${SIMCELLO.DIR}"/>
  </target>

  <!-- ==================================================================== -->
  <!-- Run tests on source files                                            -->
  <!-- ==================================================================== -->
  <target name="test" depends="test:setup,init,compile:unit,compile:tests,format,
			       test:postcompile,test:test,
			       test:emma:report, test:junit:report" description="Test ${ant.project.name}">
   <echo message="Testing done!"/>
  </target>         
  
  <!-- ==================================================================== -->
  <!-- Do everything!                                                       -->
  <!-- ==================================================================== -->	  
  <target name="all" depends="jar,format,copy"/>	
</project>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to