]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1283] moved browseArtifact() functionality over to metadata repository and remov...
authorBrett Porter <brett@apache.org>
Fri, 27 Nov 2009 20:50:34 +0000 (20:50 +0000)
committerBrett Porter <brett@apache.org>
Fri, 27 Nov 2009 20:50:34 +0000 (20:50 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885001 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index 0b32610bbd083ac2c5614bc1617c81db7fc26c4f..520cc7b6129198284d5692f7515a2027914dee35 100644 (file)
@@ -26,14 +26,22 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
 import org.apache.maven.archiva.database.browsing.BrowsingResults;
-import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
+import org.apache.maven.archiva.model.CiManagement;
+import org.apache.maven.archiva.model.Dependency;
+import org.apache.maven.archiva.model.IssueManagement;
+import org.apache.maven.archiva.model.License;
+import org.apache.maven.archiva.model.MailingList;
+import org.apache.maven.archiva.model.Organization;
+import org.apache.maven.archiva.model.Scm;
+import org.apache.maven.archiva.model.VersionedReference;
 import org.apache.maven.archiva.security.AccessDeniedException;
 import org.apache.maven.archiva.security.ArchivaSecurityException;
 import org.apache.maven.archiva.security.PrincipalNotFoundException;
@@ -49,11 +57,6 @@ import org.apache.maven.archiva.security.UserRepositories;
 public class BrowseAction
     extends PlexusActionSupport
 {
-    /**
-     * @plexus.requirement role-hint="default"
-     */
-    private RepositoryBrowsing repoBrowsing;
-
     /**
      * @plexus.requirement
      */
@@ -172,6 +175,7 @@ public class BrowseAction
     }
 
     public String browseArtifact()
+        throws MetadataResolverException
     {
         if ( StringUtils.isEmpty( groupId ) )
         {
@@ -193,14 +197,24 @@ public class BrowseAction
             return GlobalResults.ACCESS_TO_NO_REPOS;
         }
 
-        this.results = repoBrowsing.selectArtifactId( getPrincipal(), selectedRepos, groupId, artifactId );
+        Set<String> versions = new LinkedHashSet<String>();
+        for ( String repoId : selectedRepos )
+        {
+            versions.addAll( metadataResolver.getProjectVersions( repoId, groupId, artifactId ) );
+        }
+
+        this.results = new BrowsingResults( groupId, artifactId );
+        // TODO: sort by known version ordering method
+        results.setVersions( new ArrayList<String>( versions ) );
+        results.setSelectedRepositoryIds( selectedRepos );
 
-        populateSharedModel();
+        populateSharedModel( selectedRepos );
 
         return SUCCESS;
     }
 
-    private void populateSharedModel()
+    private void populateSharedModel( Collection<String> selectedRepos )
+        throws MetadataResolverException
     {
         sharedModel = new ArchivaProjectModel();
         sharedModel.setGroupId( groupId );
@@ -209,80 +223,173 @@ public class BrowseAction
 
         for ( String version : this.results.getVersions() )
         {
-            try
+            ProjectVersionMetadata versionMetadata = null;
+            for ( String repoId : selectedRepos )
+            {
+                if ( versionMetadata == null )
+                {
+                    versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
+                }
+            }
+
+            if ( versionMetadata == null )
+            {
+                continue;
+            }
+
+            ArchivaProjectModel model = populateLegacyModel( versionMetadata );
+
+            if ( isFirstVersion )
             {
-                ArchivaProjectModel model =
-                    repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
+                sharedModel = model;
+                sharedModel.setVersion( null );
+            }
+            else
+            {
+                if ( sharedModel.getPackaging() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getPackaging(), model.getPackaging() ) )
+                {
+                    sharedModel.setPackaging( null );
+                }
+
+                if ( sharedModel.getName() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getName(), model.getName() ) )
+                {
+                    sharedModel.setName( "" );
+                }
+
+                if ( sharedModel.getDescription() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getDescription(), model.getDescription() ) )
+                {
+                    sharedModel.setDescription( null );
+                }
 
-                if ( model == null )
+                if ( sharedModel.getIssueManagement() != null && model.getIssueManagement() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getIssueManagement().getIssueManagementUrl(),
+                                                   model.getIssueManagement().getIssueManagementUrl() ) )
                 {
-                    continue;
+                    sharedModel.setIssueManagement( null );
                 }
 
