Search in sources :

Example 31 with TransferException

use of org.commonjava.maven.galley.TransferException 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<DocRef<ProjectRef>>(locations.size());
    final Map<Location, DocRef<ProjectRef>> cached = getAllCached(ref, locations);
    final List<? extends Location> toRetrieve = new ArrayList<Location>(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));
    if (transfers != null && !transfers.isEmpty()) {
        for (final Transfer transfer : transfers) {
            final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(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) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) 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 32 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class MavenPomReader method read.

public MavenPomView read(final ProjectVersionRef ref, final Transfer pom, final List<? extends Location> locations, final EventMetadata eventMetadata, final String... activeProfileLocations) throws GalleyMavenException {
    final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
    DocRef<ProjectVersionRef> dr;
    try {
        dr = getDocRef(ref, pom, false, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, ref, stack.size(), ref, e.getMessage());
    }
    stack.add(dr);
    ProjectVersionRef next = xml.getParentRef(dr.getDoc());
    while (next != null && dr != null) {
        try {
            dr = getDocRef(next, locations, false, eventMetadata);
        } catch (final TransferException e) {
            throw new GalleyMavenException("Failed to retrieve POM for: {}, {} levels deep in ancestry stack of: {}. Reason: {}", e, next, stack.size(), ref, e.getMessage());
        }
        if (dr == null) {
            throw new GalleyMavenException("Cannot resolve {}, {} levels dep in the ancestry stack of: {}", next, stack.size(), ref);
        }
        stack.add(dr);
        next = xml.getParentRef(dr.getDoc());
    }
    final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileLocations);
    assembleImportedInformation(view, locations);
    logStructure(view);
    return view;
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenPomView(org.commonjava.maven.galley.maven.model.view.MavenPomView)

Example 33 with TransferException

use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.

the class TestTransport method createDownloadJob.

// Transport implementation...
@Override
public DownloadJob createDownloadJob(final ConcreteResource resource, final Transfer target, final Map<Transfer, Long> transferSizes, final int timeoutSeconds, final EventMetadata eventMetadata) throws TransferException {
    final TestDownload job = downloads.get(resource);
    logger.info("Download for: {} is: {}", resource, job);
    if (job == null) {
        throw new TransferException("No download registered for the endpoint: {}", resource);
    }
    job.setTransfer(target);
    job.setEventMetadata(eventMetadata);
    return job;
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) TransferException(org.commonjava.maven.galley.TransferException)

Example 34 with TransferException

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

the class ProxyResponseWriter method transfer.

private void transfer(final HttpConduitWrapper http, final RemoteRepository repo, final String path, final boolean writeBody, final UserPass proxyUserPass) throws IOException, IndyWorkflowException {
    if (transferred) {
        return;
    }
    transferred = true;
    if (!http.isOpen()) {
        throw new IOException("Sink channel already closed (or null)!");
    }
    final EventMetadata eventMetadata = createEventMetadata(writeBody, proxyUserPass, path, repo);
    Transfer txfr = null;
    try {
        txfr = contentController.get(repo.getKey(), path, eventMetadata);
    } catch (final IndyWorkflowException e) {
        // block TransferException to allow handling below.
        if (!(e.getCause() instanceof TransferException)) {
            throw e;
        }
        logger.debug("Suppressed exception for further handling inside proxy logic:", e);
    }
    if (txfr != null && txfr.exists()) {
        http.writeExistingTransfer(txfr, writeBody, path, eventMetadata);
    } else {
        http.writeNotFoundTransfer(repo, path);
    }
}
Also used : TransferException(org.commonjava.maven.galley.TransferException) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 35 with TransferException

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

the class IndyLocationExpander method expand.

/**
     * For group references, expand into a list of concrete repository locations (hosted or remote). For remote repository references that are 
     * specified as cache-only locations (see: {@link CacheOnlyLocation}), lookup the corresponding {@link RemoteRepository} and use it to create a
     * {@link RepositoryLocation} that contains any relevant SSL, authentication, proxy, etc. attbributes.
     */
@Override
public <T extends Location> List<Location> expand(final Collection<T> locations) throws TransferException {
    final List<Location> result = new ArrayList<Location>();
    for (final Location location : locations) {
        if (location instanceof GroupLocation) {
            final GroupLocation gl = (GroupLocation) location;
            try {
                logger.debug("Expanding group: {}", gl.getKey());
                final List<ArtifactStore> members = data.query().packageType(gl.getKey().getPackageType()).getOrderedConcreteStoresInGroup(gl.getKey().getName());
                if (members != null) {
                    for (final ArtifactStore member : members) {
                        if (!result.contains(member)) {
                            logger.debug("expansion += {}", member.getKey());
                            result.add(LocationUtils.toLocation(member));
                        }
                    }
                    logger.debug("Expanded group: {} to:\n  {}", gl.getKey(), new JoinString("\n  ", result));
                }
            } catch (final IndyDataException e) {
                throw new TransferException("Failed to lookup ordered concrete artifact stores contained in group: {}. Reason: {}", e, gl, e.getMessage());
            }
        } else if (location instanceof CacheOnlyLocation && !((CacheOnlyLocation) location).isHostedRepository()) {
            final StoreKey key = ((KeyedLocation) location).getKey();
            try {
                final ArtifactStore store = data.getArtifactStore(key);
                if (store == null) {
                    throw new TransferException("Cannot find ArtifactStore to match key: %s.", key);
                }
                logger.debug("Adding single store: {} for location: {}", store, location);
                result.add(LocationUtils.toLocation(store));
            } catch (final IndyDataException e) {
                throw new TransferException("Failed to lookup store for key: {}. Reason: {}", e, key, e.getMessage());
            }
        } else {
            logger.debug("No expansion available for location: {}", location);
            result.add(location);
        }
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) TransferException(org.commonjava.maven.galley.TransferException) GroupLocation(org.commonjava.indy.model.galley.GroupLocation) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) CacheOnlyLocation(org.commonjava.indy.model.galley.CacheOnlyLocation) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) 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

TransferException (org.commonjava.maven.galley.TransferException)49 IOException (java.io.IOException)17 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 Transfer (org.commonjava.maven.galley.model.Transfer)12 ArrayList (java.util.ArrayList)9 TransferLocationException (org.commonjava.maven.galley.TransferLocationException)9 TransferTimeoutException (org.commonjava.maven.galley.TransferTimeoutException)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 OutputStream (java.io.OutputStream)7 ListingResult (org.commonjava.maven.galley.model.ListingResult)7 InputStream (java.io.InputStream)6 Location (org.commonjava.maven.galley.model.Location)6 File (java.io.File)5 HashMap (java.util.HashMap)5 JarFile (java.util.jar.JarFile)5 ZipEntry (java.util.zip.ZipEntry)5 ZipFile (java.util.zip.ZipFile)5 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)5 Test (org.junit.Test)5 ExecutionException (java.util.concurrent.ExecutionException)4