]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1283] migrate mailingLists() method to metadata repository
authorBrett Porter <brett@apache.org>
Thu, 26 Nov 2009 06:44:40 +0000 (06:44 +0000)
committerBrett Porter <brett@apache.org>
Thu, 26 Nov 2009 06:44:40 +0000 (06:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884414 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/maven/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MailingList.java [new file with mode: 0644]
archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ProjectVersionMetadata.java
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
archiva-modules/plugins/maven2-repository/src/test/repositories/test/org/apache/archiva/archiva-parent/3/archiva-parent-3.pom
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index d44348934a6a9c974584895c361d21d0844ae63f..88bcdd96c834ffb32609096628827660cc315873 100644 (file)
@@ -146,7 +146,13 @@ public class ShowArtifactAction
             addActionError( "Artifact not found" );
             return ERROR;
         }
+        populateLegacyModel( versionMetadata );
 
+        return SUCCESS;
+    }
+
+    private void populateLegacyModel( ProjectVersionMetadata versionMetadata )
+    {
         // TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics
         model = new ArchivaProjectModel();
         MavenProjectFacet projectFacet = (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
@@ -208,8 +214,20 @@ public class ShowArtifactAction
                 model.addLicense( license );
             }
         }
-
-        return SUCCESS;
+        if ( versionMetadata.getMailingLists() != null )
+        {
+            for ( org.apache.archiva.metadata.model.MailingList l : versionMetadata.getMailingLists() )
+            {
+                MailingList mailingList = new MailingList();
+                mailingList.setMainArchiveUrl( l.getMainArchiveUrl() );
+                mailingList.setName( l.getName() );
+                mailingList.setPostAddress( l.getPostAddress() );
+                mailingList.setSubscribeAddress( l.getSubscribeAddress() );
+                mailingList.setUnsubscribeAddress( l.getUnsubscribeAddress() );
+                mailingList.setOtherArchives( l.getOtherArchives() );
+                model.addMailingList( mailingList );
+            }
+        }
     }
 
     /**
@@ -231,7 +249,32 @@ public class ShowArtifactAction
     public String mailingLists()
         throws ObjectNotFoundException, ArchivaDatabaseException
     {
-        this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
+        // 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
+        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;
+        }
+        populateLegacyModel( versionMetadata );
+
         this.mailingLists = model.getMailingLists();
 
         return SUCCESS;
index 1772606e2cec6d6592d026d214d6f1d399ce12b6..8db9c0835d519e9d0f29f37c0f2883d310641c95 100644 (file)
@@ -27,6 +27,7 @@ import com.opensymphony.xwork2.Action;
 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.MailingList;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.Scm;
@@ -43,7 +44,6 @@ 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.Dependency;
-import org.apache.maven.archiva.model.MailingList;
 import org.apache.maven.archiva.model.VersionedReference;
 import org.apache.maven.archiva.security.UserRepositories;
 import org.apache.maven.archiva.security.UserRepositoriesStub;
@@ -357,22 +357,16 @@ public class ShowArtifactActionTest
     public void testGetMailingLists()
         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 );
+        ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
         MailingList ml1 = createMailingList( "Users List", "users" );
         MailingList ml2 = createMailingList( "Developers List", "dev" );
-        legacyModel.setMailingLists( Arrays.asList( ml1, ml2 ) );
-        MockControl projectDaoMockControl = createProjectDaoMock( legacyModel );
+        versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
+        metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
 
         setActionParameters();
 
         String result = action.mailingLists();
 
-        artifactDaoMockControl.verify();
-        projectDaoMockControl.verify();
-
         assertActionSuccess( action, result );
 
         assertActionParameters( action );
@@ -515,7 +509,7 @@ public class ShowArtifactActionTest
         return dependency;
     }
 
-    private void assertMailingList( MailingList mailingList, String name, String prefix )
+    private void assertMailingList( org.apache.maven.archiva.model.MailingList mailingList, String name, String prefix )
     {
         assertEquals( name, mailingList.getName() );
         assertEquals( prefix + "-post@", mailingList.getPostAddress() );
diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MailingList.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/MailingList.java
new file mode 100644 (file)
index 0000000..a9530b7
--- /dev/null
@@ -0,0 +1,97 @@
+package org.apache.archiva.metadata.model;
+
+import java.util.List;
+
+/*
+ * 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 MailingList
+{
+    private String mainArchiveUrl;
+
+    private List<String> otherArchives;
+
+    private String name;
+
+    private String postAddress;
+
+    private String subscribeAddress;
+
+    private String unsubscribeAddress;
+
+    public void setMainArchiveUrl( String mainArchiveUrl )
+    {
+        this.mainArchiveUrl = mainArchiveUrl;
+    }
+
+    public String getMainArchiveUrl()
+    {
+        return mainArchiveUrl;
+    }
+
+    public void setOtherArchives( List<String> otherArchives )
+    {
+        this.otherArchives = otherArchives;
+    }
+
+    public List<String> getOtherArchives()
+    {
+        return otherArchives;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public void setPostAddress( String postAddress )
+    {
+        this.postAddress = postAddress;
+    }
+
+    public void setSubscribeAddress( String subscribeAddress )
+    {
+        this.subscribeAddress = subscribeAddress;
+    }
+
+    public void setUnsubscribeAddress( String unsubscribeAddress )
+    {
+        this.unsubscribeAddress = unsubscribeAddress;
+    }
+
+    public String getSubscribeAddress()
+    {
+        return subscribeAddress;
+    }
+
+    public String getUnsubscribeAddress()
+    {
+        return unsubscribeAddress;
+    }
+
+    public String getPostAddress()
+    {
+        return postAddress;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+}
index 159afd15ca6d6694d4f256e15cf9e9a724ac38e5..ff78fcd76382763fe476c919babb5ee8152b0391 100644 (file)
@@ -45,7 +45,9 @@ public class ProjectVersionMetadata
 
     private List<License> licenses;
 
-    private Map<String, ProjectVersionFacet> facets = new HashMap<String, ProjectVersionFacet>();;
+    private Map<String, ProjectVersionFacet> facets = new HashMap<String, ProjectVersionFacet>();
+
+    private List<MailingList> mailingLists;
 
     public String getId()
     {
@@ -165,4 +167,23 @@ public class ProjectVersionMetadata
     {
         return this.facets.keySet();
     }
+
+    public void setMailingLists( List<MailingList> mailingLists )
+    {
+        this.mailingLists = mailingLists;
+    }
+
+    public List<MailingList> getMailingLists()
+    {
+        return mailingLists;
+    }
+
+    public void addMailingList( MailingList mailingList )
+    {
+        if ( this.mailingLists == null )
+        {
+            this.mailingLists = new ArrayList<MailingList>();
+        }
+        this.mailingLists.add( mailingList );
+    }
 }
index ced07bdabf32fca5ceb8c4ea41fe879eaee632ac..f2904011891ebf49f23567c120abca3b926be22d 100644 (file)
@@ -36,6 +36,7 @@ import org.apache.maven.archiva.xml.XMLException;
 import org.apache.maven.model.CiManagement;
 import org.apache.maven.model.IssueManagement;
 import org.apache.maven.model.License;
+import org.apache.maven.model.MailingList;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Organization;
 import org.apache.maven.model.Scm;
@@ -141,6 +142,7 @@ public class Maven2RepositoryMetadataResolver
         metadata.setId( projectVersion );
         metadata.setIssueManagement( convertIssueManagement( model.getIssueManagement() ) );
         metadata.setLicenses( convertLicenses( model.getLicenses() ) );
+        metadata.setMailingLists( convertMailingLists( model.getMailingLists() ) );
         metadata.setName( model.getName() );
         metadata.setOrganization( convertOrganization( model.getOrganization() ) );
         metadata.setScm( convertScm( model.getScm() ) );
@@ -201,6 +203,25 @@ public class Maven2RepositoryMetadataResolver
         return l;
     }
 
+    private List<org.apache.archiva.metadata.model.MailingList> convertMailingLists( List<MailingList> mailingLists )
+    {
+        List<org.apache.archiva.metadata.model.MailingList> l =
+            new ArrayList<org.apache.archiva.metadata.model.MailingList>();
+        for ( MailingList mailingList : mailingLists )
+        {
+            org.apache.archiva.metadata.model.MailingList newMailingList =
+                new org.apache.archiva.metadata.model.MailingList();
+            newMailingList.setName( mailingList.getName() );
+            newMailingList.setMainArchiveUrl( mailingList.getArchive() );
+            newMailingList.setPostAddress( mailingList.getPost() );
+            newMailingList.setSubscribeAddress( mailingList.getSubscribe() );
+            newMailingList.setUnsubscribeAddress( mailingList.getUnsubscribe() );
+            newMailingList.setOtherArchives( mailingList.getOtherArchives() );
+            l.add( newMailingList );
+        }
+        return l;
+    }
+
     private org.apache.archiva.metadata.model.IssueManagement convertIssueManagement( IssueManagement issueManagement )
     {
         org.apache.archiva.metadata.model.IssueManagement im = null;
index c9494adae410a5cd836681d396d8ba2a259ee4a8..85e0cb1a4aa99a4c141fca555733a10a39a297d5 100644 (file)
@@ -19,9 +19,13 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 
 import org.apache.archiva.metadata.model.License;
+import org.apache.archiva.metadata.model.MailingList;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.MetadataResolverException;
@@ -89,6 +93,15 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
         assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
         checkOrganizationApache( metadata );
+
+        assertEquals( 4, metadata.getMailingLists().size() );
+        assertMailingList( "users", metadata.getMailingLists().get( 0 ), "Archiva User List", true,
+                           "http://www.nabble.com/archiva-users-f16426.html" );
+        assertMailingList( "dev", metadata.getMailingLists().get( 1 ), "Archiva Developer List", true,
+                           "http://www.nabble.com/archiva-dev-f16427.html" );
+        assertMailingList( "commits", metadata.getMailingLists().get( 2 ), "Archiva Commits List", false, null );
+        assertMailingList( "issues", metadata.getMailingLists().get( 3 ), "Archiva Issues List", false,
+                           "http://www.nabble.com/Archiva---Issues-f29617.html" );
     }
 
     public void testGetProjectVersionMetadataForTimestampedSnapshot()
@@ -120,6 +133,11 @@ public class Maven2RepositoryMetadataResolverTest
         assertEquals( ASF_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
         assertEquals( ASF_SCM_VIEWVC_BASE + path, metadata.getScm().getUrl() );
         checkOrganizationApache( metadata );
+        assertEquals( 1, metadata.getMailingLists().size() );
+        assertMailingList( metadata.getMailingLists().get( 0 ), "Apache Announce List",
+                           "http://mail-archives.apache.org/mod_mbox/www-announce/", "announce@apache.org",
+                           "announce-subscribe@apache.org", "announce-unsubscribe@apache.org",
+                           Collections.<String>emptyList(), true );
     }
 
     public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
@@ -170,6 +188,39 @@ public class Maven2RepositoryMetadataResolverTest
 
     }
 
+    private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
+                                    String unsubscribe, List<String> otherArchives, boolean allowPost )
+    {
+        assertEquals( archive, mailingList.getMainArchiveUrl() );
+        if ( allowPost )
+        {
+            assertEquals( post, mailingList.getPostAddress() );
+        }
+        else
+        {
+            assertNull( mailingList.getPostAddress() );
+        }
+        assertEquals( subscribe, mailingList.getSubscribeAddress() );
+        assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
+        assertEquals( name, mailingList.getName() );
+        assertEquals( otherArchives, mailingList.getOtherArchives() );
+    }
+
+    private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
+                                    String nabbleUrl )
+    {
+        List<String> otherArchives = new ArrayList<String>();
+        otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
+        if ( nabbleUrl != null )
+        {
+            otherArchives.add( nabbleUrl );
+        }
+        otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
+        assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
+                           prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
+                           prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
+    }
+
     private void checkApacheLicense( ProjectVersionMetadata metadata )
     {
         assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
index 4624a80c09cb19465458e3cf8f770653380da61b..ea51d4f99c29cd6d3dee7e0736c1b5f71533b385 100644 (file)
@@ -60,7 +60,7 @@
       <subscribe>dev-subscribe@archiva.apache.org</subscribe>
       <unsubscribe>dev-unsubscribe@archiva.apache.org</unsubscribe>
       <post>dev@archiva.apache.org</post>
-      <archive>http://mail-archives.apache.org/mod_mbox/archiva-dev</archive>
+      <archive>http://mail-archives.apache.org/mod_mbox/archiva-dev/</archive>
       <otherArchives>
         <otherArchive>http://www.mail-archive.com/dev@archiva.apache.org</otherArchive>
         <otherArchive>http://www.nabble.com/archiva-dev-f16427.html</otherArchive>
@@ -71,7 +71,7 @@
       <name>Archiva Commits List</name>
       <subscribe>commits-subscribe@archiva.apache.org</subscribe>
       <unsubscribe>commits-unsubscribe@archiva.apache.org</unsubscribe>
-      <archive>http://mail-archives.apache.org/mod_mbox/archiva-commits</archive>
+      <archive>http://mail-archives.apache.org/mod_mbox/archiva-commits/</archive>
       <otherArchives>
         <otherArchive>http://www.mail-archive.com/commits@archiva.apache.org</otherArchive>
         <otherArchive>http://markmail.org/list/org.apache.archiva.commits</otherArchive>
       <name>Archiva Issues List</name>
       <subscribe>issues-subscribe@archiva.apache.org</subscribe>
       <unsubscribe>issues-unsubscribe@archiva.apache.org</unsubscribe>
-      <archive>http://mail-archives.apache.org/mod_mbox/archiva-issues</archive>
+      <archive>http://mail-archives.apache.org/mod_mbox/archiva-issues/</archive>
       <otherArchives>
         <otherArchive>http://www.mail-archive.com/issues@archiva.apache.org</otherArchive>
         <otherArchive>http://www.nabble.com/Archiva---Issues-f29617.html</otherArchive>
+        <otherArchive>http://markmail.org/list/org.apache.archiva.issues</otherArchive>
       </otherArchives>
     </mailingList>
    </mailingLists>
index 6e575325d0123674285a3bf6e514bd17b2c697d8..cc2f2c9715af6cc62b03465e7f356d4b8947ef34 100644 (file)
@@ -25,6 +25,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
@@ -35,6 +36,7 @@ import org.apache.archiva.metadata.model.ArtifactMetadata;
 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.MailingList;
 import org.apache.archiva.metadata.model.MetadataFacetFactory;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectMetadata;
@@ -123,6 +125,17 @@ public class FileMetadataRepository
             setProperty( properties, "license." + i + ".url", license.getUrl() );
             i++;
         }
+        i = 0;
+        for ( MailingList mailingList : versionMetadata.getMailingLists() )
+        {
+            setProperty( properties, "mailingList." + i + ".archive", mailingList.getMainArchiveUrl() );
+            setProperty( properties, "mailingList." + i + ".name", mailingList.getName() );
+            setProperty( properties, "mailingList." + i + ".post", mailingList.getPostAddress() );
+            setProperty( properties, "mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress() );
+            setProperty( properties, "mailingList." + i + ".subscribe", mailingList.getSubscribeAddress() );
+            setProperty( properties, "mailingList." + i + ".otherArchives", join( mailingList.getOtherArchives() ) );
+            i++;
+        }
         properties.setProperty( "facetIds", join( versionMetadata.getAllFacetIds() ) );
         for ( ProjectVersionFacet facet : versionMetadata.getAllFacets() )
         {
@@ -296,6 +309,30 @@ public class FileMetadataRepository
                 i++;
             }
 
+            done = false;
+            i = 0;
+            while ( !done )
+            {
+                String mailingListName = properties.getProperty( "mailingList." + i + ".name" );
+                if ( mailingListName != null )
+                {
+                    MailingList mailingList = new MailingList();
+                    mailingList.setName( mailingListName );
+                    mailingList.setMainArchiveUrl( properties.getProperty( "mailingList." + i + ".archive" ) );
+                    mailingList.setOtherArchives(
+                        Arrays.asList( properties.getProperty( "mailingList." + i + ".otherArchives" ).split( "," ) ) );
+                    mailingList.setPostAddress( properties.getProperty( "mailingList." + i + ".post" ) );
+                    mailingList.setSubscribeAddress( properties.getProperty( "mailingList." + i + ".subscribe" ) );
+                    mailingList.setUnsubscribeAddress( properties.getProperty( "mailingList." + i + ".unsubscribe" ) );
+                    versionMetadata.addMailingList( mailingList );
+                }
+                else
+                {
+                    done = true;
+                }
+                i++;
+            }
+
             for ( String facetId : properties.getProperty( "facetIds" ).split( "," ) )
             {
                 MetadataFacetFactory factory = metadataFacetFactories.get( facetId );