Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageAggregate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class ScoverageAggregate extends DefaultTask {
@Input
final Property<Boolean> deleteReportsOnAggregation = project.objects.property(Boolean)

@Input
final Property<String> sourceEncoding = project.objects.property(String)

// TODO - consider separate options for `report` and `aggregate` tasks
@Input
final Property<Boolean> coverageOutputCobertura = project.objects.property(Boolean)
Expand Down Expand Up @@ -60,6 +63,7 @@ class ScoverageAggregate extends DefaultTask {
rootDir,
reportDir.get(),
coverage.get(),
sourceEncoding.get(),
coverageOutputCobertura.get(),
coverageOutputXML.get(),
coverageOutputHTML.get(),
Expand Down
9 changes: 9 additions & 0 deletions src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ class ScoveragePlugin implements Plugin<PluginAware> {
def globalReportTask = project.tasks.register(REPORT_NAME, ScoverageAggregate)
def globalCheckTask = project.tasks.register(CHECK_NAME, OverallCheckTask)


project.afterEvaluate {
def detectedSourceEncoding = compileTask.scalaCompileOptions.encoding
if (detectedSourceEncoding == null) {
detectedSourceEncoding = "UTF-8"
}

// calling toList() on TaskCollection is required
// to avoid potential ConcurrentModificationException in multi-project builds
def testTasks = project.tasks.withType(Test).toList()
Expand All @@ -123,6 +129,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
reportDir = taskReportDir
sources = extension.sources
dataDir = extension.dataDir
sourceEncoding.set(detectedSourceEncoding)
coverageOutputCobertura = extension.coverageOutputCobertura
coverageOutputXML = extension.coverageOutputXML
coverageOutputHTML = extension.coverageOutputHTML
Expand All @@ -139,6 +146,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
group = 'verification'
runner = scoverageRunner
reportDir = extension.reportDir
sourceEncoding.set(detectedSourceEncoding)
dirsToAggregateFrom = reportDirs
deleteReportsOnAggregation = false
coverageOutputCobertura = extension.coverageOutputCobertura
Expand Down Expand Up @@ -171,6 +179,7 @@ class ScoveragePlugin implements Plugin<PluginAware> {
group = 'verification'
runner = scoverageRunner
reportDir = extension.reportDir
sourceEncoding.set(detectedSourceEncoding)
deleteReportsOnAggregation = extension.deleteReportsOnAggregation
coverageOutputCobertura = extension.coverageOutputCobertura
coverageOutputXML = extension.coverageOutputXML
Expand Down
4 changes: 4 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageReport.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ScoverageReport extends DefaultTask {
@OutputDirectory
final Property<File> reportDir = project.objects.property(File)

@Input
final Property<String> sourceEncoding = project.objects.property(String)

@Input
final Property<Boolean> coverageOutputCobertura = project.objects.property(Boolean)
@Input
Expand Down Expand Up @@ -59,6 +62,7 @@ class ScoverageReport extends DefaultTask {
sources.get(),
reportDir.get(),
coverage,
sourceEncoding.get(),
coverageOutputCobertura.get(),
coverageOutputXML.get(),
coverageOutputHTML.get(),
Expand Down
10 changes: 9 additions & 1 deletion src/main/groovy/org/scoverage/ScoverageWriter.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package org.scoverage;

import org.gradle.api.logging.Logger;
import scala.Some;
import scala.collection.JavaConverters;
import scala.collection.mutable.Buffer;
import scoverage.Constants;
import scoverage.Coverage;
import scoverage.report.CoberturaXmlWriter;
import scoverage.report.ScoverageHtmlWriter;
import scoverage.report.ScoverageXmlWriter;

import java.io.File;
import java.nio.charset.Charset;
import java.util.Arrays;

/**
* Util for generating and saving coverage files.
Expand All @@ -29,6 +34,7 @@ public ScoverageWriter(Logger logger) {
* @param sourceDir directory with project sources
* @param reportDir directory for generate reports
* @param coverage coverage data
* @param sourceEncoding the encoding of the source files
* @param coverageOutputCobertura switch for Cobertura output
* @param coverageOutputXML switch for Scoverage XML output
* @param coverageOutputHTML switch for Scoverage HTML output
Expand All @@ -37,6 +43,7 @@ public ScoverageWriter(Logger logger) {
public void write(File sourceDir,
File reportDir,
Coverage coverage,
String sourceEncoding,
Boolean coverageOutputCobertura,
Boolean coverageOutputXML,
Boolean coverageOutputHTML,
Expand Down Expand Up @@ -70,7 +77,8 @@ public void write(File sourceDir,
}

if (coverageOutputHTML) {
new ScoverageHtmlWriter(sourceDir, reportDir).write(coverage);
Buffer<File> sources = JavaConverters.asScalaBuffer(Arrays.asList(sourceDir));
new ScoverageHtmlWriter(sources, reportDir, new Some<>(sourceEncoding)).write(coverage);
logger.info("[scoverage] Written HTML report to " +
reportDir.getAbsolutePath() +
File.separator +
Expand Down