-                if ( isFirstVersion )
+                if ( sharedModel.getCiManagement() != null && model.getCiManagement() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getCiManagement().getCiUrl(),
+                                                   model.getCiManagement().getCiUrl() ) )
                 {
-                    sharedModel = model;
-                    sharedModel.setVersion( null );
+                    sharedModel.setCiManagement( null );
                 }
-                else
+
+                if ( sharedModel.getOrganization() != null && model.getOrganization() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getOrganization().getOrganizationName(),
+                                                   model.getOrganization().getOrganizationName() ) )
+                {
+                    sharedModel.setOrganization( null );
+                }
+
+                if ( sharedModel.getUrl() != null &&
+                    !StringUtils.equalsIgnoreCase( sharedModel.getUrl(), model.getUrl() ) )
                 {
-                    if ( sharedModel.getPackaging() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getPackaging(), model.getPackaging() ) )
-                    {
-                        sharedModel.setPackaging( null );
-                    }
-
-                    if ( sharedModel.getName() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getName(), model.getName() ) )
-                    {
-                        sharedModel.setName( "" );
-                    }
-
-                    if ( sharedModel.getDescription() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getDescription(), model.getDescription() ) )
-                    {
-                        sharedModel.setDescription( null );
-                    }
-
-                    if ( sharedModel.getIssueManagement() != null && model.getIssueManagement() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getIssueManagement().getIssueManagementUrl(),
-                                                       model.getIssueManagement().getIssueManagementUrl() ) )
-                    {
-                        sharedModel.setIssueManagement( null );
-                    }
-
-                    if ( sharedModel.getCiManagement() != null && model.getCiManagement() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getCiManagement().getCiUrl(),
-                                                       model.getCiManagement().getCiUrl() ) )
-                    {
-                        sharedModel.setCiManagement( null );
-                    }
-
-                    if ( sharedModel.getOrganization() != null && model.getOrganization() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getOrganization().getOrganizationName(),
-                                                       model.getOrganization().getOrganizationName() ) )
-                    {
-                        sharedModel.setOrganization( null );
-                    }
-
-                    if ( sharedModel.getUrl() != null &&
-                        !StringUtils.equalsIgnoreCase( sharedModel.getUrl(), model.getUrl() ) )
-                    {
-                        sharedModel.setUrl( null );
-                    }
+                    sharedModel.setUrl( null );
                 }
