Skip to content

Commit 7576b7f

Browse files
committed
pass the desired JaCoCo report outdir through to the tester
1 parent edbbbc9 commit 7576b7f

File tree

9 files changed

+115
-560
lines changed

9 files changed

+115
-560
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*BEGIN_COPYRIGHT_BLOCK
2+
*
3+
* Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*
29+
* This software is Open Source Initiative approved Open Source Software.
30+
* Open Source Initative Approved is a trademark of the Open Source Initiative.
31+
*
32+
* This file is part of DrJava. Download the current version of this project
33+
* from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
34+
*
35+
* END_COPYRIGHT_BLOCK*/
36+
37+
package edu.rice.cs.drjava.model.coverage;
38+
39+
import java.io.Serializable;
40+
41+
public class CoverageMetadata implements Serializable {
42+
43+
private boolean doCoverage;
44+
private String outputDirectory;
45+
46+
public CoverageMetadata(boolean doCoverage, String outputDirectory) {
47+
this.doCoverage = doCoverage;
48+
this.outputDirectory = outputDirectory;
49+
}
50+
51+
public boolean getFlag() {
52+
return this.doCoverage;
53+
}
54+
55+
public String getOutdirPath() {
56+
return this.outputDirectory;
57+
}
58+
}

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@
8787
import static edu.rice.cs.plt.debug.DebugUtil.debug;
8888
import edu.rice.cs.drjava.model.compiler.LanguageLevelStackTraceMapper;
8989

