[MRM-1283] start to migrate browse functionality to use the content repository. At present, this does everything except the just-in-time processing of models that haven't been stored yet

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@883603 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-24 06:26:04 +00:00
parent 76eeda51bb
commit 627ad47211
23 changed files with 990 additions and 252 deletions

View File

@ -28,7 +28,6 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectBuildMetadata; import org.apache.archiva.metadata.model.ProjectBuildMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.file.FileMetadataRepository;
import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationNames; import org.apache.maven.archiva.configuration.ConfigurationNames;
import org.apache.maven.archiva.configuration.FileTypes; import org.apache.maven.archiva.configuration.FileTypes;
@ -84,6 +83,9 @@ public class ArchivaMetadataCreationConsumer
private List<String> includes = new ArrayList<String>(); private List<String> includes = new ArrayList<String>();
/**
* @plexus.requirement
*/
private MetadataRepository metadataRepository; private MetadataRepository metadataRepository;
public String getId() public String getId()
@ -115,8 +117,6 @@ public class ArchivaMetadataCreationConsumer
throws ConsumerException throws ConsumerException
{ {
this.repository.setRepository( repo ); this.repository.setRepository( repo );
// FIXME: remove hardcoding
this.metadataRepository = new FileMetadataRepository( new File( repository.getRepoRoot(), ".metadata" ) );
this.whenGathered = whenGathered; this.whenGathered = whenGathered;
} }
@ -138,27 +138,28 @@ public class ArchivaMetadataCreationConsumer
File file = new File( repository.getRepoRoot(), path ); File file = new File( repository.getRepoRoot(), path );
// TODO: needed in a more central place, but trying to isolate impact to start with
String metadataId = artifact.getGroupId() + "." + artifact.getArtifactId();
ProjectMetadata project = new ProjectMetadata(); ProjectMetadata project = new ProjectMetadata();
project.setId( metadataId ); project.setNamespace( artifact.getGroupId() );
project.setId( artifact.getArtifactId() );
ProjectBuildMetadata build = new ProjectBuildMetadata(); ProjectBuildMetadata build = new ProjectBuildMetadata();
build.setId( artifact.getVersion() ); build.setId( artifact.getVersion() ); // TODO: this should be the version from the POM, not the timestamped version
ArtifactMetadata artifactMeta = new ArtifactMetadata(); ArtifactMetadata artifactMeta = new ArtifactMetadata();
artifactMeta.setId( file.getName() ); artifactMeta.setId( file.getName() );
artifactMeta.setUpdated( file.lastModified() ); artifactMeta.setUpdated( file.lastModified() );
artifactMeta.setSize( file.length() ); artifactMeta.setSize( file.length() );
artifactMeta.setVersion( artifact.getVersion() );
// TODO: read the POM and fill in the rest of the information
// TODO: store "whenGathered" // TODO: store "whenGathered"
// TODO: transaction // TODO: transaction
// read the metadata and update it if it is newer or doesn't exist // read the metadata and update it if it is newer or doesn't exist
metadataRepository.updateArtifact( metadataId, build.getId(), artifactMeta ); metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), build.getId(), artifactMeta );
metadataRepository.updateBuild( metadataId, build ); metadataRepository.updateBuild( repository.getId(), project.getNamespace(), project.getId(), build );
metadataRepository.updateProject( project ); metadataRepository.updateProject( repository.getId(), project );
} }
public void completeScan() public void completeScan()

View File

@ -166,10 +166,6 @@ public class ArchivaRepositoryScanningTaskExecutor
// log.info( "Scanning for removed repository content" ); // log.info( "Scanning for removed repository content" );
// FIXME: remove hardcoding
// MetadataRepository metadataRepository =
// new FileMetadataRepository( new File( arepo.getLocation(), ".metadata" ) );
// metadataRepository.findAllProjects(); // metadataRepository.findAllProjects();
// FIXME: do something // FIXME: do something

View File

@ -259,6 +259,27 @@
<artifactId>atlassian-xmlrpc-binder-server-spring</artifactId> <artifactId>atlassian-xmlrpc-binder-server-spring</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-model</artifactId>
<version>1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-api</artifactId>
<version>1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-file</artifactId>
<version>1.3-SNAPSHOT</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId> <!-- FIXME: temporary coupling to plugin, should be runtime -->
<artifactId>maven2-repository</artifactId>
<version>1.3-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <resources>

View File

