Sunday Jun 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.

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« June 2008 »
SunMonTueWedThuFriSat
1
6
13
19
26
28
29
     
       
Today