Skip to content

Commit 96d25da

Browse files
committed
This revision updates the version of jacoco in drjava/lib to the
latest version. It also revised the MemoryClassLoader class for code coverage in an attempt to get code coverage to work. But it is still not quite right. The following files were added, deleted, or modified: modified: ../build.xml new file: org.jacoco.agent-0.7.7.201606060606.jar new file: org.jacoco.ant-0.7.7.201606060606.jar deleted: org.jacoco.core-0.7.3.201409180205.jar new file: org.jacoco.core-0.7.7.201606060606.jar deleted: org.jacoco.report-0.7.3.201409180205.jar new file: org.jacoco.report-0.7.7.201606060606.jar modified: ../src/edu/rice/cs/drjava/model/coverage/MemoryClassLoader.java modified: ../src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java
1 parent 50bdbb6 commit 96d25da

9 files changed

+39
-28
lines changed

drjava/build.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666

6767
<fileset id="libs" dir="lib" includes="*.jar" /> <!-- Only include jars that are at the top level (not in buildlib) -->
6868
<fileset id="jrelibs" dir="${java.home}/lib" includes="*.jar" />
69-
<echo message="jrelibs = ${jrelibs}" />
69+
<echo message="libs = ${toString:libs}" />
70+
<echo message="jrelibs = ${toString:jrelibs}" />
7071
<fileset id="extlibs" dir="${java.home}/lib/ext" includes="*.jar" />
71-
<echo message="${extlibs}" />
72+
<echo message="extlibs = ${toString:extlibs}" />
7273
<!-- Use ConcJUnit if use-concjunit is not defined and we are not running Java 7. -->
7374
<!-- ConcJUnit is currently incompatible with Java 7. -->
7475
<!-- ConcJunit is causing problems with unit testing on Mac OS x platforms; defeating it here
@@ -215,7 +216,7 @@
215216
<move todir="classes/base">
216217
<fileset dir="classes/test" includes="**/*" />
217218
</move>
218-
<echo message="jrelibs=${jrelibs}" />
219+
<echo message="jrelibs=${toString:jrelibs}" />
219220
<javac srcdir="src" destdir="classes/base" source="1.7" target="1.7"
220221
bootclasspath="${java8-runtime}" sourcepath="" includeAntRuntime="no"
221222
executable="${java8-home}/bin/javac" fork="yes" memoryMaximumSize="1024M"
233 KB
Binary file not shown.
38 KB
Binary file not shown.
-116 KB
Binary file not shown.
135 KB
Binary file not shown.
-124 KB
Binary file not shown.
138 KB
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/coverage/MemoryClassLoader.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
import java.util.HashMap;
55
import java.lang.ClassLoader;
66

7-
/**
8-
* A class loader that loads classes from in-memory data.
9-
*/
7+
import edu.rice.cs.util.Log;
8+
9+
/** A class loader that loads classes from in-memory data. */
1010
public class MemoryClassLoader extends ClassLoader {
11+
12+
private static final Log _log = new Log("JUnitTestManager.txt", true);
13+
14+
public MemoryClassLoader(ClassLoader parent) { super(parent); }
1115

1216
private final Map<String, byte[]> definitions =
1317
new HashMap<String, byte[]>();
1418

15-
/**
16-
* Add a in-memory representation of a class.
17-
*
18-
* @param name name of the class
19-
* @param bytes class definition
20-
*/
19+
/** Add a in-memory representation of a class.
20+
* @param name name of the class
21+
* @param bytes class definition
22+
*/
2123
public void addDefinition(final String name, final byte[] bytes) {
2224
definitions.put(name, bytes);
2325
}
@@ -29,6 +31,7 @@ protected Class<?> loadClass(final String name, final boolean resolve)
2931
if (bytes != null) {
3032
return defineClass(name, bytes, 0, bytes.length);
3133
}
34+
_log.log("Calling loadClass(" + name + ", " + resolve + ")");
3235
return super.loadClass(name, resolve);
3336
}
3437
}

drjava/src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
import java.util.Map;
4949
import java.util.ArrayList;
5050

51+
import edu.rice.cs.drjava.model.coverage.*;
52+
import edu.rice.cs.drjava.model.compiler.LanguageLevelStackTraceMapper;
5153
import edu.rice.cs.util.Log;
54+
import edu.rice.cs.util.UnexpectedException;
5255
import edu.rice.cs.util.classloader.ClassFileError;
5356
import edu.rice.cs.plt.io.IOUtil;
5457
import edu.rice.cs.plt.lambda.Lambda;
@@ -61,8 +64,6 @@
6164
import static edu.rice.cs.plt.debug.DebugUtil.debug;
6265
import static edu.rice.cs.plt.debug.DebugUtil.error;
6366

64-
import edu.rice.cs.drjava.model.compiler.LanguageLevelStackTraceMapper;
65-
6667
import org.jacoco.core.analysis.Analyzer;
6768
import org.jacoco.core.analysis.CoverageBuilder;
6869
import org.jacoco.core.analysis.IBundleCoverage;
@@ -72,7 +73,7 @@
7273
import org.jacoco.core.runtime.IRuntime;
7374
import org.jacoco.core.runtime.LoggerRuntime;
7475
import org.jacoco.core.runtime.RuntimeData;
75-
import edu.rice.cs.drjava.model.coverage.*;
76+
7677

