1616 * limitations under the License.
1717 */
1818
19+ import org .apache .commons .lang3 .StringUtils ;
1920import org .apache .maven .plugin .AbstractMojo ;
2021import org .apache .maven .plugin .MojoExecution ;
2122import org .apache .maven .plugin .MojoExecutionException ;
@@ -51,7 +52,7 @@ public class MyMojo extends AbstractMojo
5152 @ Parameter (property = "configurationFilePath" , required = true )
5253 private String configurationFilePath ;
5354
54- @ Parameter (property = "includedTags" , required = true )
55+ @ Parameter (property = "includedTags" )
5556 private String includedTags ;
5657
5758 @ Parameter ( defaultValue = "${mojoExecution}" , readonly = true )
@@ -88,6 +89,8 @@ public void execute() throws MojoExecutionException {
8889 public void createTestRunners () throws IOException {
8990
9091 String content = new String (Files .readAllBytes (Paths .get (templateRunnerPath )));
92+ content = ripOffPackageNameFromJavaFile (content );
93+
9194 File dir = new File (runnersDirectoryPath );
9295
9396 for (int i =0 ;i <totalFiles ;i ++) {
@@ -102,6 +105,19 @@ public void createTestRunners() throws IOException {
102105 getLog ().info ("Total Test Runners Created : " +totalFiles );
103106 }
104107
108+ public String ripOffPackageNameFromJavaFile (String content ) throws IOException {
109+
110+ File file = new File (templateRunnerPath );
111+ String filePath = file .getCanonicalPath ();
112+ filePath = filePath .replaceAll ("\\ \\ " ,"." );
113+ filePath = StringUtils .substringBetween (filePath ,"src.test.java." ,"." +file .getName ());
114+
115+ if (content .contains ("package" ) && content .contains (filePath )) {
116+ content = content .replaceAll ("package.*" +filePath +".*;" ,"" );
117+ }
118+ return content ;
119+ }
120+
105121 public void createDataPropertiesFile () throws IOException {
106122
107123 File dir = new File (dataDirectoryPath );
@@ -114,7 +130,27 @@ public void createDataPropertiesFile() throws IOException {
114130 }
115131 }
116132
117- public void addSpecificsToTestRunners () throws IOException {
133+ public void addSpecificsToTestRunnersForTextTemplateFile () throws IOException {
134+
135+ File folder = new File (runnersDirectoryPath );
136+ File [] listOfFiles = folder .listFiles ();
137+ assert listOfFiles != null ;
138+
139+ for (File file : listOfFiles ) {
140+ if (file .isFile ()) {
141+ Map <String , String > map = new HashMap <>();
142+ map .put ("TEST_RUNNER_CLASS_NAME" ,file .getName ().split ("\\ ." )[0 ]);
143+ map .put ("FEATURE_FILES_PATH" , featureFilesPath );
144+ map .put ("FEATURE_FILES_TAGS" ,includedTags );
145+ replaceTerms (file , map );
146+ }
147+ }
148+ }
149+
150+ public void addSpecificsToTestRunnersForJavaTemplateFile () throws IOException {
151+
152+ File javaFile = new File (templateRunnerPath );
153+ String javaFileName = javaFile .getName ().split ("\\ ." )[0 ];
118154
119155 File folder = new File (runnersDirectoryPath );
120156 File [] listOfFiles = folder .listFiles ();
@@ -123,6 +159,7 @@ public void addSpecificsToTestRunners() throws IOException {
123159 for (File file : listOfFiles ) {
124160 if (file .isFile ()) {
125161 Map <String , String > map = new HashMap <>();
162+ map .put (javaFileName ,file .getName ().split ("\\ ." )[0 ]);
126163 map .put ("TEST_RUNNER_CLASS_NAME" ,file .getName ().split ("\\ ." )[0 ]);
127164 map .put ("FEATURE_FILES_PATH" , featureFilesPath );
128165 map .put ("FEATURE_FILES_TAGS" ,includedTags );
@@ -131,6 +168,14 @@ public void addSpecificsToTestRunners() throws IOException {
131168 }
132169 }
133170
171+ public void addSpecificsToTestRunners () throws IOException {
172+
173+ if (templateRunnerPath .contains (".java" ))
174+ addSpecificsToTestRunnersForJavaTemplateFile ();
175+ else
176+ addSpecificsToTestRunnersForTextTemplateFile ();
177+ }
178+
134179 public void replaceTerms (File file , Map <String , String > map ) throws IOException {
135180
136181 StringBuilder oldContent = new StringBuilder ();
0 commit comments