Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3799

The artifact id of a core extension found from a pom.xml embedded in a JAR is not resolved

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 18.9.0-rc-1
    • 17.10.13
    • Extension
    • None
    • Unit
    • Unknown
    • N/A
    • N/A

    Description

      When a JAR of the classpath has no .xed descriptor, the core extension scanner falls back on the META-INF/maven/<groupId>/<artifactId>/pom.xml embedded in the JAR (MavenExtensionScanner#parseMavenPom). The groupId and the version found there are resolved (MavenUtils#resolveGroupId and MavenUtils#resolveVersion expand Maven properties and fall back on the parent), but the artifact id is used as it is in ModelConverter#convertToExtension:

      String groupId = MavenUtils.resolveGroupId(model);
      String artifactId = model.getArtifactId();
      String type = this.converter.mavenPackagingToExtensionType(model.getPackaging());
      String version = MavenUtils.resolveVersion(model);
      

      As a result, a JAR whose embedded pom.xml is the raw (not interpolated) one and contains a property in its <artifactId> is registered as a core extension with an invalid id. XWiki then tries to resolve that id on each of the configured extension repositories at each startup, and logs an error for each of them.

      For example netty-tcnative-boringssl-static native JARs (the ones with a linux-x86_64, osx-aarch_64, etc. classifier) embed a pom.xml containing <artifactId>${project.artifactId}</artifactId>, which leads to:

      ERROR aultExtensionRepositoryManager - Unexpected error when trying to find extension [io.netty:${project.artifactId}/2.0.81.Final] in repository [maven-xwiki:maven:https://nexus-snapshots.xwiki.org/repository/public-proxy {}]
      org.xwiki.extension.ResolveException: Failed to resolve artifact [io.netty:${project.artifactId}:jar:2.0.81.Final] descriptor
      [...]
      Caused by: org.apache.http.client.HttpResponseException: status code: 400, reason phrase: Invalid repository path (400)
      

      Note that adding an equivalent of MavenUtils#resolveGroupId for the artifact id is not enough: ${project.artifactId} is self referencing, so it cannot be resolved from the model alone. But the right value is available twice next to the descriptor:

      • in the path of the descriptor itself, META-INF/maven/<groupId>/<artifactId>/pom.xml (the scanner builds the URL it parses from that path)
      • in the pom.properties that Maven generates in the same folder, which contains the resolved groupId, artifactId and version

      It would also be safer to refuse to send an extension id which still contains an unresolved property to the remote repositories, instead of producing an error for each of them at each startup.

      Attachments

        Activity

          People

            tmortagne Thomas Mortagne
            tmortagne Thomas Mortagne
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: