ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/embed ProjectHelperImpl2.java ant-sax2.jar
Date Thu, 18 Jul 2002 20:47:32 GMT
costin      2002/07/18 13:47:32

  Modified:    proposal/sandbox/embed ProjectHelperImpl2.java ant-sax2.jar
  Log:
  Merged all the changes from ProjectHelper.
  
  The only thing not merged is 'description' - I would rather add a
  'description' task, it's cleaner.
  
  Revision  Changes    Path
  1.7       +45 -95    jakarta-ant/proposal/sandbox/embed/ProjectHelperImpl2.java
  
  Index: ProjectHelperImpl2.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/embed/ProjectHelperImpl2.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ProjectHelperImpl2.java	16 Jul 2002 22:17:05 -0000	1.6
  +++ ProjectHelperImpl2.java	18 Jul 2002 20:47:32 -0000	1.7
  @@ -60,6 +60,7 @@
   import java.io.FileInputStream;
   import java.io.FileNotFoundException;
   import java.io.IOException;
  +import java.io.UnsupportedEncodingException;
   import java.util.Hashtable;
   import java.util.Vector;
   import java.util.Enumeration;
  @@ -67,7 +68,6 @@
   import java.util.Stack;
   import org.xml.sax.Locator;
   import org.xml.sax.InputSource;
  -//import org.xml.sax.HandlerBase;
   import org.xml.sax.SAXParseException;
   import org.xml.sax.XMLReader;
   import org.xml.sax.SAXException;
  @@ -78,11 +78,8 @@
   import org.xml.sax.helpers.DefaultHandler;
   import org.xml.sax.helpers.AttributeListImpl;
   
  -import javax.xml.parsers.SAXParserFactory;
  -import javax.xml.parsers.SAXParser;
  -import javax.xml.parsers.ParserConfigurationException;
  +import org.apache.tools.ant.util.JAXPUtils;
   
  -import org.apache.tools.ant.types.SystemPath;
   /**
    * Sax2 based project reader
    *
  @@ -92,12 +89,6 @@
   public class ProjectHelperImpl2 extends ProjectHelper {
       /* Stateless */
       
  -    /** 
  -     * Parser factory to use to create parsers.
  -     * @see #getParserFactory
  -     */
  -    private static SAXParserFactory parserFactory = null;
  -
       /**
        * Parses the project file, configuring the project as it goes.
        * 
  @@ -106,7 +97,11 @@
        */
       public void parse(Project project, Object source) throws BuildException {
           // Hook our one tasks.
  -        project.addDataTypeDefinition( "systemPath" , SystemPath.class );
  +        try {
  +            Class c=Class.forName("org.apache.tools.ant.types.SystemPath");
  +            project.addDataTypeDefinition( "systemPath" , c );
  +        } catch (Exception ex ) {
  +        }
           
           AntXmlContext context=new AntXmlContext();
           if(source instanceof File) {
  @@ -132,12 +127,7 @@
                */
               org.xml.sax.XMLReader parser;
       
  -            if (parserFactory == null) {
  -                parserFactory = SAXParserFactory.newInstance();
  -            }
  -
  -            SAXParser saxParser = parserFactory.newSAXParser();
  -            parser =saxParser.getXMLReader();
  +            parser =JAXPUtils.getXMLReader();
   
               String uri = "file:" + context.buildFile.getAbsolutePath().replace('\\', '/');
               for (int index = uri.indexOf('#'); index != -1; index = uri.indexOf('#')) {
  @@ -156,13 +146,9 @@
               parser.setErrorHandler(hb);
               parser.setDTDHandler(hb);
               parser.parse(inputSource);
  -        }
  -        catch(ParserConfigurationException exc) {
  -            throw new BuildException("Parser has not been configured correctly", exc);
  -        }
  -        catch(SAXParseException exc) {
  +        } catch(SAXParseException exc) {
               Location location =
  -                new Location(context.buildFile.toString(), exc.getLineNumber(), exc.getColumnNumber());
  +                new Location(exc.getSystemId(), exc.getLineNumber(), exc.getColumnNumber());
   
               Throwable t = exc.getException();
               if (t instanceof BuildException) {
  @@ -185,8 +171,11 @@
           catch(FileNotFoundException exc) {
               throw new BuildException(exc);
           }
  +        catch(UnsupportedEncodingException exc) {
  +              throw new BuildException("Encoding of project file is invalid.",exc);
  +        }
           catch(IOException exc) {
  -            throw new BuildException("Error reading project file", exc);
  +            throw new BuildException("Error reading project file: " +exc.getMessage(),
exc);
           }
           finally {
               if (inputStream != null) {
  @@ -301,6 +290,18 @@
            */
           Locator locator;
   
  +         /**
  +          * Target that all other targets will depend upon implicitly.
  +          *
  +          * <p>This holds all tasks and data type definitions that have
  +          * been placed outside of targets.</p>
  +          */
  +        Target implicitTarget = new Target();
  +
  +        public AntXmlContext() {
  +            implicitTarget.setName("");
  +        }
  +        
           /**
            * Scans an attribute list for the <code>id</code> attribute and 
            * stores a reference to the target object in the project if an
  @@ -431,7 +432,6 @@
            * @exception SAXException in case of error (not thrown in 
            *                         this implementation)
            * 
  -         * @see #finished()
            */
           public void endElement(String uri, String name, String qName) throws SAXException
{
               currentHandler.onEndElement(uri, name, context);
  @@ -521,14 +521,12 @@
                   }
               }
   
  -            if (def == null) {
  -                throw new SAXParseException("The default attribute of project is required",

  -                                            context.locator);
  -            }
  -            
               Project project=context.project;
  -            project.setDefaultTarget(def);
   
  +            if (def != null && !def.equals("")) {
  +                project.setDefaultTarget(def);
  +            }
  +            
               if (name != null) {
                   project.setName(name);
                   project.addReference(name, project);
  @@ -553,7 +551,7 @@
                       }
                   }
               }
  -
  +            project.addTarget("", context.implicitTarget);
           }
   
           /**
  @@ -576,16 +574,12 @@
                                          AntXmlContext context)
               throws SAXParseException
           {
  -            if (qname.equals("taskdef")) {
  -                return new TaskHandler(null, null, null);
  -            } else if (qname.equals("typedef")) {
  -                return new TaskHandler(null, null, null);
  -            } else if (qname.equals("property")) {
  -                return new TaskHandler(null, null, null);
  -            } else if (qname.equals("target")) {
  +            if (qname.equals("target")) {
                   return new TargetHandler();
               } else if (context.project.getDataTypeDefinitions().get(qname) != null) {
  -                return new DataTypeHandler(null);
  +                return new DataTypeHandler(context.implicitTarget);
  +            } else if (context.project.getTaskDefinitions().get(qname) != null) {
  +                return new TaskHandler(context.implicitTarget,null,context.implicitTarget);
               } else {
                   throw new SAXParseException("Unexpected element \"" + qname + "\" " + name,
context.locator);
               }
  @@ -633,6 +627,8 @@
   
                   if (key.equals("name")) {
                       name = value;
  +                    if( "".equals( name ) )
  +                        throw new BuildException("name attribute must not be empty");
                   } else if (key.equals("depends")) {
                       depends = value;
                   } else if (key.equals("if")) {
  @@ -654,6 +650,7 @@
               }
   
               target = new Target();
  +            target.addDependency( "" );
               target.setName(name);
               target.setIf(ifCond);
               target.setUnless(unlessCond);
  @@ -731,18 +728,13 @@
            *                      Must not be <code>null</code>.
            * 
            * @param container     Container for the element. 
  -         *                      May be <code>null</code> if the target is 
  -         *                      <code>null</code> as well. If the
  -         *                      target is <code>null</code>, this parameter
  -         *                      is effectively ignored.
  +         *                      Must not be <code>null</code>
            * 
            * @param parentWrapper Wrapper for the parent element, if any.
  -         *                      May be <code>null</code>. If the
  -         *                      target is <code>null</code>, this parameter
  -         *                      is effectively ignored.
  +         *                      May be <code>null</code>.
            * 
            * @param target        Target this element is part of.
  -         *                      May be <code>null</code>.
  +         *                      Must not be <code>null</code>.
            */
           public TaskHandler(TaskContainer container, RuntimeConfigurable2 parentWrapper,
Target target) {
               this.container = container;
  @@ -785,13 +777,11 @@
                   task.setTaskName(qname);
               }
   
  -            task.setLocation(new Location(context.buildFile.toString(),
  +            task.setLocation(new Location(context.locator.getSystemId(),
                                             context.locator.getLineNumber(),
                                             context.locator.getColumnNumber()));
               context.configureId(task, attrs);
   
  -            // Top level tasks don't have associated targets
  -            if (target != null) {
                   task.setOwningTarget(target);
                   container.addTask(task);
                   task.init();
  @@ -801,25 +791,11 @@
                   if (parentWrapper != null) {
                       parentWrapper.addChild(wrapper);
                   }
  -            } else {
  -                task.init();
  -                PropertyHelper.getPropertyHelper(context.project).configure(task, attrs,
context.project);
  -            }
           }
   
  -        /**
  -         * Executes the task if it is a top-level one.
  -         */
  -        public void onEndElement(String uri, String tag, AntXmlContext context) {
  -            if (task != null && target == null) {
  -                task.execute();
  -            }
  -        }
   
           /**
  -         * Adds text to the task, using the wrapper if one is
  -         * available (in other words if the task is within a target) 
  -         * or using addText otherwise.
  +         * Adds text to the task, using the wrapper
            * 
            * @param buf A character array of the text within the element.
            *            Will not be <code>null</code>.
  @@ -834,15 +810,7 @@
                                  AntXmlContext context)
               throws SAXParseException
           {
  -            if (wrapper == null) {
  -                try {
  -                    ProjectHelper.addText(context.project, task, buf, start, count);
  -                } catch (BuildException exc) {
  -                    throw new SAXParseException(exc.getMessage(), context.locator, exc);
  -                }
  -            } else {
                   wrapper.addText(buf, start, count);
  -            }
           }
           
           /**
  @@ -907,10 +875,10 @@
            *                      Must not be <code>null</code>.
            * 
            * @param parentWrapper Wrapper for the parent element, if any.
  -         *                      May be <code>null</code>.
  +         *                      Must not be <code>null</code>.
            * 
            * @param target        Target this element is part of.
  -         *                      May be <code>null</code>.
  +         *                      Must not be <code>null</code>.
            */
           public NestedElementHandler(Object parent,
                                       RuntimeConfigurable2 parentWrapper,
  @@ -962,14 +930,9 @@
   
                   context.configureId(child, attrs);
   
  -                if (parentWrapper != null) {
                       childWrapper = new RuntimeConfigurable2(child, qname);
                       childWrapper.setAttributes2(attrs);
                       parentWrapper.addChild(childWrapper);
  -                } else {
  -                    PropertyHelper.getPropertyHelper(context.project).configure(child,
attrs, context.project);
  -                    ih.storeElement(context.project, parent, child, elementName);
  -                }
               } catch (BuildException exc) {
                   throw new SAXParseException(exc.getMessage(), context.locator, exc);
               }
  @@ -992,15 +955,7 @@
                                  AntXmlContext context)
               throws SAXParseException
           {
  -            if (parentWrapper == null) {
  -                try {
  -                    ProjectHelper.addText(context.project, child, buf, start, count);
  -                } catch (BuildException exc) {
  -                    throw new SAXParseException(exc.getMessage(), context.locator, exc);
  -                }
  -            } else {
                   childWrapper.addText(buf, start, count);
  -            }
           }
   
           /**
  @@ -1080,14 +1035,9 @@
                       throw new BuildException("Unknown data type "+qname);
                   }
                   
  -                if (target != null) {
                       wrapper = new RuntimeConfigurable2(element, qname);
                       wrapper.setAttributes2(attrs);
                       target.addDataType(wrapper);
  -                } else {
  -                    PropertyHelper.getPropertyHelper(context.project).configure(element,
attrs, context.project);
  -                    context.configureId(element, attrs);
  -                }
               } catch (BuildException exc) {
                   throw new SAXParseException(exc.getMessage(), context.locator, exc);
               }
  
  
  
  1.5       +59 -72    jakarta-ant/proposal/sandbox/embed/ant-sax2.jar
  
  	<<Binary file>>
  
  

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


Mime
View raw message