Search in sources :

Example 1 with RemoteRepositoryContent

use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.

the class DefaultRepositoryProxyConnectors method fetchFromProxies.

@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, ArtifactReference artifact) throws ProxyDownloadException {
    Path localFile = toLocalFile(repository, artifact);
    Properties requestProperties = new Properties();
    requestProperties.setProperty("filetype", "artifact");
    requestProperties.setProperty("version", artifact.getVersion());
    requestProperties.setProperty("managedRepositoryId", repository.getId());
    List<ProxyConnector> connectors = getProxyConnectors(repository);
    Map<String, Exception> previousExceptions = new LinkedHashMap<>();
    for (ProxyConnector connector : connectors) {
        if (connector.isDisabled()) {
            continue;
        }
        RemoteRepositoryContent targetRepository = connector.getTargetRepository();
        requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
        String targetPath = targetRepository.toPath(artifact);
        if (SystemUtils.IS_OS_WINDOWS) {
            // toPath use system PATH_SEPARATOR so on windows url are \ which doesn't work very well :-)
            targetPath = FilenameUtils.separatorsToUnix(targetPath);
        }
        try {
            Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, true);
            if (fileExists(downloadedFile)) {
                log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
                return downloadedFile;
            }
        } catch (NotFoundException e) {
            log.debug("Artifact {} not found on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
        } catch (NotModifiedException e) {
            log.debug("Artifact {} not updated on repository \"{}\".", Keys.toKey(artifact), targetRepository.getRepository().getId());
        } catch (ProxyException | RepositoryAdminException e) {
            validatePolicies(this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact, targetRepository, localFile, e, previousExceptions);
        }
    }
    if (!previousExceptions.isEmpty()) {
        throw new ProxyDownloadException("Failures occurred downloading from some remote repositories", previousExceptions);
    }
    log.debug("Exhausted all target repositories, artifact {} not found.", Keys.toKey(artifact));
    return null;
}
Also used : Path(java.nio.file.Path) Properties(java.util.Properties) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) TaskQueueException(org.apache.archiva.redback.components.taskqueue.TaskQueueException) PolicyConfigurationException(org.apache.archiva.policies.PolicyConfigurationException) WagonFactoryException(org.apache.archiva.proxy.common.WagonFactoryException) FileLockException(org.apache.archiva.common.filelock.FileLockException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ConnectionException(org.apache.maven.wagon.ConnectionException) ProxyDownloadException(org.apache.archiva.policies.ProxyDownloadException) FileLockTimeoutException(org.apache.archiva.common.filelock.FileLockTimeoutException) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) IOException(java.io.IOException) PolicyViolationException(org.apache.archiva.policies.PolicyViolationException) WagonException(org.apache.maven.wagon.WagonException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) LinkedHashMap(java.util.LinkedHashMap) RemoteRepositoryContent(org.apache.archiva.repository.RemoteRepositoryContent) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector)

Example 2 with RemoteRepositoryContent

use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.

the class DefaultRepositoryProxyConnectors method fetchMetadataFromProxies.

