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;
public class BrowseAction
extends PlexusActionSupport
{
- /**
- * @plexus.requirement role-hint="default"
- */
- private RepositoryBrowsing repoBrowsing;
-
/**
* @plexus.requirement
*/
}
public String browseArtifact()
+ throws MetadataResolverException
{
if ( StringUtils.isEmpty( groupId ) )
{
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 );
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()
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();
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 )
{
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,
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;
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;
+ }
}
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
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" );
}
public void testBrowseArtifactNoObservableRepos()
+ throws MetadataResolverException
{
setObservableRepos( Collections.<String>emptyList() );
String selectedGroupId = "org.apache";
}
public void testBrowseArtifactNoGroupId()
+ throws MetadataResolverException
{
String selectedArtifactId = "apache";
}
public void testBrowseArtifactNoArtifactId()
+ throws MetadataResolverException
{
String selectedGroupId = "org.apache";
}
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() );
}
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() );
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
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;
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;
- }
}
// 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 );
+ }
}
Collection<String> getNamespaces( String repoId, String namespace );
Collection<String> getProjects( String repoId, String namespace );
+
+ Collection<String> getProjectVersions( String repoId, String namespace, String projectId );
}
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 )
{
{
throw new UnsupportedOperationException();
}
+
+ public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+ {
+ throw new UnsupportedOperationException();
+ }
}
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
{