1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.cli.main.option.output;
26
27 import static java.util.logging.Level.FINE;
28 import static java.util.logging.Logger.getLogger;
29 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.BASE_DIRECTORY_OPTION_NULL_ERROR;
30 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.DISPLAY_NAME_OPTION_NULL_ERROR;
31 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.DISPLAY_PACKAGE_NAME_OPTION_NULL_ERROR;
32 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.DISPLAY_TYPE_OPTION_NULL_ERROR;
33 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.EXCLUDE_OPTION_NULL_ERROR;
34 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.INCLUDE_OPTION_NULL_ERROR;
35 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.PROGRAMMING_LANGUAGE_OPTION_NULL_ERROR;
36 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.SPACE_CHAR;
37 import static net.sourceforge.plantumldependency.common.utils.check.ParameterCheckerUtils.checkNull;
38 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.buildLogString;
39 import static net.sourceforge.plantumldependency.common.utils.log.LogUtils.setLevelOfAllLoggersAndHandlers;
40 import static net.sourceforge.plantumldependency.commoncli.constants.log.ErrorConstants.VERBOSE_OPTION_NULL_ERROR;
41 import static net.sourceforge.plantumldependency.commoncli.constants.log.FineConstants.OPTION_NOT_SPECIFIED_FINE;
42 import static net.sourceforge.plantumldependency.commoncli.option.status.OptionStatus.ACTIVE_OPTIONAL_OPTION_STATUS;
43
44 import java.io.File;
45 import java.util.Set;
46 import java.util.logging.Level;
47 import java.util.logging.Logger;
48 import java.util.regex.Pattern;
49
50 import net.sourceforge.plantumldependency.cli.main.option.basedirectory.PlantUMLDependencyBaseDirectoryOption;
51 import net.sourceforge.plantumldependency.cli.main.option.display.name.PlantUMLDependencyDisplayNameOption;
52 import net.sourceforge.plantumldependency.cli.main.option.display.packagename.PlantUMLDependencyDisplayPackageNameOption;
53 import net.sourceforge.plantumldependency.cli.main.option.display.type.PlantUMLDependencyDisplayTypeOption;
54 import net.sourceforge.plantumldependency.cli.main.option.display.type.argument.DisplayType;
55 import net.sourceforge.plantumldependency.cli.main.option.exclude.PlantUMLDependencyExcludeOption;
56 import net.sourceforge.plantumldependency.cli.main.option.include.PlantUMLDependencyIncludeOption;
57 import net.sourceforge.plantumldependency.cli.main.option.programminglanguage.PlantUMLDependencyProgrammingLanguageOption;
58 import net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.ProgrammingLanguage;
59 import net.sourceforge.plantumldependency.commoncli.command.CommandLine;
60 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
61 import net.sourceforge.plantumldependency.commoncli.option.argument.impl.file.ExistingOrNotFileOptionArgumentImpl;
62 import net.sourceforge.plantumldependency.commoncli.option.execution.ExecutableOption;
63 import net.sourceforge.plantumldependency.commoncli.option.execution.OptionExecution;
64 import net.sourceforge.plantumldependency.commoncli.option.impl.output.OutputOption;
65 import net.sourceforge.plantumldependency.commoncli.option.impl.verbose.VerboseLevelOption;
66
67 import org.apache.tools.ant.types.FileSet;
68
69
70
71
72
73
74
75
76
77
78 public class PlantUMLDependencyOutputOption extends OutputOption implements ExecutableOption {
79
80
81 private static final long serialVersionUID = -1629517125349614965L;
82
83
84 private static final transient Logger LOGGER = getLogger(PlantUMLDependencyOutputOption.class.getName());
85
86
87 private VerboseLevelOption verboseLevelOption;
88
89
90 private PlantUMLDependencyProgrammingLanguageOption programmingLanguageOption;
91
92
93 private PlantUMLDependencyIncludeOption includeOption;
94
95
96 private PlantUMLDependencyExcludeOption excludeOption;
97
98
99 private PlantUMLDependencyDisplayTypeOption displayTypeOption;
100
101
102 private PlantUMLDependencyDisplayPackageNameOption displayPackageNameOption;
103
104
105 private PlantUMLDependencyDisplayNameOption displayNameOption;
106
107
108 private PlantUMLDependencyBaseDirectoryOption baseDirOption;
109
110
111 private int priority;
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 public PlantUMLDependencyOutputOption(final VerboseLevelOption verboseLvlOpt,
146 final PlantUMLDependencyProgrammingLanguageOption programmingLanguageOpt,
147 final PlantUMLDependencyIncludeOption includeOpt, final PlantUMLDependencyExcludeOption excludeOpt,
148 final PlantUMLDependencyDisplayTypeOption displayTypeOpt,
149 final PlantUMLDependencyDisplayPackageNameOption displayPackageNameOpt,
150 final PlantUMLDependencyDisplayNameOption displayNameOpt,
151 final PlantUMLDependencyBaseDirectoryOption baseDirOpt, final int optionPriority) {
152 super(new ExistingOrNotFileOptionArgumentImpl(true), new StringBuilder(
153 "To specify the output file path where to generate the PlantUML description."), SPACE_CHAR,
154 ACTIVE_OPTIONAL_OPTION_STATUS);
155 setVerboseLevelOption(verboseLvlOpt);
156 setProgrammingLanguageOption(programmingLanguageOpt);
157 setIncludeOption(includeOpt);
158 setExcludeOption(excludeOpt);
159 setDisplayTypeOption(displayTypeOpt);
160 setDisplayPackageNameOption(displayPackageNameOpt);
161 setDisplayNameOption(displayNameOpt);
162 setBaseDirOption(baseDirOpt);
163 setPriority(optionPriority);
164 }
165
166
167
168
169
170
171
172
173 private PlantUMLDependencyBaseDirectoryOption getBaseDirOption() {
174 return baseDirOption;
175 }
176
177
178
179
180
181
182
183
184 private PlantUMLDependencyDisplayNameOption getDisplayNameOption() {
185 return displayNameOption;
186 }
187
188
189
190
191
192
193
194
195 private PlantUMLDependencyDisplayPackageNameOption getDisplayPackageNameOption() {
196 return displayPackageNameOption;
197 }
198
199
200
201
202
203
204
205
206 private PlantUMLDependencyDisplayTypeOption getDisplayTypeOption() {
207 return displayTypeOption;
208 }
209
210
211
212
213
214
215
216
217 private PlantUMLDependencyExcludeOption getExcludeOption() {
218 return excludeOption;
219 }
220
221
222
223
224
225
226
227
228 private PlantUMLDependencyIncludeOption getIncludeOption() {
229 return includeOption;
230 }
231
232
233
234
235
236
237 @Override
238 public int getPriority() {
239 return priority;
240 }
241
242
243
244
245
246
247
248
249 private PlantUMLDependencyProgrammingLanguageOption getProgrammingLanguageOption() {
250 return programmingLanguageOption;
251 }
252
253
254
255
256
257
258
259
260 private VerboseLevelOption getVerboseLevelOption() {
261 return verboseLevelOption;
262 }
263
264
265
266
267
268
269 @Override
270 public OptionExecution parseCommandLine(final CommandLine commandLine) throws CommandLineException {
271 OptionExecution optionExecution = null;
272
273 final Level verboseLevel = getVerboseLevelOption().findAndParseArgumentOrGetDefaultArgument(commandLine);
274 setLevelOfAllLoggersAndHandlers(verboseLevel);
275
276 if (commandLine.isOptionSpecified(this)) {
277 final File outputFile = findAndParseArgumentOrGetDefaultArgument(commandLine);
278 final String excludes = getExcludeOption().findAndParseArgumentAsStringOrGetDefaultArgument(commandLine);
279 final FileSet includesExcludes = getIncludeOption().findAndParseArgumentOrGetDefaultArgument(commandLine);
280 includesExcludes.setExcludes(excludes);
281 final File baseDirectory = getBaseDirOption().findAndParseArgumentOrGetDefaultArgument(commandLine);
282 includesExcludes.setDir(baseDirectory);
283 final Set < DisplayType > displayTypesOptions = getDisplayTypeOption()
284 .findAndParseArgumentOrGetDefaultArgument(commandLine);
285 final Pattern displayPackageNamePatternOpt = getDisplayPackageNameOption()
286 .findAndParseArgumentOrGetDefaultArgument(commandLine);
287 final Pattern displayNamePatternOpt = getDisplayNameOption().findAndParseArgumentOrGetDefaultArgument(
288 commandLine);
289 final ProgrammingLanguage programmingLanguage = getProgrammingLanguageOption()
290 .findAndParseArgumentOrGetDefaultArgument(commandLine);
291 optionExecution = new PlantUMLDependencyOutputOptionExecution(outputFile, programmingLanguage,
292 includesExcludes, displayTypesOptions, displayPackageNamePatternOpt, displayNamePatternOpt,
293 getPriority());
294 } else {
295 LOGGER.log(FINE, buildLogString(OPTION_NOT_SPECIFIED_FINE, getAllNames()));
296 }
297
298 return optionExecution;
299 }
300
301
302
303
304
305
306
307
308
309 private void setBaseDirOption(final PlantUMLDependencyBaseDirectoryOption value) {
310 checkNull(value, BASE_DIRECTORY_OPTION_NULL_ERROR);
311
312 baseDirOption = value;
313 }
314
315
316
317
318
319
320
321
322
323 private void setDisplayNameOption(final PlantUMLDependencyDisplayNameOption value) {
324 checkNull(value, DISPLAY_NAME_OPTION_NULL_ERROR);
325
326 displayNameOption = value;
327 }
328
329
330
331
332
333
334
335
336
337 private void setDisplayPackageNameOption(final PlantUMLDependencyDisplayPackageNameOption value) {
338 checkNull(value, DISPLAY_PACKAGE_NAME_OPTION_NULL_ERROR);
339
340 displayPackageNameOption = value;
341 }
342
343
344
345
346
347
348
349
350
351 private void setDisplayTypeOption(final PlantUMLDependencyDisplayTypeOption value) {
352 checkNull(value, DISPLAY_TYPE_OPTION_NULL_ERROR);
353
354 displayTypeOption = value;
355 }
356
357
358
359
360
361
362
363
364
365 private void setExcludeOption(final PlantUMLDependencyExcludeOption value) {
366 checkNull(value, EXCLUDE_OPTION_NULL_ERROR);
367
368 excludeOption = value;
369 }
370
371
372
373
374
375
376
377
378
379 private void setIncludeOption(final PlantUMLDependencyIncludeOption value) {
380 checkNull(value, INCLUDE_OPTION_NULL_ERROR);
381
382 includeOption = value;
383 }
384
385
386
387
388
389
390
391
392
393 private void setPriority(final int value) {
394 priority = value;
395 }
396
397
398
399
400
401
402
403
404
405 private void setProgrammingLanguageOption(final PlantUMLDependencyProgrammingLanguageOption value) {
406 checkNull(value, PROGRAMMING_LANGUAGE_OPTION_NULL_ERROR);
407
408 programmingLanguageOption = value;
409 }
410
411
412
413
414
415
416
417
418
419 private void setVerboseLevelOption(final VerboseLevelOption value) {
420 checkNull(value, VERBOSE_OPTION_NULL_ERROR);
421
422 verboseLevelOption = value;
423 }
424 }