Skip to content

Add an option to execute the plugin with a custom encoding setting #70

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

Closed
Closed
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------
Expand Down Expand Up @@ -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"
```
3 changes: 3 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageAggregate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +35,8 @@ class ScoverageExtension {
List<String> excludedPackages = []
/** regex for each excluded file */
List<String> excludedFiles = []
/** Custom encoding to run the report application with */
String encoding

FileCollection pluginClasspath

Expand Down Expand Up @@ -146,10 +150,23 @@ class ScoverageExtension {
if (extension.highlighting) {
parameters.add('-Yrangepos')
}
if (extension.encoding) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part was not actually necessary in my build, but I suspect that this is only because I was using the Gradle daemon, where as in the case of not using it, it may be that the other settings (in the fork options) will be irrelevant and this one will actually matter.

parameters.add("-Dfile.encoding=$extension.encoding".toString())
}
doFirst {
GFileUtils.deleteDirectory(destinationDir)
}
scalaCompileOptions.additionalParameters = parameters

if (extension.encoding) {
List<String> forkOptions = ["-Dfile.encoding=$extension.encoding".toString()]
List<String> 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'))
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/groovy/org/scoverage/ScoverageReport.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down