]> source.dussan.org Git - archiva.git/commitdiff
[MRM-123]
authorMaria Odea B. Ching <oching@apache.org>
Mon, 7 Apr 2008 15:50:57 +0000 (15:50 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 7 Apr 2008 15:50:57 +0000 (15:50 +0000)
-generate/update rss feeds after repository scan
-add rss feed icon in repositories (for new artifacts in repo feed) and in browse artifact (for new versions of artifact feed)

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@645576 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-repository-layer/pom.xml
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/DefaultRepositoryScanner.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/scanner/RepositoryScannerInstance.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java
archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/rss/rss.xml [new file with mode: 0644]
pom.xml

index 02744b17932f85312dbe31555867b82b796930d6..f23658bfe1d9523031d2fa7d18064d9bec433020 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-configuration</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-rss</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-xml-tools</artifactId>
+    </dependency>
     <dependency>
       <groupId>xmlunit</groupId>
       <artifactId>xmlunit</artifactId>
index a78ee10ace35b10b51cd4286176cda2f399a7599..0ad94eb2761be54e2278a14f5168d52074bded1f 100644 (file)
@@ -23,13 +23,20 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.archiva.rss.processor.RssFeedProcessor;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.maven.archiva.configuration.FileTypes;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
 import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.RepositoryNotFoundException;
+import org.apache.maven.archiva.repository.layout.LayoutException;
 import org.codehaus.plexus.util.DirectoryWalker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -55,6 +62,16 @@ public class DefaultRepositoryScanner
      * @plexus.requirement
      */
     private RepositoryContentConsumers consumerUtil;
+    
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryContentFactory repositoryFactory;
+    
+    /**
+     * @plexus.requirement role-hint="new-artifacts"
+     */
+    private RssFeedProcessor rssFeedProcessor;
 
     public RepositoryScanStatistics scan( ManagedRepositoryConfiguration repository, long changesSince )
         throws RepositoryException
@@ -126,6 +143,10 @@ public class DefaultRepositoryScanner
         stats.setKnownConsumers( gatherIds( knownContentConsumers ) );
         stats.setInvalidConsumers( gatherIds( invalidContentConsumers ) );
 
+        // generate RSS feeds
+        List<ArchivaArtifact> newArtifacts = getNewArtifacts( scannerInstance.getNewFiles(), repository.getId() );
+        rssFeedProcessor.process( newArtifacts );
+        
         return stats;
     }
 
@@ -138,4 +159,40 @@ public class DefaultRepositoryScanner
         }
         return ids;
     }
+    
+    private List<ArchivaArtifact> getNewArtifacts( List<File> files, String repoId )
+    {
+        List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
+        
+        // TODO: filter the file types of artifacts that will be included in the rss feeds        
+        try
+        {
+            ManagedRepositoryContent repository = repositoryFactory.getManagedRepositoryContent( repoId );
+            for( File file : files )
+            {
+                try
+                {
+                    ArtifactReference ref = repository.toArtifactReference( file.getAbsolutePath() );
+                    ArchivaArtifact artifact = new ArchivaArtifact( ref.getGroupId(),ref.getArtifactId(), ref.getVersion(),
+                                                                   ref.getClassifier(), ref.getType() );
+                    artifact.getModel().setRepositoryId( repoId );
+                    newArtifacts.add( artifact );
+                }
+                catch ( LayoutException le )
+                {
+                    
+                }
+            }
+        }
+        catch ( RepositoryNotFoundException re )
+        {
+            log.error( re.getMessage() );
+        }
+        catch ( RepositoryException e )
+        {
+            log.error( e.getMessage() );   
+        }
+        
+        return newArtifacts;
+    }
 }
index 9c0f386804ef67ca403965edd494c650dfa753b3..d3d4b28f36ee468bf5a1f38820da9e65c4517d0f 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.maven.archiva.repository.scanner;
  */
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.collections.Closure;
@@ -66,6 +67,8 @@ public class RepositoryScannerInstance
     private ConsumerProcessFileClosure consumerProcessFile;
 
     private ConsumerWantsFilePredicate consumerWantsFile;
