FileDocCategorySizeDatePackage
ProjectHelperImpl.javaAPI DocApache Ant 1.7041951Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.helper

ProjectHelperImpl

public class ProjectHelperImpl extends org.apache.tools.ant.ProjectHelper
Original helper.

Fields Summary
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
helper for path -> URI and URI -> path conversions.
private Parser
parser
SAX 1 style parser used to parse the given file. This may in fact be a SAX 2 XMLReader wrapped in an XMLReaderAdapter.
private org.apache.tools.ant.Project
project
The project to configure.
private File
buildFile
The configuration file to parse.
private File
buildFileParent
Parent directory of the build file. Used for resolving entities and setting the project's base directory.
private Locator
locator
Locator for the configuration file parser. Used for giving locations of errors etc.
private org.apache.tools.ant.Target
implicitTarget
Target that all other targets will depend upon implicitly.

This holds all tasks and data type definitions that have been placed outside of targets.

Constructors Summary
public ProjectHelperImpl()
default constructor


           
      
        implicitTarget.setName("");
    
Methods Summary
private voidconfigureId(java.lang.Object target, org.xml.sax.AttributeList attr)
Scans an attribute list for the id attribute and stores a reference to the target object in the project if an id is found.

This method was moved out of the configure method to allow it to be executed at parse time.

see
#configure(Object,AttributeList,Project)

        String id = attr.getValue("id");
        if (id != null) {
            project.addReference(id, target);
        }
    
private static voidhandleElement(org.apache.tools.ant.helper.ProjectHelperImpl helperImpl, org.xml.sax.DocumentHandler parent, org.apache.tools.ant.Target target, java.lang.String elementName, org.xml.sax.AttributeList attrs)
Start a new DataTypeHandler if element is known to be a data-type and a TaskHandler otherwise.

Factored out of TargetHandler.

since
Ant 1.6

        if (elementName.equals("description")) {
            new DescriptionHandler(helperImpl, parent);
        } else if (helperImpl.project.getDataTypeDefinitions()
                   .get(elementName) != null) {
            new DataTypeHandler(helperImpl, parent, target)
                .init(elementName, attrs);
        } else {
            new TaskHandler(helperImpl, parent, target, null, target)
                .init(elementName, attrs);
        }
    
public voidparse(org.apache.tools.ant.Project project, java.lang.Object source)
Parses the project file, configuring the project as it goes.

param
project project instance to be configured.
param
source the source from which the project is read.
exception
BuildException if the configuration is invalid or cannot be read.

        if (!(source instanceof File)) {
            throw new BuildException("Only File source supported by "
                + "default plugin");
        }
        File bFile = (File) source;
        FileInputStream inputStream = null;
        InputSource inputSource = null;

        this.project = project;
        this.buildFile = new File(bFile.getAbsolutePath());
        buildFileParent = new File(this.buildFile.getParent());

        try {
            try {
                parser = JAXPUtils.getParser();
            } catch (BuildException e) {
                parser = new XMLReaderAdapter(JAXPUtils.getXMLReader());
            }


            String uri = FILE_UTILS.toURI(bFile.getAbsolutePath());
            inputStream = new FileInputStream(bFile);
            inputSource = new InputSource(inputStream);
            inputSource.setSystemId(uri);
            project.log("parsing buildfile " + bFile + " with URI = "
                + uri, Project.MSG_VERBOSE);
            HandlerBase hb = new RootHandler(this);
            parser.setDocumentHandler(hb);
            parser.setEntityResolver(hb);
            parser.setErrorHandler(hb);
            parser.setDTDHandler(hb);
            parser.parse(inputSource);
        } catch (SAXParseException exc) {
            Location location =
                new Location(exc.getSystemId(), exc.getLineNumber(),
                    exc.getColumnNumber());

            Throwable t = exc.getException();
            if (t instanceof BuildException) {
                BuildException be = (BuildException) t;
                if (be.getLocation() == Location.UNKNOWN_LOCATION) {
                    be.setLocation(location);
                }
                throw be;
            }

            throw new BuildException(exc.getMessage(), t, location);
        } catch (SAXException exc) {
            Throwable t = exc.getException();
            if (t instanceof BuildException) {
                throw (BuildException) t;
            }
            throw new BuildException(exc.getMessage(), t);
        } 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.getMessage(), exc);
        } finally {
            FileUtils.close(inputStream);
        }