Search in sources :

Example 1 with ProjectVersionRefLocation

use of org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation in project galley by Commonjava.

the class ArtifactManagerImpl method resolveFirstVirtualResource.

private VirtualResource resolveFirstVirtualResource(List<? extends Location> locations, ArtifactRef ref, final EventMetadata eventMetadata) throws TransferException {
    locations = expander.expand(locations);
    if (ref.isVariableVersion()) {
        final ProjectVersionRefLocation resolved = resolveSingleVariableVersion(locations, ref, eventMetadata);
        if (resolved != null) {
            locations = Collections.singletonList(resolved.getLocation());
            ref = (ArtifactRef) resolved.getRef();
        }
    }
    return new VirtualResource(expander.expand(locations), formatArtifactPath(ref, mapper));
}
Also used : ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 2 with ProjectVersionRefLocation

use of org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation in project galley by Commonjava.

the class VersionResolverImpl method resolveFirstSnapshotRefWithLocation.

private ProjectVersionRefLocation resolveFirstSnapshotRefWithLocation(final List<? extends Location> locations, final ProjectVersionRef ref, final VersionSelectionStrategy selectionStrategy, final EventMetadata eventMetadata) throws TransferException {
    for (final Location location : locations) {
        final Map<SingleVersion, Location> available = new TreeMap<>();
        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<>(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;
}
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) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) TreeMap(java.util.TreeMap) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 3 with ProjectVersionRefLocation

use of org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation in project galley by Commonjava.

the class VersionResolverImpl method resolveLatestMultiRefWithLocation.

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<>();
    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<>(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;
}
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 4 with ProjectVersionRefLocation

use of org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation in project galley by Commonjava.

the class VersionResolverImpl method resolveAllSnapshotRefsWithLocations.

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<>();
    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<>(available.keySet());
    Collections.sort(versions);
    final List<ProjectVersionRefLocation> result = new ArrayList<>();
    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;
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) InvalidVersionSpecificationException(org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) ArrayList(java.util.ArrayList) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) SingleVersion(org.commonjava.maven.atlas.ident.version.SingleVersion) TreeMap(java.util.TreeMap) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 5 with ProjectVersionRefLocation

use of org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation in project galley by Commonjava.

the class ArtifactManagerImpl method resolveAllVirtualResource.

private VirtualResource resolveAllVirtualResource(List<? extends Location> locations, final ArtifactRef ref, final EventMetadata eventMetadata) throws TransferException {
    locations = expander.expand(locations);
    logger.debug("Locations expanded to: {} for artifact: {}", locations, ref);
    VirtualResource virt = new VirtualResource(locations, formatArtifactPath(ref, mapper));
    if (ref.isVariableVersion()) {
        final List<ProjectVersionRefLocation> resolved = resolveAllVariableVersions(locations, ref, eventMetadata);
        if (resolved != null && !resolved.isEmpty()) {
            final List<ConcreteResource> resources = new ArrayList<>(resolved.size());
            for (final ProjectVersionRefLocation result : resolved) {
                resources.add(new ConcreteResource(result.getLocation(), formatArtifactPath(ref, mapper)));
            }
            virt = new VirtualResource(resources);
        } else {
            return null;
        }
    }
    return virt;
}
Also used : ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Aggregations

ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)7 ArrayList (java.util.ArrayList)6 TreeMap (java.util.TreeMap)5 SingleVersion (org.commonjava.maven.atlas.ident.version.SingleVersion)5 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)5 MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)5 Location (org.commonjava.maven.galley.model.Location)5 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)3 InvalidVersionSpecificationException (org.commonjava.maven.atlas.ident.version.InvalidVersionSpecificationException)3 VersionSpec (org.commonjava.maven.atlas.ident.version.VersionSpec)2 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)2 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)1