private void handleExclusions(Artifact artifact, Dependency dependency) {
   List<String> exclusions = new ArrayList<String>();
   for (Exclusion exclusion : dependency.getExclusions()) {
     exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
   }
   ArtifactFilter filter = new ExcludesArtifactFilter(exclusions);
   artifact.setDependencyFilter(filter);
 }
Beispiel #2
0
  // generic method to retrieve all the transitive dependencies
  private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
    List<Artifact> artifacts = new ArrayList<Artifact>();

    for (Iterator<?> dependencies = project.getDependencies().iterator();
        dependencies.hasNext(); ) {
      Dependency dependency = (Dependency) dependencies.next();

      String groupId = dependency.getGroupId();
      String artifactId = dependency.getArtifactId();

      VersionRange versionRange;
      try {
        versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
      } catch (InvalidVersionSpecificationException e) {
        throw new MojoExecutionException("unable to parse version", e);
      }

      String type = dependency.getType();
      if (type == null) {
        type = "jar";
      }
      String classifier = dependency.getClassifier();
      boolean optional = dependency.isOptional();
      String scope = dependency.getScope();
      if (scope == null) {
        scope = Artifact.SCOPE_COMPILE;
      }

      Artifact art =
          this.artifactFactory.createDependencyArtifact(
              groupId, artifactId, versionRange, type, classifier, scope, null, optional);

      if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
        art.setFile(new File(dependency.getSystemPath()));
      }

      List<String> exclusions = new ArrayList<String>();
      for (Iterator<?> j = dependency.getExclusions().iterator(); j.hasNext(); ) {
        Exclusion e = (Exclusion) j.next();
        exclusions.add(e.getGroupId() + ":" + e.getArtifactId());
      }

      ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);

      art.setDependencyFilter(newFilter);

      artifacts.add(art);
    }

    return artifacts;
  }
Beispiel #3
0
  // DefaultProjectBuilder
  public Artifact createDependencyArtifact(Dependency d) {
    if (d.getVersion() == null) {
      return null;
    }

    VersionRange versionRange;
    try {
      versionRange = VersionRange.createFromVersionSpec(d.getVersion());
    } catch (InvalidVersionSpecificationException e) {
      return null;
    }

    Artifact artifact =
        XcreateDependencyArtifact(
            d.getGroupId(),
            d.getArtifactId(),
            versionRange,
            d.getType(),
            d.getClassifier(),
            d.getScope(),
            d.isOptional());

    if (Artifact.SCOPE_SYSTEM.equals(d.getScope()) && d.getSystemPath() != null) {
      artifact.setFile(new File(d.getSystemPath()));
    }

    if (!d.getExclusions().isEmpty()) {
      List<String> exclusions = new ArrayList<>();

      for (Exclusion exclusion : d.getExclusions()) {
        exclusions.add(exclusion.getGroupId() + ':' + exclusion.getArtifactId());
      }

      artifact.setDependencyFilter(new ExcludesArtifactFilter(exclusions));
    }

    return artifact;
  }
  /**
   * Returns the list of project artifacts. Also artifacts generated from referenced projects will
   * be added, but with the <code>resolved</code> property set to true.
   *
   * @return list of projects artifacts
   * @throws MojoExecutionException if unable to parse dependency versions
   */
  private Set getProjectArtifacts() throws MojoExecutionException {
    // keep it sorted, this should avoid random classpath order in tests
    Set artifacts = new TreeSet();

    for (Iterator dependencies = getProject().getDependencies().iterator();
        dependencies.hasNext(); ) {
      Dependency dependency = (Dependency) dependencies.next();

      String groupId = dependency.getGroupId();
      String artifactId = dependency.getArtifactId();
      VersionRange versionRange;
      try {
        versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
      } catch (InvalidVersionSpecificationException e) {
        throw new MojoExecutionException(
            Messages.getString(
                "unabletoparseversion",
                new Object[] { // $NON-NLS-1$
                  dependency.getArtifactId(),
                  dependency.getVersion(),
                  dependency.getManagementKey(),
                  e.getMessage()
                }),
            e);
      }

      String type = dependency.getType();
      if (type == null) {
        type = "jar"; // $NON-NLS-1$
      }
      String classifier = dependency.getClassifier();
      boolean optional = dependency.isOptional();
      String scope = dependency.getScope();
      if (scope == null) {
        scope = Artifact.SCOPE_COMPILE;
      }

      Artifact art =
          getArtifactFactory()
              .createDependencyArtifact(
                  groupId, artifactId, versionRange, type, classifier, scope, optional);

      if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
        art.setFile(new File(dependency.getSystemPath()));
      }

      List exclusions = new ArrayList();
      for (Iterator j = dependency.getExclusions().iterator(); j.hasNext(); ) {
        Exclusion e = (Exclusion) j.next();
        exclusions.add(e.getGroupId() + ":" + e.getArtifactId()); // $NON-NLS-1$
      }

      ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);

      art.setDependencyFilter(newFilter);

      artifacts.add(art);
    }

    return artifacts;
  }