* @throws ExecutionException if the execution failed
*/
public void executeAntTarget(String servletContextPath, String contextPrefix,
String publicationId, File publicationDirectory, File buildFile, String target,
Map arguments, Map properties, File logFile) throws ExecutionException {
Project project = new LenyaProject(getServiceManager());
project.setCoreLoader(getClass().getClassLoader());
Throwable error = null;
try {
// create task log directory if it doesn't exist
File logDirectory = logFile.getParentFile();
if (!logDirectory.exists()) {
logDirectory.mkdirs();
}
project.setUserProperty("XmlLogger.file", logFile.getAbsolutePath());
XmlLogger logger = new XmlLogger();
project.addBuildListener(logger);
project.fireBuildStarted();
project.init();
project.setBaseDir(publicationDirectory);
ProjectHelper helper = ProjectHelper.getProjectHelper();
helper.parse(project, buildFile);
project.setUserProperty(PUBLICATION_DIRECTORY, publicationDirectory.getAbsolutePath());
project.setUserProperty(PUBLICATION_ID, publicationId);
project.setUserProperty(SERVLET_CONTEXT_PATH, servletContextPath);
project.setUserProperty(CONTEXT_PREFIX, contextPrefix);
String key;
String value;
Map.Entry entry;
for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
entry = (Map.Entry) iter.next();
key = (String) entry.getKey();
value = (String) entry.getValue();
project.setUserProperty(key, value);
}
if (target == null) {
target = project.getDefaultTarget();
}
project.executeTarget(target);
} catch (BuildException e) {
error = e;
throw new ExecutionException(e);
} finally {
project.fireBuildFinished(error);
}
}