90+
import edu.rice.cs.drjava.model.coverage.CoverageMetadata;
91+
9092
/** Manages unit testing via JUnit.
9193
* @version $Id$
9294
*/
9395
public class DefaultJUnitModel implements JUnitModel, JUnitModelCallback {
94-
95-
private boolean coverage = false;
96+
97+
private CoverageMetadata coverageMetadata = null;
9698

9799
/** log for use in debugging */
98100
private static Log _log = new Log("DefaultJUnitModel.txt", false);
@@ -145,14 +147,20 @@ public DefaultJUnitModel(MainJVM jvm, CompilerModel compilerModel, GlobalModel m
145147

146148
//-------------------------- Field Setters --------------------------------//
147149

148-
public void setCoverage(boolean c) { this.coverage = c; }
150+
public void setCoverage(boolean coverage, String outdirPath) {
151+
this.coverageMetadata = new CoverageMetadata(coverage, outdirPath);
152+
}
153+
149154
public void setForceTestSuffix(boolean b) { _forceTestSuffix = b; }
150155

151156
//------------------------ Simple Predicates ------------------------------//
152157

153158
public boolean isTestInProgress() { return _testInProgress; }
154159
public JUnitResultTuple getResult() { return this.result; }
155-
public boolean getCoverage() { return this.coverage; }
160+
161+
public boolean getCoverage() {
162+
return (this.coverageMetadata != null) ? this.coverageMetadata.getFlag() : false;
163+
}
156164

157165
//------------------------Listener Management -----------------------------//
158166

@@ -498,7 +506,8 @@ public void run() {
498506
synchronized(_compilerModel.getCompilerLock()) {
499507
// synchronized over _compilerModel to ensure that compilation and junit testing are mutually exclusive.
500508
/** Set up junit test suite on slave JVM; get TestCase classes forming that suite */
501-
List<String> tests = _jvm.findTestClasses(classNames, files, coverage).unwrap(null);
509+
List<String> tests = _jvm.findTestClasses(classNames, files,
510+
coverageMetadata).unwrap(null);
502511

503512
if (tests == null || tests.isEmpty()) {
504513
nonTestCase(allTests, false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public interface JUnitModel {
4747

4848

4949
/** set the forceTestSuffix flag that forces class names in projects to end in "Test */
50-
public void setCoverage(boolean c);
50+
public void setCoverage(boolean c, String p);
5151
public void setForceTestSuffix(boolean b);
5252

5353
public JUnitResultTuple getResult();

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class JUnitTestManager {
105105
private List<File> _testFiles = null;
106106

107107
// For JaCoCo
108+
private String coverageOutdir = null;
108109
private IRuntime runtime = null;
109110
private RuntimeData myData = null;
110111
private List<String> classNames = null;
@@ -122,7 +123,9 @@ public JUnitTestManager(JUnitModelCallback jmc, Lambda<ClassLoader, ClassLoader>
122123
* @param files the files corresponding to classNames
123124
*/
124125
public List<String> findTestClasses(final List<String> classNames,
125-
final List<File> files, boolean doCoverage) {
126+
final List<File> files, CoverageMetadata coverageMetadata) {
127+
128+
boolean doCoverage = coverageMetadata.getFlag();
126129

127130
// Set up the loader
128131
final ClassLoader loader;
@@ -131,6 +134,7 @@ public List<String> findTestClasses(final List<String> classNames,
131134
} else {
132135

133136
// JaCoCo: Create instrumented versions of class files.
137+
this.coverageOutdir = coverageMetadata.getOutdirPath();
134138
this.runtime = new LoggerRuntime();
135139
this.myData = new RuntimeData();
136140
this.classNames = classNames;
@@ -256,16 +260,18 @@ public List<String> findTestClasses(final List<String> classNames,
256260
_jmc.testSuiteEnded(errors);
257261

258262

259-
if (this.runtime != null) {
263+
if (this.runtime != null) { /* doCoverage was true */
260264

261-
// Collect session info (including which code was executed)
265+
/* Collect session info (including which code was executed) */
262266
final ExecutionDataStore executionData = new ExecutionDataStore();
263267
final SessionInfoStore sessionInfos = new SessionInfoStore();
264268
myData.collect(executionData, sessionInfos, false);
265269
this.runtime.shutdown();
266270

267-
// Together with the original class definition we can calculate coverage
268-
// information:
271+
/**
272+
* Together with the original class definitions we can calculate
273+
* coverage information
274+
*/
269275
final CoverageBuilder coverageBuilder = new CoverageBuilder();
270276
final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
271277

@@ -276,15 +282,18 @@ public List<String> findTestClasses(final List<String> classNames,
276282
replace(".java", ".class")), this.classNames.get(j));
277283
}
278284

279-
// Run the structure analyzer on a single class folder to build up
280-
// the coverage model. The process would be similar if your classes
281-
// were in a jar file. Typically you would create a bundle for each
282-
// class folder and each jar you want in your report. If you have
283-
// more than one bundle you will need to add a grouping node to your
284-
// report
285+
/**
286+
* Run the structure analyzer on a single class folder to build up
287+
* the coverage model. The process would be similar if the classes
288+
* were in a jar file; typically you would create a bundle for each
289+
* class folder and each jar you want in your report. If you have
290+
* more than one bundle you will need to add a grouping node to your
291+
* report
292+
*/
285293
final IBundleCoverage bundleCoverage = coverageBuilder.getBundle(
286294
this.files.get(0).getParentFile().getName());
287-
ReportGenerator rg = new ReportGenerator("/tmp/", coverageBuilder);
295+
ReportGenerator rg = new ReportGenerator(this.coverageOutdir,
296+
coverageBuilder);
288297
rg.createReport(bundleCoverage, executionData,
289298
sessionInfos, this.files.get(0).getParentFile());
290299
lineColors = rg.getAllLineColors();
@@ -295,7 +304,7 @@ public List<String> findTestClasses(final List<String> classNames,
295304
Utilities.show(stackTrace.toString());
296305
}
297306

298-
// Reset the runtime
307+
/* Reset the runtime */
299308
this.runtime = null;
300309
}
301310
}

drjava/src/edu/rice/cs/drjava/model/repl/newjvm/InterpreterJVM.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import edu.rice.cs.drjava.model.junit.JUnitTestManager;
6565
import edu.rice.cs.drjava.model.junit.JUnitError;
6666
import edu.rice.cs.drjava.model.junit.JUnitResultTuple;
67+
import edu.rice.cs.drjava.model.coverage.CoverageMetadata;
6768
import edu.rice.cs.drjava.model.repl.InteractionsPaneOptions;
6869

6970
import edu.rice.cs.dynamicjava.Options;
@@ -522,8 +523,8 @@ public void setRequireVariableType(boolean require) {
522523
* @return the class names that are actually test cases
523524
*/
524525
public List<String> findTestClasses(List<String> classNames,
525-
List<File> files, boolean doCoverage) throws RemoteException {
526-
return _junitTestManager.findTestClasses(classNames, files, doCoverage);
526+
List<File> files, CoverageMetadata coverageMetadata) throws RemoteException {
527+
return _junitTestManager.findTestClasses(classNames, files, coverageMetadata);
527528
}
528529

529530
/** Runs JUnit test suite already cached in the Interpreter JVM. Unsynchronized because it contains a remote call

drjava/src/edu/rice/cs/drjava/model/repl/newjvm/InterpreterJVMRemoteI.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@
4343
import edu.rice.cs.plt.tuple.Pair;
4444
import edu.rice.cs.util.newjvm.*;
4545
import edu.rice.cs.drjava.model.junit.JUnitResultTuple;
46+
import edu.rice.cs.drjava.model.coverage.CoverageMetadata;
4647

4748
/** This interface specifies the methods that the interpreter JVM exposes for the MainJVM to call.
4849
* @version $Id$
4950
*/
5051
public interface InterpreterJVMRemoteI extends SlaveRemote {
5152

5253
public List<String> findTestClasses(List<String> classNames,
53-
List<File> files, boolean doCoverage) throws RemoteException;
54+
List<File> files, CoverageMetadata coverageMetadata) throws RemoteException;
5455

5556
public JUnitResultTuple runTestSuite() throws RemoteException;
5657

drjava/src/edu/rice/cs/drjava/model/repl/newjvm/MainJVM.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import edu.rice.cs.drjava.model.junit.JUnitError;
5252
import edu.rice.cs.drjava.model.junit.JUnitModelCallback;
5353
import edu.rice.cs.drjava.model.junit.JUnitResultTuple;
54+
import edu.rice.cs.drjava.model.coverage.CoverageMetadata;
5455
import edu.rice.cs.drjava.model.debug.DebugModelCallback;
5556
import edu.rice.cs.drjava.platform.PlatformFactory;
5657
import edu.rice.cs.drjava.ui.DrJavaErrorHandler;
@@ -460,11 +461,18 @@ public boolean setPackageScope(String packageName) {
460461
* @return the class names that are actually test cases
461462
*/
462463
public Option<List<String>> findTestClasses(List<String> classNames,
463-
List<File> files, boolean doCoverage) {
464+
List<File> files, CoverageMetadata coverageMetadata) {
464465
InterpreterJVMRemoteI remote = _state.value().interpreter(false);
465-
if (remote == null) { return Option.none(); }
466-
try { return Option.some(remote.findTestClasses(classNames, files, doCoverage)); }
467-
catch (RemoteException e) { _handleRemoteException(e); return Option.none(); }
466+
if (remote == null) {
467+
return Option.none();
468+
}
469+
470+
try {
471+
return Option.some(remote.findTestClasses(classNames, files, coverageMetadata));
472+
} catch (RemoteException e) {
473+
_handleRemoteException(e);
474+
return Option.none();
475+
}
468476
}
469477

470478
/**

drjava/src/edu/rice/cs/drjava/ui/coverage/CoverageFrame.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void displayReport() {
172172
}
173173

174174
//this.highlight(_model.getJUnitModel().getResult().getLineColors(), false);
175-
this._model.getJUnitModel().setCoverage(false);
175+
this._model.getJUnitModel().setCoverage(false, "");
176176
}
177177

178178
/**
@@ -295,7 +295,8 @@ private void cancel() {
295295
* Begins JUnit testing with code coverage.
296296
*/
297297
private void startJUnit(){
298-
_model.getJUnitModel().setCoverage(true);
298+
_model.getJUnitModel().setCoverage(true,
299+
this._outputDirSelector.getFileFromField().getPath());
299300
_mainFrame._junitAll();
300301
CoverageFrame.this.setVisible(false);
301302
}

0 commit comments

Comments
 (0)