Skip to content

encoding #71

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
wants to merge 4 commits into from
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
2 changes: 0 additions & 2 deletions src/main/groovy/org/scoverage/AggregateReportApp.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.scoverage;

import scoverage.Coverage;
import scoverage.report.CoberturaXmlWriter;
import scoverage.report.CoverageAggregator;
import scoverage.report.ScoverageHtmlWriter;

import java.io.File;

Expand Down
8 changes: 7 additions & 1 deletion src/main/groovy/org/scoverage/OverallCheckTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ class OverallCheckTask extends DefaultTask {
File reportFile = new File(reportDir ? reportDir : extension.reportDir, coverageType.fileName)

try {
Node xml = parser.parse(reportFile)
String encoding = ScoveragePlugin.encoding(project)
Node xml
if (encoding) {
xml = parser.parse(new InputStreamReader(new FileInputStream(reportFile), encoding))
} else {
xml = parser.parse(reportFile)
}
NumberFormat nf = NumberFormat.getInstance(locale == null ? Locale.getDefault() : locale);
Double coverageValue = nf.parse(xml.attribute(coverageType.paramName) as String).doubleValue();
Double overallRate = coverageType.normalize(coverageValue)
Expand Down
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 @@ -12,6 +12,10 @@ class ScoverageAggregate extends JavaExec {
def extension = ScoveragePlugin.extensionIn(project)
setClasspath(ScoveragePlugin.extensionIn(project).pluginClasspath)
setMain('org.scoverage.AggregateReportApp')
String encoding = ScoveragePlugin.encoding(project)
if (encoding) {
jvmArgs("-Dfile.encoding=$encoding")
}
def reportPath = reportDirOrDefault()
setArgs([
project.projectDir,
Expand Down
20 changes: 12 additions & 8 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class ScoverageExtension {

ScoverageExtension(Project project) {

project.plugins.apply(JavaPlugin.class);
project.plugins.apply(ScalaPlugin.class);
project.plugins.apply(JavaPlugin.class)
project.plugins.apply(ScalaPlugin.class)
project.afterEvaluate(configureRuntimeOptions)

project.configurations.create(ScoveragePlugin.CONFIGURATION_NAME) {
Expand Down Expand Up @@ -76,7 +76,7 @@ class ScoverageExtension {
runtimeClasspath = it.output + mainSourceSet.output + project.configurations.scoverage + original.runtimeClasspath
}

def scoverageJar = project.tasks.create('jarScoverage', Jar.class) {
project.tasks.create('jarScoverage', Jar.class) {
dependsOn('scoverageClasses')
classifier = ScoveragePlugin.CONFIGURATION_NAME
from mainSourceSet.output
Expand All @@ -87,13 +87,13 @@ class ScoverageExtension {

project.tasks.create(ScoveragePlugin.TEST_NAME, Test.class) {
conventionMapping.map("testClassesDir", new Callable<Object>() {
public Object call() throws Exception {
return testSourceSet.output.classesDir;
Object call() throws Exception {
return testSourceSet.output.classesDir
}
})
conventionMapping.map("classpath", new Callable<Object>() {
public Object call() throws Exception {
return testSourceSet.runtimeClasspath;
Object call() throws Exception {
return testSourceSet.runtimeClasspath
}
})
}
Expand Down Expand Up @@ -126,7 +126,7 @@ class ScoverageExtension {
File pluginFile
try {
pluginFile = configuration.filter { it.name.contains('plugin') }.iterator().next()
} catch(NoSuchElementException e) {
} catch (NoSuchElementException ignored) {
throw new GradleException("Could not find a plugin jar in configuration '${ScoveragePlugin.CONFIGURATION_NAME}'")
}

Expand All @@ -150,6 +150,10 @@ class ScoverageExtension {
GFileUtils.deleteDirectory(destinationDir)
}
scalaCompileOptions.additionalParameters = parameters
String encoding = scalaCompileOptions.encoding
if (encoding) {
scalaCompileOptions.forkOptions.jvmArgs.add('-Dfile.encoding=' + encoding)
}
// the compile task creates a store of measured statements
outputs.file(new File(extension.dataDir, 'scoverage.coverage.xml'))
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/groovy/org/scoverage/ScoveragePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.scoverage

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.scala.ScalaCompile

class ScoveragePlugin implements Plugin<Project> {
static String CONFIGURATION_NAME = 'scoverage'
Expand All @@ -22,4 +23,9 @@ class ScoveragePlugin implements Plugin<Project> {
protected static ScoverageExtension extensionIn(Project project) {
project.extensions[CONFIGURATION_NAME]
}

protected static String encoding(Project project) {
ScalaCompile compile = project.tasks[ScoveragePlugin.COMPILE_NAME] as ScalaCompile
compile.scalaCompileOptions.encoding
}
}
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 @@ -8,6 +8,10 @@ class ScoverageReport extends JavaExec {
void exec() {
def extension = ScoveragePlugin.extensionIn(project)
extension.reportDir.mkdirs()
String encoding = ScoveragePlugin.encoding(project)
if (encoding) {
jvmArgs("-Dfile.encoding=$encoding")
}
setClasspath(extension.pluginClasspath)
setMain('org.scoverage.SingleReportApp')
setArgs([
Expand Down