Search in sources :

Example 6 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project galley by Commonjava.

the class VersionResolverImpl method resolveAllMultiRefsWithLocations.

private List<ProjectVersionRefLocation> resolveAllMultiRefsWithLocations(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 List<ProjectVersionRefLocation> result = new ArrayList<ProjectVersionRefLocation>();
        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) {
                versions.remove(selected);
                if (selected.isConcrete() && spec.contains(selected)) {
                    result.add(new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected)));
                }
            }
        }
        return result;
    }
    return Collections.<ProjectVersionRefLocation>emptyList();
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TreeMap(java.util.TreeMap) VersionSpec(org.commonjava.maven.atlas.ident.version.VersionSpec) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 7 with MavenMetadataView

use of org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView in project galley by Commonjava.

the class VersionResolverImpl method resolveLatestSnapshotRefWithLocation.

private ProjectVersionRefLocation resolveLatestSnapshotRefWithLocation(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) {
                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()) {
        return null;
    }
    final List<SingleVersion> versions = new ArrayList<SingleVersion>(available.keySet());
    Collections.sort(versions);
    final SingleVersion selected = selectionStrategy.select(versions);
    if (selected == null) {
        return null;
    }
    return new ProjectVersionRefLocation(ref.selectVersion(selected), available.get(selected));
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)7 SingleVersion (org.commonjava.maven.atlas.ident.version.SingleVersion)6 ArrayList (java.util.ArrayList)5 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)5 Location (org.commonjava.maven.galley.model.Location)5 TreeMap (java.util.TreeMap)4 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)4 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)4 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 StoreResource (org.commonjava.indy.content.StoreResource)2 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)2 VersionSpec (org.commonjava.maven.atlas.ident.version.VersionSpec)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 VersioningView (org.commonjava.maven.galley.maven.model.view.meta.VersioningView)2 Test (org.junit.Test)2 ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)1 SnapshotPart (org.commonjava.maven.atlas.ident.version.part.SnapshotPart)1 TransferException (org.commonjava.maven.galley.TransferException)1 DocRef (org.commonjava.maven.galley.maven.model.view.DocRef)1