Skip to content

Commit f2bd00b

Browse files
committed
Added the ability to supply system properties and other jvm arguments to the jvm that is started for running cucumber.
Fixed a couple of minor errors in the documentation.
1 parent 2cf0da0 commit f2bd00b

File tree

13 files changed

+44
-18
lines changed

13 files changed

+44
-18
lines changed

README.markdown

+9-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ To install the cucumber plugin, add entries to the build plugins file (project/p
7777

7878
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
7979

80-
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.0")
80+
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.1")
8181

8282
### Basic Configuration ###
8383
To add the cucumber plugin settings to a basic project, just add the following to the build.sbt file:
@@ -127,8 +127,10 @@ If none of the above are set to true then the default output is pretty printed f
127127
* cucumberJsonReportFile - The location of the JSON format report file. Defaults fo a java.io.File of ./target/scala-{scalaVersion}/cucumber.json
128128

129129
### JVM Settings ###
130-
* cucumberMaxMemory - The maximum JVM memory to allocate to the JRuby process. Defaults to the string "256M"
131-
* cucumberMaxPermGen - The maximum PermGen space for the JRuby process. Defaults to the string "64M"
130+
* cucumberMaxMemory - The maximum JVM memory to allocate to the JVM process. Defaults to the string "256M"
131+
* cucumberMaxPermGen - The maximum PermGen space for the JVM process. Defaults to the string "64M"
132+
* cucumberSystemProperties - System properties to be passed to the JVM process using the -D flag. Defaults to and empty Map[String, String]
133+
* cucumberJVMOptions - Additional options to be passed to the JVM that runs cucumber. Defaults to an empty List[String]
132134

133135
### Lifecycle Settings ###
134136
* cucumberBefore - A function of type () => Unit that will be run BEFORE cucumber is executed. Defaults to a no-op function
@@ -141,6 +143,10 @@ Requests for features can be posted to the issues list or emailed to the author.
141143

142144
## Release History ##
143145

146+
### 0.6.1 ###
147+
Update to allow system properties and other JVM arguments to be passed to the JVM that runs cucumber.
148+
Corrections to documentation.
149+
144150
### 0.6.0 ###
145151
Updated to work the SBT 0.12.0, Scala 2.9.2 and the latest Cucumber-jvm 1.0.14 versions.
146152

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "xsbt-cucumber-plugin"
22

3-
version := "0.6.0"
3+
version := "0.6.1"
44

55
organization := "templemore"
66

src/main/scala/templemore/xsbt/cucumber/Cucumber.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ import sbt.OutputStrategy
99
*/
1010
case class Cucumber(classpath: List[File],
1111
outputStrategy: OutputStrategy,
12+
systemProperties: Map[String, String],
13+
jvmOptions: List[String],
1214
overrideMaxMemory: Option[String] = None,
1315
overrideMaxPermGen: Option[String] = None) {
1416

1517
private val maxMemory = overrideMaxMemory.getOrElse("256M")
1618
private val maxPermGen = overrideMaxPermGen.getOrElse("64M")
1719

18-
private val jvmArgs = "-classpath" :: makeClasspath(classpath) ::
19-
("-Xmx%s" format maxMemory) :: ("-XX:MaxPermSize=%s" format maxPermGen) :: Nil
20+
private val jvmArgs = ("-classpath" :: makeClasspath ::
21+
("-Xmx%s" format maxMemory) :: ("-XX:MaxPermSize=%s" format maxPermGen) :: Nil) ++
22+
makeSystemProperties ++ jvmOptions
2023

2124
def cuke(featuresDir: File, basePackage: String, options: List[String] = List(),
2225
tags: List[String] = List(), names: List[String] = List()): Int = {
@@ -30,6 +33,7 @@ case class Cucumber(classpath: List[File],
3033
Fork.java(None, args, None, Map.empty[String, String], outputStrategy)
3134
}
3235

33-
protected def makeClasspath(pathElements: List[File]) = pathElements.map(_.getPath).mkString(File.pathSeparator)
36+
protected def makeClasspath = classpath.map(_.getPath).mkString(File.pathSeparator)
3437
protected def makeOptionsList(options: List[String], flag: String) = options flatMap(List(flag, _))
38+
protected def makeSystemProperties = systemProperties.toList map (entry => "-D%s=%s".format(entry._1, entry._2))
3539
}

src/main/scala/templemore/xsbt/cucumber/CucumberIntegration.scala

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ trait CucumberIntegration {
4242
log.info("Running cucumber...")
4343
cucumberOptions.beforeFunc()
4444
val cucumber = Cucumber(cucumberSettings.classpath, cucumberSettings.outputStrategy,
45+
cucumberSettings.systemProperties, cucumberSettings.jvmOptions,
4546
Some(cucumberSettings.maxMemory), Some(cucumberSettings.maxPermGen))
4647
val result = cucumber.cuke(cucumberOptions.featuresDir, cucumberOptions.basePackage,
4748
cucumberOptions.options ++ cucumberOutput.options, tagsFromArgs(args), namesFromArgs(args))

src/main/scala/templemore/xsbt/cucumber/CucumberPlugin.scala

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
2121

2222
val cucumberMaxMemory = SettingKey[String]("cucumber-max-memory")
2323
val cucumberMaxPermGen = SettingKey[String]("cucumber-max-perm-gen")
24+
val cucumberSystemProperties = SettingKey[Map[String, String]]("cucumber-system-properties")
25+
val cucumberJVMOptions = SettingKey[List[String]]("cucumber-jvm-options")
2426

2527
val cucumberFeaturesDir = SettingKey[File]("cucumber-features-directory")
2628
val cucumberStepsBasePackage = SettingKey[String]("cucumber-steps-base-package")
@@ -43,9 +45,9 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
4345
(argTask, cucumberTestSettings, cucumberOptions, cucumberOutput, streams) map(testWithCucumber)
4446

4547
protected def cucumberSettingsTask: Initialize[Task[CucumberSettings]] =
46-
(cucumberMaxMemory, cucumberMaxPermGen, fullClasspath in Test, streams) map {
47-
(mm, mpg, cp, s) => {
48-
CucumberSettings(mm, mpg, cp.toList.map(_.data), LoggedOutput(s.log))
48+
(cucumberMaxMemory, cucumberMaxPermGen, cucumberSystemProperties, cucumberJVMOptions, fullClasspath in Test, streams) map {
49+
(mm, mpg, sp, jvmopt, cp, s) => {
50+
CucumberSettings(mm, mpg, sp, jvmopt, cp.toList.map(_.data), LoggedOutput(s.log))
4951
}
5052
}
5153

@@ -83,10 +85,12 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
8385

8486
cucumberMaxMemory := "256M",
8587
cucumberMaxPermGen := "64M",
88+
cucumberSystemProperties := Map.empty[String, String],
89+
cucumberJVMOptions := Nil,
8690

8791
cucumberFeaturesDir <<= (baseDirectory) { _ / "src" / "test" / "features" },
8892
cucumberStepsBasePackage := "",
89-
cucumberExtraOptions := List[String](),
93+
cucumberExtraOptions := List.empty[String],
9094

9195
cucumberPrettyReport := false,
9296
cucumberHtmlReport := false,

src/main/scala/templemore/xsbt/cucumber/CucumberSettings.scala

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import sbt.OutputStrategy
88
*/
99
case class CucumberSettings(maxMemory: String,
1010
maxPermGen: String,
11+
systemProperties: Map[String, String],
12+
jvmOptions: List[String],
1113
classpath: List[File],
1214
outputStrategy: OutputStrategy)
1315

testProjects/multiModuleTestProject/project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import templemore.xsbt.cucumber.CucumberPlugin
55
object BuildSettings {
66
val buildOrganization = "templemore"
77
val buildScalaVersion = "2.9.2"
8-
val buildVersion = "0.6.0"
8+
val buildVersion = "0.6.1"
99

1010
val buildSettings = Defaults.defaultSettings ++
1111
Seq (organization := buildOrganization,
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
resolvers += Resolver.file("Local Repo", file((Path.userHome / ".m2" / "repository").toString))
22

3-
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.0")
3+
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.1")

testProjects/testProject/build.sbt

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "test-project"
22

3-
version := "0.6.0"
3+
version := "0.6.1"
44

55
organization := "templemore"
66

@@ -19,3 +19,8 @@ cucumberHtmlReport := true
1919
cucumberJunitReport := true
2020

2121
cucumberJsonReport := true
22+
23+
cucumberSystemProperties := Map("testing" -> "true", "demo" -> "yes")
24+
25+
cucumberJVMOptions := List("-showversion", "-esa")
26+

testProjects/testProject/project/plugin.sbt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
resolvers += Resolver.file("Local Repo", file((Path.userHome / ".m2" / "repository").toString))
1+
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo"
2+
3+
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.1")
4+
25

3-
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.0")

testProjects/testProject/src/test/scala/test/CucumberJarStepDefinitions.scala

+2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ class CucumberJarStepDefinitions extends ScalaDsl with EN with ShouldMatchers {
1919
Then("""^Cucumber is executed against the features and step definitions$""") { () =>
2020
givenCalled should be (true)
2121
whenCalled should be (true)
22+
System.getProperty("testing") should be ("true")
23+
System.getProperty("demo") should be ("yes")
2224
}
2325
}

testProjects/testProject2_10/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name := "test-project"
22

3-
version := "0.6.0"
3+
version := "0.6.1"
44

55
organization := "templemore"
66

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
resolvers += Resolver.file("Local Repo", file((Path.userHome / ".m2" / "repository").toString))
22

3-
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.0")
3+
addSbtPlugin("templemore" % "xsbt-cucumber-plugin" % "0.6.1")

0 commit comments

Comments
 (0)