use of org.commonjava.maven.galley.spi.io.TransferDecorator in project galley by Commonjava.
the class PartyLineCacheProviderTest method setup.
@Before
public void setup() throws Exception {
final PathGenerator pathgen = new HashedLocationPathGenerator();
final FileEventManager events = new TestFileEventManager();
final TransferDecorator decorator = new TestTransferDecorator();
provider = new PartyLineCacheProvider(temp.newFolder(), pathgen, events, decorator);
}
use of org.commonjava.maven.galley.spi.io.TransferDecorator in project indy by Commonjava.
the class DefaultGalleyStorageProvider method setupTransferDecoratorPipeline.
/**
* The order is important. We put the checksum decorator at the last because some decorators may change the content.
*/
private void setupTransferDecoratorPipeline() {
List<TransferDecorator> decorators = new ArrayList<>();
decorators.add(new IOLatencyDecorator(timerProviderFunction(), meterProvider(), cumulativeTimer()));
decorators.add(new NoCacheTransferDecorator(specialPathManager));
decorators.add(new UploadMetadataGenTransferDecorator(specialPathManager, timerProviderFunction()));
for (TransferDecorator decorator : transferDecorators) {
decorators.add(decorator);
}
decorators.add(getChecksummingTransferDecorator());
if (featureConfig.getFileChangeTracking()) {
decorators.add(new FileChangeTrackingDecorator(config));
}
transferDecorator = new TransferDecoratorManager(decorators);
}
use of org.commonjava.maven.galley.spi.io.TransferDecorator in project galley by Commonjava.
the class TransferDecoratorPipeline method decorateRead.
@Override
public InputStream decorateRead(final InputStream stream, final Transfer transfer, final EventMetadata metadata) throws IOException {
Logger logger = LoggerFactory.getLogger(getClass());
InputStream result = stream;
for (TransferDecorator decorator : decorators) {
logger.debug("Decorating: {} using decorator: {}", result.getClass().getName(), decorator.getClass().getName());
result = decorator.decorateRead(result, transfer, metadata);
}
logger.debug("Returning: {}", result.getClass().getName());
return result;
}
use of org.commonjava.maven.galley.spi.io.TransferDecorator in project galley by Commonjava.
the class GridFileSystemCacheProviderTest method setup.
@Before
public void setup() throws Exception {
final PathGenerator pathgen = new HashedLocationPathGenerator();
final FileEventManager events = new TestFileEventManager();
final TransferDecorator decorator = new TestTransferDecorator();
Cache<String, byte[]> data = CACHE_MANAGER.getCache(name.getMethodName() + "-data");
Cache<String, GridFile.Metadata> metadata = CACHE_MANAGER.getCache(name.getMethodName() + "-metadata");
final GridFilesystem fs = new GridFilesystem(data, metadata);
provider = new GridFileSystemCacheProvider(pathgen, events, decorator, fs);
}
use of org.commonjava.maven.galley.spi.io.TransferDecorator 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<>();
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) {
// this will avoid some package.json redirect path empty errors, especially for the group.
if (metadata.get(STORAGE_PATH) != null) {
filenames.add(fname);
continue;
}
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 && remoteListing.length > 0) {
final TransferDecorator decorator = cachedListing.getDecorator();
if (decorator != null) {
try {
Logger logger = LoggerFactory.getLogger(getClass());
// noinspection ConfusingArgumentToVarargsMethod
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 && remoteListing.length > 0) {
if (transport != null && 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<>(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()]));
}
Aggregations