@@ -70,8 +70,10 @@ public void translateInTests(String name) {
7070
7171 linesToAddForDataAndGlue .addAll (Configuration .linesToAddForDataAndGlue );
7272 dataIn = new InputIterator (name , featureDirectory );
73+ alterFeatureDirectory ();
7374 if (dataIn .isEmpty ())
7475 return ;
76+
7577 for (int pass = 1 ; pass <= 3 ; pass ++) {
7678 dataIn .reset ();
7779 boolean eof = false ;
@@ -87,6 +89,16 @@ public void translateInTests(String name) {
8789 endUp ();
8890 }
8991
92+ private void alterFeatureDirectory () {
93+ // Remove feature directory from the package and directory
94+ String searchFor = Configuration .treeDirectory ;
95+ String alternateSearchFor = searchFor .replace ("/" ,"\\ " );
96+ String directory = featureDirectory .replace (searchFor , "" );
97+ directory = directory .replace (alternateSearchFor ,"" );
98+ featureDirectory = directory ;
99+ featurePackagePath = featureDirectory .replace ("\\ " , "." ).replace ("/" , "." );
100+ }
101+
90102 private void findFeatureDirectory (String name ) {
91103 String directory = "" ;
92104 int indexForward = name .lastIndexOf ('/' );
@@ -137,11 +149,17 @@ private Pair<List<String>, List<String>> splitLine(String line) {
137149 }
138150 continue ;
139151 }
152+ word = filterWord (word );
140153 words .add (word );
141154 }
142155 return new Pair <>(words , comment );
143156 }
144-
157+ public static String filterWord (String input ) {
158+ if (input == null ) {
159+ return "" ;
160+ }
161+ return input .replaceAll ("[^0-9a-zA-Z_]" , "" );
162+ }
145163 private static String wordWithOutColon (String word ) {
146164 return word .replaceAll ("^:+|:+$" , "" );
147165 }
@@ -246,6 +264,7 @@ void writeInputFeature(String filename) {
246264 myLog .write (dataIn .toString ());
247265 myLog .close ();
248266 } catch (IOException e ) {
267+ System .err .println (e .getMessage () + " Cause " + e .getCause ());
249268 System .err .println ("**** Cannot write to " + fullFilename );
250269 }
251270 }
@@ -292,7 +311,6 @@ private boolean actOnFeatureFirstHalf(String fullName) {
292311 featureName = fullName ;
293312 featureActedOn = true ;
294313 packagePath = Configuration .packageName + "." + featurePackagePath + featureName ;
295- writeInputFeature (Configuration .testSubDirectory + featureDirectory + featureName + "/" );
296314 String testPathname = Configuration .testSubDirectory + featureDirectory + featureName + "/" +
297315 featureName + ".java" ;
298316 printFlow (" Writing " + testPathname );
@@ -314,6 +332,7 @@ private boolean actOnFeatureFirstHalf(String fullName) {
314332 }
315333 glueClass = fullName + "_glue" ;
316334 glueObject = makeName (fullName ) + "_glue_object" ;
335+ writeInputFeature (Configuration .testSubDirectory + featureDirectory + featureName + "/" );
317336 return false ;
318337 }
319338
@@ -326,7 +345,8 @@ private String makeBuildName(String s) {
326345
327346 private String makeName (String input ) {
328347 if (input .isEmpty ()) return "NAME_IS_EMPTY" ;
329- String temp = input .replace (' ' , '_' );
348+ String temp = input .replaceAll (" " , "_" );
349+ temp = filterWord (temp );
330350 return Character .toLowerCase (temp .charAt (0 )) + temp .substring (1 );
331351 }
332352
@@ -674,7 +694,8 @@ static class InputIterator {
674694 public String toString () {
675695 StringBuilder temp = new StringBuilder ();
676696 for (String line : linesIn ){
677- temp .append (line + "\n " );
697+ temp .append (line );
698+ temp .append ("\n " );
678699 }
679700 return temp .toString ();
680701 }
@@ -1404,7 +1425,7 @@ private void createJSONToTableMethod(String className) {
14041425 public static List<CLASSNAME> listFromJson(String json) {
14051426 List<CLASSNAME> list = new ArrayList<>();
14061427 json = json.replaceAll("\\ \\ s", "");
1407- String[] jsonObjects = json.replace("[", "").replace("]", "").split("\\ \\ }, \\ \\ { ");
1428+ String[] jsonObjects = json.replace("[", "").replace("]", "").split("[},{] ");
14081429
14091430 for (String jsonObject : jsonObjects) {
14101431 jsonObject = "{" + jsonObject.replace("{", "").replace("}", "") + "}";
@@ -1986,7 +2007,8 @@ static class Configuration {
19862007
19872008 public static final String featureSubDirectory = "src/test/java/" ;
19882009 // where features are stored
1989- public static final String startingFeatureDirectory = featureSubDirectory + "features/" ;
2010+ public static final String treeDirectory = "features/" ;
2011+ public static final String startingFeatureDirectory = featureSubDirectory + treeDirectory ;
19902012 // where the directory tree of features is to be found.
19912013 public static boolean searchTree = false ;
19922014 public static final String packageName = "gherkinexecutor" ;
0 commit comments