1 package com.aurea.maven.plugins.sonic;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.apache.maven.execution.MavenSession;
7 import org.apache.maven.plugin.BuildPluginManager;
8 import org.apache.maven.plugin.MojoExecutionException;
9 import org.apache.maven.plugin.MojoFailureException;
10 import org.codehaus.plexus.util.FileUtils;
11 import org.twdata.maven.mojoexecutor.MojoExecutor;
12
13 import com.aurea.maven.plugins.sonic.utils.ZipUtilities;
14 import com.progress.sonic.utilities.esb.admin.ESBArtifactCopyJob;
15 import com.progress.sonic.utilities.mfutils.MFUtils;
16 import com.progress.sonic.utilities.mfutils.NullArtifactNotificationListener;
17 import com.sonicsw.deploy.artifact.SonicFSArtifact;
18 import com.sonicsw.deploy.storage.FileArtifactStorage;
19 import com.sonicsw.deploy.tools.common.ExportPropertiesArtifact;
20
21
22
23
24
25
26
27
28
29 public class SonicUnpackDependenciesMojo extends AbstractSonicMojo {
30
31 private static final int DOMAIN_PING_TIMEOUT = 1000;
32
33
34
35
36
37
38
39 private String domain;
40
41
42
43
44
45
46
47
48 private String user;
49
50
51
52
53
54
55
56
57 private String password;
58
59
60
61
62
63
64
65
66 private String mgmtUrl;
67
68
69
70
71
72
73
74
75 private MavenSession session;
76
77
78
79
80
81
82
83 protected BuildPluginManager pluginManager;
84
85 private File markersDirectory = null;
86
87
88
89
90 protected MFUtils mfUtils = null;
91
92
93
94
95
96
97 protected MFUtils getMFUtils() throws MojoExecutionException {
98
99 if (mfUtils == null) {
100 getLog().info("Connecting to Sonic Domain ...");
101 getLog().debug("Domain: " + getDomainName());
102 getLog().debug("ManagementURL: " + getManagementUrl());
103 getLog().debug("User: " + getAdminUser());
104 getLog().debug("Password: " + getAdminPassword());
105 mfUtils = new MFUtils(getDomainName(), getManagementUrl(), getAdminUser(), getAdminPassword());
106 }
107 return mfUtils;
108 }
109
110 @Override
111 protected void doExecute() throws MojoExecutionException, MojoFailureException {
112 try {
113 markersDirectory = new File(getDependencyDirectory(), "markers");
114 unpackSonicCompile();
115
116
117
118 unpackDxsiXars();
119 unpackTopologyConfig();
120
121
122
123
124
125
126
127 unpackSonicProvided();
128 copyDependentJars();
129 copySonicExtensions();
130 } catch (Exception ex) {
131 if (ex.getCause() != null && ex.getCause().getMessage() != null
132 && ex.getCause().getMessage().contains("MDEP-98")) {
133
134
135 ex.printStackTrace();
136 } else {
137 throw ex;
138 }
139
140 }
141 }
142
143 private void unpackTopologyConfig() throws MojoExecutionException {
144 MojoExecutor.executeMojo(MojoExecutor.plugin(MojoExecutor.groupId("org.apache.maven.plugins"),
145 MojoExecutor.artifactId("maven-dependency-plugin"), MojoExecutor.version("2.7")), MojoExecutor
146 .goal("unpack-dependencies"), MojoExecutor.configuration(new MojoExecutor.Element[] {
147 MojoExecutor.element(MojoExecutor.name("outputDirectory"), getDependencyDirectory() + "/topology"),
148 MojoExecutor.element(MojoExecutor.name("excludeScope"), "provided"),
149 MojoExecutor.element(MojoExecutor.name("markersDirectory"), markersDirectory.getAbsolutePath()),
150 MojoExecutor.element(MojoExecutor.name("includeTypes"), "topology"),
151 MojoExecutor.element(MojoExecutor.name("useRepositoryLayout"), "false"),
152 MojoExecutor.element(MojoExecutor.name("useSubDirectoryPerType"), "false") }), MojoExecutor
153 .executionEnvironment(project, session, pluginManager));
154 try {
155 FileUtils.deleteDirectory(markersDirectory);
156 } catch (IOException e) {
157
158
159 e.printStackTrace();
160 }
161
162 }
163
164 private void unpackSonicCompile() throws MojoExecutionException {
165
166
167 MojoExecutor.executeMojo(MojoExecutor.plugin(MojoExecutor.groupId("org.apache.maven.plugins"),
168 MojoExecutor.artifactId("maven-dependency-plugin"), MojoExecutor.version("2.7")), MojoExecutor
169 .goal("unpack-dependencies"), MojoExecutor.configuration(new MojoExecutor.Element[] {
170 MojoExecutor.element(MojoExecutor.name("outputDirectory"), getDependencyDirectory() + "/xar/compile"),
171 MojoExecutor.element(MojoExecutor.name("excludeScope"), "provided"),
172 MojoExecutor.element(MojoExecutor.name("markersDirectory"), markersDirectory.getAbsolutePath()),
173 MojoExecutor.element(MojoExecutor.name("includeTypes"), "zip,esb,esbstyp,connect"),
174 MojoExecutor.element(MojoExecutor.name("useRepositoryLayout"), "true"),
175 MojoExecutor.element(MojoExecutor.name("useSubDirectoryPerType"), "true") }), MojoExecutor
176 .executionEnvironment(project, session, pluginManager));
177
178 try {
179 FileUtils.deleteDirectory(markersDirectory);
180 } catch (IOException e) {
181
182
183 e.printStackTrace();
184 }
185 }
186
187 private void unpackDxsiXars() throws MojoExecutionException {
188 File dxsiExtractDir = new File(getDependencyDirectory(), "dxsi");
189 File dependencyTmpDir = new File(dxsiExtractDir, "dependencyTmp");
190 File xarTmpDir = new File(dxsiExtractDir, "xarTmp");
191
192 MojoExecutor.executeMojo(MojoExecutor.plugin(MojoExecutor.groupId("org.apache.maven.plugins"),
193 MojoExecutor.artifactId("maven-dependency-plugin"), MojoExecutor.version("2.7")), MojoExecutor
194 .goal("unpack-dependencies"), MojoExecutor.configuration(new MojoExecutor.Element[] {
195 MojoExecutor.element(MojoExecutor.name("outputDirectory"), dependencyTmpDir.getPath()),
196 MojoExecutor.element(MojoExecutor.name("excludeScope"), "provided"),
197 MojoExecutor.element(MojoExecutor.name("includeScope"), "compile"),
198 MojoExecutor.element(MojoExecutor.name("markersDirectory"), markersDirectory.getAbsolutePath()),
199 MojoExecutor.element(MojoExecutor.name("includeTypes"), "dxsi"),
200 MojoExecutor.element(MojoExecutor.name("useRepositoryLayout"), "true"),
201 MojoExecutor.element(MojoExecutor.name("useSubDirectoryPerType"), "true") }), MojoExecutor
202 .executionEnvironment(project, session, pluginManager));
203
204
205
206 String[] xarExtension = { "xar" };
207 String[] xarFiles = FileUtils.getFilesFromExtension(dependencyTmpDir.getPath(), xarExtension);
208 for (String xarFilename : xarFiles) {
209 ZipUtilities.doUnzipAction(xarFilename, xarTmpDir.getPath());
210 }
211
212
213
214 try {
215 FileUtils.deleteDirectory(new File(xarTmpDir, "ESB"));
216 } catch (IOException e1) {
217
218 e1.printStackTrace();
219 }
220
221
222
223 try {
224
225 FileArtifactStorage fas = new FileArtifactStorage();
226 fas.addNotificationListener(new NullArtifactNotificationListener());
227 fas.setRoot(xarTmpDir.getAbsolutePath());
228
229 ExportPropertiesArtifact expProperties = new ExportPropertiesArtifact();
230
231 expProperties.addRoot(new SonicFSArtifact("/"));
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246 expProperties.addIgnore(new SonicFSArtifact("workspace/"));
247
248
249 if (!MFUtils.pingDomain(getManagementUrl(), DOMAIN_PING_TIMEOUT)) {
250 getLog().warn("Could not connect to Sonic Domain at " + getManagementUrl());
251 } else {
252 new ESBArtifactCopyJob(fas, getMFUtils().getDSArtifactStorage(), expProperties, false).copy();
253 getLog().info("DXSI Environment Imported!");
254 }
255 } catch (Exception e) {
256 getLog().error("Failed to import ESB Service Type into local DS", e);
257 } finally {
258 getMFUtils().cleanup();
259 }
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 }
277
278
279
280
281
282
283 protected String getDomainName() throws MojoExecutionException {
284
285 return domain;
286 }
287
288
289
290
291
292
293 protected String getAdminUser() throws MojoExecutionException {
294
295 return user;
296 }
297
298
299
300
301
302
303 protected String getAdminPassword() throws MojoExecutionException {
304
305 return password;
306 }
307
308
309
310
311
312
313 protected String getManagementUrl() throws MojoExecutionException {
314
315 return mgmtUrl;
316 }
317
318 @SuppressWarnings("unused")
319 private void unpackSonicProvided() throws MojoExecutionException {
320
321 MojoExecutor.executeMojo(MojoExecutor.plugin(MojoExecutor.groupId("org.apache.maven.plugins"),
322 MojoExecutor.artifactId("maven-dependency-plugin"), MojoExecutor.version("2.7")), MojoExecutor
323 .goal("unpack-dependencies"), MojoExecutor.configuration(new MojoExecutor.Element[] {
324 MojoExecutor.element(MojoExecutor.name("outputDirectory"), getDependencyDirectory() + "/xar/provided"),
325 MojoExecutor.element(MojoExecutor.name("excludeScope"), "compile"),
326 MojoExecutor.element(MojoExecutor.name("includeScope"), "provided"),
327 MojoExecutor.element(MojoExecutor.name("markersDirectory"), markersDirectory.getAbsolutePath()),
328 MojoExecutor.element(MojoExecutor.name("includeTypes"), "esbstyp,esb"),
329 MojoExecutor.element(MojoExecutor.name("useRepositoryLayout"), "true"),
330 MojoExecutor.element(MojoExecutor.name("useSubDirectoryPerType"), "true") }), MojoExecutor
331 .executionEnvironment(project, session, pluginManager));
332
333 try {
334 FileUtils.deleteDirectory(markersDirectory);
335 } catch (IOException e) {
336
337
338 e.printStackTrace();
339 }
340 }
341
342 private void copyDependentJars() throws MojoExecutionException {
343
344 getLog().debug("TBO-DEBUG- COPY JAR FILES");
345 getLog().debug("TBO-DEBUG- Output Directory: " + getDependencyDirectory() + "/jar");
346
347 MojoExecutor.executeMojo(MojoExecutor.plugin(MojoExecutor.groupId("org.apache.maven.plugins"),
348 MojoExecutor.artifactId("maven-dependency-plugin"), MojoExecutor.version("2.7")), MojoExecutor
349 .goal("copy-dependencies"), MojoExecutor.configuration(new MojoExecutor.Element[] {
350 MojoExecutor.element(MojoExecutor.name("outputDirectory"), getDependencyDirectory() + "/jar"),
351 MojoExecutor.element(MojoExecutor.name("excludeScope"), "test"),
352 MojoExecutor.element(MojoExecutor.name("includeScope"), "runtime"),
353 MojoExecutor.element(MojoExecutor.name("markersDirectory"), markersDirectory.getAbsolutePath()),
354 MojoExecutor.element(MojoExecutor.name("excludeGroupIds"),
355 "com.aurea.sonic.mq,com.aurea.sonic.esb,junit,org.mockito"),
356 MojoExecutor.element(MojoExecutor.name("excludeArtifactIds"), "esb_mockups"),
357 MojoExecutor.element(MojoExecutor.name("includeTypes"), "jar"),
358 MojoExecutor.element(MojoExecutor.name("useRepositoryLayout"), "true"),
359 MojoExecutor.element(MojoExecutor.name("useSubDirectoryPerType"), "false") }), MojoExecutor
360 .executionEnvironment(project, session, pluginManager));
361
362 getLog().debug("TBO-DEBUG- COPY JAR FILES - END");
363
364 try {
365 FileUtils.deleteDirectory(markersDirectory);
366 } catch (IOException e) {
367
368 e.printStackTrace();
369 }
370 }
371
372 private void copySonicExtensions() throws MojoExecutionException {
373
374 MojoExecutor.executeMojo(MojoExecutor.plugin(MojoExecutor.groupId("org.apache.maven.plugins"),
375 MojoExecutor.artifactId("maven-dependency-plugin"), MojoExecutor.version("2.7")), MojoExecutor
376 .goal("copy-dependencies"), MojoExecutor.configuration(new MojoExecutor.Element[] {
377 MojoExecutor.element(MojoExecutor.name("outputDirectory"), getDependencyDirectory() + "/jar"),
378 MojoExecutor.element(MojoExecutor.name("includeScope"), "runtime"),
379 MojoExecutor.element(MojoExecutor.name("markersDirectory"), markersDirectory.getAbsolutePath()),
380 MojoExecutor.element(MojoExecutor.name("includeGroupIds"),
381 "com.progress.sonic.mqx,com.progress.sonic.esbx,com.aurea.sonic.mqx,com.aurea.sonic.esbx"),
382 MojoExecutor.element(MojoExecutor.name("includeTypes"), "jar"),
383 MojoExecutor.element(MojoExecutor.name("useRepositoryLayout"), "true"),
384 MojoExecutor.element(MojoExecutor.name("useSubDirectoryPerType"), "false") }), MojoExecutor
385 .executionEnvironment(project, session, pluginManager));
386
387 try {
388 FileUtils.deleteDirectory(markersDirectory);
389 } catch (IOException e) {
390
391
392 e.printStackTrace();
393 }
394 }
395
396 }