RepositoryQueryLayer repositoryQueryLayer =
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,
- snapshot.getTimestamp() + "-" + snapshot.getBuildNumber() );
- Artifact artifact =
- artifactFactory.createProjectArtifact( metadata.getGroupId(), metadata.getArtifactId(), version );
- artifact.isSnapshot(); // trigger baseVersion correction
+ 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." );
+ if ( !repositoryQueryLayer.containsArtifact( artifact ) )
+ {
+ reporter.addFailure( metadata, "Snapshot artifact " + version + " does not exist." );
+ }
}
}
{
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(
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() );
}
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" );
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;