2009-07-29 23 views
2

使用RCP更新站點禁止孤立插件,否則插件不在功能中。 如果未填寫此條件,則更新管理器將返回以下錯誤: 生成的配置不包含平臺。如何在eclipse RCP中找到孤立插件?

不幸的是,沒有辦法確定哪些插件是孤兒。 如何找到孤兒插件?

回答

4

這是一個起點(這適用於Eclipse 3.4及更高版本,當引入P2存儲庫時,早期版本以不同的方式存儲其配置,IIRC可以看到platform.xml中的所有插件和功能)。

用「Hello World」模板創建一個新的插件項目(New-> Other-> Plug-in Development-> Plug-in Project),然後將此代碼放入SampleAction的run方法中。

運行該插件作爲測試Eclipse應用程序並選擇Sample Menu-> Sample Action,不屬於某個功能的插件將輸出到父級工作區的控制檯。當我運行這個時,有不止一次的預期,我已經看了幾遍,看不出邏輯錯誤。

編輯,發現邏輯錯誤,使用了最內層循環中使用的錯誤數組索引。儘管如此,仍然不太合適。

編輯2.(Facepalm時刻)發現問題。請務必使用所有工作空間運行目標工作區,並啓用目標插件,否則顯然會導致結果偏斜。如果你安裝插件並打扮一下,你就不會有這個問題。

//get all the plugins that belong to features 
IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); 

Map<Long, IBundleGroup> bundlesMap = new HashMap<Long, IBundleGroup>(); 

if (providers != null) { 
    for (int i = 0; i < providers.length; i++) { 
     IBundleGroup[] bundleGroups = providers[i].getBundleGroups(); 

     System.out.println("Bundle groups:"); 
     for (int j = 0; j < bundleGroups.length; j++) { 
      Bundle[] bundles = bundleGroups[j] == null ? new Bundle[0] : bundleGroups[j] 
        .getBundles(); 
      System.out.println(bundleGroups[j].getIdentifier()); 
      for (int k = 0; k < bundles.length; k++) { 
       bundlesMap.put(bundles[k].getBundleId(), bundleGroups[j]); 
      }     
     } 
    } 
} 

BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext(); 

if(bundleContext instanceof BundleContextImpl) {    
    Bundle[] bundles = ((BundleContextImpl)bundleContext).getBundles(); 

    System.out.println("Orphan Bundles:"); 
    for (int i = 0; i < bundles.length; i++) { 
     if(!bundlesMap.containsKey(bundles[i].getBundleId())) { 
      System.out.println(bundles[i].getSymbolicName()); 
     } 
    }    
} 
+0

印象深刻... +1 – VonC 2009-07-29 15:43:01