[MRM-1327] refactor the repository API to make each concern clearer. Storage, resolver and metadata repository are separate interfaces. Rename methods on the resolver and the storage to be clearer of their intent

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1051788 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-12-22 08:31:56 +00:00
parent f9cd1037d1
commit c63e2a3f77
28 changed files with 567 additions and 527 deletions

View File

@ -25,7 +25,7 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
@ -90,7 +90,7 @@ public class ArchivaMetadataCreationConsumer
*
* @plexus.requirement role-hint="maven2"
*/
private StorageMetadataResolver storageResolver;
private RepositoryStorage repositoryStorage;
private static final Logger log = LoggerFactory.getLogger( ArchivaMetadataCreationConsumer.class );
@ -141,7 +141,7 @@ public class ArchivaMetadataCreationConsumer
// the initial scan. Any request for this information will be intercepted and populated on-demand
// or picked up by subsequent scans
ArtifactMetadata artifact = storageResolver.getArtifactForPath( repoId, path );
ArtifactMetadata artifact = repositoryStorage.readArtifactMetadataFromPath( repoId, path );
ProjectMetadata project = new ProjectMetadata();
project.setNamespace( artifact.getNamespace() );
@ -152,8 +152,8 @@ public class ArchivaMetadataCreationConsumer
ProjectVersionMetadata versionMetadata = null;
try
{
versionMetadata = storageResolver.getProjectVersion( repoId, artifact.getNamespace(), artifact.getProject(),
projectVersion );
versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId, artifact.getNamespace(),
artifact.getProject(), projectVersion );
}
catch ( MetadataResolutionException e )
{

View File

@ -19,17 +19,17 @@ package org.apache.archiva.metadata.repository;
* under the License.
*/
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
public class TestMetadataRepository
implements MetadataRepository
{
@ -144,12 +144,12 @@ public class TestMetadataRepository
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id )
public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void deleteRepository( String repoId )
public void removeRepository( String repoId )
{
//To change body of implemented methods use File | Settings | File Templates.
}
@ -160,7 +160,8 @@ public class TestMetadataRepository
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public List<ArtifactMetadata> getArtifacts(String repositoryId){
public List<ArtifactMetadata> getArtifacts( String repositoryId )
{
return null;
}
}

View File

@ -19,15 +19,8 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.ProjectMetadata;
@ -38,8 +31,14 @@ import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.rss.RssFeedGenerator;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
public class NewArtifactsRssFeedProcessorTest
extends PlexusInSpringTestCase
@ -95,13 +94,14 @@ public class NewArtifactsRssFeedProcessorTest
assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
assertTrue( feed.getDescription().equals(
"New artifacts found in repository 'test-repo' during repository scan." ) );
"New artifacts found in repository 'test-repo' during repository scan." ) );
assertTrue( feed.getLanguage().equals( "en-us" ) );
assertTrue( feed.getPublishedDate().equals( whenGathered ) );
List<SyndEntry> entries = feed.getEntries();
assertEquals( entries.size(), 1 );
assertTrue( entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
assertTrue( entries.get( 0 ).getTitle().equals(
"New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );
}
@ -140,12 +140,12 @@ public class NewArtifactsRssFeedProcessorTest
throw new UnsupportedOperationException();
}
public void deleteArtifact( String arg0, String arg1, String arg2, String arg3, String arg4 )
public void removeArtifact( String arg0, String arg1, String arg2, String arg3, String arg4 )
{
throw new UnsupportedOperationException();
}
public void deleteRepository( String arg0 )
public void removeRepository( String arg0 )
{
throw new UnsupportedOperationException();
}
@ -287,10 +287,10 @@ public class NewArtifactsRssFeedProcessorTest
{
this.artifactsByDateRange = artifactsByDateRange;
}
public List<ArtifactMetadata> getArtifacts( String repositoryId )
{
return artifactsByDateRange;
return artifactsByDateRange;
}
}
}

View File

