mirror of https://github.com/apache/archiva.git
[MRM-456] permit having configuration in both sources as long as it doesn't contain any elements that might not save properly (lists)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@564135 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d9ff71462a
commit
a658609b5c
|
@ -32,6 +32,7 @@ import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -144,20 +145,40 @@ public class DefaultArchivaConfiguration
|
||||||
throws RegistryException, IndeterminateConfigurationException
|
throws RegistryException, IndeterminateConfigurationException
|
||||||
{
|
{
|
||||||
Registry section = registry.getSection( KEY + ".user" );
|
Registry section = registry.getSection( KEY + ".user" );
|
||||||
|
Registry baseSection = registry.getSection( KEY + ".base" );
|
||||||
if ( section == null )
|
if ( section == null )
|
||||||
{
|
{
|
||||||
section = registry.getSection( KEY + ".base" );
|
section = baseSection;
|
||||||
if ( section == null )
|
if ( section == null )
|
||||||
{
|
{
|
||||||
section = createDefaultConfigurationFile();
|
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(
|
// a little aggressive with the repositoryScanning and databaseScanning - should be no need to split
|
||||||
"Configuration can not be saved when it is loaded from two sources" );
|
// 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 );
|
new ConfigurationRegistryWriter().write( configuration, section );
|
||||||
|
|
|
@ -348,7 +348,7 @@ public class ArchivaConfigurationTest
|
||||||
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
assertFalse( "check value", configuration.getWebapp().getUi().isAppletFindEnabled() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreConfigurationFailsWhenReadFromBothLocations()
|
public void testStoreConfigurationFailsWhenReadFromBothLocationsNoLists()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
File baseFile = getTestFile( "target/test/test-file.xml" );
|
File baseFile = getTestFile( "target/test/test-file.xml" );
|
||||||
|
@ -373,6 +373,84 @@ public class ArchivaConfigurationTest
|
||||||
|
|
||||||
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
configuration.getWebapp().getUi().setAppletFindEnabled( false );
|
||||||
|
|
||||||
|
archivaConfiguration.save( configuration );
|
||||||
|
|
||||||
|
assertTrue( "Check file exists", baseFile.exists() );
|
||||||
|
assertEquals( "Check base file is unchanged", "<configuration/>",
|
||||||
|
FileUtils.fileRead( baseFile.getAbsolutePath() ) );
|
||||||
|
assertTrue( "Check file exists", userFile.exists() );
|
||||||
|
assertFalse( "Check base file is changed",
|
||||||
|
"<configuration/>".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(), "<configuration/>" );
|
||||||
|
|
||||||
|
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", "<configuration/>",
|
||||||
|
FileUtils.fileRead( baseFile.getAbsolutePath() ) );
|
||||||
|
assertTrue( "Check file exists", userFile.exists() );
|
||||||
|
assertFalse( "Check base file is changed",
|
||||||
|
"<configuration/>".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(), "<configuration/>" );
|
||||||
|
|
||||||
|
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
|
try
|
||||||
{
|
{
|
||||||
archivaConfiguration.save( configuration );
|
archivaConfiguration.save( configuration );
|
||||||
|
|
Loading…
Reference in New Issue