modulitos
modulitos

Reputation: 15814

Eclipse API: How to check whether an IFile is a .project or .classpath file?

Simply put, here is my question:

If given an IFile, is there a way to check whether that IFile is a .classpath file or a .project file?

Here is the full scoop:

I am implementing a resource synchronizer as part of an Eclipse plug-in that is creating a "copy codebase" (a copy of the entire workspace) using "resource changed messages" that I have arranged to be received. These messages indicate which resources I must add/change/delete. For example, when a Java Project is added, I am receiving the following 4 messages in this order:

  1. {ADD ".classpath" FILE}
  2. {ADD ".project" FILE}
  3. {ADD "org.eclipse.jdt.core.prefs" FILE}
  4. {ADD "src" FOLDER}.

In order to create the PROJECT resource in this example, I ensure that the parents of each resource in the message exists. So when I create each resource, I check that the resource's parent resource exists - if not, I create the parent resource (like the PROJECT resource for the first ".classpath" message in our example) and then I recursively check whether the parent's parent exists.

My problem is that Eclipse automatically creates a ".project" file when a PROJECT is created, so the {ADD ".project" FILE} message becomes redundant. If I could only detect when I am processing the {ADD ".classpath" FILE} message, then I can selectively create a PROJECT, then immediately delete the automatically generated ".project" file, and not have any conflicts when I process the next message (which is the {ADD ".project" FILE}).

Upvotes: 1

Views: 371

Answers (1)

greg-449
greg-449

Reputation: 111142

These file names are fixed so you can just check for the name if the file is in the project root folder.

org.eclipse.core.resources.IProjectDescription.DESCRIPTION_FILE_NAME is the standard constant for .project and org.eclipse.jdt.core.IJavaProject.CLASSPATH_FILE_NAME for .classpath.

Upvotes: 2

Related Questions