|
Re: project.getWorkingLocation() [message #328089 is a reply to message #328079] |
Tue, 13 May 2008 20:18 |
Eclipse User |
|
|
|
Originally posted by: merks.ca.ibm.com
Fabio,
Comments below.
Fabio Mancinelli wrote:
> Dear all,
>
> I was playing with the project.getWorkingLocation() method but I have
> issues. Could anyone tell me why the following code causes an exception?
>
> IProject test =
> ResourcesPlugin.getWorkspace().getRoot().getProject("test");
> if (!test.exists()) {
> test.create(null);
> }
So you create a project test.
>
> IPath workingLocation = test.getWorkingLocation(Activator.PLUGIN_ID);
> System.out.format("Working location: %s\n", workingLocation);
And then get a working location for it...
>
> IPath folderPath = workingLocation.append("folder");
> System.out.format("Folder: %s\n", folderPath);
Then you make a path under that working location.
>
> IFolder folder =
> ResourcesPlugin.getWorkspace().getRoot().getFolder(folderPat h);
This looks bad. The working location isn't in the workspace. Keep in
mind that the paths used in these kinds of methods are workspace
relative, i.e., /project/path, not absolute file system paths.
> if(!folder.exists()) {
> folder.create(true, true, null);
> }
>
> The output is:
>
> Working location:
> /.../runtime-ResourcesTest/.metadata/.plugins/org.eclipse.co re.resources/.projects/test/test.resources
>
>
> Folder:
> /.../runtime-ResourcesTest/.metadata/.plugins/org.eclipse.co re.resources/.projects/test/test.resources/folder
>
>
> org.eclipse.core.internal.resources.ResourceException: Resource
> '/.../runtime-ResourcesTest/.metadata/.plugins/org.eclipse.c ore.resources/.projects/test/test.resources'
> does not exist.
It's pointing out that there is no IFolder that's a parent of the folder
you're trying to create.
>
> Of course if I do a "cd
> /.../runtime-ResourcesTest/.metadata/.plugins/org.eclipse.co re.resources/.projects/test/test.resources "
> the directory is there.
>
> This brings two questions:
>
> 1) Maybe the working location should be used through standard java.io
> mechanisms?
Yes.
>
> 2) Is the working location a good location for storing some frequently
> recomputed information such as cache indexes, temp files, etc.? In my
> application I don't want to flood listeners with resource change
> events for data that is never used directly and that should not be
> accessible from the project.
Hmmm. Good question. I suspect that it is good for that, but my
comment isn't well informed.
>
> Thank you for your hints.
>
> Cheers,
> Fabio
|
|
|
|
Powered by
FUDForum. Page generated in 0.03365 seconds