Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-2009

ArtifactDeployer assumes artifactId has no dots in it

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2018.4.1
    • Fix Version/s: 2018.5.0
    • Component/s: core
    • Labels:
      None

      Description

      Defect for SWARM-1359.

      Attempting to deploy the WebSphere MQ JMS resource adapter (which has Maven coordinates com.ibm.mq:wmq.jmsra:9.0.5.0:rar) using the following swarm yaml config:

      swarm:
        deployments:
          com.ibm.mq:wmq.jmsra.rar:
      

      results in the following exception:

      WFSWARM0009: Unable to determine version number from GAV: com.ibm.mq:wmq:jmsra:*
      

      As you can see, jmsra is being interpreted as the artifact type, and the actual type (rar) has been dropped.

      The relevant code in ArtifactDeployer.java shows that a split is done on the second part of the colon-separated deployment spec, and the assumption is made that it contains a single dot. That assumption is incorrect.

          public void deploy() throws Exception {
              List<SimpleKey> subkeys = configView.simpleSubkeys(ConfigKey.of("swarm", "deployment"));
      
              for (SimpleKey subkey : subkeys) {
                  String spec = subkey.name();
                  if (spec.contains(":")) {
                      String[] parts = spec.split(":");
                      String groupId = parts[0];
                      parts = parts[1].split("\\.");
                      String artifactId = parts[0];
                      String packaging = parts[1];
      
                      JavaArchive artifact = Swarm.artifact(groupId + ":" + artifactId + ":" + packaging + ":*", artifactId + "." + packaging);
                      deployer.get().deploy(artifact, spec);
                  }
              }
      
          }
      

      I would propose to change it to the following:

          public void deploy() throws Exception {
              List<SimpleKey> subkeys = configView.simpleSubkeys(ConfigKey.of("swarm", "deployment"));
      
              for (SimpleKey subkey : subkeys) {
                  String spec = subkey.name();
                  if (spec.contains(":")) {
                      String[] parts = spec.split(":");
                      String groupId = parts[0];
                      int p = parts[1].lastIndexOf('.')
                      String artifactId;
                      String packaging;
                      if (p == -1) {
                        artifactId = parts[1];
                        packaging = "jar";
                      } else {
                        artifactId = parts[1].substring(0, p);
                        packaging = parts[1].substring(p + 1);
                      }
                      JavaArchive artifact = Swarm.artifact(groupId + ":" + artifactId + ":" + packaging + ":*", artifactId + "." + packaging);
                      deployer.get().deploy(artifact, spec);
                  }
              }
          }
      

      I'm working on a unit test to reproduce the issue and I'll submit a patch with the test and the fix shortly.

      Also, can we not just use the official Maven GAV annotation, e.g.: com.foo:bar:war:classifier?
      This would remove any ambiguity created in the current notation (the artifactId.type makes the artifact type look like a file extension, even though the two aren't necessarily the same) and allow the user to specify a classifier, something that's currently missing.
      To keep backwards compatibility, the artifact specification can be interpreted as the old notation if it contains a single colon and as the new notation otherwise.
      I can submit a patch with unit tests and code for this if it is seen as a valuable addition.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                fransflippo F F
                Reporter:
                fransflippo F F
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: