From f2946af28476512f979b65ecc54868dee42eaaf5 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Thu, 13 Aug 2009 19:17:19 +0000 Subject: [PATCH] [MNG-4297] Disallow use of properties in the project coordinates o For Maven 3.0, started to produce a warning git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@803995 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/DefaultMaven.java | 2 +- .../model/building/DefaultModelBuilder.java | 1 + .../validation/DefaultModelValidator.java | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index efcb024bdc..59416f20b1 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -322,7 +322,7 @@ public class DefaultMaven logger.warn( "It is highly recommended to fix these problems" + " because they threaten the stability of your build." ); logger.warn( "" ); - logger.warn( "For this reason, future Maven versions will no" + logger.warn( "For this reason, future Maven versions might no" + " longer support building such malformed projects." ); logger.warn( "" ); } 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 62b88f5251..a1c2ca5fde 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 @@ -289,6 +289,7 @@ public class DefaultModelBuilder model.setPomFile( pomFile ); + problems.setSourceHint( model ); modelValidator.validateRawModel( model, request, problems ); return model; diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 2c5874c804..ab2d9d1b2b 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -71,6 +71,10 @@ public class DefaultModelValidator if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ) { + validateStringNoExpression( "groupId", problems, true, model.getGroupId() ); + validateStringNoExpression( "artifactId", problems, true, model.getArtifactId() ); + validateStringNoExpression( "version", problems, true, model.getVersion() ); + validateDependencies( problems, model.getDependencies(), "dependencies.dependency", request ); if ( model.getDependencyManagement() != null ) @@ -385,6 +389,24 @@ public class DefaultModelValidator // Field validation // ---------------------------------------------------------------------- + private boolean validateStringNoExpression( String fieldName, ModelProblemCollector problems, boolean warning, + String string ) + { + if ( !hasExpression( string ) ) + { + return true; + } + + addViolation( problems, warning, "'" + fieldName + "' contains an expression but should be a constant." ); + + return false; + } + + private boolean hasExpression( String value ) + { + return value != null && value.indexOf( "${" ) >= 0; + } + private boolean validateStringNotEmpty( String fieldName, ModelProblemCollector problems, boolean warning, String string ) { return validateStringNotEmpty( fieldName, problems, warning, string, null );