use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project galley by Commonjava.
the class MavenMetadataReader method getMetadata.
public MavenMetadataView getMetadata(final ProjectRef ref, final List<? extends Location> locations, final EventMetadata eventMetadata) throws GalleyMavenException {
final List<DocRef<ProjectRef>> docs = new ArrayList<>(locations.size());
final Map<Location, DocRef<ProjectRef>> cached = getAllCached(ref, locations);
final List<? extends Location> toRetrieve = new ArrayList<>(locations);
for (final Location loc : locations) {
final DocRef<ProjectRef> dr = cached.get(loc);
if (dr != null) {
docs.add(dr);
toRetrieve.remove(loc);
} else {
docs.add(null);
}
}
List<Transfer> transfers;
try {
transfers = metadataManager.retrieveAll(toRetrieve, ref, eventMetadata);
} catch (final TransferException e) {
throw new GalleyMavenException("Failed to resolve metadata for: {} from: {}. Reason: {}", e, ref, locations, e.getMessage());
}
logger.debug("Resolved {} transfers:\n {}", transfers.size(), new JoinString("\n ", transfers));
// noinspection ConstantConditions
if (transfers != null && !transfers.isEmpty()) {
for (final Transfer transfer : transfers) {
final DocRef<ProjectRef> dr = new DocRef<>(ref, transfer.getLocation(), xml.parse(transfer, eventMetadata));
final int idx = locations.indexOf(transfer.getLocation());
//
if (idx > -1) {
docs.set(idx, dr);
} else {
docs.add(dr);
}
}
}
for (final Iterator<DocRef<ProjectRef>> iterator = docs.iterator(); iterator.hasNext(); ) {
final DocRef<ProjectRef> docRef = iterator.next();
if (docRef == null) {
iterator.remove();
}
}
logger.debug("Got {} metadata documents for: {}", docs.size(), ref);
return new MavenMetadataView(docs, xpath, xml);
}
use of org.commonjava.maven.atlas.ident.ref.ProjectRef in project galley by Commonjava.
the class MavenMetadataReader method readMetadata.
public MavenMetadataView readMetadata(final ProjectRef ref, final List<Transfer> transfers, final EventMetadata eventMetadata) throws GalleyMavenException {
final List<DocRef<ProjectRef>> docs = new ArrayList<>(transfers.size());
// noinspection ConstantConditions
if (transfers != null && !transfers.isEmpty()) {
for (final Transfer transfer : transfers) {
if (transfer == null) {
continue;
}
final DocRef<ProjectRef> dr = new DocRef<>(ref, transfer.getLocation(), xml.parse(transfer, eventMetadata));
docs.add(dr);
}
}
if (docs.isEmpty()) {
return null;
}
return new MavenMetadataView(docs, xpath, xml);
}
Aggregations