Search in sources :

Example 6 with VirtualResource

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

the class ArtifactManagerImpl method resolveArtifactMappings.

private void resolveArtifactMappings(final ArtifactBatch batch, final EventMetadata eventMetadata) throws TransferException {
    final Map<ArtifactRef, Resource> resources = new HashMap<ArtifactRef, Resource>(batch.size());
    for (final ArtifactRef artifact : batch) {
        final VirtualResource virt = resolveFirstVirtualResource(batch.getLocations(artifact), artifact, eventMetadata);
        resources.put(artifact, virt);
    }
    batch.setArtifactToResourceMapping(resources);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Resource(org.commonjava.maven.galley.model.Resource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 7 with VirtualResource

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

the class ArtifactMetadataManagerImpl method store.

/* (non-Javadoc)
     * @see org.commonjava.maven.galley.ArtifactMetadataManager#store(org.commonjava.maven.galley.model.Location, java.lang.String, java.lang.String, java.io.InputStream)
     */
@Override
public Transfer store(final Location location, final String groupId, final String filename, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
    final VirtualResource virt = new VirtualResource(expander.expand(location), formatMetadataPath(groupId, filename));
    final ConcreteResource selected = ArtifactRules.selectStorageResource(virt);
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new TransferException("No deployment locations available for: {}", virt.toConcreteResources());
    }
    return transferManager.store(selected, stream, eventMetadata);
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 8 with VirtualResource

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

the class ArtifactMetadataManagerImpl method store.

/* (non-Javadoc)
     * @see org.commonjava.maven.galley.ArtifactMetadataManager#store(org.commonjava.maven.galley.model.Location, org.commonjava.maven.atlas.ident.ref.ProjectRef, java.lang.String, java.io.InputStream)
     */
@Override
public Transfer store(final Location location, final ProjectRef ref, final String filename, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
    final VirtualResource virt = new VirtualResource(expander.expand(location), formatMetadataPath(ref, filename));
    final ConcreteResource selected = ArtifactRules.selectStorageResource(virt);
    if (selected == null) {
        logger.warn("Cannot deploy. No valid deploy points in group.");
        throw new TransferException("No deployment locations available for: {}", virt.toConcreteResources());
    }
    return transferManager.store(selected, stream, eventMetadata);
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) VirtualResource(org.commonjava.maven.galley.model.VirtualResource)

Example 9 with VirtualResource

use of org.commonjava.maven.galley.model.VirtualResource 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<TypeAndClassifier, ConcreteResource>();
    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 = (ConcreteResource) 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)

Example 10 with VirtualResource

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

the class IndyLocationExpander method expand.

/** Using the same basic logic as {@link IndyLocationExpander#expand(Collection)}, convert the specified {@link Resource} into a
     * {@link VirtualResource} that contains references to the expanded {@link Location} list.
     * 
     * @see IndyLocationExpander#expand(Collection)
     */
@Override
public VirtualResource expand(final Resource resource) throws TransferException {
    List<Location> locations;
    if (resource instanceof VirtualResource) {
        final List<ConcreteResource> concrete = ((VirtualResource) resource).toConcreteResources();
        final List<ConcreteResource> result = new ArrayList<ConcreteResource>();
        for (final ConcreteResource cr : concrete) {
            final List<Location> expanded = expand(cr.getLocation());
            for (final Location location : expanded) {
                result.add(new ConcreteResource(location, cr.getPath()));
            }
        }
        return new VirtualResource(result);
    } else {
        final ConcreteResource cr = (ConcreteResource) resource;
        locations = expand(cr.getLocation());
        return new VirtualResource(locations, cr.getPath());
    }
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ArrayList(java.util.ArrayList) VirtualResource(org.commonjava.maven.galley.model.VirtualResource) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) RepositoryLocation(org.commonjava.indy.model.galley.RepositoryLocation) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

VirtualResource (org.commonjava.maven.galley.model.VirtualResource)11 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)8 ArrayList (java.util.ArrayList)4 TransferException (org.commonjava.maven.galley.TransferException)4 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)3 ListingResult (org.commonjava.maven.galley.model.ListingResult)3 Location (org.commonjava.maven.galley.model.Location)3 Resource (org.commonjava.maven.galley.model.Resource)3 LinkedHashMap (java.util.LinkedHashMap)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)2 StoreResource (org.commonjava.indy.content.StoreResource)2 BadGatewayException (org.commonjava.maven.galley.BadGatewayException)2 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)2 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)2 ProjectVersionRefLocation (org.commonjava.maven.galley.maven.model.ProjectVersionRefLocation)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1