@ -78,7 +78,7 @@ public class BrowseAction
Set<String> namespacesToCollapse = new LinkedHashSet<String>();
for ( String repoId : selectedRepos )
{
namespacesToCollapse.addAll( metadataResolver.getRootNamespaces( repoId ) );
namespacesToCollapse.addAll( metadataResolver.resolveRootNamespaces( repoId ) );
}
for ( String n : namespacesToCollapse )
@ -97,7 +97,7 @@ public class BrowseAction
Set<String> subNamespaces = new LinkedHashSet<String>();
for ( String repoId : repoIds )
{
subNamespaces.addAll( metadataResolver.getNamespaces( repoId, n ) );
subNamespaces.addAll( metadataResolver.resolveNamespaces( repoId, n ) );
}
if ( subNamespaces.size() != 1 )
{
@ -111,7 +111,7 @@ public class BrowseAction
{
for ( String repoId : repoIds )
{
Collection<String> projects = metadataResolver.getProjects( repoId, n );
Collection<String> projects = metadataResolver.resolveProjects( repoId, n );
if ( projects != null && !projects.isEmpty() )
{
if ( log.isDebugEnabled() )
@ -146,9 +146,9 @@ public class BrowseAction
Set<String> namespacesToCollapse = new LinkedHashSet<String>();
for ( String repoId : selectedRepos )
{
namespacesToCollapse.addAll( metadataResolver.getNamespaces( repoId, groupId ) );
namespacesToCollapse.addAll( metadataResolver.resolveNamespaces( repoId, groupId ) );
projects.addAll( metadataResolver.getProjects( repoId, groupId ) );
projects.addAll( metadataResolver.resolveProjects( repoId, groupId ) );
}
// TODO: this logic should be optional, particularly remembering we want to keep this code simple
@ -199,7 +199,7 @@ public class BrowseAction
Set<String> versions = new LinkedHashSet<String>();
for ( String repoId : selectedRepos )
{
versions.addAll( metadataResolver.getProjectVersions( repoId, groupId, artifactId ) );
versions.addAll( metadataResolver.resolveProjectVersions( repoId, groupId, artifactId ) );
}
// TODO: sort by known version ordering method
@ -230,7 +230,8 @@ public class BrowseAction
{
try
{
versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
versionMetadata = metadataResolver.resolveProjectVersion( repoId, groupId, artifactId,
version );
}
catch ( MetadataResolutionException e )
{

View File

@ -238,7 +238,7 @@ public class DeleteArtifactAction
// TODO: mismatch between artifact (snapshot) version and project (base) version here
if ( artifact.getVersion().equals( version ) )
{
metadataRepository.deleteArtifact( artifact.getRepositoryId(), artifact.getNamespace(),
metadataRepository.removeArtifact( artifact.getRepositoryId(), artifact.getNamespace(),
artifact.getProject(), artifact.getVersion(), artifact.getId() );
// TODO: move into the metadata repository proper - need to differentiate attachment of

View File

@ -157,7 +157,7 @@ public class ShowArtifactAction
// "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
try
{
versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
versionMetadata = metadataResolver.resolveProjectVersion( repoId, groupId, artifactId, version );
}
catch ( MetadataResolutionException e )
{
@ -174,9 +174,9 @@ public class ShowArtifactAction
List<ArtifactMetadata> artifacts;
try
{
artifacts = new ArrayList<ArtifactMetadata>( metadataResolver.getArtifacts( repoId, groupId,
artifactId,
version ) );
artifacts = new ArrayList<ArtifactMetadata>( metadataResolver.resolveArtifacts( repoId, groupId,
artifactId,
version ) );
}
catch ( MetadataResolutionException e )
{
@ -265,7 +265,7 @@ public class ShowArtifactAction
for ( String repoId : getObservableRepos() )
{
// TODO: what about if we want to see this irrespective of version?
references.addAll( metadataResolver.getProjectReferences( repoId, groupId, artifactId, version ) );
references.addAll( metadataResolver.resolveProjectReferences( repoId, groupId, artifactId, version ) );
}
this.dependees = references;

View File

@ -187,7 +187,7 @@ public class DeleteManagedRepositoryAction
private void cleanupDatabase( String repoId )
throws MetadataRepositoryException
{
metadataRepository.deleteRepository( repoId );
metadataRepository.removeRepository( repoId );
}
public ManagedRepositoryConfiguration getRepository()

View File

@ -184,12 +184,12 @@ public class TestMetadataRepository
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id )
public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void deleteRepository( String repoId )
public void removeRepository( String repoId )
{
//To change body of implemented methods use File | Settings | File Templates.
}
@ -200,7 +200,8 @@ public class TestMetadataRepository
return artifacts;
}
public List<ArtifactMetadata> getArtifacts(String repositoryId){
public List<ArtifactMetadata> getArtifacts( String repositoryId )
{
return artifacts;
}
}

View File

@ -19,6 +19,11 @@ package org.apache.archiva.metadata.repository.memory;
* under the License.
*/
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolver;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@ -27,12 +32,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataResolver;
public class TestMetadataResolver
implements MetadataResolver
{
@ -49,38 +48,24 @@ public class TestMetadataResolver
private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
{
ProjectMetadata metadata = new ProjectMetadata();
metadata.setNamespace( namespace );
metadata.setId( projectId );
return metadata;
}
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
public ProjectVersionMetadata resolveProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
{
return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
String projectVersion )
{
throw new UnsupportedOperationException();
}
public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<ProjectVersionReference> resolveProjectReferences( String repoId, String namespace,
String projectId, String projectVersion )
{
return references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
}
public Collection<String> getRootNamespaces( String repoId )
public Collection<String> resolveRootNamespaces( String repoId )
{
return getNamespaces( repoId, null );
return resolveNamespaces( repoId, null );
}
public Collection<String> getNamespaces( String repoId, String baseNamespace )
public Collection<String> resolveNamespaces( String repoId, String baseNamespace )
{
Set<String> namespaces = new LinkedHashSet<String>();
int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
@ -102,23 +87,23 @@ public class TestMetadataResolver
return namespaces;
}
public Collection<String> getProjects( String repoId, String namespace )
public Collection<String> resolveProjects( String repoId, String namespace )
{
Collection<String> list = projectsInNamespace.get( namespace );
return list != null ? list : Collections.<String>emptyList();
}
public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
public Collection<String> resolveProjectVersions( String repoId, String namespace, String projectId )
{
Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
return list != null ? list : Collections.<String>emptyList();
}
public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<ArtifactMetadata> resolveArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
{
List<ArtifactMetadata> artifacts =
this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
List<ArtifactMetadata> artifacts = this.artifacts.get( createMapKey( repoId, namespace, projectId,
projectVersion ) );
return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
}

View File

@ -95,7 +95,7 @@ public class DeleteManagedRepositoryActionTest
MockControl metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
MetadataRepository metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
metadataRepository.deleteRepository( REPO_ID );
metadataRepository.removeRepository( REPO_ID );
action.setMetadataRepository( metadataRepository );
metadataRepositoryControl.replay();
@ -178,7 +178,7 @@ public class DeleteManagedRepositoryActionTest
{
MockControl metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
MetadataRepository metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
metadataRepository.deleteRepository( REPO_ID );
metadataRepository.removeRepository( REPO_ID );
metadataRepositoryControl.replay();
action.setMetadataRepository( metadataRepository );
return metadataRepositoryControl;

View File

@ -19,17 +19,17 @@ package org.apache.archiva.metadata.repository;
* under the License.
*/
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
public class TestMetadataRepository
implements MetadataRepository
{
@ -144,12 +144,12 @@ public class TestMetadataRepository
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id )
public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void deleteRepository( String repoId )
public void removeRepository( String repoId )
{
//To change body of implemented methods use File | Settings | File Templates.
}
@ -159,7 +159,9 @@ public class TestMetadataRepository
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public List<ArtifactMetadata> getArtifacts(String repositoryId){
public List<ArtifactMetadata> getArtifacts( String repositoryId )
{
return null;
}
}

View File

@ -66,7 +66,7 @@ import java.util.Map;
/**
* AdministrationServiceImpl
*
*
* @version $Id: AdministrationServiceImpl.java
*/
public class AdministrationServiceImpl
@ -197,15 +197,15 @@ public class AdministrationServiceImpl
// delete from file system
repoContent.deleteVersion( ref );
Collection<ArtifactMetadata> artifacts =
metadataRepository.getArtifacts( repoId, groupId, artifactId, version );
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, groupId, artifactId,
version );
for ( ArtifactMetadata artifact : artifacts )
{
// TODO: mismatch between artifact (snapshot) version and project (base) version here
if ( artifact.getVersion().equals( version ) )
{
metadataRepository.deleteArtifact( artifact.getRepositoryId(), artifact.getNamespace(),
metadataRepository.removeArtifact( artifact.getRepositoryId(), artifact.getNamespace(),
artifact.getProject(), artifact.getVersion(), artifact.getId() );
// TODO: move into the metadata repository proper - need to differentiate attachment of
@ -295,9 +295,9 @@ public class AdministrationServiceImpl
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
// TODO fix resolution of repo url!
ManagedRepository repo =
new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL", repoConfig.getLayout(),
repoConfig.isSnapshots(), repoConfig.isReleases() );
ManagedRepository repo = new ManagedRepository( repoConfig.getId(), repoConfig.getName(), "URL",
repoConfig.getLayout(), repoConfig.isSnapshots(),
repoConfig.isReleases() );
managedRepos.add( repo );
}
@ -316,9 +316,8 @@ public class AdministrationServiceImpl
for ( RemoteRepositoryConfiguration repoConfig : remoteRepoConfigs )
{
RemoteRepository repo =
new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
repoConfig.getLayout() );
RemoteRepository repo = new RemoteRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getUrl(),
repoConfig.getLayout() );
remoteRepos.add( repo );
}
@ -354,18 +353,18 @@ public class AdministrationServiceImpl
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
{
throw new Exception( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a managed repository." );
throw new Exception( "Unable to add new repository with id [" + repoId +
"], that id already exists as a managed repository." );
}
else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
{
throw new Exception( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a remote repository." );
throw new Exception( "Unable to add new repository with id [" + repoId +
"], that id already exists as a remote repository." );
}
else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
{
throw new Exception( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a repository group." );
throw new Exception( "Unable to add new repository with id [" + repoId +
"], that id already exists as a repository group." );
}
if ( !validator.validate( cronExpression ) )
@ -408,7 +407,7 @@ public class AdministrationServiceImpl
throw new Exception( "A repository with that id does not exist" );
}
metadataRepository.deleteRepository( repository.getId() );
metadataRepository.removeRepository( repository.getId() );
repositoryStatisticsManager.deleteStatistics( repository.getId() );
config.removeManagedRepository( repository );
@ -440,7 +439,8 @@ public class AdministrationServiceImpl
List<String> repoGroups = repoToGroupMap.get( repository.getId() );
for ( String repoGroup : repoGroups )
{
archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository( repository.getId() );
archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroup ).removeRepository(
repository.getId() );
}
}
}
@ -457,10 +457,9 @@ public class AdministrationServiceImpl
{
throw new Exception( "A repository with that id does not exist" );
}
ManagedRepository repo =
new ManagedRepository( managedRepository.getId(), managedRepository.getName(), "URL",
managedRepository.getLayout(), managedRepository.isSnapshots(),
managedRepository.isReleases() );
ManagedRepository repo = new ManagedRepository( managedRepository.getId(), managedRepository.getName(), "URL",
managedRepository.getLayout(), managedRepository.isSnapshots(),
managedRepository.isReleases() );
return repo;
}
@ -490,16 +489,16 @@ public class AdministrationServiceImpl
log.info( "Repository to be merged contains releases only.." );
if ( skipConflicts )
{
List<ArtifactMetadata> conflicts =
repositoryMerger.getConflictingArtifacts( repoId, stagingId );
List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( repoId,
stagingId );
if ( log.isDebugEnabled() )
{
log.debug( "Artifacts in conflict.." );
for( ArtifactMetadata metadata : conflicts )
for ( ArtifactMetadata metadata : conflicts )
{
log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
metadata.getProjectVersion() );
metadata.getProjectVersion() );
}
}
@ -519,16 +518,16 @@ public class AdministrationServiceImpl
log.info( "Repository to be merged has snapshot artifacts.." );
if ( skipConflicts )
{
List<ArtifactMetadata> conflicts =
repositoryMerger.getConflictingArtifacts( repoId, stagingId );
List<ArtifactMetadata> conflicts = repositoryMerger.getConflictingArtifacts( repoId,
stagingId );
if ( log.isDebugEnabled() )
{
log.debug( "Artifacts in conflict.." );
for( ArtifactMetadata metadata : conflicts )
for ( ArtifactMetadata metadata : conflicts )
{
log.debug( metadata.getNamespace() + ":" + metadata.getProject() + ":" +
metadata.getProjectVersion() );
metadata.getProjectVersion() );
}
}
@ -536,19 +535,21 @@ public class AdministrationServiceImpl
log.debug( "Source artifacts size :: " + sourceArtifacts.size() );
Filter<ArtifactMetadata> artifactsWithOutConflicts =
new IncludesFilter<ArtifactMetadata>( sourceArtifacts );
Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(
sourceArtifacts );
repositoryMerger.merge( stagingId, repoId, artifactsWithOutConflicts );
log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
repoId + "'." );
log.info(
"Staging repository '" + stagingId + "' merged successfully with managed repo '" + repoId +
"'." );
}
else
{
repositoryMerger.merge( stagingId, repoId );
log.info( "Staging repository '" + stagingId + "' merged successfully with managed repo '" +
repoId + "'." );
log.info(
"Staging repository '" + stagingId + "' merged successfully with managed repo '" + repoId +
"'." );
}
}
}
@ -593,8 +594,8 @@ public class AdministrationServiceImpl
}
if ( !file.exists() || !file.isDirectory() )
{
throw new IOException( "Unable to add repository - no write access, can not create the root directory: "
+ file );
throw new IOException(
"Unable to add repository - no write access, can not create the root directory: " + file );
}
configuration.addManagedRepository( repository );

