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
This commit is contained in:
Benjamin Bentmann 2009-06-01 12:09:01 +00:00
parent 67cf84f5c9
commit 48eccf5d3b
2 changed files with 28 additions and 14 deletions

View File

@ -43,6 +43,7 @@ import org.codehaus.plexus.util.StringUtils;
public class DefaultModelValidator public class DefaultModelValidator
implements ModelValidator implements ModelValidator
{ {
private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+"; private static final String ID_REGEX = "[A-Za-z0-9_\\-.]+";
public ModelValidationResult validateRawModel( Model model, boolean lenient ) public ModelValidationResult validateRawModel( Model model, boolean lenient )
@ -65,6 +66,8 @@ public class DefaultModelValidator
} }
} }
validateRepositories( result, model.getRepositories(), "repositories.repository" );
return result; return result;
} }
@ -184,15 +187,9 @@ public class DefaultModelValidator
validateStringNotEmpty( "build.plugins.plugin.version", result, p.getVersion(), p.getKey() ); validateStringNotEmpty( "build.plugins.plugin.version", result, p.getVersion(), p.getKey() );
} }
for ( Resource r : build.getResources() ) validateResources( result, build.getResources(), "build.resources.resource" );
{
validateStringNotEmpty( "build.resources.resource.directory", result, r.getDirectory() );
}
for ( Resource r : build.getTestResources() ) validateResources( result, build.getTestResources(), "build.testResources.testResource" );
{
validateStringNotEmpty( "build.testResources.testResource.directory", result, r.getDirectory() );
}
} }
Reporting reporting = model.getReporting(); 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 ); forcePluginExecutionIdCollision( model, result );
} }
@ -245,6 +238,14 @@ public class DefaultModelValidator
} }
} }
private void validateResources( ModelValidationResult result, List<Resource> resources, String prefix )
{
for ( Resource resource : resources )
{
validateStringNotEmpty( prefix + ".directory", result, resource.getDirectory() );
}
}
private void forcePluginExecutionIdCollision( Model model, ModelValidationResult result ) private void forcePluginExecutionIdCollision( Model model, ModelValidationResult result )
{ {
Build build = model.getBuild(); Build build = model.getBuild();

View File

@ -48,7 +48,20 @@ public class DefaultModelValidatorTest
private ModelValidationResult validate( String pom ) private ModelValidationResult validate( String pom )
throws Exception 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 @Override
@ -233,7 +246,7 @@ public class DefaultModelValidatorTest
public void testMissingRepositoryId() public void testMissingRepositoryId()
throws Exception throws Exception
{ {
ModelValidationResult result = validate( "missing-repository-id-pom.xml" ); ModelValidationResult result = validate( "missing-repository-id-pom.xml", true, false );
assertEquals( 2, result.getMessageCount() ); assertEquals( 2, result.getMessageCount() );