예제 #1
0
  /**
   * Get the set of artifacts that are provided by Synapse at runtime.
   *
   * @return
   * @throws MojoExecutionException
   */
  private Set<Artifact> getSynapseRuntimeArtifacts() throws MojoExecutionException {
    Log log = getLog();
    log.debug("Looking for synapse-core artifact in XAR project dependencies ...");
    Artifact synapseCore = null;
    for (Iterator<?> it = project.getDependencyArtifacts().iterator(); it.hasNext(); ) {
      Artifact artifact = (Artifact) it.next();
      if (artifact.getGroupId().equals("org.apache.synapse")
          && artifact.getArtifactId().equals("synapse-core")) {
        synapseCore = artifact;
        break;
      }
    }
    if (synapseCore == null) {
      throw new MojoExecutionException("Could not locate dependency on synapse-core");
    }

    log.debug("Loading project data for " + synapseCore + " ...");
    MavenProject synapseCoreProject;
    try {
      synapseCoreProject =
          projectBuilder.buildFromRepository(
              synapseCore, remoteArtifactRepositories, localRepository);
    } catch (ProjectBuildingException e) {
      throw new MojoExecutionException(
          "Unable to retrieve project information for " + synapseCore, e);
    }
    Set<Artifact> synapseRuntimeDeps;
    try {
      synapseRuntimeDeps =
          synapseCoreProject.createArtifacts(
              artifactFactory, Artifact.SCOPE_RUNTIME, new TypeArtifactFilter("jar"));
    } catch (InvalidDependencyVersionException e) {
      throw new MojoExecutionException("Unable to get project dependencies for " + synapseCore, e);
    }
    log.debug("Direct runtime dependencies for " + synapseCore + " :");
    logArtifacts(synapseRuntimeDeps);

    log.debug("Resolving transitive dependencies for " + synapseCore + " ...");
    try {
      synapseRuntimeDeps =
          artifactCollector
              .collect(
                  synapseRuntimeDeps,
                  synapseCoreProject.getArtifact(),
                  synapseCoreProject.getManagedVersionMap(),
                  localRepository,
                  remoteArtifactRepositories,
                  artifactMetadataSource,
                  null,
                  Collections.singletonList(new DebugResolutionListener(logger)))
              .getArtifacts();
    } catch (ArtifactResolutionException e) {
      throw new MojoExecutionException(
          "Unable to resolve transitive dependencies for " + synapseCore);
    }
    log.debug("All runtime dependencies for " + synapseCore + " :");
    logArtifacts(synapseRuntimeDeps);

    return synapseRuntimeDeps;
  }
예제 #2
0
  @SuppressWarnings("unchecked")
  private Collection<Artifact> getNonTransitivePlugins(Set<Artifact> projectArtifacts)
      throws MojoExecutionException {
    Collection<Artifact> deps = new LinkedHashSet<Artifact>();

    for (Artifact artifact : projectArtifacts) {
      Artifact pomArtifact =
          artifactFactory.createArtifact(
              artifact.getGroupId(),
              artifact.getArtifactId(),
              artifact.getVersion(),
              artifact.getClassifier(),
              "pom");
      Set<Artifact> result;
      try {
        MavenProject pomProject =
            mavenProjectBuilder.buildFromRepository(
                pomArtifact, remoteRepositories, localRepository);

        Set<Artifact> artifacts = pomProject.createArtifacts(artifactFactory, null, null);
        artifacts = filterOutSystemDependencies(artifacts);
        ArtifactResolutionResult arr =
            resolver.resolveTransitively(
                artifacts,
                pomArtifact,
                localRepository,
                remoteRepositories,
                artifactMetadataSource,
                null);
        result = arr.getArtifacts();
      } catch (Exception e) {
        throw new MojoExecutionException(
            "Failed to resolve non-transitive deps " + e.getMessage(), e);
      }

      LinkedHashSet<Artifact> plugins = new LinkedHashSet<Artifact>();
      plugins.addAll(filtterArtifacts(result, getFilters(null, null, "nexus-plugin", null)));
      plugins.addAll(filtterArtifacts(result, getFilters(null, null, "zip", "bundle")));

      plugins.addAll(getNonTransitivePlugins(plugins));

      if (!plugins.isEmpty()) {
        getLog()
            .debug(
                "Adding non-transitive dependencies for: "
                    + artifact
                    + " -\n"
                    + plugins.toString().replace(',', '\n'));
      }

      deps.addAll(plugins);
    }

    return deps;
  }