7778
import edu.rice.cs.util.UnexpectedException;
7879
import edu.rice.cs.util.swing.Utilities;
@@ -112,9 +113,9 @@ public class JUnitTestManager {
112113
private JUnitResultTuple lastResult = new JUnitResultTuple(false, null);
113114

114115
/** Standard constructor
115-
* @param jmc a JUnitModelCallback
116-
* @param loaderFactory factory to create class loaders
117-
*/
116+
* @param jmc a JUnitModelCallback
117+
* @param loaderFactory factory to create class loaders
118+
*/
118119
public JUnitTestManager(JUnitModelCallback jmc, Lambda<ClassLoader, ClassLoader> loaderFactory) {
119120
_jmc = jmc;
120121
_loaderFactory = loaderFactory;
@@ -172,24 +173,27 @@ public List<String> findTestClasses(final List<String> classNames,
172173
}
173174
}
174175

175-
loader = new MemoryClassLoader();
176+
loader = new MemoryClassLoader(JUnitTestManager.class.getClassLoader());
176177
for (int i = 0; i < classNames.size(); i++) {
177178
String name = classNames.get(i);
178179
byte[] code = instrumenteds.get(i);
179180
_log.log("Loading class file for '" + name + "' consisting of " + code.length + " bytes");
180181
((MemoryClassLoader)loader).addDefinition(classNames.get(i), instrumenteds.get(i));
181182
}
182183

184+
_log.log("Instrumented class files defined in MemoryClassLoader");
183185
try {
184186
this.runtime.startup(myData);
185187
} catch (Exception e) {
188+
_log.log("In code coverage startup, throwing wrapped exception " + e);
186189
throw new UnexpectedException(e);
187190
}
188191
}
189192

190193
if (_testClassNames != null && ! _testClassNames.isEmpty())
191194
throw new IllegalStateException("Test suite is still pending!");
192195

196+
_log.log("Preparing to run test cases");
193197
_testRunner = makeRunner(loader);
194198

195199
_testClassNames = new ArrayList<String>();
@@ -204,7 +208,9 @@ public List<String> findTestClasses(final List<String> classNames,
204208
if (_isJUnitTest(possibleTest)) {
205209
_testClassNames.add(cName);
206210
_testFiles.add(pair.second());
207-
_suite.addTest(new JUnit4TestAdapter(possibleTest));
211+
Test test = new JUnit4TestAdapter(possibleTest);
212+
_suite.addTest(test);
213+
_log.log("Adding test " + test + " to test suite");
208214
}
209215
}
210216
catch (ClassNotFoundException e) { error.log(e); }
@@ -239,7 +245,7 @@ public List<String> findTestClasses(final List<String> classNames,
239245
// Utilities.show("runTestSuite() in SlaveJVM called");
240246

241247
try {
242-
// System.err.println("Calling _testRunner.runSuite(...)");
248+
_log.log("Calling _testRunner.runSuite(" + _suite + ")");
243249
TestResult result = _testRunner.runSuite(_suite);
244250

245251
JUnitError[] errors = new JUnitError[result.errorCount() + result.failureCount()];
@@ -340,7 +346,8 @@ private boolean _isJUnitTest(Class<?> c) {
340346
boolean isAssignable = Test.class.isAssignableFrom(c);
341347
boolean isAbstract = Modifier.isAbstract(c.getModifiers());
342348
boolean isInterface = Modifier.isInterface(c.getModifiers());
343-
JUnit4TestAdapter a = new JUnit4TestAdapter(c);
349+
JUnit4TestAdapter a = new JUnit4TestAdapter(c);
350+
_log.log("a.getTests() = " + a.getTests());
344351
boolean isJUnit4Test = (a.getTests().size() > 0) && ! a.getTests().get(0).toString().contains("initializationError");
345352
//had to add specific check for initializationError. Is there a better way of checking if a class contains a test?
346353

@@ -494,10 +501,10 @@ private JUnitError _makeJUnitError(TestFailure failure, List<String> classNames,
494501
}
495502

496503
/** Parses the line number out of the stack trace in the given class name.
497-
* @param sw stack trace
498-
* @param classname class in which stack trace was generated
499-
* @return the line number
500-
*/
504+
* @param sw stack trace
505+
* @param classname class in which stack trace was generated
506+
* @return the line number
507+
*/
501508
private int _lineNumber(String sw, String classname) {
502509
// TODO: use stack trace elements to find line number
503510
int lineNum;
@@ -520,8 +527,8 @@ private int _lineNumber(String sw, String classname) {
520527
}
521528

522529
/** @param current template for the runner's class loader
523-
* @return a fresh JUnitTestRunner with its own class loader instance.
524-
*/
530+
* @return a fresh JUnitTestRunner with its own class loader instance.
531+
*/
525532
private JUnitTestRunner makeRunner(ClassLoader current) {
526533
return new JUnitTestRunner(_jmc, _loaderFactory.value(current));
527534
}

0 commit comments

Comments
 (0)