Search in sources :

Example 1 with NotFoundException

use of org.apache.archiva.proxy.base.NotFoundException in project archiva by apache.

the class MavenRepositoryProxyHandler method transferSimpleFile.

/**
 * Perform the transfer of the remote file to the local file specified.
 *
 * @param wagon            the wagon instance to use.
 * @param remoteRepository the remote repository to use
 * @param remotePath       the remote path to attempt to get
 * @param origFile         the local file to save to
 * @throws ProxyException if there was a problem moving the downloaded file into place.
 */
protected void transferSimpleFile(Wagon wagon, RemoteRepository remoteRepository, String remotePath, Path origFile, Path destFile) throws ProxyException {
    assert (remotePath != null);
    // Transfer the file.
    try {
        if (!Files.exists(origFile)) {
            log.debug("Retrieving {} from {}", remotePath, remoteRepository.getId());
            wagon.get(addParameters(remotePath, remoteRepository), destFile.toFile());
            // You wouldn't get here on failure, a WagonException would have been thrown.
            log.debug("Downloaded successfully.");
        } else {
            boolean success;
            log.debug("Retrieving {} from {} if updated", remotePath, remoteRepository.getId());
            try {
                success = wagon.getIfNewer(addParameters(remotePath, remoteRepository), destFile.toFile(), Files.getLastModifiedTime(origFile).toMillis());
            } catch (IOException e) {
                throw new ProxyException("Failed to the modification time of " + origFile.toAbsolutePath());
            }
            if (!success) {
                throw new NotModifiedException("Not downloaded, as local file is newer than remote side: " + origFile.toAbsolutePath());
            }
            if (Files.exists(destFile)) {
                log.debug("Downloaded successfully.");
            }
        }
    } catch (ResourceDoesNotExistException e) {
        throw new NotFoundException("Resource [" + remoteRepository.getLocation() + "/" + remotePath + "] does not exist: " + e.getMessage(), e);
    } catch (WagonException e) {
        // TODO: shouldn't have to drill into the cause, but TransferFailedException is often not descriptive enough
        String msg = "Download failure on resource [" + remoteRepository.getLocation() + "/" + remotePath + "]:" + e.getMessage();
        if (e.getCause() != null) {
            msg += " (cause: " + e.getCause() + ")";
        }
        throw new ProxyException(msg, e);
    }
}
Also used : NotFoundException(org.apache.archiva.proxy.base.NotFoundException) IOException(java.io.IOException) ProxyException(org.apache.archiva.proxy.base.ProxyException) WagonException(org.apache.maven.wagon.WagonException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) NotModifiedException(org.apache.archiva.proxy.base.NotModifiedException)

Aggregations

IOException (java.io.IOException)1 NotFoundException (org.apache.archiva.proxy.base.NotFoundException)1 NotModifiedException (org.apache.archiva.proxy.base.NotModifiedException)1 ProxyException (org.apache.archiva.proxy.base.ProxyException)1 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)1 WagonException (org.apache.maven.wagon.WagonException)1