1
2
3
4
5
6
7
8
9
10
11 package org.mule.tools.visualizer.maven;
12
13 import org.mule.tools.visualizer.MuleVisualizer;
14 import org.mule.tools.visualizer.config.GraphConfig;
15 import org.mule.tools.visualizer.config.GraphEnvironment;
16 import org.mule.util.FileUtils;
17
18 import java.io.IOException;
19 import java.util.Iterator;
20 import java.util.LinkedList;
21 import java.util.List;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.MojoFailureException;
26
27
28 public class MuleVisualizerPlugin extends AbstractMojo
29 {
30
31
32 private List files = new LinkedList();
33
34
35 private String exec;
36
37
38 private String outputdir;
39
40
41 private String outputfile;
42
43
44 private String caption;
45
46
47 private String mappings;
48
49
50 private boolean keepdotfiles;
51
52
53 private boolean combinefiles;
54
55
56 private String urls;
57
58
59 private String config;
60
61
62 private String workingdir;
63
64
65 private boolean showconnectors;
66
67
68 private boolean showmodels;
69
70
71 private boolean showconfig;
72
73
74 private boolean showagents;
75
76
77 private boolean showtransformers;
78
79
80 private boolean showall;
81
82
83 private String templateprops;
84
85 public MuleVisualizerPlugin()
86 {
87 try
88 {
89 setWorkingdir(FileUtils.getResourcePath("target", getClass()));
90 }
91 catch (Exception e)
92 {
93 setWorkingdir(null);
94 }
95 }
96
97 public void execute() throws MojoExecutionException, MojoFailureException
98 {
99 dumpParameters();
100
101 try
102 {
103 GraphConfig config = buildConfig();
104 GraphEnvironment environment = new GraphEnvironment(config);
105 MuleVisualizer visualizer = new MuleVisualizer(environment);
106 visualizer.visualize(files);
107 }
108 catch (Exception e)
109 {
110 throw new MojoExecutionException("Failed to run visualizer: " + e.getMessage(), e);
111 }
112 }
113
114 private void dumpParameters()
115 {
116 Iterator file = getFiles().iterator();
117 while (file.hasNext())
118 {
119 getLog().info("file: " + file.next().toString());
120 }
121 getLog().info("workingdir: " + getWorkingdir());
122 getLog().info("outputdir: " + getOutputdir());
123 }
124
125 protected GraphConfig buildConfig() throws IOException
126 {
127
128 GraphConfig config = new GraphConfig();
129 config.loadProperties(getConfig());
130 config.setWorkingDirectory(getWorkingdir());
131 config.setFiles(getFiles());
132 config.loadTemplateProps(getTemplateprops());
133 config.setOutputDirectory(getOutputdir());
134 config.setOutputFilename(getOutputfile());
135 config.setCaption(getCaption());
136 config.setExecuteCommand(getExec());
137 config.setKeepDotFiles(isKeepdotfiles());
138 config.setCombineFiles(isCombinefiles());
139 config.setShowAll(isShowall());
140 if (!config.isShowAll())
141 {
142 config.setShowAgents(isShowagents());
143 config.setShowConfig(isShowconfig());
144 config.setShowConnectors(isShowconnectors());
145 config.setShowModels(isShowmodels());
146 config.setShowTransformers(isShowtransformers());
147 }
148 config.setMappingsFile(getMappings());
149 config.setUrlsFile(getUrls());
150 return config;
151 }
152
153 public void setFiles(List files)
154 {
155 this.files = files;
156 }
157
158 public List getFiles()
159 {
160 return files;
161 }
162
163 public void setOutputdir(String outputdir)
164 {
165 this.outputdir = outputdir;
166 }
167
168 public String getOutputdir()
169 {
170 return outputdir;
171 }
172
173 public void setExec(String exec)
174 {
175 this.exec = exec;
176 }
177
178 public String getExec()
179 {
180 return exec;
181 }
182
183 public void setOutputfile(String outputfile)
184 {
185 this.outputfile = outputfile;
186 }
187
188 public String getOutputfile()
189 {
190 return outputfile;
191 }
192
193 public void setCaption(String caption)
194 {
195 this.caption = caption;
196 }
197
198 public String getCaption()
199 {
200 return caption;
201 }
202
203 public void setMappings(String mappings)
204 {
205 this.mappings = mappings;
206 }
207
208 public String getMappings()
209 {
210 return mappings;
211 }
212
213 public void setKeepdotfiles(boolean keepdotfiles)
214 {
215 this.keepdotfiles = keepdotfiles;
216 }
217
218 public boolean isKeepdotfiles()
219 {
220 return keepdotfiles;
221 }
222
223 public void setCombinefiles(boolean combinefiles)
224 {
225 this.combinefiles = combinefiles;
226 }
227
228 public boolean isCombinefiles()
229 {
230 return combinefiles;
231 }
232
233 public void setUrls(String urls)
234 {
235 this.urls = urls;
236 }
237
238 public String getUrls()
239 {
240 return urls;
241 }
242
243 public void setConfig(String config)
244 {
245 this.config = config;
246 }
247
248 public String getConfig()
249 {
250 return config;
251 }
252
253 public void setWorkingdir(String workingdir)
254 {
255 this.workingdir = workingdir;
256 }
257
258 public String getWorkingdir()
259 {
260 return workingdir;
261 }
262
263 public void setShowconnectors(boolean showconnectors)
264 {
265 this.showconnectors = showconnectors;
266 }
267
268 public boolean isShowconnectors()
269 {
270 return showconnectors;
271 }
272
273 public void setShowmodels(boolean showmodels)
274 {
275 this.showmodels = showmodels;
276 }
277
278 public boolean isShowmodels()
279 {
280 return showmodels;
281 }
282
283 public void setShowconfig(boolean showconfig)
284 {
285 this.showconfig = showconfig;
286 }
287
288 public boolean isShowconfig()
289 {
290 return showconfig;
291 }
292
293 public void setShowagents(boolean showagents)
294 {
295 this.showagents = showagents;
296 }
297
298 public boolean isShowagents()
299 {
300 return showagents;
301 }
302
303 public void setShowtransformers(boolean showtransformers)
304 {
305 this.showtransformers = showtransformers;
306 }
307
308 public boolean isShowtransformers()
309 {
310 return showtransformers;
311 }
312
313 public void setShowall(boolean showall)
314 {
315 this.showall = showall;
316 }
317
318 public boolean isShowall()
319 {
320 return showall;
321 }
322
323 public void setTemplateprops(String templateprops)
324 {
325 this.templateprops = templateprops;
326 }
327
328 public String getTemplateprops()
329 {
330 return templateprops;
331 }
332 }