@ -19,28 +19,37 @@ package org.apache.maven.archiva.web.action;
* under the License. * under the License.
*/ */
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.opensymphony.xwork2.Validateable; import com.opensymphony.xwork2.Validateable;
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.ObjectNotFoundException;
import org.apache.maven.archiva.database.browsing.RepositoryBrowsing; import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
import org.apache.maven.archiva.model.ArchivaProjectModel; 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.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.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.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.ArchivaSecurityException;
import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
/** /**
* Browse the repository. * Browse the repository.
* *
* TODO change name to ShowVersionedAction to conform to terminology. * TODO change name to ShowVersionedAction to conform to terminology.
* *
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup" * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
*/ */
public class ShowArtifactAction public class ShowArtifactAction
@ -58,7 +67,12 @@ public class ShowArtifactAction
* @plexus.requirement * @plexus.requirement
*/ */
private UserRepositories userRepositories; private UserRepositories userRepositories;
/**
* @plexus.requirement
*/
private MetadataRepository metadataRepository;
/* .\ Exposed Output Objects \.__________________________________ */ /* .\ Exposed Output Objects \.__________________________________ */
private String groupId; private String groupId;
@ -82,45 +96,100 @@ public class ShowArtifactAction
private List<MailingList> mailingLists; private List<MailingList> mailingLists;
private List<Dependency> dependencies; private List<Dependency> dependencies;
private List<String> snapshotVersions; private List<String> snapshotVersions;
/** /**
* Show the versioned project information tab. TODO: Change name to 'project' * Show the versioned project information tab. TODO: Change name to 'project'
*/ */
public String artifact() public String artifact()
throws ObjectNotFoundException, ArchivaDatabaseException
{ {
try // In the future, this should be replaced by the repository grouping mechanism, so that we are only making
// simple resource requests here and letting the resolver take care of it
ProjectBuildMetadata build = null;
snapshotVersions = new ArrayList<String>();
for ( String repoId : getObservableRepos() )
{ {
if( VersionUtil.isSnapshot( version ) ) if ( build == null )
{ {
this.model = // TODO: we don't really want the implementation being that intelligent - so another resolver to do
repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version ); // the "just-in-time" nature of picking up the metadata (if appropriate for the repository type) if not
// found in the content repository is needed here
this.snapshotVersions = build = metadataRepository.getProjectBuild( repoId, groupId, artifactId, version );
repoBrowsing.getOtherSnapshotVersions( getObservableRepos(), groupId, artifactId, version ); if ( build != null )
if( this.snapshotVersions.contains( version ) )
{ {
this.snapshotVersions.remove( version ); repositoryId = repoId;
} }
} }
else snapshotVersions.addAll( metadataRepository.getArtifactVersions( repoId, groupId, artifactId, version ) );
{ snapshotVersions.remove( version );
this.model =
repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
}
this.repositoryId =
repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
} }
catch ( ObjectNotFoundException e )
if ( build == null )
{ {
log.debug( e.getMessage(), e ); addActionError( "Artifact not found" );
addActionError( e.getMessage() );
return ERROR; return ERROR;
} }
// TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics
model = new ArchivaProjectModel();
MavenProjectFacet projectFacet = (MavenProjectFacet) build.getFacet( MavenProjectFacet.FACET_ID );
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 );
}
model.setVersion( build.getId() );
model.setDescription( build.getDescription() );
model.setName( build.getName() );
model.setUrl( build.getUrl() );
if ( build.getOrganization() != null )
{
Organization organization = new Organization();
organization.setName( build.getOrganization().getName() );
organization.setUrl( build.getOrganization().getUrl() );
model.setOrganization( organization );
}
if ( build.getCiManagement() != null )
{
CiManagement ci = new CiManagement();
ci.setSystem( build.getCiManagement().getSystem() );
ci.setUrl( build.getCiManagement().getUrl() );
model.setCiManagement( ci );
}
if ( build.getIssueManagement() != null )
{
IssueManagement issueManagement = new IssueManagement();
issueManagement.setSystem( build.getIssueManagement().getSystem() );
issueManagement.setUrl( build.getIssueManagement().getUrl() );
model.setIssueManagement( issueManagement );
}
if ( build.getScm() != null )
{
Scm scm = new Scm();
scm.setConnection( build.getScm().getConnection() );
scm.setDeveloperConnection( build.getScm().getDeveloperConnection() );
scm.setUrl( build.getScm().getUrl() );
model.setScm( scm );
}
if ( build.getLicenses() != null )
{
for ( org.apache.archiva.metadata.model.License l : build.getLicenses() )
{
License license = new License();
license.setName( l.getName() );
license.setUrl( l.getUrl() );
model.addLicense( license );
}
}
return SUCCESS; return SUCCESS;
} }
@ -296,4 +365,8 @@ public class ShowArtifactAction
this.snapshotVersions = snapshotVersions; this.snapshotVersions = snapshotVersions;
} }
public MetadataRepository getMetadataRepository()
{
return metadataRepository;
}
} }

View File

