Linked resource

*链接的含义

---代表一个资源,但是这个资源存在的地方,是在其他地方,非当前显示位置.这和软链接的概念一致,可以说是EFS的软链接.

*相关API

---哪些元素能创建link

IFolder,IFile,org.eclipse.core.internal.resources.Resource

---验证是否为link

IResource.isLinked(int options),options=IResource.CHECK_ANCESTORS,则自己或父资源任一为link,则方法返回true.

IResource.isLinked() == isLinked(IResource.NONE)

一般以createLink方式创建的为link,其下的内容就不属于link.所以CHECK_ANCESTORS区分了这2中情况.

*Broken Link

---含义,link定义的path不存在或未定义的情况 

---resource对Broken link的处理协议,

* The copy and move methods will fail when called on broken links.
* Calling refreshLocal on a broken link will not cause the resource to be removed from the workspace, as it does for normal resources that are missing from the file system.
* The method getLocation will return null for linked resources whose locations are relative to undefined path variables.
* You can still use delete to remove broken links from the workspace.

*禁用link的方式

---org.eclipse.core.resources.natures扩展点中设置"<options allowLinking="false"/>"

---org.eclipse.core.resources.teamHook,可参考TeamHook

---设置禁用属性ResourcesPlugin.PREF_DISABLE_LINKING

1.在首选项中配置,Preferences->Workspace->Linked Resources

2.Platform.getPreferencesService().getRootNode().node(InstanceScope.SCOPE)
        .node(ResourcesPlugin.PI_RESOURCES).putBoolean(ResourcesPlugin.PREF_DISABLE_LINKING, true);

3.ResourcesPlugin.getPlugin().getPluginPreferences().setValue(ResourcesPlugin.PREF_DISABLE_LINKING, "false");//@deprecated

*创建link

Linked Resource示例IWorkspace workspace =ResourcesPlugin.getWorkspace();
IPathVariableManager pvm =workspace.getPathVariableManager();
String name ="TEMP";
URI value =URI.create("file:/C:/temp");
//if(pvm.validateName(name).isOK()&&pvm.validateValue(value).isOK())
	pvm.setURIValue(name, value);
IProject proj =workspace.getRoot().getProject("bank");
IFolder folder =proj.getFolder("apps");
IFolder link =folder.getFolder("link"); //linked resource
IPath loc =new Path("TEMP/link");
	
if(workspace.validateLinkLocation(link, loc).isOK()){
	link.createLink(loc, IResource.ALLOW_MISSING_LOCAL|IResource.REPLACE, null);
	System.out.println(link.getFullPath());    //-->/bank/apps/link
	System.out.println(link.getLocation());    //-->C:/temp/link
	System.out.println(link.getRawLocation());  //-->TEMP/link
	System.out.println(link.isLinked());	//true
	
	IFile child = link.getFile("abc.txt"); //不存在
	System.out.println(child.getFullPath());  	//-->/bank/apps/link/abc.txt
	System.out.println(child.getLocation());	//-->C:/temp/link/abc.txt
	System.out.println(child.getRawLocation());	//-->C:/temp/link/abc.txt
	System.out.println(child.isLinked());	//false
	System.out.println(child.isLinked(IResource.CHECK_ANCESTORS));	//true
	System.out.println(child.exists());		//false
}

*记录link

---对于包含link的Project,在Project的".project"文件中会记录下link的信息

"When a user creates a linked resource in a project, a description of the linked resource is added to the project description file (".project") in the project's location. "

项目对link的记录<linkedResources>
    <link>
        <name>apps/link</name>
        <type>2</type> <!--2表示文件夹,1表示文件-->
        <locationURI>TEMP/link</locationURI>
    </link>
</linkedResources>


*参考

http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/resAdv_events.htm

http://www.eclipse.org/eclipse/platform-core/documents/user_settings/faq.html

转载于:https://www.cnblogs.com/bronte/articles/1960037.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值