Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Code coverage and code style tools that work withaspectj?

Hi Antti,

 

I have had very good success recently using developer builds of Cobertura. It gives line and branch coverage. The one caveat is that it reports a lack of coverage for certain lines of code that can not actually be executed, e.g., declare parents. However, the Cobertura developer seems to be open to supporting AspectJ integration so I’m hoping to work with him to fix this limitation.

 

I will be checking this infrastructure into the Glassbox Inspector project in the next week or two. In the meanwhile, I’ve attached the updated ant build.xml file we are using to integrate Cobertura, including use with load-time weaving tests.

 

I have also previously used Emma although it doesn’t provide line-level coverage: it expects synthetic methods to have a Java synthetic modifier whereas AspectJ uses a custom AjSynthetic attribute due to problems with other tools. So Emma/AspectJ integration for line-level coverage is at a bit of an impasse.

 


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Adrian Colyer
Sent: Tuesday, April 11, 2006 9:48 AM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Code coverage and code style tools that work withaspectj?

 

I know that previous versions of Clover used to have issues with AspectJ compiled code... don't know whether that is fixed now or not. Emma works well with AspectJ though...

On 11/04/06, Antti Karanta <antti.karanta@xxxxxxx> wrote:



                          Hi!

  Does anyone know / have experience w/ code coverage and code style
tools that work w/ aspectj?

  I haven't tried any code coverage tools w/ aspectj, but now I would
need one. I ran checkstyle but it seemed to go berserk from aspectj
syntax so I quit it. Haven't checked it for about two years, so I don't
know whether the situation has improved.

  Anyhow, any experiences on what works and what doesn't are greatly
appreciated!



         -Antti-



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users




--
-- Adrian
adrian.colyer@xxxxxxxxx

