From bd87258629db8e3fcc7aa04777afc16314c3cde0 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Wed, 22 Jul 2015 09:52:01 +0100 Subject: [PATCH] [MNG-5840] The fix for parent version validation caused a regression in the parent version range - With this change we basically unwind MNG-5840 for the rumoured validation in the workspace resolver when dealing with a parent version range. Not ideal but only way for now to retain the version range feature --- maven-model-builder/pom.xml | 4 ++ .../model/building/DefaultModelBuilder.java | 50 +++++++++++-------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/maven-model-builder/pom.xml b/maven-model-builder/pom.xml index 0af97b8e7c..1071557406 100644 --- a/maven-model-builder/pom.xml +++ b/maven-model-builder/pom.xml @@ -47,6 +47,10 @@ org.apache.maven maven-model + + org.apache.maven + maven-artifact + org.apache.maven maven-builder-support diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index 673a50f5a2..ab00fef6d5 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -20,20 +20,9 @@ package org.apache.maven.model.building; */ -import static org.apache.maven.model.building.Result.error; -import static org.apache.maven.model.building.Result.newResult; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; - +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Activation; import org.apache.maven.model.Build; import org.apache.maven.model.Dependency; @@ -73,6 +62,20 @@ import org.apache.maven.model.validation.ModelValidator; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import static org.apache.maven.model.building.Result.error; +import static org.apache.maven.model.building.Result.newResult; + /** * @author Benjamin Bentmann */ @@ -921,15 +924,18 @@ public class DefaultModelBuilder } if ( version != null && parent.getVersion() != null && !version.equals( parent.getVersion() ) ) { - // - // If the parent version is a range we will let it through here as we do not have the classes - // for determining if the parent is within the range in scope. This may lead to MNG-5840 style - // regressions in the range, but without this the parent version range will not work at all. - // - - if ( !parent.getVersion().startsWith( "[" ) && !parent.getVersion().startsWith( "(" ) ) + try { - // version skew drop back to resolution from the repository + VersionRange parentRange = VersionRange.createFromVersionSpec( parent.getVersion() ); + if ( !parentRange.containsVersion( new DefaultArtifactVersion( version ) ) ) + { + // version skew drop back to resolution from the repository + return null; + } + } + catch ( InvalidVersionSpecificationException e ) + { + // invalid version range, so drop back to resolution from the repository return null; } }