Updating from bidirlayout to RepoContent techniques.

git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@585569 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Joakim Erdfelt 2007-10-17 16:47:33 +00:00
parent f3d43d4d4d
commit 568312aa1f
4 changed files with 36 additions and 39 deletions

View File

@ -23,13 +23,12 @@ import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryException;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.apache.maven.archiva.repository.project.resolvers.ManagedRepositoryProjectResolver;
import org.apache.maven.archiva.repository.project.resolvers.NopProjectResolver;
import org.apache.maven.archiva.repository.project.resolvers.ProjectModelResolverStack;
import org.apache.maven.archiva.repository.project.resolvers.ManagedRepositoryProjectResolver;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
@ -53,11 +52,11 @@ public class ProjectModelResolverFactory
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
/**
* @plexus.requirement
*/
private BidirectionalRepositoryLayoutFactory layoutFactory;
private RepositoryContentFactory repositoryFactory;
/**
* @plexus.requirement role-hint="model400"
@ -68,7 +67,7 @@ public class ProjectModelResolverFactory
* @plexus.requirement role-hint="model300"
*/
private ProjectModelReader project300Reader;
private ProjectModelResolverStack currentResolverStack = new ProjectModelResolverStack();
public void afterConfigurationChange( Registry registry, String propertyName, Object propertyValue )
@ -99,24 +98,15 @@ public class ProjectModelResolverFactory
private ManagedRepositoryProjectResolver toResolver( ManagedRepositoryConfiguration repo )
throws RepositoryException
{
try
{
BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repo.getLayout() );
ProjectModelReader reader = project400Reader;
ManagedRepositoryContent repoContent = repositoryFactory.getManagedRepositoryContent( repo.getId() );
ProjectModelReader reader = project400Reader;
if ( StringUtils.equals( "legacy", repo.getLayout() ) )
{
reader = project300Reader;
}
ManagedRepositoryProjectResolver resolver = new ManagedRepositoryProjectResolver( repo, reader, layout );
return resolver;
}
catch ( LayoutException e )
if ( StringUtils.equals( "legacy", repo.getLayout() ) )
{
throw new RepositoryException(
"Unable to create RepositoryProjectResolver due to invalid layout spec: " + repo );
reader = project300Reader;
}
return new ManagedRepositoryProjectResolver( repoContent, reader );
}
private void update()

View File

@ -19,11 +19,10 @@ package org.apache.maven.archiva.repository.project.resolvers;
* under the License.
*/
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.project.ProjectModelException;
import org.apache.maven.archiva.repository.project.ProjectModelReader;
import org.apache.maven.archiva.repository.project.ProjectModelResolver;
@ -39,18 +38,14 @@ import java.io.File;
public class ManagedRepositoryProjectResolver
implements ProjectModelResolver, FilesystemBasedResolver
{
private ManagedRepositoryConfiguration repository;
private ManagedRepositoryContent repository;
private ProjectModelReader reader;
private BidirectionalRepositoryLayout layout;
public ManagedRepositoryProjectResolver( ManagedRepositoryConfiguration repository, ProjectModelReader reader,
BidirectionalRepositoryLayout layout )
public ManagedRepositoryProjectResolver( ManagedRepositoryContent repository, ProjectModelReader reader )
{
this.repository = repository;
this.reader = reader;
this.layout = layout;
}
public ArchivaProjectModel resolveProjectModel( VersionedReference reference )
@ -59,8 +54,7 @@ public class ManagedRepositoryProjectResolver
ArchivaArtifact artifact = new ArchivaArtifact( reference.getGroupId(), reference.getArtifactId(), reference
.getVersion(), "", "pom" );
String path = layout.toPath( artifact );
File repoFile = new File( this.repository.getLocation(), path );
File repoFile = repository.toFile( artifact );
return reader.read( repoFile );
}

View File

@ -51,6 +51,21 @@ public abstract class AbstractRepositoryLayerTestCase
repo.setUrl( url );
return repo;
}
protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location, String layout )
throws Exception
{
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId( id );
repo.setName( name );
repo.setLocation( location.getAbsolutePath() );
repo.setLayout( layout );
ManagedRepositoryContent repoContent = (ManagedRepositoryContent) lookup( ManagedRepositoryContent.class, layout );
repoContent.setRepository( repo );
return repoContent;
}
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
throws Exception
@ -59,6 +74,7 @@ public abstract class AbstractRepositoryLayerTestCase
repo.setId( id );
repo.setName( name );
repo.setUrl( url );
repo.setLayout( layout );
RemoteRepositoryContent repoContent = (RemoteRepositoryContent) lookup( RemoteRepositoryContent.class, layout );
repoContent.setRepository( repo );

View File

@ -20,13 +20,11 @@ package org.apache.maven.archiva.repository.project.filters;
*/
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.Dependency;
import org.apache.maven.archiva.model.Individual;
import org.apache.maven.archiva.repository.AbstractRepositoryLayerTestCase;
import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
import org.apache.maven.archiva.repository.layout.DefaultBidirectionalRepositoryLayout;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.project.ProjectModelException;
import org.apache.maven.archiva.repository.project.ProjectModelFilter;
import org.apache.maven.archiva.repository.project.ProjectModelReader;
@ -68,15 +66,14 @@ public class EffectiveProjectModelFilterTest
return reader.read( pomFile );
}
private ProjectModelResolver createDefaultRepositoryResolver()
private ProjectModelResolver createDefaultRepositoryResolver() throws Exception
{
File defaultRepoDir = new File( getBasedir(), DEFAULT_REPOSITORY );
ManagedRepositoryConfiguration repo = createRepository( "defaultTestRepo", "Default Test Repo", defaultRepoDir );
ManagedRepositoryContent repo = createManagedRepositoryContent( "defaultTestRepo", "Default Test Repo", defaultRepoDir, "default" );
ProjectModelReader reader = new ProjectModel400Reader();
BidirectionalRepositoryLayout layout = new DefaultBidirectionalRepositoryLayout();
ManagedRepositoryProjectResolver resolver = new ManagedRepositoryProjectResolver( repo, reader, layout );
ManagedRepositoryProjectResolver resolver = new ManagedRepositoryProjectResolver( repo, reader );
return resolver;
}