+            }
+
+            isFirstVersion = false;
+        }
+    }
+
+    private ArchivaProjectModel populateLegacyModel( ProjectVersionMetadata versionMetadata )
+    {
+        // TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics
+        ArchivaProjectModel model = new ArchivaProjectModel();
+        MavenProjectFacet projectFacet = (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
+        if ( projectFacet != null )
+        {
+            model.setGroupId( projectFacet.getGroupId() );
+            model.setArtifactId( projectFacet.getArtifactId() );
+            model.setPackaging( projectFacet.getPackaging() );
+            if ( projectFacet.getParent() != null )
+            {
+                VersionedReference parent = new VersionedReference();
+                parent.setGroupId( projectFacet.getParent().getGroupId() );
+                parent.setArtifactId( projectFacet.getParent().getArtifactId() );
+                parent.setVersion( projectFacet.getParent().getVersion() );
+                model.setParentProject( parent );
+            }
+        }
 
-                isFirstVersion = false;
+        model.setVersion( versionMetadata.getId() );
+        model.setDescription( versionMetadata.getDescription() );
+        model.setName( versionMetadata.getName() );
+        model.setUrl( versionMetadata.getUrl() );
+        if ( versionMetadata.getOrganization() != null )
+        {
+            Organization organization = new Organization();
+            organization.setName( versionMetadata.getOrganization().getName() );
+            organization.setUrl( versionMetadata.getOrganization().getUrl() );
+            model.setOrganization( organization );
+        }
+        if ( versionMetadata.getCiManagement() != null )
+        {
+            CiManagement ci = new CiManagement();
+            ci.setSystem( versionMetadata.getCiManagement().getSystem() );
+            ci.setUrl( versionMetadata.getCiManagement().getUrl() );
+            model.setCiManagement( ci );
+        }
+        if ( versionMetadata.getIssueManagement() != null )
+        {
+            IssueManagement issueManagement = new IssueManagement();
+            issueManagement.setSystem( versionMetadata.getIssueManagement().getSystem() );
+            issueManagement.setUrl( versionMetadata.getIssueManagement().getUrl() );
+            model.setIssueManagement( issueManagement );
+        }
+        if ( versionMetadata.getScm() != null )
+        {
+            Scm scm = new Scm();
+            scm.setConnection( versionMetadata.getScm().getConnection() );
+            scm.setDeveloperConnection( versionMetadata.getScm().getDeveloperConnection() );
+            scm.setUrl( versionMetadata.getScm().getUrl() );
+            model.setScm( scm );
+        }
+        if ( versionMetadata.getLicenses() != null )
+        {
+            for ( org.apache.archiva.metadata.model.License l : versionMetadata.getLicenses() )
+            {
+                License license = new License();
+                license.setName( l.getName() );
+                license.setUrl( l.getUrl() );
+                model.addLicense( license );
             }
-            catch ( ObjectNotFoundException e )
+        }
+        if ( versionMetadata.getMailingLists() != null )
+        {
+            for ( org.apache.archiva.metadata.model.MailingList l : versionMetadata.getMailingLists() )
             {
-                log.debug( e.getMessage(), e );
+                MailingList mailingList = new MailingList();
+                mailingList.setMainArchiveUrl( l.getMainArchiveUrl() );
+                mailingList.setName( l.getName() );
+                mailingList.setPostAddress( l.getPostAddress() );
+                mailingList.setSubscribeAddress( l.getSubscribeAddress() );
+                mailingList.setUnsubscribeAddress( l.getUnsubscribeAddress() );
+                mailingList.setOtherArchives( l.getOtherArchives() );
+                model.addMailingList( mailingList );
             }
-            catch ( ArchivaDatabaseException e )
+        }
+        if ( versionMetadata.getDependencies() != null )
+        {
+            for ( org.apache.archiva.metadata.model.Dependency d : versionMetadata.getDependencies() )
             {
-                log.debug( e.getMessage(), e );
+                Dependency dependency = new Dependency();
+                dependency.setScope( d.getScope() );
+                dependency.setSystemPath( d.getSystemPath() );
+                dependency.setType( d.getType() );
+                dependency.setVersion( d.getVersion() );
+                dependency.setArtifactId( d.getArtifactId() );
+                dependency.setClassifier( d.getClassifier() );
+                dependency.setGroupId( d.getGroupId() );
+                dependency.setOptional( d.isOptional() );
+                model.addDependency( dependency );
             }
         }
+        return model;
     }
 
     private List<String> getObservableRepos()
index 658e464578f93af365f1e0c6a95f9147404c01b8..f58193a66ed08064b3b4f7e4e52bf89b603983c7 100644 (file)
@@ -46,6 +46,8 @@ public class TestMetadataResolver
 
     private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
 
+    private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
+
     public ProjectMetadata getProject( String repoId, String namespace, String projectId )
     {
         ProjectMetadata metadata = new ProjectMetadata();
@@ -111,10 +113,17 @@ public class TestMetadataResolver
         return list != null ? list : Collections.<String>emptyList();
     }
 
+    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+    {
+        Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
+        return list != null ? list : Collections.<String>emptyList();
+    }
+
     public void setProjectVersion( String repoId, String namespace, String projectId,
                                    ProjectVersionMetadata versionMetadata )
     {
         projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
+
         Collection<String> projects = projectsInNamespace.get( namespace );
         if ( projects == null )
         {
@@ -122,6 +131,15 @@ public class TestMetadataResolver
             projectsInNamespace.put( namespace, projects );
         }
         projects.add( projectId );
+
+        String key = namespace + ":" + projectId;
+        Collection<String> versions = versionsInProject.get( key );
+        if ( versions == null )
+        {
+            versions = new LinkedHashSet<String>();
+            versionsInProject.put( key, versions );
+        }
+        versions.add( versionMetadata.getId() );
     }
 
     public void setArtifactVersions( String repoId, String namespace, String projectId, String projectVersion,
index 7226d7eecee8a69690f8b57908b0ca2bae6974f5..aa9f9a8400be633db704246388519c2331659a48 100644 (file)
@@ -21,7 +21,15 @@ package org.apache.maven.archiva.web.action;
 
 import java.util.List;
 
+import org.apache.archiva.metadata.model.CiManagement;
+import org.apache.archiva.metadata.model.IssueManagement;
+import org.apache.archiva.metadata.model.License;
+import org.apache.archiva.metadata.model.Organization;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
+import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 import org.apache.maven.archiva.security.UserRepositories;
 import org.apache.maven.archiva.security.UserRepositoriesStub;
@@ -119,4 +127,55 @@ public abstract class AbstractActionTestCase
         assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() );
         assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() );
     }
