[MANTTASKS-192] display an explicit error message when using a remote repository with a refid which has not been defined instead of NPE

git-svn-id: https://svn.apache.org/repos/asf/maven/ant-tasks/trunk@965226 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/build-tests.xml b/build-tests.xml
index 0830fca..4708ef4 100644
--- a/build-tests.xml
+++ b/build-tests.xml
@@ -71,6 +71,7 @@
         - test-bad-dep
         - test-invalid-pom-ref
     	- test-bad-system-dep
+    	- test-bad-repo-refid
     </echo>
   </target>
 
@@ -677,6 +678,14 @@
     </artifact:dependencies>
   </target>
 
+  <target name="test-bad-repo-refid" depends="initTaskDefs">
+  	<echo>Expected failure: undefined remoteRepository refid</echo>
+    <artifact:dependencies>
+      <remoteRepository refid="not-defined"/>
+      <dependency groupId="commons-logging" artifactId="commons-logging" version="1.1.1"/>
+    </artifact:dependencies>
+  </target>
+
   <macrodef name="check.file.exists">
     <attribute name="file"/>
     <attribute name="type" default="file"/>
diff --git a/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java b/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java
index 392939b..7361dba 100644
--- a/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java
+++ b/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactWithRepositoryTask.java
@@ -132,6 +132,15 @@
      */
     public void addConfiguredRemoteRepository( RemoteRepository remoteRepository )
     {
+        if ( remoteRepository.getRefid() != null )
+        {
+            // check that the refid points to a repository that is properly defined
+            String refid = remoteRepository.getRefid();
+            if ( getProject().getReference( refid ) == null )
+            {
+                throw new BuildException( "Unknown remote repository refid='" + refid + "'." );
+            }
+        }
         // Validate the url and id parameters before adding the repository
         if ( remoteRepository.getUrl() == null )
         {