Search in sources :

Example 41 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class MavenRepositoryProxyHandler method transferResources.

/**
 * @param connector
 * @param remoteRepository
 * @param tmpResource
 * @param checksumFiles
 * @param url
 * @param remotePath
 * @param resource
 * @param workingDirectory
 * @param repository
 * @throws ProxyException
 * @throws NotModifiedException
 */
@Override
protected void transferResources(ProxyConnector connector, RemoteRepository remoteRepository, StorageAsset tmpResource, StorageAsset[] checksumFiles, String url, String remotePath, StorageAsset resource, Path workingDirectory, ManagedRepository repository) throws ProxyException, NotModifiedException {
    Wagon wagon = null;
    try {
        URI repoUrl = remoteRepository.getLocation();
        String protocol = repoUrl.getScheme();
        NetworkProxy networkProxy = null;
        String proxyId = connector.getProxyId();
        if (StringUtils.isNotBlank(proxyId)) {
            networkProxy = getNetworkProxy(proxyId);
        }
        WagonFactoryRequest wagonFactoryRequest = new WagonFactoryRequest("wagon#" + protocol, remoteRepository.getExtraHeaders());
        if (networkProxy == null) {
            log.warn("No network proxy with id {} found for connector {}->{}", proxyId, connector.getSourceRepository().getId(), connector.getTargetRepository().getId());
        } else {
            wagonFactoryRequest = wagonFactoryRequest.networkProxy(networkProxy);
        }
        wagon = wagonFactory.getWagon(wagonFactoryRequest);
        if (wagon == null) {
            throw new ProxyException("Unsupported target repository protocol: " + protocol);
        }
        boolean connected = connectToRepository(connector, wagon, remoteRepository);
        if (connected) {
            transferArtifact(wagon, remoteRepository, remotePath, resource.getFilePath(), tmpResource);
            // save on connections since md5 is rarely used
            for (StorageAsset checksumFile : checksumFiles) {
                String ext = "." + StringUtils.substringAfterLast(checksumFile.getName(), ".");
                transferChecksum(wagon, remoteRepository, remotePath, resource.getFilePath(), ext, checksumFile.getFilePath());
            }
        }
    } catch (NotModifiedException e) {
        // Do not cache url here.
        throw e;
    } catch (ProxyException e) {
        urlFailureCache.cacheFailure(url);
        throw e;
    } catch (WagonFactoryException e) {
        throw new ProxyException(e.getMessage(), e);
    } finally {
        if (wagon != null) {
            try {
                wagon.disconnect();
            } catch (ConnectionException e) {
                log.warn("Unable to disconnect wagon.", e);
            }
        }
    }
}
Also used : WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) WagonFactoryException(org.apache.archiva.maven.common.proxy.WagonFactoryException) Wagon(org.apache.maven.wagon.Wagon) ProxyException(org.apache.archiva.proxy.base.ProxyException) URI(java.net.URI) NetworkProxy(org.apache.archiva.proxy.model.NetworkProxy) ConnectionException(org.apache.maven.wagon.ConnectionException) NotModifiedException(org.apache.archiva.proxy.base.NotModifiedException)

Example 42 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class CacheFailuresTransferTest method testGetWithCacheFailuresOff.

