]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1283] migrate dependees() / "used by" tab to metadata repository and remove...
authorBrett Porter <brett@apache.org>
Fri, 27 Nov 2009 00:16:19 +0000 (00:16 +0000)
committerBrett Porter <brett@apache.org>
Fri, 27 Nov 2009 00:16:19 +0000 (00:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884727 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionReference.java [new file with mode: 0644]
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index 604727b4fd01fcb6ef50931e6a4a707ceaeefcf1..921c7a56e99586cfc187d296afe28b8443ab969d 100644 (file)
@@ -25,13 +25,13 @@ import java.util.List;
 
 import com.opensymphony.xwork2.Validateable;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.MetadataResolverException;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.commons.lang.StringUtils;
 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;
@@ -59,11 +59,6 @@ public class ShowArtifactAction
 {
     /* .\ Not Exposed \._____________________________________________ */
 
-    /**
-     * @plexus.requirement role-hint="default"
-     */
-    private RepositoryBrowsing repoBrowsing;
-
     /**
      * @plexus.requirement
      */
@@ -146,15 +141,15 @@ public class ShowArtifactAction
             addActionError( "Artifact not found" );
             return ERROR;
         }
-        populateLegacyModel( versionMetadata );
+        model = populateLegacyModel( versionMetadata );
 
         return SUCCESS;
     }
 
