Ejemplo n.º 1
0
  private List toMessages(String target, Throwable cause) {
    if (cause.getCause() != null) {
      return toMessages(target, cause.getCause());
    }

    if (cause instanceof MultipleArtifactsNotFoundException) {
      final MultipleArtifactsNotFoundException manfe = (MultipleArtifactsNotFoundException) cause;
      return parseMissingDependenciesFromFormattedMessage(target, manfe.getMessage());
    }

    try {
      final String longMessage =
          (String)
              cause
                  .getClass()
                  .getMethod("getLongMessage", (Class[]) null)
                  .invoke(cause, (Object[]) null);
      return parseCompileFailuresFromFormattedMessage(target, longMessage);
    } catch (Exception e) {
    }

    return Collections.singletonList(
        new AntEventSummary(
            Constants.MESSAGE_LOGGED,
            null,
            target,
            null,
            cause.getClass().getName() + ": " + cause.getMessage(),
            0));
  }
  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);
  }