@Test
public void testGetWithCacheFailuresOff() throws Exception {
    String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
    Path expectedFile = managedDefaultDir.resolve(path);
    setupTestableManagedRepository(path);
    assertNotExistsInManagedDefaultRepo(expectedFile);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    // Configure Repository (usually done within archiva.xml configuration)
    saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default");
    saveRemoteRepositoryConfig("badproxied2", "Bad Proxied 2", "http://bad.machine.com/anotherrepo/", "default");
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    saveConnector(ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    doThrow(new ResourceDoesNotExistException("resource does not exist.")).when(wagonMock).get(eq(path), any());
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    verify(wagonMock, times(2)).get(eq(path), any());
    reset(wagonMock);
    doThrow(new ResourceDoesNotExistException("resource does not exist.")).when(wagonMock).get(eq(path), any());
    downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    verify(wagonMock, times(2)).get(eq(path), any());
    assertNotDownloaded(downloadedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) Test(org.junit.Test)

Example 43 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class CacheFailuresTransferTest method testGetWithCacheFailuresOn.

@Test
public void testGetWithCacheFailuresOn() throws Exception {
    String path = "org/apache/maven/test/get-in-second-proxy/1.0/get-in-second-proxy-1.0.jar";
    Path expectedFile = managedDefaultDir.resolve(path);
    setupTestableManagedRepository(path);
    assertNotExistsInManagedDefaultRepo(expectedFile);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    // ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
    // Configure Repository (usually done within archiva.xml configuration)
    saveRemoteRepositoryConfig("badproxied1", "Bad Proxied 1", "http://bad.machine.com/repo/", "default");
    saveRemoteRepositoryConfig("badproxied2", "Bad Proxied 2", "http://bad.machine.com/anotherrepo/", "default");
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "badproxied1", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false);
    saveConnector(ID_DEFAULT_MANAGED, "badproxied2", ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.YES, false);
    doThrow(new ResourceDoesNotExistException("resource does not exist.")).when(wagonMock).get(eq(path), any());
    // noinspection UnusedAssignment
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    assertNotDownloaded(downloadedFile);
    assertNoTempFiles(expectedFile);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) Test(org.junit.Test)

Example 44 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ChecksumTransferTest method testGetChecksumCorrectSha1BadMd5UsingFailSetting.

@Test
public void testGetChecksumCorrectSha1BadMd5UsingFailSetting() throws Exception {
    String path = "org/apache/maven/test/get-checksum-sha1-bad-md5/1.0/get-checksum-sha1-bad-md5-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.FAIL, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    assertNotDownloaded(downloadedFile);
    assertChecksums(expectedFile, null, null);
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Example 45 with StorageAsset

use of org.apache.archiva.repository.storage.StorageAsset in project archiva by apache.

the class ChecksumTransferTest method testGetChecksumNoSha1CorrectMd5.

@Test
public void testGetChecksumNoSha1CorrectMd5() throws Exception {
    String path = "org/apache/maven/test/get-checksum-md5-only/1.0/get-checksum-md5-only-1.0.jar";
    setupTestableManagedRepository(path);
    Path expectedFile = managedDefaultDir.resolve(path);
    BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout(BaseRepositoryContentLayout.class);
    Artifact artifact = layout.getArtifact(path);
    FileUtils.deleteDirectory(expectedFile.getParent());
    assertFalse(Files.exists(expectedFile));
    // Configure Connector (usually done within archiva.xml configuration)
    saveConnector(ID_DEFAULT_MANAGED, "proxied1", ChecksumPolicy.IGNORE, ReleasesPolicy.ALWAYS, SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO, false);
    StorageAsset downloadedFile = proxyHandler.fetchFromProxies(managedDefaultRepository.getRepository(), artifact);
    Path proxied1File = Paths.get(REPOPATH_PROXIED1, path);
    assertFileEquals(expectedFile, downloadedFile.getFilePath(), proxied1File);
    assertNoTempFiles(expectedFile);
    assertChecksums(expectedFile, null, "f3af5201bf8da801da37db8842846e1c *get-checksum-md5-only-1.0.jar");
}
Also used : Path(java.nio.file.Path) BaseRepositoryContentLayout(org.apache.archiva.repository.content.BaseRepositoryContentLayout) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) Artifact(org.apache.archiva.repository.content.Artifact) Test(org.junit.Test)

Aggregations

StorageAsset (org.apache.archiva.repository.storage.StorageAsset)191 Path (java.nio.file.Path)91 BaseRepositoryContentLayout (org.apache.archiva.repository.content.BaseRepositoryContentLayout)61 IOException (java.io.IOException)59 Test (org.junit.Test)59 Artifact (org.apache.archiva.repository.content.Artifact)54 ManagedRepository (org.apache.archiva.repository.ManagedRepository)27 ArchivaIndexingContext (org.apache.archiva.indexer.ArchivaIndexingContext)22 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)22 List (java.util.List)20 Inject (javax.inject.Inject)20 RepositoryMetadataException (org.apache.archiva.repository.metadata.RepositoryMetadataException)20 Collectors (java.util.stream.Collectors)19 RemoteRepository (org.apache.archiva.repository.RemoteRepository)19 IndexingContext (org.apache.maven.index.context.IndexingContext)19 FilesystemStorage (org.apache.archiva.repository.storage.fs.FilesystemStorage)18 StringUtils (org.apache.commons.lang3.StringUtils)18 Logger (org.slf4j.Logger)18 LoggerFactory (org.slf4j.LoggerFactory)18 Map (java.util.Map)17