peterreilly    2003/11/06 06:57:10

  Modified:    src/main/org/apache/tools/ant ProjectHelper.java
               src/main/org/apache/tools/ant/taskdefs Ant.java Definer.java
                        ImportTask.java MacroInstance.java
  Log:
  Provide error stack for [*]ant[*] and macro call
  use same code for import and antlib
  
  Revision  Changes    Path
  1.103     +27 -1     ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.102
  retrieving revision 1.103
  diff -u -r1.102 -r1.103
  --- ProjectHelper.java        29 Oct 2003 10:18:14 -0000      1.102
  +++ ProjectHelper.java        6 Nov 2003 14:57:10 -0000       1.103
  @@ -531,5 +531,31 @@
           }
           return componentName.substring(0, index);
       }
  -//end class
  +
  +    /**
  +     * Add location to build exception.
  +     * @param ex the build exception, if the build exception
  +     *           does not include
  +     * @param newLocation the location of the calling task (may be null)
  +     * @return a new build exception based in the build exception with
  +     *         location set to newLocation. If the original exception
  +     *         did not have a location, just return the build exception
  +     */
  +    public static BuildException addLocationToBuildException(
  +        BuildException ex, Location newLocation) {
  +        if (ex.getLocation() == null || ex.getMessage() == null) {
  +            return ex;
  +        }
  +        String errorMessage
  +            = "Following error occured while executing this line"
  +            + System.getProperty("line.separator")
  +            + ex.getLocation().toString()
  +            + ex.getMessage();
  +        if (newLocation == null) {
  +            return new BuildException(errorMessage);
  +        } else {
  +            return new BuildException(
  +                errorMessage, newLocation);
  +        }
  +    }
   }
  
  
  
  1.94      +10 -2     ant/src/main/org/apache/tools/ant/taskdefs/Ant.java
  
  Index: Ant.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- Ant.java  10 Oct 2003 13:19:46 -0000      1.93
  +++ Ant.java  6 Nov 2003 14:57:10 -0000       1.94
  @@ -378,7 +378,12 @@
                   }
               }
   
  -            ProjectHelper.configureProject(newProject, new File(antFile));
  +            try {
  +                ProjectHelper.configureProject(newProject, new 
File(antFile));
  +            } catch (BuildException ex) {
  +                throw ProjectHelper.addLocationToBuildException(
  +                    ex, getLocation());
  +            }
   
               if (target == null) {
                   target = newProject.getDefaultTarget();
  @@ -413,7 +418,10 @@
                   try {
                       log("Entering " + antFile + "...", Project.MSG_VERBOSE);
                       newProject.executeTarget(target);
  -                } finally {
  +                } catch (BuildException ex) {
  +                    throw ProjectHelper.addLocationToBuildException(
  +                        ex, getLocation());
  +              } finally {
                       log("Exiting " + antFile + ".", Project.MSG_VERBOSE);
                   }
               }
  
  
  
  1.47      +2 -9      ant/src/main/org/apache/tools/ant/taskdefs/Definer.java
  
  Index: Definer.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Definer.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- Definer.java      30 Oct 2003 15:43:13 -0000      1.46
  +++ Definer.java      6 Nov 2003 14:57:10 -0000       1.47
  @@ -343,15 +343,8 @@
               antlib.setURI(getURI());
               antlib.perform();
           } catch (BuildException ex) {
  -            Location exLocation = ex.getLocation();
  -            if (exLocation == null) {
  -                throw ex;
  -            }
  -            throw new BuildException(
  -                "Error executing antlib"
  -                + System.getProperty("line.separator")
  -                + exLocation.toString()
  -                + " " + ex.getMessage());
  +            throw ProjectHelper.addLocationToBuildException(
  +                ex, getLocation());
           }
       }
   
  
  
  
  1.21      +3 -10     
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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ImportTask.java   3 Nov 2003 16:36:19 -0000       1.20
  +++ ImportTask.java   6 Nov 2003 14:57:10 -0000       1.21
  @@ -55,7 +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.ProjectHelper;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.ProjectHelper;
   import org.apache.tools.ant.Task;
  @@ -183,15 +183,8 @@
           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());
  +            throw ProjectHelper.addLocationToBuildException(
  +                ex, getLocation());
           }
       }
   
  
  
  
  1.8       +8 -2      
ant/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
  
  Index: MacroInstance.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MacroInstance.java        8 Oct 2003 08:44:46 -0000       1.7
  +++ MacroInstance.java        6 Nov 2003 14:57:10 -0000       1.8
  @@ -66,10 +66,11 @@
   
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DynamicConfigurator;
  +import org.apache.tools.ant.ProjectHelper;
  +import org.apache.tools.ant.RuntimeConfigurable;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.TaskContainer;
   import org.apache.tools.ant.UnknownElement;
  -import org.apache.tools.ant.RuntimeConfigurable;
   
   /**
    * The class to be placed in the ant type definition.
  @@ -264,6 +265,11 @@
           // need to set the project on unknown element
           UnknownElement c = copy(macroDef.getNestedTask());
           c.init();
  -        c.perform();
  +        try {
  +            c.perform();
  +        } catch (BuildException ex) {
  +            throw ProjectHelper.addLocationToBuildException(
  +                ex, getLocation());
  +        }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to