From 48eccf5d3bd9671c74c16b31c41aa06afa28b109 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 1 Jun 2009 12:09:01 +0000 Subject: [PATCH] o Validated repositories upfront as these are required for parent resolution git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@780622 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/DefaultModelValidator.java | 25 ++++++++++--------- .../validation/DefaultModelValidatorTest.java | 17 +++++++++++-- 2 files changed, 28 insertions(+), 14 deletions(-) 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 367661d312..1162a9fb6b 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 @@ -43,6 +43,7 @@ import org.codehaus.plexus.util.StringUtils; public class DefaultModelValidator implements ModelValidator { + private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+"; public ModelValidationResult validateRawModel( Model model, boolean lenient ) @@ -65,6 +66,8 @@ public class DefaultModelValidator } } + validateRepositories( result, model.getRepositories(), "repositories.repository" ); + return result; } @@ -184,15 +187,9 @@ public class DefaultModelValidator validateStringNotEmpty( "build.plugins.plugin.version", result, p.getVersion(), p.getKey() ); } - for ( Resource r : build.getResources() ) - { - validateStringNotEmpty( "build.resources.resource.directory", result, r.getDirectory() ); - } + validateResources( result, build.getResources(), "build.resources.resource" ); - for ( Resource r : build.getTestResources() ) - { - validateStringNotEmpty( "build.testResources.testResource.directory", result, r.getDirectory() ); - } + validateResources( result, build.getTestResources(), "build.testResources.testResource" ); } Reporting reporting = model.getReporting(); @@ -208,10 +205,6 @@ public class DefaultModelValidator } } - validateRepositories( result, model.getRepositories(), "repositories.repository" ); - - // validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" ); - forcePluginExecutionIdCollision( model, result ); } @@ -245,6 +238,14 @@ public class DefaultModelValidator } } + private void validateResources( ModelValidationResult result, List resources, String prefix ) + { + for ( Resource resource : resources ) + { + validateStringNotEmpty( prefix + ".directory", result, resource.getDirectory() ); + } + } + private void forcePluginExecutionIdCollision( Model model, ModelValidationResult result ) { Build build = model.getBuild(); 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 f76ed64a6c..4274b9b6e6 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 @@ -48,7 +48,20 @@ public class DefaultModelValidatorTest private ModelValidationResult validate( String pom ) throws Exception { - return validator.validateEffectiveModel( read( pom ), false ); + return validate(pom, false, false); + } + + private ModelValidationResult validate( String pom, boolean raw, boolean lenient ) + throws Exception + { + if ( raw ) + { + return validator.validateRawModel( read( pom ), lenient ); + } + else + { + return validator.validateEffectiveModel( read( pom ), lenient ); + } } @Override @@ -233,7 +246,7 @@ public class DefaultModelValidatorTest public void testMissingRepositoryId() throws Exception { - ModelValidationResult result = validate( "missing-repository-id-pom.xml" ); + ModelValidationResult result = validate( "missing-repository-id-pom.xml", true, false ); assertEquals( 2, result.getMessageCount() );