1 /*
2 PlantUMLDependencyProgramTask.java
3 Creation date : 15/06/2011
4 Copyright © Benjamin Croizet (graffity2199@yahoo.fr)
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 or GNU Lesser General Public License as published by the
9 Free Software Foundation; either version 3 of the License,
10 or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received copies of the GNU General Public License
18 and GNU Lesser General Public License along with this program;
19 if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 http://www.fsf.org/licensing/licenses/gpl.html
22 http://www.gnu.org/licenses/lgpl.html
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 * The PlantUML dependency <a href="http://ant.apache.org"><b>Ant</b></a> {@link Task}.
52 *
53 * @author Benjamin Croizet (<a href="mailto:graffity2199@yahoo.fr>graffity2199@yahoo.fr</a>)
54 * @since 1.1.0
55 * @version 1.4.0
56 */
57 public class PlantUMLDependencyProgramTask extends Task {
58
59 /**
60 * Creates the array of {@link String} arguments to call PlantUML Dependency.
61 *
62 * @param argumentsMap
63 * the {@link Map} of arguments taken from the Ant build file. The {@link Map}
64 * perfectly matches the PlantUML Dependency command line arguments, with argument
65 * main synopsis as keys, and their associated value, mustn't be <code>null</code>.
66 * @return the array of {@link String} containing PlantUML Dependency command line arguments.
67 * @since 1.1.0
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 * The {@link Map} of arguments taken from the Ant build file. The {@link Map} perfectly matches
85 * the PlantUML Dependency command line arguments, with argument main synopsis as keys, and
86 * their associated value.
87 */
88 private final Map < String, String > argsMap = new HashMap < String, String >();
89
90 /**
91 * {@inheritDoc}
92 *
93 * @since 1.1.0
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 * Gets the value of <code>argsMap</code>.
108 *
109 * @return the value of <code>argsMap</code>.
110 * @see #setArgsMap(Map)
111 * @since 1.1.0
112 */
113 private Map < String, String > getArgsMap() {
114 return argsMap;
115 }
116
117 /**
118 * Gets the value of <code>baseDir</code>.
119 *
120 * @return the value of <code>baseDir</code>.
121 * @see #setBaseDir(String)
122 * @since 1.1.0
123 */
124 public String getBaseDir() {
125 return getArgsMap().get(PlantUMLDependencyBaseDirectoryOption.OPTION_MAIN_SYNOPSIS);
126 }
127
128 /**
129 * Gets the value of <code>displayName</code>.
130 *
131 * @return the value of <code>displayName</code>.
132 * @see #setDisplayName(String)
133 * @since 1.4.0
134 */
135 public String getDisplayName() {
136 return getArgsMap().get(PlantUMLDependencyDisplayNameOption.OPTION_MAIN_SYNOPSIS);
137 }
138
139 /**
140 * Gets the value of <code>displayPackageName</code>.
141 *
142 * @return the value of <code>displayPackageName</code>.
143 * @see #setDisplayPackageName(String)
144 * @since 1.4.0
145 */
146 public String getDisplayPackageName() {
147 return getArgsMap().get(PlantUMLDependencyDisplayPackageNameOption.OPTION_MAIN_SYNOPSIS);
148 }
149
150 /**
151 * Gets the value of <code>displayType</code>.
152 *
153 * @return the value of <code>displayType</code>.
154 * @see #setDisplayType(String)
155 * @since 1.1.0
156 */
157 public String getDisplayType() {
158 return getArgsMap().get(PlantUMLDependencyDisplayTypeOption.OPTION_MAIN_SYNOPSIS);
159 }
160
161 /**
162 * Gets the value of <code>excludes</code>.
163 *
164 * @return the value of <code>excludes</code>.
165 * @see #setExcludes(String)
166 * @since 1.1.0
167 */
168 public String getExcludes() {
169 return getArgsMap().get(PlantUMLDependencyExcludeOption.OPTION_MAIN_SYNOPSIS);
170 }
171
172 /**
173 * Gets the value of <code>includes</code>.
174 *
175 * @return the value of <code>includes</code>.
176 * @see #setIncludes(String)
177 * @since 1.1.0
178 */
179 public String getIncludes() {
180 return getArgsMap().get(PlantUMLDependencyIncludeOption.OPTION_MAIN_SYNOPSIS);
181 }
182
183 /**
184 * Gets the value of <code>output</code>.
185 *
186 * @return the value of <code>output</code>.
187 * @see #setOutput(String)
188 * @since 1.1.0
189 */
190 public String getOutput() {
191 return getArgsMap().get(OutputOption.OPTION_MAIN_SYNOPSIS);
192 }
193
194 /**
195 * Gets the value of <code>programmingLanguage</code>.
196 *
197 * @return the value of <code>programmingLanguage</code>.
198 * @see #setProgrammingLanguage(String)
199 * @since 1.1.0
200 */
201 public String getProgrammingLanguage() {
202 return getArgsMap().get(PlantUMLDependencyProgrammingLanguageOption.OPTION_MAIN_SYNOPSIS);
203 }
204
205 /**
206 * Gets the value of <code>verboseLevel</code>.
207 *
208 * @return the value of <code>verboseLevel</code>.
209 * @see #setVerboseLevel(String)
210 * @since 1.1.0
211 */
212 public String getVerboseLevel() {
213 return getArgsMap().get(VerboseLevelOption.OPTION_MAIN_SYNOPSIS);
214 }
215
216 /**
217 * Sets the value of <code>baseDir</code>.
218 *
219 * @param value
220 * the <code>baseDir</code> to set, can be <code>null</code>.
221 * @see #getBaseDir()
222 * @since 1.1.0
223 */
224 public void setBaseDir(final String value) {
225 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyBaseDirectoryOption.OPTION_MAIN_SYNOPSIS, value);
226 }
227
228 /**
229 * Sets the value of <code>displayName</code>.
230 *
231 * @param value
232 * the <code>displayName</code> to set, can be <code>null</code>.
233 * @see #getDisplayName()
234 * @since 1.4.0
235 */
236 public void setDisplayName(final String value) {
237 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyDisplayNameOption.OPTION_MAIN_SYNOPSIS, value);
238 }
239
240 /**
241 * Sets the value of <code>displayPackageName</code>.
242 *
243 * @param value
244 * the <code>displayPackageName</code> to set, can be <code>null</code>.
245 * @see #getDisplayPackageName()
246 * @since 1.4.0
247 */
248 public void setDisplayPackageName(final String value) {
249 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyDisplayPackageNameOption.OPTION_MAIN_SYNOPSIS, value);
250 }
251
252 /**
253 * Sets the value of <code>displayType</code>.
254 *
255 * @param value
256 * the <code>displayType</code> to set, can be <code>null</code>.
257 * @see #getDisplayType()
258 * @since 1.1.0
259 */
260 public void setDisplayType(final String value) {
261 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyDisplayTypeOption.OPTION_MAIN_SYNOPSIS, value);
262 }
263
264 /**
265 * Sets the value of <code>excludes</code>.
266 *
267 * @param value
268 * the <code>excludes</code> to set, can be <code>null</code>.
269 * @see #getExcludes()
270 * @since 1.1.0
271 */
272 public void setExcludes(final String value) {
273 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyExcludeOption.OPTION_MAIN_SYNOPSIS, value);
274 }
275
276 /**
277 * Sets the value of <code>includes</code>.
278 *
279 * @param value
280 * the <code>includes</code> to set, can be <code>null</code>.
281 * @see #getIncludes()
282 * @since 1.1.0
283 */
284 public void setIncludes(final String value) {
285 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyIncludeOption.OPTION_MAIN_SYNOPSIS, value);
286 }
287
288 /**
289 * Sets the value of <code>output</code>.
290 *
291 * @param value
292 * the <code>output</code> to set, can be <code>null</code>.
293 * @see #getOutput()
294 * @since 1.1.0
295 */
296 public void setOutput(final String value) {
297 putNonEmptyStringToMap(getArgsMap(), OutputOption.OPTION_MAIN_SYNOPSIS, value);
298 }
299
300 /**
301 * Sets the value of <code>programmingLanguage</code>.
302 *
303 * @param value
304 * the <code>programmingLanguage</code> to set, can be <code>null</code>.
305 * @see #getProgrammingLanguage()
306 * @since 1.1.0
307 */
308 public void setProgrammingLanguage(final String value) {
309 putNonEmptyStringToMap(getArgsMap(), PlantUMLDependencyProgrammingLanguageOption.OPTION_MAIN_SYNOPSIS, value);
310 }
311
312 /**
313 * Sets the value of <code>verboseLevel</code>.
314 *
315 * @param value
316 * the <code>verboseLevel</code> to set, can be <code>null</code>.
317 * @see #getVerboseLevel()
318 * @since 1.1.0
319 */
320 public void setVerboseLevel(final String value) {
321 putNonEmptyStringToMap(getArgsMap(), VerboseLevelOption.OPTION_MAIN_SYNOPSIS, value);
322 }
323
324 /**
325 * {@inheritDoc}
326 *
327 * @since 1.1.0
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 }