@Override
public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath) {
    Path localFile = Paths.get(repository.getRepoRoot(), logicalPath);
    Properties requestProperties = new Properties();
    requestProperties.setProperty("filetype", "metadata");
    boolean metadataNeedsUpdating = false;
    long originalTimestamp = getLastModified(localFile);
    List<ProxyConnector> connectors = new ArrayList<>(getProxyConnectors(repository));
    for (ProxyConnector connector : connectors) {
        if (connector.isDisabled()) {
            continue;
        }
        RemoteRepositoryContent targetRepository = connector.getTargetRepository();
        Path localRepoFile = toLocalRepoFile(repository, targetRepository, logicalPath);
        long originalMetadataTimestamp = getLastModified(localRepoFile);
        try {
            transferFile(connector, targetRepository, logicalPath, repository, localRepoFile, requestProperties, true);
            if (hasBeenUpdated(localRepoFile, originalMetadataTimestamp)) {
                metadataNeedsUpdating = true;
            }
        } catch (NotFoundException e) {
            log.debug("Metadata {} not found on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
        } catch (NotModifiedException e) {
            log.debug("Metadata {} not updated on remote repository '{}'.", logicalPath, targetRepository.getRepository().getId(), e);
        } catch (ProxyException | RepositoryAdminException e) {
            log.warn("Transfer error from repository {} for versioned Metadata {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), logicalPath, e.getMessage());
            log.debug("Full stack trace", e);
        }
    }
    if (hasBeenUpdated(localFile, originalTimestamp)) {
        metadataNeedsUpdating = true;
    }
    if (metadataNeedsUpdating || !Files.exists(localFile)) {
        try {
            metadataTools.updateMetadata(repository, logicalPath);
        } catch (RepositoryMetadataException e) {
            log.warn("Unable to update metadata {}:{}", localFile.toAbsolutePath(), e.getMessage(), e);
        }
    }
    if (fileExists(localFile)) {
        return new ProxyFetchResult(localFile, metadataNeedsUpdating);
    }
    return new ProxyFetchResult(null, false);
}
Also used : Path(java.nio.file.Path) ProxyFetchResult(org.apache.archiva.proxy.model.ProxyFetchResult) ArrayList(java.util.ArrayList) Properties(java.util.Properties) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryMetadataException(org.apache.archiva.repository.metadata.RepositoryMetadataException) RemoteRepositoryContent(org.apache.archiva.repository.RemoteRepositoryContent) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector)

Example 3 with RemoteRepositoryContent

use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.

the class DefaultRepositoryProxyConnectors method fetchFromProxies.

@Override
public Path fetchFromProxies(ManagedRepositoryContent repository, String path) {
    Path localFile = Paths.get(repository.getRepoRoot(), path);
    // no update policies for these paths
    if (Files.exists(localFile)) {
        return null;
    }
    Properties requestProperties = new Properties();
    requestProperties.setProperty("filetype", "resource");
    requestProperties.setProperty("managedRepositoryId", repository.getId());
    List<ProxyConnector> connectors = getProxyConnectors(repository);
    for (ProxyConnector connector : connectors) {
        if (connector.isDisabled()) {
            continue;
        }
        RemoteRepositoryContent targetRepository = connector.getTargetRepository();
        requestProperties.setProperty("remoteRepositoryId", targetRepository.getId());
        String targetPath = path;
        try {
            Path downloadedFile = transferFile(connector, targetRepository, targetPath, repository, localFile, requestProperties, false);
            if (fileExists(downloadedFile)) {
                log.debug("Successfully transferred: {}", downloadedFile.toAbsolutePath());
                return downloadedFile;
            }
        } catch (NotFoundException e) {
            log.debug("Resource {} not found on repository \"{}\".", path, targetRepository.getRepository().getId());
        } catch (NotModifiedException e) {
            log.debug("Resource {} not updated on repository \"{}\".", path, targetRepository.getRepository().getId());
        } catch (ProxyException e) {
            log.warn("Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage());
            log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository \"{}" + "\" for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage(), e);
        } catch (RepositoryAdminException e) {
            log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}", targetRepository.getRepository().getId(), path, e.getMessage(), e);
            log.debug(MarkerFactory.getDetachedMarker("transfer.error"), "Full stack trace", e);
        }
    }
    log.debug("Exhausted all target repositories, resource {} not found.", path);
    return null;
}
Also used : Path(java.nio.file.Path) RemoteRepositoryContent(org.apache.archiva.repository.RemoteRepositoryContent) ProxyConnector(org.apache.archiva.proxy.model.ProxyConnector) Properties(java.util.Properties) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 4 with RemoteRepositoryContent

use of org.apache.archiva.repository.RemoteRepositoryContent in project archiva by apache.

the class MetadataToolsTest method testGetRepositorySpecificName.

@Test
public void testGetRepositorySpecificName() throws Exception {
    RemoteRepositoryContent repoJavaNet = createRemoteRepositoryContent("maven2-repository.dev.java.net", "Java.net Repository for Maven 2", "http://download.java.net/maven/2/", "default");
    RemoteRepositoryContent repoCentral = createRemoteRepositoryContent("central", "Central Global Repository", "http://repo1.maven.org/maven2/", "default");
    String convertedName = tools.getRepositorySpecificName(repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml");
    assertMetadataPath("commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml", convertedName);
    convertedName = tools.getRepositorySpecificName(repoCentral, "commons-lang/commons-lang/maven-metadata.xml");
    assertMetadataPath("commons-lang/commons-lang/maven-metadata-central.xml", convertedName);
}
Also used : RemoteRepositoryContent(org.apache.archiva.repository.RemoteRepositoryContent) Test(org.junit.Test)

Aggregations

RemoteRepositoryContent (org.apache.archiva.repository.RemoteRepositoryContent)4 Path (java.nio.file.Path)3 Properties (java.util.Properties)3 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 ProxyConnector (org.apache.archiva.proxy.model.ProxyConnector)3 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 FileLockException (org.apache.archiva.common.filelock.FileLockException)1 FileLockTimeoutException (org.apache.archiva.common.filelock.FileLockTimeoutException)1 PolicyConfigurationException (org.apache.archiva.policies.PolicyConfigurationException)1 PolicyViolationException (org.apache.archiva.policies.PolicyViolationException)1 ProxyDownloadException (org.apache.archiva.policies.ProxyDownloadException)1 WagonFactoryException (org.apache.archiva.proxy.common.WagonFactoryException)1 ProxyFetchResult (org.apache.archiva.proxy.model.ProxyFetchResult)1 TaskQueueException (org.apache.archiva.redback.components.taskqueue.TaskQueueException)1 ConnectionException (org.apache.maven.wagon.ConnectionException)1 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)1 WagonException (org.apache.maven.wagon.WagonException)1