Creating source folder programmatically [message #316726] |
Fri, 15 June 2007 17:41  |
Eclipse User |
|
|
|
Originally posted by: neelesh.thakur.yahoo.com
Hi
Can any one tell me how can I create source folder programmatically. I
want to create source folder in my plugin.
I have tried but it is giving Java Model Exception.. here is my code..
IProject iProject = iJavaProject.getProject();
IFolder iFolder = iProject.getFolder("src-JUnit");
IPath sourceFolderPath = iFolder.getFullPath();
IClasspathEntry entry = JavaCore.newSourceEntry(sourceFolderPath);
IClasspathEntry[] entries = iJavaProject.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[newEntries.length - 1] = entry;
iJavaProject.setRawClasspath(newEntries, new NullProgressMonitor());
and here is the exception trail..
Java Model Exception: Java Model Status [Cannot nest 'exp/src-JUnit'
inside 'exp'. To enable the nesting exclude 'src-JUnit/' from 'exp']
at
org.eclipse.jdt.internal.core.JavaModelOperation.runOperatio n(JavaModelOperation.java:775)
at
org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(Ja vaProject.java:3016)
at
org.eclipse.jdt.internal.core.JavaProject.setRawClasspath(Ja vaProject.java:3032)
at
treeviewmultpage.views.SampleView.createJunitSRCFolder(Sampl eView.java:275)
Any help will be appreciated.
Thanks
Neelesh
|
|
|
|
|
|
Re: Creating source folder programmatically [message #316746 is a reply to message #316743] |
Sun, 17 June 2007 17:27  |
Eclipse User |
|
|
|
Originally posted by: automatic.javalobby.org
If you have a folder A and a folder A/B, then you need to update the parent folder (A) to exclude any of B's content (so that A doesn't compile all of B's stuff).
This happens automatically when you do it in the menus (something like 'update exclusion lists automatically) but I suspect you have to do it on your own if you want to do it programmatically.
You could try having different folders, e.g. A and B, which wouldn't need that workaround.
If your main location is the project root itself, then you could try removing that. It probably involves trying to get the parent folder (e.g. A above, or the project root) and then setting exclusion filters on the IClassPathEntry
http://help.eclipse.org/help32/topic/org.eclipse.jdt.doc.isv /reference/api/org/eclipse/jdt/core/IClasspathEntry.html
However, I don't know how you'd go about changing them, or even if this is the right approach. Have a look and see how it's done when a new source folder wizard is running.
Alex.
|
|
|
Powered by
FUDForum. Page generated in 0.03329 seconds