16
16
* limitations under the License.
17
17
*/
18
18
19
- import org .apache .commons .lang3 .StringUtils ;
20
19
import org .apache .maven .plugin .AbstractMojo ;
21
20
import org .apache .maven .plugin .MojoExecution ;
22
21
import org .apache .maven .plugin .MojoExecutionException ;
@@ -56,8 +55,13 @@ public class MyMojo extends AbstractMojo
56
55
@ Parameter ( defaultValue = "${mojoExecution}" , readonly = true )
57
56
private MojoExecution mojo ;
58
57
59
- String runnersDirectoryPath = System .getProperty ("user.dir" )+ File .separator +"target" +File .separator +"parallel-xbrowser" +File .separator +"runners" ;
58
+ String baseDirectory = System .getProperty ("user.dir" )+ File .separator +"target" +File .separator +"parallel-xbrowser" ;
59
+ String runnersDirectoryPath = baseDirectory +File .separator +"runners" ;
60
+ String propertiesDirectoryPath = baseDirectory +File .separator +"properties" ;
61
+ String dataDirectoryPath = baseDirectory +File .separator +"data" ;
60
62
Map <Integer , Map <String , String >> configMap ;
63
+ String fileNamePattern = "IT_Cucumber_Parallel_Cross_Browser_" ;
64
+ int totalFiles = 0 ;
61
65
62
66
@ Override
63
67
public void execute () throws MojoExecutionException {
@@ -69,35 +73,23 @@ public void execute() throws MojoExecutionException {
69
73
getLog ().info ("------------------------------------------------------------------------" );
70
74
try {
71
75
configMap = convertXMLToJSONAndReturnMap ();
72
- prepareTemplateRunnerFile ();
73
76
createTestRunners ();
77
+ createPropertiesFilesForEachTestRunner ();
74
78
addSpecificsToTestRunners ();
75
79
printConfigurationsLogs ();
80
+ createDataPropertiesFile ();
76
81
} catch (Exception exc ) {
77
82
getLog ().info ("Exception : " +exc .getMessage ());
78
83
}
79
84
}
80
85
81
- public void prepareTemplateRunnerFile () throws IOException {
82
-
83
- Map <String , String > map = new HashMap <>();
84
- map .put ("FEATURE_FILES_PATH" , featureFilesPath );
85
- map .put ("FEATURE_FILES_TAGS" ,includedTags );
86
-
87
- String filePath = templateRunnerPath ;
88
- File file = new File (filePath );
89
- replaceTerms (file , map );
90
- }
91
-
92
86
public void createTestRunners () throws IOException {
93
87
94
- int totalFiles = configMap .size ();
95
88
String content = new String (Files .readAllBytes (Paths .get (templateRunnerPath )));
96
- String fileName = "IT_Cucumber_Parallel_Cross_Browser_Test_Runner_" ;
97
89
File dir = new File (runnersDirectoryPath );
98
90
99
91
for (int i =0 ;i <totalFiles ;i ++) {
100
- String filePath = runnersDirectoryPath + File .separator + fileName +i +".java" ;
92
+ String filePath = runnersDirectoryPath + File .separator + fileNamePattern +i +".java" ;
101
93
if (!dir .exists ()) dir .mkdirs ();
102
94
File file = new File (filePath );
103
95
boolean flag = file .createNewFile ();
@@ -108,21 +100,31 @@ public void createTestRunners() throws IOException {
108
100
getLog ().info ("Total Test Runners Created : " +totalFiles );
109
101
}
110
102
103
+ public void createDataPropertiesFile () throws IOException {
104
+
105
+ File dir = new File (dataDirectoryPath );
106
+
107
+ for (int i =0 ;i <totalFiles ;i ++) {
108
+ String filePath = dataDirectoryPath + File .separator + fileNamePattern +i +".properties" ;
109
+ if (!dir .exists ()) dir .mkdirs ();
110
+ File file = new File (filePath );
111
+ file .createNewFile ();
112
+ }
113
+ }
114
+
111
115
public void addSpecificsToTestRunners () throws IOException {
112
116
113
117
File folder = new File (runnersDirectoryPath );
114
118
File [] listOfFiles = folder .listFiles ();
115
119
assert listOfFiles != null ;
116
120
117
- int index = 0 ;
118
-
119
121
for (File file : listOfFiles ) {
120
122
if (file .isFile ()) {
121
- Map <String , String > m = configMap . get ( index );
122
- m .put ("TEST_RUNNER_CLASS_NAME" ,file .getName ().split ("\\ ." )[0 ]);
123
- replaceTerms ( file , m );
124
- m . remove ( "TEST_RUNNER_CLASS_NAME" );
125
- index += 1 ;
123
+ Map <String , String > map = new HashMap <>( );
124
+ map .put ("TEST_RUNNER_CLASS_NAME" ,file .getName ().split ("\\ ." )[0 ]);
125
+ map . put ( "FEATURE_FILES_PATH" , featureFilesPath );
126
+ map . put ( "FEATURE_FILES_TAGS" , includedTags );
127
+ replaceTerms ( file , map ) ;
126
128
}
127
129
}
128
130
}
@@ -152,12 +154,33 @@ public void replaceTerms(File file, Map<String, String> map) throws IOException
152
154
}
153
155
}
154
156
157
+ public void createPropertiesFilesForEachTestRunner () throws IOException {
158
+
159
+ Map <Integer , Map <String , String >> map = configMap ;
160
+ File dir = new File (propertiesDirectoryPath );
161
+
162
+ for (int i =0 ;i <totalFiles ;i ++) {
163
+ String filePath = propertiesDirectoryPath + File .separator + fileNamePattern +i + ".properties" ;
164
+ if (!dir .exists ()) dir .mkdirs ();
165
+
166
+ File file = new File (filePath );
167
+ BufferedWriter bf = new BufferedWriter (new FileWriter (file ));
168
+
169
+ for (Map .Entry <String , String > entry : map .get (i ).entrySet ()) {
170
+ bf .write (entry .getKey () + ":" + entry .getValue ());
171
+ bf .newLine ();
172
+ }
173
+ bf .flush ();
174
+ }
175
+ }
176
+
155
177
public Map <Integer , Map <String , String >> convertXMLToJSONAndReturnMap () throws IOException {
156
178
157
179
Map <Integer , Map <String , String >> map = new HashMap <>();
158
180
String content = new String (Files .readAllBytes (Paths .get (configurationFilePath )));
159
181
JSONObject obj = new JSONObject (XML .toJSONObject (content ).toString ()).getJSONObject ("configurations" );
160
182
JSONArray arr = obj .getJSONArray ("configuration" );
183
+ totalFiles = arr .length ();
161
184
for (int i =0 ;i <arr .length ();i ++){
162
185
map .put (i , jsonToMap (arr .get (i ).toString ()));
163
186
}
@@ -173,7 +196,7 @@ public Map<String, String> jsonToMap(String content) throws JSONException {
173
196
while ( keys .hasNext () ){
174
197
String key = (String )keys .next ();
175
198
String value = jObject .get (key ).toString ();
176
- map .put (key + "Value" , value );
199
+ map .put (key , value );
177
200
}
178
201
return map ;
179
202
}
@@ -192,7 +215,7 @@ public void printConfigurationsLogs(){
192
215
for (Map .Entry <Integer , Map <String , String >> mapElement : configMap .entrySet ()) {
193
216
Map <String , String > map = mapElement .getValue ();
194
217
for (Map .Entry <String , String > mapEle : map .entrySet ()) {
195
- getLog ().info (StringUtils . substringBefore ( mapEle .getKey (), "Value" ) + " : " + mapEle .getValue ());
218
+ getLog ().info (mapEle .getKey () + " : " + mapEle .getValue ());
196
219
}
197
220
getLog ().info ("------------------------------------------------------------------------" );
198
221
}
0 commit comments