Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-69848

Resolving of snapshot revisions doesn't work anymore due to missing JAXB in Java 11

      Resolving of snapshot revisions doesn't work anymore in the maven-metadata-plugin due to missing JAXB in Java 11.

      A JAXB fix was done in JENKINS-68510 with PR https://github.com/jenkinsci/maven-metadata-plugin/pull/22 and released in version 2.2. However, this doesn't fix the problem with resolving snapshot revisions.

      ssturm provided a possible fix for this in the comments of JENKINS-68510. That fix solves the issue. Can this fix be implemented?

      private String resolveSnapshotRevision(String version) {
        InputStream input = null;
        try {
          LOGGER.finest("Resolving SNAPSHOT version if any...");
          URL url = new URL(getArtifactUrlForPath(version+"/maven-metadata.xml"));
      
          LOGGER.finest("Requesting metadata from URL: "+url.toExternalForm());
      
          URLConnection conn = prepareConnection(url);
      
          input = conn.getInputStream();
      
          Thread currentThread = Thread.currentThread();
          ClassLoader originalContext = currentThread.getContextClassLoader();
          try {
            currentThread.setContextClassLoader(MavenMetadataParameterDefinition.class.getClassLoader());
            JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input);
      
            if (metadata.versioning.snapshot != null && !StringUtils.isEmpty(metadata.versioning.snapshot.timestamp)) {
              return version.replaceAll("SNAPSHOT", "") +  metadata.versioning.snapshot.timestamp + "-" + metadata.versioning.snapshot.buildNumber;
            }
          } finally {
            currentThread.setContextClassLoader(originalContext);
          }
      
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e);
        } finally {
          try {
            if (input != null)
              input.close();
          } catch (IOException e) {
            // ignore
          }
        }
        // we did not find anything, return the original value
        LOGGER.finest("No match found, using default");
        return version;
      }  

          [JENKINS-69848] Resolving of snapshot revisions doesn't work anymore due to missing JAXB in Java 11

          Paul Oldenburg created issue -
          Paul Oldenburg made changes -
          Description Original: Resolving of snapshot revisions doesn't work anymore due to missing JAXB in Java 11.

          A JAXB fix was done in JENKINS-68510 with PR [https://github.com/jenkinsci/maven-metadata-plugin/pull/22] and released in version 2.2. However, this doesn't fix the problem with resolving snapshot revisions.

          [~ssturm] provided a fix for this in the comments of JENKINS-68510. That fix solves the issue. Can this fix be implemented?
          New: Resolving of snapshot revisions doesn't work anymore due to missing JAXB in Java 11.

          A JAXB fix was done in JENKINS-68510 with PR [https://github.com/jenkinsci/maven-metadata-plugin/pull/22] and released in version 2.2. However, this doesn't fix the problem with resolving snapshot revisions.

          [~ssturm] provided a possible fix for this in the comments of JENKINS-68510. That fix solves the issue. Can this fix be implemented?
          {code:java}
          private String resolveSnapshotRevision(String version) {
            InputStream input = null;
            try {
              LOGGER.finest("Resolving SNAPSHOT version if any...");
              URL url = new URL(getArtifactUrlForPath(version+"/maven-metadata.xml"));

              LOGGER.finest("Requesting metadata from URL: "+url.toExternalForm());

              URLConnection conn = prepareConnection(url);

              input = conn.getInputStream();

              Thread currentThread = Thread.currentThread();
              ClassLoader originalContext = currentThread.getContextClassLoader();
              try {
                currentThread.setContextClassLoader(MavenMetadataParameterDefinition.class.getClassLoader());
                JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class);
                Unmarshaller unmarshaller = context.createUnmarshaller();
                MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input);

                if (metadata.versioning.snapshot != null && !StringUtils.isEmpty(metadata.versioning.snapshot.timestamp)) {
                  return version.replaceAll("SNAPSHOT", "") + metadata.versioning.snapshot.timestamp + "-" + metadata.versioning.snapshot.buildNumber;
                }
              } finally {
                currentThread.setContextClassLoader(originalContext);
              }

            } catch (Exception e) {
              LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e);
            } finally {
              try {
                if (input != null)
                  input.close();
              } catch (IOException e) {
                // ignore
              }
            }
            // we did not find anything, return the original value
            LOGGER.finest("No match found, using default");
            return version;
          } {code}

          Thanks for the issue. I had solved the bug for myself, but had not yet created an official PR.
          I will create the PR soon. If you want me to provide the hpi-file, please send me a short message.

          Sebastian Sturm added a comment - Thanks for the issue. I had solved the bug for myself, but had not yet created an official PR. I will create the PR soon. If you want me to provide the hpi-file, please send me a short message.

          Pull request was created. That's probably all I can do.

          https://github.com/jenkinsci/maven-metadata-plugin/pull/48

          Sebastian Sturm added a comment - Pull request was created. That's probably all I can do. https://github.com/jenkinsci/maven-metadata-plugin/pull/48

          Thanks ssturm for creating the PR. We've already built a new hpi with your fix included, but hopefully the PR gets merged soon, so we can switch back to the official release

          Paul Oldenburg added a comment - Thanks ssturm for creating the PR. We've already built a new hpi with your fix included, but hopefully the PR gets merged soon, so we can switch back to the official release
          Paul Oldenburg made changes -
          Description Original: Resolving of snapshot revisions doesn't work anymore due to missing JAXB in Java 11.

          A JAXB fix was done in JENKINS-68510 with PR [https://github.com/jenkinsci/maven-metadata-plugin/pull/22] and released in version 2.2. However, this doesn't fix the problem with resolving snapshot revisions.

          [~ssturm] provided a possible fix for this in the comments of JENKINS-68510. That fix solves the issue. Can this fix be implemented?
          {code:java}
          private String resolveSnapshotRevision(String version) {
            InputStream input = null;
            try {
              LOGGER.finest("Resolving SNAPSHOT version if any...");
              URL url = new URL(getArtifactUrlForPath(version+"/maven-metadata.xml"));

              LOGGER.finest("Requesting metadata from URL: "+url.toExternalForm());

              URLConnection conn = prepareConnection(url);

              input = conn.getInputStream();

              Thread currentThread = Thread.currentThread();
              ClassLoader originalContext = currentThread.getContextClassLoader();
              try {
                currentThread.setContextClassLoader(MavenMetadataParameterDefinition.class.getClassLoader());
                JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class);
                Unmarshaller unmarshaller = context.createUnmarshaller();
                MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input);

                if (metadata.versioning.snapshot != null && !StringUtils.isEmpty(metadata.versioning.snapshot.timestamp)) {
                  return version.replaceAll("SNAPSHOT", "") + metadata.versioning.snapshot.timestamp + "-" + metadata.versioning.snapshot.buildNumber;
                }
              } finally {
                currentThread.setContextClassLoader(originalContext);
              }

            } catch (Exception e) {
              LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e);
            } finally {
              try {
                if (input != null)
                  input.close();
              } catch (IOException e) {
                // ignore
              }
            }
            // we did not find anything, return the original value
            LOGGER.finest("No match found, using default");
            return version;
          } {code}
          New: Resolving of snapshot revisions doesn't work anymore in the maven-metadata-plugin due to missing JAXB in Java 11.

          A JAXB fix was done in JENKINS-68510 with PR [https://github.com/jenkinsci/maven-metadata-plugin/pull/22] and released in version 2.2. However, this doesn't fix the problem with resolving snapshot revisions.

          [~ssturm] provided a possible fix for this in the comments of JENKINS-68510. That fix solves the issue. Can this fix be implemented?
          {code:java}
          private String resolveSnapshotRevision(String version) {
            InputStream input = null;
            try {
              LOGGER.finest("Resolving SNAPSHOT version if any...");
              URL url = new URL(getArtifactUrlForPath(version+"/maven-metadata.xml"));

              LOGGER.finest("Requesting metadata from URL: "+url.toExternalForm());

              URLConnection conn = prepareConnection(url);

              input = conn.getInputStream();

              Thread currentThread = Thread.currentThread();
              ClassLoader originalContext = currentThread.getContextClassLoader();
              try {
                currentThread.setContextClassLoader(MavenMetadataParameterDefinition.class.getClassLoader());
                JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class);
                Unmarshaller unmarshaller = context.createUnmarshaller();
                MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input);

                if (metadata.versioning.snapshot != null && !StringUtils.isEmpty(metadata.versioning.snapshot.timestamp)) {
                  return version.replaceAll("SNAPSHOT", "") + metadata.versioning.snapshot.timestamp + "-" + metadata.versioning.snapshot.buildNumber;
                }
              } finally {
                currentThread.setContextClassLoader(originalContext);
              }

            } catch (Exception e) {
              LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e);
            } finally {
              try {
                if (input != null)
                  input.close();
              } catch (IOException e) {
                // ignore
              }
            }
            // we did not find anything, return the original value
            LOGGER.finest("No match found, using default");
            return version;
          } {code}

            marcrohlfs Marc Rohlfs
            poldenburg Paul Oldenburg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: