您的位置:首页 > 编程语言 > Java开发

Eclipse变量插件问题

2016-07-04 16:38 375 查看
Eclipse变量插件问题
 

最近在研究JDT的源代码,因为首先感兴趣的是调试相关的功能,所以在查看JDT的源代码之前,首先看到Eclipse上的两篇比较不错的文章:

《We Have Lift-off  The Launching Framework in Eclipse》和

《How to Write an Eclipse Debugger》

前面一篇讲解了Eclipse的”启动框架”,后一篇讲解了Eclipse的调试框架。后一篇中,作者有个示例插件,我下下来调试,学习。在学习过程中,碰到一个奇怪的问题,就是我修改了plugin.xml文件后,却并不能生效,例如,这是原先的内容:

<extension
         point="org.eclipse.core.variables.valueVariables">
      <variable
    initialValue="c:\perl\bin\perl.exe"
            name="perlExecutable"
            description="Path to Perl executablein the local file system">
      </variable>
   </extension>

 

我修改为:

<extension
         point="org.eclipse.core.variables.valueVariables">
      <variable
            initialValue="D:\app\Administrator\product\11.2.0\dbhome_1\perl\bin\"
            name="perlExecutable"
            description="Path to Perl executablein the local file system">
      </variable>
   </extension>
 
第一次修改生效了,然后第二次我是在,“被调试的Eclipse进程”执行的时候修改为:
<extension
         point="org.eclipse.core.variables.valueVariables">
      <variable
            initialValue="D:\app\Administrator\product\11.2.0\dbhome_1\perl\bin\perl.exe"
            name="perlExecutable"
            description="Path to Perl executablein the local file system">
      </variable>
   </extension>
 
结果,没有起作用,而且后面无论我怎么操作,这个值就一直保持为:”D:\app\Administrator\product\11.2.0\dbhome_1\perl\bin\”。无论我是重启Eclipse也好,还是加-clean参数,都无济于事,百度和google了好长时间,也没找到问题所在,无奈之下,只好去查看org.eclipse.core.variables.valueVariables的源代码,终于发现了问题所在。请看以下代码:
/**
     * Load contributedvariables and persisted variables
     */
    private synchronized void initialize() {
       if (fDynamicVariables == null) {
           fInternalChange = true;
           fDynamicVariables = new HashMap(5);
           fValueVariables = new HashMap(5);
           loadContributedValueVariables();
           loadPersistedValueVariables();
           loadDynamicVariables();
       InstanceScope.INSTANCE.getNode(VariablesPlugin.PI_CORE_VARIABLES).addPreferenceChangeListener(this);
           fInternalChange = false;
       }
    }
 
这里,在StringVariableManager 初始化的时候会先加载插件中的变量,然后再加载“持久化的变量值”。跟踪loadPersistedValueVariables()会发现perlExecutable 的值为D:\app\Administrator\product\11.2.0\dbhome_1\perl\bin\。
因此,修改后并不起作用。总会被覆盖掉,那么要怎么清除这个值呢?
 
Eclipse的Preferences的值是保存在以下位置的:
${workspace}\.metadata\.plugins\org.eclipse.core.runtime\.settings
 
打开org.eclipse.core.variables.prefs文件,是个xml文件,保存的就是变量的值。删掉这个文件,自然就会读取插件文件中定义的值。
 
总结:
   Eclipse的VariablesPlugin 会将定义的变量存储在工作空间的preferences中,如果修改plugin.xml文件中的变量值没有生效,最好检查一下工作空间中是否已经保存了值,如果保存了,需要删除这个文件,才能生效。
 
//*****************************************************************/
//**  本人原创文章,转摘请保留本段内容,万分感谢!
//**  microdreamsoft(Lin Shaohua):
//**  由于本人水平有限,欢迎各位高手指正。
//**  本人所有原创文章将发布在以下blog:
//**   http://hi.baidu.com/microdreamsoft //**   http://blog.csdn.net/hydream //**   http://www.cnblogs.com/MicroDreamSoft/ //**   http://websoso.bokee.com //**   http://89727175.qzone.qq.com //**   http://751728871.qzone.qq.com //*****************************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: