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 | 0 | 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 | 0 | private File markersDirectory = null; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | 0 | protected MFUtils mfUtils = null; |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
protected MFUtils getMFUtils() throws MojoExecutionException { |
98 | |
|
99 | 0 | if (mfUtils == null) { |
100 | 0 | getLog().info("Connecting to Sonic Domain ..."); |
101 | 0 | getLog().debug("Domain: " + getDomainName()); |
102 | 0 | getLog().debug("ManagementURL: " + getManagementUrl()); |
103 | 0 | getLog().debug("User: " + getAdminUser()); |
104 | 0 | getLog().debug("Password: " + getAdminPassword()); |
105 | 0 | mfUtils = new MFUtils(getDomainName(), getManagementUrl(), getAdminUser(), getAdminPassword()); |
106 | |
} |
107 | 0 | return mfUtils; |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
protected void doExecute() throws MojoExecutionException, MojoFailureException { |
112 | |
try { |
113 | 0 | markersDirectory = new File(getDependencyDirectory(), "markers"); |
114 | 0 | unpackSonicCompile(); |
115 | |
|
116 | |
|
117 | |
|
118 | 0 | unpackDxsiXars(); |
119 | 0 | unpackTopologyConfig(); |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | 0 | unpackSonicProvided(); |
128 | 0 | copyDependentJars(); |
129 | 0 | copySonicExtensions(); |
130 | 0 | } catch (Exception ex) { |
131 | 0 | if (ex.getCause() != null && ex.getCause().getMessage() != null |
132 | |
&& ex.getCause().getMessage().contains("MDEP-98")) { |
133 | |
|
134 | |
|
135 | 0 | ex.printStackTrace(); |
136 | |
} else { |
137 | 0 | throw ex; |
138 | |
} |
139 | |
|
140 | 0 | } |
141 | 0 | } |
142 | |
|
143 | |
private void unpackTopologyConfig() throws MojoExecutionException { |
144 | 0 | 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 | 0 | FileUtils.deleteDirectory(markersDirectory); |
156 | 0 | } catch (IOException e) { |
157 | |
|
158 | |
|
159 | 0 | e.printStackTrace(); |
160 | 0 | } |
161 | |
|
162 | 0 | } |
163 | |
|
164 | |
private void unpackSonicCompile() throws MojoExecutionException { |
165 | |
|
166 | |
|
167 | 0 | 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 | 0 | FileUtils.deleteDirectory(markersDirectory); |
180 | 0 | } catch (IOException e) { |
181 | |
|
182 | |
|
183 | 0 | e.printStackTrace(); |
184 | 0 | } |
185 | 0 | } |
186 | |
|
187 | |
private void unpackDxsiXars() throws MojoExecutionException { |
188 | 0 | File dxsiExtractDir = new File(getDependencyDirectory(), "dxsi"); |
189 | 0 | File dependencyTmpDir = new File(dxsiExtractDir, "dependencyTmp"); |
190 | 0 | File xarTmpDir = new File(dxsiExtractDir, "xarTmp"); |
191 | |
|
192 | 0 | 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 | 0 | String[] xarExtension = { "xar" }; |
207 | 0 | String[] xarFiles = FileUtils.getFilesFromExtension(dependencyTmpDir.getPath(), xarExtension); |
208 | 0 | for (String xarFilename : xarFiles) { |
209 | 0 | ZipUtilities.doUnzipAction(xarFilename, xarTmpDir.getPath()); |
210 | |
} |
211 | |
|
212 | |
|
213 | |
|
214 | |
try { |
215 | 0 | FileUtils.deleteDirectory(new File(xarTmpDir, "ESB")); |
216 | 0 | } catch (IOException e1) { |
217 | |
|
218 | 0 | e1.printStackTrace(); |
219 | 0 | } |
220 | |
|
221 | |
|
222 | |
|
223 | |
try { |
224 | |
|
225 | 0 | FileArtifactStorage fas = new FileArtifactStorage(); |
226 | 0 | fas.addNotificationListener(new NullArtifactNotificationListener()); |
227 | 0 | fas.setRoot(xarTmpDir.getAbsolutePath()); |
228 | |
|
229 | 0 | ExportPropertiesArtifact expProperties = new ExportPropertiesArtifact(); |
230 | |
|
231 | 0 | expProperties.addRoot(new SonicFSArtifact("/")); |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | 0 | expProperties.addIgnore(new SonicFSArtifact("workspace/")); |
247 | |
|
248 | |
|
249 | 0 | if (!MFUtils.pingDomain(getManagementUrl(), DOMAIN_PING_TIMEOUT)) { |
250 | 0 | getLog().warn("Could not connect to Sonic Domain at " + getManagementUrl()); |
251 | |
} else { |
252 | 0 | new ESBArtifactCopyJob(fas, getMFUtils().getDSArtifactStorage(), expProperties, false).copy(); |
253 | 0 | getLog().info("DXSI Environment Imported!"); |
254 | |
} |
255 | 0 | } catch (Exception e) { |
256 | 0 | getLog().error("Failed to import ESB Service Type into local DS", e); |
257 | |
} finally { |
258 | 0 | getMFUtils().cleanup(); |
259 | 0 | } |
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | 0 | } |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
protected String getDomainName() throws MojoExecutionException { |
284 | |
|
285 | 0 | return domain; |
286 | |
} |
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
protected String getAdminUser() throws MojoExecutionException { |
294 | |
|
295 | 0 | return user; |
296 | |
} |
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
|
303 | |
protected String getAdminPassword() throws MojoExecutionException { |
304 | |
|
305 | 0 | return password; |
306 | |
} |
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
protected String getManagementUrl() throws MojoExecutionException { |
314 | |
|
315 | 0 | return mgmtUrl; |
316 | |
} |
317 | |
|
318 | |
@SuppressWarnings("unused") |
319 | |
private void unpackSonicProvided() throws MojoExecutionException { |
320 | |
|
321 | 0 | 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 | 0 | FileUtils.deleteDirectory(markersDirectory); |
335 | 0 | } catch (IOException e) { |
336 | |
|
337 | |
|
338 | 0 | e.printStackTrace(); |
339 | 0 | } |
340 | 0 | } |
341 | |
|
342 | |
private void copyDependentJars() throws MojoExecutionException { |
343 | |
|
344 | 0 | getLog().debug("TBO-DEBUG- COPY JAR FILES"); |
345 | 0 | getLog().debug("TBO-DEBUG- Output Directory: " + getDependencyDirectory() + "/jar"); |
346 | |
|
347 | 0 | 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 | 0 | getLog().debug("TBO-DEBUG- COPY JAR FILES - END"); |
363 | |
|
364 | |
try { |
365 | 0 | FileUtils.deleteDirectory(markersDirectory); |
366 | 0 | } catch (IOException e) { |
367 | |
|
368 | 0 | e.printStackTrace(); |
369 | 0 | } |
370 | 0 | } |
371 | |
|
372 | |
private void copySonicExtensions() throws MojoExecutionException { |
373 | |
|
374 | 0 | 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 | 0 | FileUtils.deleteDirectory(markersDirectory); |
389 | 0 | } catch (IOException e) { |
390 | |
|
391 | |
|
392 | 0 | e.printStackTrace(); |
393 | 0 | } |
394 | 0 | } |
395 | |
|
396 | |
} |