use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class TransferManagerImpl method retrieve.
@Override
public Transfer retrieve(final ConcreteResource resource, final boolean suppressFailures, final EventMetadata eventMetadata) throws TransferException {
// logger.info( "Attempting to resolve: {}", resource );
// TODO: Handle the case where storage isn't allowed?
// NOTE: This would expand the notion out from simply:
// "don't allow storing new stuff"
// to:
// "don't ever cache this stuff"
Transfer target = null;
try {
// TODO: (see above re:storing) Handle things like local archives that really don't need to be cached...
target = getCacheReference(resource);
if (target.exists()) {
logger.debug("Using cached copy of: {}", target);
return target;
}
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
if (!resource.allowsDownloading() || (specialPathInfo != null && !specialPathInfo.isRetrievable())) {
logger.debug("Download not allowed for: {}. Returning null transfer.", resource);
return null;
}
final Transfer retrieved = downloader.download(resource, target, getTimeoutSeconds(resource), getTransport(resource), suppressFailures, eventMetadata);
if (retrieved != null && retrieved.exists() && !target.equals(retrieved)) {
if (specialPathInfo == null || specialPathInfo.isCachable()) {
cacheProvider.createAlias(retrieved.getResource(), target.getResource());
}
}
if (target.exists()) {
logger.debug("DOWNLOADED: {}", resource);
return target;
} else {
logger.debug("NOT DOWNLOADED: {}", resource);
return null;
}
} catch (final TransferException e) {
fileEventManager.fire(new FileErrorEvent(target, e, eventMetadata));
throw e;
} catch (final IOException e) {
final TransferException error = new TransferException("Failed to download: {}. Reason: {}", e, resource, e.getMessage());
fileEventManager.fire(new FileErrorEvent(target, error, eventMetadata));
throw error;
}
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class UploadHandler method joinOrStart.
private boolean joinOrStart(final ConcreteResource resource, final int timeoutSeconds, final InputStream stream, final long length, final String contentType, final Transport transport) throws TransferException {
if (transport == null) {
return false;
}
Future<PublishJob> future;
synchronized (pending) {
future = pending.get(resource);
if (future == null) {
final PublishJob job = transport.createPublishJob(resource, stream, length, timeoutSeconds);
future = executor.submit(job);
pending.put(resource, future);
}
}
int waitSeconds = (int) (timeoutSeconds * config.getTimeoutOverextensionFactor());
int tries = 1;
try {
while (tries > 0) {
tries--;
try {
final PublishJob job = future.get(timeoutSeconds, TimeUnit.SECONDS);
if (job.getError() != null) {
throw job.getError();
}
nfc.clearMissing(resource);
return job.isSuccessful();
} catch (final InterruptedException e) {
throw new TransferException("Interrupted publish: {}. Reason: {}", e, resource, e.getMessage());
} catch (final ExecutionException e) {
throw new TransferException("Failed to publish: {}. Reason: {}", e, resource, e.getMessage());
} catch (final TimeoutException e) {
Long size = transferSizes.get(resource);
if (tries > 0) {
continue;
} else if (size != null && size > config.getThresholdWaitRetrySize()) {
logger.debug("Publishing a large file: {}. Retrying Future.get() up to {} times.", size, tries);
tries = (int) (size / config.getWaitRetryScalingIncrement());
continue;
} else {
throw new TransferTimeoutException(resource, "Timed out waiting for execution of: {}", e, resource);
}
} catch (final TransferException e) {
throw e;
} catch (final Exception e) {
throw new TransferException("Failed listing: {}. Reason: {}", e, resource, e.getMessage());
}
}
} finally {
transferSizes.remove(resource);
// logger.info( "Marking download complete: {}", url );
pending.remove(resource);
}
return false;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class SimpleUrlLocationResolver method resolve.
@Override
public final Location resolve(final String spec) throws TransferException {
final Location location = new SimpleLocation(spec);
final List<Location> locations = locationExpander.expand(location);
if (locations == null || locations.isEmpty()) {
throw new TransferException("Invalid location: '%s'. Location expansion returned no results.", spec);
}
for (final Iterator<Location> iterator = new ArrayList<Location>(locations).iterator(); iterator.hasNext(); ) {
final Location loc = iterator.next();
// normally, this will probably throw an exception if no transport is available.
// in case it's not, remove the location if the transport is null.
final Transport transport = transportManager.getTransport(loc);
if (transport == null) {
iterator.remove();
}
}
if (locations == null || locations.isEmpty()) {
throw new TransferException("Invalid location: '%s'. No transports available for expanded locations.", spec);
}
return location;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class MavenPomReader method readLocalPom.
public MavenPomView readLocalPom(final ProjectVersionRef ref, final Transfer transfer, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
DocRef<ProjectVersionRef> dr;
try {
dr = getDocRef(ref, transfer, cache, eventMetadata);
} catch (final TransferException e) {
throw new GalleyMavenException("Failed to parse POM for: {}. Reason: {}", e, ref, e.getMessage());
}
final MavenPomView view = new MavenPomView(ref, Collections.singletonList(dr), xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
logStructure(view);
return view;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class MavenPomReader method read.
public MavenPomView read(final ProjectVersionRef ref, final List<? extends Location> locations, final boolean cache, final EventMetadata eventMetadata, final String... activeProfileIds) throws GalleyMavenException {
final List<DocRef<ProjectVersionRef>> stack = new ArrayList<DocRef<ProjectVersionRef>>();
ProjectVersionRef next = ref;
do {
DocRef<ProjectVersionRef> dr;
try {
dr = getDocRef(next, locations, cache, 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());
} while (next != null);
final MavenPomView view = new MavenPomView(ref, stack, xpath, pluginDefaults, pluginImplications, xml, activeProfileIds);
assembleImportedInformation(view, locations);
logStructure(view);
return view;
}
Aggregations