metadataRequest.setArtifact( artifact );
metadataRequest.setRemoteRepositories( childRemoteRepositories );
try
{
ResolutionGroup rGroup;
Object childKey;
do
{
childKey = child.getKey();
if ( managedVersions.containsKey( childKey ) )
{
// If this child node is a managed dependency, ensure
// we are using the dependency management version
// of this child if applicable b/c we want to use the
// managed version's POM, *not* any other version's POM.
// We retrieve the POM below in the retrieval step.
manageArtifact( child, managedVersions, listeners );
// Also, we need to ensure that any exclusions it presents are
// added to the artifact before we retrive the metadata
// for the artifact; otherwise we may end up with unwanted
// dependencies.
Artifact ma = managedVersions.get( childKey );
ArtifactFilter managedExclusionFilter = ma.getDependencyFilter();
if ( null != managedExclusionFilter )
{
if ( null != artifact.getDependencyFilter() )
{
AndArtifactFilter aaf = new AndArtifactFilter();
aaf.add( artifact.getDependencyFilter() );
aaf.add( managedExclusionFilter );
artifact.setDependencyFilter( aaf );
}
else
{
artifact.setDependencyFilter( managedExclusionFilter );
}
}
}
if ( artifact.getVersion() == null )
{
// set the recommended version
// TODO: maybe its better to just pass the range through to retrieval and use a
// transformation?
ArtifactVersion version;
if ( !artifact.isSelectedVersionKnown() )
{
List<ArtifactVersion> versions = artifact.getAvailableVersions();
if ( versions == null )
{
versions = source.retrieveAvailableVersions( metadataRequest );
artifact.setAvailableVersions( versions );
}
Collections.sort( versions );
VersionRange versionRange = artifact.getVersionRange();
version = versionRange.matchVersion( versions );
if ( version == null )
{
if ( versions.isEmpty() )
{
throw new OverConstrainedVersionException(
"No versions are present in the repository for the artifact with a range "
+ versionRange,
artifact,
childRemoteRepositories );
}
throw new OverConstrainedVersionException( "Couldn't find a version in "
+ versions + " to match range " + versionRange, artifact,
childRemoteRepositories );
}
}
else
{
version = artifact.getSelectedVersion();
}
artifact.selectVersion( version.toString() );
fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child );
}
rGroup = source.retrieve( metadataRequest );
if ( rGroup == null )
{
break;
}
}
while( !childKey.equals( child.getKey() ) );
if ( parentArtifact != null && parentArtifact.getDependencyFilter() != null
&& !parentArtifact.getDependencyFilter().include( artifact ) )
{
// MNG-3769: the [probably relocated] artifact is excluded.
// We could process exclusions on relocated artifact details in the
// MavenMetadataSource.createArtifacts(..) step, BUT that would
// require resolving the POM from the repository very early on in
// the build.
continue;
}
// TODO might be better to have source.retrieve() throw a specific exception for this
// situation
// and catch here rather than have it return null
if ( rGroup == null )
{
// relocated dependency artifact is declared excluded, no need to add and recurse
// further
continue;
}
child.addDependencies( rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter );
}
catch ( CyclicDependencyException e )
{
// would like to throw this, but we have crappy stuff in the repo