@ -0,0 +1,89 @@
package org.apache.archiva.metadata.repository.memory;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository;
public class MemoryMetadataRepository
implements MetadataRepository
{
private Map<String, ProjectBuildMetadata> projectBuilds = new HashMap<String, ProjectBuildMetadata>();
private Map<String, List<String>> artifactVersions = new HashMap<String, List<String>>();
public void updateProject( String repoId, ProjectMetadata project )
{
throw new UnsupportedOperationException( );
}
public void updateArtifact( String repoId, String namespace, String projectId, String buildId, ArtifactMetadata artifactMeta )
{
throw new UnsupportedOperationException( );
}
public void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
{
throw new UnsupportedOperationException( );
}
public ProjectMetadata getProject( String repoId, String namespace, String projectId )
{
ProjectMetadata metadata = new ProjectMetadata();
metadata.setNamespace( namespace );
metadata.setId( projectId );
return metadata;
}
public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
{
return projectBuilds.get( createMapKey( repoId, namespace, projectId, buildId ) );
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
{
List<String> versions = artifactVersions.get( createMapKey( repoId, namespace, projectId, buildId ) );
return ( versions != null ? versions : Collections.<String>emptyList() );
}
public void setProjectBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
{
projectBuilds.put( createMapKey( repoId, namespace, projectId, build.getId() ), build );
}
public void setArtifactVersions( String repoId, String namespace, String projectId, String version,
List<String> versions )
{
artifactVersions.put( createMapKey( repoId, namespace, projectId, version ), versions );
}
private String createMapKey( String repoId, String namespace, String projectId, String buildId )
{
return repoId + ":" + namespace + ":" + projectId + ":" + buildId;
}
}

View File

@ -24,25 +24,19 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.Action;
import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.archiva.metadata.model.CiManagement;
import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.archiva.metadata.model.IssueManagement;
import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.archiva.metadata.model.License;
import org.apache.maven.archiva.database.ProjectModelDAO; import org.apache.archiva.metadata.model.Organization;
import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint; import org.apache.archiva.metadata.model.ProjectBuildMetadata;
import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.archiva.metadata.model.Scm;
import org.apache.maven.archiva.model.ArchivaArtifactModel; import org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository;
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.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.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.apache.maven.archiva.security.UserRepositoriesStub; import org.apache.maven.archiva.security.UserRepositoriesStub;
import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
public class ShowArtifactActionTest public class ShowArtifactActionTest
extends PlexusInSpringTestCase extends PlexusInSpringTestCase
@ -97,32 +91,28 @@ public class ShowArtifactActionTest
private static final String TEST_SCM_URL = "scmUrl"; private static final String TEST_SCM_URL = "scmUrl";
private ShowArtifactAction action;
private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT"; private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1"; private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
private ArchivaDAOStub archivaDao;
private static final List<String> ALL_TEST_SNAPSHOT_VERSIONS = private static final List<String> ALL_TEST_SNAPSHOT_VERSIONS =
Arrays.asList( TEST_TS_SNAPSHOT_VERSION, "1.0-20091120.222222-2", "1.0-20091123.333333-3" ); Arrays.asList( TEST_TS_SNAPSHOT_VERSION, "1.0-20091120.222222-2", "1.0-20091123.333333-3" );
private static final String OTHER_TEST_REPO = "first-repo"; private static final String OTHER_TEST_REPO = "first-repo";
private ShowArtifactAction action;
private MemoryMetadataRepository metadataRepository;
public void testInstantiation() public void testInstantiation()
{ {
assertFalse( action == lookup( Action.class, ACTION_HINT ) ); assertFalse( action == lookup( Action.class, ACTION_HINT ) );
} }
public void testGetArtifactUniqueRelease() public void testGetArtifactUniqueRelease()
throws ArchivaDatabaseException
{ {
List<ArchivaArtifact> artifacts = metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -130,9 +120,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result ); assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action ); assertActionParameters( action );
ArchivaProjectModel model = action.getModel(); ArchivaProjectModel model = action.getModel();
assertDefaultModel( model ); assertDefaultModel( model );
@ -142,18 +129,15 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() ); assertNull( action.getDependees() );
assertNull( action.getDependencies() ); assertNull( action.getDependencies() );
assertNull( action.getMailingLists() ); assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() ); assertTrue( action.getSnapshotVersions().isEmpty() );
} }
public void testGetArtifactUniqueSnapshot() public void testGetArtifactUniqueSnapshot()
throws ArchivaDatabaseException
{ {
List<ArchivaArtifact> artifacts = metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION ) ); createProjectModel( TEST_SNAPSHOT_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, TEST_SNAPSHOT_VERSION, 2 ); metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
MockControl projectDaoMockControl = ALL_TEST_SNAPSHOT_VERSIONS );
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION ) );
archivaDao.setVersions( ALL_TEST_SNAPSHOT_VERSIONS );
action.setGroupId( TEST_GROUP_ID ); action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID ); action.setArtifactId( TEST_ARTIFACT_ID );
@ -163,9 +147,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result ); assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertEquals( TEST_GROUP_ID, action.getGroupId() ); assertEquals( TEST_GROUP_ID, action.getGroupId() );
assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() ); assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() ); assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
@ -182,14 +163,11 @@ public class ShowArtifactActionTest
} }
public void testGetArtifactUniqueSnapshotTimestamped() public void testGetArtifactUniqueSnapshotTimestamped()
throws ArchivaDatabaseException
{ {
List<ArchivaArtifact> artifacts = metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION ) ); createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, TEST_TS_SNAPSHOT_VERSION, 2 ); metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
MockControl projectDaoMockControl = ALL_TEST_SNAPSHOT_VERSIONS );
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION ) );
archivaDao.setVersions( ALL_TEST_SNAPSHOT_VERSIONS );
action.setGroupId( TEST_GROUP_ID ); action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID ); action.setArtifactId( TEST_ARTIFACT_ID );
@ -199,9 +177,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result ); assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertEquals( TEST_GROUP_ID, action.getGroupId() ); assertEquals( TEST_GROUP_ID, action.getGroupId() );
assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() ); assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
assertEquals( TEST_TS_SNAPSHOT_VERSION, action.getVersion() ); assertEquals( TEST_TS_SNAPSHOT_VERSION, action.getVersion() );
@ -219,71 +194,49 @@ public class ShowArtifactActionTest
} }
public void testGetMissingProject() public void testGetMissingProject()
throws ArchivaDatabaseException
{ {
MockControl artifactDaoMockControl = createArtifactDaoMock( Collections.<ArchivaArtifact>emptyList(), 1 );
setActionParameters(); setActionParameters();
String result = action.artifact(); String result = action.artifact();
assertError( result ); assertError( result );
artifactDaoMockControl.verify();
assertActionParameters( action ); assertActionParameters( action );
assertNoOutputFields(); assertNoOutputFields();
} }
public void testGetArtifactNoObservableRepos() public void testGetArtifactNoObservableRepos()
throws ArchivaDatabaseException
{ {
setObservableRepos( Collections.<String>emptyList() ); setObservableRepos( Collections.<String>emptyList() );
setActionParameters(); setActionParameters();
try String result = action.artifact();
{
action.artifact();
// Actually, it'd be better to have an error: // Actually, it'd be better to have an error:
// assertError( result ); assertError( result );
// assertActionParameters( action ); assertActionParameters( action );
// assertNoOutputFields(); assertNoOutputFields();
fail();
}
catch ( ArchivaDatabaseException e )
{
assertTrue( true );
}
} }
public void testGetArtifactNotInObservableRepos() public void testGetArtifactNotInObservableRepos()
throws ArchivaDatabaseException
{ {
List<ArchivaArtifact> artifacts = Collections.singletonList( metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, OTHER_TEST_REPO ) ); createProjectModel( TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
setActionParameters(); setActionParameters();
String result = action.artifact(); String result = action.artifact();
assertError( result ); assertError( result );
artifactDaoMockControl.verify();
assertActionParameters( action ); assertActionParameters( action );
assertNoOutputFields(); assertNoOutputFields();
} }
public void testGetArtifactOnlySeenInSecondObservableRepo() public void testGetArtifactOnlySeenInSecondObservableRepo()
throws ArchivaDatabaseException
{ {
setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) ); setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
List<ArchivaArtifact> artifacts = metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -291,9 +244,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result ); assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action ); assertActionParameters( action );
ArchivaProjectModel model = action.getModel(); ArchivaProjectModel model = action.getModel();
assertDefaultModel( model ); assertDefaultModel( model );
@ -303,19 +253,16 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() ); assertNull( action.getDependees() );
assertNull( action.getDependencies() ); assertNull( action.getDependencies() );
assertNull( action.getMailingLists() ); assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() ); assertTrue( action.getSnapshotVersions().isEmpty() );
} }
public void testGetArtifactSeenInBothObservableRepo() public void testGetArtifactSeenInBothObservableRepo()
throws ArchivaDatabaseException
{ {
setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) ); setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
List<ArchivaArtifact> artifacts = metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
Arrays.asList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ), createProjectModel( TEST_VERSION ) );
createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, OTHER_TEST_REPO ) ); metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 ); createProjectModel( TEST_VERSION ) );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -323,9 +270,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result ); assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action ); assertActionParameters( action );
ArchivaProjectModel model = action.getModel(); ArchivaProjectModel model = action.getModel();
assertDefaultModel( model ); assertDefaultModel( model );
@ -335,19 +279,16 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() ); assertNull( action.getDependees() );
assertNull( action.getDependencies() ); assertNull( action.getDependencies() );
assertNull( action.getMailingLists() ); assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() ); assertTrue( action.getSnapshotVersions().isEmpty() );
} }
public void testGetArtifactCanOnlyObserveInOneOfTwoRepos() public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
throws ArchivaDatabaseException
{ {
setObservableRepos( Arrays.asList( TEST_REPO ) ); setObservableRepos( Arrays.asList( TEST_REPO ) );
List<ArchivaArtifact> artifacts = metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
Arrays.asList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, OTHER_TEST_REPO ), createProjectModel( TEST_VERSION ) );
createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) ); metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 ); createProjectModel( TEST_VERSION ) );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -355,9 +296,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result ); assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action ); assertActionParameters( action );
ArchivaProjectModel model = action.getModel(); ArchivaProjectModel model = action.getModel();
assertDefaultModel( model ); assertDefaultModel( model );
@ -367,7 +305,7 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() ); assertNull( action.getDependees() );
assertNull( action.getDependencies() ); assertNull( action.getDependencies() );
assertNull( action.getMailingLists() ); assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() ); assertTrue( action.getSnapshotVersions().isEmpty() );
} }
private void assertNoOutputFields() private void assertNoOutputFields()
@ -376,7 +314,7 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() ); assertNull( action.getDependees() );
assertNull( action.getDependencies() ); assertNull( action.getDependencies() );
assertNull( action.getMailingLists() ); assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() ); assertTrue( action.getSnapshotVersions().isEmpty() );
} }
private void assertError( String result ) private void assertError( String result )
@ -401,22 +339,18 @@ public class ShowArtifactActionTest
assertEquals( TEST_GROUP_ID, model.getGroupId() ); assertEquals( TEST_GROUP_ID, model.getGroupId() );
assertEquals( TEST_ARTIFACT_ID, model.getArtifactId() ); assertEquals( TEST_ARTIFACT_ID, model.getArtifactId() );
assertEquals( version, model.getVersion() ); assertEquals( version, model.getVersion() );
assertEquals( TEST_PACKAGING, model.getPackaging() );
assertEquals( TEST_URL, model.getUrl() ); assertEquals( TEST_URL, model.getUrl() );
assertEquals( TEST_NAME, model.getName() ); assertEquals( TEST_NAME, model.getName() );
assertEquals( TEST_DESCRIPTION, model.getDescription() ); assertEquals( TEST_DESCRIPTION, model.getDescription() );
assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() ); assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() );
assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() ); assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() );
assertEquals( 2, model.getLicenses().size() ); assertEquals( 2, model.getLicenses().size() );
License l = model.getLicenses().get( 0 ); org.apache.maven.archiva.model.License l = model.getLicenses().get( 0 );
assertEquals( TEST_LICENSE_NAME, l.getName() ); assertEquals( TEST_LICENSE_NAME, l.getName() );
assertEquals( TEST_LICENSE_URL, l.getUrl() ); assertEquals( TEST_LICENSE_URL, l.getUrl() );
l = model.getLicenses().get( 1 ); l = model.getLicenses().get( 1 );
assertEquals( TEST_LICENSE_NAME_2, l.getName() ); assertEquals( TEST_LICENSE_NAME_2, l.getName() );
assertEquals( TEST_LICENSE_URL_2, l.getUrl() ); assertEquals( TEST_LICENSE_URL_2, l.getUrl() );
assertEquals( TEST_PARENT_GROUP_ID, model.getParentProject().getGroupId() );
assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() );
assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() );
assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() ); assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() );
assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() ); assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() );
assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() ); assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() );
@ -424,6 +358,11 @@ public class ShowArtifactActionTest
assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() ); assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() );
assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() ); assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() );
assertEquals( TEST_SCM_URL, model.getScm().getUrl() ); assertEquals( TEST_SCM_URL, model.getScm().getUrl() );
assertEquals( TEST_PACKAGING, model.getPackaging() );
assertEquals( TEST_PARENT_GROUP_ID, model.getParentProject().getGroupId() );
assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() );
assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() );
} }
private void setActionParameters() private void setActionParameters()
@ -447,21 +386,13 @@ public class ShowArtifactActionTest
assertTrue( action.getActionMessages().isEmpty() ); assertTrue( action.getActionMessages().isEmpty() );
} }
private ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version ) private ProjectBuildMetadata createProjectModel( String version )
{ {
ArchivaProjectModel model = new ArchivaProjectModel(); ProjectBuildMetadata model = new ProjectBuildMetadata();
model.setGroupId( groupId ); model.setId( version );
model.setArtifactId( artifactId );
model.setVersion( version );
model.setPackaging( TEST_PACKAGING );
model.setUrl( TEST_URL ); model.setUrl( TEST_URL );
model.setName( TEST_NAME ); model.setName( TEST_NAME );
model.setDescription( TEST_DESCRIPTION ); 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(); CiManagement ci = new CiManagement();
ci.setSystem( TEST_CI_SYSTEM ); ci.setSystem( TEST_CI_SYSTEM );
ci.setUrl( TEST_CI_URL ); ci.setUrl( TEST_CI_URL );
@ -470,10 +401,10 @@ public class ShowArtifactActionTest
issue.setSystem( TEST_ISSUE_SYSTEM ); issue.setSystem( TEST_ISSUE_SYSTEM );
issue.setUrl( TEST_ISSUE_URL ); issue.setUrl( TEST_ISSUE_URL );
model.setIssueManagement( issue ); model.setIssueManagement( issue );
Organization org = new Organization(); Organization organization = new Organization();
org.setName( TEST_ORGANIZATION_NAME ); organization.setName( TEST_ORGANIZATION_NAME );
org.setUrl( TEST_ORGANIZATION_URL ); organization.setUrl( TEST_ORGANIZATION_URL );
model.setOrganization( org ); model.setOrganization( organization );
License l = new License(); License l = new License();
l.setName( TEST_LICENSE_NAME ); l.setName( TEST_LICENSE_NAME );
l.setUrl( TEST_LICENSE_URL ); l.setUrl( TEST_LICENSE_URL );
@ -487,66 +418,25 @@ public class ShowArtifactActionTest
scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION ); scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
scm.setUrl( TEST_SCM_URL ); scm.setUrl( TEST_SCM_URL );
model.setScm( scm ); 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; return model;
} }
private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, int count )
throws ArchivaDatabaseException
{
return createArtifactDaoMock( artifacts, TEST_VERSION, count );
}
private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, String version, int count )
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 );
ArtifactsRelatedConstraint c = new ArtifactsRelatedConstraint( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
dao.queryArtifacts( c );
control.setReturnValue( artifacts, count );
control.replay();
return control;
}
private MockControl createProjectDaoMock( ArchivaProjectModel project )
throws ArchivaDatabaseException
{
MockControl control = MockControl.createNiceControl( ProjectModelDAO.class );
ProjectModelDAO dao = (ProjectModelDAO) control.getMock();
archivaDao.setProjectDao( dao );
control.expectAndReturn(
dao.getProjectModel( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
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 );
}
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT ); action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" ); metadataRepository = (MemoryMetadataRepository) action.getMetadataRepository();
} }
} }

