Skip to content

Commit

Permalink
Proposed solution to #487
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Apr 7, 2013
1 parent 298686d commit 840601a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 47 deletions.
2 changes: 1 addition & 1 deletion groovy/src/main/code_generator/I18n.groovy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ${i18n.underscoredIsoCode.toUpperCase()} {
GroovyBackend.instance.addStepDefinition(regexp, 0, body);
}

public static void ${java.text.Normalizer.normalize(kw, java.text.Normalizer.Form.NFD)}(Pattern regexp, int timeoutMillis, Closure body) throws Throwable {
public static void ${kw}(Pattern regexp, int timeoutMillis, Closure body) throws Throwable {
GroovyBackend.instance.addStepDefinition(regexp, timeoutMillis, body);
}
<% } %>
Expand Down
35 changes: 4 additions & 31 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,39 +73,12 @@ import gherkin.I18n
def engine = new SimpleTemplateEngine()
def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.java.txt").getText()
def normalize(s) {
if(System.getProperty("java.version").startsWith("1.6")) {
return s
} else {
return java.text.Normalizer.normalize(s, java.text.Normalizer.Form.NFD)
}
}
// TODO: Need to add i18n.getName() and i18n.getNative() for better names.
def package_html = """\
<body>
<p>
\${i18n.getLocale().getDisplayLanguage()}
</p>
</body>
"""
I18n.all.each { i18n ->
i18n.codeKeywords.each { kw ->
def normalized_kw = normalize(kw)
def binding = ["i18n":i18n, "kw":normalized_kw]
template = engine.createTemplate(templateSource).make(binding)
def file = new File(project.baseDir, "target${File.separator}generated-sources${File.separator}i18n${File.separator}java${File.separator}cucumber${File.separator}api${File.separator}java${File.separator}${i18n.underscoredIsoCode}${File.separator}${normalized_kw}.java")
file.parentFile.mkdirs()
file.write(template.toString(), "UTF-8")
}
// html
def binding = ["i18n":i18n]
def html = engine.createTemplate(package_html).make(binding).toString()
def file = new File(project.baseDir, "target${File.separator}generated-sources${File.separator}i18n${File.separator}java${File.separator}cucumber${File.separator}api${File.separator}java${File.separator}${i18n.underscoredIsoCode}${File.separator}package.html")
file.write(html, "UTF-8")
template = engine.createTemplate(templateSource).make(binding)
def file = new File(project.baseDir, "target${File.separator}generated-sources${File.separator}i18n${File.separator}java${File.separator}cucumber${File.separator}api${File.separator}java${File.separator}${i18n.underscoredIsoCode}.java")
file.parentFile.mkdirs()
file.write(template.toString(), "UTF-8")
}
]]></groovy>
Expand Down
36 changes: 22 additions & 14 deletions java/src/main/code_generator/I18n.java.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cucumber.api.java.${i18n.underscoredIsoCode};
package cucumber.api.java;

import cucumber.runtime.java.StepDefAnnotation;

Expand All @@ -7,18 +7,26 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@StepDefAnnotation
public @interface ${kw} {
/**
* @return a regular expression
*/
String value();
/**
* ${i18n.getLocale().getDisplayLanguage()}
*/
public class ${i18n.underscoredIsoCode} {
private ${i18n.underscoredIsoCode} {}

/**
* @return max amount of time this is allowed to run for. 0 (default) means no restriction.
*/
int timeout() default 0;
}
<% i18n.codeKeywords.each { kw -> %>
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@StepDefAnnotation
public @interface ${kw} {
/**
* @return a regular expression
*/
String value();

/**
* @return max amount of time this is allowed to run for. 0 (default) means no restriction.
*/
int timeout() default 0;
}
<% } %>
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package cucumber.runtime.java.stepdefs;

import cucumber.api.java.en.Given;
import cucumber.api.java.sv.;

public class Stepdefs {
@Given("test")
public void test() {

}

@("test")
public void testEncoding() {

}
}
2 changes: 1 addition & 1 deletion jruby/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module Cucumber
module JRuby
module Dsl
<% i18n.codeKeywords.each { kw -> %>
def \${java.text.Normalizer.normalize(kw, java.text.Normalizer.Form.NFD)}(regexp, &proc)
def \${kw}(regexp, &proc)
register_stepdef(regexp, proc)
end
<% } %>
Expand Down

0 comments on commit 840601a

Please sign in to comment.