Search in sources :

Example 6 with SpecialPathInfo

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;
}
Also used : ChecksummingInputStream(org.commonjava.maven.galley.io.checksum.ChecksummingInputStream) ChecksummingDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo)

Example 7 with SpecialPathInfo

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);
    }
}
Also used : SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) AbstractChecksumGenerator(org.commonjava.maven.galley.io.checksum.AbstractChecksumGenerator)

Example 8 with SpecialPathInfo

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;
}
Also used : ChecksummingOutputStream(org.commonjava.maven.galley.io.checksum.ChecksummingOutputStream) ChecksummingDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo)

Example 9 with SpecialPathInfo

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;
}
Also used : SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Logger(org.slf4j.Logger)

Example 10 with SpecialPathInfo

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;
}
Also used : NoCacheInputStream(org.commonjava.maven.galley.io.nocache.NoCacheInputStream) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo)

Aggregations

SpecialPathInfo (org.commonjava.maven.galley.model.SpecialPathInfo)15 Transfer (org.commonjava.maven.galley.model.Transfer)5 Logger (org.slf4j.Logger)5 IOException (java.io.IOException)4 TransferException (org.commonjava.maven.galley.TransferException)4 IndyDataException (org.commonjava.indy.data.IndyDataException)3 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)3 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 PostConstruct (javax.annotation.PostConstruct)2 Inject (javax.inject.Inject)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 StoreType (org.commonjava.indy.model.core.StoreType)2 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)2 ChecksummingDecoratorAdvisor (org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor)2 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)2