/**
   * Returns <code>true</code> if the update should be applied.
   *
   * @param artifact The artifact.
   * @param currentVersion The current version of the artifact.
   * @param updateVersion The proposed new version of the artifact.
   * @return <code>true</code> if the update should be applied.
   * @since 1.0-alpha-1
   */
  protected boolean shouldApplyUpdate(
      Artifact artifact, String currentVersion, ArtifactVersion updateVersion) {
    getLog().debug("Proposal is to update from " + currentVersion + " to " + updateVersion);

    if (updateVersion == null) {
      getLog().warn("Not updating version: could not resolve any versions");
      return false;
    }

    artifact.setVersion(updateVersion.toString());
    try {
      resolver.resolveAlways(artifact, remoteArtifactRepositories, localRepository);
    } catch (ArtifactResolutionException e) {
      getLog().warn("Not updating version: could not resolve " + artifact.toString(), e);
      return false;
    } catch (ArtifactNotFoundException e) {
      getLog().warn("Not updating version: could not find " + artifact.toString(), e);
      return false;
    }

    if (currentVersion.equals(updateVersion.toString())) {
      getLog().info("Current version of " + artifact.toString() + " is the latest.");
      return false;
    }
    return true;
  }
예제 #2
0
  @Override
  public ArtifactDescriptorResult readArtifactDescriptor(
      RepositorySystemSession session, ArtifactDescriptorRequest request)
      throws ArtifactDescriptorException {

    ArtifactDescriptorException originalException = null;
    final Artifact artifact = request.getArtifact();
    // try FOSS local repo
    {
      try {
        final ArtifactDescriptorRequest alternateRequest =
            new ArtifactDescriptorRequest(
                    request.getArtifact(),
                    singletonList(fossRepository),
                    request.getRequestContext())
                .setTrace(request.getTrace());

        final ArtifactDescriptorResult result =
            delegate.readArtifactDescriptor(session, alternateRequest);
        if (result.getExceptions().isEmpty()) {
          return result;
        }
      } catch (ArtifactDescriptorException e) {
        originalException = e;
      }
    }
    // try FOSS local repo with LATEST
    if (!artifact.getVersion().equals(LATEST_VERSION)) {
      try {
        final Artifact alternateArtifact = artifact.setVersion(LATEST_VERSION);

        final ArtifactDescriptorRequest alternateRequest =
            new ArtifactDescriptorRequest(
                    alternateArtifact, singletonList(fossRepository), request.getRequestContext())
                .setTrace(request.getTrace());

        final ArtifactDescriptorResult result =
            delegate.readArtifactDescriptor(session, alternateRequest);
        if (result.getExceptions().isEmpty()) {
          logger.warn(
              "Could not find artifact descriptor "
                  + artifact
                  + ", using LATEST "
                  + result.getArtifact());
          return result;
        }
      } catch (ArtifactDescriptorException e) {
        logger.debug("LATEST resolution of " + artifact + " failed", e);
        if (originalException == null) {
          originalException = e;
        }
      }
    }
    // try JPP local repo
    if (useJpp) {
      // use maven as much as possible
      final RepositorySystemSession alternateSession = openJpp(session);
      try {
        final ArtifactDescriptorRequest alternateRequest =
            new ArtifactDescriptorRequest(
                request.getArtifact(), singletonList(fossRepository), request.getRequestContext());

        alternateRequest.setTrace(request.getTrace());

        final ArtifactDescriptorResult result =
            delegate.readArtifactDescriptor(alternateSession, alternateRequest);
        //                logger.warn("result from JPP " + result);
        if (result.getExceptions().isEmpty()) {
          // TODO: I may want to muck the result a bit to make sure JPP is also used for
          // resolveArtifact
          // JPP probably did not return the proper version, which
          // makes the MavenPluginValidator barf
          // lets muck it
          //                    result.setArtifact(new JPPArtifact(result.getArtifact()));
          logger.warn(
              "Could not find artifact descriptor "
                  + artifact
                  + ", using JPP "
                  + result.getArtifact());
          return result;
        }
      } catch (ArtifactDescriptorException e) {
        logger.debug("JPP resolution of " + artifact + " failed", e);
        if (originalException == null) {
          originalException = e;
        }
      }
    }

    if (originalException != null) {
      throw originalException;
    }

    throw new RuntimeException(
        "NYI: org.fedoraproject.maven.repository.internal."
            + "FossRepositorySystem.readArtifactDescriptor");
  }