From 5988085525a39025a9f3d7cfb0592d42261abaf0 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Thu, 18 Jan 2018 15:50:36 +0100 Subject: [PATCH] =?UTF-8?q?[MNG-6342]=C2=A0Emit=20a=20WARNING=20about=20LA?= =?UTF-8?q?TEST/RELEASE=20in=20parent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../validation/DefaultModelValidator.java | 7 ++++ .../validation/DefaultModelValidatorTest.java | 15 ++++++++ .../raw-model/bad-parent-version-latest.xml | 37 +++++++++++++++++++ .../raw-model/bad-parent-version-release.xml | 37 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-latest.xml create mode 100644 maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-release.xml 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 9299b4377d..f0acb1fe87 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 @@ -105,6 +105,13 @@ public void validateRawModel( Model m, ModelBuildingRequest request, ModelProble + ", the parent element cannot have the same groupId:artifactId as the project.", parent ); } + + if ( equals( "LATEST", parent.getVersion() ) || equals( "RELEASE", parent.getVersion() ) ) + { + addViolation( problems, Severity.WARNING, Version.BASE, "parent.version", null, + "is either LATEST or RELEASE (both of them are being deprecated)", parent ); + } + } if ( request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ) diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java index 0bb3bd4fb0..b02e0d90b3 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -781,4 +781,19 @@ public void testCiFriendlyBadSha1Plus2() assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) ); } + public void testParentVersionLATEST() + throws Exception + { + SimpleProblemCollector result = validateRaw( "raw-model/bad-parent-version-latest.xml" ); + assertViolations( result, 0, 0, 1 ); + assertEquals( "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", result.getWarnings().get( 0 ) ); + } + + public void testParentVersionRELEASE() + throws Exception + { + SimpleProblemCollector result = validateRaw( "raw-model/bad-parent-version-release.xml" ); + assertViolations( result, 0, 0, 1 ); + assertEquals( "'parent.version' is either LATEST or RELEASE (both of them are being deprecated)", result.getWarnings().get( 0 ) ); + } } diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-latest.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-latest.xml new file mode 100644 index 0000000000..7ed30ad1df --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-latest.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + + + com.example.group + com-parent + LATEST + + com.example.group + valid-version-wrong + 1.0 + + + This will test if the validation for the parent version + is working correct in case of usage of LATEST + + \ No newline at end of file diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-release.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-release.xml new file mode 100644 index 0000000000..65fcc2671e --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-version-release.xml @@ -0,0 +1,37 @@ + + + + 4.0.0 + + + com.example.group + com-parent + RELEASE + + com.example.group + valid-version-wrong + 1.0 + + + This will test if the validation for the parent version + is working correct in case of usage of RELEASE + + \ No newline at end of file