Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and re-enable Gosu #1086

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions gosu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.2.5-SNAPSHOT</version>
<version>1.2.6-SNAPSHOT</version>
</parent>

<artifactId>cucumber-gosu</artifactId>
<packaging>jar</packaging>
<name>Cucumber-JVM: Gosu</name>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${gosu.skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>info.cukes</groupId>
Expand Down
83 changes: 22 additions & 61 deletions gosu/src/main/java/cucumber/runtime/gosu/GlueSource.java
Original file line number Diff line number Diff line change
@@ -1,73 +1,34 @@
package cucumber.runtime.gosu;

import cucumber.runtime.io.Resource;
import gw.lang.launch.IArgInfo;
import gw.lang.launch.IBooleanArgKey;
import gw.lang.launch.IProgramSource;
import gw.lang.launch.IStringArgKey;
import gw.lang.reflect.ReflectUtil;
import gw.lang.reflect.gs.GosuClassPathThing;
import gw.lang.reflect.gs.IProgramInstance;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
class GlueSource {

class GlueSource implements IProgramSource {
private final StringBuilder sourceBuilder = new StringBuilder();

@Override
public String getRawPath() {
// This file doesn't really exist, but we have to say something I guess!
return "cucumber.gsp";
}

@Override
public File getFile() {
return null;
}

@Override
public InputStream openInputStream() throws IOException {
return new ByteArrayInputStream(sourceBuilder.toString().getBytes("UTF-8"));
/**
* Performs minimal initialization of the Gosu TypeSystem; this is required for later calls to ReflectUtil#getClass
*/
public GlueSource() {
GosuClassPathThing.init();
}

/**
* Given a glue Resource, calculates the FQN of the Gosu Program as a class,
* loads it via reflection and calls its evaluate method.
* @param glueScript
*/
public void addGlueScript(Resource glueScript) {
// https://groups.google.com/d/msg/gosu-lang/yMJnzQwuFpo/msg81GNGlAYJ
String className = glueScript.getClassName(".gsp");
sourceBuilder.append("(" + className + ".Type as java.lang.Class).getDeclaredMethod( \"evaluate\", {gw.lang.reflect.gs.IExternalSymbolMap} ).invoke( new " + className + "(), {null})\n");
Class clazz = ReflectUtil.getClass(className).getBackingClass();
try {
((IProgramInstance)(clazz.newInstance())).evaluate(null);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}

public IArgInfo toArgInfo() {
return new IArgInfo() {
@Override
public boolean consumeArg(IBooleanArgKey iBooleanArgKey) {
return false;
}

@Override
public String consumeArg(IStringArgKey iStringArgKey) {
return null;
}

@Override
public void processUnknownArgs() {

}

@Override
public String getErrorMessage() {
return null;
}

@Override
public IProgramSource getProgramSource() {
return GlueSource.this;
}

@Override
public List<String> getArgsList() {
return null;
}
};
}
}
6 changes: 2 additions & 4 deletions gosu/src/main/java/cucumber/runtime/gosu/GosuBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import cucumber.runtime.snippets.FunctionNameGenerator;
import cucumber.runtime.snippets.SnippetGenerator;
import gherkin.formatter.model.Step;
import gw.lang.Gosu;
import gw.lang.function.AbstractBlock;

import java.util.List;
Expand Down Expand Up @@ -37,8 +36,6 @@ public void loadGlue(Glue glue, List<String> gluePaths) {
}
}

Gosu gosu = new Gosu();
gosu.start(source.toArgInfo());
}

@Override
Expand All @@ -60,7 +57,8 @@ public void disposeWorld() {
public String getSnippet(Step step, FunctionNameGenerator functionNameGenerator) {
return snippetGenerator.getSnippet(step, null); }

public void addStepDefinition(String regexp, Object body) {
@SuppressWarnings("unused") // this is indeed invoked by static methods on cucumber.api.gosu.en.Dsl
public void addStepDefinition( String regexp, Object body) {
AbstractBlock block = (AbstractBlock) body;
glue.addStepDefinition(new GosuStepDefinition(Pattern.compile(regexp), block, currentLocation()));
}
Expand Down
17 changes: 7 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
<clojure.version>1.8.0</clojure.version>
<!-- This is only here for the example project to use, the 3 scala projects maintain their own versions -->
<scala.latest.version>2.11.8</scala.latest.version>
<gosu.version>1.2</gosu.version>
<gosu.version>1.14.2</gosu.version>
<!-- used by Gosu to skip test execution on Java 7 -->
<gosu.skipTests>true</gosu.skipTests>
<rhino.version>1.7.7.1</rhino.version>
<jsoup.version>1.9.2</jsoup.version>
<testng.version>6.9.10</testng.version>
Expand Down Expand Up @@ -526,14 +528,6 @@
</dependencies>
</dependencyManagement>

<repositories>
<!--<repository>-->
<!--<id>gosu-lang.org-releases</id>-->
<!--<name>Official Gosu website (releases)</name>-->
<!--<url>http://gosu-lang.org/repositories/m2/releases</url>-->
<!--</repository>-->
</repositories>

<!--
this adds a repository that the plugins will use for dependency resolution
Any items that we use in a plugin's <dependency> phase can be resolved from here, as well as central
Expand All @@ -546,7 +540,7 @@
</pluginRepositories>

<modules>
<!--<module>gosu</module>-->
<module>gosu</module>
<module>core</module>
<module>java</module>
<module>testng</module>
Expand Down Expand Up @@ -576,6 +570,9 @@
<modules>
<module>java8</module>
</modules>
<properties>
<gosu.skipTests>false</gosu.skipTests>
</properties>
</profile>

<profile>
Expand Down