From 4fe4dc198e8ba22e532fcb17412d1bd9e8999872 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Sat, 21 Jun 2008 01:25:56 +0000 Subject: [PATCH] [MRM-789] -added an additional check in ArchivaConfiguration to append 'data/repositories/[repo_id]' in the repo location when the default config (from default-archiva.xml) is used -added test git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@670114 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultArchivaConfiguration.java | 32 +++- .../ArchivaConfigurationTest.java | 36 ++++ .../ArchivaConfigurationTest.xml | 21 +++ .../configuration/test-default-archiva.xml | 174 ++++++++++++++++++ 4 files changed, 258 insertions(+), 5 deletions(-) create mode 100644 archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/test-default-archiva.xml diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java index 2e86bde8d..af3180d13 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/DefaultArchivaConfiguration.java @@ -138,7 +138,7 @@ public class DefaultArchivaConfiguration */ private boolean isConfigurationDefaulted = false; - private static final String KEY = "org.apache.maven.archiva"; + private static final String KEY = "org.apache.maven.archiva"; public synchronized Configuration getConfiguration() { @@ -146,13 +146,17 @@ public class DefaultArchivaConfiguration { configuration = load(); configuration = unescapeExpressions( configuration ); + if( isConfigurationDefaulted ) + { + configuration = checkRepositoryLocations( configuration ); + } } return configuration; } private Configuration load() - { + { // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties) Registry subset = registry.getSubset( KEY ); if ( subset.getString( "version" ) == null ) @@ -164,8 +168,8 @@ public class DefaultArchivaConfiguration subset = readDefaultConfiguration(); } } - - Configuration config = new ConfigurationRegistryReader().read( subset ); + + Configuration config = new ConfigurationRegistryReader().read( subset ); if ( !config.getRepositories().isEmpty() ) { @@ -173,7 +177,7 @@ public class DefaultArchivaConfiguration { V1RepositoryConfiguration r = i.next(); r.setScanned( r.isIndexed() ); - + if ( r.getUrl().startsWith( "file://" ) ) { r.setLocation( r.getUrl().substring( 7 ) ); @@ -696,6 +700,24 @@ public class DefaultArchivaConfiguration return config; } + + private Configuration checkRepositoryLocations( Configuration config ) + { + // additional check for [MRM-789], ensure that the location of the default repositories + // are not installed in the server installation + for( ManagedRepositoryConfiguration repo : (List) config.getManagedRepositories() ) + { + String repoPath = repo.getLocation(); + File repoLocation = new File( repoPath ); + + if( repoLocation.exists() && repoLocation.isDirectory() && !repoPath.endsWith( "data/repositories/" + repo.getId() ) ) + { + repo.setLocation( repoPath + "/data/repositories/" + repo.getId() ); + } + } + + return config; + } public String getUserConfigFilename() { diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java index 6b7251142..75ff15c3a 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java +++ b/archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.custommonkey.xmlunit.XMLAssert; @@ -87,7 +88,42 @@ public class ArchivaConfigurationTest assertEquals( "check managed repositories", "default", repository.getLayout() ); assertTrue( "check managed repositories", repository.isScanned() ); } + + // test for [MRM-789] + public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting() + throws Exception + { + File repo = new File( getBasedir(), "/target/test-classes/existing_snapshots" ); + repo.mkdirs(); + + repo = new File( getBasedir(), "/target/test-classes/existing_internal" ); + repo.mkdirs(); + + String existingTestDefaultArchivaConfigFile = "" + + FileUtils.readFileToString( getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) ) + + ""; + existingTestDefaultArchivaConfigFile = StringUtils.replace( existingTestDefaultArchivaConfigFile, "${appserver.base}", getBasedir() ); + + File generatedTestDefaultArchivaConfigFile = + new File( getBasedir(), "target/test-classes/org/apache/maven/archiva/configuration/default-archiva.xml" ); + + FileUtils.writeStringToFile( generatedTestDefaultArchivaConfigFile, existingTestDefaultArchivaConfigFile, null ); + + ArchivaConfiguration archivaConfiguration = + (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName(), + "test-defaults-default-repo-location-exists" ); + Configuration configuration = archivaConfiguration.getConfiguration(); + assertConfiguration( configuration ); + + ManagedRepositoryConfiguration repository = + (ManagedRepositoryConfiguration) configuration.getManagedRepositories().get( 0 ); + assertTrue( "check managed repositories", repository.getLocation().endsWith( "data/repositories/internal" ) ); + + generatedTestDefaultArchivaConfigFile.delete(); + assertFalse( generatedTestDefaultArchivaConfigFile.exists() ); + } + /** * Ensures that the provided configuration matches the details present in the archiva-default.xml file. */ diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml index 319fc4e32..0e84402c7 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml +++ b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/ArchivaConfigurationTest.xml @@ -20,6 +20,27 @@ + + + org.apache.maven.archiva.configuration.ArchivaConfiguration + test-defaults-default-repo-location-exists + org.apache.maven.archiva.configuration.DefaultArchivaConfiguration + + + org.codehaus.plexus.registry.Registry + empty + + + org.apache.maven.archiva.policies.PreDownloadPolicy + prePolicies + + + org.apache.maven.archiva.policies.PostDownloadPolicy + postPolicies + + + + org.apache.maven.archiva.configuration.ArchivaConfiguration test-defaults diff --git a/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/test-default-archiva.xml b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/test-default-archiva.xml new file mode 100644 index 000000000..30fdf38a0 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-configuration/src/test/resources/org/apache/maven/archiva/configuration/test-default-archiva.xml @@ -0,0 +1,174 @@ + 2 + + + internal + Archiva Managed Internal Repository + ${appserver.base}/target/test-classes/existing_internal + default + true + false + true + 0 0 * * * ? + 30 + + + snapshots + Archiva Managed Snapshot Repository + ${appserver.base}/target/test-classes/existing_snapshots + default + false + true + true + 0 0\,30 * * * ? + 30 + + + + + central + Central Repository + http://repo1.maven.org/maven2 + default + + + maven2-repository.dev.java.net + Java.net Repository for Maven 2 + http://download.java.net/maven/2/ + default + + + + + + internal + central + + + disabled + once + fix + cached + + + **/* + + + + internal + maven2-repository.dev.java.net + + + disabled + once + fix + cached + + + javax/** + org/jvnet/** + com/sun/** + + + + + + + jaxen/jars/jaxen-1.0-FCS-full.jar + jaxen:jaxen:1.0-FCS:full:jar + + + + + + + artifacts + + **/*.pom + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.dtd + **/*.tld + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + + + + indexable-content + + **/*.txt + **/*.TXT + **/*.block + **/*.config + **/*.pom + **/*.xml + **/*.xsd + **/*.dtd + **/*.tld + + + + auto-remove + + **/*.bak + **/*~ + **/*- + + + + ignored + + **/.htaccess + **/KEYS + **/*.rb + **/*.sh + **/.svn/** + **/.DAV/** + + + + + update-db-artifact + create-missing-checksums + update-db-repository-metadata + validate-checksum + validate-signature + index-content + auto-remove + auto-rename + metadata-updater + + + + update-db-bad-content + + + + + 0 0 * * * ? + + index-artifact + update-db-project + validate-repository-metadata + index-archive-toc + update-db-bytecode-stats + index-public-methods + + + not-present-remove-db-artifact + not-present-remove-db-project + not-present-remove-indexed + + + + + + true + true + +