Search in sources :

Example 31 with ProxyConnectorConfiguration

use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.

the class RemoteRepositoryHandler method removeRepositoryConfiguration.

@Override
protected void removeRepositoryConfiguration(Configuration configuration, RemoteRepositoryConfiguration repoConfiguration) {
    configuration.removeRemoteRepository(repoConfiguration);
    List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(configuration.getProxyConnectors());
    for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
        if (StringUtils.equals(proxyConnector.getTargetRepoId(), repoConfiguration.getId())) {
            configuration.removeProxyConnector(proxyConnector);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration)

Example 32 with ProxyConnectorConfiguration

use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.

the class AbstractProxyTestCase method setUp.

@Before
public void setUp() throws Exception {
    config = (MockConfiguration) applicationContext.getBean("archivaConfiguration#mock", ArchivaConfiguration.class);
    config.getConfiguration().setManagedRepositories(new ArrayList<ManagedRepositoryConfiguration>());
    config.getConfiguration().setRemoteRepositories(new ArrayList<RemoteRepositoryConfiguration>());
    config.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>());
    ArchivaRuntimeConfiguration runtimeConfiguration = new ArchivaRuntimeConfiguration();
    List<String> checksumTypes = new ArrayList<>();
    checksumTypes.add("md5");
    checksumTypes.add("sha256");
    checksumTypes.add("sha1");
    checksumTypes.add("asc");
    runtimeConfiguration.setChecksumTypes(checksumTypes);
    config.getConfiguration().setArchivaRuntimeConfiguration(runtimeConfiguration);
    repositoryRegistry.setArchivaConfiguration(config);
    // Setup source repository (using default layout)
    String name = getClass().getSimpleName();
    Path repoPath = Paths.get("target/test-repository/managed/" + name);
    managedDefaultRepository = createRepository(ID_DEFAULT_MANAGED, "Default Managed Repository", repoPath.toString(), "default");
    managedDefaultDir = repoPath.resolve(ID_DEFAULT_MANAGED);
    org.apache.archiva.repository.ManagedRepository repoConfig = repositoryRegistry.getManagedRepository(ID_DEFAULT_MANAGED);
    // Setup target (proxied to) repository.
    saveRemoteRepositoryConfig(ID_PROXIED1, "Proxied Repository 1", Paths.get(REPOPATH_PROXIED1).toUri().toURL().toExternalForm(), "default");
    // Setup target (proxied to) repository.
    saveRemoteRepositoryConfig(ID_PROXIED2, "Proxied Repository 2", Paths.get(REPOPATH_PROXIED2).toUri().toURL().toExternalForm(), "default");
    repositoryRegistry.reload();
    repositoryRegistry.putRepository(repoConfig);
    // Setup the proxy handler.
    // proxyHandler = applicationContext.getBean (RepositoryProxyHandler) lookup( RepositoryProxyHandler.class.getName() );
    proxyHandler = applicationContext.getBean("repositoryProxyHandler#test", RepositoryProxyHandler.class);
    assertNotNull(proxyRegistry);
    assertTrue(proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).contains(proxyHandler));
    // Setup the wagon mock.
    wagonMock = mock(Wagon.class);
    delegate = (WagonDelegate) applicationContext.getBean("wagon#http", Wagon.class);
    delegate.setDelegate(wagonMock);
    log.info("\n.\\ {}() \\._________________________________________\n", name);
}
Also used : Path(java.nio.file.Path) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Wagon(org.apache.maven.wagon.Wagon) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ArchivaRuntimeConfiguration(org.apache.archiva.configuration.model.ArchivaRuntimeConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryProxyHandler(org.apache.archiva.proxy.model.RepositoryProxyHandler) Before(org.junit.Before)

Example 33 with ProxyConnectorConfiguration

use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    c = new Configuration();
    testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    testRepo.setReleases(true);
    testRepo.setSnapshots(false);
    c.addManagedRepository(testRepo);
    testRepoS = new ManagedRepositoryConfiguration();
    testRepoS.setId(TEST_SNAP_REPO_ID);
    testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
    testRepoS.setReleases(false);
    testRepoS.setSnapshots(true);
    c.addManagedRepository(testRepoS);
    RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
    testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
    testRemoteRepo.setLayout("default");
    testRemoteRepo.setName("Central Repository");
    testRemoteRepo.setUrl("http://central.repo.com/maven2");
    testRemoteRepo.setTimeout(10);
    c.addRemoteRepository(testRemoteRepo);
    ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
    proxyConnector.setSourceRepoId(TEST_REPO_ID);
    proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnector.setDisabled(false);
    c.addProxyConnector(proxyConnector);
    ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
    proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
    proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnectors.setDisabled(false);
    c.addProxyConnector(proxyConnectors);
    List<String> repos = new ArrayList<>();
    repos.add(TEST_REPO_ID);
    repos.add(TEST_SNAP_REPO_ID);
    RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
    repoGroup.setId(TEST_REPO_GROUP_ID);
    repoGroup.setRepositories(repos);
    c.addRepositoryGroup(repoGroup);
    configuration.save(c);
    repositoryRegistry.reload();
    assertFalse(c.getManagedRepositories().get(0).isSnapshots());
    assertTrue(c.getManagedRepositories().get(0).isReleases());
    assertTrue(c.getManagedRepositories().get(1).isSnapshots());
    assertFalse(c.getManagedRepositories().get(1).isReleases());
    wagonFactory = mock(WagonFactory.class);
    storage.setWagonFactory(wagonFactory);
    Wagon wagon = new MockWagon();
    when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Example 34 with ProxyConnectorConfiguration

use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411Test method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    c = new Configuration();
    testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    testRepo.setReleases(true);
    testRepo.setSnapshots(true);
    c.addManagedRepository(testRepo);
    RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
    testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
    testRemoteRepo.setLayout("default");
    testRemoteRepo.setName("Central Repository");
    testRemoteRepo.setUrl("http://central.repo.com/maven2");
    testRemoteRepo.setTimeout(10);
    c.addRemoteRepository(testRemoteRepo);
    ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
    proxyConnector.setSourceRepoId(TEST_REPO_ID);
    proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnector.setDisabled(false);
    c.addProxyConnector(proxyConnector);
    configuration.save(c);
    repositoryRegistry.reload();
    assertTrue(c.getManagedRepositories().get(0).isSnapshots());
    assertTrue(c.getManagedRepositories().get(0).isReleases());
    wagonFactory = mock(WagonFactory.class);
    assertNotNull(storage);
    storage.setWagonFactory(wagonFactory);
    Wagon wagon = new MockWagon();
    when(wagonFactory.getWagon(new WagonFactoryRequest("wagon#http", new HashMap<String, String>()))).thenReturn(wagon);
}
Also used : WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) HashMap(java.util.HashMap) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Example 35 with ProxyConnectorConfiguration

