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;
private List<String> includes = new ArrayList<String>();
+ /**
+ * @plexus.requirement
+ */
private MetadataRepository metadataRepository;
public String getId()
throws ConsumerException
{
this.repository.setRepository( repo );
- // FIXME: remove hardcoding
- this.metadataRepository = new FileMetadataRepository( new File( repository.getRepoRoot(), ".metadata" ) );
this.whenGathered = whenGathered;
}
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()
// log.info( "Scanning for removed repository content" );
- // FIXME: remove hardcoding
-// MetadataRepository metadataRepository =
-// new FileMetadataRepository( new File( arepo.getLocation(), ".metadata" ) );
-
// metadataRepository.findAllProjects();
// FIXME: do something
<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>
* 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
* @plexus.requirement
*/
private UserRepositories userRepositories;
-
+
+ /**
+ * @plexus.requirement
+ */
+ private MetadataRepository metadataRepository;
+
/* .\ Exposed Output Objects \.__________________________________ */
private String groupId;
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;
}
this.snapshotVersions = snapshotVersions;
}
+ public MetadataRepository getMetadataRepository()
+ {
+ return metadataRepository;
+ }
}
--- /dev/null
+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;
+ }
+}
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
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();
assertActionSuccess( action, result );
- artifactDaoMockControl.verify();
- projectDaoMockControl.verify();
-
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
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 );
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() );
}
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 );
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() );
}
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();
-
- // Actually, it'd be better to have an error:
-// assertError( result );
-// assertActionParameters( action );
-// assertNoOutputFields();
- fail();
- }
- catch ( ArchivaDatabaseException e )
- {
- assertTrue( true );
- }
+ String result = action.artifact();
+
+ // 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();
assertActionSuccess( action, result );
- artifactDaoMockControl.verify();
- projectDaoMockControl.verify();
-
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
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();
assertActionSuccess( action, result );
- artifactDaoMockControl.verify();
- projectDaoMockControl.verify();
-
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
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();
assertActionSuccess( action, result );
- artifactDaoMockControl.verify();
- projectDaoMockControl.verify();
-
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
- assertNull( action.getSnapshotVersions() );
+ assertTrue( action.getSnapshotVersions().isEmpty() );
}
private void assertNoOutputFields()
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getMailingLists() );
- assertNull( action.getSnapshotVersions() );
+ assertTrue( action.getSnapshotVersions().isEmpty() );
}
private void assertError( String result )
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() );
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()
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 );
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 );
scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
scm.setUrl( TEST_SCM_URL );
model.setScm( scm );
- 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 );
+ 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;
}
protected void setUp()
{
super.setUp();
action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
- archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );
+ metadataRepository = (MemoryMetadataRepository) action.getMetadataRepository();
}
}
<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>
| | |-- created=
| | |-- description=
| | |-- name=
- | | |-- organizationName=
- | | |-- organizationUrl=
+ | | |-- organization.name=
+ | | |-- organization.url=
| | `-- updated=
| |-- maven:artifactId=
| `-- maven:groupId=
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
\ No newline at end of file
private long size;
+ private String version;
+
public String getId()
{
return id;
{
this.size = size;
}
+
+ public String getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion( String version )
+ {
+ this.version = version;
+ }
}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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();
+}
* 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;
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 );
+ }
}
public class ProjectMetadata
{
+ private String namespace;
+
private String id;
public void setId( String id )
return id;
}
+ public String getNamespace()
+ {
+ return namespace;
+ }
+
+ public void setNamespace( String namespace )
+ {
+ this.namespace = namespace;
+ }
}
--- /dev/null
+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;
+ }
+}
* 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 repoId, String namespace, String projectId, String buildId, ArtifactMetadata artifactMeta );
+
+ void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build );
+
+ ProjectMetadata getProject( String repoId, String namespace, String projectId );
- void updateArtifact( String projectId, String buildId, ArtifactMetadata artifactMeta );
+ ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId );
- void updateBuild( String projectId, ProjectBuildMetadata build );
+ Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId );
}
--- /dev/null
+<?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>
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+}
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;
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 );
}
}
}
- 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() );
}
}
- 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
{
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
- {
- writeProperties( properties, directory );
- }
- catch ( IOException e )
+ 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() )
{
- // 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 )
<packaging>pom</packaging>
<modules>
<module>metadata-repository-file</module>
+ <module>maven2-repository</module>
</modules>
-</project>
+</project>
\ No newline at end of file