Search in sources :

Example 56 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class RepositoryRegistry method putRepository.

/**
 * Adds a new repository to the current list, or replaces the repository definition with
 * the same id, if it exists already.
 * The change is saved to the configuration immediately.
 *
 * @param managedRepository the new repository.
 * @throws RepositoryException if the new repository could not be saved to the configuration.
 */
public ManagedRepository putRepository(ManagedRepository managedRepository) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        final String id = managedRepository.getId();
        if (remoteRepositories.containsKey(id)) {
            throw new RepositoryException("There exists a remote repository with id " + id + ". Could not update with managed repository.");
        }
        ManagedRepository originRepo = managedRepositories.put(id, managedRepository);
        try {
            if (originRepo != null) {
                originRepo.close();
            }
            RepositoryProvider provider = getProvider(managedRepository.getType());
            ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration(managedRepository);
            Configuration configuration = getArchivaConfiguration().getConfiguration();
            updateRepositoryReferences(provider, managedRepository, newCfg, configuration);
            ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById(id);
            if (oldCfg != null) {
                configuration.removeManagedRepository(oldCfg);
            }
            configuration.addManagedRepository(newCfg);
            getArchivaConfiguration().save(configuration);
            return managedRepository;
        } catch (Exception e) {
            // Rollback
            if (originRepo != null) {
                managedRepositories.put(id, originRepo);
            } else {
                managedRepositories.remove(id);
            }
            log.error("Exception during configuration update {}", e.getMessage(), e);
            throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
        }
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) RegistryException(org.apache.archiva.redback.components.registry.RegistryException) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException)

Example 57 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class RepositoryRegistry method putRepository.

/**
 * Adds a remote repository, or overwrites the repository definition with the same id, if it exists already.
 * The modification is saved to the configuration immediately.
 *
 * @param remoteRepository the remote repository to add
 * @throws RepositoryException if an error occurs during configuration save
 */
public RemoteRepository putRepository(RemoteRepository remoteRepository) throws RepositoryException {
    rwLock.writeLock().lock();
    try {
        Configuration configuration = getArchivaConfiguration().getConfiguration();
        try {
            RemoteRepository repo = putRepository(remoteRepository, configuration);
            getArchivaConfiguration().save(configuration);
            return repo;
        } catch (RegistryException | IndeterminateConfigurationException e) {
            log.error("Error while saving remote repository {}", e.getMessage(), e);
            throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
        }
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.IndeterminateConfigurationException) RegistryException(org.apache.archiva.redback.components.registry.RegistryException)

Example 58 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class FileMetadataRepositoryTest method createTestConfiguration.

protected static ArchivaConfiguration createTestConfiguration(Path directory) {
    ArchivaConfiguration config = mock(ArchivaConfiguration.class);
    Configuration configData = new Configuration();
    configData.addManagedRepository(createManagedRepository(TEST_REPO_ID, directory));
    configData.addManagedRepository(createManagedRepository("other-repo", directory));
    when(config.getConfiguration()).thenReturn(configData);
    return config;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration)

Example 59 with Configuration

use of org.apache.archiva.configuration.Configuration 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.RepositoryGroupConfiguration) WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.proxy.common.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Example 60 with Configuration

use of org.apache.archiva.configuration.Configuration in project archiva by apache.

the class Maven2RepositoryMetadataResolverMRM1411Test method testGetProjectVersionMetadataWithParentNoRemoteReposConfigured.

@Test
public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured() throws Exception {
    // remove configuration
    Configuration config = configuration.getConfiguration();
    RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById(TEST_REMOTE_REPO_ID);
    config.removeRemoteRepository(remoteRepo);
    configuration.save(config);
    copyTestArtifactWithParent("target/test-classes/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0"));
    assertEquals("1.0", metadata.getId());
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
    assertNotNull(facet);
    assertEquals("com.example.test", facet.getGroupId());
    assertEquals("test-artifact-module-a", facet.getArtifactId());
    assertEquals("jar", facet.getPackaging());
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-artifact-module-a");
    paths.add("target/test-repository/com/example/test/test-artifact-parent");
    paths.add("target/test-repository/com/example/test/test-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.archiva.configuration.Configuration)63 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)30 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)29 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)21 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)19 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)16 NetworkConfiguration (org.apache.archiva.admin.model.beans.NetworkConfiguration)13 UiConfiguration (org.apache.archiva.admin.model.beans.UiConfiguration)13 WebappConfiguration (org.apache.archiva.configuration.WebappConfiguration)13 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)11 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)11 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)11 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Path (java.nio.file.Path)8 RepositoryException (org.apache.archiva.repository.RepositoryException)7 IOException (java.io.IOException)4 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)4