import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
/**
* <p>
.getDatabaseScanning().getCronExpression() ) );
}
+ // [MRM-661] Due to a bug in the modello registry writer, we need to take these out by hand. They'll be put back by the writer.
+ if ( configuration.getManagedRepositories().isEmpty() )
+ {
+ section.removeSubset( "managedRepositories" );
+ }
+ if ( configuration.getRemoteRepositories().isEmpty() )
+ {
+ section.removeSubset( "remoteRepositories" );
+ }
+ if ( configuration.getProxyConnectors().isEmpty() )
+ {
+ section.removeSubset( "proxyConnectors" );
+ }
+ if ( configuration.getNetworkProxies().isEmpty() )
+ {
+ section.removeSubset( "networkProxies" );
+ }
+ if ( configuration.getLegacyArtifactPaths().isEmpty() )
+ {
+ section.removeSubset( "legacyArtifactPaths" );
+ }
+ if ( configuration.getRepositoryScanning() != null )
+ {
+ if ( configuration.getRepositoryScanning().getKnownContentConsumers().isEmpty() )
+ {
+ section.removeSubset( "repositoryScanning.knownContentConsumers" );
+ }
+ if ( configuration.getRepositoryScanning().getInvalidContentConsumers().isEmpty() )
+ {
+ section.removeSubset( "repositoryScanning.invalidContentConsumers" );
+ }
+ }
+ if ( configuration.getDatabaseScanning() != null )
+ {
+ if ( configuration.getDatabaseScanning().getCleanupConsumers().isEmpty() )
+ {
+ section.removeSubset( "databaseScanning.cleanupConsumers" );
+ }
+ if ( configuration.getDatabaseScanning().getUnprocessedConsumers().isEmpty() )
+ {
+ section.removeSubset( "databaseScanning.unprocessedConsumers" );
+ }
+ }
+
new ConfigurationRegistryWriter().write( configuration, section );
section.save();
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<configuration>
+ <version>2</version>
+ <managedRepositories>
+ <managedRepository>
+ <id>snapshots</id>
+ <name>Archiva Managed Snapshot Repository</name>
+ <location>${appserver.base}/repositories/snapshots</location>
+ <layout>default</layout>
+ <releases>false</releases>
+ <snapshots>true</snapshots>
+ <scanned>true</scanned>
+ <refreshCronExpression>0 0,30 * * ?</refreshCronExpression>
+ </managedRepository>
+ </managedRepositories>
+ <remoteRepositories>
+ <remoteRepository>
+ <id>central</id>
+ <name>Central Repository</name>
+ <url>http://repo1.maven.org/maven2</url>
+ <layout>default</layout>
+ </remoteRepository>
+ </remoteRepositories>
+ <proxyConnectors>
+ <proxyConnector>
+ <order>2</order>
+ <sourceRepoId>internal</sourceRepoId>
+ <targetRepoId>maven2-repository.dev.java.net</targetRepoId>
+ <proxyId/>
+ <whiteListPatterns>
+ <whiteListPattern>javax/**</whiteListPattern>
+ </whiteListPatterns>
+ <policies>
+ <releases>once</releases>
+ <checksum>fix</checksum>
+ <snapshots>never</snapshots>
+ <cache-failures>yes</cache-failures>
+ </policies>
+ </proxyConnector>
+ </proxyConnectors>
+ <networkProxies>
+ <networkProxy>
+ <id>proxy</id>
+ <host>proxy</host>
+ <port>8080</port>
+ </networkProxy>
+ </networkProxies>
+ <legacyArtifactPaths>
+ <legacyArtifactPath>
+ <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path>
+ <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact>
+ </legacyArtifactPath>
+ </legacyArtifactPaths>
+ <repositoryScanning>
+ <knownContentConsumers>
+ <knownContentConsumer>auto-remove</knownContentConsumer>
+ </knownContentConsumers>
+ <invalidContentConsumers>
+ <invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
+ </invalidContentConsumers>
+ </repositoryScanning>
+ <databaseScanning>
+ <unprocessedConsumers>
+ <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer>
+ </unprocessedConsumers>
+ <cleanupConsumers>
+ <cleanupConsumer>not-present-remove-db-project</cleanupConsumer>
+ </cleanupConsumers>
+ </databaseScanning>
+</configuration>
assertEquals( "check cron expression", "0 0,20 0 * * ?", repository.getRefreshCronExpression() );
}
+ public void testRemoveLastElements()
+ throws Exception
+ {
+ File baseFile = getTestFile( "target/test/test-file.xml" );
+ baseFile.delete();
+ assertFalse( baseFile.exists() );
+
+ File userFile = getTestFile( "target/test/test-file-user.xml" );
+ userFile.delete();
+ assertFalse( userFile.exists() );
+
+ baseFile.getParentFile().mkdirs();
+ FileUtils.copyFile( getTestFile( "src/test/conf/conf-single-list-elements.xml" ), baseFile );
+
+ userFile.getParentFile().mkdirs();
+ FileUtils.writeStringToFile( userFile, "<configuration/>", null );
+
+ ArchivaConfiguration archivaConfiguration =
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-remove-central" );
+
+ Configuration configuration = archivaConfiguration.getConfiguration();
+
+ 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 =
+ (ProxyConnectorConfiguration) 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 = (LegacyArtifactPath) configuration.getLegacyArtifactPaths().get( 0 );
+ assertNotNull( path );
+ configuration.removeLegacyArtifactPath( path );
+ assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
+
+ RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
+ String consumer = (String) scanning.getKnownContentConsumers().get( 0 );
+ assertNotNull( consumer );
+ scanning.removeKnownContentConsumer( consumer );
+ assertTrue( scanning.getKnownContentConsumers().isEmpty() );
+ consumer = (String) scanning.getInvalidContentConsumers().get( 0 );
+ assertNotNull( consumer );
+ scanning.removeInvalidContentConsumer( consumer );
+ assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
+
+ DatabaseScanningConfiguration databaseScanning = configuration.getDatabaseScanning();
+ consumer = (String) databaseScanning.getCleanupConsumers().get( 0 );
+ assertNotNull( consumer );
+ databaseScanning.removeCleanupConsumer( consumer );
+ assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
+ consumer = (String) databaseScanning.getUnprocessedConsumers().get( 0 );
+ assertNotNull( consumer );
+ databaseScanning.removeUnprocessedConsumer( consumer );
+ assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
+
+ archivaConfiguration.save( configuration );
+
+ archivaConfiguration =
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-read-saved" );
+ configuration = archivaConfiguration.getConfiguration();
+ assertNull( configuration.getRemoteRepositoriesAsMap().get( "central" ) );
+ assertNull( configuration.getManagedRepositoriesAsMap().get( "snapshots" ) );
+ assertTrue( configuration.getProxyConnectors().isEmpty() );
+ assertNull( configuration.getNetworkProxiesAsMap().get( "proxy" ) );
+ assertTrue( configuration.getLegacyArtifactPaths().isEmpty() );
+ scanning = configuration.getRepositoryScanning();
+ assertTrue( scanning.getKnownContentConsumers().isEmpty() );
+ assertTrue( scanning.getInvalidContentConsumers().isEmpty() );
+ databaseScanning = configuration.getDatabaseScanning();
+ assertTrue( databaseScanning.getCleanupConsumers().isEmpty() );
+ assertTrue( databaseScanning.getUnprocessedConsumers().isEmpty() );
+ }
+
/**
* [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
*/
</configuration>
</component>
+ <component>
+ <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+ <role-hint>test-remove-central</role-hint>
+ <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
+ <requirements>
+ <requirement>
+ <role>org.codehaus.plexus.registry.Registry</role>
+ <role-hint>remove-central</role-hint>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.archiva.policies.PreDownloadPolicy</role>
+ <field-name>prePolicies</field-name>
+ </requirement>
+ <requirement>
+ <role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
+ <field-name>postPolicies</field-name>
+ </requirement>
+ </requirements>
+ <configuration>
+ <userConfigFilename>${basedir}/target/test/test-file.xml</userConfigFilename>
+ </configuration>
+ </component>
+ <component>
+ <role>org.codehaus.plexus.registry.Registry</role>
+ <role-hint>remove-central</role-hint>
+ <implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
+ <configuration>
+ <properties>
+ <xml fileName="${basedir}/target/test/test-file.xml" config-optional="true" config-forceCreate="true"
+ config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
+ </properties>
+ </configuration>
+ </component>
+
<component>
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
<role-hint>test-not-allowed-to-write-to-both</role-hint>