+
+    protected ProjectVersionMetadata createProjectModel( String version )
+    {
+        return createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
+    }
+
+    protected ProjectVersionMetadata createProjectModel( String groupId, String artifactId, String version )
+    {
+        ProjectVersionMetadata model = new ProjectVersionMetadata();
+        model.setId( version );
+        model.setUrl( TEST_URL );
+        model.setName( TEST_NAME );
+        model.setDescription( TEST_DESCRIPTION );
+        CiManagement ci = new CiManagement();
+        ci.setSystem( TEST_CI_SYSTEM );
+        ci.setUrl( TEST_CI_URL );
+        model.setCiManagement( ci );
+        IssueManagement issue = new IssueManagement();
+        issue.setSystem( TEST_ISSUE_SYSTEM );
+        issue.setUrl( TEST_ISSUE_URL );
+        model.setIssueManagement( issue );
+        Organization organization = new Organization();
+        organization.setName( TEST_ORGANIZATION_NAME );
+        organization.setUrl( TEST_ORGANIZATION_URL );
+        model.setOrganization( organization );
+        License l = new License();
+        l.setName( TEST_LICENSE_NAME );
+        l.setUrl( TEST_LICENSE_URL );
+        model.addLicense( l );
+        l = new License();
+        l.setName( TEST_LICENSE_NAME_2 );
+        l.setUrl( TEST_LICENSE_URL_2 );
+        model.addLicense( l );
+        Scm scm = new Scm();
+        scm.setConnection( TEST_SCM_CONNECTION );
+        scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
+        scm.setUrl( TEST_SCM_URL );
+        model.setScm( scm );
+
+        MavenProjectFacet mavenProjectFacet = new MavenProjectFacet();
+        mavenProjectFacet.setGroupId( groupId );
+        mavenProjectFacet.setArtifactId( artifactId );
+        mavenProjectFacet.setPackaging( TEST_PACKAGING );
+        MavenProjectParent parent = new MavenProjectParent();
+        parent.setGroupId( TEST_PARENT_GROUP_ID );
+        parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
+        parent.setVersion( TEST_PARENT_VERSION );
+        mavenProjectFacet.setParent( parent );
+        model.addFacet( mavenProjectFacet );
+        return model;
+    }
 }
index 34b4da6de58d80db92bde35645e91a0cb3849b38..72a1811ae2a5d968bb39785cc58b512690083c63 100644 (file)
@@ -25,24 +25,11 @@ import java.util.List;
 
 import com.opensymphony.xwork2.Action;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
-import org.apache.maven.archiva.database.ArchivaDAO;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.ProjectModelDAO;
 import org.apache.maven.archiva.database.browsing.BrowsingResults;
-import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.apache.maven.archiva.model.ArchivaArtifactModel;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.model.CiManagement;
-import org.apache.maven.archiva.model.IssueManagement;
-import org.apache.maven.archiva.model.License;
-import org.apache.maven.archiva.model.Organization;
-import org.apache.maven.archiva.model.Scm;
-import org.apache.maven.archiva.model.VersionedReference;
-import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub;
-import org.easymock.MockControl;
 
 public class BrowseActionTest
     extends AbstractActionTestCase
@@ -51,8 +38,6 @@ public class BrowseActionTest
 
     private BrowseAction action;
 
-    private ArchivaDAOStub archivaDao;
-
     private static final List<String> GROUPS =
         Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle",
                        "repeat.repeat" );
