use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ConfigurationRegistryReader method readConfiguration.
private Configuration readConfiguration(String prefix, Registry registry) {
Configuration value = new Configuration();
// String version = registry.getString( prefix + "version", value.getVersion() );
List<String> versionList = registry.getList(prefix + "version");
String version = value.getVersion();
if (versionList != null && !versionList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = versionList.size(); i < size; i++) {
sb.append(versionList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
version = sb.toString();
}
value.setVersion(version);
// String metadataStore = registry.getString( prefix + "metadataStore", value.getMetadataStore() );
List<String> metadataStoreList = registry.getList(prefix + "metadataStore");
String metadataStore = value.getMetadataStore();
if (metadataStoreList != null && !metadataStoreList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = metadataStoreList.size(); i < size; i++) {
sb.append(metadataStoreList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
metadataStore = sb.toString();
}
value.setMetadataStore(metadataStore);
java.util.List repositoryGroups = new java.util.ArrayList();
List repositoryGroupsSubsets = registry.getSubsetList(prefix + "repositoryGroups.repositoryGroup");
for (Iterator i = repositoryGroupsSubsets.iterator(); i.hasNext(); ) {
RepositoryGroupConfiguration v = readRepositoryGroupConfiguration("", (Registry) i.next());
repositoryGroups.add(v);
}
value.setRepositoryGroups(repositoryGroups);
java.util.List managedRepositories = new java.util.ArrayList();
List managedRepositoriesSubsets = registry.getSubsetList(prefix + "managedRepositories.managedRepository");
for (Iterator i = managedRepositoriesSubsets.iterator(); i.hasNext(); ) {
ManagedRepositoryConfiguration v = readManagedRepositoryConfiguration("", (Registry) i.next());
managedRepositories.add(v);
}
value.setManagedRepositories(managedRepositories);
java.util.List remoteRepositories = new java.util.ArrayList();
List remoteRepositoriesSubsets = registry.getSubsetList(prefix + "remoteRepositories.remoteRepository");
for (Iterator i = remoteRepositoriesSubsets.iterator(); i.hasNext(); ) {
RemoteRepositoryConfiguration v = readRemoteRepositoryConfiguration("", (Registry) i.next());
remoteRepositories.add(v);
}
value.setRemoteRepositories(remoteRepositories);
java.util.List proxyConnectors = new java.util.ArrayList();
List proxyConnectorsSubsets = registry.getSubsetList(prefix + "proxyConnectors.proxyConnector");
for (Iterator i = proxyConnectorsSubsets.iterator(); i.hasNext(); ) {
ProxyConnectorConfiguration v = readProxyConnectorConfiguration("", (Registry) i.next());
proxyConnectors.add(v);
}
value.setProxyConnectors(proxyConnectors);
java.util.List networkProxies = new java.util.ArrayList();
List networkProxiesSubsets = registry.getSubsetList(prefix + "networkProxies.networkProxy");
for (Iterator i = networkProxiesSubsets.iterator(); i.hasNext(); ) {
NetworkProxyConfiguration v = readNetworkProxyConfiguration("", (Registry) i.next());
networkProxies.add(v);
}
value.setNetworkProxies(networkProxies);
java.util.List legacyArtifactPaths = new java.util.ArrayList();
List legacyArtifactPathsSubsets = registry.getSubsetList(prefix + "legacyArtifactPaths.legacyArtifactPath");
for (Iterator i = legacyArtifactPathsSubsets.iterator(); i.hasNext(); ) {
LegacyArtifactPath v = readLegacyArtifactPath("", (Registry) i.next());
legacyArtifactPaths.add(v);
}
value.setLegacyArtifactPaths(legacyArtifactPaths);
RepositoryScanningConfiguration repositoryScanning = readRepositoryScanningConfiguration(prefix + "repositoryScanning.", registry);
value.setRepositoryScanning(repositoryScanning);
WebappConfiguration webapp = readWebappConfiguration(prefix + "webapp.", registry);
value.setWebapp(webapp);
OrganisationInformation organisationInfo = readOrganisationInformation(prefix + "organisationInfo.", registry);
value.setOrganisationInfo(organisationInfo);
NetworkConfiguration networkConfiguration = readNetworkConfiguration(prefix + "networkConfiguration.", registry);
value.setNetworkConfiguration(networkConfiguration);
RedbackRuntimeConfiguration redbackRuntimeConfiguration = readRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", registry);
value.setRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
ArchivaRuntimeConfiguration archivaRuntimeConfiguration = readArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", registry);
value.setArchivaRuntimeConfiguration(archivaRuntimeConfiguration);
java.util.List proxyConnectorRuleConfigurations = new java.util.ArrayList();
List proxyConnectorRuleConfigurationsSubsets = registry.getSubsetList(prefix + "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration");
for (Iterator i = proxyConnectorRuleConfigurationsSubsets.iterator(); i.hasNext(); ) {
ProxyConnectorRuleConfiguration v = readProxyConnectorRuleConfiguration("", (Registry) i.next());
proxyConnectorRuleConfigurations.add(v);
}
value.setProxyConnectorRuleConfigurations(proxyConnectorRuleConfigurations);
ArchivaDefaultConfiguration archivaDefaultConfiguration = readArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", registry);
value.setArchivaDefaultConfiguration(archivaDefaultConfiguration);
return value;
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaConfigurationTest method testLoadConfigurationFromInvalidUserLocationOnDisk.
@Test
public void testLoadConfigurationFromInvalidUserLocationOnDisk() throws Exception {
Path testConfDir = getTestFile("target/test-appserver-base/conf/");
Files.createDirectories(testConfDir);
ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-not-allowed-to-write-to-user");
Configuration config = archivaConfiguration.getConfiguration();
archivaConfiguration.save(config);
// No Exception == test passes.
// Expected Path is: Should not have thrown an exception.
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaConfigurationTest method testStoreConfigurationFailsWhenReadFromBothLocationsNoLists.
@Test
public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists() 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.writeStringToFile(baseFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
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);
archivaConfiguration.save(configuration);
assertTrue("Check file exists", Files.exists(baseFile));
assertEquals("Check base file is unchanged", "<configuration/>", FileUtils.readFileToString(baseFile.toFile(), Charset.forName("UTF-8")));
assertTrue("Check file exists", Files.exists(userFile));
assertFalse("Check base file is changed", "<configuration/>".equals(FileUtils.readFileToString(userFile.toFile(), Charset.forName("UTF-8"))));
// check it
configuration = archivaConfiguration.getConfiguration();
assertFalse("check value", configuration.getWebapp().getUi().isAppletFindEnabled());
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaConfigurationTest method testGetConfigurationFromDefaults.
@Test
public void testGetConfigurationFromDefaults() throws Exception {
ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-defaults");
Configuration configuration = archivaConfiguration.getConfiguration();
assertConfiguration(configuration, 2, 1, 1);
assertEquals("check network proxies", 0, configuration.getNetworkProxies().size());
ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
assertEquals("check managed repositories", "${appserver.base}/repositories/internal", repository.getLocation());
assertEquals("check managed repositories", "Archiva Managed Internal Repository", repository.getName());
assertEquals("check managed repositories", "internal", repository.getId());
assertEquals("check managed repositories", "default", repository.getLayout());
assertTrue("check managed repositories", repository.isScanned());
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaConfigurationTest method testGetConfigurationFromRegistryWithTwoConfigurationResources.
@Test
public void testGetConfigurationFromRegistryWithTwoConfigurationResources() throws Exception {
ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-configuration-both");
Configuration configuration = archivaConfiguration.getConfiguration();
// from base
assertEquals("check repositories", 2, configuration.getManagedRepositories().size());
assertEquals("check repositories", 2, configuration.getRemoteRepositories().size());
// from user
assertEquals("check proxy connectors", 2, configuration.getProxyConnectors().size());
WebappConfiguration webapp = configuration.getWebapp();
assertNotNull("check webapp", webapp);
UserInterfaceOptions ui = webapp.getUi();
assertNotNull("check webapp ui", ui);
// from base
assertFalse("check showFindArtifacts", ui.isShowFindArtifacts());
// from user
assertFalse("check appletFindEnabled", ui.isAppletFindEnabled());
}
Aggregations