View File

@ -61,7 +61,7 @@ public class SearchServiceImpl
this.metadataRepository = metadataRepository;
}
@SuppressWarnings("unchecked")
@SuppressWarnings( "unchecked" )
public List<Artifact> quickSearch( String queryString )
throws Exception
{
@ -85,9 +85,9 @@ public class SearchServiceImpl
// slight behaviour change to previous implementation: instead of allocating "jar" when not
// found in the database, we can rely on the metadata repository to create it on the fly. We
// just allocate the default packaging if the Maven facet is not found.
FacetedMetadata model =
metadataResolver.getProjectVersion( repoId, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
FacetedMetadata model = metadataResolver.resolveProjectVersion( repoId, resultHit.getGroupId(),
resultHit.getArtifactId(),
version );
if ( model != null )
{
@ -143,7 +143,7 @@ public class SearchServiceImpl
for ( String repoId : observableRepos )
{
Collection<String> results = metadataResolver.getProjectVersions( repoId, groupId, artifactId );
Collection<String> results = metadataResolver.resolveProjectVersions( repoId, groupId, artifactId );
for ( final String version : results )
{
@ -176,16 +176,16 @@ public class SearchServiceImpl
for ( String repoId : observableRepos )
{
ProjectVersionMetadata model = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
ProjectVersionMetadata model = metadataResolver.resolveProjectVersion( repoId, groupId, artifactId,
version );
if ( model != null )
{
List<Dependency> dependencies = new ArrayList<Dependency>();
List<org.apache.archiva.metadata.model.Dependency> modelDeps = model.getDependencies();
for ( org.apache.archiva.metadata.model.Dependency dep : modelDeps )
{
Dependency dependency =
new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(),
dep.getType(), dep.getScope() );
Dependency dependency = new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(),
dep.getClassifier(), dep.getType(), dep.getScope() );
dependencies.add( dependency );
}
return dependencies;
@ -211,12 +211,12 @@ public class SearchServiceImpl
for ( String repoId : observableRepos )
{
Collection<ProjectVersionReference> refs =
metadataResolver.getProjectReferences( repoId, groupId, artifactId, version );
Collection<ProjectVersionReference> refs = metadataResolver.resolveProjectReferences( repoId, groupId,
artifactId, version );
for ( ProjectVersionReference ref : refs )
{
artifacts.add(
new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(), "" ) );
artifacts.add( new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(),
"" ) );
}
}

View File

@ -19,15 +19,6 @@ package org.apache.archiva.web.xmlrpc.services;
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@ -63,9 +54,18 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
import org.easymock.classextension.MockClassControl;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* AdministrationServiceImplTest
*
*
* @version $Id: AdministrationServiceImplTest.java
*/
public class AdministrationServiceImplTest
@ -174,10 +174,9 @@ public class AdministrationServiceImplTest
auditListenerControl = MockControl.createControl( AuditListener.class );
auditListener = (AuditListener) auditListenerControl.getMock();
service =
new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory, metadataRepository,
repositoryTaskScheduler, Collections.singletonList( listener ),
repositoryStatisticsManager, repositoryMerger, auditListener );
service = new AdministrationServiceImpl( archivaConfig, repoConsumersUtil, repositoryFactory,
metadataRepository, repositoryTaskScheduler, Collections.singletonList(
listener ), repositoryStatisticsManager, repositoryMerger, auditListener );
}
/* Tests for repository consumers */
@ -338,8 +337,9 @@ public class AdministrationServiceImplTest
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(),
artifact.getNamespace(),
artifact.getProject(),
artifact.getVersion() ), artifacts );
metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getVersion() ),
artifacts );
metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getVersion(), artifact.getId() );
listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
@ -394,8 +394,9 @@ public class AdministrationServiceImplTest
metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( repoContent.getId(),
artifact.getNamespace(),
artifact.getProject(),
artifact.getVersion() ), artifacts );
metadataRepository.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getVersion() ),
artifacts );
metadataRepository.removeArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
artifact.getVersion(), artifact.getId() );
listener.deleteArtifact( repoContent.getId(), artifact.getNamespace(), artifact.getProject(),
@ -474,8 +475,8 @@ public class AdministrationServiceImplTest
FileUtils.copyDirectory( srcDir, repoDir, FileFilterUtils.makeSVNAware( null ) );
ManagedRepositoryConfiguration managedRepo =
createManagedRepo( "internal", layout, "Internal Repository", true, false );
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", layout, "Internal Repository", true,
false );
managedRepo.setLocation( repoDir.getAbsolutePath() );
return managedRepo;
}
@ -509,13 +510,16 @@ public class AdministrationServiceImplTest
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), createManagedRepo( "internal",
"default",
"Internal Repository",
true,
false ) );
RepositoryTask task = new RepositoryTask();
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ),
false );
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask(
"internal" ), false );
repositoryTaskScheduler.queueTask( task );
repositoryTaskSchedulerControl.setMatcher( MockControl.ALWAYS_MATCHER );
@ -544,11 +548,14 @@ public class AdministrationServiceImplTest
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), createManagedRepo( "internal",
"default",
"Internal Repository",
true,
false ) );
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask( "internal" ),
true );
repositoryTaskSchedulerControl.expectAndReturn( repositoryTaskScheduler.isProcessingRepositoryTask(
"internal" ), true );
archivaConfigControl.replay();
configControl.replay();
@ -625,7 +632,8 @@ public class AdministrationServiceImplTest
List<RemoteRepositoryConfiguration> remoteRepos = new ArrayList<RemoteRepositoryConfiguration>();
remoteRepos.add( createRemoteRepository( "central", "Central Repository", "default",
"http://repo1.maven.org/maven2" ) );
remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy", "http://dummy.com/dummy" ) );
remoteRepos.add( createRemoteRepository( "dummy", "Dummy Remote Repository", "legacy",
"http://dummy.com/dummy" ) );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.getRemoteRepositories(), remoteRepos );
@ -673,8 +681,9 @@ public class AdministrationServiceImplTest
throws Exception
{
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ),
createManagedRepo( "repo", "default", "repo", true, false ) );
configControl.expectAndReturn( config.findManagedRepositoryById( "repo" ), createManagedRepo( "repo", "default",
"repo", true,
false ) );
configControl.expectAndReturn( config.findManagedRepositoryById( "repo-stage" ), null );
archivaConfigControl.replay();
@ -830,8 +839,8 @@ public class AdministrationServiceImplTest
String stageLocation = releaseLocation + "-stage";
ManagedRepositoryConfiguration managedRepo = createManagedRepo( "repo1", "default", "repo", true, false );
RemoteRepositoryConfiguration remoteRepo =
createRemoteRepository( "central", "Central Repository", "default", "http://repo1.maven.org/maven2" );
RemoteRepositoryConfiguration remoteRepo = createRemoteRepository( "central", "Central Repository", "default",
"http://repo1.maven.org/maven2" );
List<String> repositories = new ArrayList<String>();
repositories.add( managedRepo.getName() );
RepositoryGroupConfiguration repoGroup = createRepoGroupConfig( "repoGroup", repositories );
@ -861,9 +870,8 @@ public class AdministrationServiceImplTest
configControl.replay();
assertFalse( new File( releaseLocation ).isDirectory() );
assertFalse( new File( stageLocation ).isDirectory() );
boolean success =
service.addManagedRepository( repoId, layout, name, releaseLocation, true, true, false, true,
"0 15 3 * * ? *" );
boolean success = service.addManagedRepository( repoId, layout, name, releaseLocation, true, true, false, true,
"0 15 3 * * ? *" );
assertTrue( success );
assertTrue( new File( releaseLocation ).isDirectory() );
assertTrue( new File( stageLocation ).isDirectory() );

