Coverage Report - com.aurea.maven.plugins.sonic.SonicUnpackDependenciesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
SonicUnpackDependenciesMojo
0%
0/88
0%
0/12
2.25
 
 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  
  * exports from the Sonic Domain the ESB artifacts from the current Maven
 23  
  * artifact into /deploy/generated-src.
 24  
  * 
 25  
  * @author Jamie Townsend
 26  
  * 
 27  
  * @goal unpack-dependencies
 28  
  */
 29  0
 public class SonicUnpackDependenciesMojo extends AbstractSonicMojo {
 30  
 
 31  
         private static final int DOMAIN_PING_TIMEOUT = 1000;
 32  
 
 33  
         /**
 34  
          * The Sonic Domain to connect to.
 35  
          * 
 36  
          * @parameter property="sonicesb.devDomainName" default-value="Domain1"
 37  
          * @required
 38  
          */
 39  
         private String domain;
 40  
 
 41  
         /**
 42  
          * The user name used for the connection.
 43  
          * 
 44  
          * @parameter property="sonicesb.devDomainUser"
 45  
          *            default-value="Administrator"
 46  
          * @required
 47  
          */
 48  
         private String user;
 49  
 
 50  
         /**
 51  
          * The password used for the connection.
 52  
          * 
 53  
          * @parameter property="sonicesb.devDomainPassword"
 54  
          *            default-value="Administrator"
 55  
          * @required
 56  
          */
 57  
         private String password;
 58  
 
 59  
         /**
 60  
          * The management connection url.
 61  
          * 
 62  
          * @parameter property="sonicesb.devDomainUrl"
 63  
          *            default-value="tcp://localhost:2506"
 64  
          * @required
 65  
          */
 66  
         private String mgmtUrl;
 67  
 
 68  
         /**
 69  
          * The Maven Session Object.
 70  
          * 
 71  
          * @parameter default-value="${session}"
 72  
          * @required
 73  
          * @readonly
 74  
          */
 75  
         private MavenSession session;
 76  
 
 77  
         /**
 78  
          * The Maven PluginManager Object.
 79  
          * 
 80  
          * @component
 81  
          * @required
 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  
          * @return MFUtils
 94  
          * @throws MojoExecutionException
 95  
          *             if something goes wrong
 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  
                         // TBO: The unpackDxsiXars is now running all the time. It will take
 116  
                         // artifacts from the dxsi-distribution
 117  
                         // and load it into the SonicDS for operational work.
 118  0
                         unpackDxsiXars();
 119  0
                         unpackTopologyConfig();
 120  
                         // Tests will need to point out if the unpack sonic provided options
 121  
                         // is really needed.
 122  
                         // Removed it in order to allow for SDP Package (SDM)
 123  
                         // interdependencies in provided mode.
 124  
 
 125  
                         // Inserting unpack Sonic Provided but only to allow Service Types
 126  
                         // being provided and getting the rules from the snippets
 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  
                                 // KNOW ISSUE: throws an exception when using Eclipse Workspace
 134  
                                 // referenced projects
 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  
                         // This should never happen and if it does, it shouldn't really
 158  
                         // matter
 159  0
                         e.printStackTrace();
 160  0
                 }
 161  
 
 162  0
         }
 163  
 
 164  
         private void unpackSonicCompile() throws MojoExecutionException {
 165  
                 // projects
 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  
                         // This should never happen and if it does, it shouldn't really
 182  
                         // matter
 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  
                 // TBO
 205  
                 // Extracting the xar file to a temp location.
 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  
                 // Removing the ESB Directory ... avoiding the import of the service
 213  
                 // instance and endpoint.
 214  
                 try {
 215  0
                         FileUtils.deleteDirectory(new File(xarTmpDir, "ESB"));
 216  0
                 } catch (IOException e1) {
 217  
                         // TODO Auto-generated catch block
 218  0
                         e1.printStackTrace();
 219  0
                 }
 220  
 
 221  
                 // Uploading the xar content but ignore the Endpoint and Service
 222  
                 // Instance
 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  
                         // resources root e.g. JARs
 231  0
                         expProperties.addRoot(new SonicFSArtifact("/"));
 232  
                         // TBO: Ignoring the ESB-Endpoint and ServiceInstance. These need to
 233  
                         // be uploaded manually
 234  
                         // TBO: By default they are not included ... no ignore needed.
 235  
                         // Creating Ignores List
 236  
                         // expProperties.addIgnore(new
 237  
                         // ESBArtifact(ESBArtifact.CONNECTION_TYPE, "**"));
 238  
                         // expProperties.addIgnore(new
 239  
                         // ESBArtifact(ESBArtifact.ENDPOINT_TYPE, "**"));
 240  
                         // expProperties.addIgnore(new ESBArtifact(ESBArtifact.SERVICE_TYPE,
 241  
                         // "**"));
 242  
                         // ignores.add(new ESBArtifact(ESBArtifact.SERVICE_TYPE,
 243  
                         // "DataXtendSIServiceType"));
 244  
                         // just to make sure that no workspace related files get imported,
 245  
                         // although that should never happen
 246  0
                         expProperties.addIgnore(new SonicFSArtifact("workspace/"));
 247  
                         // expProperties.addIgnore(ignores.toArray(new ESBArtifact[] {} ));
 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  
                 // TBO: REMARK: 2013 - Do we need to delete these directories at this
 262  
                 // point? It might be that these are still needed at the time we extract
 263  
                 // the generated resource
 264  
                 // This is not an issue for the process build in the workbench but is an
 265  
                 // issue for the head-less build cycle due to the difference in
 266  
                 // dependencies.
 267  
                 // try {
 268  
                 // FileUtils.deleteDirectory(markersDirectory);
 269  
                 // FileUtils.deleteDirectory(dependencyTmpDir);
 270  
                 // FileUtils.deleteDirectory(xarTmpDir);
 271  
                 // } catch (IOException e) {
 272  
                 // // This should never happen and if it does, it shouldn't really
 273  
                 // matter
 274  
                 // e.printStackTrace();
 275  
                 // }
 276  0
         }
 277  
 
 278  
         /**
 279  
          * @return String
 280  
          * @throws MojoExecutionException
 281  
          *             if something goes wrong
 282  
          */
 283  
         protected String getDomainName() throws MojoExecutionException {
 284  
 
 285  0
                 return domain;
 286  
         }
 287  
 
 288  
         /**
 289  
          * @return String
 290  
          * @throws MojoExecutionException
 291  
          *             if something goes wrong
 292  
          */
 293  
         protected String getAdminUser() throws MojoExecutionException {
 294  
 
 295  0
                 return user;
 296  
         }
 297  
 
 298  
         /**
 299  
          * @return String
 300  
          * @throws MojoExecutionException
 301  
          *             if something goes wrong
 302  
          */
 303  
         protected String getAdminPassword() throws MojoExecutionException {
 304  
 
 305  0
                 return password;
 306  
         }
 307  
 
 308  
         /**
 309  
          * @return String
 310  
          * @throws MojoExecutionException
 311  
          *             if something goes wrong
 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"), // "zip,esb,esbstyp,dxsi,connect"
 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  
                         // This should never happen and if it does, it shouldn't really
 337  
                         // matter
 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  
                         // This should never happen and if it does, it shouldn't really
 391  
                         // matter
 392  0
                         e.printStackTrace();
 393  0
                 }
 394  0
         }
 395  
 
 396  
 }