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));
}
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;
}
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);
}
}
}
}
Aggregations