-    private void populateLegacyModel( ProjectVersionMetadata versionMetadata )
+    private ArchivaProjectModel populateLegacyModel( ProjectVersionMetadata versionMetadata )
     {
         // TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics
-        model = new ArchivaProjectModel();
+        ArchivaProjectModel model = new ArchivaProjectModel();
         MavenProjectFacet projectFacet = (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
         if ( projectFacet != null )
         {
@@ -244,6 +239,7 @@ public class ShowArtifactAction
                 model.addDependency( dependency );
             }
         }
+        return model;
     }
 
     /**
@@ -274,7 +270,7 @@ public class ShowArtifactAction
             addActionError( "Artifact not found" );
             return ERROR;
         }
-        populateLegacyModel( versionMetadata );
+        model = populateLegacyModel( versionMetadata );
 
         this.dependencies = model.getDependencies();
 
@@ -309,7 +305,7 @@ public class ShowArtifactAction
             addActionError( "Artifact not found" );
             return ERROR;
         }
-        populateLegacyModel( versionMetadata );
+        model = populateLegacyModel( versionMetadata );
 
         this.mailingLists = model.getMailingLists();
 
@@ -334,9 +330,52 @@ public class ShowArtifactAction
     public String dependees()
         throws ObjectNotFoundException, ArchivaDatabaseException
     {
-        this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
+        ProjectVersionMetadata versionMetadata = null;
+        for ( String repoId : getObservableRepos() )
+        {
+            if ( versionMetadata == null )
+            {
+                try
+                {
+                    versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
+                }
+                catch ( MetadataResolverException e )
+                {
+                    addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
+                    return ERROR;
+                }
+            }
+        }
+
+        if ( versionMetadata == null )
+        {
+            addActionError( "Artifact not found" );
+            return ERROR;
+        }
+        model = populateLegacyModel( versionMetadata );
+
+        List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
+        // TODO: what if we get duplicates across repositories?
+        for ( String repoId : getObservableRepos() )
+        {
+            // TODO: what about if we want to see this irrespective of version?
+            references.addAll( metadataResolver.getProjectReferences( repoId, groupId, artifactId, version ) );
+        }
+
+        this.dependees = new ArrayList<ArchivaProjectModel>();
+        for ( ProjectVersionReference reference : references )
+        {
+            ArchivaProjectModel ref = new ArchivaProjectModel();
 
-        this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
+            ref.setGroupId( reference.getNamespace() );
+            ref.setArtifactId( reference.getProjectId() );
+            ref.setVersion( reference.getProjectVersion() );
+
+            dependees.add( ref );
+        }
+
+        // TODO: may need to note on the page that references will be incomplete if the other artifacts are not yet stored in the content repository
+        // (especially in the case of pre-population import)
 
         return SUCCESS;
     }
@@ -350,6 +389,9 @@ public class ShowArtifactAction
         // temporarily use this as we only need the model for the tag to perform, but we should be resolving the
         // graph here instead
 
+        // TODO: may need to note on the page that tree will be incomplete if the other artifacts are not yet stored in the content repository
+        // (especially in the case of pre-population import)
+
         return artifact();
     }
 
index 2b48830dc6d53fa53eceffb226b4e6fdcc4e9a6a..8287f3aaec8936585079c159f5f6a1fabb511656 100644 (file)
@@ -25,8 +25,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 
 public class TestMetadataResolver
@@ -36,6 +37,9 @@ public class TestMetadataResolver
 
     private Map<String, List<String>> artifactVersions = new HashMap<String, List<String>>();
 
+    private Map<String, List<ProjectVersionReference>> references =
+        new HashMap<String, List<ProjectVersionReference>>();
+
     public ProjectMetadata getProject( String repoId, String namespace, String projectId )
     {
         ProjectMetadata metadata = new ProjectMetadata();
@@ -44,30 +48,45 @@ public class TestMetadataResolver
         return metadata;
     }
 
-    public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
+    public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
+                                                     String projectVersion )
     {
         return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
     }
 
-    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion )
+    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
+                                                   String projectVersion )
     {
         List<String> versions = artifactVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
         return ( versions != null ? versions : Collections.<String>emptyList() );
     }
 
-    public void setProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata )
+    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                                     String projectVersion )
+    {
+        return references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+    }
+
+    public void setProjectVersion( String repoId, String namespace, String projectId,
+                                   ProjectVersionMetadata versionMetadata )
     {
         projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
     }
 
-    public void setArtifactVersions( String repoId, String namespace, String projectId, String version,
+    public void setArtifactVersions( String repoId, String namespace, String projectId, String projectVersion,
                                      List<String> versions )
     {
-        artifactVersions.put( createMapKey( repoId, namespace, projectId, version ), versions );
+        artifactVersions.put( createMapKey( repoId, namespace, projectId, projectVersion ), versions );
     }
 
     private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
     {
         return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
     }
+
+    public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
+                                      List<ProjectVersionReference> references )
+    {
+        this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
+    }
 }
index f2ed1692dbde87c5a912dea7aad829a159dfbbed..70e55165e283a6f4ecfcc7f519b2b963c6282096 100644 (file)
@@ -31,25 +31,16 @@ import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.MailingList;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
-import org.apache.maven.archiva.database.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.database.constraints.ProjectsByArtifactUsageConstraint;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.apache.maven.archiva.model.ArchivaArtifactModel;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
-import org.apache.maven.archiva.model.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
@@ -115,8 +106,6 @@ public class ShowArtifactActionTest
 
     private ShowArtifactAction action;
 
-    private ArchivaDAOStub archivaDao;
-
     private TestMetadataResolver metadataResolver;
 
     public void testInstantiation()
@@ -415,34 +404,17 @@ public class ShowArtifactActionTest
     public void testGetDependees()
         throws ArchivaDatabaseException
     {
-        List<ArchivaArtifact> artifacts =
-            Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
-        MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
-        ArchivaProjectModel legacyModel = createLegacyProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
-
-        MockControl projectDaoMockControl = MockControl.createNiceControl( ProjectModelDAO.class );
-        ProjectModelDAO dao = (ProjectModelDAO) projectDaoMockControl.getMock();
-        archivaDao.setProjectDao( dao );
-
-        projectDaoMockControl.expectAndReturn(
-            dao.getProjectModel( legacyModel.getGroupId(), legacyModel.getArtifactId(), legacyModel.getVersion() ),
-            legacyModel );
-
-        ArchivaProjectModel dependee1 = createBasicLegacyModel( "groupId", "artifactId1", "version" );
-        ArchivaProjectModel dependee2 = createBasicLegacyModel( "groupId", "artifactId2", "version" );
-        projectDaoMockControl.expectAndReturn( dao.queryProjectModels(
-            new ProjectsByArtifactUsageConstraint( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) ),
+        ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
+        metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
+        ProjectVersionReference dependee1 = createReference( "artifactId1" );
+        ProjectVersionReference dependee2 = createReference( "artifactId2" );
+        metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
                                                Arrays.asList( dependee1, dependee2 ) );
 
-        projectDaoMockControl.replay();
-
         setActionParameters();
 
         String result = action.dependees();
 
-        artifactDaoMockControl.verify();
-        projectDaoMockControl.verify();
-
         assertActionSuccess( action, result );
 
         assertActionParameters( action );
@@ -459,6 +431,16 @@ public class ShowArtifactActionTest
         assertNull( action.getSnapshotVersions() );
     }
 
+    private ProjectVersionReference createReference( String projectId )
+    {
+        ProjectVersionReference reference = new ProjectVersionReference();
+        reference.setNamespace( "groupId" );
+        reference.setProjectId( projectId );
+        reference.setProjectVersion( "version" );
+        reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
+        return reference;
+    }
+
     private void assertCoordinate( ArchivaProjectModel dependee, String artifactId )
     {
         assertEquals( artifactId, dependee.getArtifactId() );
@@ -651,99 +633,11 @@ public class ShowArtifactActionTest
         return model;
     }
 
-    private ArchivaProjectModel createLegacyProjectModel( String groupId, String artifactId, String version )
-    {
-        ArchivaProjectModel model = createBasicLegacyModel( groupId, artifactId, version );
-        model.setPackaging( TEST_PACKAGING );
-        model.setUrl( TEST_URL );
-        model.setName( TEST_NAME );
-        model.setDescription( TEST_DESCRIPTION );
-        VersionedReference parent = new VersionedReference();
-        parent.setGroupId( TEST_PARENT_GROUP_ID );
-        parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
-        parent.setVersion( TEST_PARENT_VERSION );
-        model.setParentProject( parent );
-        org.apache.maven.archiva.model.CiManagement ci = new org.apache.maven.archiva.model.CiManagement();
-        ci.setSystem( TEST_CI_SYSTEM );
-        ci.setUrl( TEST_CI_URL );
-        model.setCiManagement( ci );
-        org.apache.maven.archiva.model.IssueManagement issue = new org.apache.maven.archiva.model.IssueManagement();
-        issue.setSystem( TEST_ISSUE_SYSTEM );
-        issue.setUrl( TEST_ISSUE_URL );
-        model.setIssueManagement( issue );
-        org.apache.maven.archiva.model.Organization org = new org.apache.maven.archiva.model.Organization();
-        org.setName( TEST_ORGANIZATION_NAME );
-        org.setUrl( TEST_ORGANIZATION_URL );
-        model.setOrganization( org );
-        org.apache.maven.archiva.model.License l = new org.apache.maven.archiva.model.License();
-        l.setName( TEST_LICENSE_NAME );
-        l.setUrl( TEST_LICENSE_URL );
-        model.addLicense( l );
-        l = new org.apache.maven.archiva.model.License();
-        l.setName( TEST_LICENSE_NAME_2 );
-        l.setUrl( TEST_LICENSE_URL_2 );
-        model.addLicense( l );
-        org.apache.maven.archiva.model.Scm scm = new org.apache.maven.archiva.model.Scm();
-        scm.setConnection( TEST_SCM_CONNECTION );
-        scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
-        scm.setUrl( TEST_SCM_URL );
-        model.setScm( scm );
-        return model;
-    }
-
-    private ArchivaProjectModel createBasicLegacyModel( String groupId, String artifactId, String version )
-    {
-        ArchivaProjectModel model = new ArchivaProjectModel();
-        model.setGroupId( groupId );
-        model.setArtifactId( artifactId );
-        model.setVersion( version );
-        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 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 );
         metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
-        archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );
     }
 }
diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionReference.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionReference.java
new file mode 100644 (file)
index 0000000..5dd4b90
--- /dev/null
@@ -0,0 +1,77 @@
+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 ProjectVersionReference
+{
+    private ReferenceType referenceType;
+
+    private String projectId;
+
+    private String namespace;
+
+    private String projectVersion;
+
+    public void setReferenceType( ReferenceType referenceType )
+    {
+        this.referenceType = referenceType;
+    }
+
+    public void setNamespace( String namespace )
+    {
+        this.namespace = namespace;
+    }
+
+    public void setProjectId( String projectId )
+    {
+        this.projectId = projectId;
+    }
+
+    public ReferenceType getReferenceType()
+    {
+        return referenceType;
+    }
+
+    public String getProjectId()
+    {
+        return projectId;
+    }
+
+    public String getProjectVersion()
+    {
+        return projectVersion;
+    }
+
+    public String getNamespace()
+    {
+        return namespace;
+    }
+
+    public void setProjectVersion( String projectVersion )
+    {
+        this.projectVersion = projectVersion;
+    }
+
+    public enum ReferenceType
+    {
+        DEPENDENCY,
+        PARENT
+    }
+}
index a13061a6f58d5f0bf324559de5f1829a3b1c9dd7..64f15522dc9269aeebb15ea8bfb914e01091d63f 100644 (file)
@@ -21,8 +21,10 @@ package org.apache.archiva.metadata.repository;
 
 import java.util.Collection;
 
+import org.apache.archiva.metadata.model.Dependency;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 
 /**
  * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver"
@@ -38,7 +40,7 @@ public class DefaultMetadataResolver
     /**
      * FIXME: this needs to be configurable based on storage type, and availability of proxy module
      * ... could be a different type since we need methods to modify the storage metadata, which would also allow more
-     *     appropriate methods to pass in the already determined repository configuration, for example, instead of the ID
+     * appropriate methods to pass in the already determined repository configuration, for example, instead of the ID
      *
      * @plexus.requirement role-hint="maven2"
      */
@@ -63,6 +65,22 @@ public class DefaultMetadataResolver
             metadata = storageResolver.getProjectVersion( repoId, namespace, projectId, projectVersion );
             if ( metadata != null )
             {
+                // FIXME: make this a more generic post-processing that plugins can take advantage of
+                //       eg. maven projects should be able to process parent here
+                if ( !metadata.getDependencies().isEmpty() )
+                {
+                    ProjectVersionReference ref = new ProjectVersionReference();
+                    ref.setNamespace( namespace );
+                    ref.setProjectId( projectId );
+                    ref.setProjectVersion( projectVersion );
+                    ref.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
+                    for ( Dependency dependency : metadata.getDependencies() )
+                    {
+                        metadataRepository.updateProjectReference( repoId, dependency.getGroupId(),
+                                                                   dependency.getArtifactId(), dependency.getVersion(),
+                                                                   ref );
+                    }
+                }
                 metadataRepository.updateProjectVersion( repoId, namespace, projectId, metadata );
             }
         }
@@ -75,4 +93,12 @@ public class DefaultMetadataResolver
         // TODO: intercept
         return metadataRepository.getArtifactVersions( repoId, namespace, projectId, projectVersion );
     }
+
+    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                                     String projectVersion )
+    {
+        // TODO: is this assumption correct? could a storage mech. actually know all references in a non-Maven scenario?
+        // not passed to the storage mechanism as resolving references would require iterating all artifacts
+        return metadataRepository.getProjectReferences( repoId, namespace, projectId, projectVersion );
+    }
 }
