private ArtifactResolutionResult resolve(MavenArtifactRef a, boolean resolveTransitively)
      throws MojoExecutionException {
    Artifact artifact =
        repositorySystem.createArtifact(a.getGroupId(), a.getArtifactId(), a.getVersion(), "jar");

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setLocalRepository(localRepository);
    request.setRemoteRepositories(remoteRepositories);
    request.setResolveRoot(true);
    request.setResolveTransitively(resolveTransitively);
    ArtifactResolutionResult result = repositorySystem.resolve(request);

    if (!result.isSuccess()) {
      throw new MojoExecutionException("Could not resolve extra classpath entry");
    }

    result.setOriginatingArtifact(artifact);

    return result;
  }
Exemple #2
0
  protected void addMvn2CompatResults(
      MavenProject project,
      List<Exception> exceptions,
      List<ResolutionListener> listeners,
      ArtifactRepository localRepository,
      Collection<MavenExecutionResult> executionResults) {
    ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
    resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
    resolutionRequest.setArtifact(project.getArtifact());
    resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
    resolutionRequest.setLocalRepository(localRepository);
    resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
    resolutionRequest.setListeners(listeners);

    resolutionRequest.setResolveRoot(false);
    resolutionRequest.setResolveTransitively(true);

    ArtifactResolver resolver = getComponent(ArtifactResolver.class);
    ArtifactResolutionResult result = resolver.resolve(resolutionRequest);

    project.setArtifacts(result.getArtifacts());
    executionResults.add(new MavenExecutionResult(project, exceptions));
  }
  /**
   * Returns the Set of APKLIB, AAR, APK (direct or transitive) dependencies of the supplied
   * artifact.
   *
   * <p>The project is searched until artifact is found and then the library dependencies are looked
   * for recursively.
   *
   * @param session MavenSession in which to resolve the artifacts.
   * @param repositorySystem RepositorySystem with which to resolve the artifacts.
   * @param artifact Artifact for whom to get the dependencies.
   * @return Set of APK, APKLIB and AAR dependencies.
   * @throws org.apache.maven.plugin.MojoExecutionException if it couldn't resolve any of the
   *     dependencies.
   */
  public Set<Artifact> getLibraryDependenciesFor(
      MavenSession session, RepositorySystem repositorySystem, Artifact artifact)
      throws MojoExecutionException {
    // Set a filter that should only return interesting artifacts.
    final ArtifactFilter filter =
        new ArtifactFilter() {
          @Override
          public boolean include(Artifact found) {
            final String type = found.getType();
            return (type.equals(APKLIB) || type.equals(AAR) || type.equals(APK));
          }
        };

    log.debug("MavenSession = " + session + "  repositorySystem = " + repositorySystem);

    final ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(false); // Don't include source artifact in result
    request.setResolveTransitively(true); // Include direct plus transitive dependencies.
    request.setServers(session.getRequest().getServers());
    request.setMirrors(session.getRequest().getMirrors());
    request.setProxies(session.getRequest().getProxies());
    request.setLocalRepository(session.getLocalRepository());
    request.setRemoteRepositories(session.getCurrentProject().getRemoteArtifactRepositories());

    final ArtifactResolutionResult result = repositorySystem.resolve(request);

    final Set<Artifact> libraryDeps = new HashSet<Artifact>();
    for (final Artifact depArtifact : result.getArtifacts()) {
      if (filter.include(depArtifact)) {
        libraryDeps.add(depArtifact);
      }
    }

    return libraryDeps;
  }