Re: Retrieving Java Packages

Svata Dedic <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.projects.devel
Organization CollabNet Hosting
Message-ID <[email protected]>
Hello, Joe (et all),

Joe Warzecha wrote:
> I defined a project nature that extends the java project nature.
> At some point, I want to retrieve the java packages that the user
> has created in the project. Is there an api call to do this?
> 
> I was able to get the packages this way:
> 
> * Retrieve JavaSourcesComponent from current Project:
>     JavaSourcesComponent [] jscs = 
>          PackagesDataObject.getDefault (curProject).getJSCs ();
> 
> * Retrieve ClassPath Roots from JavaSourcesComponent:
>     DataFolder [] dfs = jscs [i].getCPRoots ();
> 
> * Determine packages from ClassPath Roots:
>     DataObject [] dataObjs = dfs [i].getChildren ();
>     /* Go through DataObjects looking for DataFolders */
> 
> Retrieving the packages seems like something that module
> writers might want to do, so IMO it might be nice if the
> java module supplied a method to retrieve them.
> 
It's a very late reply :-) but during recent refactoring of Java module 
implementation, two classes emerged:
* JavaResource, which describes a resource as it would be seen by a 
classloader with one file visible and possibly some files hidden by the 
visible one
* JavaPackage, which contains resources, reacts to file changes by 
refreshing etc.

The root/default package can be built around a FileSet or a ClassPath 
instance.

I would consider this class as a good utility for Java module 
APIs/support if the general assessment is that working with packages 
respecting resource hiding/merging is a usual thing to do for java tools.

-Svata
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.