| 1 | |
package com.aurea.maven.plugins.sonic.esb; |
| 2 | |
|
| 3 | |
import java.io.File; |
| 4 | |
import java.io.FileInputStream; |
| 5 | |
import java.io.InputStream; |
| 6 | |
import java.util.ArrayList; |
| 7 | |
import java.util.Iterator; |
| 8 | |
import java.util.List; |
| 9 | |
import java.util.Properties; |
| 10 | |
|
| 11 | |
import org.apache.maven.model.Resource; |
| 12 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 13 | |
import org.apache.maven.plugin.MojoFailureException; |
| 14 | |
import org.apache.maven.project.MavenProjectHelper; |
| 15 | |
import org.codehaus.plexus.archiver.Archiver; |
| 16 | |
import org.codehaus.plexus.archiver.manager.ArchiverManager; |
| 17 | |
import org.codehaus.plexus.util.FileUtils; |
| 18 | |
import org.codehaus.plexus.util.xml.XmlStreamReader; |
| 19 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 20 | |
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; |
| 21 | |
|
| 22 | |
import com.aurea.maven.plugins.sonic.utils.FileUtilities; |
| 23 | |
import com.aurea.maven.plugins.sonic.utils.SnippetsProcessor; |
| 24 | |
import com.aurea.maven.plugins.sonic.utils.Xpp3Utils; |
| 25 | |
import com.sonicsw.deploy.action.CreateMapAction; |
| 26 | |
|
| 27 | 0 | public abstract class AbstractEsbPackageMojo extends AbstractESBConnectMojo { |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
private MavenProjectHelper projectHelper; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
private String artifactID; |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
protected File esbTailorPropFile; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
protected File testEsbTailorPropFile; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
protected ArchiverManager archiverManager; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
ArrayList<String> parameterMatches; |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
ArrayList<String> testParameterMatches; |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
String xarExcludes; |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
protected boolean copyXarToDeploy; |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
protected abstract String getGeneratedSrcDir(); |
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
protected abstract String getAssemblyDir(); |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
protected abstract List<Resource> getResources(); |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
protected abstract File getEsbTailorPropFile(); |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
protected void doExecute() throws MojoExecutionException, MojoFailureException { |
| 117 | |
|
| 118 | 0 | super.doExecute(); |
| 119 | |
|
| 120 | 0 | File archiveFile = null; |
| 121 | |
|
| 122 | 0 | getLog().info("Packaging ESB project ..."); |
| 123 | |
try { |
| 124 | 0 | archiveFile = createEsbAssembly(); |
| 125 | |
|
| 126 | 0 | } catch (Exception e) { |
| 127 | 0 | throw new MojoExecutionException("Failed to package ESB archive " |
| 128 | |
+ (archiveFile == null ? "null" : archiveFile.getAbsolutePath()), e); |
| 129 | 0 | } |
| 130 | 0 | String classifier = getClassifier(); |
| 131 | 0 | if (classifier != null) { |
| 132 | 0 | projectHelper.attachArtifact(project, getType(), classifier, archiveFile); |
| 133 | |
} else { |
| 134 | 0 | project.getArtifact().setFile(archiveFile); |
| 135 | |
} |
| 136 | 0 | } |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
protected void addArtifactReplaceRules(final List<Xpp3Dom> _replaceRules) { |
| 143 | |
|
| 144 | 0 | Xpp3Dom projectReplace = new Xpp3Dom("stringReplaceMap"); |
| 145 | 0 | projectReplace.setAttribute("name", "sonicfs:///workspace/" + getProjectName() |
| 146 | |
+ getSonicEsbSourceDirectoryFromBase()); |
| 147 | 0 | projectReplace.setAttribute("updatedName", "sonicfs:///" + getSonicFSProjectDir()); |
| 148 | 0 | _replaceRules.add(projectReplace); |
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | 0 | Xpp3Dom libReplace = new Xpp3Dom("stringReplaceMap"); |
| 179 | 0 | libReplace.setAttribute("name", "sonicfs:///workspace/" + getProjectName() + "/lib/" + getArtifactId()); |
| 180 | 0 | libReplace.setAttribute("updatedName", "sonicfs:///" + getSonicFSResourcesDir() + "/" |
| 181 | |
+ getGroupId().replaceAll("\\.", "/") + "/" + getArtifactId() + "/" + getVersion() + "/" |
| 182 | |
+ getFinalAssemblyBaseName()); |
| 183 | 0 | _replaceRules.add(libReplace); |
| 184 | 0 | } |
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
protected void generateTailoring(final SnippetsProcessor _sp) throws Exception { |
| 193 | |
|
| 194 | 0 | XmlStreamReader reader = null; |
| 195 | 0 | XmlStreamReader esbtailorReader = null; |
| 196 | |
|
| 197 | 0 | String tailorFile = getTailorDir() + "/" + getFinalAssemblyBaseName() + ".xar.xml"; |
| 198 | |
|
| 199 | 0 | ClassLoader cl = getClass().getClassLoader(); |
| 200 | |
|
| 201 | 0 | Xpp3Dom tailorDom = null; |
| 202 | |
|
| 203 | 0 | String tailorRulesFile = "ESB/deploy/" + getESBVersion() + "/DefaultTailorRules.xml"; |
| 204 | 0 | String rulesFile = getAssemblyDir() + "/" + getRulesFileName(); |
| 205 | |
|
| 206 | |
try { |
| 207 | 0 | InputStream is = cl.getResourceAsStream(tailorRulesFile); |
| 208 | |
|
| 209 | 0 | byte[] content = new byte[is.available()]; |
| 210 | 0 | is.read(content); |
| 211 | 0 | FileUtilities.writeFile(content, rulesFile); |
| 212 | |
|
| 213 | |
|
| 214 | 0 | reader = new XmlStreamReader(new File(rulesFile)); |
| 215 | 0 | tailorDom = Xpp3DomBuilder.build(reader); |
| 216 | 0 | } catch (Exception e) { |
| 217 | 0 | getLog().error("Could not access: " + tailorRulesFile, e); |
| 218 | 0 | } |
| 219 | |
|
| 220 | |
|
| 221 | 0 | Xpp3Dom stringReplace = tailorDom.getChild("DevEnvRules").getChild("stringReplaceMaps"); |
| 222 | 0 | Xpp3Utils.removeAllChildren(tailorDom, "DevEnvRules/stringReplaceMaps"); |
| 223 | |
|
| 224 | |
|
| 225 | 0 | List<Xpp3Dom> replaceRules = Xpp3Utils.collectElements(getDependencyDirectory(), "**/*.xar.xml", |
| 226 | |
"StringReplaceMaps/stringReplaceMap"); |
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | 0 | addArtifactReplaceRules(replaceRules); |
| 231 | |
|
| 232 | |
|
| 233 | 0 | getLog().debug("Inserting Tailor Rules ------"); |
| 234 | 0 | getLog().debug("Check File " + getEsbTailorPropFile()); |
| 235 | 0 | getLog().debug("Base-Dir: " + project.getBasedir()); |
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | 0 | File esbTailorFile = getEsbTailorPropFile(); |
| 240 | 0 | if (esbTailorFile.exists()) { |
| 241 | |
try { |
| 242 | 0 | getLog().info("Tailoring the String Replace Maps with custom tailoring"); |
| 243 | 0 | esbtailorReader = new XmlStreamReader(esbTailorFile); |
| 244 | 0 | Xpp3Dom esbtailorDom = Xpp3DomBuilder.build(esbtailorReader); |
| 245 | 0 | for (Xpp3Dom child : esbtailorDom.getChild("CustomStringReplaceMaps").getChildren()) { |
| 246 | 0 | Xpp3Dom stringreplacer = new Xpp3Dom("stringReplaceMap"); |
| 247 | 0 | stringreplacer.setAttribute("name", child.getAttribute("name")); |
| 248 | 0 | stringreplacer.setAttribute("updatedName", child.getAttribute("updatedName")); |
| 249 | 0 | replaceRules.add(stringreplacer); |
| 250 | |
} |
| 251 | 0 | } catch (Exception e) { |
| 252 | 0 | getLog().error("Problem encountered with the formatting of the file: " + e.getMessage(), e); |
| 253 | 0 | } |
| 254 | |
} else { |
| 255 | 0 | getLog().debug("No Tailoring File Found"); |
| 256 | |
} |
| 257 | |
|
| 258 | |
|
| 259 | 0 | replaceRules = Xpp3Utils.unifyXpp3List(replaceRules, "/stringReplaceMap/@name"); |
| 260 | |
|
| 261 | 0 | for (Xpp3Dom replaceRule : replaceRules) { |
| 262 | 0 | stringReplace.addChild(replaceRule); |
| 263 | 0 | } |
| 264 | |
|
| 265 | 0 | Xpp3Dom propertiesReplaceMap = getSonicConnectPropertiesReplaceMap(); |
| 266 | 0 | if (propertiesReplaceMap != null) { |
| 267 | 0 | getLog().debug("Need to insert the Property Replace Maps "); |
| 268 | 0 | tailorDom.addChild(propertiesReplaceMap); |
| 269 | |
} else { |
| 270 | 0 | getLog().debug("No Properties File Found for Sonic Connect Project"); |
| 271 | |
} |
| 272 | |
|
| 273 | |
|
| 274 | 0 | List<Xpp3Dom> serviceRules = Xpp3Utils.collectElements(getDependencyDirectory(), "**/*.rules.snippet"); |
| 275 | 0 | serviceRules = Xpp3Utils.unifyXpp3List(serviceRules, "/ServiceRule/@type"); |
| 276 | |
|
| 277 | 0 | Xpp3Dom insertPoint = tailorDom.getChild("ServiceRules"); |
| 278 | 0 | for (Xpp3Dom serviceRule : serviceRules) { |
| 279 | 0 | if (serviceRule.getChildCount() > 0) { |
| 280 | 0 | insertPoint.addChild(serviceRule); |
| 281 | |
} |
| 282 | 0 | } |
| 283 | |
|
| 284 | 0 | FileUtilities.writeFile(tailorDom.toString().getBytes(), rulesFile); |
| 285 | |
|
| 286 | |
|
| 287 | 0 | CreateMapAction cmAction = new CreateMapAction(new File(tailorFile), new File(rulesFile)); |
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | 0 | cmAction.run(_sp.getXarAnalyser().getStorage()); |
| 292 | |
|
| 293 | |
|
| 294 | 0 | reader = new XmlStreamReader(new File(tailorFile)); |
| 295 | 0 | tailorDom = Xpp3DomBuilder.build(reader); |
| 296 | |
|
| 297 | |
|
| 298 | 0 | Xpp3Utils.removeAllChildren(tailorDom, "EndpointMaps"); |
| 299 | |
|
| 300 | |
|
| 301 | 0 | Xpp3Utils.removeAllChildren(tailorDom, "ProcessMaps/ProcessMap"); |
| 302 | |
|
| 303 | |
|
| 304 | 0 | List<Xpp3Dom> serviceMaps = Xpp3Utils.collectElements(tailorDom, "ServiceMaps/ServiceMap"); |
| 305 | 0 | for (Xpp3Dom serviceMap : serviceMaps) { |
| 306 | 0 | Xpp3Dom paramMap = null; |
| 307 | 0 | if (serviceMap.getChild("paramMap") != null) { |
| 308 | 0 | paramMap = serviceMap.getChild("paramMap"); |
| 309 | |
} |
| 310 | 0 | Xpp3Utils.removeAllChildren(serviceMap); |
| 311 | 0 | if (paramMap != null) { |
| 312 | 0 | serviceMap.addChild(paramMap); |
| 313 | |
} |
| 314 | 0 | } |
| 315 | |
|
| 316 | 0 | FileUtilities.writeFile(tailorDom.toString().getBytes(), tailorFile); |
| 317 | |
|
| 318 | 0 | } |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
protected void generateVariables() throws Exception { |
| 325 | |
|
| 326 | 0 | String tailorFile = getTailorDir() + "/" + getFinalAssemblyBaseName() + ".xar.xml"; |
| 327 | |
|
| 328 | 0 | Xpp3Dom variables = new Xpp3Dom("Variables"); |
| 329 | |
|
| 330 | 0 | XmlStreamReader reader = new XmlStreamReader(new File(tailorFile)); |
| 331 | 0 | Xpp3Dom tailorDom = Xpp3DomBuilder.build(reader); |
| 332 | 0 | generateVariablesFromTailoring(tailorDom, variables, null); |
| 333 | 0 | generateVariablesFromProperties(variables); |
| 334 | |
|
| 335 | 0 | FileUtilities.writeFile(variables.toString().getBytes(), getSnippetDir() + "/" + getFinalAssemblyBaseName() |
| 336 | |
+ ".variables.snippet"); |
| 337 | 0 | FileUtilities.writeFile(tailorDom.toString().getBytes(), tailorFile); |
| 338 | 0 | } |
| 339 | |
|
| 340 | |
protected void generateVariablesFromProperties(final Xpp3Dom _variables) { |
| 341 | |
|
| 342 | 0 | } |
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
protected void generateVariablesFromTailoring(final Xpp3Dom _element, final Xpp3Dom _variables, |
| 353 | |
final String _context) { |
| 354 | |
|
| 355 | 0 | String nextContext = _context; |
| 356 | |
|
| 357 | 0 | if (_element != null) { |
| 358 | 0 | if ("StringParam".equals(_element.getName())) { |
| 359 | 0 | String paramName = "@" + _context + "." + _element.getAttribute("name").trim() + "@"; |
| 360 | 0 | String paramContent = null; |
| 361 | 0 | if (_element.getAttribute("url") != null) { |
| 362 | 0 | paramContent = _element.getAttribute("url"); |
| 363 | 0 | _element.setAttribute("url", paramName); |
| 364 | |
} else { |
| 365 | 0 | paramContent = _element.getValue(); |
| 366 | 0 | _element.setValue(paramName); |
| 367 | |
} |
| 368 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", paramContent, "name=" + paramName)); |
| 369 | |
} |
| 370 | 0 | if ("XmlParam".equals(_element.getName())) { |
| 371 | 0 | if ("connections".equals(_element.getAttribute("name"))) { |
| 372 | 0 | getLog().debug("TBO: ------ Need to treat a connection Object"); |
| 373 | 0 | for (Xpp3Dom child : _element.getChildren()) { |
| 374 | 0 | generateDatabaseVariables(child, _variables, "db.connect." + _context); |
| 375 | |
} |
| 376 | |
} |
| 377 | |
} |
| 378 | 0 | if ("stringReplaceMap".equals(_element.getName())) { |
| 379 | 0 | String updatedNameAttribute = _element.getAttribute("updatedName"); |
| 380 | 0 | if (updatedNameAttribute != null && updatedNameAttribute.startsWith("@") |
| 381 | |
&& updatedNameAttribute.endsWith("@")) { |
| 382 | 0 | getLog().debug("Found stringReplaceMap variable: " + updatedNameAttribute); |
| 383 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", null, "name=" + updatedNameAttribute)); |
| 384 | |
} |
| 385 | |
} |
| 386 | 0 | if ("ServiceMap".equals(_element.getName())) { |
| 387 | 0 | nextContext = "svc." + _element.getAttribute("name"); |
| 388 | 0 | } else if ("ConnectionMap".equals(_element.getName())) { |
| 389 | 0 | nextContext = "con." + _element.getAttribute("name"); |
| 390 | |
} |
| 391 | |
|
| 392 | 0 | if ("propertyReplaceMap".equals(_element.getName())) { |
| 393 | 0 | String prop = _element.getAttribute("propertyName"); |
| 394 | 0 | String val = _element.getAttribute("updatedValue"); |
| 395 | 0 | String parameter = "@" + "connect." + artifactID + "." + prop + "@"; |
| 396 | 0 | _element.setAttribute("updatedValue", parameter); |
| 397 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", val, "name=" + parameter)); |
| 398 | 0 | getLog().debug("Found PropertyReplaceMap Variable " + parameter + " with value " + val); |
| 399 | |
} |
| 400 | |
|
| 401 | 0 | for (Xpp3Dom child : _element.getChildren()) { |
| 402 | 0 | generateVariablesFromTailoring(child, _variables, nextContext); |
| 403 | |
} |
| 404 | |
} |
| 405 | 0 | } |
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
|
| 413 | |
|
| 414 | |
|
| 415 | |
protected void generateDatabaseVariables(final Xpp3Dom _element, final Xpp3Dom _variables, final String _context) { |
| 416 | |
|
| 417 | 0 | getLog().debug("Element: " + _element.getName() + " --- " + _context); |
| 418 | 0 | if ("connection".equals(_element.getName()) || "rdbms:connection".equals(_element.getName())) { |
| 419 | 0 | getLog().debug("Creating the connection stuff"); |
| 420 | 0 | String password = _element.getAttribute("password"); |
| 421 | 0 | String passwordref = "@" + _context + "." + _element.getName() + ".password" + "@"; |
| 422 | 0 | _element.setAttribute("password", passwordref); |
| 423 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", password, "name=" + passwordref)); |
| 424 | |
|
| 425 | 0 | String username = _element.getAttribute("username"); |
| 426 | 0 | String usernameref = "@" + _context + "." + _element.getName() + ".username" + "@"; |
| 427 | 0 | _element.setAttribute("username", usernameref); |
| 428 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", username, "name=" + usernameref)); |
| 429 | |
|
| 430 | 0 | String jdbcURL = _element.getAttribute("jdbcURL"); |
| 431 | 0 | String jdbcURLref = "@" + _context + "." + _element.getName() + ".jdbcURL" + "@"; |
| 432 | 0 | _element.setAttribute("jdbcURL", jdbcURLref); |
| 433 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", jdbcURL, "name=" + jdbcURLref)); |
| 434 | |
|
| 435 | 0 | String name = _element.getAttribute("name"); |
| 436 | 0 | String nameref = "@" + _context + "." + _element.getName() + ".name" + "@"; |
| 437 | 0 | _element.setAttribute("name", nameref); |
| 438 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", name, "name=" + nameref)); |
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
} |
| 443 | 0 | if ("scheduledQueries".equals(_element.getName())) { |
| 444 | 0 | int queryNum = 0; |
| 445 | 0 | getLog().debug("Handling Scheduled Queries --- " + queryNum); |
| 446 | 0 | for (Xpp3Dom child : _element.getChildren()) { |
| 447 | 0 | generateDatabaseQueries(child, _variables, "query." + queryNum + "." + _context); |
| 448 | 0 | queryNum++; |
| 449 | |
} |
| 450 | 0 | } else { |
| 451 | 0 | for (Xpp3Dom child : _element.getChildren()) { |
| 452 | 0 | generateDatabaseVariables(child, _variables, _context); |
| 453 | |
} |
| 454 | |
} |
| 455 | 0 | } |
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
protected void generateDatabaseQueries(final Xpp3Dom _element, final Xpp3Dom _variables, final String _context) { |
| 466 | |
|
| 467 | 0 | for (Xpp3Dom child : _element.getChildren()) { |
| 468 | 0 | if ("address".equals(child.getName())) { |
| 469 | 0 | String ref = child.getAttribute("endpoint_ref"); |
| 470 | 0 | String refname = "@" + _context + "." + child.getName() + ".endpoint_ref@"; |
| 471 | 0 | String type = child.getAttribute("type"); |
| 472 | 0 | String typename = "@" + _context + "." + child.getName() + ".type@"; |
| 473 | 0 | child.setAttribute("endpoint_ref", refname); |
| 474 | 0 | child.setAttribute("type", typename); |
| 475 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", ref, "name=" + refname)); |
| 476 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", type, "name=" + typename)); |
| 477 | 0 | } else { |
| 478 | 0 | String paramName = "@" + _context + "." + child.getName().trim() + "@"; |
| 479 | 0 | String paramContent = child.getValue(); |
| 480 | 0 | getLog().debug("TBO ----- Setting paramName = " + paramName + " Content = " + paramContent); |
| 481 | 0 | child.setValue(paramName); |
| 482 | 0 | _variables.addChild(Xpp3Utils.createXpp3Dom("Variable", paramContent, "name=" + paramName)); |
| 483 | |
} |
| 484 | |
} |
| 485 | |
|
| 486 | 0 | } |
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
|
| 493 | |
|
| 494 | |
protected void copyGeneratedSrcToXarDir() throws MojoExecutionException { |
| 495 | |
|
| 496 | 0 | String xarDir = getPackageXarDir(); |
| 497 | |
|
| 498 | 0 | getLog().info("Copying generated src to xar dir ..."); |
| 499 | 0 | getLog().debug("generatedSrcDir: " + getGeneratedSrcDir()); |
| 500 | 0 | getLog().debug("xarDir: " + xarDir); |
| 501 | |
|
| 502 | 0 | new File(xarDir, "ESB").mkdirs(); |
| 503 | 0 | new File(xarDir, "SonicFS").mkdirs(); |
| 504 | |
|
| 505 | |
try { |
| 506 | |
|
| 507 | |
|
| 508 | 0 | StringBuffer excludes = new StringBuffer(); |
| 509 | 0 | String separator = ""; |
| 510 | 0 | for (Xpp3Dom svc : Xpp3Utils.collectElements(getDependencyDirectory(), "**/*.rules.snippet")) { |
| 511 | 0 | String svcName = svc.getAttribute("type"); |
| 512 | 0 | excludes.append(separator); |
| 513 | 0 | excludes.append("ESB/ServiceTypes/" + svcName + ".*"); |
| 514 | 0 | separator = ","; |
| 515 | 0 | excludes.append(separator); |
| 516 | 0 | excludes.append("SonicFS/System/**/" + svcName + ".properties"); |
| 517 | 0 | excludes.append(separator); |
| 518 | 0 | excludes.append("SonicFS/System/**/" + svcName + ".gif"); |
| 519 | 0 | } |
| 520 | |
|
| 521 | 0 | FileUtilities.copyFiles(getGeneratedSrcDir(), xarDir, null, excludes.toString() + "," |
| 522 | |
+ getXarExcludePatterns(), null, false); |
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | 0 | } catch (Exception e) { |
| 527 | 0 | throw new MojoExecutionException("Error copying xar content: ", e); |
| 528 | 0 | } |
| 529 | 0 | } |
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
protected void createAssemblyStructure() { |
| 535 | |
|
| 536 | 0 | String[] dirs = new String[] { getAssemblyDir(), getSnippetDir(), getTailorDir() }; |
| 537 | |
|
| 538 | 0 | for (String dirName : dirs) { |
| 539 | 0 | File dir = new File(dirName); |
| 540 | 0 | dir.mkdirs(); |
| 541 | |
} |
| 542 | 0 | } |
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
protected void generateQueuesSnippet(final SnippetsProcessor _sp) throws Exception { |
| 551 | |
|
| 552 | 0 | String queuesFile = getFinalAssemblyBaseName() + ".queues.snippet"; |
| 553 | 0 | FileUtilities.writeFile(_sp.getQueuesSnippet().getBytes(), getSnippetDir() + "/" + queuesFile); |
| 554 | 0 | } |
| 555 | |
|
| 556 | |
|
| 557 | |
|
| 558 | |
|
| 559 | |
|
| 560 | |
|
| 561 | |
|
| 562 | |
protected void generateSvcInstancesSnippet(final SnippetsProcessor _sp) throws Exception { |
| 563 | |
|
| 564 | 0 | String instancesFile = getFinalAssemblyBaseName() + ".instances.snippet"; |
| 565 | 0 | FileUtilities.writeFile(_sp.getSvcInstancesSnippet(getGroupId() + "." + getArtifactId()).getBytes(), |
| 566 | |
getSnippetDir() + "/" + instancesFile); |
| 567 | 0 | } |
| 568 | |
|
| 569 | |
|
| 570 | |
|
| 571 | |
|
| 572 | |
|
| 573 | |
protected String getAssemblyXarsDir() { |
| 574 | |
|
| 575 | 0 | return getAssemblyDir() + "/" + XARS_DIR_NAME; |
| 576 | |
} |
| 577 | |
|
| 578 | |
|
| 579 | |
|
| 580 | |
|
| 581 | |
protected String getTailorDir() { |
| 582 | |
|
| 583 | 0 | return getAssemblyXarsDir() + "/" + TAILOR_DIR_NAME; |
| 584 | |
} |
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
protected String getSnippetDir() { |
| 590 | |
|
| 591 | 0 | return getAssemblyXarsDir() + "/" + SDM_SNIPPET_DIR_NAME; |
| 592 | |
} |
| 593 | |
|
| 594 | |
|
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
|
| 599 | |
protected abstract String getType(); |
| 600 | |
|
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
|
| 606 | |
File createEsbAssembly() throws Exception { |
| 607 | |
|
| 608 | |
|
| 609 | |
|
| 610 | 0 | copyGeneratedSrcToXarDir(); |
| 611 | |
|
| 612 | 0 | createAssemblyStructure(); |
| 613 | |
|
| 614 | 0 | getLog().info("Creating ESB assembly ..."); |
| 615 | 0 | File archiveFile = new File(getAssemblyDir()); |
| 616 | |
|
| 617 | 0 | copyJarFiles(); |
| 618 | 0 | File xarArchive = createXarFile(); |
| 619 | |
|
| 620 | |
|
| 621 | 0 | FileUtils.copyFileToDirectory(xarArchive, new File(archiveFile, XARS_DIR_NAME)); |
| 622 | 0 | if (copyXarToDeploy) { |
| 623 | 0 | final File deployDir = new File(project.getBasedir(), "deploy"); |
| 624 | 0 | getLog().info("Copying xar archive to " + deployDir.getPath()); |
| 625 | 0 | FileUtils.copyFileToDirectory(xarArchive, deployDir); |
| 626 | |
} |
| 627 | |
|
| 628 | 0 | SnippetsProcessor sp = new SnippetsProcessor(xarArchive); |
| 629 | |
|
| 630 | 0 | getLog().debug("Creating Queue snippet ..."); |
| 631 | 0 | generateQueuesSnippet(sp); |
| 632 | 0 | getLog().debug("Creating Tailoring rules ..."); |
| 633 | 0 | generateTailorRules(sp); |
| 634 | 0 | getLog().debug("Creating Tailoring file ..."); |
| 635 | 0 | generateTailoring(sp); |
| 636 | 0 | getLog().debug("Creating Instance snippet ..."); |
| 637 | 0 | generateSvcInstancesSnippet(sp); |
| 638 | 0 | getLog().debug("Extracting Variables ..."); |
| 639 | 0 | generateVariables(); |
| 640 | |
|
| 641 | 0 | Archiver archiver = archiverManager.getArchiver("zip"); |
| 642 | |
|
| 643 | 0 | archiveFile = getArchiveFile(project.getBuild().getDirectory(), getFinalAssemblyBaseName(true), "zip"); |
| 644 | 0 | archiver.setDestFile(archiveFile); |
| 645 | 0 | archiver.addDirectory(new File(getAssemblyDir())); |
| 646 | 0 | archiver.createArchive(); |
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | 0 | FileUtils.forceDelete(new File("target" + File.separatorChar + "unzip")); |
| 655 | |
|
| 656 | 0 | return archiveFile; |
| 657 | |
} |
| 658 | |
|
| 659 | |
|
| 660 | |
|
| 661 | |
|
| 662 | |
|
| 663 | |
|
| 664 | |
protected File createXarFile() throws Exception { |
| 665 | |
|
| 666 | |
|
| 667 | 0 | List<Resource> resources = getResources(); |
| 668 | 0 | for (Resource resource : resources) { |
| 669 | 0 | FileUtilities.copyFiles( |
| 670 | |
resource.getDirectory(), |
| 671 | |
getPackageXarDir() + "/SonicFS", |
| 672 | |
"**/*", |
| 673 | |
getXarExcludePatterns(), |
| 674 | |
"/workspace/" + getProjectName() |
| 675 | |
+ resource.getDirectory().replace(project.getBasedir().getAbsolutePath(), ""), false); |
| 676 | |
|
| 677 | 0 | } |
| 678 | |
|
| 679 | |
|
| 680 | |
|
| 681 | 0 | FileUtilities.copyFiles(getSonicEsbSourceDirectory().getAbsolutePath(), getPackageXarDir() + "/SonicFS", |
| 682 | |
"**/*", "**/*.esbp,**/*.sid,**/*.esbsvc," + getXarExcludePatterns(), "/workspace/" + getProjectName() |
| 683 | |
+ getSonicEsbSourceDirectoryFromBase(), false); |
| 684 | |
|
| 685 | |
|
| 686 | 0 | File archiveFile = getArchiveFile(getPackageXarFileDir(), getFinalAssemblyBaseName(), "xar"); |
| 687 | 0 | Archiver archiver = archiverManager.getArchiver("zip"); |
| 688 | 0 | archiver.setDestFile(archiveFile); |
| 689 | 0 | archiver.addDirectory(new File(getPackageXarDir())); |
| 690 | 0 | archiver.createArchive(); |
| 691 | 0 | return archiveFile; |
| 692 | |
} |
| 693 | |
|
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | |
|
| 698 | |
|
| 699 | |
protected String getXarExcludePatterns() { |
| 700 | |
|
| 701 | 0 | return xarExcludes; |
| 702 | |
} |
| 703 | |
|
| 704 | |
private File getArchiveFile(final String _basedir, final String _finalBaseName, final String _extension) { |
| 705 | |
|
| 706 | 0 | return new File(_basedir, _finalBaseName + "." + _extension); |
| 707 | |
} |
| 708 | |
|
| 709 | |
|
| 710 | |
|
| 711 | |
|
| 712 | |
|
| 713 | |
|
| 714 | |
|
| 715 | |
private void generateTailorRules(final SnippetsProcessor _sp) throws Exception { |
| 716 | |
|
| 717 | 0 | String rulesFile = getFinalAssemblyBaseName() + ".rules.snippet"; |
| 718 | 0 | ArrayList<String> pm = getParameterMatches(); |
| 719 | 0 | if (pm == null) { |
| 720 | 0 | pm = new ArrayList<String>(); |
| 721 | |
} |
| 722 | |
|
| 723 | 0 | getLog().debug("Checking the Tailor Rule File for parameter rule definitions"); |
| 724 | 0 | XmlStreamReader esbtailorReader = null; |
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | 0 | File esbTailorFile = getEsbTailorPropFile(); |
| 729 | 0 | if (esbTailorFile.exists()) { |
| 730 | |
try { |
| 731 | 0 | getLog().info("Tailoring the Init Parameter Visibility"); |
| 732 | 0 | esbtailorReader = new XmlStreamReader(esbTailorFile); |
| 733 | 0 | Xpp3Dom esbtailorDom = Xpp3DomBuilder.build(esbtailorReader); |
| 734 | 0 | if (esbtailorDom.getChild("parameterMatches") == null) { |
| 735 | 0 | getLog().info("No External Parameter Matches found"); |
| 736 | |
} else { |
| 737 | 0 | for (Xpp3Dom child : esbtailorDom.getChild("parameterMatches").getChildren()) { |
| 738 | 0 | pm.add(child.getValue()); |
| 739 | 0 | getLog().debug("added: " + child.getValue()); |
| 740 | |
} |
| 741 | |
} |
| 742 | 0 | } catch (Exception e) { |
| 743 | 0 | getLog().error("Problem encountered with the formatting of the file: " + e.getMessage(), e); |
| 744 | 0 | } |
| 745 | |
} else { |
| 746 | 0 | getLog().debug("No Tailoring File Found"); |
| 747 | |
} |
| 748 | 0 | if (pm.size() == 0) { |
| 749 | 0 | pm.add(".*"); |
| 750 | |
} |
| 751 | 0 | FileUtilities.writeFile(_sp.getTailorSnippet(pm).getBytes(), getSnippetDir() + "/" + rulesFile); |
| 752 | 0 | } |
| 753 | |
|
| 754 | |
|
| 755 | |
|
| 756 | |
|
| 757 | |
protected abstract ArrayList<String> getParameterMatches(); |
| 758 | |
|
| 759 | |
private Xpp3Dom getSonicConnectPropertiesReplaceMap() { |
| 760 | 0 | File connectProperties = new File(new File(project.getBasedir(), "lib"), project.getArtifactId() |
| 761 | |
+ ".properties"); |
| 762 | 0 | if (connectProperties.exists()) { |
| 763 | 0 | Properties props = new Properties(); |
| 764 | |
FileInputStream fis; |
| 765 | |
try { |
| 766 | 0 | fis = new FileInputStream(connectProperties); |
| 767 | 0 | props.load(fis); |
| 768 | 0 | fis.close(); |
| 769 | 0 | } catch (Exception e) { |
| 770 | 0 | getLog().error("No Valid Properties file found!", e); |
| 771 | 0 | return null; |
| 772 | 0 | } |
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
|
| 777 | |
|
| 778 | |
|
| 779 | |
|
| 780 | |
|
| 781 | 0 | Xpp3Dom propertyRules = new Xpp3Dom("PropertyRules"); |
| 782 | 0 | Xpp3Dom propertyReplaceMaps = new Xpp3Dom("PropertyReplaceMaps"); |
| 783 | |
|
| 784 | 0 | propertyReplaceMaps.setAttribute("artifactName", artifactID + ".properties"); |
| 785 | |
|
| 786 | 0 | Xpp3Dom replaceMap = null; |
| 787 | |
|
| 788 | 0 | Iterator<Object> it = props.keySet().iterator(); |
| 789 | 0 | while (it.hasNext()) { |
| 790 | 0 | String key = (String) it.next(); |
| 791 | 0 | getLog().debug("Found Property " + key + ":" + props.getProperty(key)); |
| 792 | 0 | if (props.getProperty(key).startsWith("$")) { |
| 793 | 0 | getLog().debug("Ignoring key " + key + " : " + props.getProperty(key)); |
| 794 | 0 | continue; |
| 795 | |
} |
| 796 | 0 | replaceMap = new Xpp3Dom("propertyReplaceMap"); |
| 797 | |
|
| 798 | |
|
| 799 | 0 | replaceMap.setAttribute("propertyName", (String) key); |
| 800 | 0 | replaceMap.setAttribute("updatedValue", props.getProperty(key)); |
| 801 | |
|
| 802 | 0 | propertyReplaceMaps.addChild(replaceMap); |
| 803 | 0 | } |
| 804 | |
|
| 805 | 0 | propertyRules.addChild(propertyReplaceMaps); |
| 806 | |
|
| 807 | 0 | return propertyRules; |
| 808 | |
} else { |
| 809 | 0 | return null; |
| 810 | |
} |
| 811 | |
} |
| 812 | |
|
| 813 | |
} |