mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 09:24:54 +00:00
[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
This commit is contained in:
parent
74d0a6376f
commit
7d462ad3fe
@ -63,6 +63,7 @@ void updateProjectReference( String repoId, String namespace, String projectId,
|
||||
|
||||
List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime );
|
||||
|
||||
// TODO: remove from API, just use configuration
|
||||
Collection<String> getRepositories();
|
||||
|
||||
List<ArtifactMetadata> getArtifactsByChecksum( String repoId, String checksum );
|
||||
|
@ -28,6 +28,10 @@
|
||||
<artifactId>metadata-repository-file</artifactId>
|
||||
<name>File System Backed Metadata Repository</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-configuration</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>metadata-repository-api</artifactId>
|
||||
|
@ -27,7 +27,6 @@
|
||||
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.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;
|
||||
|
||||
@ -63,18 +63,16 @@
|
||||
public class FileMetadataRepository
|
||||
implements MetadataRepository
|
||||
{
|
||||
/**
|
||||
* TODO: this isn't suitable for production use
|
||||
*
|
||||
* @plexus.configuration
|
||||
*/
|
||||
private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
|
||||
|
||||
/**
|
||||
* @plexus.requirement role="org.apache.archiva.metadata.model.MetadataFacetFactory"
|
||||
*/
|
||||
private Map<String, MetadataFacetFactory> metadataFacetFactories;
|
||||
|
||||
/**
|
||||
* @plexus.requirement
|
||||
*/
|
||||
private ArchivaConfiguration configuration;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger( FileMetadataRepository.class );
|
||||
|
||||
private static final String PROJECT_METADATA_KEY = "project-metadata";
|
||||
@ -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 @@ private void updateProject( String repoId, String namespace, String id )
|
||||
|
||||
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 void updateProjectVersion( String repoId, String namespace, String projec
|
||||
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 void updateProjectVersion( String repoId, String namespace, String projec
|
||||
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 void updateNamespace( String repoId, String namespace )
|
||||
{
|
||||
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 Collection<ArtifactMetadata> getArtifacts( String repoId, String namespac
|
||||
{
|
||||
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 @@ else if ( "sha1".equals( field ) )
|
||||
|
||||
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 List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, Strin
|
||||
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 void deleteArtifact( String repositoryId, String namespace, String projec
|
||||
|
||||
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 @@ private void getArtifactsByChecksum( List<ArtifactMetadata> artifacts, String re
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ private void setProperty( Properties properties, String name, String value )
|
||||
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 @@ private Properties readProperties( File directory, String propertiesKey )
|
||||
|
||||
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 ProjectMetadata getProject( String repoId, String namespace, String proje
|
||||
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 ProjectVersionMetadata getProjectVersion( String repoId, String namespace
|
||||
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 Collection<String> getArtifactVersions( String repoId, String namespace,
|
||||
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 Collection<String> getRootNamespaces( String repoId )
|
||||
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 Collection<String> getNamespaces( String repoId, String baseNamespace )
|
||||
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 Collection<String> getProjects( String repoId, String namespace )
|
||||
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 @@ private void writeProperties( Properties properties, File directory, String prop
|
||||
}
|
||||
}
|
||||
|
||||
public void setDirectory( File directory )
|
||||
{
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
public void setMetadataFacetFactories( Map<String, MetadataFacetFactory> metadataFacetFactories )
|
||||
{
|
||||
this.metadataFacetFactories = metadataFacetFactories;
|
||||
}
|
||||
|
||||
public void setConfiguration( ArchivaConfiguration configuration )
|
||||
{
|
||||
this.configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,11 @@
|
||||
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 void setUp()
|
||||
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 MetadataFacet createMetadataFacet( String repositoryId, String name )
|
||||
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 void testGetArtifactVersionsMultipleArtifactsSingleVersion()
|
||||
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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user