示例#1
0
  @Override
  public List<Dependency> resolveVersions(
      final Dependency dep, final List<DependencyRepository> repositories) {
    List<Dependency> result = new ArrayList<Dependency>();

    List<RemoteRepository> remoteRepos = convertToMavenRepos(repositories);
    VersionRangeResult r = getVersions(dep, remoteRepos);

    for (Version v : r.getVersions()) {
      result.add(DependencyBuilder.create(dep).setVersion(v.toString()));
    }

    return result;
  }
示例#2
0
  @Override
  public List<DependencyResource> resolveArtifacts(
      Dependency dep, final List<DependencyRepository> repositories) {
    List<DependencyResource> result = new ArrayList<DependencyResource>();

    try {
      RepositorySystem system = container.lookup(RepositorySystem.class);
      MavenRepositorySystemSession session = setupRepoSession(system);

      session.setIgnoreInvalidArtifactDescriptor(true);
      session.setIgnoreMissingArtifactDescriptor(true);

      VersionRangeResult versions = getVersions(dep, convertToMavenRepos(repositories));

      VERSION:
      for (Version version : versions.getVersions()) {
        ArtifactRequest request = new ArtifactRequest();
        ArtifactRepository ar = versions.getRepository(version);
        if (ar instanceof RemoteRepository) {
          RemoteRepository remoteRepo =
              new RemoteRepository(
                  ar.getId(), ar.getContentType(), ((RemoteRepository) ar).getUrl());
          request.addRepository(remoteRepo);
          DependencyBuilder currentVersion =
              DependencyBuilder.create(dep).setVersion(version.toString());
          request.setArtifact(new DefaultArtifact(currentVersion.toCoordinates()));

          try {
            ArtifactResult a = system.resolveArtifact(session, request);

            File file = a.getArtifact().getFile();
            DependencyResource resource = new DependencyResource(factory, file, currentVersion);
            if (!result.contains(resource)) {
              result.add(resource);
              continue VERSION;
            }
          } catch (ArtifactResolutionException e) {
            System.out.println(e.getMessage());
          }
        }
      }
    } catch (ComponentLookupException e) {
      throw new ProjectModelException("Error in dependency resolution container", e);
    }
    return result;
  }
  @Override
  public VersionRangeResult resolveVersionRange(
      RepositorySystemSession session, VersionRangeRequest request)
      throws VersionRangeResolutionException {

    debugf("resolveVersionRange %s", request);
    //        assertFedoraRepository(request.getRepositories());
    try {
      // try FOSS local repo
      final VersionRangeRequest alternateRequest =
          new VersionRangeRequest(
                  request.getArtifact(), singletonList(fossRepository), request.getRequestContext())
              .setTrace(request.getTrace());

      final VersionRangeResult result = delegate.resolveVersionRange(session, alternateRequest);
      //            logger.warn("result = " + result.getVersions());

      final Version highestVersion = result.getHighestVersion();

      if (result.getExceptions().isEmpty()) {
        // Did we find something in the repo?
        // TODO: this is the best thing I could think off, what is the correct check?
        if (highestVersion != null && result.getRepository(highestVersion) != null) {
          return result;
        }
      }

      // the FOSS local repo might be running without metadata
      // TODO: how to check that?
      if (hasArtifact(session, request, highestVersion)) {
        result.setRepository(highestVersion, fossRepository);
        return result;
      }

      if (!useJpp) {
        return result;
      }

      // try JPP local repo
      // JPP will always return something regardless of the version, but
      // without a version readArtifactDescriptor will go into the
      // DefaultVersionResolver so we can't put in LATEST.
      //            throw new RuntimeException("NYI");
      // TODO: what if highestVersion is null?
      result.setRepository(highestVersion, jppRepositoryManager.getRepository());
      logger.warn("Could not resolve version range " + request + ", using JPP " + result);
      return result;
    } catch (VersionRangeResolutionException e) {
      throw e;
    }
  }