Search in sources :

Example 1 with ChecksumValidationException

use of org.apache.archiva.checksum.ChecksumValidationException in project archiva by apache.

the class ValidateChecksumConsumer method processFile.

@Override
public void processFile(String path) throws ConsumerException {
    Path checksumFile = this.repositoryDir.resolve(path);
    try {
        ChecksumReference cf = ChecksummedFile.getFromChecksumFile(checksumFile);
        if (!cf.getFile().isValidChecksum(cf.getAlgorithm(), true)) {
            log.warn("The checksum for {} is invalid.", checksumFile);
            triggerConsumerWarning(NOT_VALID_CHECKSUM, "The checksum for " + checksumFile + " is invalid.");
        }
    } catch (ChecksumValidationException e) {
        if (e.getErrorType() == READ_ERROR) {
            log.error("Checksum read error during validation on {}", checksumFile);
            triggerConsumerError(CHECKSUM_IO_ERROR, "Checksum I/O error during validation on " + checksumFile);
        } else if (e.getErrorType() == INVALID_FORMAT || e.getErrorType() == DIGEST_ERROR) {
            log.error("Digester failure during checksum validation on {}", checksumFile);
            triggerConsumerError(CHECKSUM_DIGESTER_FAILURE, "Digester failure during checksum validation on " + checksumFile);
        } else if (e.getErrorType() == FILE_NOT_FOUND) {
            log.error("File not found during checksum validation: ", e);
            triggerConsumerError(CHECKSUM_NOT_FOUND, "File not found during checksum validation: " + e.getMessage());
        }
    }
}
Also used : Path(java.nio.file.Path) ChecksumValidationException(org.apache.archiva.checksum.ChecksumValidationException) ChecksumReference(org.apache.archiva.checksum.ChecksumReference)

Example 2 with ChecksumValidationException

use of org.apache.archiva.checksum.ChecksumValidationException in project archiva by apache.

the class LegacyToDefaultConverter method verifyChecksum.

private boolean verifyChecksum(Path file, String fileName, ChecksumAlgorithm digester, Artifact artifact, String key) throws IOException {
    boolean result;
    Path checksumFile = file.resolveSibling(fileName);
    // We ignore the check, if the checksum file does not exist
    if (!Files.exists(checksumFile)) {
        return true;
    }
    ChecksummedFile csFile = new ChecksummedFile(file);
    try {
        result = csFile.isValidChecksum(digester, true);
    } catch (ChecksumValidationException e) {
        addWarning(artifact, Messages.getString(key));
        result = false;
    }
    return result;
}
Also used : Path(java.nio.file.Path) ChecksummedFile(org.apache.archiva.checksum.ChecksummedFile) ChecksumValidationException(org.apache.archiva.checksum.ChecksumValidationException)

Aggregations

Path (java.nio.file.Path)2 ChecksumValidationException (org.apache.archiva.checksum.ChecksumValidationException)2 ChecksumReference (org.apache.archiva.checksum.ChecksumReference)1 ChecksummedFile (org.apache.archiva.checksum.ChecksummedFile)1