-
Notifications
You must be signed in to change notification settings - Fork 127
provide a CLI for writing reports from generated results #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package scoverage.report | ||
|
||
import java.io.File | ||
|
||
import org.rogach.scallop.ArgType.V | ||
import org.rogach.scallop.{singleArgConverter, ValueConverter, Scallop} | ||
import scoverage.{IOUtils, Serializer, Constants, Coverage} | ||
|
||
import language.implicitConversions | ||
|
||
object ReportWriter { | ||
|
||
private def dir(base: File, name: String) = { | ||
val directory = new File(base, name) | ||
directory.mkdirs() | ||
directory | ||
} | ||
|
||
def writeReports(outputDirectory: File, | ||
baseDirectory: File, | ||
coverage: Coverage, | ||
coverageOutputCobertura: Boolean, | ||
coverageOutputXML: Boolean, | ||
coverageOutputHTML: Boolean, | ||
coverageDebug: Boolean): Unit = { | ||
|
||
if (coverageOutputCobertura) { | ||
new CoberturaXmlWriter(baseDirectory, dir(outputDirectory, "cobertura")).write(coverage) | ||
} | ||
|
||
if (coverageOutputXML) { | ||
val xmlDir = dir(outputDirectory, "xml") | ||
new ScoverageXmlWriter(baseDirectory, xmlDir, false).write(coverage) | ||
if (coverageDebug) { | ||
new ScoverageXmlWriter(baseDirectory, xmlDir, true).write(coverage) | ||
} | ||
} | ||
|
||
if (coverageOutputHTML) { | ||
new ScoverageHtmlWriter(baseDirectory, dir(outputDirectory, "html")).write(coverage) | ||
} | ||
|
||
} | ||
} | ||
|
||
object Reports extends App { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems from their documentation that |
||
|
||
private val defaultsToTrue = () => Some(true) | ||
private implicit val stringToFile = singleArgConverter(new File(_)) | ||
|
||
val BASE_DIR: String = "base-dir" | ||
val OUTPUT_DIR: String = "output-dir" | ||
val AGGREGATE_SUB_PROJECTS: String = "aggregate" | ||
val CLEAN_AGGREGATED_FILES: String = "clean" | ||
val SINGLE_DATA_DIR: String = "data-dir" | ||
val OUTPUT_COBERTURA_XML: String = "cobertura" | ||
val OUTPUT_SCOVERAGE_DEBUG_XML: String = "debug" | ||
val OUTPUT_SCOVERAGE_XML: String = "xml" | ||
val OUTPUT_SCOVERAGE_HTML: String = "html" | ||
|
||
private val opts = Scallop(args) | ||
.opt[File](BASE_DIR, required = true) | ||
.opt[File](OUTPUT_DIR, required = true) | ||
.opt[Boolean](AGGREGATE_SUB_PROJECTS, required = false, default = () => None) | ||
.opt[File](SINGLE_DATA_DIR, required = false, validate = f => Serializer.coverageFile(f).exists()) | ||
.opt[Boolean](CLEAN_AGGREGATED_FILES, default = defaultsToTrue) | ||
.opt[Boolean](OUTPUT_SCOVERAGE_DEBUG_XML, default = defaultsToTrue) | ||
.opt[Boolean](OUTPUT_COBERTURA_XML, default = defaultsToTrue) | ||
.opt[Boolean](OUTPUT_SCOVERAGE_XML, default = defaultsToTrue) | ||
.opt[Boolean](OUTPUT_SCOVERAGE_HTML, default = defaultsToTrue) | ||
.verify | ||
|
||
private val baseDir = opts[File](BASE_DIR) | ||
|
||
private val coverage: Option[Coverage] = { | ||
// opts.get[_] appears not to work as expected here | ||
(opts.isSupplied(SINGLE_DATA_DIR), opts.isSupplied(AGGREGATE_SUB_PROJECTS)) match { | ||
case (true, false) => | ||
val dataDir = opts[File](SINGLE_DATA_DIR) | ||
val coverageFile = Serializer.coverageFile(dataDir) | ||
if (coverageFile.exists()) { | ||
val coverage = Serializer.deserialize(coverageFile) | ||
val measurementFiles = IOUtils.findMeasurementFiles(dataDir) | ||
val measurements = IOUtils.invoked(measurementFiles) | ||
coverage.apply(measurements) | ||
Some(coverage) | ||
} else { | ||
None | ||
} | ||
case (false, true) => | ||
CoverageAggregator.aggregate(baseDir, opts[Boolean](CLEAN_AGGREGATED_FILES)) | ||
case (true, true)=> | ||
Console.err.println(s"Cannot specify $SINGLE_DATA_DIR and $AGGREGATE_SUB_PROJECTS") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like to have messages prefixed with plugin name, like |
||
None | ||
case (false, false) => | ||
Console.err.println(s"Must specify $SINGLE_DATA_DIR or $AGGREGATE_SUB_PROJECTS") | ||
None | ||
} | ||
} | ||
|
||
coverage match { | ||
case Some(data) => | ||
ReportWriter.writeReports( | ||
opts[File](OUTPUT_DIR), | ||
baseDir, | ||
data, | ||
opts[Boolean](OUTPUT_COBERTURA_XML), | ||
opts[Boolean](OUTPUT_SCOVERAGE_XML), | ||
opts[Boolean](OUTPUT_SCOVERAGE_HTML), | ||
opts[Boolean](OUTPUT_SCOVERAGE_DEBUG_XML)) | ||
println("Wrote reports") | ||
case None => | ||
Console.err.println(s"No coverage found") | ||
sys.exit(1) | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like you put all reports in separate directories 👍