You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2009/12/11 23:27:18 UTC
svn commit: r889839 - in /ofbiz/trunk: .gitignore build.xml
framework/base/build.xml framework/base/config/test-containers.xml
framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java
framework/start/src/org/ofbiz/base/start/test.properties
Author: doogie
Date: Fri Dec 11 22:27:18 2009
New Revision: 889839
URL: http://svn.apache.org/viewvc?rev=889839&view=rev
Log:
Instrumentation with cobertura. It won't actually do anything, tho,
until cobertura-1.9.3.jar is placed into framework/base/lib.
Added:
ofbiz/trunk/framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java
Modified:
ofbiz/trunk/.gitignore
ofbiz/trunk/build.xml
ofbiz/trunk/framework/base/build.xml
ofbiz/trunk/framework/base/config/test-containers.xml
ofbiz/trunk/framework/start/src/org/ofbiz/base/start/test.properties
Modified: ofbiz/trunk/.gitignore
URL: http://svn.apache.org/viewvc/ofbiz/trunk/.gitignore?rev=889839&r1=889838&r2=889839&view=diff
==============================================================================
--- ofbiz/trunk/.gitignore (original)
+++ ofbiz/trunk/.gitignore Fri Dec 11 22:27:18 2009
@@ -51,6 +51,8 @@
runtime/svninfo.ftl
runtime/test-list-build.xml
runtime/logs/access_log.*
+runtime/logs/cobertura.dat
+runtime/logs/cobertura-report
runtime/logs/*.log*
runtime/logs/*.html*
runtime/logs/test-results/*
Modified: ofbiz/trunk/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/build.xml?rev=889839&r1=889838&r2=889839&view=diff
==============================================================================
--- ofbiz/trunk/build.xml (original)
+++ ofbiz/trunk/build.xml Fri Dec 11 22:27:18 2009
@@ -503,6 +503,25 @@
<ant antfile="runtime/test-list-build.xml" target="all-tests"/>
</target>
+ <target name="cobertura-report">
+ <delete dir="runtime/logs/cobertura-report"/>
+ <mkdir dir="runtime/logs/cobertura-report"/>
+ <taskdef resource="tasks.properties">
+ <classpath>
+ <fileset dir="framework/base/lib">
+ <include name="cobertura-1.9.3.jar" />
+ <include name="log4j-1.2.15.jar" />
+ <include name="scripting/asm*.jar" />
+ </fileset>
+ </classpath>
+ </taskdef>
+ <cobertura-report datafile="runtime/logs/cobertura.dat" destdir="runtime/logs/cobertura-report">
+ <fileset dir=".">
+ <include name="*/*/src/**/*.java"/>
+ </fileset>
+ </cobertura-report>
+ </target>
+
<!-- ================================================================== -->
<!-- Create New Component. This target will create basic directory structure for an OFBiz component in hot-deploy directory. -->
<!-- ================================================================== -->
Modified: ofbiz/trunk/framework/base/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/build.xml?rev=889839&r1=889838&r2=889839&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/build.xml (original)
+++ ofbiz/trunk/framework/base/build.xml Fri Dec 11 22:27:18 2009
@@ -52,9 +52,15 @@
<available classname="javax.crypto.Cipher" classpathref="local.class.path"/>
</not>
</condition>
+ <condition property="exclude.cobertura" value="org/ofbiz/base/config/Cobertura*.java">
+ <not>
+ <available classname="net.sourceforge.cobertura.instrument.ClassInstrumenter" classpathref="local.class.path"/>
+ </not>
+ </condition>
<!-- compile base -->
<javac15 destdir="${build.dir}/classes" srcdir="${src.dir}">
+ <exclude name="${exclude.cobertura}"/>
<exclude name="${exclude.crypto}"/>
<exclude name="org/ofbiz/base/util/OfbizJsBsfEngine.java"/>
</javac15>
Modified: ofbiz/trunk/framework/base/config/test-containers.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/config/test-containers.xml?rev=889839&r1=889838&r2=889839&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/config/test-containers.xml (original)
+++ ofbiz/trunk/framework/base/config/test-containers.xml Fri Dec 11 22:27:18 2009
@@ -21,7 +21,10 @@
<ofbiz-containers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-containers.xsd">
<!-- load the ofbiz component container (always first) -->
- <container name="component-container" class="org.ofbiz.base.container.ComponentContainer"/>
+ <container name="component-container" class="org.ofbiz.base.container.ComponentContainer">
+ <property name="ofbiz.instrumenterClassName" value="org.ofbiz.base.config.CoberturaInstrumenter"/>
+ <property name="ofbiz.instrumenterFile" value="runtime/logs/cobertura.dat"/>
+ </container>
<!-- load the cached classloader container (always second) -->
<container name="classloader-container" class="org.ofbiz.base.container.ClassLoaderContainer"/>
Added: ofbiz/trunk/framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java?rev=889839&view=auto
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java (added)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java Fri Dec 11 22:27:18 2009
@@ -0,0 +1,73 @@
+package org.ofbiz.base.config;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.ClassVisitor;
+
+import net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler;
+import net.sourceforge.cobertura.coveragedata.ProjectData;
+
+import org.ofbiz.base.start.Instrumenter;
+
+public final class CoberturaInstrumenter implements Instrumenter {
+ private static final Constructor INSTRUMENTER_CONSTRUCTOR;
+ private static final Method IS_INSTRUMENTED_METHOD;
+ static {
+ try {
+ Class<?> clz = CoberturaInstrumenter.class.getClassLoader().loadClass("net.sourceforge.cobertura.instrument.ClassInstrumenter");
+ INSTRUMENTER_CONSTRUCTOR = clz.getConstructor(ProjectData.class, ClassVisitor.class, Collection.class, Collection.class);
+ INSTRUMENTER_CONSTRUCTOR.setAccessible(true);
+ IS_INSTRUMENTED_METHOD = clz.getDeclaredMethod("isInstrumented");
+ IS_INSTRUMENTED_METHOD.setAccessible(true);
+ } catch (Throwable t) {
+ throw (InternalError) new InternalError(t.getMessage()).initCause(t);
+ }
+ }
+
+ protected File dataFile;
+ protected ProjectData projectData;
+ protected boolean forInstrumenting;
+
+ public File getDefaultFile() throws IOException {
+ return CoverageDataFileHandler.getDefaultDataFile();
+ }
+
+ public void open(File dataFile, boolean forInstrumenting) throws IOException {
+ System.setProperty("net.sourceforge.cobertura.datafile", dataFile.toString());
+ this.forInstrumenting = forInstrumenting;
+ this.dataFile = dataFile;
+ if (forInstrumenting) {
+ if (dataFile.exists()) {
+ projectData = CoverageDataFileHandler.loadCoverageData(dataFile);
+ } else {
+ projectData = new ProjectData();
+ }
+ }
+ }
+
+ public void close() throws IOException {
+ if (forInstrumenting) {
+ CoverageDataFileHandler.saveCoverageData(projectData, dataFile);
+ }
+ }
+
+ public byte[] instrumentClass(byte[] bytes) throws IOException {
+ ClassReader cr = new ClassReader(bytes);
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS/* | ClassWriter.COMPUTE_FRAMES*/);
+ try {
+ ClassVisitor ci = (ClassVisitor) INSTRUMENTER_CONSTRUCTOR.newInstance(projectData != null ? projectData : ProjectData.getGlobalProjectData(), cw, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+ cr.accept(ci, 0);
+ if (((Boolean) IS_INSTRUMENTED_METHOD.invoke(ci)).booleanValue()) return cw.toByteArray();
+ } catch (Throwable t) {
+ throw (IOException) new IOException(t.getMessage()).initCause(t);
+ }
+ return bytes;
+ }
+}
Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/test.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/test.properties?rev=889839&r1=889838&r2=889839&view=diff
==============================================================================
--- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/test.properties (original)
+++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/test.properties Fri Dec 11 22:27:18 2009
@@ -50,6 +50,9 @@
# -- Auto-Shutdown after load
ofbiz.auto.shutdown=true
+ofbiz.instrumenterClassName=org.ofbiz.base.config.CoberturaInstrumenter
+ofbiz.instrumenterFile=runtime/logs/cobertura.dat
+
# --- Default Derby system home directory
#derby.system.home=runtime/data/derby