View File

@ -35,5 +35,11 @@
<role-hint>default</role-hint> <role-hint>default</role-hint>
<implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation> <implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation>
</component> </component>
<component>
<role>org.apache.archiva.metadata.repository.MetadataRepository</role>
<role-hint>default</role-hint>
<implementation>org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository</implementation>
<instantiation-strategy>per-lookup</instantiation-strategy>
</component>
</components> </components>
</plexus> </plexus>

View File

@ -28,8 +28,8 @@ The following is the intended content model for the metadata content repository:
| | |-- created= | | |-- created=
| | |-- description= | | |-- description=
| | |-- name= | | |-- name=
| | |-- organizationName= | | |-- organization.name=
| | |-- organizationUrl= | | |-- organization.url=
| | `-- updated= | | `-- updated=
| |-- maven:artifactId= | |-- maven:artifactId=
| `-- maven:groupId= | `-- maven:groupId=
@ -50,3 +50,5 @@ file in the original storageUrl when it is requested
4) The API will still use separate namespace and project identifiers (the namespace can be null if there isn't one). This is chosen to allow 4) The API will still use separate namespace and project identifiers (the namespace can be null if there isn't one). This is chosen to allow
splitting the namespace on '.', and also allowing '.' in the project identifier without splitting splitting the namespace on '.', and also allowing '.' in the project identifier without splitting
5) properties with '.' may be nested in other representations such as Java models or XML, if appropriate

