From: Joakim Erdfelt Date: Wed, 17 Oct 2007 16:47:33 +0000 (+0000) Subject: Updating from bidirlayout to RepoContent techniques. X-Git-Tag: archiva-1.0-beta-3~71 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=568312aa1fa711614687893de3cce974c552dd12;p=archiva.git Updating from bidirlayout to RepoContent techniques. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@585569 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java index 68988af67..edea17854 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java @@ -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() diff --git a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java index 4463569b6..c604249ed 100644 --- a/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java +++ b/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java @@ -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 ); } diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java index c361e9e48..3636e9dee 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java @@ -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 ); diff --git a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java index 16ab3aecb..c4f04182b 100644 --- a/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java +++ b/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java @@ -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; }