Hi Marc,
Please find the full stack.
ava.io.IOException: Error while instrumenting oracle/apps/scm/productModel/items/ui/bean/ItemOverviewBean.
at org.jacoco.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:109)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:134)
at ree.PerTestCoverageCollector$2.visitClassExecution(PerTestCoverageCollector.java:572)
at org.jacoco.core.data.ExecutionDataReader.readExecutionData(ExecutionDataReader.java:151)
at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:116)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:93)
at ree.PerTestCoverageCollector.dump(PerTestCoverageCollector.java:692)
at ree.PerTestCoverageCollector.executeTest(PerTestCoverageCollector.java:211)
at ree.PerTestCoverageManager.main(PerTestCoverageManager.java:97)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
at org.jacoco.core.internal.instr.InstrSupport.getMajorVersion(InstrSupport.java:176)
at org.jacoco.core.internal.instr.InstrSupport.classReaderFor(InstrSupport.java:275)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:75)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:107)
... 8 more
The Code I was trying out is as below
public void dump(InputStream in) throws Exception {
File output_file = new File((configData.get("OUTPUT_FILE_DIR") + TESTCASE_NAME + "#"+configData.get("TEST_NUM")+(".txt")));
System.out.println("TestCase: "+TESTCASE_NAME);
System.out.println("OUTPUT_FILE_DIR: "+configData.get("OUTPUT_FILE_DIR"));
System.out.println(configData.get("OUTPUT_FILE_DIR") + TESTCASE_NAME + ".txt");
output_file.createNewFile();
final PrintStream out = new PrintStream(new FileOutputStream(output_file, false));
out.println("CLASS ID HITS/PROBES CLASS NAME");
System.out.println("INDATE in"+in);
//String results = new BufferedReader (new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
//System.out.println("INDATE"+results);
final ExecutionDataReader reader = new ExecutionDataReader(in);
reader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(final SessionInfo info) {
out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(info.getStartTimeStamp()),
new Date(info.getDumpTimeStamp()));
}
});
reader.setExecutionDataVisitor(new IExecutionDataVisitor() {
public void visitClassExecution(final ExecutionData data) {
CLASS_NAME = data.getName();//"oracle/apps/scm/productModel/items/ui/bean/ItemOverviewBean";//
long CLASS_ID = data.getId();
Date todayDate = new Date();
final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println("Today DAte is :" + sdf.format(todayDate));
System.out.println("CLASS_NAME:"+CLASS_NAME);
System.out.println("CLASS_ID:"+CLASS_ID);
//Test method level coverage
/*************************************************************************************/
// For instrumentation and runtime we need a IRuntime instance
// to collect execution data:
try{
final IRuntime runtime = new LoggerRuntime();
// The Instrumenter creates a modified version of our test target class
// that contains additional probes for execution data recording:
final Instrumenter instr = new Instrumenter(runtime);
InputStream original = getTargetClass();
final byte[] instrumented = instr.instrument(original, CLASS_NAME);
original.close();
// Now we're ready to run our instrumented class and need to startup the
// runtime first:
final RuntimeData dataRunTime = new RuntimeData();
runtime.startup(dataRunTime);
// In this tutorial we use a special class loader to directly load the
// instrumented class definition from a byte[] instances.
final MemoryClassLoader memoryClassLoader = new MemoryClassLoader();
memoryClassLoader.addDefinition(CLASS_NAME, instrumented);
final Class<?> targetClass = memoryClassLoader.loadClass(CLASS_NAME);
// Here we execute our test target class through its Runnable interface:
final Runnable targetInstance = (Runnable) targetClass.newInstance();
targetInstance.run();
// At the end of test execution we collect execution data and shutdown
// the runtime:
final ExecutionDataStore executionData = new ExecutionDataStore();
final SessionInfoStore sessionInfos = new SessionInfoStore();
dataRunTime.collect(executionData, sessionInfos, false);
runtime.shutdown();
// Together with the original class definition we can calculate coverage
// information:
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
original = getTargetClass();
analyzer.analyzeClass(original, CLASS_NAME);
original.close();
// Let's dump some metrics and line coverage information:
for (final IClassCoverage cc : coverageBuilder.getClasses()) {
out.printf("Coverage of class %s%n", cc.getName());
printCounter("instructions", cc.getInstructionCounter());
printCounter("branches", cc.getBranchCounter());
printCounter("lines", cc.getLineCounter());
printCounter("methods", cc.getMethodCounter());
printCounter("complexity", cc.getComplexityCounter());
for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {
out.printf("Line %s: %s%n", Integer.valueOf(i),
getColor(cc.getLine(i).getStatus()));
}
}
}catch(Exception e){
e.printStackTrace();
}
/***************************************************************************************/
}
//}
});
reader.read();
in.close();
System.out.println();
}
/** Currently hardcoded the file details to validate **/
public InputStream getTargetClass() throws Exception{
InputStream fs = new FileInputStream(CLASSPATH);
System.out.println(fs.toString());
String results = new BufferedReader (new InputStreamReader(fs)).lines().collect(Collectors.joining("\n"));
System.out.println("INDATE"+results);
return fs;
}
Thanks,
Prabitha