@@ -111,6 +96,7 @@ public class BrowseActionTest
     }
 
     public void testBrowseArtifactNoObservableRepos()
+        throws MetadataResolverException
     {
         setObservableRepos( Collections.<String>emptyList() );
         String selectedGroupId = "org.apache";
@@ -243,6 +229,7 @@ public class BrowseActionTest
     }
 
     public void testBrowseArtifactNoGroupId()
+        throws MetadataResolverException
     {
         String selectedArtifactId = "apache";
 
@@ -258,6 +245,7 @@ public class BrowseActionTest
     }
 
     public void testBrowseArtifactNoArtifactId()
+        throws MetadataResolverException
     {
         String selectedGroupId = "org.apache";
 
@@ -273,28 +261,26 @@ public class BrowseActionTest
     }
 
     public void testBrowseArtifact()
-        throws ArchivaDatabaseException
+        throws ArchivaDatabaseException, MetadataResolverException
     {
         String selectedGroupId = "org.apache";
         String selectedArtifactId = "apache";
 
         List<String> versions = Arrays.asList( "1", "2", "3", "4" );
-        archivaDao.setVersions( versions );
-        MockControl artifactDaoMockControl = createArtifactDaoMock( selectedGroupId, selectedArtifactId, versions );
-        MockControl projectDaoMockControl = createProjectDaoMock(
-            Arrays.asList( createProjectModel( selectedGroupId, selectedArtifactId, "1" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "2" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "3" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "4" ) ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "1" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "2" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "3" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "4" ) );
 
         action.setGroupId( selectedGroupId );
         action.setArtifactId( selectedArtifactId );
         String result = action.browseArtifact();
         assertSuccessResult( result );
 
-        artifactDaoMockControl.verify();
-        projectDaoMockControl.verify();
-
         assertEquals( selectedGroupId, action.getGroupId() );
         assertEquals( selectedArtifactId, action.getArtifactId() );
         assertNull( action.getRepositoryId() );
@@ -313,30 +299,30 @@ public class BrowseActionTest
     }
 
     public void testBrowseArtifactWithSnapshots()
-        throws ArchivaDatabaseException
+        throws ArchivaDatabaseException, MetadataResolverException
     {
         String selectedGroupId = "org.apache";
         String selectedArtifactId = "apache";
 
         List<String> versions = Arrays.asList( "1", "2", "3", "4-SNAPSHOT", "4", "5-SNAPSHOT" );
-        archivaDao.setVersions( versions );
-        MockControl artifactDaoMockControl = createArtifactDaoMock( selectedGroupId, selectedArtifactId, versions );
-        MockControl projectDaoMockControl = createProjectDaoMock(
-            Arrays.asList( createProjectModel( selectedGroupId, selectedArtifactId, "1" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "2" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "3" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "4" ),
-                           createProjectModel( selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "1" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "2" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "3" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "4" ) );
+        metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, selectedArtifactId,
+                                            createProjectModel( selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) );
 
         action.setGroupId( selectedGroupId );
         action.setArtifactId( selectedArtifactId );
         String result = action.browseArtifact();
         assertSuccessResult( result );
 
-        artifactDaoMockControl.verify();
-        projectDaoMockControl.verify();
-
         assertEquals( selectedGroupId, action.getGroupId() );
         assertEquals( selectedArtifactId, action.getArtifactId() );
         assertNull( action.getRepositoryId() );
@@ -389,107 +375,11 @@ public class BrowseActionTest
         assertNull( action.getSharedModel() );
     }
 
