diff options
author | Maria Odea B. Ching <oching@apache.org> | 2008-06-21 01:25:56 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2008-06-21 01:25:56 +0000 |
commit | 4fe4dc198e8ba22e532fcb17412d1bd9e8999872 (patch) | |
tree | b62840d2b95c30686ca55fd5ad9536435b0c1f91 /archiva-modules/archiva-base | |
parent | 831a518f977aed367f2a35ba2c526b4c1e6b5969 (diff) | |
download | archiva-4fe4dc198e8ba22e532fcb17412d1bd9e8999872.tar.gz archiva-4fe4dc198e8ba22e532fcb17412d1bd9e8999872.zip |
[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
Diffstat (limited to 'archiva-modules/archiva-base')
4 files changed, 258 insertions, 5 deletions
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<ManagedRepositoryConfiguration>) 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 = "<configuration>" + + FileUtils.readFileToString( getTestFile( "target/test-classes/org/apache/maven/archiva/configuration/test-default-archiva.xml" ) ) + + "</configuration>"; + 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 @@ <component-set> <components> + + <component> + <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> + <role-hint>test-defaults-default-repo-location-exists</role-hint> + <implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> + <requirements> + <requirement> + <role>org.codehaus.plexus.registry.Registry</role> + <role-hint>empty</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> + </component> + <component> <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> <role-hint>test-defaults</role-hint> 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 @@ + <version>2</version> + <managedRepositories> + <managedRepository> + <id>internal</id> + <name>Archiva Managed Internal Repository</name> + <location>${appserver.base}/target/test-classes/existing_internal</location> + <layout>default</layout> + <releases>true</releases> + <snapshots>false</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0 * * * ?</refreshCronExpression> + <daysOlder>30</daysOlder> + </managedRepository> + <managedRepository> + <id>snapshots</id> + <name>Archiva Managed Snapshot Repository</name> + <location>${appserver.base}/target/test-classes/existing_snapshots</location> + <layout>default</layout> + <releases>false</releases> + <snapshots>true</snapshots> + <scanned>true</scanned> + <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression> + <daysOlder>30</daysOlder> + </managedRepository> + </managedRepositories> + <remoteRepositories> + <remoteRepository> + <id>central</id> + <name>Central Repository</name> + <url>http://repo1.maven.org/maven2</url> + <layout>default</layout> + </remoteRepository> + <remoteRepository> + <id>maven2-repository.dev.java.net</id> + <name>Java.net Repository for Maven 2</name> + <url>http://download.java.net/maven/2/</url> + <layout>default</layout> + </remoteRepository> + </remoteRepositories> + + <proxyConnectors> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>central</targetRepoId> + <proxyId/> + <policies> + <snapshots>disabled</snapshots> + <releases>once</releases> + <checksum>fix</checksum> + <cache-failures>cached</cache-failures> + </policies> + <whiteListPatterns> + <whiteListPattern>**/*</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + <proxyConnector> + <sourceRepoId>internal</sourceRepoId> + <targetRepoId>maven2-repository.dev.java.net</targetRepoId> + <proxyId/> + <policies> + <snapshots>disabled</snapshots> + <releases>once</releases> + <checksum>fix</checksum> + <cache-failures>cached</cache-failures> + </policies> + <whiteListPatterns> + <whiteListPattern>javax/**</whiteListPattern> + <whiteListPattern>org/jvnet/**</whiteListPattern> + <whiteListPattern>com/sun/**</whiteListPattern> + </whiteListPatterns> + </proxyConnector> + </proxyConnectors> + + <legacyArtifactPaths> + <legacyArtifactPath> + <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path> + <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact> + </legacyArtifactPath> + </legacyArtifactPaths> + + <repositoryScanning> + <fileTypes> + <fileType> + <id>artifacts</id> + <patterns> + <pattern>**/*.pom</pattern> + <pattern>**/*.jar</pattern> + <pattern>**/*.ear</pattern> + <pattern>**/*.war</pattern> + <pattern>**/*.car</pattern> + <pattern>**/*.sar</pattern> + <pattern>**/*.mar</pattern> + <pattern>**/*.rar</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + <pattern>**/*.tar.gz</pattern> + <pattern>**/*.tar.bz2</pattern> + <pattern>**/*.zip</pattern> + </patterns> + </fileType> + <fileType> + <id>indexable-content</id> + <patterns> + <pattern>**/*.txt</pattern> + <pattern>**/*.TXT</pattern> + <pattern>**/*.block</pattern> + <pattern>**/*.config</pattern> + <pattern>**/*.pom</pattern> + <pattern>**/*.xml</pattern> + <pattern>**/*.xsd</pattern> + <pattern>**/*.dtd</pattern> + <pattern>**/*.tld</pattern> + </patterns> + </fileType> + <fileType> + <id>auto-remove</id> + <patterns> + <pattern>**/*.bak</pattern> + <pattern>**/*~</pattern> + <pattern>**/*-</pattern> + </patterns> + </fileType> + <fileType> + <id>ignored</id> + <patterns> + <pattern>**/.htaccess</pattern> + <pattern>**/KEYS</pattern> + <pattern>**/*.rb</pattern> + <pattern>**/*.sh</pattern> + <pattern>**/.svn/**</pattern> + <pattern>**/.DAV/**</pattern> + </patterns> + </fileType> + </fileTypes> + <knownContentConsumers> + <knownContentConsumer>update-db-artifact</knownContentConsumer> + <knownContentConsumer>create-missing-checksums</knownContentConsumer> + <knownContentConsumer>update-db-repository-metadata</knownContentConsumer> + <knownContentConsumer>validate-checksum</knownContentConsumer> + <knownContentConsumer>validate-signature</knownContentConsumer> + <knownContentConsumer>index-content</knownContentConsumer> + <knownContentConsumer>auto-remove</knownContentConsumer> + <knownContentConsumer>auto-rename</knownContentConsumer> + <knownContentConsumer>metadata-updater</knownContentConsumer> + <!--knownContentConsumer>repository-purge</knownContentConsumer--> + </knownContentConsumers> + <invalidContentConsumers> + <invalidContentConsumer>update-db-bad-content</invalidContentConsumer> + </invalidContentConsumers> + </repositoryScanning> + + <databaseScanning> + <cronExpression>0 0 * * * ?</cronExpression> + <unprocessedConsumers> + <unprocessedConsumer>index-artifact</unprocessedConsumer> + <unprocessedConsumer>update-db-project</unprocessedConsumer> + <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> + <unprocessedConsumer>index-archive-toc</unprocessedConsumer> + <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> + <unprocessedConsumer>index-public-methods</unprocessedConsumer> + </unprocessedConsumers> + <cleanupConsumers> + <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer> + <cleanupConsumer>not-present-remove-db-project</cleanupConsumer> + <cleanupConsumer>not-present-remove-indexed</cleanupConsumer> + </cleanupConsumers> + </databaseScanning> + + <webapp> + <ui> + <showFindArtifacts>true</showFindArtifacts> + <appletFindEnabled>true</appletFindEnabled> + </ui> + </webapp> |