antlibUrl.openConnection().connect();
} catch (IOException ex) {
throw new BuildException(
"Unable to find " + antlibUrl, ex);
}
ComponentHelper helper =
ComponentHelper.getComponentHelper(project);
helper.enterAntLib(uri);
URLResource antlibResource = new URLResource(antlibUrl);
try {
// Should be safe to parse
ProjectHelper parser = null;
Object p =
project.getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
if (p instanceof ProjectHelper) {
parser = (ProjectHelper) p;
if (!parser.canParseAntlibDescriptor(antlibResource)) {
parser = null;
}
}
if (parser == null) {
ProjectHelperRepository helperRepository =
ProjectHelperRepository.getInstance();
parser = helperRepository.getProjectHelperForAntlib(antlibResource);
}
UnknownElement ue =
parser.parseAntlibDescriptor(project, antlibResource);
// Check name is "antlib"
if (!(ue.getTag().equals(TAG))) {
throw new BuildException(
"Unexpected tag " + ue.getTag() + " expecting "
+ TAG, ue.getLocation());
}
Antlib antlib = new Antlib();
antlib.setProject(project);
antlib.setLocation(ue.getLocation());
antlib.setTaskName("antlib");
antlib.init();
ue.configure(antlib);
return antlib;
} finally {
helper.exitAntLib();
}
}