Search in sources :

Example 36 with RemoteRepositoryConfiguration

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

the class RemoteRepositoryHandler method put.

@Override
public RemoteRepository put(RemoteRepository repository) throws RepositoryException {
    final String id = repository.getId();
    RemoteRepository originRepo = getRepositories().remove(id);
    if (originRepo == null && repositoryHandlerManager.isRegisteredId(id)) {
        throw new RepositoryException("There exists a repository with id " + id + ". Could not update with managed repository.");
    }
    try {
        if (originRepo != null && repository != originRepo) {
            deactivateRepository(originRepo);
            pushEvent(LifecycleEvent.UNREGISTERED, originRepo);
        }
        RepositoryProvider provider = getProvider(repository.getType());
        RemoteRepositoryConfiguration newCfg = provider.getRemoteConfiguration(repository);
        getConfigurationHandler().getLock().writeLock().lock();
        try {
            Configuration configuration = getConfigurationHandler().getBaseConfiguration();
            updateReferences(repository, newCfg);
            RemoteRepositoryConfiguration oldCfg = configuration.findRemoteRepositoryById(id);
            if (oldCfg != null) {
                configuration.removeRemoteRepository(oldCfg);
            }
            configuration.addRemoteRepository(newCfg);
            getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
            setLastState(repository, RepositoryState.SAVED);
            activateRepository(repository);
        } finally {
            getConfigurationHandler().getLock().writeLock().unlock();
        }
        getRepositories().put(id, repository);
        setLastState(repository, RepositoryState.REGISTERED);
        return repository;
    } catch (Exception e) {
        // Rollback only partly, because repository is closed already
        if (originRepo != null) {
            getRepositories().put(id, originRepo);
        } else {
            getRepositories().remove(id);
        }
        log.error("Exception during configuration update {}", e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) RegistryException(org.apache.archiva.components.registry.RegistryException) RepositoryException(org.apache.archiva.repository.RepositoryException) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException)

Example 37 with RemoteRepositoryConfiguration

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

the class ArchivaRepositoryRegistryTest method putRemoteRepositoryFromConfigWithoutSave.

@Test
public void putRemoteRepositoryFromConfigWithoutSave() throws Exception {
    Configuration configuration = archivaConfiguration.getConfiguration();
    RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
    Configuration newConfiguration = new Configuration();
    cfg.setId("test002");
    cfg.setName("This is test 002");
    RemoteRepository repo = repositoryRegistry.putRepository(cfg, newConfiguration);
    assertNotNull(repo);
    assertEquals("test002", repo.getId());
    assertEquals("This is test 002", repo.getName());
    assertNotNull(repo.getContent());
    archivaConfiguration.reload();
    assertEquals(1, archivaConfiguration.getConfiguration().getRemoteRepositories().size());
    Collection<RemoteRepository> repos = repositoryRegistry.getRemoteRepositories();
    assertEquals(1, repos.size());
    assertEquals(1, newConfiguration.getRemoteRepositories().size());
    RemoteRepository internalRepo = repositoryRegistry.getRemoteRepository("central");
    cfg = new RemoteRepositoryConfiguration();
    cfg.setId("central");
    cfg.setName("This is central test 002");
    repo = repositoryRegistry.putRepository(cfg, newConfiguration);
    assertEquals("This is central test 002", repo.getName());
    assertEquals(2, newConfiguration.getRemoteRepositories().size());
    repositoryRegistry.reload();
    assertEquals(1, repositoryRegistry.getRemoteRepositories().size());
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) BasicRemoteRepository(org.apache.archiva.repository.base.remote.BasicRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 38 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration 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 39 with RemoteRepositoryConfiguration

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

the class AbstractProxyTestCase method saveRemoteRepositoryConfig.

protected void saveRemoteRepositoryConfig(String id, String name, String url, String layout) {
    RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
    repoConfig.setId(id);
    repoConfig.setName(name);
    repoConfig.setLayout(layout);
    repoConfig.setUrl(url);
    int count = config.getConfiguration().getRemoteRepositories().size();
    config.getConfiguration().addRemoteRepository(repoConfig);
    String prefix = "remoteRepositories.remoteRepository(" + count + ")";
    config.triggerChange(prefix + ".id", repoConfig.getId());
    config.triggerChange(prefix + ".name", repoConfig.getName());
    config.triggerChange(prefix + ".url", repoConfig.getUrl());
    config.triggerChange(prefix + ".layout", repoConfig.getLayout());
    repositoryRegistry.reload();
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)

Example 40 with RemoteRepositoryConfiguration

use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration 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)

Aggregations

RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)46 Configuration (org.apache.archiva.configuration.model.Configuration)17 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)14 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 ContextConfiguration (org.springframework.test.context.ContextConfiguration)11 ArrayList (java.util.ArrayList)9 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)9 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)9 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Test (org.junit.Test)8 Path (java.nio.file.Path)7 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)7 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)7 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)6 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)6 PasswordCredentials (org.apache.archiva.repository.base.PasswordCredentials)6 Iterator (java.util.Iterator)5 List (java.util.List)5