archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r630880 - in /maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src: main/java/org/apache/maven/archiva/configuration/ test/conf/ test/java/org/apache/maven/archiva/configuration/ test/resources/org/apache/maven/archiv...
Date Mon, 25 Feb 2008 15:38:03 GMT
Author: brett
Date: Mon Feb 25 07:38:01 2008
New Revision: 630880

URL: http://svn.apache.org/viewvc?rev=630880&view=rev
Log:
[MRM-661] fix handling of removing the last element from a list
Merged from: r630878

Added:
    maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/conf-single-list-elements.xml
      - copied unchanged from r630878, maven/archiva/trunk/archiva-base/archiva-configuration/src/test/conf/conf-single-list-elements.xml
Modified:
    maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
    maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
    maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml

Modified: maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java?rev=630880&r1=630879&r2=630880&view=diff
==============================================================================
--- maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
(original)
+++ maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
Mon Feb 25 07:38:01 2008
@@ -53,8 +53,8 @@
 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>
@@ -440,6 +440,50 @@
             configuration.getDatabaseScanning().setCronExpression(
                                                                    escapeCronExpression(
configuration
                                                                        .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 );

Modified: maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java?rev=630880&r1=630879&r2=630880&view=diff
==============================================================================
--- maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
(original)
+++ maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
Mon Feb 25 07:38:01 2008
@@ -637,6 +637,93 @@
         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.
      */

Modified: maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml
URL: http://svn.apache.org/viewvc/maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml?rev=630880&r1=630879&r2=630880&view=diff
==============================================================================
--- maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml
(original)
+++ maven/archiva/branches/archiva-1.0.x/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml
Mon Feb 25 07:38:01 2008
@@ -345,6 +345,40 @@
     
     <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>
       <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
       <requirements>



Mime
View raw message