[英]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? 如果提供了IFile,是否可以检查IFile是.classpath
文件还是.project
文件?
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. 我正在实现一个资源同步器,作为Eclipse插件的一部分,该插件使用我准备接收的“资源已更改的消息”来创建“复制代码库”(整个工作区的副本)。 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: 例如,当添加一个Java项目时,我将按以下顺序接收以下4条消息:
In order to create the PROJECT resource in this example, I ensure that the parents of each resource in the message exists. 为了在此示例中创建PROJECT资源,我确保消息中每个资源的父级都存在。 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. 因此,当我创建每个资源时,我都会检查资源的父资源是否存在-如果不存在,则会创建父资源(如示例中第一个“ .classpath”消息的PROJECT资源),然后递归检查父资源的父资源存在。
My problem is that Eclipse automatically creates a ".project" file when a PROJECT is created, so the {ADD ".project" FILE} message becomes redundant. 我的问题是创建项目时Eclipse自动创建一个“ .project”文件,因此{ADD“ .project” FILE}消息变得多余。 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}). 如果我只能检测到何时处理{ADD“ .classpath” FILE}消息,则可以有选择地创建一个PROJECT,然后立即删除自动生成的“ .project”文件,并且在处理下一个时没有任何冲突。消息(即{ADD“ .project” FILE})。
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
. org.eclipse.core.resources.IProjectDescription.DESCRIPTION_FILE_NAME
是.project
的标准常量, org.eclipse.jdt.core.IJavaProject.CLASSPATH_FILE_NAME
是.classpath
的标准常量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.