diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
index 7c007bb6e..c652fb28b 100644
--- a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
+++ b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java
@@ -32,6 +32,7 @@ import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -144,20 +145,40 @@ public class DefaultArchivaConfiguration
throws RegistryException, IndeterminateConfigurationException
{
Registry section = registry.getSection( KEY + ".user" );
+ Registry baseSection = registry.getSection( KEY + ".base" );
if ( section == null )
{
- section = registry.getSection( KEY + ".base" );
+ section = baseSection;
if ( section == null )
{
section = createDefaultConfigurationFile();
}
}
- else if ( registry.getSection( KEY + ".base" ) != null )
+ else if ( baseSection != null )
{
- this.configuration = null;
+ Collection keys = baseSection.getKeys();
+ boolean foundList = false;
+ for ( Iterator i = keys.iterator(); i.hasNext() && !foundList; )
+ {
+ String key = (String) i.next();
- throw new IndeterminateConfigurationException(
- "Configuration can not be saved when it is loaded from two sources" );
+ // a little aggressive with the repositoryScanning and databaseScanning - should be no need to split
+ // that configuration
+ if ( key.startsWith( "repositories" ) || key.startsWith( "proxyConnectors" ) ||
+ key.startsWith( "networkProxies" ) || key.startsWith( "repositoryScanning" ) ||
+ key.startsWith( "databaseScanning" ) )
+ {
+ foundList = true;
+ }
+ }
+
+ if ( foundList )
+ {
+ this.configuration = null;
+
+ throw new IndeterminateConfigurationException(
+ "Configuration can not be saved when it is loaded from two sources" );
+ }
}
new ConfigurationRegistryWriter().write( configuration, section );
diff --git a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
index d3a485b89..697702a53 100644
--- a/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
+++ b/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java
@@ -348,7 +348,7 @@ public class ArchivaConfigurationTest
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
}
- public void testStoreConfigurationFailsWhenReadFromBothLocations()
+ public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
throws Exception
{
File baseFile = getTestFile( "target/test/test-file.xml" );
@@ -373,6 +373,84 @@ public class ArchivaConfigurationTest
configuration.getWebapp().getUi().setAppletFindEnabled( false );
+ archivaConfiguration.save( configuration );
+
+ assertTrue( "Check file exists", baseFile.exists() );
+ assertEquals( "Check base file is unchanged", "",
+ FileUtils.fileRead( baseFile.getAbsolutePath() ) );
+ assertTrue( "Check file exists", userFile.exists() );
+ assertFalse( "Check base file is changed",
+ "".equals( FileUtils.fileRead( userFile.getAbsolutePath() ) ) );
+
+ // check it
+ configuration = archivaConfiguration.getConfiguration();
+ assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
+ }
+
+ public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists()
+ 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() );
+
+ userFile.getParentFile().mkdirs();
+ FileUtils.copyFile( getTestFile( "src/test/conf/conf-user.xml" ), userFile );
+
+ baseFile.getParentFile().mkdirs();
+ FileUtils.fileWrite( baseFile.getAbsolutePath(), "" );
+
+ ArchivaConfiguration archivaConfiguration =
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+
+ Configuration configuration = archivaConfiguration.getConfiguration();
+ assertTrue( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
+
+ configuration.getWebapp().getUi().setShowFindArtifacts( false );
+
+ archivaConfiguration.save( configuration );
+
+ assertTrue( "Check file exists", baseFile.exists() );
+ assertEquals( "Check base file is unchanged", "",
+ FileUtils.fileRead( baseFile.getAbsolutePath() ) );
+ assertTrue( "Check file exists", userFile.exists() );
+ assertFalse( "Check base file is changed",
+ "".equals( FileUtils.fileRead( userFile.getAbsolutePath() ) ) );
+
+ // check it
+ configuration = archivaConfiguration.getConfiguration();
+ assertFalse( "check value", configuration.getWebapp().getUi().isShowFindArtifacts() );
+ }
+
+ public void testStoreConfigurationFailsWhenReadFromBothLocationsAppserverHasLists()
+ 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-base.xml" ), baseFile );
+
+ userFile.getParentFile().mkdirs();
+ FileUtils.fileWrite( userFile.getAbsolutePath(), "" );
+
+ ArchivaConfiguration archivaConfiguration =
+ (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), "test-save-user" );
+
+ Configuration configuration = archivaConfiguration.getConfiguration();
+ assertTrue( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
+
+ configuration.getWebapp().getUi().setAppletFindEnabled( false );
+
try
{
archivaConfiguration.save( configuration );