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() );
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
//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.
}
{
//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.
+ }
}
</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>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>jcl-over-slf4j</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
* 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;
+ }
}
* 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;
* 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
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." );
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 );
this.generator = generator;
}
- public ArtifactDAO getArtifactDAO()
- {
- return artifactDAO;
- }
-
- public void setArtifactDAO( ArtifactDAO artifactDAO )
- {
- this.artifactDAO = artifactDAO;
- }
-
public int getNumberOfDaysBeforeNow()
{
return numberOfDaysBeforeNow;
{
this.numberOfDaysBeforeNow = numberOfDaysBeforeNow;
}
-
}
* 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
*/
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()
{
this.generator = generator;
}
-
- public ArtifactDAO getArtifactDAO()
- {
- return artifactDAO;
- }
-
- public void setArtifactDAO( ArtifactDAO artifactDAO )
- {
- this.artifactDAO = artifactDAO;
- }
-
}
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
{
public static final String KEY_ARTIFACT_ID = "artifactId";
- SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException;
+ SyndFeed process( Map<String, String> reqParams )
+ throws MetadataResolverException;
}
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
{
private NewArtifactsRssFeedProcessor newArtifactsProcessor;
- private ArtifactDAOStub artifactDAOStub;
+ private MetadataRepository metadataRepository;
- private RssFeedGenerator rssFeedGenerator;
+ private MockControl metadataRepositoryControl;
@Override
public void setUp()
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;
}
}
* 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()
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;
}
}
+++ /dev/null
-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;
- }
-}
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;
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.
*
}
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(
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 );
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 );
+ }
}
/**
--- /dev/null
+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
+++ /dev/null
-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;
- }
-
-}
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
{
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
}
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()
{
<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>
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
//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.
}
{
//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.
+ }
}
private String sha1;
+ private String namespace;
+
+ private String project;
+
+ private String repositoryId;
+
public String getId()
{
return id;
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 + '\'' + '}';
+ }
}
* under the License.
*/
+import java.util.Collection;
+import java.util.Date;
import java.util.List;
import org.apache.archiva.metadata.model.ArtifactMetadata;
/**
* 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 );
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 );
}
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;
}
}
+ 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 );
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
*/
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;
private static final String UNKNOWN = "unknown";
+ private static final String OTHER_REPO = "other-repo";
+
public void setUp()
throws Exception
{
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
{