]> source.dussan.org Git - archiva.git/commitdiff
Updating from bidirlayout to RepoContent techniques.
authorJoakim Erdfelt <joakime@apache.org>
Wed, 17 Oct 2007 16:47:33 +0000 (16:47 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Wed, 17 Oct 2007 16:47:33 +0000 (16:47 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@585569 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/ProjectModelResolverFactory.java
archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/project/resolvers/ManagedRepositoryProjectResolver.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/AbstractRepositoryLayerTestCase.java
archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/project/filters/EffectiveProjectModelFilterTest.java

index 68988af67c25f973807ee580af99b5ff2b572350..edea1785431766aa2439d8f23f864acf207ad189 100644 (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()
index 4463569b66a5449fbfd3696ef28f4b550bdbe127..c604249ed4a8dc47d995b5571044acb1f1a036bc 100644 (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 );
     }
index c361e9e483028fee0a74ad3d962e0e5a11cc97bf..3636e9deea99b5de9d92954789e16e70eb57fcba 100644 (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 );
index 16ab3aecbeba064b7128f7dcf67e44ba6521aaa4..c4f04182b8ec614069f2726bcdcfbfe89df1ba83 100644 (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;
     }