in maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java [249:305]
public VersionRange restrict( VersionRange restriction )
{
List r1 = this.restrictions;
List r2 = restriction.restrictions;
List restrictions;
if ( r1.isEmpty() || r2.isEmpty() )
{
restrictions = Collections.EMPTY_LIST;
}
else
{
restrictions = intersection( r1, r2 );
}
ArtifactVersion version = null;
if ( restrictions.size() > 0 )
{
boolean found = false;
for ( Iterator i = restrictions.iterator(); i.hasNext() && !found; )
{
Restriction r = (Restriction) i.next();
if ( recommendedVersion != null && r.containsVersion( recommendedVersion ) )
{
// if we find the original, use that
version = recommendedVersion;
found = true;
}
else if ( version == null && restriction.getRecommendedVersion() != null
&& r.containsVersion( restriction.getRecommendedVersion() ) )
{
// use this if we can, but prefer the original if possible
version = restriction.getRecommendedVersion();
}
}
}
// Either the original or the specified version ranges have no restructions
else if ( recommendedVersion != null )
{
// Use the original recommended version since it exists
version = recommendedVersion;
}
else if ( restriction.recommendedVersion != null )
{
// Use the recommended version from the specified VersionRange since there is no
// original recommended version
version = restriction.recommendedVersion;
}
/* TODO: should throw this immediately, but need artifact
else
{
throw new OverConstrainedVersionException( "Restricting incompatible version ranges" );
}
*/
return new VersionRange( version, restrictions );
}