Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » List of source folders on build path
List of source folders on build path [message #111557] Tue, 28 October 2003 22:33 Go to next message
Vijay Ganesan is currently offline Vijay GanesanFriend
Messages: 40
Registered: July 2009
Member
Given an IJavaProject, how do I programatically get a list of all source
folders on build path?
I am able to get the output folder by using getOutputLocation() but I can't
seem to find anything in the API docs to get the source folders.
Thanks

Vijay
Re: List of source folders on build path [message #111681 is a reply to message #111557] Wed, 29 October 2003 11:44 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
IJavaProject javaProject = ...;
ArrayList sourceFolders = new ArrayList();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IClasspathEntry[] entries = javaProject..getResolvedClasspath(true);
for (int i = 0; i < entries.length; i++) {
IClasspathEntry entry = entries[i];
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPath path = entry.getPath();
IFolder sourceFolder = root.getFolder(path);
sourceFolders.add(sourceFolder);
}
}

Jerome

"Vijay Ganesan" <vijay@mindspring.com> wrote in message
news:bnmqpl$cnh$1@eclipse.org...
>
> Given an IJavaProject, how do I programatically get a list of all source
> folders on build path?
> I am able to get the output folder by using getOutputLocation() but I
can't
> seem to find anything in the API docs to get the source folders.
> Thanks
>
> Vijay
>
>
Re: List of source folders on build path [message #111797 is a reply to message #111681] Thu, 30 October 2003 03:40 Go to previous messageGo to next message
Vijay Ganesan is currently offline Vijay GanesanFriend
Messages: 40
Registered: July 2009
Member
Jerome,
This works except for this situation:
I created a project called "djsk" and added some files (in the default
package) without creating a source folder. The source folder on build path
is djsk
Now I get the following exception:
java.lang.IllegalArgumentException: Path must include project and resource
name: /djsk
on the call:
IFolder sourceFolder = root.getFolder(path);

Looks like I *have* to create folders in the project to put my source?

Thanks
Vijay

--stack trace--
at org.eclipse.core.internal.utils.Assert.isLegal(Assert.java:5 5)
at
org.eclipse.core.internal.resources.Workspace.newResource(Wo rkspace.java:144
2)
at
org.eclipse.core.internal.resources.Container.getFolder(Cont ainer.java:129)


"Jerome Lanneluc" <jerome_lanneluc@fr.ibm.com> wrote in message
news:bno94e$ull$1@eclipse.org...
> IJavaProject javaProject = ...;
> ArrayList sourceFolders = new ArrayList();
> IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
> IClasspathEntry[] entries = javaProject..getResolvedClasspath(true);
> for (int i = 0; i < entries.length; i++) {
> IClasspathEntry entry = entries[i];
> if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
> IPath path = entry.getPath();
> IFolder sourceFolder = root.getFolder(path);
> sourceFolders.add(sourceFolder);
> }
> }
>
> Jerome
>
> "Vijay Ganesan" <vijay@mindspring.com> wrote in message
> news:bnmqpl$cnh$1@eclipse.org...
> >
> > Given an IJavaProject, how do I programatically get a list of all source
> > folders on build path?
> > I am able to get the output folder by using getOutputLocation() but I
> can't
> > seem to find anything in the API docs to get the source folders.
> > Thanks
> >
> > Vijay
> >
> >
>
>
Re: List of source folders on build path [message #112013 is a reply to message #111797] Thu, 30 October 2003 10:32 Go to previous message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
No, you just need to check if the IPath has only 1 segment. In this case use
getProject(...) instead of getFolder(...).

Jerome

"Vijay Ganesan" <vijay@mindspring.com> wrote in message
news:bnq157$vmf$1@eclipse.org...
> Jerome,
> This works except for this situation:
> I created a project called "djsk" and added some files (in the default
> package) without creating a source folder. The source folder on build path
> is djsk
> Now I get the following exception:
> java.lang.IllegalArgumentException: Path must include project and resource
> name: /djsk
> on the call:
> IFolder sourceFolder = root.getFolder(path);
>
> Looks like I *have* to create folders in the project to put my source?
>
> Thanks
> Vijay
>
> --stack trace--
> at org.eclipse.core.internal.utils.Assert.isLegal(Assert.java:5 5)
> at
>
org.eclipse.core.internal.resources.Workspace.newResource(Wo rkspace.java:144
> 2)
> at
>
org.eclipse.core.internal.resources.Container.getFolder(Cont ainer.java:129)
>
>
> "Jerome Lanneluc" <jerome_lanneluc@fr.ibm.com> wrote in message
> news:bno94e$ull$1@eclipse.org...
> > IJavaProject javaProject = ...;
> > ArrayList sourceFolders = new ArrayList();
> > IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
> > IClasspathEntry[] entries = javaProject..getResolvedClasspath(true);
> > for (int i = 0; i < entries.length; i++) {
> > IClasspathEntry entry = entries[i];
> > if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
> > IPath path = entry.getPath();
> > IFolder sourceFolder = root.getFolder(path);
> > sourceFolders.add(sourceFolder);
> > }
> > }
> >
> > Jerome
> >
> > "Vijay Ganesan" <vijay@mindspring.com> wrote in message
> > news:bnmqpl$cnh$1@eclipse.org...
> > >
> > > Given an IJavaProject, how do I programatically get a list of all
source
> > > folders on build path?
> > > I am able to get the output folder by using getOutputLocation() but I
> > can't
> > > seem to find anything in the API docs to get the source folders.
> > > Thanks
> > >
> > > Vijay
> > >
> > >
> >
> >
>
>
Previous Topic:Compiling a single java source file
Next Topic:Crash while debugging java apps
Goto Forum:
  


Current Time: Wed Apr 24 16:22:24 GMT 2024

Powered by FUDForum. Page generated in 0.02287 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top