Search in sources :

Example 11 with SingleVersion

use of org.commonjava.atlas.maven.ident.version.SingleVersion 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<>();
    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<>(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) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) TreeMap(java.util.TreeMap) ProjectVersionRefLocation(org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation) Location(org.commonjava.maven.galley.model.Location)

Example 12 with SingleVersion

use of org.commonjava.atlas.maven.ident.version.SingleVersion in project indy by Commonjava.

the class KojiMavenMetadataProvider method executeKojiMetadataLookup.

@Measure
private Metadata executeKojiMetadataLookup(ProjectRef ga, String path) throws KojiClientException, IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    // short-term caches to help improve performance a bit by avoiding xml-rpc calls.
    List<KojiArchiveInfo> archives = kojiContentProvider.listArchivesMatching(ga, null);
    Map<Integer, KojiBuildArchiveCollection> seenBuildArchives = new ConcurrentHashMap<>();
    Set<Integer> seenBuilds = new ConcurrentHashSet<>();
    DrainingExecutorCompletionService<SingleVersion> svc = new DrainingExecutorCompletionService<>(kojiMDService);
    detectOverloadVoid(() -> {
        for (KojiArchiveInfo archive : archives) {
            svc.submit(archiveScanner(path, ga, archive, seenBuilds, seenBuildArchives));
        }
    });
    Set<SingleVersion> versions = new ConcurrentHashSet<>();
    try {
        svc.drain(v -> {
            if (v != null) {
                versions.add(v);
            }
        });
    } catch (InterruptedException | ExecutionException e) {
        logger.warn("Failed to scan for Koji metadata related to: " + ga, e);
    }
    if (versions.isEmpty()) {
        logger.debug("No versions found in Koji builds for metadata: {}", path);
        return null;
    }
    List<SingleVersion> sortedVersions = new ArrayList<>(versions);
    Collections.sort(sortedVersions);
    Metadata md = new Metadata();
    md.setGroupId(ga.getGroupId());
    md.setArtifactId(ga.getArtifactId());
    Versioning versioning = new Versioning();
    versioning.setRelease(sortedVersions.get(versions.size() - 1).renderStandard());
    versioning.setLatest(sortedVersions.get(versions.size() - 1).renderStandard());
    versioning.setVersions(sortedVersions.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
    Date lastUpdated = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
    versioning.setLastUpdated(new SimpleDateFormat(LAST_UPDATED_FORMAT).format(lastUpdated));
    md.setVersioning(versioning);
    return md;
}
Also used : ArrayList(java.util.ArrayList) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) Logger(org.slf4j.Logger) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) Date(java.util.Date) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) KojiBuildArchiveCollection(com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection) ConcurrentHashSet(org.infinispan.commons.util.concurrent.ConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) ExecutionException(java.util.concurrent.ExecutionException) SimpleDateFormat(java.text.SimpleDateFormat) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 13 with SingleVersion

use of org.commonjava.atlas.maven.ident.version.SingleVersion in project indy by Commonjava.

the class MavenMetadataMerger method sortVersions.

public void sortVersions(Metadata metadata) {
    Versioning versioning = metadata.getVersioning();
    if (versioning != null && versioning.getVersions() != null) {
        List<SingleVersion> versionObjects = versioning.getVersions().stream().map((v) -> {
            try {
                return VersionUtils.createSingleVersion(v);
            } catch (InvalidVersionSpecificationException e) {
                return null;
            }
        }).filter(Objects::nonNull).collect(Collectors.toList());
        Collections.sort(versionObjects);
        versioning.setVersions(versionObjects.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
        if (versionObjects.size() > 0) {
            String latest = versionObjects.get(versionObjects.size() - 1).renderStandard();
            versioning.setLatest(latest);
            if (!latest.endsWith(LOCAL_SNAPSHOT_VERSION_PART)) {
                versioning.setRelease(latest);
            }
        }
    }
}
Also used : Versioning(org.apache.maven.artifact.repository.metadata.Versioning) InvalidVersionSpecificationException(org.commonjava.atlas.maven.ident.version.InvalidVersionSpecificationException) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion)

Aggregations

SingleVersion (org.commonjava.atlas.maven.ident.version.SingleVersion)13 ArrayList (java.util.ArrayList)8 MavenMetadataView (org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView)7 InvalidVersionSpecificationException (org.commonjava.atlas.maven.ident.version.InvalidVersionSpecificationException)6 TreeMap (java.util.TreeMap)5 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)5 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)5 Location (org.commonjava.maven.galley.model.Location)5 JoinString (org.commonjava.atlas.maven.ident.util.JoinString)4 StoreResource (org.commonjava.indy.content.StoreResource)3 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 Logger (org.slf4j.Logger)3 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)2 SimpleProjectVersionRef (org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef)2 VersionSpec (org.commonjava.atlas.maven.ident.version.VersionSpec)2 VersioningView (org.commonjava.maven.galley.maven.model.view.meta.VersioningView)2 Test (org.junit.Test)2