-    private MockControl createArtifactDaoMock( String groupId, String artifactId, List<String> versions )
-        throws ArchivaDatabaseException
-    {
-        // testing deeper than normal with the mocks as we intend to replace RepositoryBrowsing, not just the database
-        // underneath it - those sections will be adjusted with a mock content repository later
-        MockControl control = MockControl.createNiceControl( ArtifactDAO.class );
-        ArtifactDAO dao = (ArtifactDAO) control.getMock();
-        archivaDao.setArtifactDao( dao );
-
-        for ( String v : versions )
-        {
-            ArtifactsRelatedConstraint c = new ArtifactsRelatedConstraint( groupId, artifactId, v );
-            dao.queryArtifacts( c );
-            control.setReturnValue( Collections.singletonList( createArtifact( groupId, artifactId, v ) ) );
-        }
-
-        control.replay();
-        return control;
-    }
-
-    private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
-    {
-        return createArtifact( groupId, artifactId, version, TEST_REPO );
-    }
-
-    private ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String repoId )
-    {
-        ArchivaArtifactModel model = new ArchivaArtifactModel();
-        model.setGroupId( groupId );
-        model.setArtifactId( artifactId );
-        model.setVersion( version );
-        model.setRepositoryId( repoId );
-        return new ArchivaArtifact( model );
-    }
-
-    private MockControl createProjectDaoMock( List<ArchivaProjectModel> projects )
-        throws ArchivaDatabaseException
-    {
-        MockControl control = MockControl.createNiceControl( ProjectModelDAO.class );
-        ProjectModelDAO dao = (ProjectModelDAO) control.getMock();
-        archivaDao.setProjectDao( dao );
-
-        for ( ArchivaProjectModel project : projects )
-        {
-            control.expectAndReturn(
-                dao.getProjectModel( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
-        }
-
-        control.replay();
-        return control;
-    }
-
     protected void setUp()
         throws Exception
     {
         super.setUp();
         action = (BrowseAction) lookup( Action.class, ACTION_HINT );
-        archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );
         metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
     }
-
-    protected ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
-    {
-        ArchivaProjectModel model = new ArchivaProjectModel();
-        model.setGroupId( groupId );
-        model.setArtifactId( artifactId );
-        model.setVersion( version );
-        model.setPackaging( TEST_PACKAGING );
-        model.setUrl( TEST_URL );
-        model.setName( TEST_NAME );
-        model.setDescription( TEST_DESCRIPTION );
-        VersionedReference parent = new VersionedReference();
-        parent.setGroupId( TEST_PARENT_GROUP_ID );
-        parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
-        parent.setVersion( TEST_PARENT_VERSION );
-        model.setParentProject( parent );
-        CiManagement ci = new CiManagement();
-        ci.setSystem( TEST_CI_SYSTEM );
-        ci.setUrl( TEST_CI_URL );
-        model.setCiManagement( ci );
-        IssueManagement issue = new IssueManagement();
-        issue.setSystem( TEST_ISSUE_SYSTEM );
-        issue.setUrl( TEST_ISSUE_URL );
-        model.setIssueManagement( issue );
-        Organization org = new Organization();
-        org.setName( TEST_ORGANIZATION_NAME );
-        org.setUrl( TEST_ORGANIZATION_URL );
-        model.setOrganization( org );
-        License l = new License();
-        l.setName( TEST_LICENSE_NAME );
-        l.setUrl( TEST_LICENSE_URL );
-        model.addLicense( l );
-        l = new License();
-        l.setName( TEST_LICENSE_NAME_2 );
-        l.setUrl( TEST_LICENSE_URL_2 );
-        model.addLicense( l );
-        Scm scm = new Scm();
-        scm.setConnection( TEST_SCM_CONNECTION );
-        scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
-        scm.setUrl( TEST_SCM_URL );
-        model.setScm( scm );
-        return model;
-    }
 }
\ No newline at end of file
index 3911ae55ff3eec7f971eb77ed1e8ce4acb1dfce8..8c8139f9b64ff4f90fa311928d70482825498f56 100644 (file)
@@ -24,18 +24,11 @@ import java.util.Collections;
 import java.util.List;
 
 import com.opensymphony.xwork2.Action;
-import org.apache.archiva.metadata.model.CiManagement;
 import org.apache.archiva.metadata.model.Dependency;
-import org.apache.archiva.metadata.model.IssueManagement;
-import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.MailingList;
-import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionReference;
-import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
-import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
-import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
 
@@ -506,50 +499,4 @@ public class ShowArtifactActionTest
         action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
         metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
     }
