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());
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations