Search code examples
javaparsingantbuild.xmlbuild-tools

which Classes in ANT Source parse build.xml?


i want to know which classes in the ANT source code are used to parse the build.xml build file. after parsing this build.xml file i want to store the details that were present in the build.xml into a arraylist of targets.


Solution

  • Project and ProjectHelper are the 2 classes used to parse the ants's build.xml. Following is the the code snippet that parses the xml.

    Project project = new Project();
    File buildFile = inputFile.getFile();
    project.setUserProperty("ant.file", buildFile.getAbsolutePath());
    ProjectHelper projectHelper = ProjectHelper.getProjectHelper();
    project.addReference("ant.projectHelper", projectHelper);
    //ProjectHelper.configureProject(project, buildFile);
    projectHelper.parse(project, buildFile);
    //you can use either static method configureProject of ProjectHelper or normal parse method.
    

    The parse or configureProject reads the file you have provided and parses it and maps with the corresponding objects in the Project object.