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.ant;
26
27 import static net.sourceforge.plantumldependency.cli.main.program.PlantUMLDependencyProgram.processProgramArguments;
28 import static net.sourceforge.plantumldependency.common.utils.exception.ExceptionUtils.getStackTraceAsString;
29 import static net.sourceforge.plantumldependency.common.utils.map.MapUtils.putNonEmptyStringToMap;
30
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36 import net.sourceforge.plantumldependency.cli.exception.PlantUMLDependencyException;
37 import net.sourceforge.plantumldependency.cli.main.option.basedirectory.PlantUMLDependencyBaseDirectoryOption;
38 import net.sourceforge.plantumldependency.cli.main.option.display.name.PlantUMLDependencyDisplayNameOption;
39 import net.sourceforge.plantumldependency.cli.main.option.display.packagename.PlantUMLDependencyDisplayPackageNameOption;
40 import net.sourceforge.plantumldependency.cli.main.option.display.type.PlantUMLDependencyDisplayTypeOption;
41 import net.sourceforge.plantumldependency.cli.main.option.exclude.PlantUMLDependencyExcludeOption;
42 import net.sourceforge.plantumldependency.cli.main.option.include.PlantUMLDependencyIncludeOption;
43 import net.sourceforge.plantumldependency.cli.main.option.programminglanguage.PlantUMLDependencyProgrammingLanguageOption;
44 import net.sourceforge.plantumldependency.commoncli.option.impl.output.OutputOption;
45 import net.sourceforge.plantumldependency.commoncli.option.impl.verbose.VerboseLevelOption;
46
47 import org.apache.tools.ant.BuildException;
48 import org.apache.tools.ant.Task;
49
50
51
52
53
54
55
56
57 public class PlantUMLDependencyProgramTask extends Task {
58
59
60
61
62
63
64
65
66
67
68
69 private static String[] createArgs(final Map < String, String > argumentsMap) {
70
71 final List < String > argsList = new ArrayList < String >();
72
73 for (final Map.Entry < String, String > argument : argumentsMap.entrySet()) {
74 final String argumentSynopsis = argument.getKey();
75 final String argumentValue = argument.getValue();
76 argsList.add(argumentSynopsis);
77 argsList.add(argumentValue);
78 }
79
80 return argsList.toArray(new String[argsList.size()]);
81 }
82
83
84
85
86
87
88 private final Map < String, String > argsMap = new HashMap < String, String >();
89
90
91
92
93
94
95 @Override
96 public void execute() {
97 try {
98 final String[] args = createArgs(getArgsMap());
99 processProgramArguments(args);
100 } catch (final PlantUMLDependencyException e) {
101 log(getStackTraceAsString(e));
102 throw new BuildException(e);
103 }
104 }
105
106
107
108
109
110
111
112
113 private Map < String, String > getArgsMap() {
114 return argsMap;
115 }
116
117
118
119
120
121
122
123
124 public String getBaseDir() {
125 return getArgsMap().get(PlantUMLDependencyBaseDirectoryOption.OPTION_MAIN_SYNOPSIS);
126 }
127
128
129
130
131
132
133
134
135 public String getDisplayName() {
136 return getArgsMap().get(PlantUMLDependencyDisplayNameOption.OPTION_MAIN_SYNOPSIS);
137 }
138
139
140
141
142
143
144
145
146 public String getDisplayPackageName() {
147 return getArgsMap().get(PlantUMLDependencyDisplayPackageNameOption.OPTION_MAIN_SYNOPSIS);
148 }
149
150
151
152
153
154
155
156
157 public String getDisplayType() {
158 return getArgsMap().get(PlantUMLDependencyDisplayTypeOption.OPTION_MAIN_SYNOPSIS);
159 }
160
161
162
163
164
165
166
167
168 public String getExcludes() {
169 return getArgsMap().get(PlantUMLDependencyExcludeOption.OPTION_MAIN_SYNOPSIS);
170 }
171
172
173
174
175
176
177
178
179 public String getIncludes() {
180 return getArgsMap().get(PlantUMLDependencyIncludeOption.OPTION_MAIN_SYNOPSIS);
181 }
182
183
184
185
186
187
188
189
190 public String getOutput() {
191 return getArgsMap().get(OutputOption.OPTION_MAIN_SYNOPSIS);
192 }
193
194
195
196
197
198
199
200
201 public String getProgrammingLanguage() {
202 return getArgsMap().get(PlantUMLDependencyProgrammingLanguageOption.OPTION_MAIN_SYNOPSIS);
203 }
204
205
206
207
208
209
210
211
212 public String getVerboseLevel() {
213 return getArgsMap().get(VerboseLevelOption.OPTION_MAIN_SYNOPSIS);
214 }
215
216
217
218
219
220
221
222
223
224 public void setBaseDir(final String value) {
225 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyBaseDirectoryOption.OPTION_MAIN_SYNOPSIS, value);
226 }
227
228
229
230
231
232
233
234
235
236 public void setDisplayName(final String value) {
237 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyDisplayNameOption.OPTION_MAIN_SYNOPSIS, value);
238 }
239
240
241
242
243
244
245
246
247
248 public void setDisplayPackageName(final String value) {
249 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyDisplayPackageNameOption.OPTION_MAIN_SYNOPSIS, value);
250 }
251
252
253
254
255
256
257
258
259
260 public void setDisplayType(final String value) {
261 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyDisplayTypeOption.OPTION_MAIN_SYNOPSIS, value);
262 }
263
264
265
266
267
268
269
270
271
272 public void setExcludes(final String value) {
273 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyExcludeOption.OPTION_MAIN_SYNOPSIS, value);
274 }
275
276
277
278
279
280
281
282
283
284 public void setIncludes(final String value) {
285 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyIncludeOption.OPTION_MAIN_SYNOPSIS, value);
286 }
287
288
289
290
291
292
293
294
295
296 public void setOutput(final String value) {
297 putNonEmptyStringToMap(getArgsMap(), OutputOption.OPTION_MAIN_SYNOPSIS, value);
298 }
299
300
301
302
303
304
305
306
307
308 public void setProgrammingLanguage(final String value) {
309 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyProgrammingLanguageOption.OPTION_MAIN_SYNOPSIS, value);
310 }
311
312
313
314
315
316
317
318
319
320 public void setVerboseLevel(final String value) {
321 putNonEmptyStringToMap(getArgsMap(), VerboseLevelOption.OPTION_MAIN_SYNOPSIS, value);
322 }
323
324
325
326
327
328
329 @Override
330 public String toString() {
331 return getClass().getSimpleName() + " [output=" + getOutput() + ", verboseLevel=" + getVerboseLevel()
332 + ", programmingLanguage=" + getProgrammingLanguage() + ", includes=" + getIncludes() + ", excludes="
333 + getExcludes() + ", displayType=" + getDisplayType() + ", baseDir=" + getBaseDir() + ", displayName="
334 + getDisplayName() + ", displayPackageName=" + getDisplayPackageName() + "]";
335 }
336 }