View File

@ -29,6 +29,8 @@ public class ArtifactMetadata
private long size; private long size;
private String version;
public String getId() public String getId()
{ {
return id; return id;
@ -63,4 +65,14 @@ public class ArtifactMetadata
{ {
this.size = size; this.size = size;
} }
public String getVersion()
{
return version;
}
public void setVersion( String version )
{
this.version = version;
}
} }

View File

@ -0,0 +1,47 @@
package org.apache.archiva.metadata.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class CiManagement
{
private String system;
private String url;
public String getUrl()
{
return url;
}
public void setUrl( String url )
{
this.url = url;
}
public String getSystem()
{
return system;
}
public void setSystem( String system )
{
this.system = system;
}
}

View File

@ -0,0 +1,47 @@
package org.apache.archiva.metadata.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class IssueManagement
{
private String system;
private String url;
public String getUrl()
{
return url;
}
public void setUrl( String url )
{
this.url = url;
}
public String getSystem()
{
return system;
}
public void setSystem( String system )
{
this.system = system;
}
}

View File

@ -0,0 +1,47 @@
package org.apache.archiva.metadata.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class License
{
private String name;
private String url;
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
public String getUrl()
{
return url;
}
public void setUrl( String url )
{
this.url = url;
}
}

View File

@ -0,0 +1,47 @@
package org.apache.archiva.metadata.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class Organization
{
private String name;
private String url;
public String getUrl()
{
return url;
}
public void setUrl( String url )
{
this.url = url;
}
public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
}

View File

@ -0,0 +1,25 @@
package org.apache.archiva.metadata.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public interface ProjectBuildFacet
{
String getFacetId();
}

View File

@ -19,10 +19,33 @@ package org.apache.archiva.metadata.model;
* under the License. * under the License.
*/ */
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProjectBuildMetadata public class ProjectBuildMetadata
{ {
private String id; private String id;
private String url;
private String name;
private String description;
private Organization organization;
private IssueManagement issueManagement;
private Scm scm;
private CiManagement ciManagement;
private List<License> licenses;
private Map<String, ProjectBuildFacet> facets;
public String getId() public String getId()
{ {
return id; return id;
@ -33,4 +56,106 @@ public class ProjectBuildMetadata
this.id = id; this.id = id;
} }
public void setUrl( String url )
{
this.url = url;
}
public void setName( String name )
{
this.name = name;
}
public void setDescription( String description )
{
this.description = description;
}
public String getDescription()
{
return description;
}
public String getUrl()
{
return url;
}
public String getName()
{
return name;
}
public Organization getOrganization()
{
return organization;
}
public void setOrganization( Organization organization )
{
this.organization = organization;
}
public IssueManagement getIssueManagement()
{
return issueManagement;
}
public void setIssueManagement( IssueManagement issueManagement )
{
this.issueManagement = issueManagement;
}
public Scm getScm()
{
return scm;
}
public void setScm( Scm scm )
{
this.scm = scm;
}
public CiManagement getCiManagement()
{
return ciManagement;
}
public void setCiManagement( CiManagement ciManagement )
{
this.ciManagement = ciManagement;
}
public List<License> getLicenses()
{
return licenses;
}
public void setLicenses( List<License> licenses )
{
this.licenses = licenses;
}
public void addLicense( License license )
{
if ( this.licenses == null )
{
this.licenses = new ArrayList<License>();
}
this.licenses.add( license );
}
public void addFacet( ProjectBuildFacet mavenProjectFacet )
{
if ( this.facets == null )
{
this.facets = new HashMap<String, ProjectBuildFacet>();
}
this.facets.put( mavenProjectFacet.getFacetId(), mavenProjectFacet );
}
public ProjectBuildFacet getFacet( String facetId )
{
return this.facets.get( facetId );
}
} }

View File

@ -21,6 +21,8 @@ package org.apache.archiva.metadata.model;
public class ProjectMetadata public class ProjectMetadata
{ {
private String namespace;
private String id; private String id;
public void setId( String id ) public void setId( String id )
@ -33,4 +35,13 @@ public class ProjectMetadata
return id; return id;
} }
public String getNamespace()
{
return namespace;
}
public void setNamespace( String namespace )
{
this.namespace = namespace;
}
} }

View File

@ -0,0 +1,59 @@
package org.apache.archiva.metadata.model;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class Scm
{
private String connection;
private String developerConnection;
private String url;
public String getUrl()
{
return url;
}
public void setUrl( String url )
{
this.url = url;
}
public String getDeveloperConnection()
{
return developerConnection;
}
public void setDeveloperConnection( String developerConnection )
{
this.developerConnection = developerConnection;
}
public String getConnection()
{
return connection;
}
public void setConnection( String connection )
{
this.connection = connection;
}
}

View File

@ -19,20 +19,27 @@ package org.apache.archiva.metadata.repository;
* under the License. * under the License.
*/ */
import java.util.Collection;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectBuildMetadata; import org.apache.archiva.metadata.model.ProjectBuildMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectMetadata;
public interface MetadataRepository public interface MetadataRepository
{ {
/** /**
* Update metadata for a particular project in the metadata repository, or create it if it does not already exist. * Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
* @param project the project metadata to create or update * @param project the project metadata to create or update
*/ */
void updateProject( ProjectMetadata project ); void updateProject( String repoId, ProjectMetadata project );
void updateArtifact( String projectId, String buildId, ArtifactMetadata artifactMeta ); void updateArtifact( String repoId, String namespace, String projectId, String buildId, ArtifactMetadata artifactMeta );
void updateBuild( String projectId, ProjectBuildMetadata build ); void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build );
ProjectMetadata getProject( String repoId, String namespace, String projectId );
ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId );
Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId );
} }

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>plugins</artifactId>
<groupId>org.apache.archiva</groupId>
<version>1.3-SNAPSHOT</version>
</parent>
<artifactId>maven2-repository</artifactId>
<name>Maven 2.x Repository Support</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-model</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,81 @@
package org.apache.archiva.metadata.repository.storage.maven2;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.archiva.metadata.model.ProjectBuildFacet;
public class MavenProjectFacet
implements ProjectBuildFacet
{
private String groupId;
private String artifactId;
private MavenProjectParent parent;
private String packaging;
public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2";
public String getGroupId()
{
return groupId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public String getArtifactId()
{
return artifactId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public MavenProjectParent getParent()
{
return parent;
}
public void setParent( MavenProjectParent parent )
{
this.parent = parent;
}
public String getPackaging()
{
return packaging;
}
public void setPackaging( String packaging )
{
this.packaging = packaging;
}
public String getFacetId()
{
return FACET_ID;
}
}

View File

@ -0,0 +1,59 @@
package org.apache.archiva.metadata.repository.storage.maven2;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
public class MavenProjectParent
{
private String groupId;
private String artifactId;
private String version;
public String getVersion()
{
return version;
}
public void setVersion( String version )
{
this.version = version;
}
public String getArtifactId()
{
return artifactId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public String getGroupId()
{
return groupId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
}

View File

@ -24,6 +24,10 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
@ -32,23 +36,26 @@ import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
/**
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
*/
public class FileMetadataRepository public class FileMetadataRepository
implements MetadataRepository implements MetadataRepository
{ {
private File directory; /**
* @plexus.configuration
*/
private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
public FileMetadataRepository( File directory ) public void updateProject( String repoId, ProjectMetadata project )
{
this.directory = directory;
}
public void updateProject( ProjectMetadata project )
{ {
// TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes // TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
try try
{ {
File projectDirectory = new File( this.directory, project.getId() ); File projectDirectory =
new File( this.directory, repoId + "/" + project.getNamespace() + "/" + project.getId() );
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( "namespace", project.getNamespace() );
properties.setProperty( "id", project.getId() ); properties.setProperty( "id", project.getId() );
writeProperties( properties, projectDirectory ); writeProperties( properties, projectDirectory );
} }
@ -59,9 +66,9 @@ public class FileMetadataRepository
} }
} }
public void updateBuild( String projectId, ProjectBuildMetadata build ) public void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
{ {
File directory = new File( this.directory, projectId ); File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId );
Properties properties = new Properties(); Properties properties = new Properties();
properties.setProperty( "id", build.getId() ); properties.setProperty( "id", build.getId() );
@ -77,10 +84,30 @@ public class FileMetadataRepository
} }
} }
public void updateArtifact( String projectId, String buildId, ArtifactMetadata artifact ) public void updateArtifact( String repoId, String namespace, String projectId, String buildId,
ArtifactMetadata artifact )
{ {
File directory = new File( this.directory, projectId + "/" + buildId ); File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + buildId );
Properties properties = readProperties( directory );
properties.setProperty( "updated:" + artifact.getId(), Long.toString( artifact.getUpdated().getTime() ) );
properties.setProperty( "size:" + artifact.getId(), Long.toString( artifact.getSize() ) );
properties.setProperty( "version:" + artifact.getId(), artifact.getVersion() );
try
{
writeProperties( properties, directory );
}
catch ( IOException e )
{
// TODO
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
private Properties readProperties( File directory )
{
Properties properties = new Properties(); Properties properties = new Properties();
FileInputStream in = null; FileInputStream in = null;
try try
@ -101,19 +128,48 @@ public class FileMetadataRepository
{ {
IOUtils.closeQuietly( in ); IOUtils.closeQuietly( in );
} }
return properties;
}
properties.setProperty( artifact.getId() + ".updated", Long.toString( artifact.getUpdated().getTime() ) ); public ProjectMetadata getProject( String repoId, String groupId, String projectId )
properties.setProperty( artifact.getId() + ".size", Long.toString( artifact.getSize() ) ); {
File directory = new File( this.directory, repoId + "/" + projectId );
try Properties properties = readProperties( directory );
ProjectMetadata project = new ProjectMetadata();
project.setNamespace( properties.getProperty( "namespace" ) );
project.setId( properties.getProperty( "id" ) );
return project;
}
public ProjectBuildMetadata getProjectBuild( String repoId, String groupId, String projectId, String buildId )
{
File directory = new File( this.directory, repoId + "/" + projectId + "/" + buildId );
Properties properties = readProperties( directory );
ProjectBuildMetadata build = new ProjectBuildMetadata();
build.setId( properties.getProperty( "id" ) );
return build;
}
public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
{
File directory = new File( this.directory, repoId + "/" + projectId + "/" + buildId );
Properties properties = readProperties( directory );
List<String> versions = new ArrayList<String>();
for ( Map.Entry entry : properties.entrySet() )
{ {
writeProperties( properties, directory ); String name = (String) entry.getKey();
} if ( name.startsWith( "version:" ) )
catch ( IOException e ) {
{ versions.add( (String) entry.getValue() );
// TODO }
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} }
return versions;
} }
private void writeProperties( Properties properties, File directory ) private void writeProperties( Properties properties, File directory )

View File

@ -28,5 +28,6 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>metadata-repository-file</module> <module>metadata-repository-file</module>
<module>maven2-repository</module>
</modules> </modules>
</project> </project>