예제 #1
0
  private static boolean equals(
      org.eclipse.aether.artifact.Artifact a1, org.eclipse.aether.artifact.Artifact a2) {
    if (a1 == a2) {
      return true;
    }

    return a1.getArtifactId().equals(a2.getArtifactId())
        && a1.getGroupId().equals(a2.getGroupId())
        && a1.getVersion().equals(a2.getVersion())
        && a1.getExtension().equals(a2.getExtension())
        && a1.getClassifier().equals(a2.getClassifier());
  }
  private Artifact unify(Artifact dependent, Artifact dependency) {
    for (Entry<String, String> unification : unified.entrySet()) {
      String groupFilter = unification.getKey();
      String version = unification.getValue();
      String artifactId = dependency.toString();

      if ("".equals(version)) {
        version = dependent.getVersion();
      }
      if (artifactId.startsWith(groupFilter) && (!"".equals(version))) {
        Artifact retVal =
            new DefaultArtifact(
                dependency.getGroupId(),
                dependency.getArtifactId(),
                dependency.getClassifier(),
                dependency.getExtension(),
                // The important one
                version);
        retVal.setProperties(dependency.getProperties());
        return retVal;
      }
    }

    return dependency;
  }
예제 #3
0
  @Override
  protected void merge(Metadata recessive) {
    Snapshot snapshot;
    String lastUpdated;

    if (metadata.getVersioning() == null) {
      DateFormat utcDateFormatter = new SimpleDateFormat("yyyyMMdd.HHmmss");
      utcDateFormatter.setCalendar(new GregorianCalendar());
      utcDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

      snapshot = new Snapshot();
      snapshot.setBuildNumber(getBuildNumber(recessive) + 1);
      snapshot.setTimestamp(utcDateFormatter.format(new Date()));

      Versioning versioning = new Versioning();
      versioning.setSnapshot(snapshot);
      versioning.setLastUpdated(snapshot.getTimestamp().replace(".", ""));
      lastUpdated = versioning.getLastUpdated();

      metadata.setVersioning(versioning);
    } else {
      snapshot = metadata.getVersioning().getSnapshot();
      lastUpdated = metadata.getVersioning().getLastUpdated();
    }

    for (Artifact artifact : artifacts) {
      String version = artifact.getVersion();

      if (version.endsWith(SNAPSHOT)) {
        String qualifier = snapshot.getTimestamp() + '-' + snapshot.getBuildNumber();
        version = version.substring(0, version.length() - SNAPSHOT.length()) + qualifier;
      }

      SnapshotVersion sv = new SnapshotVersion();
      sv.setClassifier(artifact.getClassifier());
      sv.setExtension(artifact.getExtension());
      sv.setVersion(version);
      sv.setUpdated(lastUpdated);

      versions.put(getKey(sv.getClassifier(), sv.getExtension()), sv);
    }

    artifacts.clear();

    Versioning versioning = recessive.getVersioning();
    if (versioning != null) {
      for (SnapshotVersion sv : versioning.getSnapshotVersions()) {
        String key = getKey(sv.getClassifier(), sv.getExtension());
        if (!versions.containsKey(key)) {
          versions.put(key, sv);
        }
      }
    }

    if (!legacyFormat) {
      metadata.getVersioning().setSnapshotVersions(new ArrayList<>(versions.values()));
    }
  }
예제 #4
0
 public String getClassifier() {
   return delegate.getClassifier();
 }
예제 #5
0
 public String getExpandedVersion(Artifact artifact) {
   String key = getKey(artifact.getClassifier(), artifact.getExtension());
   return versions.get(key).getVersion();
 }
  private Set<Artifact> processTransientDependencies(Dependency dependency, boolean sharedLibraries)
      throws MojoExecutionException {
    try {
      final Set<Artifact> artifacts = new LinkedHashSet<Artifact>();

      final CollectRequest collectRequest = new CollectRequest();

      collectRequest.setRoot(dependency);
      collectRequest.setRepositories(projectRepos);
      final DependencyNode node =
          repoSystem.collectDependencies(repoSession, collectRequest).getRoot();

      Collection<String> exclusionPatterns = new ArrayList<String>();
      if (dependency.getExclusions() != null && !dependency.getExclusions().isEmpty()) {
        for (Exclusion exclusion : dependency.getExclusions()) {
          exclusionPatterns.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        }
      }

      final DependencyRequest dependencyRequest =
          new DependencyRequest(
              node,
              new AndDependencyFilter(
                  new ExclusionsDependencyFilter(exclusionPatterns),
                  new AndDependencyFilter(
                      new ScopeDependencyFilter(
                          Arrays.asList("compile", "runtime"), Arrays.asList("test")),
                      // Also exclude any optional dependencies
                      new DependencyFilter() {
                        @Override
                        public boolean accept(
                            DependencyNode dependencyNode, List<DependencyNode> dependencyNodes) {
                          return !dependencyNode.getDependency().isOptional();
                        }
                      })));

      repoSystem.resolveDependencies(repoSession, dependencyRequest);

      PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
      node.accept(nlg);

      final List<Dependency> dependencies = nlg.getDependencies(false);

      for (Dependency dep : dependencies) {
        final org.eclipse.aether.artifact.Artifact depAetherArtifact = dep.getArtifact();
        if (isNativeLibrary(sharedLibraries, depAetherArtifact.getExtension())) {
          final Artifact mavenArtifact =
              artifactFactory.createDependencyArtifact(
                  depAetherArtifact.getGroupId(),
                  depAetherArtifact.getArtifactId(),
                  VersionRange.createFromVersion(depAetherArtifact.getVersion()),
                  depAetherArtifact.getExtension(),
                  depAetherArtifact.getClassifier(),
                  dep.getScope());
          mavenArtifact.setFile(depAetherArtifact.getFile());
          artifacts.add(mavenArtifact);
        }
      }

      return artifacts;
    } catch (Exception e) {
      throw new MojoExecutionException("Error while processing transient dependencies", e);
    }
  }