Skip to content

Commit

Permalink
[Java8] Updated java8 for the use of Gherkin v4.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
brasmusson committed Dec 18, 2016
1 parent 41c169a commit d66b876
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
26 changes: 17 additions & 9 deletions java8/pom.xml
Expand Up @@ -58,7 +58,8 @@

<groovy><![CDATA[
import groovy.text.SimpleTemplateEngine
import gherkin.I18n
import gherkin.GherkinDialect
import gherkin.GherkinDialectProvider
def engine = new SimpleTemplateEngine()
Expand All @@ -70,14 +71,21 @@ def normalize(s) {
}
}
I18n.all.each { i18n ->
def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.java8.txt").getText()
def className = "${i18n.underscoredIsoCode}".capitalize()
def binding = [ "i18n":i18n, "className":className ]
def template = engine.createTemplate(templateSource).make(binding)
def file = new File(project.baseDir, "target${File.separator}generated-sources${File.separator}i18n${File.separator}java8${File.separator}cucumber${File.separator}api${File.separator}java8${File.separator}${className}.java")
file.parentFile.mkdirs()
file.write(template.toString(), "UTF-8")
def unsupported = ["em"] // The generated files for Emoij do not compile.
def dialectProvider = new GherkinDialectProvider()
GherkinDialectProvider.DIALECTS.keySet().each { language ->
def dialect = dialectProvider.getDialect(language, null)
def normalized_language = dialect.language.replaceAll("[\\s-]", "_").toLowerCase()
if (!unsupported.contains(normalized_language)) {
def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.java8.txt").getText()
def className = "${normalized_language}".capitalize()
def binding = [ "i18n":dialect, "className":className ]
def template = engine.createTemplate(templateSource).make(binding)
def file = new File(project.baseDir, "target${File.separator}generated-sources${File.separator}i18n${File.separator}java8${File.separator}cucumber${File.separator}api${File.separator}java8${File.separator}${className}.java")
file.parentFile.mkdirs()
file.write(template.toString(), "UTF-8")
}
}
]]></groovy>
Expand Down
12 changes: 6 additions & 6 deletions java8/src/main/code_generator/I18n.java8.txt
Expand Up @@ -5,25 +5,25 @@ import cucumber.runtime.java8.LambdaGlueBase;
import cucumber.runtime.java.JavaBackend;

public interface ${className} extends LambdaGlueBase {
<% i18n.codeKeywords.each { kw -> %>
default void ${java.text.Normalizer.normalize(kw, java.text.Normalizer.Form.NFC)}(final String regexp, final StepdefBody.A0 body) {
<% i18n.stepKeywords.findAll { !it.contains('*') && !it.matches("^\\d.*") }.sort().unique().each { kw -> %>
default void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final StepdefBody.A0 body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, 0, body, ConstantPoolTypeIntrospector.INSTANCE);
}

default void ${java.text.Normalizer.normalize(kw, java.text.Normalizer.Form.NFC)}(final String regexp, final long timeoutMillis, final StepdefBody.A0 body) {
default void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final long timeoutMillis, final StepdefBody.A0 body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, timeoutMillis, body, ConstantPoolTypeIntrospector.INSTANCE);
}
<% (1..9).each { arity ->
def ts = (1..arity).collect { n -> "T"+n }
def genericSignature = ts.join(",") %>

default <${genericSignature}> void ${java.text.Normalizer.normalize(kw, java.text.Normalizer.Form.NFC)}(final String regexp, final StepdefBody.A${arity}<${genericSignature}> body) {
default <${genericSignature}> void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final StepdefBody.A${arity}<${genericSignature}> body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, 0, body, ConstantPoolTypeIntrospector.INSTANCE);
}

default <${genericSignature}> void ${java.text.Normalizer.normalize(kw, java.text.Normalizer.Form.NFC)}(final String regexp, final long timeoutMillis, final StepdefBody.A${arity}<${genericSignature}> body) {
default <${genericSignature}> void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final long timeoutMillis, final StepdefBody.A${arity}<${genericSignature}> body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, timeoutMillis, body, ConstantPoolTypeIntrospector.INSTANCE);
}
<% } %>
<% } %>
}
}

0 comments on commit d66b876

Please sign in to comment.