aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-11-27 20:50:34 +0000
committerBrett Porter <brett@apache.org>2009-11-27 20:50:34 +0000
commit2721d7bf8d98505f9961d0d741b3bbc396497f2b (patch)
tree05bae765b4a7b7f3773c72c4a1ca7679f0332710 /archiva-modules
parent043a336aa51e38a72cf297e9359c174cab8a839c (diff)
downloadarchiva-2721d7bf8d98505f9961d0d741b3bbc396497f2b.tar.gz
archiva-2721d7bf8d98505f9961d0d741b3bbc396497f2b.zip
[MRM-1283] moved browseArtifact() functionality over to metadata repository and remove repositoryBrowsing component
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885001 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java245
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java18
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java59
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java162
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java53
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java7
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java2
-rw-r--r--archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java6
-rw-r--r--archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java18
9 files changed, 312 insertions, 258 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
index 0b32610bb..520cc7b61 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java
@@ -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;
@@ -50,11 +58,6 @@ public class BrowseAction
extends PlexusActionSupport
{
/**
- * @plexus.requirement role-hint="default"
- */
- private RepositoryBrowsing repoBrowsing;
-
- /**
* @plexus.requirement
*/
private MetadataResolver metadataResolver;
@@ -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()
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
index 658e46457..f58193a66 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
@@ -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,
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
index 7226d7eec..aa9f9a840 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java
@@ -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;
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java
index 34b4da6de..72a1811ae 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java
@@ -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
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
index 3911ae55f..8c8139f9b 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
@@ -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;
- }
}
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
index 17b237455..8e54a6ea2 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
@@ -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 );
+ }
}
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java
index 2a2600ae0..2f957c813 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java
@@ -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 );
}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
index 10ba310b4..771128ff4 100644
--- a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
+++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
@@ -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();
+ }
}
diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
index 57772258c..bec509ae4 100644
--- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
+++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
@@ -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
{