示例#1
0
  private List<File> getFrameworkExtensions() throws MojoExecutionException {
    List<File> files = new ArrayList<File>();

    if (frameworkExtensions != null) {
      for (Dependency frameworkExtension : frameworkExtensions) {
        Artifact artifact = repositorySystem.createDependencyArtifact(frameworkExtension);
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setResolveRoot(true).setResolveTransitively(false);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(project.getPluginArtifactRepositories());
        request.setOffline(session.isOffline());
        request.setForceUpdate(session.getRequest().isUpdateSnapshots());
        ArtifactResolutionResult result = repositorySystem.resolve(request);
        try {
          resolutionErrorHandler.throwErrors(request, result);
        } catch (ArtifactResolutionException e) {
          throw new MojoExecutionException(
              "Failed to resolve framework extension " + frameworkExtension.getManagementKey(), e);
        }
        files.add(artifact.getFile());
      }
    }

    return files;
  }
  private void setTarget(
      TargetPlatformConfiguration result,
      MavenSession session,
      MavenProject project,
      Xpp3Dom configuration) {
    Xpp3Dom targetDom = configuration.getChild("target");
    if (targetDom == null) {
      return;
    }

    Xpp3Dom artifactDom = targetDom.getChild("artifact");
    if (artifactDom == null) {
      return;
    }

    Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
    Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
    Xpp3Dom versionDom = artifactDom.getChild("version");
    if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
      return;
    }
    Xpp3Dom classifierDom = artifactDom.getChild("classifier");

    String groupId = groupIdDom.getValue();
    String artifactId = artifactIdDom.getValue();
    String version = versionDom.getValue();
    String classifier = classifierDom != null ? classifierDom.getValue() : null;

    File targetFile = null;
    for (MavenProject otherProject : session.getProjects()) {
      if (groupId.equals(otherProject.getGroupId())
          && artifactId.equals(otherProject.getArtifactId())
          && version.equals(otherProject.getVersion())) {
        targetFile = new File(otherProject.getBasedir(), classifier + ".target");
        break;
      }
    }

    if (targetFile == null) {
      Artifact artifact =
          repositorySystem.createArtifactWithClassifier(
              groupId, artifactId, version, "target", classifier);
      ArtifactResolutionRequest request = new ArtifactResolutionRequest();
      request.setArtifact(artifact);
      request.setLocalRepository(session.getLocalRepository());
      request.setRemoteRepositories(project.getRemoteArtifactRepositories());
      repositorySystem.resolve(request);

      if (!artifact.isResolved()) {
        throw new RuntimeException(
            "Could not resolve target platform specification artifact " + artifact);
      }

      targetFile = artifact.getFile();
    }

    result.setTarget(targetFile);
  }
  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;
  }
 /**
  * Resolves the given artifact to a maven project.
  *
  * @param artifact
  * @throws Exception
  */
 protected MavenProject resolveProject(Artifact artifact) throws Exception {
   Artifact pomArtifact =
       repositorySystem.createArtifact(
           artifact.getGroupId(),
           artifact.getArtifactId(),
           artifact.getVersion(),
           "",
           "pom"); //$NON-NLS-1$ //$NON-NLS-2$
   ArtifactResolutionRequest request = new ArtifactResolutionRequest();
   request.setArtifact(pomArtifact);
   ArtifactResolutionResult resolved = repositorySystem.resolve(request);
   pomArtifact = resolved.getArtifacts().iterator().next();
   InputStream contentStream = null;
   MavenProject project = null;
   try {
     contentStream = new FileInputStream(pomArtifact.getFile());
     Model model = new MavenXpp3Reader().read(contentStream);
     project = new MavenProject(model);
   } finally {
     contentStream.close();
   }
   return project;
 }
示例#5
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;
  }