use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class TransferManagerImpl method doDelete.
private Boolean doDelete(final Transfer item, final EventMetadata eventMetadata) throws TransferException {
if (!item.exists()) {
return false;
}
Logger contentLogger = LoggerFactory.getLogger(DELETE_CONTENT_LOG);
contentLogger.info("BEGIN: Delete {} ({})", item.getResource(), eventMetadata);
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(item, eventMetadata.getPackageType());
if (specialPathInfo != null && !specialPathInfo.isDeletable()) {
throw new TransferException("Deleting not allowed for: %s", item);
}
if (item.isDirectory()) {
String[] listing;
try {
listing = item.list();
} catch (final IOException e) {
throw new TransferException("Delete failed: {}. Reason: cannot list directory due to: {}", e, item, e.getMessage());
}
for (final String sub : listing) {
if (!doDelete(item.getChild(sub), eventMetadata)) {
contentLogger.info("FAIL: Delete: {}", item.getResource());
return false;
}
}
} else {
try {
if (!item.delete(true, eventMetadata)) {
throw new TransferException("Failed to delete: {}.", item);
}
} catch (final IOException e) {
throw new TransferException("Failed to delete stored location: {}. Reason: {}", e, item, e.getMessage());
}
}
contentLogger.info("FINISH: Delete: {}", item.getResource());
return true;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class TransferManagerImpl method listAll.
@Override
public List<ListingResult> listAll(final VirtualResource virt, final EventMetadata metadata) throws TransferException {
final Map<ConcreteResource, Future<ListingResult>> futureList = new HashMap<>();
for (final ConcreteResource res : virt) {
final Future<ListingResult> listingFuture = executorService.submit(new Callable<ListingResult>() {
@Override
public ListingResult call() throws TransferException {
return doList(res, true, metadata);
}
});
futureList.put(res, listingFuture);
}
final List<ListingResult> results = new ArrayList<>();
for (Map.Entry<ConcreteResource, Future<ListingResult>> entry : futureList.entrySet()) {
Future<ListingResult> listingFuture = entry.getValue();
ConcreteResource res = entry.getKey();
ListingResult listing;
try {
listing = listingFuture.get();
} catch (InterruptedException ex) {
throw new TransferException("Listing of %s was interrupted", ex, res);
} catch (ExecutionException ex) {
throw new TransferException("Listing of %s threw an error: %s", ex, res, ex);
}
if (listing != null) {
results.add(listing);
}
}
return results;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class TransferManagerImpl method store.
@Override
public Transfer store(final ConcreteResource resource, final InputStream stream, final EventMetadata eventMetadata) throws TransferException {
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(resource, eventMetadata.getPackageType());
if (!resource.allowsStoring() || (specialPathInfo != null && !specialPathInfo.isStorable())) {
throw new TransferException("Storing not allowed for: {}", resource);
}
final Transfer target = getCacheReference(resource);
logger.info("STORE {}", target.getResource());
OutputStream out = null;
try {
out = target.openOutputStream(TransferOperation.UPLOAD, true, eventMetadata);
copy(stream, out);
} catch (final IOException e) {
throw new TransferException("Failed to store: {}. Reason: {}", e, resource, e.getMessage());
} finally {
closeQuietly(out);
}
return target;
}
use of org.commonjava.maven.galley.TransferException in project galley by Commonjava.
the class TransferManagerImpl method doList.
private ListingResult doList(final ConcreteResource resource, final boolean suppressFailures, EventMetadata metadata) throws TransferException {
final Transfer cachedListing = getCacheReference(resource.getChild(".listing.txt"));
Set<String> filenames = new HashSet<String>();
if (cachedListing.exists()) {
InputStream stream = null;
try {
stream = cachedListing.openInputStream();
filenames.addAll(IOUtils.readLines(stream, "UTF-8"));
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Got cached listing:\n\n{}\n\n", filenames);
} catch (final IOException e) {
throw new TransferException("Failed to read listing from cached file: %s. Reason: %s", e, cachedListing, e.getMessage());
} finally {
closeQuietly(stream);
}
} else {
final Transfer cached = getCacheReference(resource);
if (cached.exists()) {
if (cached.isFile()) {
throw new TransferException("Cannot list: {}. It does not appear to be a directory.", resource);
} else {
try {
// This is fairly stupid, but we need to append '/' to the end of directories in the listing so content processors can figure
// out what to do with them.
String[] fnames = cached.list();
if (fnames != null && fnames.length > 0) {
for (String fname : fnames) {
final ConcreteResource child = resource.getChild(fname);
final Transfer childRef = getCacheReference(child);
if (childRef.isFile()) {
filenames.add(fname);
} else {
filenames.add(fname + "/");
}
}
}
} catch (final IOException e) {
throw new TransferException("Listing failed: {}. Reason: {}", e, resource, e.getMessage());
}
}
}
if (resource.getLocation().allowsDownloading()) {
final int timeoutSeconds = getTimeoutSeconds(resource);
Transport transport = getTransport(resource);
final ListingResult remoteResult = lister.list(resource, cachedListing, timeoutSeconds, transport, suppressFailures);
if (remoteResult != null) {
String[] remoteListing = remoteResult.getListing();
if (remoteListing != null) {
final TransferDecorator decorator = cachedListing.getDecorator();
if (decorator != null) {
try {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Un-decorated listing:\n\n{}\n\n", remoteListing);
remoteListing = decorator.decorateListing(cachedListing.getParent(), remoteListing, metadata);
} catch (final IOException e) {
logger.error("Failed to decorate directory listing for: {}. Reason: {}", e, resource, e.getMessage());
remoteListing = null;
}
}
}
if (remoteListing != null) {
if (transport.allowsCaching()) {
OutputStream stream = null;
try {
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Writing listing:\n\n{}\n\nto: {}", remoteListing, cachedListing);
stream = cachedListing.openOutputStream(TransferOperation.DOWNLOAD);
stream.write(join(remoteListing, "\n").getBytes("UTF-8"));
} catch (final IOException e) {
logger.debug("Failed to store directory listing for: {}. Reason: {}", e, resource, e.getMessage());
} finally {
closeQuietly(stream);
}
}
filenames.addAll(Arrays.asList(remoteListing));
}
}
}
}
Logger logger = LoggerFactory.getLogger(getClass());
logger.debug("Listing before non-listable file removal:\n\n{}\n\n", filenames);
List<String> resultingNames = new ArrayList<String>(filenames.size());
for (String fname : filenames) {
ConcreteResource child = resource.getChild(fname);
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(child, metadata.getPackageType());
if (specialPathInfo != null && !specialPathInfo.isListable()) {
continue;
}
resultingNames.add(fname);
}
logger.debug("Final listing result:\n\n{}\n\n", resultingNames);
return new ListingResult(resource, resultingNames.toArray(new String[resultingNames.size()]));
}
use of org.commonjava.maven.galley.TransferException in project indy by Commonjava.
the class ArtifactStoreValidator method isValid.
public boolean isValid(ArtifactStore store) {
if (!(store instanceof RemoteRepository)) {
return true;
}
RemoteRepository remoteRepository = (RemoteRepository) store;
URL url = null;
try {
url = new URL(remoteRepository.getUrl());
ConcreteResource concreteResource = new ConcreteResource(LocationUtils.toLocation(remoteRepository), PathUtils.ROOT);
return transferManager.exists(concreteResource);
} catch (final MalformedURLException e) {
logger.error("[RemoteValidation] Failed to parse repository URL: '{}'. Reason: {}", e, url, e.getMessage());
} catch (final TransferException e) {
logger.warn("[RemoteValidation] Cannot connect to target repository: '{}'. Reason: {}", this, e.getMessage());
logger.debug("[RemoteValidation] exception from validation attempt for: {}", this, e);
}
return false;
}
Aggregations