Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-3347

'LATEST' placeholder is not resolved correctly for descriptors and repositories

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.2
    • 4.1.2, 4.2.0.M1
    • karaf
    • None

    Description

      I slightly modified Karaf's standard feature to give you an idea about the configuration leading to faults (see inline comments).

      <build>
          <plugins>
              <plugin>
                  <groupId>org.apache.karaf.tooling</groupId>
                  <artifactId>karaf-maven-plugin</artifactId>
                  <version>3.0.2</version>
                  <extensions>true</extensions>
                  <executions>
                      <execution>
                          <id>features-add-to-repo</id>
                          <phase>generate-resources</phase>
                          <goals>
                              <goal>features-add-to-repository</goal>
                          </goals>
                          <configuration>
                              <descriptors>
                                  <-- LATEST won't work for descriptors.-->
                                  <descriptor>mvn:org.apache.karaf.features/standard-mod/LATEST/xml/features</descriptor>
                              </descriptors>
                              <features>
                                  <feature>http</feature>
                              </features>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      </build>
      
      <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="standard-3.0.2">
          <!-- LATEST won't work for repositories as artifacts are resolved by Maven but not copied into Target folder (searching for LATEST placeholder instead of the version). -->
          <repository>mvn:org.ops4j.pax.web/pax-web-features/LATEST/xml/features</repository>
          <feature name="http" version="3.0.2" description="Implementation of the OSGI HTTP Service" resolver="(obr)">
              <feature version="[3.1.2,5)">pax-http</feature>
              <!-- LATEST will work for bundles (guess this is the same than defining no version) -->
              <bundle start-level="30">mvn:org.apache.karaf.http/org.apache.karaf.http.core/LATEST</bundle> 
              <bundle start-level="30">mvn:org.apache.karaf.http/org.apache.karaf.http.command/LATEST</bundle>
          </feature>
      </features>
      

      I debugged into the Plugin and saw that the version information are already available via the previously resolved descriptor but not taken when building the repoURI.

      In a first attempt i adjusted the uri using the descriptor which made 'LATEST' work.

      AbstractFeatureMojo.java
      protected void retrieveDescriptorsRecursively(String uri, Set<String> bundles, Map<String, Feature> featuresMap) {
          Artifact descriptor;
          try {
              descriptor = resourceToArtifact(uri, true);
          } catch (MojoExecutionException e) {
              throw new RuntimeException(e.getMessage(), e);
          }
          if (descriptor != null) {
              // descriptor is resolved via Maven resolver ('latest'-Placeholder is replaced)
              resolveArtifact(descriptor, remoteRepos);
              descriptorArtifacts.add(descriptor);
              // adjust uri with version information from descriptor as URI is not resolved in the process (see subsequent comment)
              uri = uri.toLowerCase();
              uri = uri.replace("/latest/", "/" + descriptor.getBaseVersion() + "/");
          }
          if (includeMvnBasedDescriptors) {
              bundles.add(uri);
          }
          // translateFromMaven-Method just parses URI into the right format, it does not any resolving ('latest'-Placeholder won't be replaced)
          URI repoURI = URI.create(translateFromMaven(uri.replaceAll(" ", "%20")));
          Repository repo = new Repository(repoURI, defaultStartLevel);
          for (Feature f : repo.getFeatures()) {
              featuresMap.put(f.getName() + "/" + f.getVersion(), f);
          }
          if (resolveDefinedRepositoriesRecursively) {
              for (String r : repo.getDefinedRepositories()) {
                  retrieveDescriptorsRecursively(r, bundles, featuresMap);
              }
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              ggrzybek Grzegorz Grzybek
              afinke Achim Finke
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: