[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.ProjectMetadata;
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.ConfigurationNames;
import org.apache.maven.archiva.configuration.FileTypes;
@ -84,6 +83,9 @@ public class ArchivaMetadataCreationConsumer
private List<String> includes = new ArrayList<String>();
/**
* @plexus.requirement
*/
private MetadataRepository metadataRepository;
public String getId()
@ -115,8 +117,6 @@ public class ArchivaMetadataCreationConsumer
throws ConsumerException
{
this.repository.setRepository( repo );
// FIXME: remove hardcoding
this.metadataRepository = new FileMetadataRepository( new File( repository.getRepoRoot(), ".metadata" ) );
this.whenGathered = whenGathered;
}
@ -138,27 +138,28 @@ public class ArchivaMetadataCreationConsumer
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();
project.setId( metadataId );
project.setNamespace( artifact.getGroupId() );
project.setId( artifact.getArtifactId() );
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();
artifactMeta.setId( file.getName() );
artifactMeta.setUpdated( file.lastModified() );
artifactMeta.setSize( file.length() );
artifactMeta.setVersion( artifact.getVersion() );
// TODO: read the POM and fill in the rest of the information
// TODO: store "whenGathered"
// TODO: transaction
// read the metadata and update it if it is newer or doesn't exist
metadataRepository.updateArtifact( metadataId, build.getId(), artifactMeta );
metadataRepository.updateBuild( metadataId, build );
metadataRepository.updateProject( project );
metadataRepository.updateArtifact( repository.getId(), project.getNamespace(), project.getId(), build.getId(), artifactMeta );
metadataRepository.updateBuild( repository.getId(), project.getNamespace(), project.getId(), build );
metadataRepository.updateProject( repository.getId(), project );
}
public void completeScan()

View File

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

View File

@ -259,6 +259,27 @@
<artifactId>atlassian-xmlrpc-binder-server-spring</artifactId>
<scope>runtime</scope>
</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>
<build>
<resources>

View File

@ -19,28 +19,37 @@ package org.apache.maven.archiva.web.action;
* under the License.
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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.maven.archiva.common.utils.VersionUtil;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ObjectNotFoundException;
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;
import org.apache.maven.archiva.security.UserRepositories;
/**
* Browse the repository.
*
* Browse the repository.
*
* TODO change name to ShowVersionedAction to conform to terminology.
*
*
* @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
*/
public class ShowArtifactAction
@ -58,7 +67,12 @@ public class ShowArtifactAction
* @plexus.requirement
*/
private UserRepositories userRepositories;
/**
* @plexus.requirement
*/
private MetadataRepository metadataRepository;
/* .\ Exposed Output Objects \.__________________________________ */
private String groupId;
@ -82,45 +96,100 @@ public class ShowArtifactAction
private List<MailingList> mailingLists;
private List<Dependency> dependencies;
private List<String> snapshotVersions;
/**
* Show the versioned project information tab. TODO: Change name to 'project'
*/
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 ) )
{
this.model =
repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
this.snapshotVersions =
repoBrowsing.getOtherSnapshotVersions( getObservableRepos(), groupId, artifactId, version );
if( this.snapshotVersions.contains( version ) )
if ( build == null )
{
// TODO: we don't really want the implementation being that intelligent - so another resolver to do
// 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
build = metadataRepository.getProjectBuild( repoId, groupId, artifactId, version );
if ( build != null )
{
this.snapshotVersions.remove( version );
repositoryId = repoId;
}
}
else
{
this.model =
repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
}
this.repositoryId =
repoBrowsing.getRepositoryId( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
snapshotVersions.addAll( metadataRepository.getArtifactVersions( repoId, groupId, artifactId, version ) );
snapshotVersions.remove( version );
}
catch ( ObjectNotFoundException e )
if ( build == null )
{
log.debug( e.getMessage(), e );
addActionError( e.getMessage() );
addActionError( "Artifact not found" );
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;
}
@ -296,4 +365,8 @@ public class ShowArtifactAction
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 com.opensymphony.xwork2.Action;
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.constraints.ArtifactsRelatedConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
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.ProjectBuildMetadata;
import org.apache.archiva.metadata.model.Scm;
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.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.UserRepositoriesStub;
import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
public class ShowArtifactActionTest
extends PlexusInSpringTestCase
@ -97,32 +91,28 @@ public class ShowArtifactActionTest
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_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
private ArchivaDAOStub archivaDao;
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" );
private static final String OTHER_TEST_REPO = "first-repo";
private ShowArtifactAction action;
private MemoryMetadataRepository metadataRepository;
public void testInstantiation()
{
assertFalse( action == lookup( Action.class, ACTION_HINT ) );
}
public void testGetArtifactUniqueRelease()
throws ArchivaDatabaseException
{
List<ArchivaArtifact> artifacts =
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
setActionParameters();
@ -130,9 +120,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
@ -142,18 +129,15 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() );
assertTrue( action.getSnapshotVersions().isEmpty() );
}
public void testGetArtifactUniqueSnapshot()
throws ArchivaDatabaseException
{
List<ArchivaArtifact> artifacts =
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, TEST_SNAPSHOT_VERSION, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION ) );
archivaDao.setVersions( ALL_TEST_SNAPSHOT_VERSIONS );
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_SNAPSHOT_VERSION ) );
metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
ALL_TEST_SNAPSHOT_VERSIONS );
action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID );
@ -163,9 +147,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertEquals( TEST_GROUP_ID, action.getGroupId() );
assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
@ -182,14 +163,11 @@ public class ShowArtifactActionTest
}
public void testGetArtifactUniqueSnapshotTimestamped()
throws ArchivaDatabaseException
{
List<ArchivaArtifact> artifacts =
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, TEST_TS_SNAPSHOT_VERSION, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION ) );
archivaDao.setVersions( ALL_TEST_SNAPSHOT_VERSIONS );
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
ALL_TEST_SNAPSHOT_VERSIONS );
action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID );
@ -199,9 +177,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertEquals( TEST_GROUP_ID, action.getGroupId() );
assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
assertEquals( TEST_TS_SNAPSHOT_VERSION, action.getVersion() );
@ -219,71 +194,49 @@ public class ShowArtifactActionTest
}
public void testGetMissingProject()
throws ArchivaDatabaseException
{
MockControl artifactDaoMockControl = createArtifactDaoMock( Collections.<ArchivaArtifact>emptyList(), 1 );
setActionParameters();
String result = action.artifact();
assertError( result );
artifactDaoMockControl.verify();
assertActionParameters( action );
assertNoOutputFields();
}
public void testGetArtifactNoObservableRepos()
throws ArchivaDatabaseException
{
setObservableRepos( Collections.<String>emptyList() );
setActionParameters();
try
{
action.artifact();
String result = action.artifact();
// Actually, it'd be better to have an error:
// assertError( result );
// assertActionParameters( action );
// assertNoOutputFields();
fail();
}
catch ( ArchivaDatabaseException e )
{
assertTrue( true );
}
// Actually, it'd be better to have an error:
assertError( result );
assertActionParameters( action );
assertNoOutputFields();
}
public void testGetArtifactNotInObservableRepos()
throws ArchivaDatabaseException
{
List<ArchivaArtifact> artifacts = Collections.singletonList(
createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, OTHER_TEST_REPO ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
setActionParameters();
String result = action.artifact();
assertError( result );
artifactDaoMockControl.verify();
assertActionParameters( action );
assertNoOutputFields();
}
public void testGetArtifactOnlySeenInSecondObservableRepo()
throws ArchivaDatabaseException
{
setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
List<ArchivaArtifact> artifacts =
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
setActionParameters();
@ -291,9 +244,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
@ -303,19 +253,16 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() );
assertTrue( action.getSnapshotVersions().isEmpty() );
}
public void testGetArtifactSeenInBothObservableRepo()
throws ArchivaDatabaseException
{
setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
List<ArchivaArtifact> artifacts =
Arrays.asList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ),
createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, OTHER_TEST_REPO ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
setActionParameters();
@ -323,9 +270,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
@ -335,19 +279,16 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() );
assertTrue( action.getSnapshotVersions().isEmpty() );
}
public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
throws ArchivaDatabaseException
{
setObservableRepos( Arrays.asList( TEST_REPO ) );
List<ArchivaArtifact> artifacts =
Arrays.asList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, OTHER_TEST_REPO ),
createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 2 );
MockControl projectDaoMockControl =
createProjectDaoMock( createProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_VERSION ) );
setActionParameters();
@ -355,9 +296,6 @@ public class ShowArtifactActionTest
assertActionSuccess( action, result );
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
@ -367,7 +305,7 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() );
assertTrue( action.getSnapshotVersions().isEmpty() );
}
private void assertNoOutputFields()
@ -376,7 +314,7 @@ public class ShowArtifactActionTest
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
assertNull( action.getSnapshotVersions() );
assertTrue( action.getSnapshotVersions().isEmpty() );
}
private void assertError( String result )
@ -401,22 +339,18 @@ public class ShowArtifactActionTest
assertEquals( TEST_GROUP_ID, model.getGroupId() );
assertEquals( TEST_ARTIFACT_ID, model.getArtifactId() );
assertEquals( version, model.getVersion() );
assertEquals( TEST_PACKAGING, model.getPackaging() );
assertEquals( TEST_URL, model.getUrl() );
assertEquals( TEST_NAME, model.getName() );
assertEquals( TEST_DESCRIPTION, model.getDescription() );
assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() );
assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() );
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_URL, l.getUrl() );
l = model.getLicenses().get( 1 );
assertEquals( TEST_LICENSE_NAME_2, l.getName() );
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_URL, model.getIssueManagement().getUrl() );
assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() );
@ -424,6 +358,11 @@ public class ShowArtifactActionTest
assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() );
assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() );
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()
@ -447,21 +386,13 @@ public class ShowArtifactActionTest
assertTrue( action.getActionMessages().isEmpty() );
}
private ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version )
private ProjectBuildMetadata createProjectModel( String version )
{
ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
model.setPackaging( TEST_PACKAGING );
ProjectBuildMetadata model = new ProjectBuildMetadata();
model.setId( version );
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 );
@ -470,10 +401,10 @@ public class ShowArtifactActionTest
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 );
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 );
@ -487,66 +418,25 @@ public class ShowArtifactActionTest
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;
}
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()
throws Exception
{
super.setUp();
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>
<implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation>
</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>
</plexus>

View File

@ -28,8 +28,8 @@ The following is the intended content model for the metadata content repository:
| | |-- created=
| | |-- description=
| | |-- name=
| | |-- organizationName=
| | |-- organizationUrl=
| | |-- organization.name=
| | |-- organization.url=
| | `-- updated=
| |-- maven:artifactId=
| `-- 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
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 String version;
public String getId()
{
return id;
@ -63,4 +65,14 @@ public class ArtifactMetadata
{
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.
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProjectBuildMetadata
{
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()
{
return id;
@ -33,4 +56,106 @@ public class ProjectBuildMetadata
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
{
private String namespace;
private String id;
public void setId( String id )
@ -33,4 +35,13 @@ public class ProjectMetadata
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.
*/
import java.util.Collection;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.ProjectBuildMetadata;
import org.apache.archiva.metadata.model.ProjectMetadata;
public interface MetadataRepository
{
/**
* 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
*/
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.FileOutputStream;
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 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.commons.io.IOUtils;
/**
* @plexus.component role="org.apache.archiva.metadata.repository.MetadataRepository"
*/
public class FileMetadataRepository
implements MetadataRepository
{
private File directory;
/**
* @plexus.configuration
*/
private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );
public FileMetadataRepository( File directory )
{
this.directory = directory;
}
public void updateProject( ProjectMetadata project )
public void updateProject( String repoId, ProjectMetadata project )
{
// TODO: this is a more braindead implementation than we would normally expect, for prototyping purposes
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.setProperty( "namespace", project.getNamespace() );
properties.setProperty( "id", project.getId() );
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.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();
FileInputStream in = null;
try
@ -101,19 +128,48 @@ public class FileMetadataRepository
{
IOUtils.closeQuietly( in );
}
return properties;
}
properties.setProperty( artifact.getId() + ".updated", Long.toString( artifact.getUpdated().getTime() ) );
properties.setProperty( artifact.getId() + ".size", Long.toString( artifact.getSize() ) );
public ProjectMetadata getProject( String repoId, String groupId, String projectId )
{
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 );
}
catch ( IOException e )
{
// TODO
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
String name = (String) entry.getKey();
if ( name.startsWith( "version:" ) )
{
versions.add( (String) entry.getValue() );
}
}
return versions;
}
private void writeProperties( Properties properties, File directory )

View File

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