Eclipse變量插件問題

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

//*****************************************************************/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章