use of org.apache.archiva.configuration.model.LegacyArtifactPath 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.LegacyArtifactPath in project archiva by apache.
the class ConfigurationRegistryReader method readLegacyArtifactPath.
private LegacyArtifactPath readLegacyArtifactPath(String prefix, Registry registry) {
LegacyArtifactPath value = new LegacyArtifactPath();
// String path = registry.getString( prefix + "path", value.getPath() );
List<String> pathList = registry.getList(prefix + "path");
String path = value.getPath();
if (pathList != null && !pathList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = pathList.size(); i < size; i++) {
sb.append(pathList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
path = sb.toString();
}
value.setPath(path);
// String artifact = registry.getString( prefix + "artifact", value.getArtifact() );
List<String> artifactList = registry.getList(prefix + "artifact");
String artifact = value.getArtifact();
if (artifactList != null && !artifactList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (int i = 0, size = artifactList.size(); i < size; i++) {
sb.append(artifactList.get(i));
if (i < size - 1) {
sb.append(',');
}
}
artifact = sb.toString();
}
value.setArtifact(artifact);
return value;
}
use of org.apache.archiva.configuration.model.LegacyArtifactPath 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.LegacyArtifactPath in project archiva by apache.
the class ConfigurationRegistryWriter method writeConfiguration.
private void writeConfiguration(String prefix, Configuration value, Registry registry) {
if (value != null) {
if (value.getVersion() != null) {
String version = "version";
registry.setString(prefix + version, value.getVersion());
}
if (value.getMetadataStore() != null && !value.getMetadataStore().equals("jcr")) {
String metadataStore = "metadataStore";
registry.setString(prefix + metadataStore, value.getMetadataStore());
}
if (value.getRepositoryGroups() != null && value.getRepositoryGroups().size() > 0) {
registry.removeSubset(prefix + "repositoryGroups");
int count = 0;
for (Iterator iter = value.getRepositoryGroups().iterator(); iter.hasNext(); count++) {
String name = "repositoryGroups.repositoryGroup(" + count + ")";
RepositoryGroupConfiguration o = (RepositoryGroupConfiguration) iter.next();
writeRepositoryGroupConfiguration(prefix + name + ".", o, registry);
}
}
if (value.getManagedRepositories() != null && value.getManagedRepositories().size() > 0) {
registry.removeSubset(prefix + "managedRepositories");
int count = 0;
for (Iterator iter = value.getManagedRepositories().iterator(); iter.hasNext(); count++) {
String name = "managedRepositories.managedRepository(" + count + ")";
ManagedRepositoryConfiguration o = (ManagedRepositoryConfiguration) iter.next();
writeManagedRepositoryConfiguration(prefix + name + ".", o, registry);
}
}
if (value.getRemoteRepositories() != null && value.getRemoteRepositories().size() > 0) {
registry.removeSubset(prefix + "remoteRepositories");
int count = 0;
for (Iterator iter = value.getRemoteRepositories().iterator(); iter.hasNext(); count++) {
String name = "remoteRepositories.remoteRepository(" + count + ")";
RemoteRepositoryConfiguration o = (RemoteRepositoryConfiguration) iter.next();
writeRemoteRepositoryConfiguration(prefix + name + ".", o, registry);
}
}
if (value.getProxyConnectors() != null && value.getProxyConnectors().size() > 0) {
registry.removeSubset(prefix + "proxyConnectors");
int count = 0;
for (Iterator iter = value.getProxyConnectors().iterator(); iter.hasNext(); count++) {
String name = "proxyConnectors.proxyConnector(" + count + ")";
ProxyConnectorConfiguration o = (ProxyConnectorConfiguration) iter.next();
writeProxyConnectorConfiguration(prefix + name + ".", o, registry);
}
}
if (value.getNetworkProxies() != null && value.getNetworkProxies().size() > 0) {
registry.removeSubset(prefix + "networkProxies");
int count = 0;
for (Iterator iter = value.getNetworkProxies().iterator(); iter.hasNext(); count++) {
String name = "networkProxies.networkProxy(" + count + ")";
NetworkProxyConfiguration o = (NetworkProxyConfiguration) iter.next();
writeNetworkProxyConfiguration(prefix + name + ".", o, registry);
}
}
if (value.getLegacyArtifactPaths() != null && value.getLegacyArtifactPaths().size() > 0) {
registry.removeSubset(prefix + "legacyArtifactPaths");
int count = 0;
for (Iterator iter = value.getLegacyArtifactPaths().iterator(); iter.hasNext(); count++) {
String name = "legacyArtifactPaths.legacyArtifactPath(" + count + ")";
LegacyArtifactPath o = (LegacyArtifactPath) iter.next();
writeLegacyArtifactPath(prefix + name + ".", o, registry);
}
}
if (value.getRepositoryScanning() != null) {
writeRepositoryScanningConfiguration(prefix + "repositoryScanning.", value.getRepositoryScanning(), registry);
}
if (value.getWebapp() != null) {
writeWebappConfiguration(prefix + "webapp.", value.getWebapp(), registry);
}
if (value.getOrganisationInfo() != null) {
writeOrganisationInformation(prefix + "organisationInfo.", value.getOrganisationInfo(), registry);
}
if (value.getNetworkConfiguration() != null) {
writeNetworkConfiguration(prefix + "networkConfiguration.", value.getNetworkConfiguration(), registry);
}
if (value.getRedbackRuntimeConfiguration() != null) {
writeRedbackRuntimeConfiguration(prefix + "redbackRuntimeConfiguration.", value.getRedbackRuntimeConfiguration(), registry);
}
if (value.getArchivaRuntimeConfiguration() != null) {
writeArchivaRuntimeConfiguration(prefix + "archivaRuntimeConfiguration.", value.getArchivaRuntimeConfiguration(), registry);
}
if (value.getProxyConnectorRuleConfigurations() != null && value.getProxyConnectorRuleConfigurations().size() > 0) {
registry.removeSubset(prefix + "proxyConnectorRuleConfigurations");
int count = 0;
for (Iterator iter = value.getProxyConnectorRuleConfigurations().iterator(); iter.hasNext(); count++) {
String name = "proxyConnectorRuleConfigurations.proxyConnectorRuleConfiguration(" + count + ")";
ProxyConnectorRuleConfiguration o = (ProxyConnectorRuleConfiguration) iter.next();
writeProxyConnectorRuleConfiguration(prefix + name + ".", o, registry);
}
}
if (value.getArchivaDefaultConfiguration() != null) {
writeArchivaDefaultConfiguration(prefix + "archivaDefaultConfiguration.", value.getArchivaDefaultConfiguration(), registry);
}
}
}
Aggregations