private void addPomDependenciesToTargetPlatform(
      MavenProject project,
      TargetPlatformBuilder resolutionContext,
      List<ReactorProject> reactorProjects,
      MavenSession session) {
    Set<String> projectIds = new HashSet<String>();
    for (ReactorProject p : reactorProjects) {
      String key = ArtifactUtils.key(p.getGroupId(), p.getArtifactId(), p.getVersion());
      projectIds.add(key);
    }

    ArrayList<String> scopes = new ArrayList<String>();
    scopes.add(Artifact.SCOPE_COMPILE);
    Collection<Artifact> artifacts;
    try {
      artifacts = projectDependenciesResolver.resolve(project, scopes, session);
    } catch (MultipleArtifactsNotFoundException e) {
      Collection<Artifact> missing = new HashSet<Artifact>(e.getMissingArtifacts());

      for (Iterator<Artifact> it = missing.iterator(); it.hasNext(); ) {
        Artifact a = it.next();
        String key = ArtifactUtils.key(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
        if (projectIds.contains(key)) {
          it.remove();
        }
      }

      if (!missing.isEmpty()) {
        throw new RuntimeException("Could not resolve project dependencies", e);
      }

      artifacts = e.getResolvedArtifacts();
      artifacts.removeAll(e.getMissingArtifacts());
    } catch (AbstractArtifactResolutionException e) {
      throw new RuntimeException("Could not resolve project dependencies", e);
    }
    List<Artifact> externalArtifacts = new ArrayList<Artifact>(artifacts.size());
    for (Artifact artifact : artifacts) {
      String key =
          ArtifactUtils.key(
              artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion());
      if (projectIds.contains(key)) {
        // resolved to an older snapshot from the repo, we only want the current project in the
        // reactor
        continue;
      }
      externalArtifacts.add(artifact);
    }
    List<Artifact> explicitArtifacts =
        MavenDependencyInjector.filterInjectedDependencies(
            externalArtifacts); // needed when the resolution is done again for the test runtime
    PomDependencyProcessor pomDependencyProcessor =
        new PomDependencyProcessor(
            session,
            repositorySystem,
            equinox.getService(LocalRepositoryP2Indices.class),
            getLogger());
    pomDependencyProcessor.addPomDependenciesToResolutionContext(
        project, explicitArtifacts, resolutionContext);
  }
Exemple #2
0
  protected P2Generator getP2Generator() {
    if (p2 == null) {
      p2 = equinox.getService(P2Generator.class);

      if (p2 == null) {
        throw new IllegalStateException("Could not acquire P2 metadata service");
      }
    }
    return p2;
  }
 public void initialize() throws InitializationException {
   this.resolverFactory = equinox.getService(P2ResolverFactory.class);
   this.generator =
       equinox.getService(DependencyMetadataGenerator.class, "(role-hint=dependency-only)");
 }