<?xml version="1.0" encoding="UTF-8"?>
<project name="Glassbox Inspector" basedir="." default="package">
    <property file="${user.name}.build.properties" />
    <property file="build.properties" />
    <property name="src.dir" value="src" />
    <property name="testsrc.dir" value="testsrc" />
    <property name="ltwtestsrc.dir" value="ltwtestsrc" />
    <property name="dist.dir" value="dist" />
    <property name="output.dir" value="build" />
    <property name="target.dir" value="${output.dir}/target" />
    <property name="testoutput.dir" value="${output.dir}/test" />
    <property name="ltwtestoutput.dir" value="${output.dir}/ltwtest" />
    <property name="report.tests.dir" value="${output.dir}/reports" />
    <property name="release.dir" value="../GlassboxInspectorReleases" />
    <property name="coverage.file" value="${testoutput.dir}/cobertura.ser" />

    <property name="monitor.jar" value="${dist.dir}/glassboxInspector.jar" />
    <path id="project.class.path">
        <fileset dir="lib" includes="**/*.jar" />
        <fileset dir="${aspectj.lib}" includes="aspectjrt.jar" />
        <pathelement path="${java.class.path}" />
    </path>
    <path id="test.class.path">
        <fileset file="${junit.jar}" />
        <path refid="project.class.path" />
    </path>
    <echo message="Using aspectjtools at ${aspectj.lib}/aspectjtools.jar"/>
    <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
        <classpath>
            <pathelement location="${aspectj.lib}/aspectjtools.jar" />
            <path refid="project.class.path" />
        </classpath>
    </taskdef>

    <target name="all" depends="compile,test,jar" />
    <target name="package" depends="compile,jar" />
    <target name="packageAndDeploy" depends="compile,jar,deploy" />
    <target name="release" depends="all">
        <mkdir dir="${release.dir}"/>
        <zip destfile="${release.dir}/glassbox-inspector-bin-SNAPSHOT.zip">
            <zipfileset dir="." includes="*.pdf, sample*.properties, dist/**/*" prefix="GlassboxInspector"/>
            <zipfileset dir="lib" includes="aspectjweaver*.jar,commons-collections*.jar,emory-util*.jar,log4j*.jar,spring*.jar,commons-logging*.jar,*.txt" prefix="GlassboxInspector/lib"/>
            <zipfileset dir="support" includes="jconsoleStart.*" prefix="GlassboxInspector/bin"/>
        </zip>
        <zip destfile="${release.dir}/glassbox-inspector-src-with-dependencies-SNAPSHOT.zip">
            <zipfileset dir="." includes=".*, build.*, sample*.properties, *.pdf, .settings/*, src/**/*, support/**/*, testsrc/**/*, lib/**/*" prefix="GlassboxInspector"/>
            <zipfileset dir="support" includes="*" prefix="GlassboxInspector/support"/>
        </zip>
        <zip destfile="${release.dir}/glassbox-inspector-src-SNAPSHOT.zip">
            <zipfileset dir="." includes=".*, build.*, sample*.properties, *.pdf, .settings/*, src/**/*, support/**/*, testsrc/**/*" prefix="GlassboxInspector"/>
            <zipfileset dir="support" includes="*" prefix="GlassboxInspector/support"/>
        </zip>
    </target>

    <target name="compile">
        <delete dir="${target.dir}"/>
        <iajc destdir="${target.dir}" source="1.3" target="1.3" debuglevel="source" Xlintfile="support/xlint.properties">
            <src location="${src.dir}" />
            <classpath refid="project.class.path" />
        </iajc>
    </target>
    <target name="testcompile" depends="compile">
        <delete dir="${testoutput.dir}"/>
        <mkdir dir="${testoutput.dir}/target"/>
        <delete dir="${ltwtestoutput.dir}"/>
        <mkdir dir="${ltwtestoutput.dir}"/>
        <iajc destdir="${testoutput.dir}/target" source="1.3" target="1.3" debuglevel="source" Xlintfile="support/Xlint.properties">
            <src location="${testsrc.dir}" />
			<src location="${src.dir}"/>            
            <classpath>
                <path refid="test.class.path" />
            </classpath>
            <aspectpath location="${target.dir}"/>
        </iajc>
        <javac destdir="${ltwtestoutput.dir}" source="1.3" target="1.3" debuglevel="source">
            <src location="${ltwtestsrc.dir}" />
            <classpath>
                <pathelement location="${target.dir}" />
                <path refid="test.class.path" />
            </classpath>
        </javac>
    </target>
    <target name="ltwTest" unless="${nojava5.vm}">
        <mkdir dir="${report.tests.dir}/junit"/>
        <junit printsummary="yes" haltonfailure="yes" fork="yes" jvm="${java5.vm}">
            <jvmarg value="-Xmx256m"/>
            <jvmarg value="-javaagent:${basedir}/lib/aspectjweaver.jar"/>
            <jvmarg value="-Daj.weaving.verbose=!true"/>
            <jvmarg value="-Dglassbox.inspector.jmx.StatsJmxManagement.composite=true"/>
            <classpath>
                <pathelement location="${ltwtestoutput.dir}" />
                <pathelement location="${ltwtestsrc.dir}" />
                <pathelement location="${testoutput.dir}/target" />
                <pathelement location="${testoutput.dir}/test-target" />
                <pathelement location="${testsrc.dir}" />
                <pathelement location="${target.dir}" />
                <path refid="cobertura.classpath"/>
                <path refid="test.class.path" />
            </classpath>

            <formatter type="xml" />
            <batchtest todir="${report.tests.dir}/junit" >
                <fileset dir="${ltwtestoutput.dir}">
                    <include name="**/*Test.class" />
                    <exclude name="**/*$*.class" />
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="${report.tests.dir}">
            <fileset dir="${report.tests.dir}/junit">   
                 <include name="TEST-*.xml"/>
            </fileset>   
            <report todir="${report.tests.dir}/html"/>
        </junitreport>   
    </target>
    <target name="coverage"> <!-- if="${cobertura.dir}" -->
        <path id="cobertura.classpath">
            <fileset dir="${cobertura.dir}">
                <include name="cobertura.jar" />
                <include name="lib/**/*.jar" />
            </fileset>
        </path>

        <taskdef classpathref="cobertura.classpath" resource="tasks.properties" />        
        
        <delete file="${coverage.file}" />

        <cobertura-instrument datafile="${coverage.file}">
            <ignore regex="org.apache.log4j.*" />
            <fileset dir="${testoutput.dir}/target">
                <include name="**/*.class" />
                <exclude name="**/*Dummy*.class"/>
                <exclude name="**/*Mock*.class"/>
                <exclude name="**/*Test*.class"/>
                <exclude name="**/*Debug*.class"/>
                <exclude name="**/test/**"/>
                <exclude name="**/debug/**"/>
            </fileset>
        </cobertura-instrument>
    </target>
    
    <target name="test" depends="testcompile,coverage,ltwTest">
        <mkdir dir="${report.tests.dir}/junit"/>
        <junit printsummary="yes" haltonfailure="yes" fork="yes">
            <jvmarg value="-Xmx256m"/>
        	<sysproperty key="net.sourceforge.cobertura.datafile"
        		file="${coverage.file}" />
            <classpath>
                <pathelement location="${testoutput.dir}/target" />
                <pathelement location="${testsrc.dir}" />
                <path refid="test.class.path" />
                <path refid="cobertura.classpath"/>
            </classpath>

            <formatter type="xml" />
            <batchtest todir="${report.tests.dir}/junit" >
                <fileset dir="${testoutput.dir}/target">
                    <include name="**/*Test.class" />
                    <exclude name="**/*$*.class" />
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="${report.tests.dir}">
            <fileset dir="${report.tests.dir}/junit">   
                 <include name="TEST-*.xml"/>
            </fileset>   
            <report todir="${report.tests.dir}/html"/>
        </junitreport>   
        <antcall target="coverageReport"/>
    </target>
    <target name="coverageReport"> <!-- if="${cobertura.dir}" -->
        <cobertura-report format="html" destdir="${report.tests.dir}/coverage" datafile="${coverage.file}">
            <fileset dir="${src.dir}">
                <include name="**/*.java" />
                <include name="**/*.aj" />
            </fileset>
        </cobertura-report>
    </target>

    <target name="jar">
        <copy todir="${target.dir}">
            <fileset dir="${src.dir}" includes="**/*.properties,**/*.xml" />
        </copy>
        <mkdir dir="${dist.dir}"/>
        <jar jarfile="${monitor.jar}">
            <fileset dir="${target.dir}" />
        </jar>
    </target>

    <!-- build a subet of the system. useful for testing or small deployments -->
    <target name="subset.compile">
        <delete dir="${target.dir}"/>
        <iajc destdir="${target.dir}" source="1.3" target="1.3" debuglevel="source" argfiles="subset.lst">
            <classpath refid="project.class.path" />
        </iajc>
    </target>

    <target name="deploy">
        <copy todir="${containerdir}/shared/lib" file="${monitor.jar}" />
    </target>
    <!-- this is an example of how to deploy the monitor to a web application, like the J2EE bookstore, the Spring Petclinic, or iBatis JPetStore -->
    <target name="deployPerApp">
        <copy todir="${appdir}/bookstore1/WEB-INF/lib" file="${monitor.jar}" />
        <copy todir="${appdir}/petclinic/WEB-INF/lib" file="${monitor.jar}" />
        <copy todir="${appdir}/jpetstore/WEB-INF/lib" file="${monitor.jar}" />
    </target>

    <target name="diagnostics" depends="jar">       
        <mkdir dir="${dist.dir}"/>
