Search in sources :

Example 21 with ListingResult

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

the class ArtifactManagerImpl method listAvailableArtifacts.

// TODO: This may be incompatible with snapshots, which will have LOTS of entries...
@Override
public Map<TypeAndClassifier, ConcreteResource> listAvailableArtifacts(final Location location, final ProjectVersionRef ref, final EventMetadata metadata) throws TransferException {
    final List<ListingResult> listingResults = transferManager.listAll(new VirtualResource(expander.expand(location), formatArtifactPath(ref.asProjectVersionRef(), mapper)), metadata);
    if (listingResults == null || listingResults.isEmpty()) {
        return Collections.emptyMap();
    }
    final Map<TypeAndClassifier, ConcreteResource> result = new LinkedHashMap<>();
    final String prefix = String.format("%s-%s", ref.getArtifactId(), ref.getVersionString());
    for (final ListingResult listingResult : listingResults) {
        // FIXME: snapshot handling.
        for (final String fname : listingResult.getListing()) {
            if (fname.startsWith(prefix)) {
                final String remainder = fname.substring(prefix.length());
                String classifier = null;
                String type = null;
                if (remainder.startsWith("-")) {
                    // must have a classifier.
                    final int extPos = remainder.indexOf('.');
                    if (extPos < 2) {
                        logger.warn("Listing found unparsable filename: '{}' from: {}. Skipping", fname, location);
                        continue;
                    }
                    classifier = remainder.substring(1, extPos);
                    type = remainder.substring(extPos + 1);
                } else if (remainder.startsWith(".")) {
                    type = remainder.substring(1);
                }
                final ConcreteResource res = listingResult.getResource().getChild(fname);
                result.put(new SimpleTypeAndClassifier(type, classifier), res);
            }
        }
    }
    return result;
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) ListingResult(org.commonjava.maven.galley.model.ListingResult) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ListingResult (org.commonjava.maven.galley.model.ListingResult)21 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)12 TransferException (org.commonjava.maven.galley.TransferException)11 ArrayList (java.util.ArrayList)9 Transfer (org.commonjava.maven.galley.model.Transfer)8 StoreResource (org.commonjava.indy.content.StoreResource)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)7 Test (org.junit.Test)7 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)5 VirtualResource (org.commonjava.maven.galley.model.VirtualResource)5 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)4 IOException (java.io.IOException)3 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)3 Logger (org.slf4j.Logger)3 InputStream (java.io.InputStream)2 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)2 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2