diff options
author | Maria Odea B. Ching <oching@apache.org> | 2008-04-07 15:50:57 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2008-04-07 15:50:57 +0000 |
commit | d346a91845de094c333c60cda17592038c44729d (patch) | |
tree | dd852e8605190c68e75a567f3e62bd40d03d3fef /archiva-modules/archiva-web/archiva-rss/src | |
parent | 5e407428a1f64899fbac16608356485cf8b02759 (diff) | |
download | archiva-d346a91845de094c333c60cda17592038c44729d.tar.gz archiva-d346a91845de094c333c60cda17592038c44729d.zip |
[MRM-123]
-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
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rss/src')
3 files changed, 44 insertions, 41 deletions
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java index 8357436aa..36634af96 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/RssFeedGenerator.java @@ -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; } + } diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java index a05eb0929..7b556f07a 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java +++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java @@ -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; diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java index b638c6dc6..c25432666 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java @@ -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() ); } } |