Skip to content

Commit

Permalink
Merge branch 'master' into ffbit-spring-txn-chap14
Browse files Browse the repository at this point in the history
Conflicts:
	jython/pom.xml
	pom.xml
  • Loading branch information
Dmytro Chyzhykov committed Apr 13, 2013
2 parents c87e2e2 + 3be4969 commit bfd55fd
Show file tree
Hide file tree
Showing 111 changed files with 2,761 additions and 541 deletions.
27 changes: 24 additions & 3 deletions DEVELOPERS.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Notes for developers
## About to create a new Github Issue?

We appreciate that. But before you do, please learn our basic rules:

* This is not a support or discussion forum. If you have a question, please ask it on [The Cukes Google Group](http://groups.google.com/group/cukes).
* Do you have a feature request? Then don't expect it to be implemented unless you or someone else sends a [pull request](https://help.github.com/articles/using-pull-requests).
* Reporting a bug? We need to know what java/ruby/node.js etc. runtime you have, and what jar/gem/npm package versions you are using. Bugs with [pull requests](https://help.github.com/articles/using-pull-requests) get fixed quicker. Some bugs may never be fixed.
* You have to tell us how to reproduce a bug. Bonus point for a [pull request](https://help.github.com/articles/using-pull-requests) with a failing test that reproduces the bug.
* Want to paste some code or output? Put \`\`\` on a line above and below your code/output. See [GFM](https://help.github.com/articles/github-flavored-markdown)'s *Fenced Code Blocks* for details.
* We love [pull requests](https://help.github.com/articles/using-pull-requests), but if you don't have a test to go with it we probably won't merge it.

## Building Cucumber-JVM

Expand Down Expand Up @@ -69,9 +78,21 @@ Below are some common problems you might encounter while hacking on Cucumber-JVM

This can be solved by changing the Compiler settings: `Preferences -> Compiler -> Java Compiler`:

* *Use compiler:* `Javac in-process (Java6+ only)`
* *Use compiler:* `Javac`
* *Additional command line parameters:* `-target 1.6 -source 1.6 -encoding UTF-8`

You should also use JDK 6: `Project Structure... -> Project -> Project SDK`:

* *Use 1.6", not 1.7

If you still have problems, try building the project with Maven, using Java 6:

```
export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
```

Note that even though development is sometimes easier to do with 1.6, releasing should be done with 1.7.

## Releasing

This is a reminder to the developers:
Expand Down Expand Up @@ -115,7 +136,7 @@ Now release everything:

```
mvn release:clean
mvn --batch-mode -P release-sign-artifacts release:prepare -DautoVersionSubmodules=true -DdevelopmentVersion=1.1.2-SNAPSHOT
mvn --batch-mode -P release-sign-artifacts release:prepare -DautoVersionSubmodules=true -DdevelopmentVersion=1.1.4-SNAPSHOT
mvn -P release-sign-artifacts release:perform
```

Expand Down
89 changes: 55 additions & 34 deletions History.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clojure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.1.2-SNAPSHOT</version>
<version>1.1.4-SNAPSHOT</version>
</parent>

<artifactId>cucumber-clojure</artifactId>
Expand Down
20 changes: 15 additions & 5 deletions clojure/src/main/clj/cucumber/runtime/clj.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
(defn- -setUnreportedStepExecutor [cljb executor]
"executor")

(defn- location-str [{:keys [file line]}]
(str file ":" line))

(defn add-step-definition [pattern fun location]
(.addStepDefinition
@glue
Expand All @@ -72,7 +75,7 @@
(.argumentsFrom (JdkPatternArgumentMatcher. pattern)
(.getName step)))
(getLocation [_ detail]
(str (:file location) ":" (:line location)))
(location-str location))
(getParameterCount [_]
nil)
(getParameterType [_ n argumentType]
Expand All @@ -89,19 +92,21 @@

(defmulti add-hook-definition (fn [t & _] t))

(defmethod add-hook-definition :before [_ tag-expression hook-fun]
(defmethod add-hook-definition :before [_ tag-expression hook-fun location]
(let [te (TagExpression. tag-expression)]
(.addBeforeHook
@glue
(reify
HookDefinition
(getLocation [_ detail?]
(location-str location))
(execute [hd scenario-result]
(hook-fun))
(matches [hd tags]
(.eval te tags))
(getOrder [hd] 0)))))

(defmethod add-hook-definition :after [_ tag-expression hook-fun]
(defmethod add-hook-definition :after [_ tag-expression hook-fun location]
(let [te (TagExpression. tag-expression)
max-parameter-count (->> hook-fun class .getDeclaredMethods
(filter #(= "invoke" (.getName %)))
Expand All @@ -111,6 +116,8 @@
@glue
(reify
HookDefinition
(getLocation [_ detail?]
(location-str location))
(execute [hd scenario-result]
(if (zero? max-parameter-count)
(hook-fun)
Expand All @@ -130,12 +137,15 @@
(step-macros
Given When Then And But)

(defn- hook-location [file form]
{:file file
:line (:line (meta form))})

(defmacro Before [binding-form & body]
`(add-hook-definition :before [] (fn ~binding-form ~@body)))
`(add-hook-definition :before [] (fn ~binding-form ~@body) ~(hook-location *file* &form)))

(defmacro After [binding-form & body]
`(add-hook-definition :after [] (fn ~binding-form ~@body)))
`(add-hook-definition :after [] (fn ~binding-form ~@body) ~(hook-location *file* &form)))

(defn ^:private update-keys [f m]
(reduce-kv #(assoc %1 (f %2) %3) {} m))
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.1.2-SNAPSHOT</version>
<version>1.1.4-SNAPSHOT</version>
</parent>

<artifactId>cucumber-core</artifactId>
Expand Down
34 changes: 34 additions & 0 deletions core/src/main/java/cucumber/runtime/Env.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cucumber.runtime;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

/**
* Looks up values in the following order:
* <ol>
* <li>Environment variable</li>
* <li>System property</li>
* <li>Resource bundle</li>
* </ol>
*/
public class Env {
private final String bundleName;

public Env(String bundleName) {
this.bundleName = bundleName;
}

public String get(String key) {
String value = System.getenv(key);
if (value == null) {
value = System.getProperty(key);
if (value == null) {
try {
value = ResourceBundle.getBundle(bundleName).getString(key);
} catch (MissingResourceException ignore) {
}
}
}
return value;
}
}
1 change: 0 additions & 1 deletion core/src/main/java/cucumber/runtime/Glue.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import gherkin.I18n;
import gherkin.formatter.model.Step;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public JdkPatternArgumentMatcher(Pattern pattern) {

public List<Argument> argumentsFrom(String stepName) {
Matcher matcher = pattern.matcher(stepName);
if (matcher.matches()) {
List<Argument> arguments = new ArrayList<Argument>();
if (matcher.lookingAt()) {
List<Argument> arguments = new ArrayList<Argument>(matcher.groupCount());
for (int i = 1; i <= matcher.groupCount(); i++) {
arguments.add(new Argument(matcher.start(i), matcher.group(i)));
}
Expand Down
25 changes: 12 additions & 13 deletions core/src/main/java/cucumber/runtime/ParameterInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cucumber.runtime;

import cucumber.api.Format;
import cucumber.api.Delimiter;
import cucumber.api.Format;
import cucumber.api.Transform;
import cucumber.api.Transformer;
import cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter;
Expand All @@ -14,7 +14,6 @@
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
* This class composes all interesting parameter information into one object.
Expand All @@ -32,12 +31,12 @@ public static List<ParameterInfo> fromMethod(Method method) {
Type[] genericParameterTypes = method.getGenericParameterTypes();
Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < genericParameterTypes.length; i++) {
String dateFormat = null;
String format = null;
String delimiter = DEFAULT_DELIMITER;
Transformer transformer = null;
for (Annotation annotation : annotations[i]) {
if (annotation instanceof Format) {
dateFormat = ((Format) annotation).value();
format = ((Format) annotation).value();
}
if (annotation instanceof Delimiter) {
delimiter = ((Delimiter) annotation).value();
Expand All @@ -52,7 +51,7 @@ public static List<ParameterInfo> fromMethod(Method method) {
}
}
}
result.add(new ParameterInfo(genericParameterTypes[i], dateFormat, delimiter, transformer));
result.add(new ParameterInfo(genericParameterTypes[i], format, delimiter, transformer));
}
return result;
}
Expand Down Expand Up @@ -85,20 +84,20 @@ public String toString() {
return type.toString();
}

public Object convert(String value, LocalizedXStreams.LocalizedXStream xStream, Locale locale) {
public Object convert(String value, LocalizedXStreams.LocalizedXStream xStream) {
try {
xStream.setParameterType(this);
SingleValueConverter converter;
xStream.processAnnotations(getRawType());

if (transformer != null) {
transformer.setParameterInfoAndLocale(this, locale);
transformer.setParameterInfoAndLocale(this, xStream.getLocale());
converter = transformer;
} else {
if (List.class.isAssignableFrom(getRawType())) {
converter = getListConverter(type, xStream, locale);
converter = getListConverter(type, xStream);
} else {
converter = getConverter(getRawType(), xStream, locale);
converter = getConverter(getRawType(), xStream);
}
if (converter == null) {
throw new CucumberException(String.format(
Expand All @@ -121,22 +120,22 @@ public Object convert(String value, LocalizedXStreams.LocalizedXStream xStream,
}
}

private SingleValueConverter getListConverter(Type type, LocalizedXStreams.LocalizedXStream xStream, Locale locale) {
private SingleValueConverter getListConverter(Type type, LocalizedXStreams.LocalizedXStream xStream) {
Class elementType = type instanceof ParameterizedType
? getRawType(((ParameterizedType) type).getActualTypeArguments()[0])
: Object.class;

SingleValueConverter elementConverter = getConverter(elementType, xStream, locale);
SingleValueConverter elementConverter = getConverter(elementType, xStream);
if (elementConverter == null) {
return null;
} else {
return xStream.createListConverter(delimiter, elementConverter);
}
}

private SingleValueConverter getConverter(Class<?> type, LocalizedXStreams.LocalizedXStream xStream, Locale locale) {
private SingleValueConverter getConverter(Class<?> type, LocalizedXStreams.LocalizedXStream xStream) {
if (type.isEnum()) {
return xStream.createEnumConverter(locale, (Class<? extends Enum>) type);
return xStream.createEnumConverter((Class<? extends Enum>) type);
} else {
return xStream.getSingleValueConverter(type);
}
Expand Down
29 changes: 17 additions & 12 deletions core/src/main/java/cucumber/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,30 @@ public void runAfterHooks(Reporter reporter, Set<Tag> tags) {
}

private void runHooks(List<HookDefinition> hooks, Reporter reporter, Set<Tag> tags, boolean isBefore) {
if (!runtimeOptions.dryRun) {
for (HookDefinition hook : hooks) {
runHookIfTagsMatch(hook, reporter, tags, isBefore);
}
}
if (!runtimeOptions.dryRun) {
for (HookDefinition hook : hooks) {
runHookIfTagsMatch(hook, reporter, tags, isBefore);
}
}
}

private void runHookIfTagsMatch(HookDefinition hook, Reporter reporter, Set<Tag> tags, boolean isBefore) {
if (hook.matches(tags)) {
String status = Result.PASSED;
Throwable error = null;
Match match = new Match(Collections.<Argument>emptyList(), hook.getLocation(false));
long start = System.nanoTime();
try {
hook.execute(scenarioResult);
} catch (Throwable t) {
error = t;
status = isPending(t) ? "pending" : Result.FAILED;
addError(t);
skipNextStep = true;
} finally {
long duration = System.nanoTime() - start;

String status = isPending(t) ? "pending" : Result.FAILED;
Result result = new Result(status, duration, t, DUMMY_ARG);
Result result = new Result(status, duration, error, DUMMY_ARG);
scenarioResult.add(result);
addError(t);

Match match = new Match(Collections.<Argument>emptyList(), hook.getLocation(false));
if (isBefore) {
reporter.before(match, result);
} else {
Expand Down Expand Up @@ -280,7 +282,10 @@ public void runStep(String uri, Step step, Reporter reporter, I18n i18n) {
}
}

private static boolean isPending(Throwable t) {
public static boolean isPending(Throwable t) {
if (t == null) {
return false;
}
return t.getClass().isAnnotationPresent(Pending.class) || Arrays.binarySearch(PENDING_EXCEPTIONS, t.getClass().getName()) >= 0;
}

Expand Down
11 changes: 9 additions & 2 deletions core/src/main/java/cucumber/runtime/RuntimeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -76,7 +75,7 @@ private void parse(List<String> args) {
String arg = args.remove(0).trim();

if (arg.equals("--help") || arg.equals("-h")) {
System.out.println(USAGE);
printUsage();
System.exit(0);
} else if (arg.equals("--version") || arg.equals("-v")) {
System.out.println(VERSION);
Expand All @@ -101,6 +100,9 @@ private void parse(List<String> args) {
String nextArg = args.remove(0);
Pattern patternFilter = Pattern.compile(nextArg);
parsedFilters.add(patternFilter);
} else if (arg.startsWith("-")) {
printUsage();
throw new CucumberException("Unknown option: " + arg);
} else {
PathWithLines pathWithLines = new PathWithLines(arg);
featurePaths.add(pathWithLines.path);
Expand All @@ -113,6 +115,11 @@ private void parse(List<String> args) {
}
}

private void printUsage()
{
System.out.println(USAGE);
}

public List<CucumberFeature> cucumberFeatures(ResourceLoader resourceLoader) {
return load(resourceLoader, featurePaths, filters);
}
Expand Down
7 changes: 1 addition & 6 deletions core/src/main/java/cucumber/runtime/StepDefinitionMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@ private Object[] transformedArgs(Step step, LocalizedXStreams.LocalizedXStream x

List<Object> result = new ArrayList<Object>();

List<ParameterInfo> parameterInfos = new ArrayList<ParameterInfo>();
int n = 0;
for (Argument a : getArguments()) {
Object arg;

ParameterInfo parameterInfo = getParameterType(n, String.class);
parameterInfos.add(parameterInfo);

arg = parameterInfo.convert(a.getVal(), xStream, locale);
Object arg = parameterInfo.convert(a.getVal(), xStream);
result.add(arg);
n++;
}
Expand Down
Loading

0 comments on commit bfd55fd

Please sign in to comment.