diff --git a/build.gradle b/build.gradle index f174b65..677b2d5 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ configurations { dependencies { compile gradleApi() compile localGroovy() - scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:1.0.1' + scoverage 'org.scoverage:scalac-scoverage-plugin_2.11:1.0.2' } task groovydocJar(type: Jar, dependsOn: groovydoc) { diff --git a/src/main/groovy/org/scoverage/ScoverageExtension.groovy b/src/main/groovy/org/scoverage/ScoverageExtension.groovy index 14cc301..7b0d14b 100644 --- a/src/main/groovy/org/scoverage/ScoverageExtension.groovy +++ b/src/main/groovy/org/scoverage/ScoverageExtension.groovy @@ -17,6 +17,18 @@ import org.gradle.api.tasks.testing.Test */ class ScoverageExtension { + private static boolean isEscaped(String argument) { + return (argument.startsWith('"') && argument.endsWith('"')) || (argument.startsWith('\'') && argument.endsWith('\'')) + } + + static String escape(String argument) { + if (isEscaped(argument)) { + return argument + } else { + return "\"$argument\"" + } + } + /** a directory to write working files to */ File dataDir /** a directory to write final output to */ @@ -83,24 +95,22 @@ class ScoverageExtension { FileCollection pluginDependencies = configuration.filter { it != pluginFile } t.tasks[ScoveragePlugin.COMPILE_NAME].configure { - - - List plugin = ['-Xplugin:' + pluginFile.absolutePath] - List parameters = scalaCompileOptions.additionalParameters - if (parameters != null) { - plugin.addAll(parameters) + List parameters = ['-Xplugin:' + pluginFile.absolutePath] + List existingParameters = scalaCompileOptions.additionalParameters + if (existingParameters) { + parameters.addAll(existingParameters) } - plugin.add("-P:scoverage:dataDir:${extension.dataDir.absolutePath}".toString()) + parameters.add("-P:scoverage:dataDir:${extension.dataDir.absolutePath}".toString()) if (extension.excludedPackages) { - plugin.add("-P:scoverage:excludedPackages:${extension.excludedPackages.join(';')}".toString()) + parameters.add("-P:scoverage:excludedPackages:${extension.excludedPackages.join(';')}".toString()) } if (extension.excludedFiles) { - plugin.add("-P:scoverage:excludedFiles:${extension.excludedFiles.join(';')}".toString()) + parameters.add("-P:scoverage:excludedFiles:${extension.excludedFiles.join(';')}".toString()) } if (extension.highlighting) { - plugin.add('-Yrangepos') + parameters.add('-Yrangepos') } - scalaCompileOptions.additionalParameters = plugin + scalaCompileOptions.additionalParameters = parameters.collect { escape(it) } // exclude the scala libraries that are added to enable scala version detection classpath += pluginDependencies } diff --git a/src/test/groovy/org/scoverage/ScoverageExtensionTest.groovy b/src/test/groovy/org/scoverage/ScoverageExtensionTest.groovy new file mode 100644 index 0000000..e8572ce --- /dev/null +++ b/src/test/groovy/org/scoverage/ScoverageExtensionTest.groovy @@ -0,0 +1,21 @@ +package org.scoverage + +import org.junit.Test + +import static org.hamcrest.CoreMatchers.equalTo +import static org.hamcrest.MatcherAssert.assertThat + +class ScoverageExtensionTest { + + static def quote(String s) { '\'' + s + '\'' } + + static def doubleQuote(String s) { '"' + s + '"' } + + @Test + public void testStringEscaping() throws Exception { + def parameter = 'my param' + assertThat(ScoverageExtension.escape(parameter), equalTo(doubleQuote(parameter))) + assertThat(ScoverageExtension.escape(quote(parameter)), equalTo(quote(parameter))) + assertThat(ScoverageExtension.escape(doubleQuote(parameter)), equalTo(doubleQuote(parameter))) + } +}