diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java index 0783a8fd8..d91e96cc1 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java @@ -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 includes = new ArrayList(); + /** + * @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() diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java index fd3ba2ed0..7585e699c 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java @@ -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 diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index a8f0f6e8b..bd09d0d15 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -259,6 +259,27 @@ atlassian-xmlrpc-binder-server-spring runtime + + org.apache.archiva + metadata-model + 1.3-SNAPSHOT + + + org.apache.archiva + metadata-repository-api + 1.3-SNAPSHOT + + + org.apache.archiva + metadata-repository-file + 1.3-SNAPSHOT + runtime + + + org.apache.archiva + maven2-repository + 1.3-SNAPSHOT + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index 18facd580..a2d8e89ea 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -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 mailingLists; private List dependencies; - + private List 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(); + 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; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/MemoryMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/MemoryMetadataRepository.java new file mode 100644 index 000000000..79e15ab8b --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/MemoryMetadataRepository.java @@ -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 projectBuilds = new HashMap(); + + private Map> artifactVersions = new HashMap>(); + + 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 getArtifactVersions( String repoId, String namespace, String projectId, String buildId ) + { + List versions = artifactVersions.get( createMapKey( repoId, namespace, projectId, buildId ) ); + return ( versions != null ? versions : Collections.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 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; + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java index 259121a08..e667eedfb 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java @@ -24,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 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 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 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 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.emptyList(), 1 ); - setActionParameters(); String result = action.artifact(); assertError( result ); - artifactDaoMockControl.verify(); - assertActionParameters( action ); assertNoOutputFields(); } public void testGetArtifactNoObservableRepos() - throws ArchivaDatabaseException { setObservableRepos( Collections.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 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 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 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 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 artifacts, int count ) - throws ArchivaDatabaseException - { - return createArtifactDaoMock( artifacts, TEST_VERSION, count ); - } - - private MockControl createArtifactDaoMock( List 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(); } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/ShowArtifactActionTest.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/ShowArtifactActionTest.xml index d51572b7f..c829d6c15 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/ShowArtifactActionTest.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/ShowArtifactActionTest.xml @@ -35,5 +35,11 @@ default org.apache.maven.archiva.security.UserRepositoriesStub + + org.apache.archiva.metadata.repository.MetadataRepository + default + org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository + per-lookup + diff --git a/archiva-modules/metadata/content-model.txt b/archiva-modules/metadata/content-model.txt index b60a22da0..d874634b1 100644 --- a/archiva-modules/metadata/content-model.txt +++ b/archiva-modules/metadata/content-model.txt @@ -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 \ No newline at end of file diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java index 599283177..51e6a550a 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java @@ -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; + } } diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/CiManagement.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/CiManagement.java new file mode 100644 index 000000000..bb0bc7c1b --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/CiManagement.java @@ -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; + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/IssueManagement.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/IssueManagement.java new file mode 100644 index 000000000..22f7290be --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/IssueManagement.java @@ -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; + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java new file mode 100644 index 000000000..456d63951 --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/License.java @@ -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; + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Organization.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Organization.java new file mode 100644 index 000000000..f3d841d4c --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Organization.java @@ -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; + } +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildFacet.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildFacet.java new file mode 100644 index 000000000..6b02fc8ce --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildFacet.java @@ -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(); +} diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java index 8b2d707d8..712481745 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectBuildMetadata.java @@ -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 licenses; + + private Map 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 getLicenses() + { + return licenses; + } + + public void setLicenses( List licenses ) + { + this.licenses = licenses; + } + + public void addLicense( License license ) + { + if ( this.licenses == null ) + { + this.licenses = new ArrayList(); + } + this.licenses.add( license ); + } + + public void addFacet( ProjectBuildFacet mavenProjectFacet ) + { + if ( this.facets == null ) + { + this.facets = new HashMap(); + } + this.facets.put( mavenProjectFacet.getFacetId(), mavenProjectFacet ); + } + + public ProjectBuildFacet getFacet( String facetId ) + { + return this.facets.get( facetId ); + } } diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java index 09707e2d3..8db1f0116 100644 --- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectMetadata.java @@ -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; + } } diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Scm.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Scm.java new file mode 100644 index 000000000..a3d8158fb --- /dev/null +++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/Scm.java @@ -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; + } +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index 744ba95a3..4440a9e07 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -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 getArtifactVersions( String repoId, String namespace, String projectId, String buildId ); } diff --git a/archiva-modules/plugins/maven2-repository/pom.xml b/archiva-modules/plugins/maven2-repository/pom.xml new file mode 100644 index 000000000..0cf46c7fb --- /dev/null +++ b/archiva-modules/plugins/maven2-repository/pom.xml @@ -0,0 +1,36 @@ + + + + 4.0.0 + + plugins + org.apache.archiva + 1.3-SNAPSHOT + + maven2-repository + Maven 2.x Repository Support + + + org.apache.archiva + metadata-model + + + diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java new file mode 100644 index 000000000..dd68adb85 --- /dev/null +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectFacet.java @@ -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; + } +} diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectParent.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectParent.java new file mode 100644 index 000000000..d9757d716 --- /dev/null +++ b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/MavenProjectParent.java @@ -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; + } +} diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index 2e3fca39c..a262ab244 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -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 getArtifactVersions( String repoId, String namespace, String projectId, String buildId ) + { + File directory = new File( this.directory, repoId + "/" + projectId + "/" + buildId ); + + Properties properties = readProperties( directory ); + + List versions = new ArrayList(); + 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 ) diff --git a/archiva-modules/plugins/pom.xml b/archiva-modules/plugins/pom.xml index beb029e33..d290c6ba8 100644 --- a/archiva-modules/plugins/pom.xml +++ b/archiva-modules/plugins/pom.xml @@ -28,5 +28,6 @@ pom metadata-repository-file + maven2-repository - + \ No newline at end of file