-
-    protected ProjectVersionMetadata createProjectModel( String version )
-    {
-        ProjectVersionMetadata model = new ProjectVersionMetadata();
-        model.setId( version );
-        model.setUrl( TEST_URL );
-        model.setName( TEST_NAME );
-        model.setDescription( TEST_DESCRIPTION );
-        CiManagement ci = new CiManagement();
-        ci.setSystem( TEST_CI_SYSTEM );
-        ci.setUrl( TEST_CI_URL );
-        model.setCiManagement( ci );
-        IssueManagement issue = new IssueManagement();
-        issue.setSystem( TEST_ISSUE_SYSTEM );
-        issue.setUrl( TEST_ISSUE_URL );
-        model.setIssueManagement( issue );
-        Organization organization = new Organization();
-        organization.setName( TEST_ORGANIZATION_NAME );
-        organization.setUrl( TEST_ORGANIZATION_URL );
-        model.setOrganization( organization );
-        License l = new License();
-        l.setName( TEST_LICENSE_NAME );
-        l.setUrl( TEST_LICENSE_URL );
-        model.addLicense( l );
-        l = new License();
-        l.setName( TEST_LICENSE_NAME_2 );
-        l.setUrl( TEST_LICENSE_URL_2 );
-        model.addLicense( l );
-        Scm scm = new Scm();
-        scm.setConnection( TEST_SCM_CONNECTION );
-        scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
-        scm.setUrl( TEST_SCM_URL );
-        model.setScm( scm );
-
-        MavenProjectFacet mavenProjectFacet = new MavenProjectFacet();
-        mavenProjectFacet.setGroupId( TEST_GROUP_ID );
-        mavenProjectFacet.setArtifactId( TEST_ARTIFACT_ID );
-        mavenProjectFacet.setPackaging( TEST_PACKAGING );
-        MavenProjectParent parent = new MavenProjectParent();
-        parent.setGroupId( TEST_PARENT_GROUP_ID );
-        parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
-        parent.setVersion( TEST_PARENT_VERSION );
-        mavenProjectFacet.setParent( parent );
-        model.addFacet( mavenProjectFacet );
-        return model;
-    }
 }
index 17b237455a06380b3d5e84a2b2c07a3b9ca6558a..8e54a6ea2f373cb5788d6f351ab68d0b56ac3f0d 100644 (file)
@@ -122,4 +122,11 @@ public class DefaultMetadataResolver
         // not passed to the storage mechanism as resolving references would require iterating all projects
         return metadataRepository.getProjects( repoId, namespace );
     }
+
+    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+    {
+        // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
+        // not passed to the storage mechanism as resolving references would require iterating all versions
+        return metadataRepository.getProjectVersions( repoId, namespace, projectId );
+    }
 }
index 2a2600ae0e63949a6c9de7f873a24199a8cbbc3d..2f957c813adcbba01e39de08856d2bb3422887dd 100644 (file)
@@ -53,4 +53,6 @@ public interface MetadataResolver
     Collection<String> getNamespaces( String repoId, String namespace );
 
     Collection<String> getProjects( String repoId, String namespace );
+
+    Collection<String> getProjectVersions( String repoId, String namespace, String projectId );
 }
index 10ba310b4eb866db8c2d45efc9b78e47bbf92fbf..771128ff464898613a1c7319f51f382033183a78 100644 (file)
@@ -270,6 +270,7 @@ public class Maven2RepositoryMetadataResolver
         return ci;
     }
 
+    // TODO: evidence that storage and resolver != repository API - split the interface up
     public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
                                                    String projectVersion )
     {
@@ -296,4 +297,9 @@ public class Maven2RepositoryMetadataResolver
     {
         throw new UnsupportedOperationException();
     }
+
+    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+    {
+        throw new UnsupportedOperationException();
+    }
 }
index 57772258c21701fcea46dd18350d22f874527a0a..bec509ae4f3fb9ca58bd38f2203f761626846a34 100644 (file)
@@ -559,6 +559,24 @@ public class FileMetadataRepository
         return projects;
     }
 
+    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+    {
+        List<String> projectVersions = new ArrayList<String>();
+        File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId );
+        File[] files = directory.listFiles();
+        if ( files != null )
+        {
+            for ( File projectVersion : files )
+            {
+                if ( new File( projectVersion, PROJECT_VERSION_METADATA_KEY + ".properties" ).exists() )
+                {
+                    projectVersions.add( projectVersion.getName() );
+                }
+            }
+        }
+        return projectVersions;
+    }
+
     private void writeProperties( Properties properties, File directory, String propertiesKey )
         throws IOException
     {