32
32
import org .apache .commons .cli .Options ;
33
33
import org .apache .commons .cli .ParseException ;
34
34
35
- import com .github .checkstyle .data .CliPaths ;
35
+ import com .github .checkstyle .data .CliOptions ;
36
36
import com .github .checkstyle .data .CompareMode ;
37
37
import com .github .checkstyle .data .DiffReport ;
38
38
import com .github .checkstyle .data .MergedConfigurationModule ;
39
+ import com .github .checkstyle .data .ThreadingMode ;
39
40
import com .github .checkstyle .parser .CheckstyleConfigurationsParser ;
40
41
import com .github .checkstyle .parser .CheckstyleReportsParser ;
41
42
import com .github .checkstyle .parser .CheckstyleTextParser ;
@@ -65,6 +66,7 @@ public final class Main {
65
66
+ "\t --output - path to store the resulting diff report (optional, if absent then "
66
67
+ "default path will be used: ~/XMLDiffGen_report_yyyy.mm.dd_hh_mm_ss), remember, "
67
68
+ "if this folder exists its content will be purged;\n "
69
+ + "\t --threadingMode - which type of threading mode to use: SINGLE or MULTI;\n "
68
70
+ "\t -h - simply shows help message." ;
69
71
70
72
/**
@@ -107,6 +109,11 @@ public final class Main {
107
109
*/
108
110
private static final String OPTION_REFFILES_PATH = "refFiles" ;
109
111
112
+ /**
113
+ * Name for command line option "threadingMode".
114
+ */
115
+ private static final String OPTION_THREADING_MODE = "threadingMode" ;
116
+
110
117
/**
111
118
* Name for command line option "outputPath".
112
119
*/
@@ -155,39 +162,40 @@ public static void main(final String... args) throws Exception {
155
162
System .out .println (MSG_HELP );
156
163
}
157
164
else {
158
- final CliPaths paths = getCliPaths (commandLine );
165
+ final CliOptions options = getCliOptions (commandLine );
159
166
final DiffReport diffReport ;
160
167
161
- if (paths .getCompareMode () == CompareMode .XML ) {
168
+ if (options .getCompareMode () == CompareMode .XML ) {
162
169
// XML parsing stage
163
170
System .out .println ("XML parsing is started." );
164
- diffReport = CheckstyleReportsParser .parse (paths .getBaseReportPath (),
165
- paths .getPatchReportPath (), XML_PARSE_PORTION_SIZE );
171
+ diffReport = CheckstyleReportsParser .parse (options .getBaseReportPath (),
172
+ options .getPatchReportPath (), options .getThreadingMode (),
173
+ XML_PARSE_PORTION_SIZE );
166
174
}
167
175
else {
168
176
// file parsing stage
169
177
System .out .println ("File parsing is started." );
170
- diffReport = CheckstyleTextParser .parse (paths .getBaseReportPath (),
171
- paths .getPatchReportPath ());
178
+ diffReport = CheckstyleTextParser .parse (options .getBaseReportPath (),
179
+ options .getPatchReportPath (), options . getThreadingMode ());
172
180
}
173
181
174
182
// Configuration processing stage.
175
183
MergedConfigurationModule diffConfiguration = null ;
176
- if (paths .configurationPresent ()) {
184
+ if (options .configurationPresent ()) {
177
185
System .out .println ("Creation of configuration report is started." );
178
- diffConfiguration = CheckstyleConfigurationsParser .parse (paths . getBaseConfigPath (),
179
- paths .getPatchConfigPath ());
186
+ diffConfiguration = CheckstyleConfigurationsParser .parse (
187
+ options . getBaseConfigPath (), options .getPatchConfigPath ());
180
188
}
181
189
else {
182
- System .out .println (
183
- "Configuration processing skipped: " + "no configuration paths provided." );
190
+ System .out .println ("Configuration processing skipped: "
191
+ + "no configuration options provided." );
184
192
}
185
193
186
194
// Site and XREF generation stage
187
195
System .out .println ("Creation of diff html site is started." );
188
196
try {
189
- exportResources (paths );
190
- SiteGenerator .generate (diffReport , diffConfiguration , paths );
197
+ exportResources (options );
198
+ SiteGenerator .generate (diffReport , diffConfiguration , options );
191
199
}
192
200
finally {
193
201
for (String message : JxrDummyLog .getLogs ()) {
@@ -223,8 +231,8 @@ private static CommandLine parseCli(String... args) throws ParseException {
223
231
* CLI arguments.
224
232
* @return CliPaths instance.
225
233
*/
226
- private static CliPaths getCliPaths (CommandLine commandLine ) {
227
- final CliPaths paths = parseCliToPojo (commandLine );
234
+ private static CliOptions getCliOptions (CommandLine commandLine ) {
235
+ final CliOptions paths = parseCliToPojo (commandLine );
228
236
CliArgsValidator .checkPaths (paths );
229
237
return paths ;
230
238
}
@@ -237,7 +245,7 @@ private static CliPaths getCliPaths(CommandLine commandLine) {
237
245
* @throws IOException
238
246
* thrown on failure to perform checks.
239
247
*/
240
- private static void exportResources (CliPaths paths ) throws IOException {
248
+ private static void exportResources (CliOptions paths ) throws IOException {
241
249
final Path outputPath = paths .getOutputPath ();
242
250
Files .createDirectories (outputPath );
243
251
FilesystemUtils .createOverwriteDirectory (outputPath .resolve (CSS_FILEPATH ));
@@ -265,6 +273,8 @@ private static Options buildOptions() {
265
273
"Path to the patch checkstyle-report.xml" );
266
274
options .addOption (null , OPTION_REFFILES_PATH , true ,
267
275
"Path to the directory containing source under checkstyle check, optional." );
276
+ options .addOption (null , OPTION_THREADING_MODE , true ,
277
+ "Option to control which type of threading mode to use." );
268
278
options .addOption (null , OPTION_OUTPUT_PATH , true ,
269
279
"Path to directory where diff results will be stored." );
270
280
options .addOption (null , OPTION_BASE_CONFIG_PATH , true ,
@@ -286,9 +296,9 @@ private static Options buildOptions() {
286
296
* @throws IllegalArgumentException
287
297
* on failure to find necessary arguments.
288
298
*/
289
- private static CliPaths parseCliToPojo (CommandLine commandLine )
299
+ private static CliOptions parseCliToPojo (CommandLine commandLine )
290
300
throws IllegalArgumentException {
291
- final CompareMode compareMode = getCompareMode (OPTION_COMPARE_MODE , commandLine ,
301
+ final CompareMode compareMode = getEnumOption (OPTION_COMPARE_MODE , commandLine ,
292
302
CompareMode .XML );
293
303
final Path xmlBasePath = getPath (OPTION_BASE_REPORT_PATH , commandLine , null );
294
304
final Path xmlPatchPath = getPath (OPTION_PATCH_REPORT_PATH , commandLine , null );
@@ -300,8 +310,10 @@ private static CliPaths parseCliToPojo(CommandLine commandLine)
300
310
final Path configBasePath = getPath (OPTION_BASE_CONFIG_PATH , commandLine , null );
301
311
final Path configPatchPath = getPath (OPTION_PATCH_CONFIG_PATH , commandLine , null );
302
312
final boolean shortFilePaths = commandLine .hasOption (OPTION_SHORT_PATHS );
303
- return new CliPaths (compareMode , xmlBasePath , xmlPatchPath , refFilesPath , outputPath ,
304
- configBasePath , configPatchPath , shortFilePaths );
313
+ final ThreadingMode threadingMode = getEnumOption (OPTION_THREADING_MODE , commandLine ,
314
+ ThreadingMode .MULTI );
315
+ return new CliOptions (compareMode , xmlBasePath , xmlPatchPath , refFilesPath , outputPath ,
316
+ configBasePath , configPatchPath , shortFilePaths , threadingMode );
305
317
}
306
318
307
319
/**
@@ -311,18 +323,21 @@ private static CliPaths parseCliToPojo(CommandLine commandLine)
311
323
* name of the option.
312
324
* @param commandLine
313
325
* parsed CLI.
314
- * @param defaultMode
326
+ * @param defaultValue
315
327
* mode which is used if CLI option is absent.
328
+ * @param <T>
329
+ * type of the enum.
316
330
* @return compare mode.
317
331
*/
318
- private static CompareMode getCompareMode (String optionName , CommandLine commandLine ,
319
- CompareMode defaultMode ) {
320
- final CompareMode result ;
332
+ private static < T extends Enum < T >> T getEnumOption (String optionName , CommandLine commandLine ,
333
+ T defaultValue ) {
334
+ final T result ;
321
335
if (commandLine .hasOption (optionName )) {
322
- result = CompareMode .valueOf (commandLine .getOptionValue (optionName ).toUpperCase ());
336
+ final Class <T > enumType = (Class <T >) defaultValue .getClass ();
337
+ result = Enum .valueOf (enumType , commandLine .getOptionValue (optionName ).toUpperCase ());
323
338
}
324
339
else {
325
- result = defaultMode ;
340
+ result = defaultValue ;
326
341
}
327
342
return result ;
328
343
}
0 commit comments