index 7b4e23737d3305075cb917f0fb067eb0ffdb5bac..a41016be386f6921224cdd29eb0a9c17ccef42fe 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.archiva.metadata.repository;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 
 public interface MetadataRepository
     extends MetadataResolver
@@ -39,4 +40,6 @@ public interface MetadataRepository
     void updateProjectVersion( String repoId, String namespace, String projectId,
                                ProjectVersionMetadata versionMetadata );
 
+    void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion,
+                                 ProjectVersionReference reference );
 }
index 7e6aaef7d78bb18cd094d27ea4bb18207ff7ecd8..e6f8e63165e747f1ae30193ee1ca175b1f8614fd 100644 (file)
@@ -23,6 +23,7 @@ import java.util.Collection;
 
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 
 public interface MetadataResolver
 {
@@ -32,4 +33,18 @@ public interface MetadataResolver
         throws MetadataResolverException;
 
     Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion );
+
+    /**
+     * Retrieve project references from the metadata repository. Note that this is not built into the content model for
+     * a project version as a reference may be present (due to reverse-lookup of dependencies) before the actual
+     * project is, and we want to avoid adding a stub model to the content repository.
+     *
+     * @param repoId         the repository ID to look within
+     * @param namespace      the namespace of the project to get references to
+     * @param projectId      the identifier of the project to get references to
+     * @param projectVersion the version of the project to get references to
+     * @return a list of project references
+     */
+    Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                              String projectVersion );
 }
index ffb8cba48f9b0e51a294c2023152550f60aaaca1..54e6f2e5086f07d51e5f57af740d9f2ff5e21346 100644 (file)
@@ -26,6 +26,7 @@ import java.util.List;
 
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.MetadataResolverException;
 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
@@ -274,4 +275,10 @@ public class Maven2RepositoryMetadataResolver
     {
         throw new UnsupportedOperationException();
     }
+
+    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                                     String projectVersion )
+    {
+        throw new UnsupportedOperationException();
+    }
 }
index 69cfdf7880d4dec0f866aa98db4823ea4c48fc86..728898accb9e9fad4e262aaa293c27c9398ea87e 100644 (file)
@@ -43,6 +43,7 @@ import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionFacet;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.model.Scm;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.commons.io.IOUtils;
@@ -91,9 +92,18 @@ public class FileMetadataRepository
     public void updateProjectVersion( String repoId, String namespace, String projectId,
                                       ProjectVersionMetadata versionMetadata )
     {
-        File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId );
+        File directory =
+            new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + versionMetadata.getId() );
 
-        Properties properties = new Properties();
+        Properties properties = readProperties( directory );
+        // remove properties that are not references or artifacts
+        for ( String name : properties.stringPropertyNames() )
+        {
+            if ( !name.startsWith( "artifact:" ) && !name.startsWith( "ref:" ) )
+            {
+                properties.remove( name );
+            }
+        }
         properties.setProperty( "id", versionMetadata.getId() );
         setProperty( properties, "name", versionMetadata.getName() );
         setProperty( properties, "description", versionMetadata.getDescription() );
@@ -157,7 +167,31 @@ public class FileMetadataRepository
 
         try
         {
-            writeProperties( properties, new File( directory, versionMetadata.getId() ) );
+            writeProperties( properties, directory );
+        }
+        catch ( IOException e )
+        {
+            // TODO
+            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+        }
+    }
+
+    public void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion,
+                                        ProjectVersionReference reference )
+    {
+        File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
+
+        Properties properties = readProperties( directory );
+        int i = Integer.valueOf( properties.getProperty( "ref:lastReferenceNum", "-1" ) ) + 1;
+        setProperty( properties, "ref:lastReferenceNum", Integer.toString( i ) );
+        setProperty( properties, "ref:reference." + i + ".namespace", reference.getNamespace() );
+        setProperty( properties, "ref:reference." + i + ".projectId", reference.getProjectId() );
+        setProperty( properties, "ref:reference." + i + ".projectVersion", reference.getProjectVersion() );
+        setProperty( properties, "ref:reference." + i + ".referenceType", reference.getReferenceType().toString() );
+
+        try
+        {
+            writeProperties( properties, directory );
         }
         catch ( IOException e )
         {
@@ -192,9 +226,10 @@ public class FileMetadataRepository
 
         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() );
+        properties.setProperty( "artifact:updated:" + artifact.getId(),
+                                Long.toString( artifact.getUpdated().getTime() ) );
+        properties.setProperty( "artifact:size:" + artifact.getId(), Long.toString( artifact.getSize() ) );
+        properties.setProperty( "artifact:version:" + artifact.getId(), artifact.getVersion() );
 
         try
         {
@@ -422,6 +457,28 @@ public class FileMetadataRepository
         return versions;
     }
 
+    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                                     String projectVersion )
+    {
+        File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
+
+        Properties properties = readProperties( directory );
+        int numberOfRefs = Integer.valueOf( properties.getProperty( "ref:lastReferenceNum", "-1" ) ) + 1;
+
+        List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
+        for ( int i = 0; i < numberOfRefs; i++ )
+        {
+            ProjectVersionReference reference = new ProjectVersionReference();
+            reference.setProjectId( properties.getProperty( "ref:reference." + i + ".projectId" ) );
+            reference.setNamespace( properties.getProperty( "ref:reference." + i + ".namespace" ) );
+            reference.setProjectVersion( properties.getProperty( "ref:reference." + i + ".projectVersion" ) );
+            reference.setReferenceType( ProjectVersionReference.ReferenceType.valueOf(
+                properties.getProperty( "ref:reference." + i + ".referenceType" ) ) );
+            references.add( reference );
+        }
+        return references;
+    }
+
     private void writeProperties( Properties properties, File directory )
         throws IOException
     {