mirror of https://github.com/apache/archiva.git
[MRM-77] hadle some edge cases in reports
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@441751 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
47e2bcd368
commit
9c557abae7
|
@ -197,17 +197,21 @@ public class BadMetadataReportProcessor
|
|||
RepositoryQueryLayer repositoryQueryLayer =
|
||||
repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
|
||||
|
||||
Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
|
||||
|
||||
String version = StringUtils.replace( metadata.getBaseVersion(), 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 ) )
|
||||
Versioning versioning = metadata.getMetadata().getVersioning();
|
||||
if ( versioning != null )
|
||||
{
|
||||
reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
|
||||
Snapshot snapshot = versioning.getSnapshot();
|
||||
|
||||
String version = StringUtils.replace( metadata.getBaseVersion(), 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 " + version + " does not exist." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,6 +82,15 @@ public class DependencyArtifactReportProcessor
|
|||
{
|
||||
Artifact artifact = createArtifact( dependency );
|
||||
|
||||
// TODO: handle ranges properly. We should instead be mapping out all the artifacts in the
|
||||
// repository and mapping out the graph
|
||||
|
||||
if ( artifact.getVersion() == null )
|
||||
{
|
||||
// it was a range, for now presume it exists
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
|
||||
{
|
||||
String reason = MessageFormat.format(
|
||||
|
@ -118,8 +127,14 @@ public class DependencyArtifactReportProcessor
|
|||
private Artifact createArtifact( Dependency dependency )
|
||||
throws InvalidVersionSpecificationException
|
||||
{
|
||||
return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
|
||||
VersionRange.createFromVersionSpec( dependency.getVersion() ),
|
||||
VersionRange spec = VersionRange.createFromVersionSpec( dependency.getVersion() );
|
||||
|
||||
if ( spec == null )
|
||||
{
|
||||
throw new InvalidVersionSpecificationException( "Dependency version was null" );
|
||||
}
|
||||
|
||||
return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(), spec,
|
||||
dependency.getType(), dependency.getClassifier(),
|
||||
dependency.getScope() );
|
||||
}
|
||||
|
|
|
@ -99,6 +99,26 @@ public class BadMetadataReportProcessorTest
|
|||
assertFalse( "check no more failures", failures.hasNext() );
|
||||
}
|
||||
|
||||
public void testSnapshotMetadataMissingVersioning()
|
||||
{
|
||||
Artifact artifact =
|
||||
artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" );
|
||||
|
||||
RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact );
|
||||
|
||||
badMetadataReportProcessor.processMetadata( metadata, repository, reporter );
|
||||
|
||||
Iterator failures = reporter.getMetadataIterator();
|
||||
assertTrue( "check there is a failure", failures.hasNext() );
|
||||
MetadataResults results = (MetadataResults) failures.next();
|
||||
failures = results.getFailures().iterator();
|
||||
assertTrue( "check there is a failure", failures.hasNext() );
|
||||
assertMetadata( metadata, results );
|
||||
Result result = (Result) failures.next();
|
||||
assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() );
|
||||
assertFalse( "check no more failures", failures.hasNext() );
|
||||
}
|
||||
|
||||
public void testMetadataValidVersions()
|
||||
{
|
||||
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
|
||||
|
|
|
@ -241,6 +241,37 @@ public class DependencyArtifactReportProcessorTest
|
|||
assertEquals( getDependencyVersionInvalidMessage( dependency, "[" ), result.getReason() );
|
||||
}
|
||||
|
||||
public void testValidArtifactWithInvalidDependencyVersionRange()
|
||||
{
|
||||
Artifact artifact = createValidArtifact();
|
||||
|
||||
Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, "[1.0,)" );
|
||||
model.addDependency( dependency );
|
||||
|
||||
processor.processArtifact( artifact, model, reporter );
|
||||
assertEquals( 0, reporter.getNumFailures() );
|
||||
assertEquals( 0, reporter.getNumWarnings() );
|
||||
}
|
||||
|
||||
public void testValidArtifactWithMissingDependencyVersion()
|
||||
{
|
||||
Artifact artifact = createValidArtifact();
|
||||
|
||||
Dependency dependency = createDependency( VALID_GROUP_ID, VALID_ARTIFACT_ID, null );
|
||||
model.addDependency( dependency );
|
||||
|
||||
processor.processArtifact( artifact, model, reporter );
|
||||
assertEquals( 1, reporter.getNumFailures() );
|
||||
assertEquals( 0, reporter.getNumWarnings() );
|
||||
|
||||
Iterator failures = reporter.getArtifactIterator();
|
||||
ArtifactResults results = (ArtifactResults) failures.next();
|
||||
assertFalse( failures.hasNext() );
|
||||
failures = results.getFailures().iterator();
|
||||
Result result = (Result) failures.next();
|
||||
assertEquals( getDependencyVersionInvalidMessage( dependency, null ), result.getReason() );
|
||||
}
|
||||
|
||||
private String getDependencyVersionInvalidMessage( Dependency dependency, String version )
|
||||
{
|
||||
return "Artifact's dependency " + getDependencyString( dependency ) + " contains an invalid version " + version;
|
||||
|
|
Loading…
Reference in New Issue