Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » creating source folder
creating source folder [message #310449] Mon, 04 December 2006 00:57 Go to next message
Eclipse UserFriend
hi all,
how do I create source folder programmatically.
please help me

thanks in advance
parag
Re: creating source folder [message #310450 is a reply to message #310449] Mon, 04 December 2006 01:34 Go to previous messageGo to next message
Eclipse UserFriend
Parag wrote:
> how do I create source folder programmatically.

Since you said programmatically, I'm assuming you're using the JDT APIs?
You'll need to update your IJavaProject's raw classpath.

// get your IProject
IProject project = getProject();
// create the corresponding IJavaProject
IJavaProject ijp = JavaCore.create(project);
// get the folder
IFolder folder = project.getFolder("nameOfNewSrcFolder");
// create a new source entry for it
IClasspathEntry entry = JavaCore.newSourceEntry(folder.getFullPath());
// retrieve the project's current classpath
IClasspathEntry[] entries = ijp.getRawClasspath();
// create a new array with the original entries and the new source entry
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[newEntries.length - 1] = entry;
ijp.setRawClasspath(newEntries, new NullProgressMonitor());

That should be the general gist of it.

Regards,
Rem
Re: creating source folder [message #310451 is a reply to message #310450] Mon, 04 December 2006 03:59 Go to previous messageGo to next message
Eclipse UserFriend
thanks for reply
but I am using CDT
how should I do this in CDT

please help me

parag
Re: creating source folder [message #310463 is a reply to message #310451] Mon, 04 December 2006 13:48 Go to previous messageGo to next message
Eclipse UserFriend
Parag wrote:
> thanks for reply
> but I am using CDT how should I do this in CDT

Try in eclipse.tools.cdt ... they'll have instructions for the CDT tool.

Later,
PW
Re: creating source folder [message #310531 is a reply to message #310463] Thu, 07 December 2006 04:26 Go to previous messageGo to next message
Eclipse UserFriend
I have posted the same problem on CDT newsgroups but nobody replied yet,
so I come to Platform
please help Me
Re: creating source folder [message #310534 is a reply to message #310531] Thu, 07 December 2006 05:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------070503080501090305000102
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Parag,

This is a little bit like looking for your lost key under the street
light in front of the house because the light is brightest there even
though you know the key was lost in the back yard where it's darker...

Few of us here would know the CDT APIs for how to create a source
folder. I wonder if a search like this would turn up answers:

http://www.eclipse.org/search/search.cgi?q=create+source+fol der&cmd=Search%21&form=extended&wf=574a74&ps =10&m=all&t=5&ul=%2Fnewslists%2Fnews.eclipse.too ls.cdt&wm=wrd&t=News&t=Mail
< http://www.eclipse.org/search/search.cgi?q=create+source+fol der&cmd=Search%21&form=extended&wf=574a74&ps =10&m=all&t=5&ul=%2Fnewslists%2Fnews.eclipse.too ls.cdt&wm=wrd&t=News&t=Mail>


Parag wrote:
> I have posted the same problem on CDT newsgroups but nobody replied
> yet, so I come to Platform
> please help Me
>
>
>


--------------070503080501090305000102
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Parag,<br>
<br>
This is a little bit like looking for your lost key under the street
light in front of the house because the light is brightest there even
though you know the key was lost in the back yard where it's darker...<br>
<br>
Few of us here would know the CDT APIs for how to create a source
folder.
Re: creating source folder [message #310547 is a reply to message #310534] Thu, 07 December 2006 09:57 Go to previous message
Eclipse UserFriend
I tried with below method in NewCProjectWizard.java, while creating new
project I want source folder to be created with it. I call this method in
performFinish() mehtod.
But it creates two source folder with same name "src", out of which one
is source folder & other is normal folder.

If I uncomment the condition given at line no. 28 then it gives me only
one soruce folder but it's normal folder not source folder.
What should I do,
please tell me.


/*********************************************************** **********/
1 public void createSrc() {
2 StatusInfo fRootStatus = new StatusInfo();
3 StatusInfo fProjectSt1atus = new StatusInfo();
4 boolean fIsProjectAsSourceFolder = false;
5
6 ICProject fCurrCProject;
7 IPathEntry[] fEntries;
8 StatusInfo fProjectStatus = null;
9 IPathEntry[] fNewEntries;
10 ISourceRoot sourceRoot;
11
12 boolean isSelected = fMainPage.getTemplateSelection();
13 if (isSelected) {
14 String path = newProject.getProject().getFullPath().toString();
15 IPath prjPath = newProject.getProject().getFullPath().append("src");
16 IFolder srcFolder = newProject.getProject().getFolder("src");
17 try {
18 CoreUtility.createFolder(srcFolder, true, true,
19 new SubProgressMonitor(tempMonitor, 1));
20 if (tempMonitor.isCanceled()) {
21 throw new InterruptedException();
22 }
23
24 /*
25 * if I uncomment the following condition it gives me one "src"
26 * folder but it's normal folder not source folder.
27 */
28 // if (newProject.hasNature(CProjectNature.C_NATURE_ID) ||
29 // newProject.hasNature(CCProjectNature.CC_NATURE_ID)) {
30 fCurrCProject = CoreModel.getDefault().create(newProject);
31 fEntries = fCurrCProject.getRawPathEntries();
32 fProjectStatus.setOK();
33 // return;
34 // }
35
36 // fCurrCProject.setRawPathEntries(fNewEntries, new
37 // SubProgressMonitor(monitor, 2));
38 // fCreatedRoot= fCurrCProject.findSourceRoot(folder);
39
40 ArrayList newEntries = new ArrayList(fEntries.length + 1);
41 int projectEntryIndex = -1;
42
43 for (int i = 0; i < fEntries.length; i++) {
44 IPathEntry curr = fEntries[i];
45 if (curr.getEntryKind() == IPathEntry.CDT_SOURCE) {
46 if (path.equals(curr.getPath())) {
47 fRootStatus.setError(NewFolderWizardMessages.getString("NewSourceFolderWizardPage.error.AlreadyExisting "));
//$NON-NLS-1$
48 return;
49 }
50 if (path.equals(curr.getPath())) {
51 projectEntryIndex = i;
52 }
53 }
54 newEntries.add(curr);
55 }
56
57 IPathEntry newEntry =
CoreModel.newSourceEntry(srcFolder.getFullPath());
58
59 Set modified = new HashSet();
60 // if (fExcludeInOthersFields.isSelected()) {
61 // addExclusionPatterns(newEntry, newEntries, modified);
62 // newEntries.add(CoreModel.newSourceEntry(path));
63 // } else {
64 if (projectEntryIndex != -1) {
65 fIsProjectAsSourceFolder = true;
66 newEntries.set(projectEntryIndex, newEntry);
67 } else {
68 newEntries.add(CoreModel.newSourceEntry(srcFolder
.getFullPath()));
69 }
70 // }
71
72 fNewEntries = (IPathEntry[]) newEntries
.toArray(new IPathEntry[newEntries.size()]);
73 fCurrCProject.setRawPathEntries(fNewEntries,
new SubProgressMonitor(tempMonitor, 2));
74
75 sourceRoot = fCurrCProject.findSourceRoot(srcFolder);
76
78 } catch (Exception e) {
79 CUIPlugin.getDefault().log(e);
80 } finally {
81 tempMonitor.done();
82 }
83 }
84 }
/*********************************************************** **********/

Thanks,
parag
Previous Topic:Navigation History
Next Topic:Creating a window dialog
Goto Forum:
  


Current Time: Sat May 10 16:50:44 EDT 2025

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

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

Back to the top