Set<Artifact> getResolvedArtifactsFromUnresolvedDependencies(
      List<Dependency> unresolvedDependencies, boolean resolveTransitively)
      throws MojoExecutionException {
    final Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
    //    Artifact mojoArtifact = this.artifactFactory.createBuildArtifact(project.getGroupId(),
    // project.getArtifactId(), project.getVersion(), "pom");

    /*
     * Resolve each artifact.  This will get all transitive artifacts AND eliminate conflicts.
     */
    final Set<Artifact> unresolvedArtifacts;

    //    for (Dependency d : unresolvedDependencies)
    //      System.out.println("dependency: " + d.toString());

    try {
      unresolvedArtifacts =
          MavenMetadataSource.createArtifacts(
              this.artifactFactory, unresolvedDependencies, null, null, null);
      //      for (Artifact artifact : unresolvedArtifacts) {
      //        System.out.println("unresolved " + artifact.toString());
      //      }

      if (resolveTransitively) {
        ArtifactResolutionResult artifacts =
            artifactResolver.resolveTransitively(
                unresolvedArtifacts,
                project.getArtifact(),
                remoteRepositories,
                localRepository,
                artifactMetadataSource);
        resolvedArtifacts.addAll(artifacts.getArtifacts());
      } else {
        // resolve each artifact individually
        for (Artifact artifact : unresolvedArtifacts) {
          artifactResolver.resolve(artifact, remoteRepositories, localRepository);

          resolvedArtifacts.add(artifact);
        }
      }

    } catch (Exception e) {
      throw new MojoExecutionException("Unable to complete configuring the build settings", e);
    }

    for (Artifact artifact : resolvedArtifacts) {
      System.out.println("matched " + artifact.toString());
    }

    return resolvedArtifacts;
  }
  /**
   * Removes any Grails plugin artifacts from the supplied list of dependencies. A Grails plugin is
   * any artifact whose type is equal to "grails-plugin" or "zip"
   *
   * @param artifact The list of artifacts to be cleansed.
   * @return list of plugins
   */
  private Set<Artifact> removePluginArtifacts(final Set<Artifact> artifact) {
    final Set<Artifact> pluginArtifacts = new HashSet<Artifact>();

    if (artifact != null) {
      for (final Iterator<Artifact> iter = artifact.iterator(); iter.hasNext(); ) {
        final Artifact dep = iter.next();
        if (dep.getType() != null
            && (dep.getType().equals("grails-plugin")
                || dep.getType().equals("zip")
                || (dep.getType().equals("grails-plugin2")
                    && "plugin".equals(dep.getClassifier())))) {
          pluginArtifacts.add(dep);
          //          System.out.println("removing " + dep.toString());
          iter.remove();
        }
      }
    }

    return pluginArtifacts;
  }
  @NotNull
  @Override
  public List<MavenArtifact> resolveTransitively(
      @NotNull List<MavenArtifactInfo> artifacts,
      @NotNull List<MavenRemoteRepository> remoteRepositories)
      throws RemoteException, MavenServerProcessCanceledException {

    try {
      Set<Artifact> toResolve = new LinkedHashSet<Artifact>();
      for (MavenArtifactInfo each : artifacts) {
        toResolve.add(createArtifact(each));
      }

      Artifact project =
          getComponent(ArtifactFactory.class).createBuildArtifact("temp", "temp", "666", "pom");

      Set<Artifact> res =
          getComponent(ArtifactResolver.class)
              .resolveTransitively(
                  toResolve,
                  project,
                  Collections.EMPTY_MAP,
                  myLocalRepository,
                  convertRepositories(remoteRepositories),
                  getComponent(ArtifactMetadataSource.class))
              .getArtifacts();

      return MavenModelConverter.convertArtifacts(
          res, new THashMap<Artifact, MavenArtifact>(), getLocalRepositoryFile());
    } catch (ArtifactResolutionException e) {
      Maven3ServerGlobals.getLogger().info(e);
    } catch (ArtifactNotFoundException e) {
      Maven3ServerGlobals.getLogger().info(e);
    } catch (Exception e) {
      throw rethrowException(e);
    }

    return Collections.emptyList();
  }