发现 Eclipse 中未解析的插件依赖性(3)
2008-02-23 08:10:04来源:互联网 阅读 ()
步骤 2:对 plugin.xml 文件进行递归搜索,从而遍历整个依赖链
当用户选择希望解析依赖链的插件之后,我们就需要对用户所选择的插件的 plugin.xml 文件进行分析,从而查看它的依赖性。每个依赖性都会导致检查另外一个 plugin.xml 文件,后者又有自己的依赖性。从用户选择的插件开始,这个依赖链可以迅速导致有很多个 plugin.xml 文件需要进行分析。我们可以编写一个递归函数来遍历这些依赖性,它可以查找某个插件的最新版本(针对在相同的系统中有重复插件的情况)以及它的所有依赖性。
编写这种递归函数需要执行的步骤如下所示,清单 3 给出了这个函数的源代码。递归函数有时对资源的消耗量很大,而且在用户失去耐心之前可能还没有返回结果。另外一种选择是编写一个函数,只获取用户选择的插件的直接依赖性清单。后一种方法请参看样例代码中的 loadImmediateDependencies() 函数。
- 获得用户选择的插件的路径。
- 检查这个位置上是否存在 plugin.xml 或 fragment.xml 文件。
- 对 plugin.xml 或 fragment.xml 文件进行分析,从而获得这个插件所需要的所有插件的清单。
- 对于这个清单中的每个插件 ID,寻找对应的插件。
- 如果多个插件具有相同的 ID,就只向用户报告一次,并自动确定使用版本较新的插件。如何编程对插件版本进行比较并寻找一个版本较新的插件,请参看图 4。
- 将(步骤 4 或 4a 中找到的)插件添加到一个树视图中,并递归地调用相同的函数,再次从步骤 1 开始重新执行。不过这次用户不用再选择插件了;步骤 4 或 4a 对应的代码会负责选择插件。
清单 3. recursivePluginDependencyWalker() 函数
private Vector alreadyNotified = new Vector();
private boolean firstCall = true;
private TreeParent root = null;
private void recursivePluginDependencyWalker(PluginData pdObject,
TreeParent parentNode){
try {
String path = pdObject.getPluginLocation();
PluginParser pp = null;
File pluginDotXmlFile = new File(path "/plugin.xml");
if(pluginDotXmlFile.exists()){
pp = new PluginParser(pluginDotXmlFile);
}else{
File fragmentDotXmlFile = new File(path
"/fragment.xml");
if(fragmentDotXmlFile.exists()){
pp = new PluginParser(fragmentDotXmlFile);
}else{
return;//no plugin.xml or fragment.xml found
}
}
String displayName = pdObject.getDisplayName();
System.out.println("\nPlugin [" displayName "]
requires" "\n");
String requires[] = pp.getDependencyList();
if(0 != requires.length ){
for(int i=0; i<requires.length; i ){
System.out.println("\t" requires[i] );
PluginData pd[] =
getPluginDataObjectsFromPluginID(requires[i]);
PluginData nextPlugin = null;
switch(pd.length){
case 0:
//great, we know there is
//something missing
nextPlugin = null;
break;
case 1:
//best case, everything will be smooth
nextPlugin = pd[0];
break;
default:
//worst case, there must be more
//than 1 plugin with the same id
//at different locations.
String msgLine1 =
"Plugin " displayName
" requires "
requires[i] "\n";
String msgLine2 =
"Duplicate plug-ins found for ID: \
" " requires[i]
"\""
"\n Continuing with higher version...
" ;
//it is bad to give repeated
//reminders,
//so remind only once per plugin id.
if(! alreadyNotified.contains(
new String(requires[i]))){
MessageDialog.openInformation(null,
"Dependency Walker",
msgLine1
msgLine2);
alreadyNotified.add(
new String(requires[i]));
}
//always take the better
//version anyway
nextPlugin =
getBetterVersionPlugin(pd);
break;
}//end of switch
if( null != nextPlugin ){
TreeParent nextinLine =
new TreeParent(
nextPlugin.getDisplayName(),
nextPlugin.isPlugin
LoadedInRegistry()
);
parentNode.addChild(nextinLine);
recursivePluginDependencyWalker(
nextPlugin,
nextinLine);
}else{
TreeParent nextinLine =
new TreeParent(
requires[i]
" [This plug-in is missing]
",
false);
parentNode.addChild(nextinLine);
//obviously we can't recurse
//into a missing plugin...
}
}//end of for
}else{
System.out.println("\t NOTHING:
No further dependency \n" );
//no further dependency
}
} catch (Exception e) {
e.printStackTrace();
}
}有时候,我们会碰到在不同位置存在具有相同 ID 的插件的情况。例如,ID 为 org.eclipse.xsd 的插件可能会在 <targetPlatform>\eclipse\plugins 文件夹和 <someLinkedPath>\eclipse\plugins 文件夹中同时出现。
在这种情况中,必须要确定从这两个或更多个磁盘副本中选用哪个插件。显然,我们所感兴趣的应该是最新的插件,也就是说,版本较新的插件。我们可以利用现有的一些函数来对 Eclipse 插件的版本进行比较,或者可以基于清单 4 所示的样例代码编写一个简单的函数来对插件版本进行比较。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:提升JSP应用程序七大绝招
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
