From be2616702954be7f8208b82f6dcf42add4e1509f Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 3 Jan 2011 20:45:41 +0000 Subject: [PATCH] [MNG-4957] Emit validation warning when project version uses irregular SNAPSHOT version string git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1054743 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/DefaultModelValidator.java | 19 ++++++++++++++ .../validation/DefaultModelValidatorTest.java | 10 ++++++++ .../poms/validation/bad-snapshot-version.xml | 25 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.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 200b84ece9..807808a3e5 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 @@ -273,6 +273,7 @@ public class DefaultModelValidator validateBannedCharacters( "version", problems, errOn31, model.getVersion(), null, model, ILLEGAL_VERSION_CHARS ); + validateProperSnapshotVersion( "version", problems, errOn31, model.getVersion(), null, model ); Build build = model.getBuild(); if ( build != null ) @@ -789,6 +790,24 @@ public class DefaultModelValidator return true; } + private boolean validateProperSnapshotVersion( String fieldName, ModelProblemCollector problems, Severity severity, + String string, String sourceHint, InputLocationTracker tracker ) + { + if ( string == null || string.length() <= 0 ) + { + return true; + } + + if ( string.endsWith( "SNAPSHOT" ) && !string.endsWith( "-SNAPSHOT" ) ) + { + addViolation( problems, severity, fieldName, sourceHint, "uses an unsupported snapshot version format" + + ", should be '*-SNAPSHOT' instead.", tracker ); + return false; + } + + return true; + } + private boolean validatePluginVersion( String fieldName, ModelProblemCollector problems, String string, String sourceHint, InputLocationTracker tracker, ModelBuildingRequest request ) 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 fc46b501da..75f9e278b0 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 @@ -526,6 +526,16 @@ public class DefaultModelValidatorTest assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of these characters" ); } + public void testBadSnapshotVersion() + throws Exception + { + SimpleProblemCollector result = validate( "bad-snapshot-version.xml" ); + + assertViolations( result, 0, 0, 1 ); + + assertContains( result.getWarnings().get( 0 ), "'version' uses an unsupported snapshot version format" ); + } + public void testBadRepositoryId() throws Exception { diff --git a/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml b/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml new file mode 100644 index 0000000000..70b5ddcbef --- /dev/null +++ b/maven-model-builder/src/test/resources/poms/validation/bad-snapshot-version.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + foo + bar + 1.2.3.SNAPSHOT +