| 1 | |
package com.aurea.maven.plugins.sonic.esb; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.FileOutputStream; |
| 5 | |
import java.io.IOException; |
| 6 | |
import java.io.InputStream; |
| 7 | |
import java.io.OutputStream; |
| 8 | |
import java.net.URISyntaxException; |
| 9 | |
import java.net.URL; |
| 10 | |
import java.net.URLDecoder; |
| 11 | |
import java.util.Enumeration; |
| 12 | |
import java.util.HashSet; |
| 13 | |
import java.util.Set; |
| 14 | |
import java.util.jar.JarEntry; |
| 15 | |
import java.util.jar.JarFile; |
| 16 | |
|
| 17 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 18 | |
import org.apache.maven.plugin.MojoFailureException; |
| 19 | |
|
| 20 | |
import com.aurea.maven.plugins.sonic.utils.DependencyAnalyzer; |
| 21 | |
import com.aurea.maven.plugins.sonic.utils.FileUtilities; |
| 22 | |
import com.progress.sonic.utilities.esb.admin.XarAnalyzer; |
| 23 | |
import com.progress.sonic.utilities.mfutils.MFUtils; |
| 24 | |
import com.sonicsw.deploy.IArtifact; |
| 25 | |
import com.sonicsw.deploy.artifact.ArtifactFactory; |
| 26 | |
import com.sonicsw.deploy.artifact.SonicFSArtifact; |
| 27 | |
import com.sonicsw.deploy.tools.common.ExportPropertiesArtifact; |
| 28 | |
|
| 29 | 0 | public abstract class AbstractESBConnectMojo extends AbstractESBMojo { |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | protected final File deployGenSrcDir = null; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | protected final File testableDeployGenSrcDir = null; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
protected String connectServiceLocation; |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
protected String wadlFiles; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
protected String wadlPackage; |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
protected String wadlBaseUrl; |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
protected File targetGenTestSrcDir; |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
private String dxsiVersion; |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
private String domain; |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
private String user; |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
private String password; |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
private String mgmtUrl; |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | 0 | protected MFUtils mfUtils = null; |
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
protected MFUtils getMFUtils() throws MojoExecutionException { |
| 132 | |
|
| 133 | 0 | if (mfUtils == null) { |
| 134 | 0 | getLog().info("Connecting to Sonic Domain ..."); |
| 135 | 0 | getLog().debug("Domain: " + getDomainName()); |
| 136 | 0 | getLog().debug("ManagementURL: " + getManagementUrl()); |
| 137 | 0 | getLog().debug("User: " + getAdminUser()); |
| 138 | 0 | getLog().debug("Password: " + getAdminPassword()); |
| 139 | 0 | mfUtils = new MFUtils(getDomainName(), getManagementUrl(), getAdminUser(), getAdminPassword()); |
| 140 | |
} |
| 141 | 0 | return mfUtils; |
| 142 | |
} |
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
protected String getDomainName() throws MojoExecutionException { |
| 150 | |
|
| 151 | 0 | return domain; |
| 152 | |
} |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
protected String getAdminUser() throws MojoExecutionException { |
| 160 | |
|
| 161 | 0 | return user; |
| 162 | |
} |
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
protected String getAdminPassword() throws MojoExecutionException { |
| 170 | |
|
| 171 | 0 | return password; |
| 172 | |
} |
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
protected String getManagementUrl() throws MojoExecutionException { |
| 180 | |
|
| 181 | 0 | return mgmtUrl; |
| 182 | |
} |
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
protected void doExecute() throws MojoExecutionException, MojoFailureException { |
| 188 | 0 | exportXQHome(); |
| 189 | 0 | } |
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
private void exportXQHome() { |
| 196 | |
try { |
| 197 | 0 | String xqVersion = com.sonicsw.xqimpl.Version.getMajorMinorVersion(); |
| 198 | 0 | if ("10.0".equals(xqVersion)) { |
| 199 | 0 | xqVersion = "2015"; |
| 200 | |
} |
| 201 | |
|
| 202 | 0 | String tmpDir = System.getProperty("java.io.tmpdir"); |
| 203 | 0 | File pluginTmp = new File(tmpDir, "sonicesb-maven-plugin"); |
| 204 | 0 | File xsdTmp = new File(pluginTmp, "ESB" + xqVersion); |
| 205 | |
|
| 206 | 0 | if (!xsdTmp.exists()) { |
| 207 | 0 | getLog().debug("Exporting XSD files to " + xsdTmp.getAbsolutePath()); |
| 208 | 0 | String path = "ESB/schema/" + xqVersion + "/"; |
| 209 | 0 | String[] schemas = getResourceListing(path); |
| 210 | 0 | File outputDir = new File(xsdTmp, "schema"); |
| 211 | 0 | outputDir.mkdirs(); |
| 212 | |
|
| 213 | 0 | for (String file : schemas) { |
| 214 | 0 | exportResource(path, file, outputDir); |
| 215 | |
} |
| 216 | |
} |
| 217 | |
|
| 218 | |
|
| 219 | 0 | System.setProperty("com.sonicsw.xq.home", xsdTmp.getAbsolutePath()); |
| 220 | 0 | } catch (Exception e) { |
| 221 | 0 | throw new RuntimeException(e); |
| 222 | 0 | } |
| 223 | 0 | } |
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
protected String getRulesFileName() { |
| 229 | |
|
| 230 | 0 | return getFinalAssemblyBaseName() + "-Tailoring.xml"; |
| 231 | |
} |
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
protected void addExportIgnoresForDependencies(final ExportPropertiesArtifact _expProps) { |
| 241 | |
|
| 242 | 0 | String[] dxsiIgnoreList = { "System/DataXtend/" + dxsiVersion + "/lib/commons-beanutils.jar", |
| 243 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-codec.jar", |
| 244 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-collections.jar", |
| 245 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-httpclient.jar", |
| 246 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-io-2.0.1.jar", |
| 247 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-jxpath.jar", |
| 248 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-lang.jar", |
| 249 | |
"System/DataXtend/" + dxsiVersion + "/lib/commons-vfs.jar", |
| 250 | |
"System/DataXtend/" + dxsiVersion + "/lib/jta.jar", |
| 251 | |
"System/DataXtend/" + dxsiVersion + "/lib/saaj-api.jar", |
| 252 | |
"System/DataXtend/" + dxsiVersion + "/lib/saaj-impl.jar", |
| 253 | |
"System/DataXtend/" + dxsiVersion + "/lib/antlr.jar", |
| 254 | |
"System/DataXtend/" + dxsiVersion + "/lib/velocity.jar", |
| 255 | |
"System/DataXtend/" + dxsiVersion + "/lib/jsr173_1.0_api.jar", |
| 256 | |
"System/DataXtend/" + dxsiVersion + "/lib/javassist.jar", |
| 257 | |
"System/DataXtend/" + dxsiVersion + "/lib/hibernate3.jar", |
| 258 | |
"System/DataXtend/" + dxsiVersion + "/lib/empty.jar", |
| 259 | |
"System/DataXtend/" + dxsiVersion + "/lib/ehcache.jar", |
| 260 | |
"System/DataXtend/" + dxsiVersion + "/lib/dom4j.jar", |
| 261 | |
"System/DataXtend/" + dxsiVersion + "/lib/c3p0.jar" }; |
| 262 | |
|
| 263 | 0 | String[] connectIgnoreList = { "System/SonicESB/%VERSION%/lib/esb_connect.jar", |
| 264 | |
"System/SonicESB/%VERSION%/lib/spring-context-support.jar", |
| 265 | |
"System/SonicESB/%VERSION%/lib/spring-jms.jar", "System/SonicESB/%VERSION%/lib/spring-tx.jar", |
| 266 | |
"System/SonicESB/%VERSION%/lib/spring-web.jar", "System/SonicESB/%VERSION%/lib/asm.jar", |
| 267 | |
"System/SonicESB/%VERSION%/lib/camel-cxfjetty.jar", "System/SonicESB/%VERSION%/lib/camel-sonicesb.jar", |
| 268 | |
"System/SonicESB/%VERSION%/lib/connect-datacontenthandlers.jar", |
| 269 | |
"System/SonicESB/%VERSION%/lib/connect-security.jar", "System/SonicESB/%VERSION%/lib/jaxb-impl.jar", |
| 270 | |
"System/SonicESB/%VERSION%/lib/jaxb-xjc.jar", "System/SonicESB/%VERSION%/lib/saaj-impl.jar", |
| 271 | |
"System/SonicESB/%VERSION%/lib/commons-codec.jar", |
| 272 | |
"System/SonicESB/%VERSION%/lib/commons-collections.jar", |
| 273 | |
"System/SonicESB/%VERSION%/lib/commons-httpclient.jar", |
| 274 | |
"System/SonicESB/%VERSION%/lib/commons-lang.jar", |
| 275 | |
"System/SonicESB/%VERSION%/lib/commons-logging-api.jar", |
| 276 | |
"System/SonicESB/%VERSION%/lib/jsr311-api.jar", "System/SonicESB/%VERSION%/lib/jaxb-api.jar", |
| 277 | |
"System/SonicESB/%VERSION%/lib/saaj-api.jar", "System/SonicESB/%VERSION%/lib/jaxen.jar", |
| 278 | |
"System/SonicESB/%VERSION%/lib/abdera-core.jar", |
| 279 | |
"System/SonicESB/%VERSION%/lib/abdera-extensions-json.jar", |
| 280 | |
"System/SonicESB/%VERSION%/lib/abdera-extensions-main.jar", |
| 281 | |
"System/SonicESB/%VERSION%/lib/abdera-i18n.jar", "System/SonicESB/%VERSION%/lib/abdera-parser.jar", |
| 282 | |
"System/SonicESB/%VERSION%/lib/camel-core.jar", "System/SonicESB/%VERSION%/lib/camel-cxf.jar", |
| 283 | |
"System/SonicESB/%VERSION%/lib/camel-http.jar", "System/SonicESB/%VERSION%/lib/camel-jetty.jar", |
| 284 | |
"System/SonicESB/%VERSION%/lib/camel-jms.jar", "System/SonicESB/%VERSION%/lib/camel-spring.jar", |
| 285 | |
"System/SonicESB/%VERSION%/lib/cxf-api.jar", "System/SonicESB/%VERSION%/lib/cxf-common-schemas.jar", |
| 286 | |
"System/SonicESB/%VERSION%/lib/cxf-common-utilities.jar", |
| 287 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-bindings-soap.jar", |
| 288 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-bindings-xml.jar", |
| 289 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-core.jar", |
| 290 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-databinding-aegis.jar", |
| 291 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-databinding-jaxb.jar", |
| 292 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-frontend-jaxrs.jar", |
| 293 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-frontend-jaxws.jar", |
| 294 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-frontend-simple.jar", |
| 295 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-javascript.jar", |
| 296 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-transports-http.jar", |
| 297 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-transports-http-jetty.jar", |
| 298 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-transports-local.jar", |
| 299 | |
"System/SonicESB/%VERSION%/lib/cxf-rt-ws-addr.jar", |
| 300 | |
"System/SonicESB/%VERSION%/lib/cxf-tools-common.jar", |
| 301 | |
"System/SonicESB/%VERSION%/lib/cxf-tools-java2ws.jar", |
| 302 | |
"System/SonicESB/%VERSION%/lib/cxf-tools-validator.jar", |
| 303 | |
"System/SonicESB/%VERSION%/lib/cxf-tools-wsdlto-core.jar", |
| 304 | |
"System/SonicESB/%VERSION%/lib/cxf-tools-wsdlto-databinding-jaxb.jar", |
| 305 | |
"System/SonicESB/%VERSION%/lib/cxf-tools-wsdlto-frontend-jaxws.jar", |
| 306 | |
"System/SonicESB/%VERSION%/lib/geronimo-activation_1.1_spec.jar", |
| 307 | |
"System/SonicESB/%VERSION%/lib/geronimo-annotation_1.0_spec.jar", |
| 308 | |
"System/SonicESB/%VERSION%/lib/geronimo-javamail_1.4_spec.jar", |
| 309 | |
"System/SonicESB/%VERSION%/lib/geronimo-jaxws_2.1_spec.jar", |
| 310 | |
"System/SonicESB/%VERSION%/lib/geronimo-jms_1.1_spec.jar", |
| 311 | |
"System/SonicESB/%VERSION%/lib/geronimo-servlet_2.4_spec.jar", |
| 312 | |
"System/SonicESB/%VERSION%/lib/geronimo-servlet_2.5_spec.jar", |
| 313 | |
"System/SonicESB/%VERSION%/lib/geronimo-stax-api_1.0_spec.jar", |
| 314 | |
"System/SonicESB/%VERSION%/lib/geronimo-ws-metadata_2.0_spec.jar", |
| 315 | |
"System/SonicESB/%VERSION%/lib/neethi.jar", "System/SonicESB/%VERSION%/lib/velocity.jar", |
| 316 | |
"System/SonicESB/%VERSION%/lib/axiom-api.jar", "System/SonicESB/%VERSION%/lib/axiom-impl.jar", |
| 317 | |
"System/SonicESB/%VERSION%/lib/XmlSchema.jar", "System/SonicESB/%VERSION%/lib/xmlbeans.jar", |
| 318 | |
"System/SonicESB/%VERSION%/lib/jettison.jar", "System/SonicESB/%VERSION%/lib/wstx-asl.jar", |
| 319 | |
"System/SonicESB/%VERSION%/lib/commons-management.jar", "System/SonicESB/%VERSION%/lib/jetty.jar", |
| 320 | |
"System/SonicESB/%VERSION%/lib/jetty-client.jar", "System/SonicESB/%VERSION%/lib/jetty-sslengine.jar", |
| 321 | |
"System/SonicESB/%VERSION%/lib/jetty-util.jar", "System/SonicESB/%VERSION%/lib/jetty-util5.jar", |
| 322 | |
"System/SonicESB/%VERSION%/lib/slf4j-api.jar", "System/SonicESB/%VERSION%/lib/slf4j-jdk14.jar", |
| 323 | |
"System/SonicESB/%VERSION%/lib/spring-security-core.jar", |
| 324 | |
"System/SonicESB/%VERSION%/lib/spring-security-core-tiger.jar", |
| 325 | |
"System/SonicESB/%VERSION%/lib/oro.jar", "System/SonicESB/%VERSION%/lib/wsdl4j.jar", |
| 326 | |
"System/SonicESB/%VERSION%/lib/xml-resolver.jar" }; |
| 327 | |
|
| 328 | 0 | getLog().info("Building Artifact ignore List from Dependencies : ..."); |
| 329 | |
|
| 330 | 0 | for (String xarFile : FileUtilities.getFileList(getDependencyDirectory(), "xar/**/*.xar", null)) { |
| 331 | 0 | getLog().info("Analyzing xar file: " + xarFile); |
| 332 | 0 | XarAnalyzer analyzer = new XarAnalyzer(new File(getDependencyDirectory(), xarFile)); |
| 333 | 0 | for (IArtifact a : analyzer.getAllArtifacts()) { |
| 334 | 0 | getLog().debug("Adding artifact to ignore list: " + a.getPath()); |
| 335 | 0 | _expProps.addIgnore(a); |
| 336 | 0 | } |
| 337 | |
} |
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | |
|
| 343 | 0 | getLog().info("Setting the Ignore-List for Sonic Connect"); |
| 344 | 0 | for (String library : connectIgnoreList) { |
| 345 | 0 | getLog().debug("TBO : Sonic Connect Fix - Adding " + library + " to the export ignore list"); |
| 346 | 0 | IArtifact sonicfs = ArtifactFactory.createArtifact(SonicFSArtifact.TYPE, library); |
| 347 | 0 | _expProps.addIgnore(sonicfs); |
| 348 | |
} |
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | 0 | getLog().info("Setting the Ignore-List for Sonic DXSI Libraries"); |
| 355 | 0 | for (String library : dxsiIgnoreList) { |
| 356 | 0 | getLog().debug("TBO : DXSI Fix - Adding " + library + " to the export ignore list"); |
| 357 | 0 | IArtifact sonicfs = ArtifactFactory.createArtifact(SonicFSArtifact.TYPE, library); |
| 358 | 0 | _expProps.addIgnore(sonicfs); |
| 359 | |
} |
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | 0 | DependencyAnalyzer da = new DependencyAnalyzer(getDependencyDirectory()); |
| 367 | 0 | for (String jarFile : da.getDependencyJars()) { |
| 368 | 0 | String jarURL = getSonicFSResourcesDir() + "/" + jarFile.replaceAll("\\\\", "/"); |
| 369 | 0 | IArtifact a = ArtifactFactory.createArtifact(SonicFSArtifact.TYPE, jarURL); |
| 370 | 0 | _expProps.addIgnore(a); |
| 371 | |
} |
| 372 | |
|
| 373 | 0 | } |
| 374 | |
|
| 375 | |
private void exportResource(final String path, final String file, final File outputDir) throws IOException { |
| 376 | 0 | getLog().debug("Exporting " + file + " to " + outputDir.getAbsolutePath()); |
| 377 | |
|
| 378 | 0 | ClassLoader classloader = Thread.currentThread().getContextClassLoader(); |
| 379 | 0 | File destFile = new File(outputDir, file); |
| 380 | 0 | String resource = path + file; |
| 381 | 0 | try (InputStream input = classloader.getResourceAsStream(resource); |
| 382 | 0 | OutputStream out = new FileOutputStream(destFile)) { |
| 383 | |
int read; |
| 384 | 0 | byte[] bytes = new byte[1024]; |
| 385 | 0 | while ((read = input.read(bytes)) != -1) { |
| 386 | 0 | out.write(bytes, 0, read); |
| 387 | |
} |
| 388 | 0 | } |
| 389 | 0 | } |
| 390 | |
|
| 391 | |
private String[] getResourceListing(final String path) throws IOException, URISyntaxException, |
| 392 | |
MojoExecutionException { |
| 393 | 0 | ClassLoader classloader = Thread.currentThread().getContextClassLoader(); |
| 394 | 0 | URL dirURL = classloader.getResource(path); |
| 395 | |
|
| 396 | 0 | if (dirURL == null) { |
| 397 | 0 | throw new MojoExecutionException("Cannot list files from resource " + path); |
| 398 | 0 | } else if (dirURL.getProtocol().equals("file")) { |
| 399 | |
|
| 400 | 0 | return new File(dirURL.toURI()).list(); |
| 401 | 0 | } else if (dirURL.getProtocol().equals("jar")) { |
| 402 | |
|
| 403 | 0 | String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); |
| 404 | 0 | try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"))) { |
| 405 | 0 | Enumeration<JarEntry> entries = jar.entries(); |
| 406 | 0 | Set<String> result = new HashSet<String>(); |
| 407 | 0 | while (entries.hasMoreElements()) { |
| 408 | 0 | String name = entries.nextElement().getName(); |
| 409 | 0 | if (name.startsWith(path) && !name.equals(path)) { |
| 410 | 0 | result.add(name.substring(path.length())); |
| 411 | |
} |
| 412 | 0 | } |
| 413 | 0 | return result.toArray(new String[result.size()]); |
| 414 | 0 | } |
| 415 | |
} |
| 416 | |
|
| 417 | 0 | throw new MojoExecutionException("Cannot list files for URL " + dirURL); |
| 418 | |
} |
| 419 | |
} |