Skip to content

Commit

Permalink
gluePath is the best name I have come up with for 'class path or scri…
Browse files Browse the repository at this point in the history
…pt path where stepdefs and hooks live'
  • Loading branch information
aslakhellesoy committed Oct 19, 2011
1 parent ed2927b commit 21afdd7
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 64 deletions.
Expand Up @@ -24,10 +24,10 @@ public ClojureBackend() throws ClassNotFoundException, IOException {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.world = world;
for (String codePath : codePaths) {
Resources.scan(codePath.replace('.', '/'), ".clj", new Consumer() {
for (String gluePath : gluePaths) {
Resources.scan(gluePath.replace('.', '/'), ".clj", new Consumer() {
public void consume(Resource resource) {
try {
RT.load(resource.getPath().replaceAll(".clj$", ""));
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/cucumber/cli/Main.java
Expand Up @@ -16,7 +16,7 @@ public class Main {

public static void main(String[] argv) {
List<String> filesOrDirs = new ArrayList<String>();
List<String> packageNamesOrScriptPaths = new ArrayList<String>();
List<String> gluePaths = new ArrayList<String>();
List<Object> filters = new ArrayList<Object>();
String format = "progress";
List<String> args = new ArrayList<String>(asList(argv));
Expand All @@ -31,7 +31,7 @@ public static void main(String[] argv) {
System.exit(0);
} else if (arg.equals("--glue") || arg.equals("-g")) {
String packageNameOrScriptPath = args.remove(0);
packageNamesOrScriptPaths.add(packageNameOrScriptPath);
gluePaths.add(packageNameOrScriptPath);
} else if (arg.equals("--tags") || arg.equals("-t")) {
filters.add(args.remove(0));
} else if (arg.equals("--format") || arg.equals("-f")) {
Expand All @@ -40,12 +40,12 @@ public static void main(String[] argv) {
filesOrDirs.add(arg);
}
}
if (packageNamesOrScriptPaths.isEmpty()) {
if (gluePaths.isEmpty()) {
System.out.println("Missing option: --glue");
System.exit(1);
}

Runtime runtime = new Runtime(packageNamesOrScriptPaths);
Runtime runtime = new Runtime(gluePaths);

FormatterFactory formatterReporterFactory = new FormatterFactory();
Formatter formatter = formatterReporterFactory.createFormatter(format, System.out);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runtime/Backend.java
Expand Up @@ -9,10 +9,10 @@ public interface Backend {
* Invoked before a new scenario starts. Implementations should do any necessary
* setup of new, isolated state here.
*
* @param codePaths
* @param gluePaths
* @param world
*/
void buildWorld(List<String> codePaths, World world);
void buildWorld(List<String> gluePaths, World world);

void disposeWorld();

Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/cucumber/runtime/Runtime.java
Expand Up @@ -22,19 +22,19 @@
public class Runtime {
private final List<Step> undefinedSteps = new ArrayList<Step>();
private final List<Backend> backends;
private final List<String> codePaths;
private final List<String> gluePaths;

public Runtime() {
this(System.getProperty("cucumber.glue") != null ? asList(System.getProperty("cucumber.glue").split(",")) : new ArrayList<String>());
}

public Runtime(List<String> codePaths) {
this(codePaths, Resources.instantiateSubclasses(Backend.class, "cucumber.runtime", new Class[0], new Object[0]));
public Runtime(List<String> gluePaths) {
this(gluePaths, Resources.instantiateSubclasses(Backend.class, "cucumber.runtime", new Class[0], new Object[0]));
}

public Runtime(List<String> codePaths, List<Backend> backends) {
public Runtime(List<String> gluePaths, List<Backend> backends) {
this.backends = backends;
this.codePaths = codePaths;
this.gluePaths = gluePaths;
}

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ public void run(CucumberFeature cucumberFeature, Formatter formatter, Reporter r
formatter.uri(cucumberFeature.getUri());
formatter.feature(cucumberFeature.getFeature());
for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) {
cucumberTagStatement.run(formatter, reporter, this, backends, codePaths);
cucumberTagStatement.run(formatter, reporter, this, backends, gluePaths);
}
}

Expand All @@ -98,9 +98,9 @@ public void consume(Resource resource) {
return cucumberFeatures;
}

public void buildWorlds(List<String> codePaths, World world) {
public void buildWorlds(List<String> gluePaths, World world) {
for (Backend backend : backends) {
backend.buildWorld(codePaths, world);
backend.buildWorld(gluePaths, world);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/cucumber/runtime/World.java
Expand Up @@ -32,8 +32,8 @@ public World(Runtime runtime, Collection<String> tags) {
this.tags = tags;
}

public void prepare(List<String> codePaths) {
runtime.buildWorlds(codePaths, this);
public void prepare(List<String> gluePaths) {
runtime.buildWorlds(gluePaths, this);

scenarioResult = new ScenarioResultImpl();
Collections.sort(beforeHooks, new HookComparator(true));
Expand Down
Expand Up @@ -27,19 +27,19 @@ public CucumberScenario(CucumberFeature cucumberFeature, CucumberBackground cucu
this.cucumberBackground = cucumberBackground;
}

public void createWorld(List<String> codePaths, Runtime runtime) {
public void createWorld(List<String> gluePaths, Runtime runtime) {
world = new World(runtime, tags());
world.prepare(codePaths);
world.prepare(gluePaths);
}

@Override
public void run(Formatter formatter, Reporter reporter, Runtime runtime, List<Backend> backends, List<String> codePaths) {
public void run(Formatter formatter, Reporter reporter, Runtime runtime, List<Backend> backends, List<String> gluePaths) {
// TODO: Maybe get extraPaths from scenario

// TODO: split up prepareAndFormat so we can run Background in isolation.
// Or maybe just try to make Background behave like a regular Scenario?? Printing wise at least.

createWorld(codePaths, runtime);
createWorld(gluePaths, runtime);

runBackground(formatter, reporter);

Expand Down
Expand Up @@ -29,7 +29,7 @@ public List<CucumberExamples> getCucumberExamplesList() {
}

@Override
public void run(Formatter formatter, Reporter reporter, Runtime runtime, List<Backend> backends, List<String> codePaths) {
public void run(Formatter formatter, Reporter reporter, Runtime runtime, List<Backend> backends, List<String> gluePaths) {
throw new UnsupportedOperationException();
}

Expand Down
Expand Up @@ -45,5 +45,5 @@ public String getVisualName() {
return visualName;
}

public abstract void run(Formatter formatter, Reporter reporter, Runtime runtime, List<Backend> backends, List<String> codePaths);
public abstract void run(Formatter formatter, Reporter reporter, Runtime runtime, List<Backend> backends, List<String> gluePaths);
}
2 changes: 1 addition & 1 deletion core/src/test/java/cucumber/runtime/BackgroundTest.java
Expand Up @@ -42,7 +42,7 @@ public void should_run_background() {

private class TestBackend implements Backend {
@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
}

@Override
Expand Down
Expand Up @@ -29,10 +29,10 @@ public GroovyBackend() {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.world = world;
for (String codePath : codePaths) {
Resources.scan(codePath.replace('.', '/'), ".groovy", new Consumer() {
for (String gluePath : gluePaths) {
Resources.scan(gluePath.replace('.', '/'), ".groovy", new Consumer() {
public void consume(Resource resource) {
shell.evaluate(resource.getString(), resource.getPath());
}
Expand Down
6 changes: 3 additions & 3 deletions ioke/src/main/java/cucumber/runtime/ioke/IokeBackend.java
Expand Up @@ -38,10 +38,10 @@ public IokeBackend() {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.world = world;
for (String codePath : codePaths) {
Resources.scan(codePath.replace('.', '/'), ".ik", new Consumer() {
for (String gluePath : gluePaths) {
Resources.scan(gluePath.replace('.', '/'), ".ik", new Consumer() {
public void consume(Resource resource) {
try {
currentLocation = resource.getPath();
Expand Down
6 changes: 3 additions & 3 deletions java/src/main/java/cucumber/runtime/java/JavaBackend.java
Expand Up @@ -31,10 +31,10 @@ public JavaBackend(ObjectFactory objectFactory) {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.world = world;
for (String codePath : codePaths) {
classpathMethodScanner.scan(this, codePath);
for (String gluePath : gluePaths) {
classpathMethodScanner.scan(this, gluePath);
}
objectFactory.createInstances();
}
Expand Down
6 changes: 3 additions & 3 deletions jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java
Expand Up @@ -24,11 +24,11 @@ public JRubyBackend() throws UnsupportedEncodingException {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.world = world;
jruby.put("$world", new Object());
for (String codePath : codePaths) {
Resources.scan(codePath.replace('.', '/'), ".rb", new Consumer() {
for (String gluePath : gluePaths) {
Resources.scan(gluePath.replace('.', '/'), ".rb", new Consumer() {
public void consume(Resource resource) {
jruby.runScriptlet(resource.getReader(), resource.getPath());
}
Expand Down
16 changes: 8 additions & 8 deletions junit/src/main/java/cucumber/junit/Cucumber.java
Expand Up @@ -120,12 +120,12 @@ public void consume(Resource resource) {
private void buildFeatureElementRunners(CucumberFeature cucumberFeature) {
for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) {
try {
List<String> codePaths = codePaths(super.getTestClass().getJavaClass());
List<String> gluePaths = gluePaths(super.getTestClass().getJavaClass());
ParentRunner featureElementRunner;
if (cucumberTagStatement instanceof CucumberScenario) {
featureElementRunner = new ExecutionUnitRunner(runtime, codePaths, (CucumberScenario) cucumberTagStatement, jUnitReporter);
featureElementRunner = new ExecutionUnitRunner(runtime, gluePaths, (CucumberScenario) cucumberTagStatement, jUnitReporter);
} else {
featureElementRunner = new ScenarioOutlineRunner(runtime, codePaths, (CucumberScenarioOutline) cucumberTagStatement, jUnitReporter);
featureElementRunner = new ScenarioOutlineRunner(runtime, gluePaths, (CucumberScenarioOutline) cucumberTagStatement, jUnitReporter);
}
getChildren().add(featureElementRunner);
} catch (InitializationError e) {
Expand All @@ -142,16 +142,16 @@ private Long[] toLong(long[] primitiveLongs) {
return longs;
}

private List<String> codePaths(Class featureClass) {
List<String> codePaths = new ArrayList<String>();
private List<String> gluePaths(Class featureClass) {
List<String> gluePaths = new ArrayList<String>();
String featurePackageName = featureClass.getName().substring(0, featureClass.getName().lastIndexOf("."));
codePaths.add(featurePackageName);
gluePaths.add(featurePackageName);

// Add additional ones
cucumber.junit.Feature featureAnnotation = (cucumber.junit.Feature) featureClass.getAnnotation(cucumber.junit.Feature.class);
if (featureAnnotation != null) {
codePaths.addAll(asList(featureAnnotation.packages()));
gluePaths.addAll(asList(featureAnnotation.packages()));
}
return codePaths;
return gluePaths;
}
}
4 changes: 2 additions & 2 deletions junit/src/main/java/cucumber/junit/ExamplesRunner.java
Expand Up @@ -13,14 +13,14 @@
class ExamplesRunner extends Suite {
private final CucumberExamples cucumberExamples;

protected ExamplesRunner(Runtime runtime, List<String> codePaths, CucumberExamples cucumberExamples, JUnitReporter jUnitReporter) throws InitializationError {
protected ExamplesRunner(Runtime runtime, List<String> gluePaths, CucumberExamples cucumberExamples, JUnitReporter jUnitReporter) throws InitializationError {
super(null, new ArrayList<Runner>());
this.cucumberExamples = cucumberExamples;

List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
for (CucumberScenario scenario : exampleScenarios) {
try {
ExecutionUnitRunner exampleScenarioRunner = new ExecutionUnitRunner(runtime, codePaths, scenario, jUnitReporter);
ExecutionUnitRunner exampleScenarioRunner = new ExecutionUnitRunner(runtime, gluePaths, scenario, jUnitReporter);
getChildren().add(exampleScenarioRunner);
} catch (InitializationError initializationError) {
initializationError.printStackTrace();
Expand Down
8 changes: 4 additions & 4 deletions junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java
Expand Up @@ -14,14 +14,14 @@

class ExecutionUnitRunner extends ParentRunner<Step> {
private final Runtime runtime;
private final List<String> codePaths;
private final List<String> gluePaths;
private final CucumberScenario cucumberScenario;
private final JUnitReporter jUnitReporter;

public ExecutionUnitRunner(Runtime runtime, List<String> codePaths, CucumberScenario cucumberScenario, JUnitReporter jUnitReporter) throws InitializationError {
public ExecutionUnitRunner(Runtime runtime, List<String> gluePaths, CucumberScenario cucumberScenario, JUnitReporter jUnitReporter) throws InitializationError {
super(ExecutionUnitRunner.class);
this.runtime = runtime;
this.codePaths = codePaths;
this.gluePaths = gluePaths;
this.cucumberScenario = cucumberScenario;
this.jUnitReporter = jUnitReporter;
}
Expand All @@ -45,7 +45,7 @@ protected Description describeChild(Step step) {
public void run(RunNotifier notifier) {
jUnitReporter.setStepParentRunner(this, notifier);
try {
cucumberScenario.createWorld(codePaths, runtime);
cucumberScenario.createWorld(gluePaths, runtime);

/*
We're running the background without reporting the steps as junit children - we don't want them to show up in the
Expand Down
4 changes: 2 additions & 2 deletions junit/src/main/java/cucumber/junit/ScenarioOutlineRunner.java
Expand Up @@ -13,11 +13,11 @@
class ScenarioOutlineRunner extends Suite {
private final CucumberScenarioOutline cucumberScenarioOutline;

public ScenarioOutlineRunner(Runtime runtime, List<String> codePaths, CucumberScenarioOutline cucumberScenarioOutline, JUnitReporter jUnitReporter) throws InitializationError {
public ScenarioOutlineRunner(Runtime runtime, List<String> gluePaths, CucumberScenarioOutline cucumberScenarioOutline, JUnitReporter jUnitReporter) throws InitializationError {
super(null, new ArrayList<Runner>());
this.cucumberScenarioOutline = cucumberScenarioOutline;
for (CucumberExamples cucumberExamples : cucumberScenarioOutline.getCucumberExamplesList()) {
getChildren().add(new ExamplesRunner(runtime, codePaths, cucumberExamples, jUnitReporter));
getChildren().add(new ExamplesRunner(runtime, gluePaths, cucumberExamples, jUnitReporter));
}
}

Expand Down
Expand Up @@ -25,11 +25,11 @@ public JythonBackend() {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.pyWorld = jython.eval("World()");
this.world = world;
for (String codePath : codePaths) {
Resources.scan(codePath.replace('.', '/'), ".py", new Consumer() {
for (String gluePath : gluePaths) {
Resources.scan(gluePath.replace('.', '/'), ".py", new Consumer() {
public void consume(Resource resource) {
jython.execfile(resource.getInputStream(), resource.getPath());
}
Expand Down
14 changes: 7 additions & 7 deletions rhino/src/main/java/cucumber/runtime/rhino/RhinoBackend.java
Expand Up @@ -24,7 +24,7 @@ public class RhinoBackend implements Backend {
private static final String JS_DSL = "/cucumber/runtime/rhino/dsl.js";
private final Context cx;
private final Scriptable scope;
private final Set<String> codePaths = new HashSet<String>();
private final Set<String> gluePaths = new HashSet<String>();
private World world;

public RhinoBackend() throws IOException {
Expand All @@ -36,12 +36,12 @@ public RhinoBackend() throws IOException {
}

@Override
public void buildWorld(List<String> codePaths, World world) {
public void buildWorld(List<String> gluePaths, World world) {
this.world = world;
for (String codePath : codePaths) {
codePath = codePath.replace('.', '/');
codePaths.add(codePath);
Resources.scan(codePath, ".js", new Consumer() {
for (String gluePath : gluePaths) {
gluePath = gluePath.replace('.', '/');
gluePaths.add(gluePath);
Resources.scan(gluePath, ".js", new Consumer() {
public void consume(Resource resource) {
try {
cx.evaluateReader(scope, resource.getReader(), resource.getPath(), 1, null);
Expand All @@ -67,7 +67,7 @@ private StackTraceElement stepDefLocation(String extension) {
StackTraceElement[] stackTraceElements = t.getStackTrace();
for (StackTraceElement stackTraceElement : stackTraceElements) {
boolean js = stackTraceElement.getFileName().endsWith(extension);
for (String scriptPath : codePaths) {
for (String scriptPath : gluePaths) {
boolean inScriptPath = stackTraceElement.getFileName().startsWith(scriptPath);
boolean hasLine = stackTraceElement.getLineNumber() != -1;
if (js && inScriptPath && hasLine) {
Expand Down

0 comments on commit 21afdd7

Please sign in to comment.