View File

@ -134,9 +134,10 @@ public class SearchServiceImplTest
facet.setPackaging( "war" );
model.addFacet( facet );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
model );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "repo1.mirror",
ARCHIVA_TEST_GROUP_ID,
"archiva-webapp", "1.0" ),
model );
userReposControl.replay();
searchControl.replay();
@ -188,15 +189,17 @@ public class SearchServiceImplTest
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
results );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), null );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "repo1.mirror",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), null );
ProjectVersionMetadata model = new ProjectVersionMetadata();
model.setId( "1.0" );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "public.releases",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
userReposControl.replay();
searchControl.replay();
@ -253,9 +256,10 @@ public class SearchServiceImplTest
facet.setPackaging( "jar" );
model.addFacet( facet );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( "repo1.mirror",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
userReposControl.replay();
searchControl.replay();
@ -310,8 +314,8 @@ public class SearchServiceImplTest
public void testGetArtifactByChecksum()
throws Exception
{
userReposControl.expectAndReturn( userRepos.getObservableRepositories(),
Collections.singletonList( TEST_REPO ) );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList(
TEST_REPO ) );
Date whenGathered = new Date();
@ -345,12 +349,14 @@ public class SearchServiceImplTest
observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersions( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ),
Arrays.asList( "1.0", "1.1-beta-2", "1.2" ) );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersions( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ),
Arrays.asList( "1.1-beta-1", "1.1", "1.2.1-SNAPSHOT" ) );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersions( "repo1.mirror",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID ),
Arrays.asList( "1.0", "1.1-beta-2", "1.2" ) );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersions( "public.releases",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID ),
Arrays.asList( "1.1-beta-1", "1.1", "1.2.1-SNAPSHOT" ) );
userReposControl.replay();
metadataResolverControl.replay();
@ -364,19 +370,16 @@ public class SearchServiceImplTest
assertEquals( 6, artifacts.size() );
assertEquals( new Artifact( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0", "pom" ),
artifacts.get( 0 ) );
assertEquals(
new Artifact( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.1-beta-1", "pom" ),
artifacts.get( 3 ) );
assertEquals(
new Artifact( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.1-beta-2", "pom" ),
artifacts.get( 1 ) );
assertEquals( new Artifact( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.1-beta-1",
"pom" ), artifacts.get( 3 ) );
assertEquals( new Artifact( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.1-beta-2",
"pom" ), artifacts.get( 1 ) );
assertEquals( new Artifact( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.1", "pom" ),
artifacts.get( 4 ) );
assertEquals( new Artifact( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.2", "pom" ),
artifacts.get( 2 ) );
assertEquals(
new Artifact( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.2.1-SNAPSHOT", "pom" ),
artifacts.get( 5 ) );
assertEquals( new Artifact( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.2.1-SNAPSHOT", "pom" ), artifacts.get( 5 ) );
}
public void testGetArtifactVersionsByDateArtifactExists()
@ -415,15 +418,15 @@ public class SearchServiceImplTest
model.addDependency( dependency );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList( repoId ) );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
model );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), model );
metadataResolverControl.replay();
userReposControl.replay();
List<Dependency> dependencies =
searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
List<Dependency> dependencies = searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" );
metadataResolverControl.verify();
userReposControl.verify();
@ -441,9 +444,9 @@ public class SearchServiceImplTest
String repoId = "repo1.mirror";
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), Collections.singletonList( repoId ) );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
null );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectVersion( repoId, ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), null );
userReposControl.replay();
metadataResolverControl.replay();
@ -495,9 +498,10 @@ public class SearchServiceImplTest
dependeeModels.add( dependeeModel );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectReferences( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
dependeeModels );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( repoId,
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), dependeeModels );
metadataResolverControl.replay();
userReposControl.replay();
@ -509,10 +513,10 @@ public class SearchServiceImplTest
assertNotNull( dependees );
assertEquals( 2, dependees.size() );
assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-one", "1.0", "" ),
dependees.get( 0 ) );
assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-two", "1.0", "" ),
dependees.get( 1 ) );
assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-one", "1.0", "" ), dependees.get(
0 ) );
assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-two", "1.0", "" ), dependees.get(
1 ) );
}
public void testGetDependeesArtifactDoesNotExist()
@ -525,12 +529,16 @@ public class SearchServiceImplTest
// no longer differentiating between a project not being present and a project that is present but with
// no references. If it is later determined to be needed, we will need to modify the metadata content repository
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectReferences( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), Collections.<ProjectVersionReference>emptyList() );
metadataResolverControl.expectAndReturn(
metadataResolver.getProjectReferences( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), Collections.<ProjectVersionReference>emptyList() );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( "repo1.mirror",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ),
Collections.<ProjectVersionReference>emptyList() );
metadataResolverControl.expectAndReturn( metadataResolver.resolveProjectReferences( "public.releases",
ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ),
Collections.<ProjectVersionReference>emptyList() );
userReposControl.replay();
metadataResolverControl.replay();

View File

