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,7 +197,10 @@ public class BadMetadataReportProcessor
|
||||||
RepositoryQueryLayer repositoryQueryLayer =
|
RepositoryQueryLayer repositoryQueryLayer =
|
||||||
repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
|
repositoryQueryLayerFactory.createRepositoryQueryLayer( repository );
|
||||||
|
|
||||||
Snapshot snapshot = metadata.getMetadata().getVersioning().getSnapshot();
|
Versioning versioning = metadata.getMetadata().getVersioning();
|
||||||
|
if ( versioning != null )
|
||||||
|
{
|
||||||
|
Snapshot snapshot = versioning.getSnapshot();
|
||||||
|
|
||||||
String version = StringUtils.replace( metadata.getBaseVersion(), Artifact.SNAPSHOT_VERSION,
|
String version = StringUtils.replace( metadata.getBaseVersion(), Artifact.SNAPSHOT_VERSION,
|
||||||
snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
|
snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
|
||||||
|
@ -210,6 +213,7 @@ public class BadMetadataReportProcessor
|
||||||
reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
|
reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for validating the versions declared inside an ArtifactRepositoryMetadata
|
* Method for validating the versions declared inside an ArtifactRepositoryMetadata
|
||||||
|
|
|
@ -82,6 +82,15 @@ public class DependencyArtifactReportProcessor
|
||||||
{
|
{
|
||||||
Artifact artifact = createArtifact( dependency );
|
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 ) )
|
if ( !repositoryQueryLayer.containsArtifact( artifact ) )
|
||||||
{
|
{
|
||||||
String reason = MessageFormat.format(
|
String reason = MessageFormat.format(
|
||||||
|
@ -118,8 +127,14 @@ public class DependencyArtifactReportProcessor
|
||||||
private Artifact createArtifact( Dependency dependency )
|
private Artifact createArtifact( Dependency dependency )
|
||||||
throws InvalidVersionSpecificationException
|
throws InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
return artifactFactory.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
|
VersionRange spec = VersionRange.createFromVersionSpec( dependency.getVersion() );
|
||||||
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.getType(), dependency.getClassifier(),
|
||||||
dependency.getScope() );
|
dependency.getScope() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,26 @@ public class BadMetadataReportProcessorTest
|
||||||
assertFalse( "check no more failures", failures.hasNext() );
|
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()
|
public void testMetadataValidVersions()
|
||||||
{
|
{
|
||||||
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
|
Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" );
|
||||||
|
|
|
@ -241,6 +241,37 @@ public class DependencyArtifactReportProcessorTest
|
||||||
assertEquals( getDependencyVersionInvalidMessage( dependency, "[" ), result.getReason() );
|
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 )
|
private String getDependencyVersionInvalidMessage( Dependency dependency, String version )
|
||||||
{
|
{
|
||||||
return "Artifact's dependency " + getDependencyString( dependency ) + " contains an invalid version " + version;
|
return "Artifact's dependency " + getDependencyString( dependency ) + " contains an invalid version " + version;
|
||||||
|
|
Loading…
Reference in New Issue