From ac0cc235218e8765c5c9872698c21afc88f6b49f Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 10 Oct 2005 02:16:39 +0000 Subject: [PATCH] PR: MNG-1147 validate that resources have a directory git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@312528 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/DefaultModelValidator.java | 15 +++++++++++++++ .../validation/DefaultModelValidatorTest.java | 12 ++++++++++++ .../missing-resource-directory-pom.xml | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 maven-project/src/test/resources/validation/missing-resource-directory-pom.xml diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index 181047ee27..118b6cd0f9 100644 --- a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -25,6 +25,7 @@ import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; import org.apache.maven.model.Reporting; import org.apache.maven.model.Repository; +import org.apache.maven.model.Resource; import org.codehaus.plexus.util.StringUtils; import java.util.Iterator; @@ -116,6 +117,20 @@ public class DefaultModelValidator validateStringNotEmpty( "build.plugins.plugin.groupId", result, p.getGroupId() ); } + + for ( Iterator it = build.getResources().iterator(); it.hasNext(); ) + { + Resource r = (Resource) it.next(); + + validateStringNotEmpty( "build.resources.resource.directory", result, r.getDirectory() ); + } + + for ( Iterator it = build.getTestResources().iterator(); it.hasNext(); ) + { + Resource r = (Resource) it.next(); + + validateStringNotEmpty( "build.testResources.testResource.directory", result, r.getDirectory() ); + } } Reporting reporting = model.getReporting(); diff --git a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java index ca5ed753e7..fc42d287c3 100644 --- a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java @@ -191,6 +191,18 @@ public class DefaultModelValidatorTest assertEquals( "'pluginRepositories.pluginRepository.url' is missing.", result.getMessage( 3 ) ); } + public void testMissingResourceDirectory() + throws Exception + { + ModelValidationResult result = validate( "missing-resource-directory-pom.xml" ); + + assertEquals( 2, result.getMessageCount() ); + + assertEquals( "'build.resources.resource.directory' is missing.", result.getMessage( 0 ) ); + + assertEquals( "'build.testResources.testResource.directory' is missing.", result.getMessage( 1 ) ); + } + private ModelValidationResult validate( String testName ) throws Exception { diff --git a/maven-project/src/test/resources/validation/missing-resource-directory-pom.xml b/maven-project/src/test/resources/validation/missing-resource-directory-pom.xml new file mode 100644 index 0000000000..d4864a3814 --- /dev/null +++ b/maven-project/src/test/resources/validation/missing-resource-directory-pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + foo + foo + 99.44 + bleh + + + + + + + + + + + + +