Browse files

Use a classpath: prefix if you want to load resources (features and s…

…tepdef scripts) from the classpath and not the file system. Should be a transparent change for JUnit users. See #312
  • Loading branch information...
1 parent 250a977 commit cdf108011510e7865b595ccc4ccbcdae514c959f @aslakhellesoy aslakhellesoy committed May 1, 2012
View
3 core/src/main/java/cucumber/cli/Main.java
@@ -1,6 +1,7 @@
package cucumber.cli;
import cucumber.io.FileResourceLoader;
+import cucumber.io.MultiLoader;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;
@@ -15,7 +16,7 @@ public static void main(String[] argv) throws Throwable {
public static void run(String[] argv, ClassLoader classLoader) throws IOException {
RuntimeOptions runtimeOptions = new RuntimeOptions(argv);
- Runtime runtime = new Runtime(new FileResourceLoader(), classLoader, runtimeOptions);
+ Runtime runtime = new Runtime(new MultiLoader(classLoader), classLoader, runtimeOptions);
runtime.writeStepdefsJson();
runtime.run();
System.exit(runtime.exitStatus());
View
22 core/src/main/java/cucumber/io/MultiLoader.java
@@ -0,0 +1,22 @@
+package cucumber.io;
+
+public class MultiLoader implements ResourceLoader {
+ public static final String CLASSPATH_SCHEME = "classpath://";
+
+ private final ClasspathResourceLoader classpath;
+ private final FileResourceLoader fs;
+
+ public MultiLoader(ClassLoader classLoader) {
+ classpath = new ClasspathResourceLoader(classLoader);
+ fs = new FileResourceLoader();
+ }
+
+ @Override
+ public Iterable<Resource> resources(String path, String suffix) {
+ if (path.startsWith(CLASSPATH_SCHEME)) {
+ return classpath.resources(path.substring(CLASSPATH_SCHEME.length()), suffix);
+ } else {
+ return fs.resources(path, suffix);
+ }
+ }
+}
View
1 core/src/main/java/cucumber/runtime/Runtime.java
@@ -1,6 +1,7 @@
package cucumber.runtime;
import cucumber.io.ClasspathResourceLoader;
+import cucumber.io.MultiLoader;
import cucumber.io.ResourceLoader;
import cucumber.runtime.converters.LocalizedXStreams;
import cucumber.runtime.model.CucumberFeature;
View
9 junit/src/main/java/cucumber/junit/Cucumber.java
@@ -1,6 +1,6 @@
package cucumber.junit;
-import cucumber.io.ClasspathResourceLoader;
+import cucumber.io.MultiLoader;
import cucumber.io.ResourceLoader;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Runtime;
@@ -49,11 +49,12 @@
public Cucumber(Class clazz) throws InitializationError, IOException {
super(clazz);
ClassLoader classLoader = clazz.getClassLoader();
- ResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
assertNoCucumberAnnotatedMethods(clazz);
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(clazz);
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
+
+ ResourceLoader resourceLoader = new MultiLoader(classLoader);
runtime = new Runtime(resourceLoader, classLoader, runtimeOptions);
jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader), runtimeOptions.strict);
@@ -119,9 +120,7 @@ private void addChildren(List<CucumberFeature> cucumberFeatures) throws Initiali
boolean dryRun() default false;
/**
- * Scenarios fail if
- *
- * @return
+ * @return true if strict mode is enabled (fail if there are undefined or pending steps)
*/
boolean strict() default false;
View
3 junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java
@@ -1,5 +1,6 @@
package cucumber.junit;
+import cucumber.io.MultiLoader;
import cucumber.runtime.RuntimeOptions;
import java.util.ArrayList;
@@ -95,7 +96,7 @@ private void addFeatures(Cucumber.Options options, Class clazz, List<String> arg
if (options != null && options.features().length != 0) {
Collections.addAll(args, options.features());
} else {
- args.add(packagePath(clazz));
+ args.add(MultiLoader.CLASSPATH_SCHEME + packagePath(clazz));
}
}
View
4 junit/src/test/java/cucumber/junit/CucumberTest.java
@@ -81,11 +81,11 @@ public void no_stepdefs_in_cucumber_runner_invalid() {
private class ImplicitPackage {
}
- @Cucumber.Options(features = {"cucumber/junit"})
+ @Cucumber.Options(features = {"classpath://cucumber/junit"})
private class ExplicitPackage {
}
- @Cucumber.Options(features = {"gibber/ish"})
+ @Cucumber.Options(features = {"classpath://gibber/ish"})
private class ExplicitPackageWithNoFeatures {
}
}

0 comments on commit cdf1080

Please sign in to comment.