Skip to content

Commit

Permalink
workaround for ant scalac task not handling arguments with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
maiflai committed Dec 28, 2014
1 parent 23c79e5 commit a8a19c7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 21 additions & 11 deletions src/main/groovy/org/scoverage/ScoverageExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -83,24 +95,22 @@ class ScoverageExtension {
FileCollection pluginDependencies = configuration.filter { it != pluginFile }

t.tasks[ScoveragePlugin.COMPILE_NAME].configure {


List<String> plugin = ['-Xplugin:' + pluginFile.absolutePath]
List<String> parameters = scalaCompileOptions.additionalParameters
if (parameters != null) {
plugin.addAll(parameters)
List<String> parameters = ['-Xplugin:' + pluginFile.absolutePath]
List<String> 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
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/groovy/org/scoverage/ScoverageExtensionTest.groovy
Original file line number Diff line number Diff line change
@@ -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)))
}
}

0 comments on commit a8a19c7

Please sign in to comment.