private RepositoryConverter repositoryConverter;
/**
- * @plexus.requirement role-hint="default"
+ * @plexus.requirement
*/
private ArtifactReporter reporter;
* failures and successes for checking assertions. Later, implementations will be made to present reports on the
* web interface, send them via mail, and so on.
*
- * @todo i18n
+ * @todo i18n, including message formatting and parameterisation
+ * @todo remove no longer used reports!
*/
public interface ArtifactReporter
{
String ROLE = ArtifactReporter.class.getName();
- String NULL_MODEL = "Provided model was null";
-
- String NULL_ARTIFACT = "Provided artifact was null";
-
- String EMPTY_GROUP_ID = "Group id was empty or null";
-
- String EMPTY_ARTIFACT_ID = "Artifact id was empty or null";
-
- String EMPTY_VERSION = "Version was empty or null";
-
- String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null";
-
- String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null";
-
- String EMPTY_DEPENDENCY_VERSION = "Version was empty or null";
-
- String NO_DEPENDENCIES = "Artifact has no dependencies";
-
String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository";
String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository";
+ String DEPENDENCY_INVALID_VERSION = "Artifact's dependency contains an invalid version";
+
void addFailure( Artifact artifact, String reason );
void addSuccess( Artifact artifact );
boolean hasFailures = false;
Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
- String timestamp = snapshot.getTimestamp();
- String buildNumber = String.valueOf( snapshot.getBuildNumber() );
- Artifact artifact = createArtifact( metadata );
- if ( !repositoryQueryLayer.containsArtifact( artifact, snapshot ) )
+ String version = metadata.getBaseVersion().replace( Artifact.SNAPSHOT_VERSION,
+ snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
+ Artifact artifact =
+ artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
+ artifact.isSnapshot(); // trigger baseVersion correction
+
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
- reporter.addFailure( metadata, "Snapshot artifact " + timestamp + "-" + buildNumber + " does not exist." );
+ reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
hasFailures = true;
}
{
String version = (String) versions.next();
- Artifact artifact = createArtifact( metadata, version );
+ Artifact artifact =
+ artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
{
return hasFailures;
}
- /**
- * Used to create an artifact object from a metadata base version
- */
- private Artifact createArtifact( RepositoryMetadata metadata )
- {
- return artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(),
- metadata.getBaseVersion() );
- }
-
- /**
- * Used to create an artifact object with a specified version
- */
- private Artifact createArtifact( RepositoryMetadata metadata, String version )
+ private Artifact createArtifact( RepositoryMetadata metadata, Snapshot snapshot )
{
+ String version = metadata.getBaseVersion();
return artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
}
*/
import org.apache.maven.archiva.layer.RepositoryQueryLayer;
+import org.apache.maven.archiva.layer.RepositoryQueryLayerFactory;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
public class DefaultArtifactReportProcessor
implements ArtifactReportProcessor
{
- private static final String EMPTY_STRING = "";
-
- // plexus components
+ /**
+ * @plexus.requirement
+ */
private ArtifactFactory artifactFactory;
- private RepositoryQueryLayer repositoryQueryLayer;
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryQueryLayerFactory layerFactory;
public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
ArtifactRepository repository )
{
- if ( artifact == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.NULL_ARTIFACT );
- }
- else
- {
- processArtifact( artifact, reporter );
- }
+ RepositoryQueryLayer queryLayer = layerFactory.createRepositoryQueryLayer( repository );
+ processArtifact( artifact, reporter, queryLayer );
- if ( model == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.NULL_MODEL );
- }
- else
- {
- List dependencies = model.getDependencies();
- processDependencies( dependencies, reporter );
- }
+ List dependencies = model.getDependencies();
+ processDependencies( dependencies, reporter, queryLayer );
}
- private void processArtifact( Artifact artifact, ArtifactReporter reporter )
+ private void processArtifact( Artifact artifact, ArtifactReporter reporter,
+ RepositoryQueryLayer repositoryQueryLayer )
{
- boolean hasFailed = false;
- if ( EMPTY_STRING.equals( artifact.getGroupId() ) || artifact.getGroupId() == null )
+ if ( repositoryQueryLayer.containsArtifact( artifact ) )
{
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_GROUP_ID );
- hasFailed = true;
+ reporter.addSuccess( artifact );
}
- if ( EMPTY_STRING.equals( artifact.getArtifactId() ) || artifact.getArtifactId() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_ARTIFACT_ID );
- hasFailed = true;
- }
- if ( EMPTY_STRING.equals( artifact.getVersion() ) || artifact.getVersion() == null )
+ else
{
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_VERSION );
- hasFailed = true;
- }
- if ( !hasFailed )
- {
- if ( repositoryQueryLayer.containsArtifact( artifact ) )
- {
- reporter.addSuccess( artifact );
- }
- else
- {
- reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
- }
+ reporter.addFailure( artifact, ArtifactReporter.ARTIFACT_NOT_FOUND );
}
}
- private void processDependencies( List dependencies, ArtifactReporter reporter )
+ private void processDependencies( List dependencies, ArtifactReporter reporter,
+ RepositoryQueryLayer repositoryQueryLayer )
{
if ( dependencies.size() > 0 )
{
Iterator iterator = dependencies.iterator();
while ( iterator.hasNext() )
{
- boolean hasFailed = false;
Dependency dependency = (Dependency) iterator.next();
- Artifact artifact = createArtifact( dependency );
- if ( EMPTY_STRING.equals( dependency.getGroupId() ) || dependency.getGroupId() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID );
- hasFailed = true;
- }
- if ( EMPTY_STRING.equals( dependency.getArtifactId() ) || dependency.getArtifactId() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID );
- hasFailed = true;
- }
- if ( EMPTY_STRING.equals( dependency.getVersion() ) || dependency.getVersion() == null )
- {
- reporter.addFailure( artifact, ArtifactReporter.EMPTY_DEPENDENCY_VERSION );
- hasFailed = true;
- }
- if ( !hasFailed )
+
+ Artifact artifact = null;
+ try
{
+ artifact = createArtifact( dependency );
+
if ( repositoryQueryLayer.containsArtifact( artifact ) )
{
reporter.addSuccess( artifact );
reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_NOT_FOUND );
}
}
+ catch ( InvalidVersionSpecificationException e )
+ {
+ reporter.addFailure( artifact, ArtifactReporter.DEPENDENCY_INVALID_VERSION );
+ }
}
}
-
- }
-
- /**
- * Only used for passing a mock object when unit testing
- *
- * @param repositoryQueryLayer
- */
- protected void setRepositoryQueryLayer( RepositoryQueryLayer repositoryQueryLayer )
- {
- this.repositoryQueryLayer = repositoryQueryLayer;
- }
-
- /**
- * Only used for passing a mock object when unit testing
- *
- * @param artifactFactory
- */
- protected void setArtifactFactory( ArtifactFactory artifactFactory )
- {
- this.artifactFactory = artifactFactory;
}
private Artifact createArtifact( Dependency dependency )
+ throws InvalidVersionSpecificationException
{
- return artifactFactory.createBuildArtifact( dependency.getGroupId(), dependency.getArtifactId(),
- dependency.getVersion(), "pom" );
+ return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
+ VersionRange.createFromVersionSpec( dependency.getVersion() ),
+ dependency.getType(), dependency.getClassifier(),
+ dependency.getScope() );
}
}
import java.util.List;
/**
- * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReporter" role-hint="default"
+ * @plexus.component role="org.apache.maven.archiva.reporting.ArtifactReporter"
*/
public class DefaultArtifactReporter
implements ArtifactReporter
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.archiva.layer.CachedRepositoryQueryLayer;
-import org.apache.maven.archiva.layer.RepositoryQueryLayerException;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-import org.codehaus.plexus.PlexusTestCase;
-
-import java.io.File;
-import java.util.List;
-
-/**
- *
- */
-public abstract class AbstractRepositoryQueryLayerTestCase
- extends PlexusTestCase
-{
- private ArtifactFactory artifactFactory;
-
- protected ArtifactRepository repository;
-
- protected CachedRepositoryQueryLayer queryLayer;
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
- File repositoryDirectory = getTestFile( "src/test/repository" );
-
- artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
- ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
- ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
-
- repository =
- factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
- }
-
- public void testContainsArtifactTrue()
- {
- Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
-
- assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
- }
-
- public void testContainsArtifactFalse()
- {
- Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
-
- assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
- }
-
- public void testContainsSnapshotArtifactTrue()
- {
- Snapshot snapshot = new Snapshot();
- snapshot.setTimestamp( "20050611.202024" );
- snapshot.setBuildNumber( 1 );
-
- Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
- assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
- }
-
- public void testContainsSnapshotArtifactFalse()
- {
- Snapshot snapshot = new Snapshot();
- snapshot.setTimestamp( "20050611.202024" );
- snapshot.setBuildNumber( 2 );
-
- Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" );
- assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) );
- }
-
- public void testArtifactVersionsTrue()
- throws Exception
- {
- Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
-
- List versions = queryLayer.getVersions( artifact );
-
- assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
- assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
- assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
- }
-
- public void testArtifactVersionsFalse()
- throws Exception
- {
- Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
-
- List versions = queryLayer.getVersions( artifact );
-
- assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
- assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
- assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) );
- }
-
- public void testArtifactVersionsError()
- {
- Artifact artifact = getArtifact( "groupId", "none", "ignored" );
-
- try
- {
- queryLayer.getVersions( artifact );
- fail( "expected error not thrown" );
- }
- catch ( RepositoryQueryLayerException e )
- {
- //expected
- }
- }
-
- private Artifact getArtifact( String groupId, String artifactId, String version )
- {
- return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" );
- }
-
- protected void tearDown()
- throws Exception
- {
- release( artifactFactory );
- super.tearDown();
- artifactFactory = null;
- repository = null;
- }
-}
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
public class ArtifactReportProcessorTest
extends AbstractRepositoryReportsTestCase
{
- private static final String EMPTY_STRING = "";
+ private static final String VALID_GROUP_ID = "groupId";
- private static final String VALID = "temp";
+ private static final String VALID_ARTIFACT_ID = "artifactId";
- private ArtifactReporter reporter;
+ private static final String VALID_VERSION = "1.0-alpha-1";
- private Artifact artifact;
+ private ArtifactReporter reporter;
private Model model;
- private DefaultArtifactReportProcessor processor;
+ private ArtifactReportProcessor processor;
- private static final boolean ARTIFACT_FOUND = true;
+ private ArtifactFactory artifactFactory;
- private static final boolean ARTIFACT_NOT_FOUND = false;
+ private static final String INVALID = "invalid";
protected void setUp()
throws Exception
{
super.setUp();
- reporter = new DefaultArtifactReporter();
- artifact = new MockArtifact();
+ reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
model = new Model();
- processor = new DefaultArtifactReportProcessor();
- }
+ processor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "default" );
- public void testNullArtifact()
- {
- processor.processArtifact( model, null, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.NULL_ARTIFACT, result.getReason() );
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
}
- public void testNoProjectDescriptor()
+ public void testArtifactFoundButNoDirectDependencies()
+ throws ReportProcessorException
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.processArtifact( null, artifact, reporter, null );
+ Artifact artifact = createValidArtifact();
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
+ assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.NULL_MODEL, result.getReason() );
}
- public void testArtifactFoundButNoDirectDependencies()
+ private Artifact createValidArtifact()
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 0, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
+ return artifactFactory.createProjectArtifact( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
}
public void testArtifactNotFound()
+ throws ReportProcessorException
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_NOT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
+ Artifact artifact = artifactFactory.createProjectArtifact( INVALID, INVALID, INVALID );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 0, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithNullDependency()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 2, reporter.getNumSuccesses() );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
- public void testValidArtifactWithValidSingleDependency()
+ private Dependency createValidDependency()
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ return createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, VALID_VERSION );
+ }
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
+ public void testValidArtifactWithValidSingleDependency()
+ throws ReportProcessorException
+ {
+ Artifact artifact = createValidArtifact();
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 2, reporter.getNumSuccesses() );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithValidMultipleDependencies()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
-
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ Artifact artifact = createValidArtifact();
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 6, reporter.getNumSuccesses() );
assertEquals( 0, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
}
public void testValidArtifactWithAnInvalidDependency()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
-
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, VALID );
- model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
+ Dependency dependency = createValidDependency();
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_NOT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
+ model.addDependency( createDependency( INVALID, INVALID, INVALID ) );
- setRequiredElements( artifact, VALID, VALID, VALID );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ Artifact artifact = createValidArtifact();
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 5, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testEmptyGroupId()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, EMPTY_STRING, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
- }
-
- public void testEmptyArtifactId()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, VALID, EMPTY_STRING, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
- }
-
- public void testEmptyVersion()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, VALID, VALID, EMPTY_STRING );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
- }
-
- public void testNullGroupId()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, null, VALID, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
- }
-
- public void testNullArtifactId()
+ public void testValidArtifactWithInvalidDependencyGroupId()
+ throws ReportProcessorException
{
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, VALID, null, VALID );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
- }
+ Artifact artifact = createValidArtifact();
- public void testNullVersion()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
+ Dependency dependency = createDependency( INVALID, VALID_ARTIFACT_ID, VALID_VERSION );
+ model.addDependency( dependency );
- setRequiredElements( artifact, VALID, VALID, null );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
+ processor.processArtifact( model, artifact, reporter, repository );
+ assertEquals( 1, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
- }
-
- public void testMultipleFailures()
- {
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
-
- setRequiredElements( artifact, null, null, null );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 0, reporter.getNumSuccesses() );
- assertEquals( 3, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_GROUP_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_ARTIFACT_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_VERSION, result.getReason() );
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testValidArtifactWithInvalidDependencyGroupId()
+ private Dependency createDependency( String o, String valid, String s )
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
-
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
Dependency dependency = new Dependency();
- setRequiredElements( dependency, null, VALID, VALID );
- model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
- assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 1, reporter.getNumFailures() );
- assertEquals( 0, reporter.getNumWarnings() );
-
- Iterator failures = reporter.getArtifactFailureIterator();
- ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
+ dependency.setGroupId( o );
+ dependency.setArtifactId( valid );
+ dependency.setVersion( s );
+ return dependency;
}
public void testValidArtifactWithInvalidDependencyArtifactId()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, null, VALID );
+ Dependency dependency = createDependency( VALID_GROUP_ID, INVALID, VALID_VERSION );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testValidArtifactWithInvalidDependencyVersion()
+ public void testValidArtifactWithIncorrectDependencyVersion()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, VALID, VALID, null );
+ Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, INVALID );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
+ assertEquals( ArtifactReporter.DEPENDENCY_NOT_FOUND, result.getReason() );
}
- public void testValidArtifactWithInvalidDependencyRequiredElements()
+ public void testValidArtifactWithInvalidDependencyVersion()
+ throws ReportProcessorException
{
- MockArtifactFactory artifactFactory = new MockArtifactFactory();
- processor.setArtifactFactory( artifactFactory );
+ Artifact artifact = createValidArtifact();
- setRequiredElements( artifact, VALID, VALID, VALID );
- MockRepositoryQueryLayer queryLayer = new MockRepositoryQueryLayer();
- queryLayer.addReturnValue( ARTIFACT_FOUND );
-
- Dependency dependency = new Dependency();
- setRequiredElements( dependency, null, null, null );
+ Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[" );
model.addDependency( dependency );
- queryLayer.addReturnValue( ARTIFACT_FOUND );
- processor.setRepositoryQueryLayer( queryLayer );
- processor.processArtifact( model, artifact, reporter, null );
+ processor.processArtifact( model, artifact, reporter, repository );
assertEquals( 1, reporter.getNumSuccesses() );
- assertEquals( 3, reporter.getNumFailures() );
+ assertEquals( 1, reporter.getNumFailures() );
assertEquals( 0, reporter.getNumWarnings() );
Iterator failures = reporter.getArtifactFailureIterator();
ArtifactResult result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_GROUP_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_ARTIFACT_ID, result.getReason() );
- result = (ArtifactResult) failures.next();
- assertEquals( ArtifactReporter.EMPTY_DEPENDENCY_VERSION, result.getReason() );
- }
-
- protected void tearDown()
- throws Exception
- {
- model = null;
- artifact = null;
- reporter = null;
- super.tearDown();
- }
-
- private void setRequiredElements( Artifact artifact, String groupId, String artifactId, String version )
- {
- artifact.setGroupId( groupId );
- artifact.setArtifactId( artifactId );
- artifact.setVersion( version );
- }
-
- private void setRequiredElements( Dependency dependency, String groupId, String artifactId, String version )
- {
- dependency.setGroupId( groupId );
- dependency.setArtifactId( artifactId );
- dependency.setVersion( version );
+ assertEquals( ArtifactReporter.DEPENDENCY_INVALID_VERSION, result.getReason() );
}
}
private Artifact artifact;
- private MockArtifactReportProcessor processor;
-
private Model model;
protected void setUp()
throws Exception
{
super.setUp();
- reporter = new DefaultArtifactReporter();
+ reporter = (ArtifactReporter) lookup( ArtifactReporter.ROLE );
ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
- processor = new MockArtifactReportProcessor();
Versioning versioning = new Versioning();
versioning.addVersion( "1.0-alpha-1" );
versioning.setLastUpdated( "20050611.202020" );
public void testArtifactReporterSingleSuccess()
{
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "all is good" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addSuccess( artifact );
+
+ assertEquals( 1, reporter.getNumSuccesses() );
+
Iterator success = reporter.getArtifactSuccessIterator();
assertTrue( success.hasNext() );
- assertEquals( 1, reporter.getNumSuccesses() );
Artifact result = ( (ArtifactResult) success.next() ).getArtifact();
assertEquals( "groupId", result.getGroupId() );
assertEquals( "artifactId", result.getArtifactId() );
public void testArtifactReporterMultipleSuccess()
{
- processor.clearList();
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "one" );
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "two" );
- processor.addReturnValue( ReportCondition.SUCCESS, artifact, "three" );
- reporter = new DefaultArtifactReporter();
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addSuccess( artifact );
+ reporter.addSuccess( artifact );
+ reporter.addSuccess( artifact );
Iterator success = reporter.getArtifactSuccessIterator();
assertTrue( success.hasNext() );
int i;
public void testArtifactReporterSingleFailure()
{
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addFailure( artifact, "failed once" );
Iterator failure = reporter.getArtifactFailureIterator();
assertTrue( failure.hasNext() );
failure.next();
public void testArtifactReporterMultipleFailure()
{
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addFailure( artifact, "failed once" );
+ reporter.addFailure( artifact, "failed twice" );
+ reporter.addFailure( artifact, "failed thrice" );
Iterator failure = reporter.getArtifactFailureIterator();
assertTrue( failure.hasNext() );
int i;
public void testFailureMessages()
{
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed once" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed twice" );
- processor.addReturnValue( ReportCondition.FAILURE, artifact, "failed thrice" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addFailure( artifact, "failed once" );
+ reporter.addFailure( artifact, "failed twice" );
+ reporter.addFailure( artifact, "failed thrice" );
Iterator failure = reporter.getArtifactFailureIterator();
assertEquals( "failed once", ( (ArtifactResult) failure.next() ).getReason() );
assertEquals( "failed twice", ( (ArtifactResult) failure.next() ).getReason() );
public void testArtifactReporterSingleWarning()
{
- processor.addReturnValue( ReportCondition.WARNING, artifact, "you've been warned" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addWarning( artifact, "you've been warned" );
Iterator warning = reporter.getArtifactWarningIterator();
assertTrue( warning.hasNext() );
warning.next();
public void testArtifactReporterMultipleWarning()
{
- processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addWarning( artifact, "i'm warning you" );
+ reporter.addWarning( artifact, "you have to stop now" );
+ reporter.addWarning( artifact, "all right... that does it!" );
+
Iterator warning = reporter.getArtifactWarningIterator();
assertTrue( warning.hasNext() );
int i;
public void testWarningMessages()
{
- processor.addReturnValue( ReportCondition.WARNING, artifact, "i'm warning you" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "you have to stop now" );
- processor.addReturnValue( ReportCondition.WARNING, artifact, "all right... that does it!" );
- processor.processArtifact( model, artifact, reporter, null );
+ reporter.addWarning( artifact, "i'm warning you" );
+ reporter.addWarning( artifact, "you have to stop now" );
+ reporter.addWarning( artifact, "all right... that does it!" );
+
Iterator warning = reporter.getArtifactWarningIterator();
assertEquals( "i'm warning you", ( (ArtifactResult) warning.next() ).getReason() );
assertEquals( "you have to stop now", ( (ArtifactResult) warning.next() ).getReason() );
assertEquals( "all right... that does it!", ( (ArtifactResult) warning.next() ).getReason() );
}
-
- protected void tearDown()
- throws Exception
- {
- model = null;
- processor.clearList();
- processor = null;
- reporter = null;
- super.tearDown();
- }
-
}
RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next();
assertEquals( "check metadata", metadata, result.getMetadata() );
// TODO: should be more robust
- assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() );
+ assertEquals( "check reason", "Snapshot artifact 1.0-alpha-1-20050611.202024-2 does not exist.",
+ result.getReason() );
assertFalse( "check no more failures", failures.hasNext() );
}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 junit.framework.TestCase;
-import org.apache.maven.archiva.layer.Cache;
-
-/**
- *
- */
-public class CacheTest
- extends TestCase
-{
- private Cache cache;
-
- private static final double CACHE_HIT_RATIO = 0.5;
-
- private static final double CACHE_HIT_RATIO_THRESHOLD = 0.75;
-
- public void testCacheManagementBasedOnHitsRatio()
- {
- cache = new Cache( CACHE_HIT_RATIO );
- newCacheObjectTests();
-
- String key = "key";
- String value = "value";
- for ( int ctr = 1; ctr < 10; ctr++ )
- {
- cache.put( key + ctr, value + ctr );
- }
-
- while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD )
- {
- cache.get( "key2" );
- }
- cache.put( "key10", "value10" );
- assertNull( "first key must be expired", cache.get( "key1" ) );
- }
-
- public void testCacheManagementBasedOnCacheSize()
- {
- cache = new Cache( 9 );
- newCacheObjectTests();
-
- String key = "key";
- String value = "value";
- for ( int ctr = 1; ctr < 10; ctr++ )
- {
- cache.put( key + ctr, value + ctr );
- }
-
- cache.put( "key10", "value10" );
- assertNull( "first key must be expired", cache.get( "key1" ) );
- assertEquals( "check cache size to be max size", 9, cache.size() );
- }
-
- public void testCacheManagementBasedOnCacheSizeAndHitRate()
- {
- cache = new Cache( CACHE_HIT_RATIO, 9 );
- newCacheObjectTests();
-
- String key = "key";
- String value = "value";
- for ( int ctr = 1; ctr < 5; ctr++ )
- {
- cache.put( key + ctr, value + ctr );
- }
-
- while ( cache.getHitRate() < CACHE_HIT_RATIO )
- {
- cache.get( "key3" );
- }
-
- cache.put( "key10", "value10" );
- assertNull( "first key must be expired", cache.get( "key1" ) );
-
- while ( cache.getHitRate() >= CACHE_HIT_RATIO )
- {
- cache.get( "key11" );
- }
-
- for ( int ctr = 5; ctr < 10; ctr++ )
- {
- cache.put( key + ctr, value + ctr );
- }
-
- cache.put( "key11", "value11" );
- assertNull( "second key must be expired", cache.get( "key2" ) );
- assertEquals( "check cache size to be max size", 9, cache.size() );
- }
-
- public void testCacheOnRedundantData()
- {
- cache = new Cache( CACHE_HIT_RATIO, 9 );
- newCacheObjectTests();
-
- String key = "key";
- String value = "value";
- for ( int ctr = 1; ctr < 10; ctr++ )
- {
- cache.put( key + ctr, value + ctr );
- }
-
- cache.put( "key1", "value1" );
- cache.put( "key10", "value10" );
- assertNull( "second key must be gone", cache.get( "key2" ) );
- assertEquals( "check cache size to be max size", 9, cache.size() );
- }
-
- private void newCacheObjectTests()
- {
- assertEquals( (double) 0, cache.getHitRate(), 0 );
- assertEquals( "check cache size", 0, cache.size() );
-
- String value = "value";
- String key = "key";
-
- cache.put( key, value );
- assertEquals( "check cache hit", value, cache.get( key ) );
- assertEquals( (double) 1, cache.getHitRate(), 0 );
- assertEquals( "check cache size", 1, cache.size() );
- assertNull( "check cache miss", cache.get( "none" ) );
- assertEquals( CACHE_HIT_RATIO, cache.getHitRate(), 0 );
- cache.clear();
- assertNull( "check flushed object", cache.get( "key" ) );
- assertEquals( (double) 0, cache.getHitRate(), 0 );
- assertEquals( "check flushed cache size", 0, cache.size() );
- cache.clear();
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-import org.apache.maven.archiva.layer.CachedRepositoryQueryLayer;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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.
- */
-
-/**
- *
- */
-public class CachedRepositoryQueryLayerTest
- extends AbstractRepositoryQueryLayerTestCase
-{
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
-
- queryLayer = new CachedRepositoryQueryLayer( repository );
- }
-
- public void testUseFileCache()
- {
- testContainsArtifactTrue();
- assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
- testContainsArtifactTrue();
- assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
- }
-
- public void testUseMetadataCache()
- throws Exception
- {
- testArtifactVersionsTrue();
- assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
- testArtifactVersionsTrue();
- assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
- }
-
- public void testUseFileCacheOnSnapshot()
- {
- testContainsSnapshotArtifactTrue();
- assertEquals( 0, queryLayer.getCacheHitRate(), 0 );
- testContainsSnapshotArtifactTrue();
- assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, queryLayer.getCacheHitRate(), 0 );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Edwin Punzalan
- */
-public class GenericMockObject
- implements InvocationHandler
-{
- private Map invocations = new HashMap();
-
- public GenericMockObject()
- {
- //default constructor
- }
-
- public GenericMockObject( Map returnMap )
- {
- invocations = new HashMap( returnMap );
- }
-
- public void setExpectedReturns( Method method, List returnList )
- {
- invocations.put( method, returnList );
- }
-
- public Object invoke( Object proxy, Method method, Object[] args )
- {
- if ( !invocations.containsKey( method ) )
- {
- throw new UnsupportedOperationException( "No expected return values defined." );
- }
-
- List returnList = (List) invocations.get( method );
- if ( returnList.size() < 1 )
- {
- throw new UnsupportedOperationException( "Too few expected return values defined." );
- }
- return returnList.remove( 0 );
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
-import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
-import org.apache.maven.artifact.versioning.VersionRange;
-
-import java.io.File;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * @noinspection ReturnOfNull
- */
-public class MockArtifact
- implements Artifact
-{
- private String groupId;
-
- private String artifactId;
-
- private String version;
-
- public String getGroupId()
- {
- return groupId;
- }
-
- public String getArtifactId()
- {
- return artifactId;
- }
-
- public String getVersion()
- {
- return version;
- }
-
- public void setVersion( String s )
- {
- version = s;
- }
-
- public String getScope()
- {
- return null;
- }
-
- public String getType()
- {
- return null;
- }
-
- public String getClassifier()
- {
- return null;
- }
-
- public boolean hasClassifier()
- {
- return false;
- }
-
- public File getFile()
- {
- return null;
- }
-
- public void setFile( File file )
- {
- }
-
- public String getBaseVersion()
- {
- return null;
- }
-
- public void setBaseVersion( String s )
- {
- }
-
- public String getId()
- {
- return null;
- }
-
- public String getDependencyConflictId()
- {
- return null;
- }
-
- public void addMetadata( ArtifactMetadata artifactMetadata )
- {
- }
-
- public Collection getMetadataList()
- {
- return null;
- }
-
- public void setRepository( ArtifactRepository artifactRepository )
- {
- }
-
- public ArtifactRepository getRepository()
- {
- return null;
- }
-
- public void updateVersion( String s, ArtifactRepository artifactRepository )
- {
- }
-
- public String getDownloadUrl()
- {
- return null;
- }
-
- public void setDownloadUrl( String s )
- {
- }
-
- public ArtifactFilter getDependencyFilter()
- {
- return null;
- }
-
- public void setDependencyFilter( ArtifactFilter artifactFilter )
- {
- }
-
- public ArtifactHandler getArtifactHandler()
- {
- return null;
- }
-
- public List getDependencyTrail()
- {
- return null;
- }
-
- public void setDependencyTrail( List list )
- {
- }
-
- public void setScope( String s )
- {
- }
-
- public VersionRange getVersionRange()
- {
- return null;
- }
-
- public void setVersionRange( VersionRange versionRange )
- {
- }
-
- public void selectVersion( String s )
- {
- }
-
- public void setGroupId( String s )
- {
- groupId = s;
- }
-
- public void setArtifactId( String s )
- {
- artifactId = s;
- }
-
- public boolean isSnapshot()
- {
- return false;
- }
-
- public void setResolved( boolean b )
- {
- }
-
- public boolean isResolved()
- {
- return false;
- }
-
- public void setResolvedVersion( String s )
- {
- }
-
- public void setArtifactHandler( ArtifactHandler artifactHandler )
- {
- }
-
- public boolean isRelease()
- {
- return false;
- }
-
- public void setRelease( boolean b )
- {
- }
-
- public List getAvailableVersions()
- {
- return null;
- }
-
- public void setAvailableVersions( List list )
- {
- }
-
- public boolean isOptional()
- {
- return false;
- }
-
- public ArtifactVersion getSelectedVersion()
- throws OverConstrainedVersionException
- {
- return null;
- }
-
- public boolean isSelectedVersionKnown()
- throws OverConstrainedVersionException
- {
- return false;
- }
-
- public int compareTo( Object o )
- {
- return 0;
- }
-
- public void setOptional( boolean b )
- {
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.versioning.VersionRange;
-
-/**
- * @noinspection ReturnOfNull
- */
-public class MockArtifactFactory
- implements ArtifactFactory
-{
- public Artifact createArtifact( String s, String s1, String s2, String s3, String s4 )
- {
- return null;
- }
-
- public Artifact createArtifactWithClassifier( String s, String s1, String s2, String s3, String s4 )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
- String s4 )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
- String s4, String s5 )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String s, String s1, VersionRange versionRange, String s2, String s3,
- String s4, String s5, boolean b )
- {
- return null;
- }
-
- public Artifact createBuildArtifact( String s, String s1, String s2, String s3 )
- {
- return null;
- }
-
- public Artifact createProjectArtifact( String s, String s1, String s2 )
- {
- return null;
- }
-
- public Artifact createParentArtifact( String s, String s1, String s2 )
- {
- return null;
- }
-
- public Artifact createPluginArtifact( String s, String s1, VersionRange versionRange )
- {
- return null;
- }
-
- public Artifact createProjectArtifact( String s, String s1, String s2, String s3 )
- {
- return null;
- }
-
- public Artifact createExtensionArtifact( String s, String s1, VersionRange versionRange )
- {
- return null;
- }
-
- public Artifact createDependencyArtifact( String string, String string1, VersionRange versionRange, String string2,
- String string3, String string4, boolean b )
- {
- return null;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.model.Model;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- *
- */
-public class MockArtifactReportProcessor
- implements ArtifactReportProcessor
-{
- private List reportConditions;
-
- private Iterator iterator;
-
- public MockArtifactReportProcessor()
- {
- reportConditions = new ArrayList();
- }
-
- public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter,
- ArtifactRepository repository )
- {
- if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
- {
- iterator = reportConditions.iterator();
- }
- if ( !reportConditions.isEmpty() )
- {
- while ( iterator.hasNext() )
- {
- ReportCondition reportCondition = (ReportCondition) iterator.next();
- int i = reportCondition.getResult();
- if ( i == ReportCondition.SUCCESS )
- {
- reporter.addSuccess( reportCondition.getArtifact() );
- }
- else if ( i == ReportCondition.WARNING )
- {
- reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() );
- }
- else if ( i == ReportCondition.FAILURE )
- {
- reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() );
- }
- }
- }
- }
-
- public void addReturnValue( int result, Artifact artifact, String reason )
- {
- reportConditions.add( new ReportCondition( result, artifact, reason ) );
- }
-
- public void clearList()
- {
- reportConditions.clear();
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.archiva.layer.RepositoryQueryLayer;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- *
- */
-public class MockRepositoryQueryLayer
- implements RepositoryQueryLayer
-{
- private List queryConditions;
-
- private Iterator iterator;
-
- public MockRepositoryQueryLayer()
- {
- queryConditions = new ArrayList();
- }
-
- public boolean containsArtifact( Artifact artifact )
- {
- if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again
- {
- iterator = queryConditions.iterator();
- }
- boolean b;
- if ( queryConditions.isEmpty() )
- {
- b = false;
- }
- else
- {
- b = ( (Boolean) iterator.next() ).booleanValue();
- }
- return b;
- }
-
- public void addReturnValue( boolean queryCondition )
- {
- queryConditions.add( Boolean.valueOf( queryCondition ) );
- }
-
- public void clearList()
- {
- queryConditions.clear();
- }
-
- public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
- {
- return containsArtifact( artifact );
- }
-
- public List getVersions( Artifact artifact )
- {
- return Collections.EMPTY_LIST;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.reporting;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.artifact.Artifact;
-
-/**
- *
- */
-public class ReportCondition
-{
- public static final int SUCCESS = 0;
-
- public static final int FAILURE = -1;
-
- public static final int WARNING = 1;
-
- private int result;
-
- private Artifact artifact;
-
- private String reason;
-
- public ReportCondition( int result, Artifact artifact, String reason )
- {
- this.result = result;
- this.artifact = artifact;
- this.reason = reason;
- }
-
- public int getResult()
- {
- return result;
- }
-
- public void setResult( int result )
- {
- this.result = result;
- }
-
- public Artifact getArtifact()
- {
- return artifact;
- }
-
- public void setArtifact( Artifact artifact )
- {
- this.artifact = artifact;
- }
-
- public String getReason()
- {
- return reason;
- }
-
- public void setReason( String reason )
- {
- this.reason = reason;
- }
-}
+++ /dev/null
-package org.apache.maven.archiva.layer;
-
-/*
- * Copyright 2005-2006 The Apache Software Foundation.
- *
- * Licensed 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 org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
-import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.List;
-
-/**
- *
- */
-public abstract class AbstractRepositoryQueryLayer
- implements RepositoryQueryLayer
-{
- protected ArtifactRepository repository;
-
- public boolean containsArtifact( Artifact artifact )
- {
- File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
- return f.exists();
- }
-
- public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
- {
- String artifactPath = getSnapshotArtifactRepositoryPath( artifact, snapshot );
- File artifactFile = new File( artifactPath );
- return artifactFile.exists();
- }
-
- public List getVersions( Artifact artifact )
- throws RepositoryQueryLayerException
- {
- Metadata metadata = getMetadata( artifact );
-
- return metadata.getVersioning().getVersions();
- }
-
- protected String getSnapshotArtifactRepositoryPath( Artifact artifact, Snapshot snapshot )
- {
- File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
- String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" +
- snapshot.getBuildNumber() + ".pom" );
- File snapshotFile = new File( f.getParentFile(), artifact.getArtifactId() + "-" + snapshotInfo );
- return snapshotFile.getAbsolutePath();
- }
-
- protected Metadata getMetadata( Artifact artifact )
- throws RepositoryQueryLayerException
- {
- Metadata metadata;
-
- ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
- String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
- File metadataFile = new File( repository.getBasedir(), path );
- if ( metadataFile.exists() )
- {
- MetadataXpp3Reader reader = new MetadataXpp3Reader();
- try
- {
- metadata = reader.read( new FileReader( metadataFile ) );
- }
- catch ( FileNotFoundException e )
- {
- throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
- }
- catch ( IOException e )
- {
- throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
- }
- catch ( XmlPullParserException e )
- {
- throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
- }
- }
- else
- {
- throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() );
- }
-
- return metadata;
- }
-}
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.metadata.Metadata;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
+
+import java.util.List;
/**
*
*/
public class CachedRepositoryQueryLayer
- extends AbstractRepositoryQueryLayer
+ implements RepositoryQueryLayer
{
private Cache cache;
public static final double CACHE_HIT_RATIO = 0.5;
- public CachedRepositoryQueryLayer( ArtifactRepository repository )
+ private RepositoryQueryLayer layer;
+
+ public CachedRepositoryQueryLayer( RepositoryQueryLayer layer )
{
- this.repository = repository;
+ this.layer = layer;
cache = new Cache( CACHE_HIT_RATIO );
}
+ public CachedRepositoryQueryLayer( RepositoryQueryLayer layer, Cache cache )
+ {
+ this.cache = cache;
+ this.layer = layer;
+ }
+
public double getCacheHitRate()
{
return cache.getHitRate();
{
boolean artifactFound = true;
- String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact );
+ String artifactPath = layer.getRepository().pathOf( artifact );
if ( cache.get( artifactPath ) == null )
{
- artifactFound = super.containsArtifact( artifact );
+ artifactFound = layer.containsArtifact( artifact );
if ( artifactFound )
{
cache.put( artifactPath, artifactPath );
return artifactFound;
}
- public boolean containsArtifact( Artifact artifact, Snapshot snapshot )
+ public List getVersions( Artifact artifact )
+ throws RepositoryQueryLayerException
{
- boolean artifactFound = true;
+ List list = (List) cache.get( artifact.getId() );
- String path = getSnapshotArtifactRepositoryPath( artifact, snapshot );
-
- if ( cache.get( path ) == null )
+ if ( list == null )
{
- artifactFound = super.containsArtifact( artifact, snapshot );
- if ( artifactFound )
- {
- cache.put( path, path );
- }
+ list = layer.getVersions( artifact );
+ cache.put( artifact.getId(), list );
}
- return artifactFound;
+ return list;
}
- /**
- * Override method to utilize the cache
- */
- protected Metadata getMetadata( Artifact artifact )
- throws RepositoryQueryLayerException
+ public ArtifactRepository getRepository()
{
- Metadata metadata = (Metadata) cache.get( artifact.getId() );
-
- if ( metadata == null )
- {
- metadata = super.getMetadata( artifact );
- cache.put( artifact.getId(), metadata );
- }
-
- return metadata;
+ return layer.getRepository();
}
}
* limitations under the License.
*/
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Metadata;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.List;
/**
*
*/
public class DefaultRepositoryQueryLayer
- extends AbstractRepositoryQueryLayer
+ implements RepositoryQueryLayer
{
+ protected ArtifactRepository repository;
+
public DefaultRepositoryQueryLayer( ArtifactRepository repository )
{
this.repository = repository;
}
+
+ public boolean containsArtifact( Artifact artifact )
+ {
+ File f = new File( repository.getBasedir(), repository.pathOf( artifact ) );
+ return f.exists();
+ }
+
+ public List getVersions( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata = getMetadata( artifact );
+
+ return metadata.getVersioning().getVersions();
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return repository;
+ }
+
+ private Metadata getMetadata( Artifact artifact )
+ throws RepositoryQueryLayerException
+ {
+ Metadata metadata;
+
+ ArtifactRepositoryMetadata repositoryMetadata = new ArtifactRepositoryMetadata( artifact );
+ String path = repository.pathOfRemoteRepositoryMetadata( repositoryMetadata );
+ File metadataFile = new File( repository.getBasedir(), path );
+ if ( metadataFile.exists() )
+ {
+ MetadataXpp3Reader reader = new MetadataXpp3Reader();
+ try
+ {
+ metadata = reader.read( new FileReader( metadataFile ) );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ catch ( XmlPullParserException e )
+ {
+ throw new RepositoryQueryLayerException( "Error occurred while attempting to read metadata file", e );
+ }
+ }
+ else
+ {
+ throw new RepositoryQueryLayerException( "Metadata not found: " + metadataFile.getAbsolutePath() );
+ }
+
+ return metadata;
+ }
}
*/
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.metadata.Snapshot;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List;
boolean containsArtifact( Artifact artifact );
- boolean containsArtifact( Artifact artifact, Snapshot snapshot );
-
List getVersions( Artifact artifact )
throws RepositoryQueryLayerException;
+
+ ArtifactRepository getRepository();
}
--- /dev/null
+package org.apache.maven.archiva.layer;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.codehaus.plexus.PlexusTestCase;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ *
+ */
+public abstract class AbstractRepositoryQueryLayerTestCase
+ extends PlexusTestCase
+{
+ private ArtifactFactory artifactFactory;
+
+ protected ArtifactRepository repository;
+
+ protected RepositoryQueryLayer queryLayer;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ File repositoryDirectory = getTestFile( "src/test/repository" );
+
+ artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+ ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+ ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
+
+ repository =
+ factory.createArtifactRepository( "test", repositoryDirectory.toURL().toString(), layout, null, null );
+ }
+
+ public void testContainsArtifactTrue()
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" );
+
+ assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) );
+ }
+
+ public void testContainsArtifactFalse()
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" );
+
+ assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) );
+ }
+
+ public void testContainsSnapshotArtifactTrue()
+ {
+ Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-1" );
+ assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact ) );
+ }
+
+ public void testContainsSnapshotArtifactFalse()
+ {
+ Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-20050611.202024-2" );
+ assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact ) );
+ }
+
+ public void testArtifactVersions()
+ throws Exception
+ {
+ Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" );
+
+ List versions = queryLayer.getVersions( artifact );
+
+ assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) );
+ assertFalse( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) );
+ }
+
+ public void testArtifactVersionsError()
+ {
+ Artifact artifact = getArtifact( "groupId", "none", "ignored" );
+
+ try
+ {
+ queryLayer.getVersions( artifact );
+ fail( "expected error not thrown" );
+ }
+ catch ( RepositoryQueryLayerException e )
+ {
+ //expected
+ }
+ }
+
+ private Artifact getArtifact( String groupId, String artifactId, String version )
+ {
+ Artifact projectArtifact = artifactFactory.createProjectArtifact( groupId, artifactId, version );
+ projectArtifact.isSnapshot();
+ return projectArtifact;
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.layer;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 junit.framework.TestCase;
+
+/**
+ *
+ */
+public class CacheTest
+ extends TestCase
+{
+ private Cache cache;
+
+ private static final double CACHE_HIT_RATIO = 0.5;
+
+ private static final double CACHE_HIT_RATIO_THRESHOLD = 0.75;
+
+ public void testCacheManagementBasedOnHitsRatio()
+ {
+ cache = new Cache( CACHE_HIT_RATIO );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ while ( cache.getHitRate() < CACHE_HIT_RATIO_THRESHOLD )
+ {
+ cache.get( "key2" );
+ }
+ cache.put( "key10", "value10" );
+ assertNull( "first key must be expired", cache.get( "key1" ) );
+ }
+
+ public void testCacheManagementBasedOnCacheSize()
+ {
+ cache = new Cache( 9 );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ cache.put( "key10", "value10" );
+ assertNull( "first key must be expired", cache.get( "key1" ) );
+ assertEquals( "check cache size to be max size", 9, cache.size() );
+ }
+
+ public void testCacheManagementBasedOnCacheSizeAndHitRate()
+ {
+ cache = new Cache( CACHE_HIT_RATIO, 9 );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 5; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ while ( cache.getHitRate() < CACHE_HIT_RATIO )
+ {
+ cache.get( "key3" );
+ }
+
+ cache.put( "key10", "value10" );
+ assertNull( "first key must be expired", cache.get( "key1" ) );
+
+ while ( cache.getHitRate() >= CACHE_HIT_RATIO )
+ {
+ cache.get( "key11" );
+ }
+
+ for ( int ctr = 5; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ cache.put( "key11", "value11" );
+ assertNull( "second key must be expired", cache.get( "key2" ) );
+ assertEquals( "check cache size to be max size", 9, cache.size() );
+ }
+
+ public void testCacheOnRedundantData()
+ {
+ cache = new Cache( CACHE_HIT_RATIO, 9 );
+ newCacheObjectTests();
+
+ String key = "key";
+ String value = "value";
+ for ( int ctr = 1; ctr < 10; ctr++ )
+ {
+ cache.put( key + ctr, value + ctr );
+ }
+
+ cache.put( "key1", "value1" );
+ cache.put( "key10", "value10" );
+ assertNull( "second key must be gone", cache.get( "key2" ) );
+ assertEquals( "check cache size to be max size", 9, cache.size() );
+ }
+
+ private void newCacheObjectTests()
+ {
+ assertEquals( (double) 0, cache.getHitRate(), 0 );
+ assertEquals( "check cache size", 0, cache.size() );
+
+ String value = "value";
+ String key = "key";
+
+ cache.put( key, value );
+ assertEquals( "check cache hit", value, cache.get( key ) );
+ assertEquals( (double) 1, cache.getHitRate(), 0 );
+ assertEquals( "check cache size", 1, cache.size() );
+ assertNull( "check cache miss", cache.get( "none" ) );
+ assertEquals( CACHE_HIT_RATIO, cache.getHitRate(), 0 );
+ cache.clear();
+ assertNull( "check flushed object", cache.get( "key" ) );
+ assertEquals( (double) 0, cache.getHitRate(), 0 );
+ assertEquals( "check flushed cache size", 0, cache.size() );
+ cache.clear();
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.layer;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ *
+ */
+public class CachedRepositoryQueryLayerTest
+ extends AbstractRepositoryQueryLayerTestCase
+{
+ private Cache cache;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ cache = new Cache( CachedRepositoryQueryLayer.CACHE_HIT_RATIO );
+
+ queryLayer = new CachedRepositoryQueryLayer( new DefaultRepositoryQueryLayer( repository ), cache );
+ }
+
+ public void testUseFileCache()
+ {
+ testContainsArtifactTrue();
+ assertEquals( 0, cache.getHitRate(), 0 );
+ testContainsArtifactTrue();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, cache.getHitRate(), 0 );
+ }
+
+ public void testUseMetadataCache()
+ throws Exception
+ {
+ testArtifactVersions();
+ assertEquals( 0, cache.getHitRate(), 0 );
+ testArtifactVersions();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, cache.getHitRate(), 0 );
+ }
+
+ public void testUseFileCacheOnSnapshot()
+ {
+ testContainsSnapshotArtifactTrue();
+ assertEquals( 0, cache.getHitRate(), 0 );
+ testContainsSnapshotArtifactTrue();
+ assertEquals( CachedRepositoryQueryLayer.CACHE_HIT_RATIO, cache.getHitRate(), 0 );
+ }
+}
--- /dev/null
+package org.apache.maven.archiva.layer;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+public class DefaultRepositoryQueryLayerTest
+ extends AbstractRepositoryQueryLayerTestCase
+{
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ queryLayer = new DefaultRepositoryQueryLayer( repository );
+ }
+}
--- /dev/null
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-1</version>
+</project>
--- /dev/null
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed 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.
+ -->
+
+<metadata>
+ <groupId>groupId</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-alpha-1</version>
+ <versioning>
+ <versions>
+ <version>1.0-alpha-1</version>
+ </versions>
+ </versioning>
+</metadata>