Skip to content

Commit

Permalink
OFBIZ-3651 - Minor tweaks to the Cobertura integration - A patch from…
Browse files Browse the repository at this point in the history
… Bob Morley. I've also changed the cobertura version from 1.9.3 to 1.9.4.1 (latest) as your modifications are allowing it

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1230444 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Erwan de Ferrieres committed Jan 12, 2012
1 parent 38d61a5 commit 478d8f3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ under the License.
<taskdef resource="tasks.properties">
<classpath>
<fileset dir="framework/base/lib">
<include name="cobertura-1.9.3.jar" />
<include name="cobertura-1.9.4.1.jar" />
<include name="log4j-1.2.15.jar" />
<include name="scripting/asm*.jar" />
</fileset>
Expand Down Expand Up @@ -964,7 +964,7 @@ under the License.
<taskdef resource="tasks.properties">
<classpath>
<fileset dir="framework/base/lib">
<include name="cobertura-1.9.3.jar" />
<include name="cobertura-1.9.4.1.jar" />
<include name="log4j-1.2.15.jar" />
<include name="scripting/asm*.jar" />
</fileset>
Expand Down
29 changes: 16 additions & 13 deletions framework/base/src/org/ofbiz/base/config/CoberturaInstrumenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
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.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.ofbiz.base.start.Instrumenter;

public final class CoberturaInstrumenter implements Instrumenter {
private static final Constructor INSTRUMENTER_CONSTRUCTOR;
private static final Constructor<?> INSTRUMENTER_CONSTRUCTOR;
private static final Method IS_INSTRUMENTED_METHOD;
static {
try {
Expand Down Expand Up @@ -77,14 +76,18 @@ public void close() throws IOException {
}

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);
if (forInstrumenting) {
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS/* | ClassWriter.COMPUTE_FRAMES*/);
try {
ClassVisitor ci = (ClassVisitor) INSTRUMENTER_CONSTRUCTOR.newInstance(projectData, 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public synchronized void loadComponents(String loaderConfig, boolean updateClass

// set the new classloader/classpath on the current thread
if (updateClasspath) {
classPath.instrument(instrumenterFile, instrumenterClassName);
if (UtilValidate.isNotEmpty(instrumenterFile) && UtilValidate.isNotEmpty(instrumenterClassName)) {
classPath.instrument(instrumenterFile, instrumenterClassName);
}

System.setProperty("java.class.path", classPath.toString());
System.setProperty("java.library.path", libraryPath.toString());
ClassLoader cl = classPath.getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static List<File> instrument(List<File> srcPaths, String instrumenterFile
e.printStackTrace();
return srcPaths;
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.err.println("InstrumenterWorker.instrument - Code instrumentation has been disabled, unable to find instrumenter class " + instrumenterClassName);
return srcPaths;
}
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors());
Expand Down
4 changes: 2 additions & 2 deletions ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<description homepage="http://ofbiz.apache.org/"/>
</info>
<configurations>
<conf name="cobertura" description="downloads cobertura 1.9.3 (GPL2.0) http://cobertura.sourceforge.net/"/>
<conf name="cobertura" description="downloads cobertura 1.9.4.1 (GPL2.0) http://cobertura.sourceforge.net/"/>
<conf name="postgres" description="downloads the postgres JDBC driver"/>
<conf name="sonar-ant-task" description="downloads the ant sonar task (need sonar>=2.6)"/>
</configurations>
<dependencies>
<dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.3" conf="cobertura->default"/>
<dependency org="net.sourceforge.cobertura" name="cobertura" rev="1.9.4.1" conf="cobertura->default"/>
<dependency org="postgresql" name="postgresql" rev="9.0-801.jdbc4" conf="postgres->default"/>
<dependency org="org.codehaus.sonar-plugins" name="sonar-ant-task" rev="1.0" conf="sonar-ant-task->default"/>

Expand Down

0 comments on commit 478d8f3

Please sign in to comment.