From 7d462ad3fe096105bf6f2c1f142fb754b10dc244 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Tue, 16 Feb 2010 12:44:12 +0000 Subject: [PATCH] [MRM-1282] move the content into the repository data directory git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@910504 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/MetadataRepository.java | 1 + .../plugins/metadata-repository-file/pom.xml | 4 + .../file/FileMetadataRepository.java | 74 ++++++++++--------- .../file/FileMetadataRepositoryTest.java | 37 ++++++---- 4 files changed, 68 insertions(+), 48 deletions(-) diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 437972390..77002d6c4 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -63,6 +63,7 @@ public interface MetadataRepository List getArtifactsByDateRange( String repoId, Date startTime, Date endTime ); + // TODO: remove from API, just use configuration Collection getRepositories(); List getArtifactsByChecksum( String repoId, String checksum ); diff --git a/archiva-modules/plugins/metadata-repository-file/pom.xml b/archiva-modules/plugins/metadata-repository-file/pom.xml index f9188f8b3..e93da3c15 100644 --- a/archiva-modules/plugins/metadata-repository-file/pom.xml +++ b/archiva-modules/plugins/metadata-repository-file/pom.xml @@ -28,6 +28,10 @@ metadata-repository-file File System Backed Metadata Repository + + org.apache.archiva + archiva-configuration + org.apache.archiva metadata-repository-api diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index a6ec061ba..985c646c5 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -54,6 +53,7 @@ import org.apache.archiva.metadata.model.Scm; import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,16 +64,14 @@ public class FileMetadataRepository implements MetadataRepository { /** - * TODO: this isn't suitable for production use - * - * @plexus.configuration + * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory" */ - private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" ); + private Map metadataFacetFactories; /** - * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory" + * @plexus.requirement */ - private Map metadataFacetFactories; + private ArchivaConfiguration configuration; private static final Logger log = LoggerFactory.getLogger( FileMetadataRepository.class ); @@ -85,6 +83,19 @@ public class FileMetadataRepository private static final String METADATA_KEY = "metadata"; + private File getBaseDirectory( String repoId ) + { + // TODO: should be configurable, like the index + String basedir = configuration.getConfiguration().getManagedRepositoriesAsMap().get( repoId ).getLocation(); + File dir = new File( basedir, ".archiva" ); + return dir; + } + + private File getDirectory( String repoId ) + { + return new File( getBaseDirectory( repoId ), "content" ); + } + public void updateProject( String repoId, ProjectMetadata project ) { updateProject( repoId, project.getNamespace(), project.getId() ); @@ -97,7 +108,7 @@ public class FileMetadataRepository try { - File namespaceDirectory = new File( this.directory, repoId + "/" + namespace ); + File namespaceDirectory = new File( getDirectory( repoId ), namespace ); Properties properties = new Properties(); properties.setProperty( "namespace", namespace ); properties.setProperty( "id", id ); @@ -116,7 +127,7 @@ public class FileMetadataRepository updateProject( repoId, namespace, projectId ); File directory = - new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + versionMetadata.getId() ); + new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + versionMetadata.getId() ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); // remove properties that are not references or artifacts @@ -207,7 +218,7 @@ public class FileMetadataRepository public void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion, ProjectVersionReference reference ) { - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); int i = Integer.valueOf( properties.getProperty( "ref:lastReferenceNum", "-1" ) ) + 1; @@ -232,7 +243,7 @@ public class FileMetadataRepository { try { - File namespaceDirectory = new File( this.directory, repoId + "/" + namespace ); + File namespaceDirectory = new File( getDirectory( repoId ), namespace ); Properties properties = new Properties(); properties.setProperty( "namespace", namespace ); writeProperties( properties, namespaceDirectory, NAMESPACE_METADATA_KEY ); @@ -395,7 +406,7 @@ public class FileMetadataRepository { Map artifacts = new HashMap(); - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); @@ -452,8 +463,7 @@ public class FileMetadataRepository public Collection getRepositories() { - String[] repoIds = this.directory.list(); - return repoIds != null ? Arrays.asList( repoIds ) : Collections.emptyList(); + return configuration.getConfiguration().getManagedRepositoriesAsMap().keySet(); } public List getArtifactsByChecksum( String repositoryId, String checksum ) @@ -471,9 +481,9 @@ public class FileMetadataRepository return artifacts; } - public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ) + public void deleteArtifact( String repoId, String namespace, String project, String version, String id ) { - File directory = new File( this.directory, repositoryId + "/" + namespace + "/" + project + "/" + version ); + File directory = new File( getDirectory( repoId ), namespace + "/" + project + "/" + version ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); @@ -497,11 +507,9 @@ public class FileMetadataRepository public void deleteRepository( String repoId ) { - File directory = new File( this.directory, repoId ); - try { - FileUtils.deleteDirectory( directory ); + FileUtils.deleteDirectory( getDirectory( repoId ) ); } catch ( IOException e ) { @@ -533,9 +541,9 @@ public class FileMetadataRepository } } - private File getMetadataDirectory( String repositoryId, String facetId ) + private File getMetadataDirectory( String repoId, String facetId ) { - return new File( this.directory, repositoryId + "/.meta/" + facetId ); + return new File( getBaseDirectory( repoId ), "facets/" + facetId ); } private String join( Collection ids ) @@ -564,7 +572,7 @@ public class FileMetadataRepository public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifact ) { - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); @@ -631,7 +639,7 @@ public class FileMetadataRepository public ProjectMetadata getProject( String repoId, String namespace, String projectId ) { - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); @@ -644,7 +652,7 @@ public class FileMetadataRepository public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) { - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); String id = properties.getProperty( "id" ); @@ -809,7 +817,7 @@ public class FileMetadataRepository public Collection getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion ) { - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); @@ -828,7 +836,7 @@ public class FileMetadataRepository public Collection getProjectReferences( String repoId, String namespace, String projectId, String projectVersion ) { - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); int numberOfRefs = Integer.valueOf( properties.getProperty( "ref:lastReferenceNum", "-1" ) ) + 1; @@ -855,7 +863,7 @@ public class FileMetadataRepository public Collection getNamespaces( String repoId, String baseNamespace ) { List allNamespaces = new ArrayList(); - File directory = new File( this.directory, repoId ); + File directory = getDirectory( repoId ); File[] files = directory.listFiles(); if ( files != null ) { @@ -891,7 +899,7 @@ public class FileMetadataRepository public Collection getProjects( String repoId, String namespace ) { List projects = new ArrayList(); - File directory = new File( this.directory, repoId + "/" + namespace ); + File directory = new File( getDirectory( repoId ), namespace ); File[] files = directory.listFiles(); if ( files != null ) { @@ -909,7 +917,7 @@ public class FileMetadataRepository public Collection getProjectVersions( String repoId, String namespace, String projectId ) { List projectVersions = new ArrayList(); - File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId ); + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId ); File[] files = directory.listFiles(); if ( files != null ) { @@ -939,13 +947,13 @@ public class FileMetadataRepository } } - public void setDirectory( File directory ) + public void setMetadataFacetFactories( Map metadataFacetFactories ) { - this.directory = directory; + this.metadataFacetFactories = metadataFacetFactories; } - public void setMetadataFacetFactories( Map metadataFacetFactories ) + public void setConfiguration( ArchivaConfiguration configuration ) { - this.metadataFacetFactories = metadataFacetFactories; + this.configuration = configuration; } } diff --git a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java index ed71d570b..b3150cc86 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java @@ -37,7 +37,11 @@ import org.apache.archiva.metadata.model.MetadataFacetFactory; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.commons.io.FileUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.easymock.MockControl; /** * @todo should this be a generic MetadataRepository implementation test? @@ -77,9 +81,17 @@ public class FileMetadataRepositoryTest super.setUp(); repository = new FileMetadataRepository(); - File directory = getTestFile( "target/test-repository" ); + File directory = getTestFile( "target/test-repositories" ); FileUtils.deleteDirectory( directory ); - repository.setDirectory( directory ); + + MockControl control = MockControl.createControl( ArchivaConfiguration.class ); + ArchivaConfiguration config = (ArchivaConfiguration) control.getMock(); + Configuration configData = new Configuration(); + configData.addManagedRepository( createManagedRepository( TEST_REPO_ID, directory ) ); + configData.addManagedRepository( createManagedRepository( OTHER_REPO, directory ) ); + control.expectAndDefaultReturn( config.getConfiguration(), configData ); + control.replay(); + repository.setConfiguration( config ); Map factories = new HashMap(); factories.put( TEST_FACET_ID, new MetadataFacetFactory() @@ -111,6 +123,14 @@ public class FileMetadataRepositoryTest repository.setMetadataFacetFactories( factories ); } + private static ManagedRepositoryConfiguration createManagedRepository( String repoId, File directory ) + { + ManagedRepositoryConfiguration managedRepository = new ManagedRepositoryConfiguration(); + managedRepository.setId( repoId ); + managedRepository.setLocation( new File( directory, repoId ).getAbsolutePath() ); + return managedRepository; + } + public void testRootNamespaceWithNoMetadataRepository() { Collection namespaces = repository.getRootNamespaces( TEST_REPO_ID ); @@ -330,19 +350,6 @@ public class FileMetadataRepositoryTest TEST_PROJECT_VERSION ) ); } - public void testRepositories() - { - repository.addMetadataFacet( TEST_REPO_ID, new TestMetadataFacet( TEST_VALUE ) ); - repository.addMetadataFacet( OTHER_REPO, new TestMetadataFacet( TEST_VALUE ) ); - - assertEquals( Arrays.asList( OTHER_REPO, TEST_REPO_ID ), repository.getRepositories() ); - } - - public void testRepositoriesWhenEmpty() - { - assertTrue( repository.getRepositories().isEmpty() ); - } - public void testGetArtifactsByDateRangeOpen() { repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE ); -- 2.39.5