Search in sources :

Example 16 with Configuration

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

the class ArchivaConfigurationTest method testRemoveLastElements.

@Test
public void testRemoveLastElements() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(baseFile.getParent());
    FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
    Files.createDirectories(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
    assertNotNull(repositoryGroup);
    configuration.removeRepositoryGroup(repositoryGroup);
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
    assertNotNull(repository);
    configuration.removeRemoteRepository(repository);
    assertTrue(configuration.getRemoteRepositories().isEmpty());
    ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
    assertNotNull(managedRepository);
    configuration.removeManagedRepository(managedRepository);
    assertTrue(configuration.getManagedRepositories().isEmpty());
    ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
    assertNotNull(proxyConnector);
    configuration.removeProxyConnector(proxyConnector);
    assertTrue(configuration.getProxyConnectors().isEmpty());
    NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
    assertNotNull(networkProxy);
    configuration.removeNetworkProxy(networkProxy);
    assertTrue(configuration.getNetworkProxies().isEmpty());
    LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
    assertNotNull(path);
    configuration.removeLegacyArtifactPath(path);
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
    String consumer = scanning.getKnownContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeKnownContentConsumer(consumer);
    // default values
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    consumer = scanning.getInvalidContentConsumers().get(0);
    assertNotNull(consumer);
    scanning.removeInvalidContentConsumer(consumer);
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
    archivaConfiguration.save(configuration);
    archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
    configuration = archivaConfiguration.getConfiguration();
    assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
    assertTrue(configuration.getRepositoryGroups().isEmpty());
    assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
    assertTrue(configuration.getProxyConnectors().isEmpty());
    assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
    assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
    scanning = configuration.getRepositoryScanning();
    assertFalse(scanning.getKnownContentConsumers().isEmpty());
    assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) 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) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Test(org.junit.Test)

Example 17 with Configuration

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

the class ArchivaConfigurationTest method testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists.

@Test
public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(baseFile.getParent());
    FileUtils.copyFile(getTestFile("src/test/conf/conf-base.xml").toFile(), baseFile.toFile());
    Files.createDirectories(userFile.getParent());
    FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-save-user");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertTrue("check value", configuration.getWebapp().getUi().isAppletFindEnabled());
    configuration.getWebapp().getUi().setAppletFindEnabled(false);
    try {
        archivaConfiguration.save(configuration);
        fail("Configuration saving should not succeed if it was loaded from two locations");
    } catch (IndeterminateConfigurationException e) {
        // check it was reverted
        configuration = archivaConfiguration.getConfiguration();
        assertTrue("check value", configuration.getWebapp().getUi().isAppletFindEnabled());
    }
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) 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) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) Test(org.junit.Test)

Example 18 with Configuration

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

the class DefaultArchivaAdministration method removeFileType.

@Override
public void removeFileType(String fileTypeId, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    org.apache.archiva.configuration.model.FileType fileType = new org.apache.archiva.configuration.model.FileType();
    fileType.setId(fileTypeId);
    configuration.getRepositoryScanning().removeFileType(fileType);
    saveConfiguration(configuration);
}
Also used : WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration)

Example 19 with Configuration

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

the class DefaultArchivaAdministration method setNetworkConfiguration.

@Override
public void setNetworkConfiguration(NetworkConfiguration networkConfiguration) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    if (networkConfiguration == null) {
        configuration.setNetworkConfiguration(null);
    } else {
        configuration.setNetworkConfiguration(getModelMapper().map(networkConfiguration, org.apache.archiva.configuration.model.NetworkConfiguration.class));
    }
    // setupWagon( networkConfiguration );
    saveConfiguration(configuration);
}
Also used : WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration)

Example 20 with Configuration

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

the class DefaultArchivaAdministration method addKnownContentConsumer.

@Override
public void addKnownContentConsumer(String knownContentConsumer, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    if (configuration.getRepositoryScanning().getKnownContentConsumers().contains(knownContentConsumer)) {
        log.warn("skip adding knownContentConsumer {} as already here", knownContentConsumer);
        return;
    }
    configuration.getRepositoryScanning().addKnownContentConsumer(knownContentConsumer);
    saveConfiguration(configuration);
    triggerAuditEvent("", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation);
}
Also used : WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11