Tas
Tas

Reputation: 285

Resource is not local - creating files in Eclipse plugin

So, I'm trying to set up my Eclipse plugin so that it can process some data and generate some files within a project. I can create an IFolder using project.getFolder().create and create the right IFile objects with project.getFile().create(). Once created, however, they show up in the project navigator, but I get a lot of error about the resources being "not local," and they don't seem to show up in my filesystem. What's happening, and what do I need to change?

Here's the code to create the folder:

IFolder f = project.getFolder(folderName);
if (!f.exists()) f.create(false, false, null);

And my code for creating an IFile is essentially the same. The plugin is just running on my local file system, so I assume it's something in my code creating the error.

Upvotes: 2

Views: 2171

Answers (3)

Elliotte Rusty Harold
Elliotte Rusty Harold

Reputation: 991

Check your input stream. If it's null or throws an IOException, f.create will still succeed. However the file will appear as not local in the Eclipse UI.

Upvotes: 2

P Mendham
P Mendham

Reputation: 251

I had the same problem, and I still don't understand it, but I do have something working. I didn't have a problem with folders, only with files. At first I was trying to set the file contents when creating the file:

file.create(contents, true, monitor);

This didn't work and I got the "Resource is not local" problem.

By splitting up the setting of the content into a separate step, suddenly things started to work:

file.create(new ByteArrayInputStream(new byte[0]), true, monitor);
file.setContents(content, false, false, monitor);

I hope that helps someone.

Upvotes: 1

Robin
Robin

Reputation: 151

IFolder f = project.getFolder(folderName);
if (!f.exists()) f.create(false, false, null);

In the second parameter in the f.create(...) method if set to true will make the folder LOCAL and errors will not come (at least it stopped in my case). Also, I saw these errors coming from team providers (like git etc).

Upvotes: 1

Related Questions