示例#1
0
  private ProjectVersionRefLocation resolveLatestMultiRefWithLocation(
      final List<? extends Location> locations,
      final ProjectVersionRef ref,
      final VersionSelectionStrategy selectionStrategy,
      final EventMetadata eventMetadata)
      throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
    for (final Location location : locations) {
      try {
        final MavenMetadataView metadata =
            metadataReader.getMetadata(
                ref.asProjectRef(), Collections.singletonList(location), eventMetadata);

        if (metadata != null) {
          final List<String> versions =
              metadata.resolveValues("/metadata/versioning/versions/version");

          if (versions != null) {
            for (final String version : versions) {
              try {
                final SingleVersion spec = VersionUtils.createSingleVersion(version);
                if (!available.containsKey(spec)) {
                  available.put(spec, location);
                }
              } catch (final InvalidVersionSpecificationException e) {
                debug(
                    "Unparsable version spec found in metadata: '%s' for: %s from: %s.",
                    e, version, ref, location);
              }
            }
          }
        }
      } catch (final GalleyMavenException e) {
        debug(
            "Failed to resolve/parse metadata for variable version of: '%s' from: %s.",
            e, ref, location);
      }
    }

    if (!available.isEmpty()) {
      final VersionSpec spec = ref.getVersionSpec();

      final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
      Collections.sort(versions);
      while (!versions.isEmpty()) {
        final SingleVersion selected = selectionStrategy.select(versions);
        if (selected == null) {
          return null;
        }

        versions.remove(selected);
        if (selected.isConcrete() && spec.contains(selected)) {
          return new ProjectVersionRefLocation(
              ref.selectVersion(selected), available.get(selected));
        }
      }
    }

    return null;
  }
示例#2
0
 @Override
 public ProjectVersionRef resolveFirstMatchVariableVersion(
     final List<? extends Location> locations,
     final ProjectVersionRef ref,
     final VersionSelectionStrategy selectionStrategy,
     final EventMetadata eventMetadata)
     throws TransferException {
   if (!ref.getVersionSpec().isSingle()) {
     return resolveFirstMultiRef(locations, ref, selectionStrategy, eventMetadata);
   } else if (ref.isSnapshot()) {
     return resolveFirstSnapshotRef(locations, ref, selectionStrategy, eventMetadata);
   } else {
     return ref;
   }
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((key == null) ? 0 : key.hashCode());
   return result;
 }
示例#4
0
  private List<ProjectVersionRefLocation> resolveAllSnapshotRefsWithLocations(
      final List<? extends Location> locations,
      final ProjectVersionRef ref,
      final VersionSelectionStrategy selectionStrategy,
      final EventMetadata eventMetadata)
      throws TransferException {
    final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
    for (final Location location : locations) {
      try {
        final MavenMetadataView metadata =
            metadataReader.getMetadata(ref, Collections.singletonList(location), eventMetadata);

        if (metadata != null) {
          final String latest = metadata.resolveSingleValue("/metadata/versioning/latest");
          if (latest != null) {
            try {
              final SingleVersion ver = VersionUtils.createSingleVersion(latest);
              if (ver.isSnapshot()) {
                if (!available.containsKey(ver)) {
                  available.put(ver, location);
                }
              }
            } catch (final InvalidVersionSpecificationException e) {
              debug(
                  "Unparsable version spec found in metadata: '%s' for: %s from: %s",
                  e, latest, ref, location);
            }
          }
        }
      } catch (final GalleyMavenException e) {
        debug(
            "Failed to resolve/parse metadata for snapshot version of: %s from: %s.",
            e, ref, location);
      }
    }

    if (!available.isEmpty()) {
      return Collections.emptyList();
    }

    final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
    Collections.sort(versions);

    final List<ProjectVersionRefLocation> result = new ArrayList<ProjectVersionRefLocation>();

    while (!versions.isEmpty()) {
      final SingleVersion selected = selectionStrategy.select(versions);
      if (selected != null) {
        versions.remove(selected);
        result.add(
            new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected)));
      }
    }

    return result;
  }
  @Test
  public void run() throws Exception {
    final URI source = sourceURI();
    final ProjectVersionRef root = projectVersion("group.id", "my-project", "1.0");
    final ProjectVersionRef d1 = projectVersion("other.group", "dep-L1", "1.0.1");
    final ProjectVersionRef d2 = projectVersion("foo", "dep-L2", "1.1.1");
    final ProjectVersionRef d3 = projectVersion("foo", "dep-L2", "1.1.2");

    RelationshipGraph graph = simpleGraph(root);

    /* @formatter:off */
    graph.storeRelationships(
        new SimpleParentRelationship(source, root),
        new SimpleDependencyRelationship(
            source, root, d1.asJarArtifact(), compile, 0, false, false, false),
        new SimpleDependencyRelationship(
            source, d1, d2.asJarArtifact(), compile, 0, false, false, false));
    /* @formatter:on */

    graph =
        graphFactory()
            .open(
                new ViewParams.Builder(graph.getParams())
                    .withSelection(d2.asProjectRef(), d3)
                    .build(),
                false);

    //        graph.getView()
    //             .selectVersion( d2.asProjectRef(), d3 );

    final TransitiveDependencyTraversal depTraversal = new TransitiveDependencyTraversal();
    graph.traverse(depTraversal);

    final List<ArtifactRef> artifacts = depTraversal.getArtifacts();

    assertThat(artifacts.size(), equalTo(2));

    int idx = 0;

    ArtifactRef ref = artifacts.get(idx++);
    assertThat(ref.getArtifactId(), equalTo("dep-L1"));

    ref = artifacts.get(idx++);
    assertThat(ref.getArtifactId(), equalTo("dep-L2"));
    assertThat(ref.getVersionString(), equalTo(d3.getVersionString()));
  }
 @Override
 public boolean equals(final Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   final Project other = (Project) obj;
   if (key == null) {
     if (other.key != null) {
       return false;
     }
   } else if (!key.equals(other.key)) {
     return false;
   }
   return true;
 }
示例#7
0
  private ProjectVersionRefLocation resolveFirstSnapshotRefWithLocation(
      final List<? extends Location> locations,
      final ProjectVersionRef ref,
      final VersionSelectionStrategy selectionStrategy,
      final EventMetadata eventMetadata)
      throws TransferException {
    nextLoc:
    for (final Location location : locations) {
      final Map<SingleVersion, Location> available = new TreeMap<SingleVersion, Location>();
      try {
        final MavenMetadataView metadata =
            metadataReader.getMetadata(ref, Collections.singletonList(location), eventMetadata);

        if (metadata != null) {
          addSnapshotFrom(metadata, location, ref, available);
        }
      } catch (final GalleyMavenException e) {
        debug(
            "Failed to resolve/parse metadata for snapshot version of: %s from: %s.",
            e, ref, location);
      }

      if (!available.isEmpty()) {
        final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
        Collections.sort(versions);

        final SingleVersion selected = selectionStrategy.select(versions);
        if (selected == null) {
          continue;
        }

        return new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected));
      }
    }

    return null;
  }
 public String getVersion() {
   return key.getVersionString();
 }
 public String getArtifactId() {
   return key.getArtifactId();
 }
 public String getGroupId() {
   return key.getGroupId();
 }