]> source.dussan.org Git - archiva.git/commitdiff
[MRM-661] fix handling of removing the last element from a list
authorBrett Porter <brett@apache.org>
Mon, 25 Feb 2008 15:38:01 +0000 (15:38 +0000)
committerBrett Porter <brett@apache.org>
Mon, 25 Feb 2008 15:38:01 +0000 (15:38 +0000)
Merged from: r630878

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@630880 13f79535-47bb-0310-9956-ffa450edef68

archiva-1.0.x/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/conf-single-list-elements.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
archiva-1.0.x/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml

index 4ca6f0229aecdb8b0e272a17ba8785e1f7de7fcd..d7aac869145a3f0e2d9e487f074086a5a98a5397 100644 (file)
@@ -53,8 +53,8 @@ import java.util.HashSet;
 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>
@@ -442,6 +442,50 @@ public class DefaultArchivaConfiguration
                                                                        .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();
 
diff --git a/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/conf-single-list-elements.xml b/archiva-1.0.x/archiva-base/archiva-configuration/src/test/conf/conf-single-list-elements.xml
new file mode 100644 (file)
index 0000000..2fe0066
--- /dev/null
@@ -0,0 +1,89 @@
+<?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>
index 03fd894985a113f10416e6193c7ad45618d7886e..1c5ddc33c68f5599e365b1b78b1bacece14c8880 100644 (file)
@@ -637,6 +637,93 @@ public class ArchivaConfigurationTest
         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.
      */
index abd8baae567f0132993aaf2515d5cce8957cd55e..319fc4e32345707bfd22dd193df097f4f9441042 100644 (file)
       </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>