@ -25,7 +25,7 @@ import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,19 +50,12 @@ public class DefaultMetadataResolver
*
* @plexus.requirement role-hint="maven2"
*/
private StorageMetadataResolver storageResolver;
private RepositoryStorage repositoryStorage;
private static final Logger log = LoggerFactory.getLogger( DefaultMetadataResolver.class );
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
throws MetadataResolutionException
{
// TODO: intercept
return metadataRepository.getProject( repoId, namespace, projectId );
}
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
public ProjectVersionMetadata resolveProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
ProjectVersionMetadata metadata = metadataRepository.getProjectVersion( repoId, namespace, projectId,
@ -74,7 +67,7 @@ public class DefaultMetadataResolver
// may then work here and be more efficient than always trying again)
if ( metadata == null || metadata.isIncomplete() )
{
metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
metadata = repositoryStorage.readProjectVersionMetadata( repoId, namespace, projectId, projectVersion );
if ( metadata != null )
{
if ( log.isDebugEnabled() )
@ -117,16 +110,8 @@ public class DefaultMetadataResolver
return metadata;
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
// TODO: intercept
return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion );
}
public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<ProjectVersionReference> resolveProjectReferences( String repoId, String namespace,
String projectId, String projectVersion )
throws MetadataResolutionException
{
// TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
@ -134,11 +119,11 @@ public class DefaultMetadataResolver
return metadataRepository.getProjectReferences( repoId, namespace, projectId, projectVersion );
}
public Collection<String> getRootNamespaces( String repoId )
public Collection<String> resolveRootNamespaces( String repoId )
throws MetadataResolutionException
{
Collection<String> namespaces = metadataRepository.getRootNamespaces( repoId );
Collection<String> storageNamespaces = storageResolver.getRootNamespaces( repoId, new ExcludesFilter<String>(
Collection<String> storageNamespaces = repositoryStorage.listRootNamespaces( repoId, new ExcludesFilter<String>(
namespaces ) );
if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
{
@ -163,15 +148,15 @@ public class DefaultMetadataResolver
return namespaces;
}
public Collection<String> getNamespaces( String repoId, String namespace )
public Collection<String> resolveNamespaces( String repoId, String namespace )
throws MetadataResolutionException
{
Collection<String> namespaces = metadataRepository.getNamespaces( repoId, namespace );
Collection<String> exclusions = new ArrayList<String>( namespaces );
exclusions.addAll( metadataRepository.getProjects( repoId, namespace ) );
Collection<String> storageNamespaces = storageResolver.getNamespaces( repoId, namespace,
new ExcludesFilter<String>(
exclusions ) );
Collection<String> storageNamespaces = repositoryStorage.listNamespaces( repoId, namespace,
new ExcludesFilter<String>(
exclusions ) );
if ( storageNamespaces != null && !storageNamespaces.isEmpty() )
{
if ( log.isDebugEnabled() )
@ -195,14 +180,14 @@ public class DefaultMetadataResolver
return namespaces;
}
public Collection<String> getProjects( String repoId, String namespace )
public Collection<String> resolveProjects( String repoId, String namespace )
throws MetadataResolutionException
{
Collection<String> projects = metadataRepository.getProjects( repoId, namespace );
Collection<String> exclusions = new ArrayList<String>( projects );
exclusions.addAll( metadataRepository.getNamespaces( repoId, namespace ) );
Collection<String> storageProjects = storageResolver.getProjects( repoId, namespace, new ExcludesFilter<String>(
exclusions ) );
Collection<String> storageProjects = repositoryStorage.listProjects( repoId, namespace,
new ExcludesFilter<String>( exclusions ) );
if ( storageProjects != null && !storageProjects.isEmpty() )
{
if ( log.isDebugEnabled() )
@ -211,7 +196,7 @@ public class DefaultMetadataResolver
}
for ( String projectId : storageProjects )
{
ProjectMetadata projectMetadata = storageResolver.getProject( repoId, namespace, projectId );
ProjectMetadata projectMetadata = repositoryStorage.readProjectMetadata( repoId, namespace, projectId );
if ( projectMetadata != null )
{
try
@ -230,13 +215,13 @@ public class DefaultMetadataResolver
return projects;
}
public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
public Collection<String> resolveProjectVersions( String repoId, String namespace, String projectId )
throws MetadataResolutionException
{
Collection<String> projectVersions = metadataRepository.getProjectVersions( repoId, namespace, projectId );
Collection<String> storageProjectVersions = storageResolver.getProjectVersions( repoId, namespace, projectId,
new ExcludesFilter<String>(
projectVersions ) );
Collection<String> storageProjectVersions = repositoryStorage.listProjectVersions( repoId, namespace, projectId,
new ExcludesFilter<String>(
projectVersions ) );
if ( storageProjectVersions != null && !storageProjectVersions.isEmpty() )
{
if ( log.isDebugEnabled() )
@ -247,9 +232,10 @@ public class DefaultMetadataResolver
{
try
{
ProjectVersionMetadata versionMetadata = storageResolver.getProjectVersion( repoId, namespace,
projectId,
projectVersion );
ProjectVersionMetadata versionMetadata = repositoryStorage.readProjectVersionMetadata( repoId,
namespace,
projectId,
projectVersion );
if ( versionMetadata != null )
{
metadataRepository.updateProjectVersion( repoId, namespace, projectId, versionMetadata );
@ -271,17 +257,18 @@ public class DefaultMetadataResolver
return projectVersions;
}
public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<ArtifactMetadata> resolveArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
Collection<ArtifactMetadata> artifacts = metadataRepository.getArtifacts( repoId, namespace, projectId,
projectVersion );
Collection<ArtifactMetadata> storageArtifacts = storageResolver.getArtifacts( repoId, namespace, projectId,
projectVersion,
new ExcludesFilter<String>(
createArtifactIdList(
artifacts ) ) );
Collection<ArtifactMetadata> storageArtifacts = repositoryStorage.readArtifactsMetadata( repoId, namespace,
projectId,
projectVersion,
new ExcludesFilter<String>(
createArtifactIdList(
artifacts ) ) );
if ( storageArtifacts != null && !storageArtifacts.isEmpty() )
{
if ( log.isDebugEnabled() )

View File

@ -30,7 +30,6 @@ import java.util.Date;
import java.util.List;
public interface MetadataRepository
extends MetadataResolver
{
/**
* Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
@ -81,7 +80,7 @@ public interface MetadataRepository
List<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum )
throws MetadataRepositoryException;
void deleteArtifact( String repositoryId, String namespace, String project, String version, String id )
void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
throws MetadataRepositoryException;
/**
@ -89,9 +88,49 @@ public interface MetadataRepository
*
* @param repositoryId the repository to delete
*/
void deleteRepository( String repositoryId )
void removeRepository( String repositoryId )
throws MetadataRepositoryException;
List<ArtifactMetadata> getArtifacts( String repositoryId )
throws MetadataRepositoryException;
ProjectMetadata getProject( String repoId, String namespace, String projectId )
throws MetadataResolutionException;
ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
throws MetadataResolutionException;
Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion )
throws MetadataResolutionException;
/**
* Retrieve project references from the metadata repository. Note that this is not built into the content model for
* a project version as a reference may be present (due to reverse-lookup of dependencies) before the actual
* project is, and we want to avoid adding a stub model to the content repository.
*
* @param repoId the repository ID to look within
* @param namespace the namespace of the project to get references to
* @param projectId the identifier of the project to get references to
* @param projectVersion the version of the project to get references to
* @return a list of project references
*/
Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
Collection<String> getRootNamespaces( String repoId )
throws MetadataResolutionException;
Collection<String> getNamespaces( String repoId, String namespace )
throws MetadataResolutionException;
Collection<String> getProjects( String repoId, String namespace )
throws MetadataResolutionException;
Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
throws MetadataResolutionException;
Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
}

View File

@ -20,7 +20,6 @@ package org.apache.archiva.metadata.repository;
*/
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
@ -28,13 +27,8 @@ import java.util.Collection;
public interface MetadataResolver
{
ProjectMetadata getProject( String repoId, String namespace, String projectId )
throws MetadataResolutionException;
ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
throws MetadataResolutionException;
Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion )
ProjectVersionMetadata resolveProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
/**
@ -48,23 +42,23 @@ public interface MetadataResolver
* @param projectVersion the version of the project to get references to
* @return a list of project references
*/
Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
Collection<ProjectVersionReference> resolveProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
Collection<String> getRootNamespaces( String repoId )
Collection<String> resolveRootNamespaces( String repoId )
throws MetadataResolutionException;
Collection<String> getNamespaces( String repoId, String namespace )
Collection<String> resolveNamespaces( String repoId, String namespace )
throws MetadataResolutionException;
Collection<String> getProjects( String repoId, String namespace )
Collection<String> resolveProjects( String repoId, String namespace )
throws MetadataResolutionException;
Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
Collection<String> resolveProjectVersions( String repoId, String namespace, String projectId )
throws MetadataResolutionException;
Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
Collection<ArtifactMetadata> resolveArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
}

View File

@ -0,0 +1,52 @@
package org.apache.archiva.metadata.repository.storage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.filter.Filter;
import java.util.Collection;
public interface RepositoryStorage
{
ProjectMetadata readProjectMetadata( String repoId, String namespace, String projectId )
throws MetadataResolutionException;
ProjectVersionMetadata readProjectVersionMetadata( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException;
Collection<String> listRootNamespaces( String repoId, Filter<String> filter );
Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter );
Collection<String> listProjects( String repoId, String namespace, Filter<String> filter );
Collection<String> listProjectVersions( String repoId, String namespace, String projectId, Filter<String> filter );
Collection<ArtifactMetadata> readArtifactsMetadata( String repoId, String namespace, String projectId,
String projectVersion, Filter<String> filter );
// TODO: reconsider this API, do we want to expose storage format in the form of a path?
ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path );
}

View File

@ -1,44 +0,0 @@
package org.apache.archiva.metadata.repository.storage;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.MetadataResolver;
import org.apache.archiva.metadata.repository.filter.Filter;
import java.util.Collection;
public interface StorageMetadataResolver
extends MetadataResolver
{
Collection<String> getRootNamespaces( String repoId, Filter<String> filter );
Collection<String> getNamespaces( String repoId, String namespace, Filter<String> filter );
Collection<String> getProjects( String repoId, String namespace, Filter<String> filter );
Collection<String> getProjectVersions( String repoId, String namespace, String projectId, Filter<String> filter );
Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId, String projectVersion,
Filter<String> filter );
// TODO: reconsider this API, do we want to expose storage format in the form of a path?
ArtifactMetadata getArtifactForPath( String repoId, String path );
}

View File

@ -873,7 +873,7 @@ public abstract class AbstractMetadataRepositoryTest
assertEquals( Collections.singletonList( artifact ), new ArrayList<ArtifactMetadata>( repository.getArtifacts(
TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
repository.deleteArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() );
assertTrue( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
TEST_PROJECT_VERSION ).isEmpty() );
@ -909,7 +909,7 @@ public abstract class AbstractMetadataRepositoryTest
assertEquals( expected, actual );
repository.deleteRepository( TEST_REPO_ID );
repository.removeRepository( TEST_REPO_ID );
assertTrue( repository.getArtifacts( TEST_REPO_ID ).isEmpty() );
assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() );

View File

@ -425,8 +425,8 @@ public class DefaultDependencyTreeBuilder
Collection<String> projectVersions;
try
{
projectVersions = metadataResolver.getProjectVersions( repoId, artifact.getGroupId(),
artifact.getArtifactId() );
projectVersions = metadataResolver.resolveProjectVersions( repoId, artifact.getGroupId(),
artifact.getArtifactId() );
}
catch ( MetadataResolutionException e )
{

View File

@ -24,14 +24,12 @@ import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.filter.AllFilter;
import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
@ -63,10 +61,10 @@ import java.util.Date;
import java.util.List;
/**
* @plexus.component role="org.apache.archiva.metadata.repository.storage.StorageMetadataResolver" role-hint="maven2"
* @plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryStorage" role-hint="maven2"
*/
public class Maven2RepositoryMetadataResolver
implements StorageMetadataResolver
public class Maven2RepositoryStorage
implements RepositoryStorage
{
/**
* @plexus.requirement
@ -88,12 +86,10 @@ public class Maven2RepositoryMetadataResolver
*/
private MetadataRepository metadataRepository;
private final static Logger log = LoggerFactory.getLogger( Maven2RepositoryMetadataResolver.class );
private final static Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
private static final String METADATA_FILENAME = "maven-metadata.xml";
private static final Filter<String> ALL = new AllFilter<String>();
private static final String PROBLEM_MISSING_POM = "missing-pom";
private static final String PROBLEM_INVALID_POM = "invalid-pom";
@ -103,14 +99,14 @@ public class Maven2RepositoryMetadataResolver
private static final List<String> POTENTIAL_PROBLEMS = Arrays.asList( PROBLEM_INVALID_POM, PROBLEM_MISSING_POM,
PROBLEM_MISLOCATED_POM );
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
public ProjectMetadata readProjectMetadata( String repoId, String namespace, String projectId )
{
// TODO: could natively implement the "shared model" concept from the browse action to avoid needing it there?
return null;
}
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
public ProjectVersionMetadata readProjectVersionMetadata( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
// Remove problems associated with this version, since we'll be re-adding any that still exist
@ -372,26 +368,7 @@ public class Maven2RepositoryMetadataResolver
return ci;
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
String projectVersion )
{
// TODO: useful, but not implemented yet, not called from DefaultMetadataResolver
throw new UnsupportedOperationException();
}
public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
{
// Can't be determined on a Maven 2 repository
throw new UnsupportedOperationException();
}
public Collection<String> getRootNamespaces( String repoId )
{
return getRootNamespaces( repoId, ALL );
}
public Collection<String> getRootNamespaces( String repoId, Filter<String> filter )
public Collection<String> listRootNamespaces( String repoId, Filter<String> filter )
{
File dir = getRepositoryBasedir( repoId );
@ -422,12 +399,7 @@ public class Maven2RepositoryMetadataResolver
return new File( repositoryConfiguration.getLocation() );
}
public Collection<String> getNamespaces( String repoId, String namespace )
{
return getNamespaces( repoId, namespace, ALL );
}
public Collection<String> getNamespaces( String repoId, String namespace, Filter<String> filter )
public Collection<String> listNamespaces( String repoId, String namespace, Filter<String> filter )
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace );
@ -448,12 +420,7 @@ public class Maven2RepositoryMetadataResolver
return namespaces;
}
public Collection<String> getProjects( String repoId, String namespace )
{
return getProjects( repoId, namespace, ALL );
}
public Collection<String> getProjects( String repoId, String namespace, Filter<String> filter )
public Collection<String> listProjects( String repoId, String namespace, Filter<String> filter )
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace );
@ -474,19 +441,8 @@ public class Maven2RepositoryMetadataResolver
return projects;
}
public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
{
return getProjectVersions( repoId, namespace, projectId, ALL );
}
public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
{
return getArtifacts( repoId, namespace, projectId, projectVersion, ALL );
}
public Collection<String> getProjectVersions( String repoId, String namespace, String projectId,
Filter<String> filter )
public Collection<String> listProjectVersions( String repoId, String namespace, String projectId,
Filter<String> filter )
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace, projectId );
@ -494,8 +450,8 @@ public class Maven2RepositoryMetadataResolver
return getSortedFiles( dir, filter );
}
public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion, Filter<String> filter )
public Collection<ArtifactMetadata> readArtifactsMetadata( String repoId, String namespace, String projectId,
String projectVersion, Filter<String> filter )
{
File dir = pathTranslator.toFile( getRepositoryBasedir( repoId ), namespace, projectId, projectVersion );
@ -514,7 +470,7 @@ public class Maven2RepositoryMetadataResolver
return artifacts;
}
public ArtifactMetadata getArtifactForPath( String repoId, String path )
public ArtifactMetadata readArtifactMetadataFromPath( String repoId, String path )
{
ArtifactMetadata metadata = pathTranslator.getArtifactForPath( repoId, path );
@ -653,11 +609,6 @@ public class Maven2RepositoryMetadataResolver
return metadata;
}
public void setConfiguration( ArchivaConfiguration configuration )
{
this.archivaConfiguration = configuration;
}
private static class DirectoryFilter
implements FilenameFilter
{

View File

@ -19,6 +19,12 @@ package org.apache.archiva.metadata.repository;
* under the License.
*/
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@ -26,14 +32,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
public class TestMetadataRepository
extends TestMetadataResolver
implements MetadataRepository
{
private Map<String, MetadataFacet> facets = new HashMap<String, MetadataFacet>();
@ -49,7 +48,8 @@ public class TestMetadataRepository
//To change body of implemented methods use File | Settings | File Templates.
}
public void updateProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata )
public void updateProjectVersion( String repoId, String namespace, String projectId,
ProjectVersionMetadata versionMetadata )
{
//To change body of implemented methods use File | Settings | File Templates.
}
@ -105,16 +105,76 @@ public class TestMetadataRepository
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void deleteArtifact( String repositoryId, String namespace, String project, String version, String id )
public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
{
//To change body of implemented methods use File | Settings | File Templates.
}
public void deleteRepository( String repoId )
public void removeRepository( String repoId )
{
//To change body of implemented methods use File | Settings | File Templates.
}
public List<ArtifactMetadata> getArtifacts(String repositoryId){
public List<ArtifactMetadata> getArtifacts( String repositoryId )
{
return null;
}
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getRootNamespaces( String repoId )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getNamespaces( String repoId, String namespace )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getProjects( String repoId, String namespace )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -19,61 +19,49 @@ package org.apache.archiva.metadata.repository;
* under the License.
*/
import java.util.Collection;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference;
import java.util.Collection;
public class TestMetadataResolver
implements MetadataResolver
{
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
public ProjectVersionMetadata resolveProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<ProjectVersionReference> resolveProjectReferences( String repoId, String namespace,
String projectId, String projectVersion )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<String> resolveRootNamespaces( String repoId )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<String> resolveNamespaces( String repoId, String namespace )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getRootNamespaces( String repoId )
public Collection<String> resolveProjects( String repoId, String namespace )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getNamespaces( String repoId, String namespace )
public Collection<String> resolveProjectVersions( String repoId, String namespace, String projectId )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getProjects( String repoId, String namespace )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
public Collection<ArtifactMetadata> resolveArtifacts( String repoId, String namespace, String projectId,
String projectVersion )
{
return null; //To change body of implemented methods use File | Settings | File Templates.
}

View File

@ -27,8 +27,10 @@ import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataResolutionException;
import org.apache.archiva.metadata.repository.filter.AllFilter;
import org.apache.archiva.metadata.repository.filter.ExcludesFilter;
import org.apache.archiva.metadata.repository.storage.StorageMetadataResolver;
import org.apache.archiva.metadata.repository.filter.Filter;
import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
@ -45,7 +47,9 @@ import java.util.List;
public class Maven2RepositoryMetadataResolverTest
extends PlexusInSpringTestCase
{
private Maven2RepositoryMetadataResolver resolver;
private static final Filter<String> ALL = new AllFilter<String>();
private Maven2RepositoryStorage resolver;
private static final String TEST_REPO_ID = "test";
@ -74,7 +78,7 @@ public class Maven2RepositoryMetadataResolverTest
c.addManagedRepository( testRepo );
configuration.save( c );
resolver = (Maven2RepositoryMetadataResolver) lookup( StorageMetadataResolver.class, "maven2" );
resolver = (Maven2RepositoryStorage) lookup( RepositoryStorage.class, "maven2" );
metadataRepository = (MetadataRepository) lookup( MetadataRepository.class );
metadataRepository.removeMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID );
}
@ -82,8 +86,8 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetProjectVersionMetadata()
throws Exception
{
ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache.archiva",
"archiva-common", "1.2.1" );
ProjectVersionMetadata metadata = resolver.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.archiva",
"archiva-common", "1.2.1" );
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertEquals( "jar", facet.getPackaging() );
assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
@ -136,8 +140,9 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetArtifactMetadata()
throws Exception
{
Collection<ArtifactMetadata> springArtifacts = resolver.getArtifacts( TEST_REPO_ID, "org.codehaus.plexus",
"plexus-spring", "1.2" );
Collection<ArtifactMetadata> springArtifacts = resolver.readArtifactsMetadata( TEST_REPO_ID,
"org.codehaus.plexus",
"plexus-spring", "1.2", ALL );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( springArtifacts );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
@ -177,8 +182,9 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetArtifactMetadataSnapshots()
throws Exception
{
Collection<ArtifactMetadata> testArtifacts = resolver.getArtifacts( TEST_REPO_ID, "com.example.test",
"test-artifact", "1.0-SNAPSHOT" );
Collection<ArtifactMetadata> testArtifacts = resolver.readArtifactsMetadata( TEST_REPO_ID, "com.example.test",
"test-artifact", "1.0-SNAPSHOT",
ALL );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( testArtifacts );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
@ -259,8 +265,8 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetProjectVersionMetadataForTimestampedSnapshot()
throws Exception
{
ProjectVersionMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "org.apache", "apache",
"5-SNAPSHOT" );
ProjectVersionMetadata metadata = resolver.readProjectVersionMetadata( TEST_REPO_ID, "org.apache", "apache",
"5-SNAPSHOT" );
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
assertEquals( "pom", facet.getPackaging() );
assertEquals( "http://www.apache.org/", metadata.getUrl() );
@ -296,24 +302,24 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
throws Exception
{
FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-metadata",
"1.0-SNAPSHOT" );
FacetedMetadata metadata = resolver.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
"missing-metadata", "1.0-SNAPSHOT" );
assertNull( metadata );
}
public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
throws Exception
{
FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "malformed-metadata",
"1.0-SNAPSHOT" );
FacetedMetadata metadata = resolver.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
"malformed-metadata", "1.0-SNAPSHOT" );
assertNull( metadata );
}
public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
throws Exception
{
FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "incomplete-metadata",
"1.0-SNAPSHOT" );
FacetedMetadata metadata = resolver.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test",
"incomplete-metadata", "1.0-SNAPSHOT" );
assertNull( metadata );
}
@ -324,7 +330,7 @@ public class Maven2RepositoryMetadataResolverTest
try
{
resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
resolver.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );
fail( "Should have received an exception due to invalid POM" );
}
catch ( MetadataResolutionException e )
@ -345,7 +351,7 @@ public class Maven2RepositoryMetadataResolverTest
try
{
resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
resolver.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
fail( "Should have received an exception due to mislocated POM" );
}
catch ( MetadataResolutionException e )
@ -364,7 +370,8 @@ public class Maven2RepositoryMetadataResolverTest
{
assertTrue( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
FacetedMetadata metadata = resolver.getProjectVersion( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
FacetedMetadata metadata = resolver.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom",
"1.0" );
assertNull( metadata );
assertFalse( metadataRepository.getMetadataFacets( TEST_REPO_ID, RepositoryProblemFacet.FACET_ID ).isEmpty() );
@ -377,84 +384,87 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetRootNamespaces()
{
assertEquals( Arrays.asList( "com", "org" ), resolver.getRootNamespaces( TEST_REPO_ID ) );
assertEquals( Arrays.asList( "com", "org" ), resolver.listRootNamespaces( TEST_REPO_ID, ALL ) );
}
public void testGetNamespaces()
{
assertEquals( Arrays.asList( "example" ), resolver.getNamespaces( TEST_REPO_ID, "com" ) );
assertEquals( Arrays.asList( "test" ), resolver.getNamespaces( TEST_REPO_ID, "com.example" ) );
assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "com.example.test" ) );
assertEquals( Arrays.asList( "example" ), resolver.listNamespaces( TEST_REPO_ID, "com", ALL ) );
assertEquals( Arrays.asList( "test" ), resolver.listNamespaces( TEST_REPO_ID, "com.example", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listNamespaces( TEST_REPO_ID, "com.example.test",
ALL ) );
assertEquals( Arrays.asList( "apache", "codehaus" ), resolver.getNamespaces( TEST_REPO_ID, "org" ) );
assertEquals( Arrays.asList( "archiva", "maven" ), resolver.getNamespaces( TEST_REPO_ID, "org.apache" ) );
assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.apache.archiva" ) );
assertEquals( Arrays.asList( "plugins", "shared" ), resolver.getNamespaces( TEST_REPO_ID,
"org.apache.maven" ) );
assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID,
"org.apache.maven.plugins" ) );
assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID,
"org.apache.maven.shared" ) );
assertEquals( Arrays.asList( "apache", "codehaus" ), resolver.listNamespaces( TEST_REPO_ID, "org", ALL ) );
assertEquals( Arrays.asList( "archiva", "maven" ), resolver.listNamespaces( TEST_REPO_ID, "org.apache", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listNamespaces( TEST_REPO_ID, "org.apache.archiva",
ALL ) );
assertEquals( Arrays.asList( "plugins", "shared" ), resolver.listNamespaces( TEST_REPO_ID, "org.apache.maven",
ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listNamespaces( TEST_REPO_ID,
"org.apache.maven.plugins", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listNamespaces( TEST_REPO_ID, "org.apache.maven.shared",
ALL ) );
assertEquals( Arrays.asList( "plexus" ), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus" ) );
assertEquals( Collections.<String>emptyList(), resolver.getNamespaces( TEST_REPO_ID, "org.codehaus.plexus" ) );
assertEquals( Arrays.asList( "plexus" ), resolver.listNamespaces( TEST_REPO_ID, "org.codehaus", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listNamespaces( TEST_REPO_ID, "org.codehaus.plexus",
ALL ) );
}
public void testGetProjects()
{
assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com" ) );
assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "com.example" ) );
assertEquals( Collections.<String>emptyList(), resolver.listProjects( TEST_REPO_ID, "com", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listProjects( TEST_REPO_ID, "com.example", ALL ) );
assertEquals( Arrays.asList( "incomplete-metadata", "invalid-pom", "malformed-metadata", "mislocated-pom",
"missing-metadata", "test-artifact" ), resolver.getProjects( TEST_REPO_ID,
"com.example.test" ) );
"missing-metadata", "test-artifact" ), resolver.listProjects( TEST_REPO_ID,
"com.example.test",
ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org" ) );
assertEquals( Arrays.asList( "apache" ), resolver.getProjects( TEST_REPO_ID, "org.apache" ) );
assertEquals( Collections.<String>emptyList(), resolver.listProjects( TEST_REPO_ID, "org", ALL ) );
assertEquals( Arrays.asList( "apache" ), resolver.listProjects( TEST_REPO_ID, "org.apache", ALL ) );
assertEquals( Arrays.asList( "archiva", "archiva-base", "archiva-common", "archiva-modules", "archiva-parent" ),
resolver.getProjects( TEST_REPO_ID, "org.apache.archiva" ) );
assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID, "org.apache.maven" ) );
assertEquals( Collections.<String>emptyList(), resolver.getProjects( TEST_REPO_ID,
"org.apache.maven.plugins" ) );
assertEquals( Arrays.asList( "maven-downloader" ), resolver.getProjects( TEST_REPO_ID,
"org.apache.maven.shared" ) );
resolver.listProjects( TEST_REPO_ID, "org.apache.archiva", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listProjects( TEST_REPO_ID, "org.apache.maven", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.listProjects( TEST_REPO_ID, "org.apache.maven.plugins",
ALL ) );
assertEquals( Arrays.asList( "maven-downloader" ), resolver.listProjects( TEST_REPO_ID,
"org.apache.maven.shared", ALL ) );
}
public void testGetProjectVersions()
{
assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
"incomplete-metadata" ) );
assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
"malformed-metadata" ) );
assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
"missing-metadata" ) );
assertEquals( Arrays.asList( "1.0" ), resolver.getProjectVersions( TEST_REPO_ID, "com.example.test",
"invalid-pom" ) );
assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.listProjectVersions( TEST_REPO_ID, "com.example.test",
"incomplete-metadata", ALL ) );
assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.listProjectVersions( TEST_REPO_ID, "com.example.test",
"malformed-metadata", ALL ) );
assertEquals( Arrays.asList( "1.0-SNAPSHOT" ), resolver.listProjectVersions( TEST_REPO_ID, "com.example.test",
"missing-metadata", ALL ) );
assertEquals( Arrays.asList( "1.0" ), resolver.listProjectVersions( TEST_REPO_ID, "com.example.test",
"invalid-pom", ALL ) );
assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache",
"apache" ) );
assertEquals( Arrays.asList( "4", "5-SNAPSHOT" ), resolver.listProjectVersions( TEST_REPO_ID, "org.apache",
"apache", ALL ) );
assertEquals( Arrays.asList( "1.2.1", "1.2.2" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva" ) );
assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-base" ) );
assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-common" ) );
assertEquals( Arrays.asList( "1.2.1" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-modules" ) );
assertEquals( Arrays.asList( "3" ), resolver.getProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-parent" ) );
assertEquals( Arrays.asList( "1.2.1", "1.2.2" ), resolver.listProjectVersions( TEST_REPO_ID,
"org.apache.archiva", "archiva",
ALL ) );
assertEquals( Arrays.asList( "1.2.1" ), resolver.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-base", ALL ) );
assertEquals( Arrays.asList( "1.2.1" ), resolver.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-common", ALL ) );
assertEquals( Arrays.asList( "1.2.1" ), resolver.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-modules", ALL ) );
assertEquals( Arrays.asList( "3" ), resolver.listProjectVersions( TEST_REPO_ID, "org.apache.archiva",
"archiva-parent", ALL ) );
assertEquals( Collections.<String>emptyList(), resolver.getProjectVersions( TEST_REPO_ID,
"org.apache.maven.shared",
"maven-downloader" ) );
assertEquals( Collections.<String>emptyList(), resolver.listProjectVersions( TEST_REPO_ID,
"org.apache.maven.shared",
"maven-downloader", ALL ) );
}
public void testGetArtifacts()
{
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
"org.codehaus.plexus",
"plexus-spring",
"1.2" ) );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.readArtifactsMetadata(
TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", ALL ) );
assertEquals( 3, artifacts.size() );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
@ -474,10 +484,8 @@ public class Maven2RepositoryMetadataResolverTest
{
ExcludesFilter<String> filter = new ExcludesFilter<String>( Collections.singletonList(
"plexus-spring-1.2.pom" ) );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
"org.codehaus.plexus",
"plexus-spring",
"1.2", filter ) );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.readArtifactsMetadata(
TEST_REPO_ID, "org.codehaus.plexus", "plexus-spring", "1.2", filter ) );
assertEquals( 2, artifacts.size() );
Collections.sort( artifacts, new Comparator<ArtifactMetadata>()
{
@ -493,10 +501,8 @@ public class Maven2RepositoryMetadataResolverTest
public void testGetArtifactsTimestampedSnapshots()
{
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.getArtifacts( TEST_REPO_ID,
"com.example.test",
"missing-metadata",
"1.0-SNAPSHOT" ) );
List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>( resolver.readArtifactsMetadata(
TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT", ALL ) );
assertEquals( 1, artifacts.size() );
ArtifactMetadata artifact = artifacts.get( 0 );

View File

@ -565,7 +565,7 @@ public class FileMetadataRepository
return artifacts;
}
public void deleteArtifact( String repoId, String namespace, String project, String version, String id )
public void removeArtifact( String repoId, String namespace, String project, String version, String id )
{
File directory = new File( getDirectory( repoId ), namespace + "/" + project + "/" + version );
@ -600,7 +600,7 @@ public class FileMetadataRepository
}
}
public void deleteRepository( String repoId )
public void removeRepository( String repoId )
{
try
{

View File

@ -589,7 +589,7 @@ public class JcrMetadataRepository
return artifacts;
}
public void deleteArtifact( String repositoryId, String namespace, String projectId, String projectVersion,
public void removeArtifact( String repositoryId, String namespace, String projectId, String projectVersion,
String id )
throws MetadataRepositoryException
{
@ -608,7 +608,7 @@ public class JcrMetadataRepository
}
}
public void deleteRepository( String repositoryId )
public void removeRepository( String repositoryId )
throws MetadataRepositoryException
{
try