+    
+    private List<File> newFiles = new ArrayList<File>();
 
     public RepositoryScannerInstance( ManagedRepositoryConfiguration repository,
                                       List<KnownRepositoryContentConsumer> knownConsumerList,
@@ -120,14 +123,15 @@ public class RepositoryScannerInstance
 
         stats.increaseFileCount();
 
+        // consume files regardless - the predicate will check the timestamp
+        BaseFile basefile = new BaseFile( repository.getLocation(), file );
+        
         // Timestamp finished points to the last successful scan, not this current one.
         if ( file.lastModified() >= changesSince )
         {
             stats.increaseNewFileCount();
+            newFiles.add( basefile );       
         }
-
-        // consume files regardless - the predicate will check the timestamp
-        BaseFile basefile = new BaseFile( repository.getLocation(), file );
         
         consumerProcessFile.setBasefile( basefile );
         consumerWantsFile.setBasefile( basefile );
@@ -155,4 +159,9 @@ public class RepositoryScannerInstance
     {
         log.debug( "Repository Scanner: " + message );
     }
+    
+    public List<File> getNewFiles()
+    {
+        return newFiles;
+    }
 }
index 8357436aa3b7cc13094353d6ca07256da9fbd140..36634af96bace16ed7d3f448b2b5452e9b5b3c8b 100644 (file)
@@ -44,7 +44,8 @@ import com.sun.syndication.io.XmlReader;
 /**
  * Generates RSS feeds.
  * 
- * @plexus.component role="org.apache.archiva.rss.RssFeedGenerator"
+ * @plexus.component role="org.apache.archiva.rss.RssFeedGenerator" 
+ *      instantiation-strategy="per-lookup"
  * 
  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
  * @version
@@ -57,21 +58,21 @@ public class RssFeedGenerator
     public static String DEFAULT_FEEDTYPE = "rss_2.0";
 
     public static String DEFAULT_LANGUAGE = "en-us";
-    
+
     /**
-     * @plexus.configuration default-value="${appserver.base}/data/rss"
+     * @plexus.configuration default-value="./apps/archiva/rss/"
      */
     private String rssDirectory;
 
     public void generateFeed( String title, String link, String description, List<RssFeedEntry> dataEntries,
                               String outputFilename )
