aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/plugins
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2010-02-16 12:44:12 +0000
committerBrett Porter <brett@apache.org>2010-02-16 12:44:12 +0000
commit7d462ad3fe096105bf6f2c1f142fb754b10dc244 (patch)
treef41744d88a872df89c715dd91913be91bfe1bcac /archiva-modules/plugins
parent74d0a6376f0fc4a438ce537a8f9a908cd50face3 (diff)
downloadarchiva-7d462ad3fe096105bf6f2c1f142fb754b10dc244.tar.gz
archiva-7d462ad3fe096105bf6f2c1f142fb754b10dc244.zip
[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
Diffstat (limited to 'archiva-modules/plugins')
-rw-r--r--archiva-modules/plugins/metadata-repository-file/pom.xml4
-rw-r--r--archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java74
-rw-r--r--archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java37
3 files changed, 67 insertions, 48 deletions
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
@@ -30,6 +30,10 @@
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-configuration</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
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<String, MetadataFacetFactory> metadataFacetFactories;
/**
- * @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
+ * @plexus.requirement
*/
- private Map<String, MetadataFacetFactory> 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<String, ArtifactMetadata> artifacts = new HashMap<String, ArtifactMetadata>();
- 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<String> getRepositories()
{
- String[] repoIds = this.directory.list();
- return repoIds != null ? Arrays.asList( repoIds ) : Collections.<String>emptyList();
+ return configuration.getConfiguration().getManagedRepositoriesAsMap().keySet();
}
public List<ArtifactMetadata> 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<String> 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<String> 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<ProjectVersionReference> 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<String> getNamespaces( String repoId, String baseNamespace )
{
List<String> allNamespaces = new ArrayList<String>();
- 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<String> getProjects( String repoId, String namespace )
{
List<String> projects = new ArrayList<String>();
- 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<String> getProjectVersions( String repoId, String namespace, String projectId )
{
List<String> projectVersions = new ArrayList<String>();
- 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<String, MetadataFacetFactory> metadataFacetFactories )
{
- this.directory = directory;
+ this.metadataFacetFactories = metadataFacetFactories;
}
- public void setMetadataFacetFactories( Map<String, MetadataFacetFactory> 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<String, MetadataFacetFactory> factories = new HashMap<String, MetadataFacetFactory>();
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<String> 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 );