From 8d139ecb2196ec4be450d8c824fccc3b8c15b9ce Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Fri, 27 Dec 2002 18:06:23 +0000 Subject: [PATCH] Add "importStack" that will allow import to keep track of loops. If importStack has more than one element, ProjectHelper implementations should know they are inside an import. This can also be used to display more informative error messages ( i.e. the include path to a file with errors ). Removed the SAX2 Attributes and deprecate the SAX1 Attributes methods. I made a small change to RuntimeConfigurable to make it less SAX-dependent, ProjectHelper2 will just use a simple Hashtable and RC/ProjectHelper will be SAX-independent ( except the deprecated methods ). This would allow better programmatic use of ant and maybe a DOM ProjectHelper. One interesting note: while SAX is faster, using DOM or caching the UE/RC tree will greatly optimize , where the same file is parsed on each call. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273703 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/ProjectHelper.java | 74 +++++++++---------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java index b15556286..b042d2596 100644 --- a/src/main/org/apache/tools/ant/ProjectHelper.java +++ b/src/main/org/apache/tools/ant/ProjectHelper.java @@ -115,6 +115,7 @@ public class ProjectHelper { public static void configureProject(Project project, File buildFile) throws BuildException { ProjectHelper helper = ProjectHelper.getProjectHelper(); + project.addReference("ant.projectHelper", helper); helper.parse(project, buildFile); } @@ -122,6 +123,38 @@ public class ProjectHelper { public ProjectHelper() { } + // -------------------- Common properties -------------------- + // The following properties are required by import ( and other tasks + // that read build files using ProjectHelper ). + + // A project helper may process multiple files. We'll keep track + // of them - to avoid loops and to allow caching. The caching will + // probably accelerate things like . + // The key is the absolute file, the value is a processed tree. + // Since the tree is composed of UE and RC - it can be reused ! + // protected Hashtable processedFiles=new Hashtable(); + + protected Vector importStack=new Vector(); + + // Temporary - until we figure a better API + /** EXPERIMENTAL WILL_CHANGE + * + */ +// public Hashtable getProcessedFiles() { +// return processedFiles; +// } + + /** EXPERIMENTAL WILL_CHANGE + * Import stack. + * Used to keep track of imported files. Error reporting should + * display the import path. + */ + public Vector getImportStack() { + return importStack; + } + + + // -------------------- Parse method -------------------- /** * Parses the project file, configuring the project as it goes. * @@ -285,7 +318,8 @@ public class ProjectHelper { * Must not be null. * @param project The project containing the target. * Must not be null. - * + * + * @deprecated * @exception BuildException if any of the attributes can't be handled by * the target */ @@ -317,44 +351,6 @@ public class ProjectHelper { } } - /** Configure a component using SAX2 attributes. - */ - public static void configure( Object target, Attributes attrs, Project project ) - throws BuildException - { - if (target instanceof TaskAdapter) { - target = ((TaskAdapter) target).getProxy(); - } - - IntrospectionHelper ih = - IntrospectionHelper.getHelper(target.getClass()); - - // Why ??? - project.addBuildListener(ih); - - for (int i = 0; i < attrs.getLength(); i++) { - // reflect these into the target - String attValue=attrs.getValue(i); - - // XXX ADD SPECIAL CASE FOR ${property} - don't convert to string - // and support ARRAYS. - // reflect these into the target - //String value = replaceProperties(attValue); - String value = replaceProperties(project, attValue, - project.getProperties()); - try { - ih.setAttribute(project, target, - attrs.getQName(i).toLowerCase(Locale.US), value); - - } catch (BuildException be) { - // id attribute must be set externally - if (!attrs.getQName(i).equals("id")) { - throw be; - } - } - } - } - /** * Adds the content of #PCDATA sections to an element. *