-    {   
-        File outputFile = new File( rssDirectory, outputFilename );     
+    {           
+        File outputFile = new File( rssDirectory, outputFilename );
         SyndFeed feed = null;
         List<SyndEntry> existingEntries = null;
-        
-        if( outputFile.exists() )
-        {   
+
+        if ( outputFile.exists() )
+        {
             try
             {
                 SyndFeedInput input = new SyndFeedInput();
@@ -88,25 +89,27 @@ public class RssFeedGenerator
             }
         }
         else
-        {        
-            feed = new SyndFeedImpl();            
-    
+        {
+            feed = new SyndFeedImpl();
+
             feed.setTitle( title );
             feed.setLink( link );
             feed.setDescription( description );
-            feed.setLanguage( DEFAULT_LANGUAGE );            
+            feed.setLanguage( DEFAULT_LANGUAGE );
+            feed.setPublishedDate( Calendar.getInstance().getTime() );
         }
 
-        feed.setFeedType( DEFAULT_FEEDTYPE );
-        feed.setPublishedDate( Calendar.getInstance().getTime() );
+        feed.setFeedType( DEFAULT_FEEDTYPE );        
         feed.setEntries( getEntries( dataEntries, existingEntries ) );
-        
+
         try
-        {            
+        {
             Writer writer = new FileWriter( outputFile );
             SyndFeedOutput output = new SyndFeedOutput();
             output.output( feed, writer );
             writer.close();
+
+            log.debug( "Finished writing feed to " + outputFile.getAbsolutePath() );
         }
         catch ( IOException ie )
         {
@@ -119,13 +122,13 @@ public class RssFeedGenerator
     }
 
     private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries, List<SyndEntry> existingEntries )
-    {        
-        List<SyndEntry> entries = existingEntries;     
-        if( entries == null )
+    {
+        List<SyndEntry> entries = existingEntries;
+        if ( entries == null )
         {
             entries = new ArrayList<SyndEntry>();
         }
-        
+
         SyndEntry entry;
         SyndContent description;
 
@@ -151,4 +154,5 @@ public class RssFeedGenerator
     {
         this.rssDirectory = rssDirectory;
     }
+    
 }
index a05eb0929e55a84a410bd23b79fabab0a512516c..7b556f07aa74663d5c47e81b4b21d467c7355340 100644 (file)
@@ -30,6 +30,8 @@ import org.apache.archiva.rss.RssFeedEntry;
 import org.apache.archiva.rss.RssFeedGenerator;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Process new artifacts in the repository and generate RSS feeds.
@@ -50,12 +52,16 @@ public class NewArtifactsRssFeedProcessor
      */
     private RssFeedGenerator generator;
 
+    private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class );
+
     /**
      * Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
      * new versions of artifact.
      */
     public void process( List<ArchivaArtifact> data )
     {
+        log.debug( "Process new artifacts into rss feeds." );
+        
         processNewArtifactsInRepo( data );
         processNewVersionsOfArtifact( data );
     }
@@ -67,19 +73,19 @@ public class NewArtifactsRssFeedProcessor
 
         RssFeedEntry entry =
             new RssFeedEntry( NEW_ARTIFACTS_IN_REPO + "\'" + repoId + "\'" + " as of " +
-                Calendar.getInstance().getTime(), "http://localhost:8080/archiva/repository/" + repoId );
+                Calendar.getInstance().getTime(), "http://localhost:8080/archiva/rss/new_artifacts_" + repoId + ".xml" );
         String description = "These are the new artifacts found in repository " + "\'" + repoId + "\'" + ": \n";
 
         for ( ArchivaArtifact artifact : data )
         {
-            description = description + artifact.toString() + "\n";
+            description = description + artifact.toString() + " | ";
         }
         entry.setDescription( description );
         entries.add( entry );
 
         generateFeed( "new_artifacts_" + repoId + ".xml", NEW_ARTIFACTS_IN_REPO + "\'" + repoId + "\'",
-                      "http://localhost:8080/archiva/repository/" + repoId, "New artifacts found in repository " +
-                          "\'" + repoId + "\'" + " during repository scan.", entries );
+                      "http://localhost:8080/archiva/repository/rss/new_artifacts_" + repoId + ".xml",
+                      "New artifacts found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries );
     }
 
     private void processNewVersionsOfArtifact( List<ArchivaArtifact> data )
@@ -100,21 +106,19 @@ public class NewArtifactsRssFeedProcessor
         for ( String key : artifactsMap.keySet() )
         {
             List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
-            String artifactPath = getArtifactPath( key );
             RssFeedEntry entry =
                 new RssFeedEntry( NEW_VERSIONS_OF_ARTIFACT + "\'" + key + "\'" + " as of " +
-                    Calendar.getInstance().getTime(), "http://localhost:8080/archiva/repository/" + repoId + "/" +
-                    artifactPath );
+                    Calendar.getInstance().getTime(), "http://localhost:8080/archiva/rss/new_versions_" + key + ".xml" );
 
             String description =
                 "These are the new versions of artifact " + "\'" + key + "\'" + " in the repository: \n" +
-                    StringUtils.replace( ( (String) artifactsMap.get( key ) ), "|", "\n" );
+                    ( (String) artifactsMap.get( key ) );
 
             entry.setDescription( description );
             entries.add( entry );
 
-            generateFeed( "new_versions_" + repoId + "_" + key + ".xml", NEW_VERSIONS_OF_ARTIFACT + "\'" + key + "\'",
-                          "http://localhost:8080/archiva/repository/" + repoId + "/" + artifactPath,
+            generateFeed( "new_versions_" + key + ".xml", NEW_VERSIONS_OF_ARTIFACT + "\'" + key + "\'",
+                          "http://localhost:8080/archiva/rss/new_versions_" + key + ".xml",
                           "New versions of artifact " + "\'" + key + "\' found in repository " + "\'" + repoId + "\'" +
                               " during repository scan.", entries );
         }
@@ -148,7 +152,7 @@ public class NewArtifactsRssFeedProcessor
             String value = (String) artifactsMap.get( key );
             if ( value != null )
             {
-                value = value + "|" + id;
+                value = value + " | " + id;
             }
             else
             {
@@ -160,16 +164,11 @@ public class NewArtifactsRssFeedProcessor
         return artifactsMap;
     }
 
-    private String getArtifactPath( String key )
-    {
-        return StringUtils.replace( StringUtils.replace( key, ".", "/" ), ":", "/" );
-    }
-    
     public RssFeedGenerator getGenerator()
     {
         return generator;
     }
-    
+
     public void setGenerator( RssFeedGenerator generator )
     {
         this.generator = generator;
index b638c6dc60bb31c5e17765d99421d5812666df69..c2543266668c018321134c8fdf0b438ab3cf4f49 100644 (file)
@@ -93,16 +93,16 @@ public class NewArtifactsRssFeedProcessorTest
         File outputFile = new File( rssDirectory, "new_artifacts_test-repo.xml" );        
         assertTrue( outputFile.exists() );
         
-        outputFile = new File( rssDirectory, "new_versions_test-repo_org.apache.archiva:artifact-one.xml" );        
+        outputFile = new File( rssDirectory, "new_versions_org.apache.archiva:artifact-one.xml" );        
         assertTrue( outputFile.exists() );
         
-        outputFile = new File( rssDirectory, "new_versions_test-repo_org.apache.archiva:artifact-two.xml" );        
+        outputFile = new File( rssDirectory, "new_versions_org.apache.archiva:artifact-two.xml" );        
         assertTrue( outputFile.exists() );
         
-        outputFile = new File( rssDirectory, "new_versions_test-repo_org.apache.archiva:artifact-three.xml" );        
+        outputFile = new File( rssDirectory, "new_versions_org.apache.archiva:artifact-three.xml" );        
         assertTrue( outputFile.exists() );
         
-        outputFile = new File( rssDirectory, "new_versions_test-repo_org.apache.archiva:artifact-four.xml" );        
+        outputFile = new File( rssDirectory, "new_versions_org.apache.archiva:artifact-four.xml" );        
         assertTrue( outputFile.exists() );
     }
 }
index 3fc9bbf3607a8bb9fe51ef1a38b0409c6dc95df8..fcd72989afe9c15d726171d22b1159ad35dfafb1 100644 (file)
       Delete
     </ww:a>
   </redback:ifAnyAuthorized>
+  <c:url var="rssFeedIconUrl" value="/images/icons/rss-feed.png"/>
+  <a href="/archiva/rss/new_artifacts_${repository.id}.xml">
+       <img src="${rssFeedIconUrl}" />
+  </a>
 </div>
 
 <div style="float: left">
index a415574036187ac81eceb5d272073975f1dfcacd..bf7acb2650f3ef468eb34694f25ddc9bcb9b4a81 100644 (file)
     <div id="nameColumn">
       <h2>Artifacts</h2>
       <ul>
+        <c:url var="rssFeedIconUrl" value="/images/icons/rss-feed.png"/>
         <c:forEach items="${results.artifacts}" var="artifactId">
           <c:set var="url">
             <ww:url action="browseArtifact" namespace="/">
               <ww:param name="groupId" value="%{'${results.selectedGroupId}'}"/>
               <ww:param name="artifactId" value="%{'${artifactId}'}"/>
             </ww:url>
-          </c:set>
-          <li><a href="${url}">${artifactId}/</a></li>
+          </c:set>          
+          <li>
+          <a href="${url}">${artifactId}/</a>
+          <a href="/archiva/rss/new_versions_${groupId}:${artifactId}.xml">
+               <img src="${rssFeedIconUrl}" />
+         </a>
+         </li>    
         </c:forEach>
       </ul>
     </div>
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/rss/rss.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/rss/rss.xml
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/pom.xml b/pom.xml
index b502551314f8cee18a8542e6a07eaea92e862253..dc002f5b71128d5b2da64212b06ef3d510d578de 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>archiva-webdav</artifactId>
         <version>1.1-SNAPSHOT</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.archiva</groupId>
+        <artifactId>archiva-rss</artifactId>
+        <version>1.1-SNAPSHOT</version>
+      </dependency>
       <dependency>
         <groupId>org.codehaus.plexus</groupId>
         <artifactId>plexus-spring</artifactId>