Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Gosu runtime now requires Java 8; how can we skip this module when Travis build with openjdk7 or oraclejdk7? - Thanks to @kausnz for supplying the clever reflection solution
- Loading branch information
1 parent
940b97a
commit 7edd7f1
Showing
7 changed files
with
69 additions
and
113 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
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 |
---|---|---|
@@ -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; | ||
} | ||
}; | ||
} | ||
} |
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