Exemplo n.º 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;
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
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;
  }