diff --git a/README.md b/README.md index 77de109..2ee52ee 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ You can configure output generated by `gradle reportScoverage` using flags: | coverageOutputXML | true | Enables/disables scoverage XML output. | | coverageOutputHTML | true | Enables/disables scoverage HTML output. | | coverageDebug | false | Enables/disables scoverage debug output. | +| encoding | null | Sets encoding (otherwise uses system default). | Aggregating Reports ------------------- @@ -97,3 +98,22 @@ checkScoverage { minimumRate = 0.5 } ``` + +Troubleshooting +-------------- + +### Encoding + +You may encounter the following exceptions when executing the `reportScoverage` task: + +```text +Exception in thread "main" java.nio.charset.UnmappableCharacterException: Input length = 1 + +Exception in thread "main" java.nio.charset.MalformedInputException: Input length = 1 +``` + +There is a good chance that this is a problem with encoding. You could try and resolve these by configuring the encoding +to the encoding of you sources. For example: +```groovy +scoverage.encoding = "UTF-8" +``` \ No newline at end of file diff --git a/src/main/groovy/org/scoverage/ScoverageAggregate.groovy b/src/main/groovy/org/scoverage/ScoverageAggregate.groovy index 8703d09..35b5068 100644 --- a/src/main/groovy/org/scoverage/ScoverageAggregate.groovy +++ b/src/main/groovy/org/scoverage/ScoverageAggregate.groovy @@ -12,6 +12,9 @@ class ScoverageAggregate extends JavaExec { def extension = ScoveragePlugin.extensionIn(project) setClasspath(ScoveragePlugin.extensionIn(project).pluginClasspath) setMain('org.scoverage.AggregateReportApp') + if (extension.encoding) { + jvmArgs("-Dfile.encoding=$extension.encoding") + } def reportPath = reportDirOrDefault() setArgs([ project.projectDir, diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index f866287..42cafe2 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -9,7 +9,9 @@ import org.gradle.api.plugins.JavaPlugin import org.gradle.api.plugins.scala.ScalaPlugin import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.bundling.Jar +import org.gradle.api.tasks.scala.ScalaCompile import org.gradle.api.tasks.testing.Test +import org.gradle.language.scala.tasks.AbstractScalaCompile import org.gradle.util.GFileUtils import java.util.concurrent.Callable @@ -33,6 +35,8 @@ class ScoverageExtension { List excludedPackages = [] /** regex for each excluded file */ List excludedFiles = [] + /** Custom encoding to run the report application with */ + String encoding FileCollection pluginClasspath @@ -146,10 +150,23 @@ class ScoverageExtension { if (extension.highlighting) { parameters.add('-Yrangepos') } + if (extension.encoding) { + parameters.add("-Dfile.encoding=$extension.encoding".toString()) + } doFirst { GFileUtils.deleteDirectory(destinationDir) } scalaCompileOptions.additionalParameters = parameters + + if (extension.encoding) { + List forkOptions = ["-Dfile.encoding=$extension.encoding".toString()] + List existingForkOptions = scalaCompileOptions.forkOptions.jvmArgs + if (existingForkOptions) { + forkOptions.addAll(existingForkOptions) + } + scalaCompileOptions.forkOptions.jvmArgs = forkOptions + } + // the compile task creates a store of measured statements outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml')) } diff --git a/src/main/groovy/org/scoverage/ScoverageReport.groovy b/src/main/groovy/org/scoverage/ScoverageReport.groovy index ab1f1b7..fded6ff 100644 --- a/src/main/groovy/org/scoverage/ScoverageReport.groovy +++ b/src/main/groovy/org/scoverage/ScoverageReport.groovy @@ -10,6 +10,9 @@ class ScoverageReport extends JavaExec { extension.reportDir.mkdirs() setClasspath(extension.pluginClasspath) setMain('org.scoverage.SingleReportApp') + if (extension.encoding) { + jvmArgs("-Dfile.encoding=$extension.encoding") + } setArgs([ /* sourceDir = */ extension.sources.absolutePath, /* dataDir = */ extension.dataDir.absolutePath,