private Collection<Artifact> getMostRecentArtifacts(Set<Artifact> artifacts) {
    Map<String, Artifact> artifactIdToArtifact = new HashMap<String, Artifact>();

    for (Artifact artifact : artifacts) {
      if (artifact.getScope() != null && artifact.getScope().contains("provide")) {
        continue;
      }

      String artifactId = artifact.getArtifactId();

      ArtifactVersion artifactVersion;

      try {
        artifactVersion = new DefaultArtifactVersion(artifact.getVersion());
      } catch (Exception e) {
        artifactVersion = null;
      }

      Artifact actualArtifactForId = artifactIdToArtifact.get(artifactId);
      ArtifactVersion actualArtifactVersion =
          (actualArtifactForId == null)
              ? null
              : new DefaultArtifactVersion(actualArtifactForId.getVersion());

      if (actualArtifactVersion == null) {
        artifactIdToArtifact.put(artifactId, artifact);
      } else {
        if (actualArtifactVersion.compareTo(artifactVersion) < 0) {
          artifactIdToArtifact.put(artifactId, artifact);
        }
      }
    }

    return artifactIdToArtifact.values();
  }
  /** Check gwt-user dependency matches plugin version */
  private void checkGwtUserVersion() throws MojoExecutionException {
    InputStream inputStream =
        Thread.currentThread()
            .getContextClassLoader()
            .getResourceAsStream("org/codehaus/mojo/gwt/mojoGwtVersion.properties");
    Properties properties = new Properties();
    try {
      properties.load(inputStream);

    } catch (IOException e) {
      throw new MojoExecutionException("Failed to load plugin properties", e);
    } finally {
      IOUtils.closeQuietly(inputStream);
    }
    for (Iterator iterator = getProject().getCompileArtifacts().iterator(); iterator.hasNext(); ) {
      Artifact artifact = (Artifact) iterator.next();
      if (GWT_GROUP_ID.equals(artifact.getGroupId())
          && "gwt-user".equals(artifact.getArtifactId())) {
        String mojoGwtVersion = properties.getProperty("gwt.version");
        // ComparableVersion with an up2date maven version
        ArtifactVersion mojoGwtArtifactVersion = new DefaultArtifactVersion(mojoGwtVersion);
        ArtifactVersion userGwtArtifactVersion = new DefaultArtifactVersion(artifact.getVersion());
        if (userGwtArtifactVersion.compareTo(mojoGwtArtifactVersion) < 0) {
          getLog()
              .warn(
                  "You're project declares dependency on gwt-user "
                      + artifact.getVersion()
                      + ". This plugin is designed for at least gwt version "
                      + mojoGwtVersion);
        }
        break;
      }
    }
  }
 @SuppressWarnings("unchecked")
 private boolean containsConflicts(List<DependencyNodeHopCountPair> pairs) {
   ArtifactVersion resolvedVersion = pairs.get(0).extractArtifactVersion();
   for (DependencyNodeHopCountPair pair : pairs) {
     ArtifactVersion version = pair.extractArtifactVersion();
     if (resolvedVersion.compareTo(version) < 0) {
       return true;
     }
   }
   return false;
 }
  @SuppressWarnings("unchecked")
  public void execute() throws MojoExecutionException {
    ArtifactVersion currentVersion = ri.getApplicationVersion();
    ArtifactVersion maxUsageVersion = new DefaultArtifactVersion("2.2.0");

    if (maxUsageVersion.compareTo(currentVersion) < 0) {
      getLog()
          .debug(
              "This version of Maven does not require injection of custom ArtifactHandlers using this code. Skipping.");
      return;
    }

    Map<String, ?> handlerDescriptors =
        session.getContainer().getComponentDescriptorMap(ArtifactHandler.ROLE);
    if (handlerDescriptors != null) {
      getLog().debug("Registering all unregistered ArtifactHandlers...");

      if (artifactHandlerManager instanceof DefaultArtifactHandlerManager) {
        Set<String> existingHints =
            ((DefaultArtifactHandlerManager) artifactHandlerManager).getHandlerTypes();
        if (existingHints != null) {
          for (String hint : existingHints) {
            handlerDescriptors.remove(hint);
          }
        }
      }

      if (handlerDescriptors.isEmpty()) {
        getLog().debug("All ArtifactHandlers are registered. Continuing...");
      } else {
        Map<String, ArtifactHandler> unregisteredHandlers =
            new HashMap<String, ArtifactHandler>(handlerDescriptors.size());

        for (String hint : handlerDescriptors.keySet()) {
          try {
            unregisteredHandlers.put(
                hint, (ArtifactHandler) session.lookup(ArtifactHandler.ROLE, hint));
            getLog().info("Adding ArtifactHandler for: " + hint);
          } catch (ComponentLookupException e) {
            getLog()
                .warn(
                    "Failed to lookup ArtifactHandler with hint: "
                        + hint
                        + ". Reason: "
                        + e.getMessage(),
                    e);
          }
        }

        artifactHandlerManager.addHandlers(unregisteredHandlers);
      }
    }

    getLog()
        .debug("...done.\nSetting ArtifactHandler on project-artifact: " + project.getId() + "...");

    Set<Artifact> artifacts = new HashSet<Artifact>();
    artifacts.add(project.getArtifact());

    Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    if (dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) {
      artifacts.addAll(dependencyArtifacts);
    }

    for (Artifact artifact : artifacts) {
      String type = artifact.getType();
      ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(type);

      getLog()
          .debug(
              "Artifact: "
                  + artifact.getId()
                  + "\nType: "
                  + type
                  + "\nArtifactHandler extension: "
                  + handler.getExtension());

      artifact.setArtifactHandler(handler);
    }

    getLog().debug("...done.");
  }