<!--
"add on" version would require reweaving the inspector classes 
        <iajc outjar="${dist.dir}/glassboxDiagnostics.jar" source="1.3" target="1.3" debuglevel="source" sourceroots="utilsrc" 
            sourcerootcopyfilter="**/CVS/*,**/*.java,**/*.aj">
            <classpath refid="project.class.path" />
            <aspectpath>
	            <pathelement location="${monitor.jar}" />
            </aspectpath>
        </iajc>
-->        
<!-- fails: with aspectpath inconsistent types, with just inpath not weaving inpath aspects correctly        
        <iajc outjar="${dist.dir}/glassboxInspectorDebug.jar" source="1.3" target="1.3" debuglevel="source">
            <classpath refid="project.class.path" />
            <src location="utilsrc"/>
            <inpath>
	            <pathelement location="${monitor.jar}" />
            </inpath>
            <aspectpath>
	            <pathelement location="${monitor.jar}" />
            </aspectpath>
        </iajc>
-->
        <iajc outjar="${dist.dir}/glassboxInspectorDebug.jar" source="1.3" target="1.3" debuglevel="source"  
            sourcerootcopyfilter="**/CVS/*,**/*.java,**/*.aj">
            <sourceroots>
	            <pathelement location="utilsrc"/>
                <pathelement location="src"/>
            </sourceroots>	                
            <classpath refid="project.class.path" />
            <aspectpath>
	            <pathelement location="${monitor.jar}" />
            </aspectpath>
        </iajc>
        
	</target>        
    <target name="clean">
        <delete dir="${output.dir}"/>
        <delete dir="${dist.dir}"/>
    </target>
</project>

Back to the top