use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class ChecksummingTransferDecorator method decorateRead.
@Override
public InputStream decorateRead(final InputStream stream, final Transfer transfer, final EventMetadata eventMetadata) throws IOException {
Object forceObj = eventMetadata.get(FORCE_CHECKSUM);
boolean force = Boolean.TRUE.equals(forceObj) || Boolean.parseBoolean(String.valueOf(forceObj));
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer);
logger.trace("SpecialPathInfo for: {} is: {} (decoratable? {})", transfer, specialPathInfo, (specialPathInfo == null ? true : specialPathInfo.isDecoratable()));
if (force || specialPathInfo == null || specialPathInfo.isDecoratable()) {
ChecksummingDecoratorAdvisor.ChecksumAdvice advice = readerFilter.getDecorationAdvice(transfer, DOWNLOAD, eventMetadata);
if (force && advice == NO_DECORATE) {
advice = CALCULATE_NO_WRITE;
}
boolean consumerNeedsIt = (consumer == null || consumer.needsMetadataFor(transfer));
logger.trace("Advice is: {} for {} of: {} (and consumer is missing or needs it? {})", advice, DOWNLOAD, transfer, consumerNeedsIt);
// 2. if we have a metadata consumer AND the consumer needs metadata for this transfer
if (advice != NO_DECORATE && (consumer == null || consumer.needsMetadataFor(transfer))) {
return new ChecksummingInputStream(checksumFactories, stream, transfer, consumer, advice == CALCULATE_AND_WRITE);
}
}
logger.trace("NOT decorating read with ChecksummingTransferDecorator for: {}", transfer);
return stream;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class ChecksummingTransferDecorator method decorateDelete.
public void decorateDelete(final Transfer transfer, final EventMetadata eventMetadata) throws IOException {
if (transfer.isDirectory()) {
return;
}
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer);
if (specialPathInfo == null || specialPathInfo.isDeletable()) {
for (final AbstractChecksumGeneratorFactory<?> factory : checksumFactories) {
final AbstractChecksumGenerator generator = factory.createGenerator(transfer);
generator.delete();
}
}
if (consumer != null) {
consumer.removeMetadata(transfer);
}
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class ChecksummingTransferDecorator method decorateWrite.
public OutputStream decorateWrite(final OutputStream stream, final Transfer transfer, final TransferOperation op, final EventMetadata eventMetadata) throws IOException {
Object forceObj = eventMetadata.get(FORCE_CHECKSUM);
boolean force = Boolean.TRUE.equals(forceObj) || Boolean.parseBoolean(String.valueOf(forceObj));
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer);
logger.trace("SpecialPathInfo for: {} is: {} (decoratable? {})", transfer, specialPathInfo, (specialPathInfo == null ? true : specialPathInfo.isDecoratable()));
if (force || specialPathInfo == null || specialPathInfo.isDecoratable()) {
ChecksummingDecoratorAdvisor.ChecksumAdvice advice = writerFilter.getDecorationAdvice(transfer, op, eventMetadata);
if (force && advice == NO_DECORATE) {
advice = CALCULATE_NO_WRITE;
}
boolean consumerNeedsIt = (consumer == null || consumer.needsMetadataFor(transfer));
logger.trace("Advice is: {} for {} of: {} (and consumer is missing or needs it? {})", advice, op, transfer, consumerNeedsIt);
// 2. if we have a metadata consumer AND the consumer needs metadata for this transfer
if (advice != NO_DECORATE && (consumer == null || consumer.needsMetadataFor(transfer))) {
logger.trace("Wrapping output stream to: {} for checksum generation.", transfer);
return new ChecksummingOutputStream(checksumFactories, stream, transfer, consumer, advice == CALCULATE_AND_WRITE);
}
}
logger.trace("NOT decorating write with ChecksummingTransferDecorator for: {}", transfer);
return stream;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class SpecialPathManagerImpl method getPathInfo.
private SpecialPathInfo getPathInfo(Location location, String path, Collection<SpecialPathInfo> from) {
SpecialPathInfo firstHit = null;
// Location is not used in current SpecialPathMatcher impl classes, so removed the null check.
if (path != null) {
for (SpecialPathInfo info : from) {
if (info.getMatcher().matches(location, path)) {
if (firstHit != null) {
Logger logger = LoggerFactory.getLogger(getClass());
logger.error("Duplicate special-path registration for: {}:{}. Using: {}", location, path, firstHit);
} else {
firstHit = info;
}
}
}
}
// TODO: Return SpecialPathConstants.DEFAULT_FILE or SpecialPathConstants.DEFAULT_DIR based on path if firstHit is null!
return firstHit;
}
use of org.commonjava.maven.galley.model.SpecialPathInfo in project galley by Commonjava.
the class NoCacheTransferDecorator method decorateRead.
@Override
public InputStream decorateRead(final InputStream stream, final Transfer transfer, final EventMetadata eventMetadata) throws IOException {
SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(transfer, eventMetadata.getPackageType());
logger.trace("SpecialPathInfo for: {} is: {} (cachable? {})", transfer, specialPathInfo, (specialPathInfo == null ? true : specialPathInfo.isCachable()));
if (specialPathInfo != null && !specialPathInfo.isCachable()) {
logger.trace("Decorating read with NoCacheTransferDecorator for: {}", transfer);
return new NoCacheInputStream(stream, transfer);
}
return stream;
}
Aggregations