summaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-12-09 08:08:21 +0000
committerBrett Porter <brett@apache.org>2009-12-09 08:08:21 +0000
commit99765460e017147e9663e3f653a3f243a6b705ea (patch)
treed29640960376b4688556f3935cd4f983dbf83a3c /archiva-modules
parent94e702281c96889f2736ba937cdde517646921ed (diff)
downloadarchiva-99765460e017147e9663e3f653a3f243a6b705ea.tar.gz
archiva-99765460e017147e9663e3f653a3f243a6b705ea.zip
[MRM-1299] migrate RSS from the database to the metadata repository
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@888723 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java3
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java20
-rw-r--r--archiva-modules/archiva-web/archiva-rss/pom.xml12
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java78
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessor.java76
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java108
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java8
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java102
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java102
-rw-r--r--archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java79
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java21
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java184
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java114
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java95
-rw-r--r--archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml7
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java20
-rw-r--r--archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java103
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java11
-rw-r--r--archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java117
-rw-r--r--archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java155
20 files changed, 905 insertions, 510 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
index 02c447660..d8a33deb5 100644
--- a/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
+++ b/archiva-modules/archiva-base/archiva-consumers/archiva-metadata-consumer/src/main/java/org/apache/archiva/consumers/metadata/ArchivaMetadataCreationConsumer.java
@@ -154,6 +154,9 @@ public class ArchivaMetadataCreationConsumer
versionMetadata.setId( VersionUtil.getBaseVersion( artifact.getVersion() ) );
ArtifactMetadata artifactMeta = new ArtifactMetadata();
+ artifactMeta.setRepositoryId( repository.getId() );
+ artifactMeta.setNamespace( artifact.getGroupId() );
+ artifactMeta.setProject( artifact.getArtifactId() );
artifactMeta.setId( file.getName() );
artifactMeta.setFileLastModified( file.lastModified() );
artifactMeta.setSize( file.length() );
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
index 5cd2ef472..99571538b 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
@@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repository;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -88,7 +89,8 @@ public class TestMetadataRepository
//To change body of implemented methods use File | Settings | File Templates.
}
- public void updateProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata )
+ public void updateProjectVersion( String repoId, String namespace, String projectId,
+ ProjectVersionMetadata versionMetadata )
{
//To change body of implemented methods use File | Settings | File Templates.
}
@@ -123,4 +125,20 @@ public class TestMetadataRepository
{
//To change body of implemented methods use File | Settings | File Templates.
}
+
+ public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Collection<String> getRepositories()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
}
diff --git a/archiva-modules/archiva-web/archiva-rss/pom.xml b/archiva-modules/archiva-web/archiva-rss/pom.xml
index 95633e203..b94aa75c7 100644
--- a/archiva-modules/archiva-web/archiva-rss/pom.xml
+++ b/archiva-modules/archiva-web/archiva-rss/pom.xml
@@ -35,12 +35,7 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
- <artifactId>archiva-model</artifactId>
- </dependency>
- <!-- TODO: replace with metadata processor -->
- <dependency>
- <groupId>org.apache.archiva</groupId>
- <artifactId>archiva-database</artifactId>
+ <artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -65,5 +60,10 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
index 92aa5e245..0dca954c7 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/AbstractArtifactsRssFeedProcessor.java
@@ -19,82 +19,22 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.rss.RssFeedEntry;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import com.sun.syndication.feed.synd.SyndFeed;
-
-/**
- * @version
- */
public abstract class AbstractArtifactsRssFeedProcessor
implements RssFeedProcessor
{
- public abstract SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
-
- protected List<RssFeedEntry> processData( List<ArchivaArtifact> artifacts, boolean isRepoLevel )
- {
- long tmp = 0;
- RssFeedEntry entry = null;
- List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
- String description = "";
- int idx = 0;
- 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 )
- {
- 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() + " | ";
- }
- else
- {
- 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() + " | ";
- }
- }
- else
- {
- description = description + artifact.toString() + " | ";
- }
-
- if ( idx == ( artifacts.size() - 1 ) )
- {
- entry.setDescription( description );
- entries.add( entry );
- }
-
- tmp = whenGathered;
- idx++;
- }
-
- return entries;
- }
+ /**
+ * @plexus.requirement
+ */
+ protected MetadataRepository metadataRepository;
protected abstract String getTitle();
protected abstract String getDescription();
+ public void setMetadataRepository( MetadataRepository metadataRepository )
+ {
+ this.metadataRepository = metadataRepository;
+ }
}
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 addf50dec..c7d81921c 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
@@ -19,19 +19,17 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
+import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.rss.RssFeedEntry;
import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint;
-import org.apache.maven.archiva.model.ArchivaArtifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,7 +38,6 @@ import org.slf4j.LoggerFactory;
* The artifacts will be grouped by the date when the artifacts were gathered.
* Each group will appear as one entry in the feed.
*
- * @version
* @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-artifacts"
*/
public class NewArtifactsRssFeedProcessor
@@ -59,18 +56,13 @@ public class NewArtifactsRssFeedProcessor
private Logger log = LoggerFactory.getLogger( NewArtifactsRssFeedProcessor.class );
- /**
- * @plexus.requirement role-hint="jdo"
- */
- private ArtifactDAO artifactDAO;
-
private static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone( "GMT" );
/**
* Process the newly discovered artifacts in the repository. Generate feeds for new artifacts in the repository and
* new versions of artifact.
*/
- public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
+ public SyndFeed process( Map<String, String> reqParams )
{
log.debug( "Process new artifacts into rss feeds." );
@@ -83,16 +75,53 @@ public class NewArtifactsRssFeedProcessor
return null;
}
- private SyndFeed processNewArtifactsInRepo( String repoId ) throws ArchivaDatabaseException
+ private SyndFeed processNewArtifactsInRepo( String repoId )
{
-
Calendar greaterThanThisDate = Calendar.getInstance( GMT_TIME_ZONE );
greaterThanThisDate.add( Calendar.DATE, -( getNumberOfDaysBeforeNow() ) );
-
- Constraint artifactsByRepo = new ArtifactsByRepositoryConstraint( repoId, greaterThanThisDate.getTime(), "whenGathered", false );
- List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactsByRepo );
+ greaterThanThisDate.clear( Calendar.MILLISECOND );
- List<RssFeedEntry> entries = processData( artifacts, true );
+ List<ArtifactMetadata> artifacts =
+ metadataRepository.getArtifactsByDateRange( repoId, greaterThanThisDate.getTime(), null );
+
+ long tmp = 0;
+ RssFeedEntry entry = null;
+ List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
+ String description = "";
+ int idx = 0;
+ for ( ArtifactMetadata artifact : artifacts )
+ {
+ long whenGathered = artifact.getWhenGathered().getTime();
+
+ String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
+ if ( tmp != whenGathered )
+ {
+ if ( entry != null )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ entry = null;
+ }
+
+ String repoId1 = artifact.getRepositoryId();
+ entry = new RssFeedEntry( this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date( whenGathered ) );
+ entry.setPublishedDate( artifact.getWhenGathered() );
+ description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
+ }
+ else
+ {
+ description = description + id + " | ";
+ }
+
+ if ( idx == ( artifacts.size() - 1 ) )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ }
+
+ tmp = whenGathered;
+ idx++;
+ }
return generator.generateFeed( getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " +
"\'" + repoId + "\'" + " during repository scan.", entries );
@@ -118,16 +147,6 @@ public class NewArtifactsRssFeedProcessor
this.generator = generator;
}
- public ArtifactDAO getArtifactDAO()
- {
- return artifactDAO;
- }
-
- public void setArtifactDAO( ArtifactDAO artifactDAO )
- {
- this.artifactDAO = artifactDAO;
- }
-
public int getNumberOfDaysBeforeNow()
{
return numberOfDaysBeforeNow;
@@ -137,5 +156,4 @@ public class NewArtifactsRssFeedProcessor
{
this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;
}
-
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
index c4c50e84f..a1a80ed54 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessor.java
@@ -19,25 +19,23 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Map;
+import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
import org.apache.archiva.rss.RssFeedEntry;
import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-import com.sun.syndication.feed.synd.SyndFeed;
/**
* Retrieve and process new versions of an artifact from the database and
- * generate a rss feed. The versions will be grouped by the date when the artifact
+ * generate a rss feed. The versions will be grouped by the date when the artifact
* was gathered. Each group will appear as one entry in the feed.
- *
- * @version
+ *
* @plexus.component role="org.apache.archiva.rss.processor.RssFeedProcessor" role-hint="new-versions"
*/
public class NewVersionsOfArtifactRssFeedProcessor
@@ -53,39 +51,80 @@ public class NewVersionsOfArtifactRssFeedProcessor
private RssFeedGenerator generator;
/**
- * @plexus.requirement role-hint="jdo"
- */
- private ArtifactDAO artifactDAO;
-
- /**
* Process all versions of the artifact which had a rss feed request.
*/
- public SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException
+ public SyndFeed process( Map<String, String> reqParams )
+ throws MetadataResolverException
{
- String repoId = reqParams.get( RssFeedProcessor.KEY_REPO_ID );
String groupId = reqParams.get( RssFeedProcessor.KEY_GROUP_ID );
String artifactId = reqParams.get( RssFeedProcessor.KEY_ARTIFACT_ID );
-
+
if ( groupId != null && artifactId != null )
{
- return processNewVersionsOfArtifact( repoId, groupId, artifactId );
+ return processNewVersionsOfArtifact( groupId, artifactId );
}
return null;
}
- private SyndFeed processNewVersionsOfArtifact( String repoId, String groupId, String artifactId )
- throws ArchivaDatabaseException
+ private SyndFeed processNewVersionsOfArtifact( String groupId, String artifactId )
+ throws MetadataResolverException
{
-
- Constraint artifactVersions = new ArtifactVersionsConstraint( repoId, groupId, artifactId, "whenGathered" );
- List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( artifactVersions );
-
- List<RssFeedEntry> entries = processData( artifacts, false );
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
+ for ( String repoId : metadataRepository.getRepositories() )
+ {
+ Collection<String> versions = metadataRepository.getProjectVersions( repoId, groupId, artifactId );
+ for ( String version : versions )
+ {
+ artifacts.addAll( metadataRepository.getArtifacts( repoId, groupId, artifactId, version ) );
+ }
+ }
+
+ long tmp = 0;
+ RssFeedEntry entry = null;
+ List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>();
+ String description = "";
+ int idx = 0;
+ for ( ArtifactMetadata artifact : artifacts )
+ {
+ long whenGathered = artifact.getWhenGathered().getTime();
+
+ if ( tmp != whenGathered )
+ {
+ if ( entry != null )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ entry = null;
+ }
+
+ entry = new RssFeedEntry(
+ this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date( whenGathered ) );
+ entry.setPublishedDate( artifact.getWhenGathered() );
+ description =
+ this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() +
+ " | ";
+ }
+ else
+ {
+ description = description + artifact.getId() + " | ";
+ }
+
+ if ( idx == ( artifacts.size() - 1 ) )
+ {
+ entry.setDescription( description );
+ entries.add( entry );
+ }
+
+ tmp = whenGathered;
+ idx++;
+ }
+
String key = groupId + ":" + artifactId;
-
- return generator.generateFeed( getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key +
- "\' found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries );
+
+ return generator.generateFeed( getTitle() + "\'" + key + "\'",
+ "New versions of artifact " + "\'" + key + "\' found during repository scan.",
+ entries );
}
public String getTitle()
@@ -107,15 +146,4 @@ public class NewVersionsOfArtifactRssFeedProcessor
{
this.generator = generator;
}
-
- public ArtifactDAO getArtifactDAO()
- {
- return artifactDAO;
- }
-
- public void setArtifactDAO( ArtifactDAO artifactDAO )
- {
- this.artifactDAO = artifactDAO;
- }
-
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
index 68590b50f..7d4723e31 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/main/java/org/apache/archiva/rss/processor/RssFeedProcessor.java
@@ -21,14 +21,11 @@ package org.apache.archiva.rss.processor;
import java.util.Map;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
/**
* Retrieve and process the data that will be fed into the RssFeedGenerator.
- *
- * @version
*/
public interface RssFeedProcessor
{
@@ -38,5 +35,6 @@ public interface RssFeedProcessor
public static final String KEY_ARTIFACT_ID = "artifactId";
- SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
+ SyndFeed process( Map<String, String> reqParams )
+ throws MetadataResolverException;
}
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 c4587e386..5c9670f6a 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
@@ -25,18 +25,16 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
-import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.archiva.rss.stubs.ArtifactDAOStub;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import java.util.TimeZone;
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.rss.RssFeedGenerator;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
-/**
- * @version
- */
public class NewArtifactsRssFeedProcessorTest
extends PlexusInSpringTestCase
{
@@ -44,9 +42,9 @@ public class NewArtifactsRssFeedProcessorTest
private NewArtifactsRssFeedProcessor newArtifactsProcessor;
- private ArtifactDAOStub artifactDAOStub;
+ private MetadataRepository metadataRepository;
- private RssFeedGenerator rssFeedGenerator;
+ private MockControl metadataRepositoryControl;
@Override
public void setUp()
@@ -55,69 +53,65 @@ public class NewArtifactsRssFeedProcessorTest
super.setUp();
newArtifactsProcessor = new NewArtifactsRssFeedProcessor();
- artifactDAOStub = new ArtifactDAOStub();
-
- rssFeedGenerator = new RssFeedGenerator();
+ newArtifactsProcessor.setGenerator( new RssFeedGenerator() );
- newArtifactsProcessor.setGenerator( rssFeedGenerator );
- newArtifactsProcessor.setArtifactDAO( artifactDAOStub );
+ metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
+ metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
+ newArtifactsProcessor.setMetadataRepository( metadataRepository );
}
@SuppressWarnings("unchecked")
public void testProcess()
throws Exception
{
- List<ArchivaArtifact> newArtifacts = new ArrayList<ArchivaArtifact>();
+ List<ArtifactMetadata> newArtifacts = new ArrayList<ArtifactMetadata>();
Date whenGathered = Calendar.getInstance().getTime();
- ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- newArtifacts.add( artifact );
-
- artifactDAOStub.setArtifacts( newArtifacts );
+ newArtifacts.add( createArtifact( "artifact-one", "1.0", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-one", "1.1", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-one", "2.0", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-two", "1.0.1", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-two", "1.0.2", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered ) );
+ newArtifacts.add( createArtifact( "artifact-four", "1.1-beta-2", whenGathered ) );
+
+ Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "GMT" ) );
+ cal.add( Calendar.DATE, -30 );
+ cal.clear( Calendar.MILLISECOND );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifactsByDateRange( TEST_REPO, cal.getTime(), null ), newArtifacts );
+ metadataRepositoryControl.replay();
Map<String, String> reqParams = new HashMap<String, String>();
- reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
+ reqParams.put( RssFeedProcessor.KEY_REPO_ID, TEST_REPO );
SyndFeed feed = newArtifactsProcessor.process( reqParams );
- assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
- assertTrue( feed.getDescription().equals(
- "New artifacts found in repository 'test-repo' during repository scan." ) );
+ assertTrue( feed.getTitle().equals( "New Artifacts in Repository 'test-repo'" ) );
+ 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 ).getTitle().equals( "New Artifacts in Repository 'test-repo' as of " + whenGathered ) );
assertTrue( entries.get( 0 ).getPublishedDate().equals( whenGathered ) );
+
+ metadataRepositoryControl.verify();
+ }
+
+ private ArtifactMetadata createArtifact( String artifactId, String version, Date whenGathered )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setNamespace( "org.apache.archiva" );
+ artifact.setId( artifactId + "-" + version + ".jar" );
+ artifact.setRepositoryId( TEST_REPO );
+ artifact.setWhenGathered( whenGathered );
+ artifact.setProject( artifactId );
+ artifact.setVersion( version );
+ return artifact;
}
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
index e1256954b..b1cdf7cf8 100644
--- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
+++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewVersionsOfArtifactRssFeedProcessorTest.java
@@ -19,31 +19,35 @@ package org.apache.archiva.rss.processor;
* under the License.
*/
-import java.util.ArrayList;
-import java.util.Calendar;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.archiva.rss.RssFeedGenerator;
-import org.apache.archiva.rss.stubs.ArtifactDAOStub;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
import com.sun.syndication.feed.synd.SyndEntry;
import com.sun.syndication.feed.synd.SyndFeed;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.rss.RssFeedGenerator;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.easymock.MockControl;
public class NewVersionsOfArtifactRssFeedProcessorTest
extends PlexusInSpringTestCase
{
+ private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
+
private static final String TEST_REPO = "test-repo";
- private NewVersionsOfArtifactRssFeedProcessor newVersionsProcessor;
+ private static final String GROUP_ID = "org.apache.archiva";
+
+ private static final String ARTIFACT_ID = "artifact-two";
- private ArtifactDAOStub artifactDAOStub;
+ private MockControl metadataRepositoryControl;
- private RssFeedGenerator rssFeedGenerator;
+ private MetadataRepository metadataRepository;
@Override
public void setUp()
@@ -52,64 +56,78 @@ public class NewVersionsOfArtifactRssFeedProcessorTest
super.setUp();
newVersionsProcessor = new NewVersionsOfArtifactRssFeedProcessor();
- artifactDAOStub = new ArtifactDAOStub();
+ newVersionsProcessor.setGenerator( new RssFeedGenerator() );
- rssFeedGenerator = new RssFeedGenerator();
-
- newVersionsProcessor.setGenerator( rssFeedGenerator );
- newVersionsProcessor.setArtifactDAO( artifactDAOStub );
+ metadataRepositoryControl = MockControl.createControl( MetadataRepository.class );
+ metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock();
+ newVersionsProcessor.setMetadataRepository( metadataRepository );
}
@SuppressWarnings("unchecked")
public void testProcess()
throws Exception
{
- List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
-
- Date whenGathered = Calendar.getInstance().getTime();
- whenGathered.setTime( 123456789 );
-
- ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
+ Date whenGathered = new Date( 123456789 );
- Date whenGatheredNext = Calendar.getInstance().getTime();
- whenGatheredNext.setTime( 345678912 );
+ ArtifactMetadata artifact1 = createArtifact( whenGathered, "1.0.1" );
+ ArtifactMetadata artifact2 = createArtifact( whenGathered, "1.0.2" );
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", TEST_REPO );
- artifact.getModel().setWhenGathered( whenGatheredNext );
- artifacts.add( artifact );
+ Date whenGatheredNext = new Date( 345678912 );
- artifactDAOStub.setArtifacts( artifacts );
+ ArtifactMetadata artifact3 = createArtifact( whenGatheredNext, "1.0.3-SNAPSHOT" );
Map<String, String> reqParams = new HashMap<String, String>();
- reqParams.put( RssFeedProcessor.KEY_REPO_ID, "test-repo" );
- reqParams.put( RssFeedProcessor.KEY_GROUP_ID, "org.apache.archiva" );
- reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, "artifact-two" );
+ reqParams.put( RssFeedProcessor.KEY_GROUP_ID, GROUP_ID );
+ reqParams.put( RssFeedProcessor.KEY_ARTIFACT_ID, ARTIFACT_ID );
+
+ metadataRepositoryControl.expectAndReturn( metadataRepository.getRepositories(),
+ Collections.singletonList( TEST_REPO ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getProjectVersions( TEST_REPO, GROUP_ID, ARTIFACT_ID ),
+ Arrays.asList( "1.0.1", "1.0.2", "1.0.3-SNAPSHOT" ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.1" ),
+ Collections.singletonList( artifact1 ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.2" ),
+ Collections.singletonList( artifact2 ) );
+ metadataRepositoryControl.expectAndReturn(
+ metadataRepository.getArtifacts( TEST_REPO, GROUP_ID, ARTIFACT_ID, "1.0.3-SNAPSHOT" ),
+ Collections.singletonList( artifact3 ) );
+ metadataRepositoryControl.replay();
SyndFeed feed = newVersionsProcessor.process( reqParams );
- assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
- assertEquals(
- "New versions of artifact 'org.apache.archiva:artifact-two' found in repository 'test-repo' during repository scan.",
+ assertEquals( "New Versions of Artifact 'org.apache.archiva:artifact-two'", feed.getTitle() );
+ assertEquals( "New versions of artifact 'org.apache.archiva:artifact-two' found during repository scan.",
feed.getDescription() );
assertEquals( "en-us", feed.getLanguage() );
- assertEquals( artifacts.get( 2 ).getModel().getWhenGathered(), feed.getPublishedDate() );
+ assertEquals( whenGatheredNext, 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() );
+
+ metadataRepositoryControl.verify();
+ }
+
+ private ArtifactMetadata createArtifact( Date whenGathered, String version )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setNamespace( GROUP_ID );
+ artifact.setProject( ARTIFACT_ID );
+ artifact.setVersion( version );
+ artifact.setRepositoryId( TEST_REPO );
+ artifact.setId( ARTIFACT_ID + "-" + version + ".jar" );
+ artifact.setWhenGathered( whenGathered );
+ return artifact;
}
}
diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java
deleted file mode 100644
index 9eade4d65..000000000
--- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.archiva.rss.stubs;
-
-/*
- * 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.
- */
-
-import java.util.List;
-
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-/**
- * ArtifactDAO stub.
- *
- * @version *
- */
-public class ArtifactDAOStub
- implements ArtifactDAO
-{
- private List<ArchivaArtifact> artifacts;
-
- public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
- String type, String repositoryId )
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void deleteArtifact( ArchivaArtifact artifact )
- throws ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
-
- }
-
- public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
- String type, String repositoryId )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List<ArchivaArtifact> queryArtifacts( Constraint constraint )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- return artifacts;
- }
-
- public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
- throws ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void setArtifacts( List<ArchivaArtifact> artifacts )
- {
- this.artifacts = artifacts;
- }
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java
index 1480645b8..8135fbce3 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/rss/RssFeedServlet.java
@@ -25,18 +25,20 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedOutput;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
import org.apache.archiva.rss.processor.RssFeedProcessor;
import org.apache.commons.codec.Decoder;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.maven.archiva.security.ArchivaSecurityException;
@@ -59,10 +61,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.io.FeedException;
-import com.sun.syndication.io.SyndFeedOutput;
-
/**
* Servlet for handling rss feed requests.
*
@@ -146,6 +144,7 @@ public class RssFeedServlet
}
else if ( ( groupId != null ) && ( artifactId != null ) )
{
+ // TODO: this only works for guest - we could pass in the list of repos
// new versions of artifact feed request
processor =
(RssFeedProcessor) wac.getBean( PlexusToSpringUtils.buildSpringId(
@@ -182,11 +181,6 @@ public class RssFeedServlet
SyndFeedOutput output = new SyndFeedOutput();
output.output( feed, res.getWriter() );
}
- catch ( ArchivaDatabaseException e )
- {
- log.debug( COULD_NOT_GENERATE_FEED_ERROR, e );
- res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR );
- }
catch ( UserNotFoundException unfe )
{
log.debug( COULD_NOT_AUTHENTICATE_USER, unfe );
@@ -224,6 +218,11 @@ public class RssFeedServlet
res.sendError( HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED );
}
+ catch ( MetadataResolverException e )
+ {
+ log.debug( COULD_NOT_GENERATE_FEED_ERROR, e );
+ res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR );
+ }
}
/**
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
new file mode 100644
index 000000000..f12ad2a83
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
@@ -0,0 +1,184 @@
+package org.apache.archiva.metadata.repository.memory;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacet;
+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.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataResolverException;
+
+public class TestMetadataRepository
+ implements MetadataRepository
+{
+ private static final String TEST_REPO = "test-repo";
+
+ private static final String TEST_NAMESPACE = "org.apache.archiva";
+
+ private List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
+
+ private List<String> versions = new ArrayList<String>();
+
+ public TestMetadataRepository()
+ {
+ Date whenGathered = new Date( 123456789 );
+
+ addArtifact( "artifact-one", "1.0", whenGathered );
+ addArtifact( "artifact-one", "1.1", whenGathered );
+ addArtifact( "artifact-one", "2.0", whenGathered );
+ addArtifact( "artifact-two", "1.0.1", whenGathered );
+ addArtifact( "artifact-two", "1.0.2", whenGathered );
+ addArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered );
+ addArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered );
+ addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
+ }
+
+ private void addArtifact( String projectId, String projectVersion, Date whenGathered )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setFileLastModified( System.currentTimeMillis() );
+ artifact.setNamespace( TEST_NAMESPACE );
+ artifact.setVersion( projectVersion );
+ artifact.setId( projectId + "-" + projectVersion + ".jar" );
+ artifact.setProject( projectId );
+ artifact.setRepositoryId( TEST_REPO );
+ artifact.setWhenGathered( whenGathered );
+ artifacts.add( artifact );
+
+ versions.add( projectVersion );
+ }
+
+ public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
+ String projectVersion )
+ throws MetadataResolverException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getRootNamespaces( String repoId )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getNamespaces( String repoId, String namespace )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getProjects( String repoId, String namespace )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+ throws MetadataResolverException
+ {
+ return versions;
+ }
+
+ public void updateProject( String repoId, ProjectMetadata project )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
+ ArtifactMetadata artifactMeta )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateProjectVersion( String repoId, String namespace, String projectId,
+ ProjectVersionMetadata versionMetadata )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateProjectReference( String repoId, String namespace, String projectId, String projectVersion,
+ ProjectVersionReference reference )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateNamespace( String repoId, String namespace )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<String> getMetadataFacets( String repodId, String facetId )
+ {
+ return Collections.emptyList();
+ }
+
+ public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addMetadataFacet( String repositoryId, String facetId, String name, MetadataFacet metadataFacet )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeMetadataFacets( String repositoryId, String facetId )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
+ {
+ return artifacts;
+ }
+
+ public Collection<String> getRepositories()
+ {
+ return Collections.singletonList( TEST_REPO );
+ }
+
+ public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ return artifacts;
+ }
+} \ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java
deleted file mode 100644
index 3a4f66c84..000000000
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.apache.maven.archiva.web.rss;
-
-/*
- * 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.
- */
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ArtifactDAO;
-import org.apache.maven.archiva.database.Constraint;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.model.ArchivaArtifact;
-
-/**
- * Stub used for RssFeedServlet unit test.
- *
- * @version
- */
-public class ArtifactDAOStub
- implements ArtifactDAO
-{
-
- public ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String classifier,
- String type, String repositoryId )
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void deleteArtifact( ArchivaArtifact artifact )
- throws ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
-
- }
-
- public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier,
- String type, String repositoryId )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List<ArchivaArtifact> queryArtifacts( Constraint constraint )
- throws ObjectNotFoundException, ArchivaDatabaseException
- {
- List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
-
- Date whenGathered = Calendar.getInstance().getTime();
- whenGathered.setTime( 123456789 );
-
- ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.0", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "1.1", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-one", "2.0", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.1", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.2", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-two", "1.0.3-SNAPSHOT", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-three", "2.0-SNAPSHOT", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- artifact = new ArchivaArtifact( "org.apache.archiva", "artifact-four", "1.1-beta-2", "", "jar", "test-repo" );
- artifact.getModel().setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- return artifacts;
- }
-
- public ArchivaArtifact saveArtifact( ArchivaArtifact artifact )
- throws ArchivaDatabaseException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java
index b45e1ca92..3bb93c7f5 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/RssFeedServletTest.java
@@ -21,23 +21,17 @@ package org.apache.maven.archiva.web.rss;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.codec.Encoder;
-import org.apache.commons.codec.binary.Base64;
-import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-
-import sun.misc.BASE64Encoder;
-
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HttpException;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
+import org.apache.commons.codec.Encoder;
+import org.apache.commons.codec.binary.Base64;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import sun.misc.BASE64Encoder;
-/**
- *
- * @version
- */
public class RssFeedServletTest
extends PlexusInSpringTestCase
{
@@ -68,45 +62,43 @@ public class RssFeedServletTest
assertNotNull( servlet );
WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/test-repo" );
-
+
BASE64Encoder encoder = new BASE64Encoder();
String userPass = "user1:password1";
- String encodedUserPass = encoder.encode( userPass.getBytes() );
+ String encodedUserPass = encoder.encode( userPass.getBytes() );
request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
+
WebResponse response = client.getResponse( request );
assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
assertNotNull( "Should have recieved a response", response );
assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
}
-
+
public void testRequestNewVersionsOfArtifact()
throws Exception
{
- RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation(
- "http://localhost/feeds/org/apache/archiva/artifact-two" ).getServlet();
+ RssFeedServlet servlet = (RssFeedServlet) client.newInvocation(
+ "http://localhost/feeds/org/apache/archiva/artifact-two" ).getServlet();
assertNotNull( servlet );
WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/org/apache/archiva/artifact-two" );
-
+
BASE64Encoder encoder = new BASE64Encoder();
String userPass = "user1:password1";
- String encodedUserPass = encoder.encode( userPass.getBytes() );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
- WebResponse response = client.getResponse( request );
+ String encodedUserPass = encoder.encode( userPass.getBytes() );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
+ WebResponse response = client.getResponse( request );
assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
assertNotNull( "Should have recieved a response", response );
- assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
+ assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
}
-
+
public void XXX_testInvalidRequest()
throws Exception
{
RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation(
- "http://localhost/feeds?invalid_param=xxx" ).getServlet();
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds?invalid_param=xxx" ).getServlet();
assertNotNull( servlet );
try
@@ -116,64 +108,63 @@ public class RssFeedServletTest
}
catch ( HttpException he )
{
- assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST, he.getResponseCode() );
- }
+ assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST,
+ he.getResponseCode() );
+ }
}
-
+
public void XXX_testInvalidAuthenticationRequest()
throws Exception
{
RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation(
- "http://localhost/feeds/unauthorized-repo" ).getServlet();
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds/unauthorized-repo" ).getServlet();
assertNotNull( servlet );
-
-
+
WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/unauthorized-repo" );
-
+
Encoder encoder = new Base64();
String userPass = "unauthUser:unauthPass";
- String encodedUserPass = new String( ( byte[] ) encoder.encode( userPass.getBytes() ) );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
+ String encodedUserPass = new String( (byte[]) encoder.encode( userPass.getBytes() ) );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
try
{
WebResponse resp = client.getResponse( request );
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, resp.getResponseCode() );
}
catch ( HttpException he )
- {
- assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED, he.getResponseCode() );
+ {
+ assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED,
+ he.getResponseCode() );
}
}
-
+
public void XXX_testUnauthorizedRequest()
throws Exception
{
RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation(
- "http://localhost/feeds/unauthorized-repo" ).getServlet();
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds/unauthorized-repo" ).getServlet();
assertNotNull( servlet );
-
-
+
WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/unauthorized-repo" );
-
+
BASE64Encoder encoder = new BASE64Encoder();
String userPass = "user1:password1";
- String encodedUserPass = encoder.encode( userPass.getBytes() );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
+ String encodedUserPass = encoder.encode( userPass.getBytes() );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
try
{
WebResponse resp = client.getResponse( request );
assertEquals( HttpServletResponse.SC_UNAUTHORIZED, resp.getResponseCode() );
}
catch ( HttpException he )
- {
- assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED, he.getResponseCode() );
+ {
+ assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED,
+ he.getResponseCode() );
}
- }
-
+ }
+
@Override
protected String getPlexusConfigLocation()
{
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml
index 0fec42f00..8e0467c9c 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/rss/RssFeedServletTest.xml
@@ -21,11 +21,10 @@
<plexus>
<components>
<component>
- <role>org.apache.maven.archiva.database.ArtifactDAO</role>
- <role-hint>jdo</role-hint>
- <implementation>org.apache.maven.archiva.web.rss.ArtifactDAOStub</implementation>
+ <role>org.apache.archiva.metadata.repository.MetadataRepository</role>
+ <implementation>org.apache.archiva.metadata.repository.memory.TestMetadataRepository</implementation>
</component>
-
+
<component>
<role>org.codehaus.plexus.redback.system.SecuritySystem</role>
<role-hint>default</role-hint>
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
index 5cd2ef472..99571538b 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java
@@ -21,6 +21,7 @@ package org.apache.archiva.metadata.repository;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -88,7 +89,8 @@ public class TestMetadataRepository
//To change body of implemented methods use File | Settings | File Templates.
}
- public void updateProjectVersion( String repoId, String namespace, String projectId, ProjectVersionMetadata versionMetadata )
+ public void updateProjectVersion( String repoId, String namespace, String projectId,
+ ProjectVersionMetadata versionMetadata )
{
//To change body of implemented methods use File | Settings | File Templates.
}
@@ -123,4 +125,20 @@ public class TestMetadataRepository
{
//To change body of implemented methods use File | Settings | File Templates.
}
+
+ public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Collection<String> getRepositories()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
}
diff --git a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java
index 0cf4fda3c..aee6c4b6b 100644
--- a/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java
+++ b/archiva-modules/metadata/metadata-model/src/main/java/org/apache/archiva/metadata/model/ArtifactMetadata.java
@@ -37,6 +37,12 @@ public class ArtifactMetadata
private String sha1;
+ private String namespace;
+
+ private String project;
+
+ private String repositoryId;
+
public String getId()
{
return id;
@@ -107,4 +113,101 @@ public class ArtifactMetadata
return fileLastModified;
}
+
+ public String getNamespace()
+ {
+ return namespace;
+ }
+
+ public void setNamespace( String namespace )
+ {
+ this.namespace = namespace;
+ }
+
+ public void setProject( String project )
+ {
+ this.project = project;
+ }
+
+ public String getProject()
+ {
+ return project;
+ }
+
+ public String getRepositoryId()
+ {
+ return repositoryId;
+ }
+
+ public void setRepositoryId( String repositoryId )
+ {
+ this.repositoryId = repositoryId;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ ArtifactMetadata that = (ArtifactMetadata) o;
+
+ if ( size != that.size )
+ {
+ return false;
+ }
+ if ( !fileLastModified.equals( that.fileLastModified ) )
+ {
+ return false;
+ }
+ if ( !id.equals( that.id ) )
+ {
+ return false;
+ }
+ if ( md5 != null ? !md5.equals( that.md5 ) : that.md5 != null )
+ {
+ return false;
+ }
+ if ( namespace != null ? !namespace.equals( that.namespace ) : that.namespace != null )
+ {
+ return false;
+ }
+ if ( project != null ? !project.equals( that.project ) : that.project != null )
+ {
+ return false;
+ }
+ if ( repositoryId != null ? !repositoryId.equals( that.repositoryId ) : that.repositoryId != null )
+ {
+ return false;
+ }
+ if ( sha1 != null ? !sha1.equals( that.sha1 ) : that.sha1 != null )
+ {
+ return false;
+ }
+ if ( !version.equals( that.version ) )
+ {
+ return false;
+ }
+ if ( !whenGathered.equals( that.whenGathered ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ArtifactMetadata{" + "id='" + id + '\'' + ", size=" + size + ", version='" + version + '\'' +
+ ", fileLastModified=" + fileLastModified + ", whenGathered=" + whenGathered + ", md5='" + md5 + '\'' +
+ ", sha1='" + sha1 + '\'' + ", namespace='" + namespace + '\'' + ", project='" + project + '\'' +
+ ", repositoryId='" + repositoryId + '\'' + '}';
+ }
}
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
index bc87cdbeb..6aeb13515 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
@@ -19,6 +19,8 @@ package org.apache.archiva.metadata.repository;
* under the License.
*/
+import java.util.Collection;
+import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
@@ -33,7 +35,7 @@ public interface MetadataRepository
/**
* Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
*
- * @param repoId the repository the project is in
+ * @param repoId the repository the project is in
* @param project the project metadata to create or update
*/
void updateProject( String repoId, ProjectMetadata project );
@@ -56,4 +58,11 @@ public interface MetadataRepository
void addMetadataFacet( String repositoryId, String facetId, String name, MetadataFacet metadataFacet );
void removeMetadataFacets( String repositoryId, String facetId );
+
+ List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime );
+
+ Collection<String> getRepositories();
+
+ public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+ String projectVersion );
}
diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
index 110790af3..ad9f18673 100644
--- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
+++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
@@ -28,12 +28,14 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.StringTokenizer;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.CiManagement;
@@ -310,6 +312,111 @@ public class FileMetadataRepository
}
}
+ public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
+ {
+ // TODO: this is quite slow - if we are to persist with this repository implementation we should build an index
+ // of this information (eg. in Lucene, as before)
+
+ List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
+ for ( String ns : getRootNamespaces( repoId ) )
+ {
+ getArtifactsByDateRange( artifacts, repoId, ns, startTime, endTime );
+ }
+ return artifacts;
+ }
+
+ private void getArtifactsByDateRange( List<ArtifactMetadata> artifacts, String repoId, String ns, Date startTime,
+ Date endTime )
+ {
+ for ( String namespace : getNamespaces( repoId, ns ) )
+ {
+ getArtifactsByDateRange( artifacts, repoId, ns + "." + namespace, startTime, endTime );
+ }
+
+ for ( String project : getProjects( repoId, ns ) )
+ {
+ for ( String version : getProjectVersions( repoId, ns, project ) )
+ {
+ for ( ArtifactMetadata artifact : getArtifacts( repoId, ns, project, version ) )
+ {
+ if ( startTime == null || startTime.before( artifact.getWhenGathered() ) )
+ {
+ if ( endTime == null || endTime.after( artifact.getWhenGathered() ) )
+ {
+ artifacts.add( artifact );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ Map<String, ArtifactMetadata> artifacts = new HashMap<String, ArtifactMetadata>();
+
+ File directory = new File( this.directory, repoId + "/" + namespace + "/" + projectId + "/" + projectVersion );
+
+ Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
+
+ for ( Map.Entry entry : properties.entrySet() )
+ {
+ String name = (String) entry.getKey();
+ StringTokenizer tok = new StringTokenizer( name, ":" );
+ if ( tok.hasMoreTokens() && "artifact".equals( tok.nextToken() ) )
+ {
+ String field = tok.nextToken();
+ String id = tok.nextToken();
+
+ ArtifactMetadata artifact = artifacts.get( id );
+ if ( artifact == null )
+ {
+ artifact = new ArtifactMetadata();
+ artifact.setRepositoryId( repoId );
+ artifact.setNamespace( namespace );
+ artifact.setProject( projectId );
+ artifact.setVersion( projectVersion );
+ artifact.setId( id );
+ artifacts.put( id, artifact );
+ }
+
+ String value = (String) entry.getValue();
+ if ( "updated".equals( field ) )
+ {
+ artifact.setFileLastModified( Long.valueOf( value ) );
+ }
+ else if ( "size".equals( field ) )
+ {
+ artifact.setSize( Long.valueOf( value ) );
+ }
+ else if ( "whenGathered".equals( field ) )
+ {
+ artifact.setWhenGathered( new Date( Long.valueOf( value ) ) );
+ }
+ else if ( "version".equals( field ) )
+ {
+ artifact.setVersion( value );
+ }
+ else if ( "md5".equals( field ) )
+ {
+ artifact.setMd5( value );
+ }
+ else if ( "sha1".equals( field ) )
+ {
+ artifact.setSha1( value );
+ }
+ }
+ }
+ return artifacts.values();
+ }
+
+ public Collection<String> getRepositories()
+ {
+ String[] repoIds = this.directory.list();
+ return repoIds != null ? Arrays.asList( repoIds ) : Collections.<String>emptyList();
+ }
+
private File getMetadataDirectory( String repositoryId, String facetId )
{
return new File( this.directory, repositoryId + "/.meta/" + facetId );
@@ -350,8 +457,14 @@ public class FileMetadataRepository
properties.setProperty( "artifact:whenGathered:" + artifact.getId(),
Long.toString( artifact.getWhenGathered().getTime() ) );
properties.setProperty( "artifact:size:" + artifact.getId(), Long.toString( artifact.getSize() ) );
- properties.setProperty( "artifact:md5:" + artifact.getId(), artifact.getMd5() );
- properties.setProperty( "artifact:sha1:" + artifact.getId(), artifact.getMd5() );
+ if ( artifact.getMd5() != null )
+ {
+ properties.setProperty( "artifact:md5:" + artifact.getId(), artifact.getMd5() );
+ }
+ if ( artifact.getSha1() != null )
+ {
+ properties.setProperty( "artifact:sha1:" + artifact.getId(), artifact.getSha1() );
+ }
properties.setProperty( "artifact:version:" + artifact.getId(), artifact.getVersion() );
try
diff --git a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
index 489f38b66..4df2e4173 100644
--- a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
+++ b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java
@@ -20,14 +20,19 @@ package org.apache.archiva.metadata.repository.file;
*/
import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import java.util.Map;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.model.MailingList;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.model.MetadataFacetFactory;
+import org.apache.archiva.metadata.model.ProjectMetadata;
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.commons.io.FileUtils;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
@@ -53,6 +58,8 @@ public class FileMetadataRepositoryTest
private static final String UNKNOWN = "unknown";
+ private static final String OTHER_REPO = "other-repo";
+
public void setUp()
throws Exception
{
@@ -189,6 +196,154 @@ public class FileMetadataRepositoryTest
repository.removeMetadataFacets( TEST_REPO_ID, UNKNOWN );
}
+ public void testGetArtifacts()
+ {
+ ArtifactMetadata artifact1 = createArtifact();
+ ArtifactMetadata artifact2 = createArtifact( "pom" );
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
+
+ assertEquals( Arrays.asList( artifact2, artifact1 ), new ArrayList<ArtifactMetadata>(
+ repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) );
+ }
+
+ public void testRepositories()
+ {
+ repository.addMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) );
+ repository.addMetadataFacet( OTHER_REPO, TEST_FACET_ID, TEST_NAME, new TestMetadataFacet( TEST_VALUE ) );
+
+ assertEquals( Arrays.asList( OTHER_REPO, TEST_REPO_ID ), repository.getRepositories() );
+ }
+
+ public void testRepositoriesWhenEmpty()
+ {
+ assertTrue( repository.getRepositories().isEmpty() );
+ }
+
+ public void testGetArtifactsByDateRangeOpen()
+ {
+ repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
+ repository.updateProject( TEST_REPO_ID, createProject() );
+ ArtifactMetadata artifact = createArtifact();
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ assertEquals( Collections.singletonList( artifact ),
+ repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
+ }
+
+ public void testGetArtifactsByDateRangeSparseNamespace()
+ {
+ String namespace = "org.apache.archiva";
+ repository.updateNamespace( TEST_REPO_ID, namespace );
+ repository.updateProject( TEST_REPO_ID, createProject( namespace ) );
+ ArtifactMetadata artifact = createArtifact();
+ artifact.setNamespace( namespace );
+ repository.updateArtifact( TEST_REPO_ID, namespace, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ assertEquals( Collections.singletonList( artifact ),
+ repository.getArtifactsByDateRange( TEST_REPO_ID, null, null ) );
+ }
+
+ public void testGetArtifactsByDateRangeLowerBound()
+ {
+ repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
+ repository.updateProject( TEST_REPO_ID, createProject() );
+ ArtifactMetadata artifact = createArtifact();
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ Date date = new Date( artifact.getWhenGathered().getTime() - 10000 );
+ assertEquals( Collections.singletonList( artifact ),
+ repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ) );
+ }
+
+ public void testGetArtifactsByDateRangeLowerBoundOutOfRange()
+ {
+ repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
+ repository.updateProject( TEST_REPO_ID, createProject() );
+ ArtifactMetadata artifact = createArtifact();
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ Date date = new Date( artifact.getWhenGathered().getTime() + 10000 );
+ assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, date, null ).isEmpty() );
+ }
+
+ public void testGetArtifactsByDateRangeLowerAndUpperBound()
+ {
+ repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
+ repository.updateProject( TEST_REPO_ID, createProject() );
+ ArtifactMetadata artifact = createArtifact();
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ Date lower = new Date( artifact.getWhenGathered().getTime() - 10000 );
+ Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
+ assertEquals( Collections.singletonList( artifact ),
+ repository.getArtifactsByDateRange( TEST_REPO_ID, lower, upper ) );
+ }
+
+ public void testGetArtifactsByDateRangeUpperBound()
+ {
+ repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
+ repository.updateProject( TEST_REPO_ID, createProject() );
+ ArtifactMetadata artifact = createArtifact();
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ Date upper = new Date( artifact.getWhenGathered().getTime() + 10000 );
+ assertEquals( Collections.singletonList( artifact ),
+ repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ) );
+ }
+
+ public void testGetArtifactsByDateRangeUpperBoundOutOfRange()
+ {
+ repository.updateNamespace( TEST_REPO_ID, TEST_NAMESPACE );
+ repository.updateProject( TEST_REPO_ID, createProject() );
+ ArtifactMetadata artifact = createArtifact();
+ repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
+
+ Date upper = new Date( artifact.getWhenGathered().getTime() - 10000 );
+ assertTrue( repository.getArtifactsByDateRange( TEST_REPO_ID, null, upper ).isEmpty() );
+ }
+
+ public void testGetNamespacesWithSparseDepth()
+ {
+ repository.updateNamespace( TEST_REPO_ID, "org.apache.maven.shared" );
+
+ assertEquals( Arrays.asList( "org" ), repository.getRootNamespaces( TEST_REPO_ID ) );
+ assertEquals( Arrays.asList( "apache" ), repository.getNamespaces( TEST_REPO_ID, "org" ) );
+ assertEquals( Arrays.asList( "maven" ), repository.getNamespaces( TEST_REPO_ID, "org.apache" ) );
+ assertEquals( Arrays.asList( "shared" ), repository.getNamespaces( TEST_REPO_ID, "org.apache.maven" ) );
+ }
+
+ private ProjectMetadata createProject()
+ {
+ return createProject( TEST_NAMESPACE );
+ }
+
+ private ProjectMetadata createProject( String ns )
+ {
+ ProjectMetadata project = new ProjectMetadata();
+ project.setId( TEST_PROJECT );
+ project.setNamespace( ns );
+ return project;
+ }
+
+ private ArtifactMetadata createArtifact()
+ {
+ return createArtifact( "jar" );
+ }
+
+ private ArtifactMetadata createArtifact( String type )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "." + type );
+ artifact.setWhenGathered( new Date() );
+ artifact.setNamespace( TEST_NAMESPACE );
+ artifact.setProject( TEST_PROJECT );
+ artifact.setRepositoryId( TEST_REPO_ID );
+ artifact.setFileLastModified( System.currentTimeMillis() );
+ artifact.setVersion( TEST_PROJECT_VERSION );
+ return artifact;
+ }
+
private static class TestMetadataFacet
implements MetadataFacet
{