ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/taskdefs ImportTest.java
Date Mon, 03 Nov 2003 16:36:19 GMT
peterreilly    2003/11/03 08:36:19

  Modified:    src/main/org/apache/tools/ant/taskdefs ImportTask.java
               src/testcases/org/apache/tools/ant/taskdefs ImportTest.java
  Added:       src/etc/testcases/taskdefs/import bad.xml
                        import_bad_import.xml
  Log:
  make error message for bad imports a little better
  When an buildexception is reported in the imported xml, add the importer
  xml file to the build exception
  
  Revision  Changes    Path
  1.1                  ant/src/etc/testcases/taskdefs/import/bad.xml
  
  Index: bad.xml
  ===================================================================
  <project>
  <<<
  </project>
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/import/import_bad_import.xml
  
  Index: import_bad_import.xml
  ===================================================================
  <project>
    <import file="bad.xml"/>
  </project>
  
  
  
  1.20      +14 -1     ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
  
  Index: ImportTask.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- ImportTask.java	3 Nov 2003 10:14:49 -0000	1.19
  +++ ImportTask.java	3 Nov 2003 16:36:19 -0000	1.20
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant.taskdefs;
   
   import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.Location;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.Task;
  @@ -179,7 +180,19 @@
               return;
           }
   
  -        helper.parse(getProject(), importedFile);
  +        try {
  +            helper.parse(getProject(), importedFile);
  +        } catch (BuildException ex) {
  +            Location exLocation = ex.getLocation();
  +            if (exLocation == null) {
  +                throw ex;
  +            }
  +            throw new BuildException(
  +                "Error executing import file"
  +                + System.getProperty("line.separator")
  +                + exLocation.toString()
  +                + " " + ex.getMessage());
  +        }
       }
   
       private static String getPath(File file) {
  
  
  
  1.7       +24 -0     ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java
  
  Index: ImportTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ImportTest.java	19 Sep 2003 09:36:22 -0000	1.6
  +++ ImportTest.java	3 Nov 2003 16:36:19 -0000	1.7
  @@ -54,7 +54,9 @@
   
   package org.apache.tools.ant.taskdefs;
   
  +import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.BuildFileTest;
  +import org.apache.tools.ant.Location;
   import org.apache.tools.ant.Project;
   
   /**
  @@ -118,6 +120,28 @@
               "src/etc/testcases/taskdefs/import/subdir/importinsequential.xml");
           expectPropertySet("within-imported", "foo", "bar");
           assertNotNull(getProject().getReference("baz"));
  +    }
  +
  +    public void testImportError() {
  +        try {
  +            configureProject(
  +                "src/etc/testcases/taskdefs/import/import_bad_import.xml");
  +        } catch (BuildException ex) {
  +            Location lo = ex.getLocation();
  +            assertTrue(
  +                "expected location of build exception to be set",
  +                (lo != null));
  +            assertTrue(
  +                "expected location to contain calling file",
  +                lo.getFileName().indexOf("import_bad_import.xml") != -1);
  +            assertTrue(
  +                "expected message of ex to contain called file",
  +                ex.getMessage().indexOf("bad.xml") != -1);
  +            return;
  +        }
  +        assertTrue(
  +            "Did not see build exception",
  +            false);
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message