use of org.apache.archiva.configuration.model.ProxyConnectorConfiguration in project archiva by apache.

the class RepositoryServletProxiedReleasePolicyTest method assertGetProxiedReleaseArtifactWithPolicy.

private void assertGetProxiedReleaseArtifactWithPolicy(int expectation, PolicyOption releasePolicy, boolean hasManagedCopy, long deltaManagedToRemoteTimestamp) throws Exception {
    // --- Setup
    setupCentralRemoteRepo();
    setupCleanInternalRepo();
    saveConfiguration();
    String resourcePath = "org/apache/archiva/test/1.0/test-1.0.jar";
    String expectedRemoteContents = "archiva-test-1.0|jar-remote-contents";
    String expectedManagedContents = null;
    Path remoteFile = populateRepo(remoteCentral, resourcePath, expectedRemoteContents);
    if (hasManagedCopy) {
        expectedManagedContents = "archiva-test-1.0|jar-managed-contents";
        Path managedFile = populateRepo(repoRootInternal, resourcePath, expectedManagedContents);
        Files.setLastModifiedTime(managedFile, FileTime.fromMillis(Files.getLastModifiedTime(remoteFile).toMillis() + deltaManagedToRemoteTimestamp));
    }
    archivaConfiguration.getConfiguration().setProxyConnectors(new ArrayList<ProxyConnectorConfiguration>());
    setupReleaseConnector(REPOID_INTERNAL, remoteCentral, releasePolicy);
    saveConfiguration();
    // --- Execution
    // process the response code later, not via an exception.
    // HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + resourcePath);
    WebResponse response = getServletUnitClient().getResponse(request);
    switch(expectation) {
        case EXPECT_MANAGED_CONTENTS:
            assertResponseOK(response);
            assertTrue("Invalid Test Case: Can't expect managed contents with " + "test that doesn't have a managed copy in the first place.", hasManagedCopy);
            assertEquals("Expected managed file contents", expectedManagedContents, response.getContentAsString());
            break;
        case EXPECT_REMOTE_CONTENTS:
            assertResponseOK(response);
            assertEquals("Expected remote file contents", expectedRemoteContents, response.getContentAsString());
            break;
        case EXPECT_NOT_FOUND:
            assertResponseNotFound(response);
            assertManagedFileNotExists(repoRootInternal, resourcePath);
            break;
    }
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration)

Aggregations

ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)35 ArrayList (java.util.ArrayList)11 Configuration (org.apache.archiva.configuration.model.Configuration)11 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)9 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)9 Path (java.nio.file.Path)6 ProxyConnectorRuleConfiguration (org.apache.archiva.configuration.model.ProxyConnectorRuleConfiguration)6 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)5 Iterator (java.util.Iterator)4 List (java.util.List)4 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)4 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)4 Wagon (org.apache.maven.wagon.Wagon)4 Before (org.junit.Before)4 ContextConfiguration (org.springframework.test.context.ContextConfiguration)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)3 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)3 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)3 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)3 WagonFactory (org.apache.archiva.maven.common.proxy.WagonFactory)3