Skip to content

Commit f61c719

Browse files
committed
Improved the way that output is managed and generated
1 parent e234dba commit f61c719

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed

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

+5-17
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,19 @@ import std.TaskStreams
88
*/
99
trait CucumberIntegration {
1010

11-
protected def optionsForReporting(htmlReportDir: Option[File],
12-
jsonReportFile: Option[File],
13-
junitReportFile: Option[File]): List[String] = {
14-
(Some("--format" :: "pretty" :: Nil) ::
15-
(htmlReportDir map { dir =>
16-
dir.mkdirs()
17-
"--format" :: "html:%s".format(dir.getPath) :: Nil }) ::
18-
(jsonReportFile map { file =>
19-
file.getParentFile.mkdirs()
20-
"--format" :: "json-pretty:%s".format(file.getPath) :: Nil }) ::
21-
(junitReportFile map { file =>
22-
file.getParentFile.mkdirs()
23-
"--format" :: "junit:%s".format(file.getPath) :: Nil }) :: Nil).flatten.flatten
24-
}
25-
2611
protected def testWithCucumber(args: Seq[String],
2712
cucumberSettings: CucumberSettings,
2813
cucumberOptions: CucumberOptions,
14+
cucumberOutput: CucumberOutput,
2915
s: TaskStreams[_]) = {
3016
val log = s.log
3117

3218
if ( cucumberOptions.featuresPresent ) {
3319
log.debug("Cucumber Settings: %s".format(cucumberSettings))
3420
log.debug("Cucumber Options: %s".format(cucumberOptions))
21+
log.debug("Cucumber Output: %s".format(cucumberOutput))
3522

36-
runCucumber(args, cucumberSettings, cucumberOptions, log)
23+
runCucumber(args, cucumberSettings, cucumberOptions, cucumberOutput, log)
3724
}
3825
else {
3926
log.info("No features directory found. Skipping for curent project.")
@@ -44,6 +31,7 @@ trait CucumberIntegration {
4431
private def runCucumber(args: Seq[String],
4532
cucumberSettings: CucumberSettings,
4633
cucumberOptions: CucumberOptions,
34+
cucumberOutput: CucumberOutput,
4735
log: Logger) = {
4836
def tagsFromArgs(args: Seq[String]) = args.filter(isATag).toList
4937
def namesFromArgs(args: Seq[String]) = args.filter(isNotATag).toList
@@ -56,7 +44,7 @@ trait CucumberIntegration {
5644
val cucumber = Cucumber(cucumberSettings.classpath, cucumberSettings.outputStrategy,
5745
Some(cucumberSettings.maxMemory), Some(cucumberSettings.maxPermGen))
5846
val result = cucumber.cuke(cucumberOptions.featuresDir, cucumberOptions.basePackage,
59-
cucumberOptions.options, tagsFromArgs(args), namesFromArgs(args))
47+
cucumberOptions.options ++ cucumberOutput.options, tagsFromArgs(args), namesFromArgs(args))
6048
cucumberOptions.afterFunc()
6149
result
6250
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package templemore.xsbt.cucumber
2+
3+
import java.io.File
4+
5+
/**
6+
* @author Chris Turner
7+
*/
8+
case class CucumberOutput(prettyReport: Boolean, htmlReport: Boolean, junitReport: Boolean, jsonReport: Boolean,
9+
prettyReportFile: File, htmlReportDir: File, junitReportFile: File, jsonReportFile: File) {
10+
11+
def options: List[String] = {
12+
(if (prettyReport) {
13+
prettyReportFile.getParentFile.mkdirs()
14+
"--format" :: "progress" :: "--format" :: "pretty:%s".format(prettyReportFile.getPath) :: Nil
15+
}
16+
else "--format" :: "pretty" :: Nil) ++
17+
(if ( htmlReport) {
18+
htmlReportDir.mkdirs()
19+
"--format" :: "html:%s".format(htmlReportDir.getPath) :: Nil
20+
} else Nil) ++
21+
(if ( junitReport) {
22+
junitReportFile.getParentFile.mkdirs()
23+
"--format" :: "junit:%s".format(junitReportFile.getPath) :: Nil
24+
} else Nil) ++
25+
(if ( jsonReport) {
26+
jsonReportFile.getParentFile.mkdirs()
27+
"--format" :: "json-pretty:%s".format(jsonReportFile.getPath) :: Nil
28+
} else Nil)
29+
}
30+
}

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

+32-11
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,30 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
1717
val cucumber = InputKey[Int]("cucumber")
1818
val cucumberTestSettings = TaskKey[CucumberSettings]("cucumber-settings")
1919
val cucumberOptions = TaskKey[CucumberOptions]("cucumber-options")
20+
val cucumberOutput = TaskKey[CucumberOutput]("cucumber-output")
2021

2122
val cucumberMaxMemory = SettingKey[String]("cucumber-max-memory")
2223
val cucumberMaxPermGen = SettingKey[String]("cucumber-max-perm-gen")
2324

2425
val cucumberFeaturesDir = SettingKey[File]("cucumber-features-directory")
2526
val cucumberStepsBasePackage = SettingKey[String]("cucumber-steps-base-package")
26-
val cucumberExtraOptions = SettingKey[Seq[String]]("cucumber-extra-options")
27+
val cucumberExtraOptions = SettingKey[List[String]]("cucumber-extra-options")
2728

28-
val cucumberHtmlReportDir = SettingKey[Option[File]]("cucumber-html-report")
29-
val cucumberJsonReportFile = SettingKey[Option[File]]("cucumber-json-report")
30-
val cucumberJunitReportFile = SettingKey[Option[File]]("cucumber-junit-report")
29+
val cucumberPrettyReport = SettingKey[Boolean]("cucumber-pretty-report")
30+
val cucumberHtmlReport = SettingKey[Boolean]("cucumber-html-report")
31+
val cucumberJunitReport = SettingKey[Boolean]("cucumber-junit-report")
32+
val cucumberJsonReport = SettingKey[Boolean]("cucumber-json-report")
33+
34+
val cucumberPrettyReportFile = SettingKey[File]("cucumber-pretty-report-file")
35+
val cucumberHtmlReportDir = SettingKey[File]("cucumber-html-report-dir")
36+
val cucumberJsonReportFile = SettingKey[File]("cucumber-json-report-file")
37+
val cucumberJunitReportFile = SettingKey[File]("cucumber-junit-report-file")
3138

3239
val cucumberBefore = SettingKey[LifecycleCallback]("cucumber-before")
3340
val cucumberAfter = SettingKey[LifecycleCallback]("cucumber-after")
3441

3542
protected def cucumberTask(argTask: TaskKey[Seq[String]]) =
36-
(argTask, cucumberTestSettings, cucumberOptions, streams) map(testWithCucumber)
43+
(argTask, cucumberTestSettings, cucumberOptions, cucumberOutput, streams) map(testWithCucumber)
3744

3845
protected def cucumberSettingsTask: Initialize[Task[CucumberSettings]] =
3946
(cucumberMaxMemory, cucumberMaxPermGen, fullClasspath in Test, streams) map {
@@ -44,10 +51,17 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
4451

4552
protected def cucumberOptionsTask: Initialize[Task[CucumberOptions]] =
4653
(cucumberFeaturesDir, cucumberStepsBasePackage, cucumberExtraOptions,
47-
cucumberHtmlReportDir, cucumberJsonReportFile, cucumberJunitReportFile,
4854
cucumberBefore, cucumberAfter) map {
49-
(fd, bp, o, htmlRD, jsonRF, junitRF, bf, af) => {
50-
CucumberOptions(fd, bp, optionsForReporting(htmlRD, jsonRF, junitRF) ++ o, bf, af)
55+
(fd, bp, o, bf, af) => {
56+
CucumberOptions(fd, bp, o, bf, af)
57+
}
58+
}
59+
60+
protected def cucumberOutputTask: Initialize[Task[CucumberOutput]] =
61+
(cucumberPrettyReport, cucumberHtmlReport, cucumberJunitReport, cucumberJsonReport,
62+
cucumberPrettyReportFile, cucumberHtmlReportDir, cucumberJunitReportFile, cucumberJsonReportFile) map {
63+
(pR, hR, juR, jsR, pRF, hRD, juRF, jsRF) => {
64+
CucumberOutput(pR, hR, juR, jsR, pRF, hRD, juRF, jsRF)
5165
}
5266
}
5367

@@ -65,6 +79,7 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
6579
cucumber <<= inputTask(cucumberTask),
6680
cucumberTestSettings <<= cucumberSettingsTask,
6781
cucumberOptions <<= cucumberOptionsTask,
82+
cucumberOutput <<= cucumberOutputTask,
6883

6984
cucumberMaxMemory := "256M",
7085
cucumberMaxPermGen := "64M",
@@ -73,9 +88,15 @@ object CucumberPlugin extends Plugin with CucumberIntegration {
7388
cucumberStepsBasePackage := "",
7489
cucumberExtraOptions := List[String](),
7590

76-
cucumberHtmlReportDir := None,
77-
cucumberJsonReportFile := None,
78-
cucumberJunitReportFile := None,
91+
cucumberPrettyReport := false,
92+
cucumberHtmlReport := false,
93+
cucumberJunitReport := false,
94+
cucumberJsonReport := false,
95+
96+
cucumberPrettyReportFile <<= (scalaVersion, target) { (sv, t) => t / "scala-%s".format(sv) / "cucumber.txt" },
97+
cucumberHtmlReportDir <<= (scalaVersion, target) { (sv, t) => t / "scala-%s".format(sv) / "cucumber-report" },
98+
cucumberJsonReportFile <<= (scalaVersion, target) { (sv, t) => t / "scala-%s".format(sv) / "cucumber.json" },
99+
cucumberJunitReportFile <<= (scalaVersion, target) { (sv, t) => t / "scala-%s".format(sv) / "cucumber.xml" },
79100

80101
cucumberBefore := defaultBefore,
81102
cucumberAfter := defaultAfter

testProjects/multiModuleTestProject/project/Build.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ object BuildSettings {
1111
Seq (organization := buildOrganization,
1212
scalaVersion := buildScalaVersion,
1313
version := buildVersion) ++
14-
CucumberPlugin.cucumberSettings
14+
CucumberPlugin.cucumberSettings ++
15+
Seq (CucumberPlugin.cucumberHtmlReport := true,
16+
CucumberPlugin.cucumberPrettyReport := true)
1517
}
1618

1719
object Dependencies {

testProjects/testProject/build.sbt

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ seq(cucumberSettings : _*)
1414

1515
cucumberStepsBasePackage := "test"
1616

17-
cucumberHtmlReportDir <<= (target) { d => Some(d / "cucumber-report") }
17+
cucumberHtmlReport := true
1818

19-
cucumberJsonReportFile <<= (target) { f => Some(f / "cucumber.json") }
19+
cucumberJunitReport := true
2020

21-
cucumberJunitReportFile <<= (target) { f => Some(f / "cucumber-junit.xml") }
21+
cucumberJsonReport := true

0 commit comments

Comments
 (0)