Search in sources :

Example 21 with ProjectRef

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);
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) ArrayList(java.util.ArrayList) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) TransferException(org.commonjava.maven.galley.TransferException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Transfer(org.commonjava.maven.galley.model.Transfer) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Location(org.commonjava.maven.galley.model.Location)

Example 22 with ProjectRef

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);
}
Also used : MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef)

Aggregations

ProjectRef (org.commonjava.maven.atlas.ident.ref.ProjectRef)22 SimpleProjectRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectRef)15 HashMap (java.util.HashMap)6 ProjectVersionRef (org.commonjava.maven.atlas.ident.ref.ProjectVersionRef)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 ArtifactRef (org.commonjava.maven.atlas.ident.ref.ArtifactRef)4 SimpleArtifactRef (org.commonjava.maven.atlas.ident.ref.SimpleArtifactRef)4 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)4 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 GalleyMavenException (org.commonjava.maven.galley.maven.GalleyMavenException)3 Set (java.util.Set)2 Model (org.apache.maven.model.Model)2 Profile (org.apache.maven.model.Profile)2 InvalidRefException (org.commonjava.maven.atlas.ident.ref.InvalidRefException)2 SimpleProjectVersionRef (org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 Project (org.commonjava.maven.ext.common.model.Project)2