Sunday June 15, 2008
From FileObjects to Projects
Finding the Project that the FileObject belongs to and then getting information about the Project, in this case in a class that extends org.apache.tools.ant.module.spi.AntLogger:
@Override
public void targetStarted(AntEvent event) {
File buildImplXML = event.getScriptLocation();
FileObject buildImplXMLFo = FileUtil.toFileObject(buildImplXML);
String targetName = event.getTargetName();
//Get the project that the FileObject belongs to:
Project proj = FileOwnerQuery.getOwner(buildImplXMLFo);
if (null != proj) {
//Get the project information from ProjectUtils:
ProjectInformation info = ProjectUtils.getInformation(proj);
//Get the project display name from the project information:
String projectName = info.getDisplayName();
//Get the project icon from the project information:
Icon icon = info.getIcon();
//Process the information further, depending on your needs:
if (targetName.equals("run")) {
ListDeployedAppsAction.setProjectNames(buildImplXML, projectName, icon);
}
}
}
As a result, there's no need to parse the project.xml as I had been doing a few days ago, for the project name and type. Thanks to Jesse for recently pointing the above out to me.
Jun 15 2008, 08:03:34 PM PDT Permalink


