-fix the publish date of the rss entries -remove if condition in RepositoryContentConsumers.getStartDate() git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@656516 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-r676265
@@ -309,18 +309,21 @@ public class RepositoryContentConsumers | |||
{ | |||
this.selectedInvalidConsumers = selectedInvalidConsumers; | |||
} | |||
public void setStartTime( Date startTime ) | |||
{ | |||
this.startTime = startTime; | |||
} | |||
public Date getStartTime() | |||
{ | |||
if( startTime == null ) | |||
{ | |||
startTime = new Date( System.currentTimeMillis() ); | |||
} | |||
{ | |||
startTime = new Date( System.currentTimeMillis() ); | |||
return startTime; | |||
} | |||
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) | |||
{ | |||
this.archivaConfiguration = archivaConfiguration; | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
package org.apache.maven.archiva.repository.scanner; | |||
import java.util.Date; | |||
public class RepositoryContentConsumersStub | |||
extends RepositoryContentConsumers | |||
{ | |||
private Date startTimeForTest; | |||
public void setStartTime( Date startTimeForTest ) | |||
{ | |||
this.startTimeForTest = startTimeForTest; | |||
} | |||
public Date getStartTime() | |||
{ | |||
return startTimeForTest; | |||
} | |||
} |
@@ -20,6 +20,7 @@ package org.apache.maven.archiva.repository.scanner; | |||
*/ | |||
import org.apache.commons.lang.SystemUtils; | |||
import org.apache.maven.archiva.configuration.ArchivaConfiguration; | |||
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; | |||
import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; | |||
import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer; | |||
@@ -45,10 +46,21 @@ public class RepositoryContentConsumersTest | |||
private RepositoryContentConsumers lookupRepositoryConsumers() | |||
throws Exception | |||
{ | |||
RepositoryContentConsumers consumerUtilStub = (RepositoryContentConsumers) lookup( RepositoryContentConsumers.class | |||
.getName(), "test" ); | |||
ArchivaConfiguration archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.ROLE ); | |||
RepositoryContentConsumers consumerUtil = (RepositoryContentConsumers) lookup( RepositoryContentConsumers.class | |||
.getName() ); | |||
assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtil ); | |||
return consumerUtil; | |||
.getName() ); | |||
consumerUtilStub.setAvailableKnownConsumers( consumerUtil.getAvailableKnownConsumers() ); | |||
consumerUtilStub.setAvailableInvalidConsumers( consumerUtil.getAvailableInvalidConsumers() ); | |||
consumerUtilStub.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers() ); | |||
consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers() ); | |||
consumerUtilStub.setArchivaConfiguration( archivaConfiguration ); | |||
assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtilStub ); | |||
return consumerUtilStub; | |||
} | |||
public void testGetSelectedKnownIds() |
@@ -134,6 +134,11 @@ | |||
<id>move-to-trash-then-notify</id> | |||
</configuration> | |||
</component> | |||
<component> | |||
<role>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers</role> | |||
<role-hint>test</role-hint> | |||
<implementation>org.apache.maven.archiva.repository.scanner.RepositoryContentConsumersStub</implementation> | |||
</component> | |||
</components> | |||
</component-set> |
@@ -1,5 +1,7 @@ | |||
package org.apache.archiva.rss; | |||
import java.util.Date; | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one | |||
* or more contributor license agreements. See the NOTICE file | |||
@@ -45,6 +47,8 @@ public class RssFeedEntry | |||
private String source; | |||
private Date publishedDate; | |||
public RssFeedEntry() | |||
{ | |||
@@ -144,4 +148,14 @@ public class RssFeedEntry | |||
{ | |||
this.source = source; | |||
} | |||
public Date getPublishedDate() | |||
{ | |||
return publishedDate; | |||
} | |||
public void setPublishedDate( Date publishedDate ) | |||
{ | |||
this.publishedDate = publishedDate; | |||
} | |||
} |
@@ -62,7 +62,7 @@ public class RssFeedGenerator | |||
feed.setLink( DEFAULT_LINK + queryString ); | |||
feed.setDescription( description ); | |||
feed.setLanguage( DEFAULT_LANGUAGE ); | |||
feed.setPublishedDate( Calendar.getInstance().getTime() ); | |||
feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() ); | |||
feed.setFeedType( DEFAULT_FEEDTYPE ); | |||
feed.setEntries( getEntries( dataEntries ) ); | |||
@@ -82,7 +82,7 @@ public class RssFeedGenerator | |||
{ | |||
entry = new SyndEntryImpl(); | |||
entry.setTitle( dataEntry.getTitle() ); | |||
entry.setPublishedDate( Calendar.getInstance().getTime() ); | |||
entry.setPublishedDate( dataEntry.getPublishedDate() ); | |||
description = new SyndContentImpl(); | |||
description.setType( "text/plain" ); |
@@ -48,13 +48,14 @@ public abstract class AbstractArtifactsRssFeedProcessor | |||
for ( ArchivaArtifact artifact : artifacts ) | |||
{ | |||
long whenGathered = artifact.getModel().getWhenGathered().getTime(); | |||
if ( tmp != whenGathered ) | |||
{ | |||
if ( entry != null ) | |||
{ | |||
{ | |||
entry.setDescription( description ); | |||
entries.add( entry ); | |||
entry = null; | |||
} | |||
if ( !isRepoLevel ) | |||
@@ -62,6 +63,7 @@ public abstract class AbstractArtifactsRssFeedProcessor | |||
entry = | |||
new RssFeedEntry( getTitle() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + | |||
"\'" + " as of " + new Date( whenGathered ) ); | |||
entry.setPublishedDate( artifact.getModel().getWhenGathered() ); | |||
description = getDescription() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + | |||
"\'" + ": \n" + artifact.toString() + " | "; | |||
} | |||
@@ -69,6 +71,7 @@ public abstract class AbstractArtifactsRssFeedProcessor | |||
{ | |||
String repoId = artifact.getModel().getRepositoryId(); | |||
entry = new RssFeedEntry( getTitle() + "\'" + repoId + "\'" + " as of " + new Date( whenGathered ) ); | |||
entry.setPublishedDate( artifact.getModel().getWhenGathered() ); | |||
description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | "; | |||
} | |||
} | |||
@@ -78,7 +81,7 @@ public abstract class AbstractArtifactsRssFeedProcessor | |||
} | |||
if ( idx == ( artifacts.size() - 1 ) ) | |||
{ | |||
{ | |||
entry.setDescription( description ); | |||
entries.add( entry ); | |||
} |
@@ -20,6 +20,7 @@ package org.apache.archiva.rss; | |||
*/ | |||
import java.util.ArrayList; | |||
import java.util.Date; | |||
import java.util.List; | |||
import org.codehaus.plexus.spring.PlexusInSpringTestCase; | |||
@@ -49,16 +50,21 @@ public class RssFeedGeneratorTest | |||
{ | |||
List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>(); | |||
RssFeedEntry entry = new RssFeedEntry( "Item 1" ); | |||
Date whenGathered = new Date( System.currentTimeMillis() ); | |||
entry.setDescription( "RSS 2.0 feed item 1." ); | |||
entry.setPublishedDate( whenGathered ); | |||
entries.add( entry ); | |||
entry = new RssFeedEntry( "Item 2" ); | |||
entry.setDescription( "RSS 2.0 feed item 2." ); | |||
entry.setPublishedDate( whenGathered ); | |||
entries.add( entry ); | |||
entry = new RssFeedEntry( "Item 3" ); | |||
entry.setDescription( "RSS 2.0 feed item 3." ); | |||
entry.setPublishedDate( whenGathered ); | |||
entries.add( entry ); | |||
SyndFeed feed = | |||
@@ -68,6 +74,7 @@ public class RssFeedGeneratorTest | |||
assertEquals( "http://localhost:8080/archiva/rss/generated-rss2.0-feed.xml", feed.getLink() ); | |||
assertEquals( "The test feed from Archiva.", feed.getDescription() ); | |||
assertEquals( "en-us", feed.getLanguage() ); | |||
assertEquals( entries.get( 2 ).getPublishedDate(), feed.getPublishedDate() ); | |||
List<SyndEntry> syndEntries = feed.getEntries(); | |||
assertEquals( 3, syndEntries.size() ); |
@@ -119,9 +119,11 @@ public class NewArtifactsRssFeedProcessorTest | |||
assertTrue( feed.getDescription().equals( | |||
"New artifacts found in repository 'test-repo' during repository scan." ) ); | |||
assertTrue( feed.getLanguage().equals( "en-us" ) ); | |||
assertTrue( feed.getPublishedDate().equals( whenGathered ) ); | |||
List<SyndEntry> entries = feed.getEntries(); | |||
assertEquals( entries.size(), 1 ); | |||
assertTrue( entries.get( 0 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) ); | |||
assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) ); | |||
} | |||
} |
@@ -64,7 +64,7 @@ public class NewVersionsOfArtifactRssFeedProcessorTest | |||
Date whenGathered = Calendar.getInstance().getTime(); | |||
whenGathered.setTime( 123456789 ); | |||
ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar" ); | |||
artifact.getModel().setRepositoryId( "test-repo" ); | |||
artifact.getModel().setWhenGathered( whenGathered ); | |||
@@ -76,7 +76,7 @@ public class NewVersionsOfArtifactRssFeedProcessorTest | |||
artifacts.add( artifact ); | |||
Date whenGatheredNext = Calendar.getInstance().getTime(); | |||
whenGatheredNext.setTime( 345678912 ); | |||
whenGatheredNext.setTime( 345678912 ); | |||
artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar" ); | |||
artifact.getModel().setRepositoryId( "test-repo" ); | |||
@@ -99,14 +99,19 @@ public class NewVersionsOfArtifactRssFeedProcessorTest | |||
"New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.", | |||
feed.getDescription() ); | |||
assertEquals( "en-us", feed.getLanguage() ); | |||
assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() ); | |||
List<SyndEntry> entries = feed.getEntries(); | |||
assertEquals( 2, entries.size() ); | |||
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGathered, | |||
entries.get( 0 ).getTitle() ); | |||
assertEquals( whenGathered, entries.get( 0 ).getPublishedDate() ); | |||
assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two' as of " + whenGatheredNext, | |||
entries.get( 1 ).getTitle() ); | |||
assertEquals( whenGatheredNext, entries.get( 1 ).getPublishedDate() ); | |||
} | |||
} |