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.
Asked
Active
Viewed 398 times
0
-
1If you want to explore the inner workings of Ant, it is best to download its sources and debug into an ant run. – wero Feb 23 '16 at 10:43
-
thank you very much for the help. I have already downloaded the source code and i'm working on the debug process. – sagar Choudhari Feb 24 '16 at 05:03
1 Answers
0
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.

sagar Choudhari
- 11
- 6
-
There is one problem with the parsing, the methods search for Target tag in the xml after it has recognized Project tag but gives Exception during parsing when any other custom tag like 'property' is used in the xml. – sagar Choudhari Feb 26 '16 at 04:58
-
Following is the exception that is seen. - Exception in thread "main" - The following error occurred while executing this line: jar:file:/../apache-ant-1.8.2-bin/apache-ant-1.8.2/lib/ant.jar!/org/apache/tools/ant/antlib.xml:37: Problem: failed to create task or type componentdef Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any
/ – sagar Choudhari Feb 26 '16 at 05:01declarations have taken place. Can anybody help out please -
I have come up with solution for the exception. I have changed the jars from ant-1.8.2 to ant-1.9.6. and now it works perfectly fine – sagar Choudhari Mar 01 '16 at 09:47