forked from skipoleschris/xsbt-cucumber-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further work on allowiung cucumber to work as either a standalone 'cu…
…cumber' task or as part of the built in 'test' task. - Added a launcher for launching cucumber reflectively using a supplied test class loader - Refinements to the TestFramework class for implementing into SBT as a standard test library - The features directory now defaults to being the root of the classpath rather than src/test/features - Added a new project that demonstrated how to wite up the test integration - Plugin now provides a group of settings that enable test integration
- Loading branch information
1 parent
0fbc9a0
commit 0ec12b2
Showing
13 changed files
with
135 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
integration/src/main/scala/templemore/sbt/cucumber/ReflectingCucumberLauncher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package templemore.sbt.cucumber | ||
|
||
import java.lang.reflect.InvocationTargetException | ||
import java.util.Properties | ||
|
||
class ReflectingCucumberLauncher(debug: (String) => Unit, error: (String) => Unit) { | ||
|
||
private val RuntimeOptionsClassName = "cucumber.runtime.RuntimeOptions" | ||
private val MultiLoaderClassName = "cucumber.runtime.io.MultiLoader" | ||
private val MultiLoaderClassName_1_0_9 = "cucumber.io.MultiLoader" | ||
private val RuntimeClassName = "cucumber.runtime.Runtime" | ||
|
||
def apply(cucumberArguments: Array[String], | ||
testClassLoader: ClassLoader): Int = { | ||
debug("Cucumber arguments: " + cucumberArguments.mkString(" ")) | ||
val runtime = buildRuntime(System.getProperties, cucumberArguments, testClassLoader) | ||
runCucumber(runtime).asInstanceOf[Byte].intValue | ||
} | ||
|
||
private def runCucumber(runtime: AnyRef) = try { | ||
val runtimeClass = runtime.getClass | ||
runtimeClass.getMethod("writeStepdefsJson").invoke(runtime) | ||
runtimeClass.getMethod("run").invoke(runtime) | ||
runtimeClass.getMethod("exitStatus").invoke(runtime) | ||
} catch { | ||
case e: InvocationTargetException => { | ||
val cause = if ( e.getCause == null ) e else e.getCause | ||
error("Error running cucumber. Cause: " + cause.getMessage) | ||
throw cause | ||
} | ||
} | ||
|
||
private def buildRuntime(properties: Properties, | ||
arguments: Array[String], | ||
classLoader: ClassLoader): AnyRef = { | ||
def buildLoader(clazz: Class[_]) = | ||
clazz.getConstructor(classOf[ClassLoader]).newInstance(classLoader).asInstanceOf[AnyRef] | ||
def buildOptions(clazz: Class[_]) = | ||
clazz.getConstructor(classOf[Properties], classOf[Array[String]]).newInstance(properties.asInstanceOf[AnyRef], arguments).asInstanceOf[AnyRef] | ||
|
||
val (runtimeClass, optionsClass, loaderClass) = loadCucumberClasses(classLoader) | ||
val runtimeConstructor = runtimeClass.getConstructor(loaderClass.getInterfaces()(0), classOf[ClassLoader], optionsClass) | ||
runtimeConstructor.newInstance(buildLoader(loaderClass), classLoader, buildOptions(optionsClass)).asInstanceOf[AnyRef] | ||
} | ||
|
||
private def loadCucumberClasses(classLoader: ClassLoader) = try { | ||
val multiLoaderClassName = cucumberVersion(classLoader) match { | ||
case "1.0.9" => MultiLoaderClassName_1_0_9 | ||
case _ => MultiLoaderClassName | ||
} | ||
|
||
val runtimeOptionsClass = classLoader.loadClass(RuntimeOptionsClassName) | ||
val multiLoaderClass = classLoader.loadClass(multiLoaderClassName) | ||
val runtimeClass = classLoader.loadClass(RuntimeClassName) | ||
(runtimeClass, runtimeOptionsClass, multiLoaderClass) | ||
} catch { | ||
case e: ClassNotFoundException => | ||
error("Unable to load Cucumber classes. Please check your project dependencied. (Details: " + e.getMessage + ")") | ||
throw e | ||
} | ||
|
||
private def cucumberVersion(classLoader: ClassLoader) = { | ||
val stream = classLoader.getResourceAsStream("cucumber/version.properties") | ||
try { | ||
val props = new Properties() | ||
props.load(stream) | ||
val version = props.getProperty("cucumber-jvm.version") | ||
debug("Determined cucumber-jvm version to be: " + version) | ||
version | ||
} finally { | ||
stream.close() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
target | ||
project/boot | ||
project/target | ||
project/plugins/target | ||
project/plugins/project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
...s/testInterfaceProject/project/plugin.sbt → ...testIntegrationProject/project/plugin.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
resolvers += "Templemore Repository" at "http://templemore.co.uk/repo" | ||
|
||
addSbtPlugin("templemore" % "sbt-cucumber-plugin" % "0.7.0") | ||
|
||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.