---
title: "如何获取Eclipse已经加载的插件"
author: "xiaguangme"
date: "2012-04-30T13:41:58Z"
tags: []
categories: ["行业应用"]
slug: "eclipse"
draft: false
lastmod: "2012-04-30T13:45:51Z"
id: 1505746
url: "https://simoncook.iteye.com/blog/1505746"
---

## 背景：

在Eclipse插件开发，自动化构建产品的过程中，当产品构建好之后，如何得知所build的插件都是build的成功且是被成功加载的。点击 Eclipse的/About Eclipse/Install Details/Plug-ins 然后能在这个页面所成功加载的插件.

 

![](http://pic002.cnblogs.com/images/2012/127449/2012042916210635.png)

 

 

但是要是开发规模仅是几个插件还是肉眼能区分的，如果插件个数很多就难弄了。遗憾的是这个页面不能导出 不能复制。只能肉眼看。当你开发的产品涉及自己开发的插件有上几百个的时候，就比较麻烦了。

 

## 解决办法

修改其源码，将这些插件名字写进文件。

## 如何修改

经搜索发现**这个About页面是在org.eclipse.ui.workbench插件中实现的**

找到相应的java类，做适当修改，重新编译，替换jar包中的class，以clean方式启，便能实现。

我们开发的产品对应 Eclipse 3.5.2

对应其源码在[http://archive.eclipse.org/eclipse/downloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip](http://archive.eclipse.org/eclipse/downloads/drops/R-3.5.2-201002111343/eclipse-SDK-3.5.2-win32.zip)

org.eclipse.ui.workbench插件 版本是 org.eclipse.ui.workbench\_3.5.2.M20100113-0800.jar

其对应的源码包是org.eclipse.ui.workbench.source\_3.5.2.M20100113-0800.jar

解压这个源码包导入进Eclipse

将org.eclipse.ui.workbench\_3.5.2.M20100113-0800.jar中的plugin.xml文件放至工程中，将META-INF\\MANIFEST.MF这个文件替换工程中相应文件

这样这个工程依赖其他插件的配置就ok了。如下图：

![](http://pic002.cnblogs.com/images/2012/127449/2012043013111939.png)

 

找到org.eclipse.ui.internal.about.AboutPluginsPage这个类

在 createControl(Composite parent) 方法中略作修改

将bundleInfos中获得的插件名称写入至log文件

修改如下

 

 

```
public void createControl(Composite parent) {
         initializeDialogUnits(parent);
 
         // create a data object for each bundle, remove duplicates, and include
         // only resolved bundles (bug 65548)
         Map map = new HashMap();
         for (int i = 0; i < bundles.length; ++i) {
             AboutBundleData data = new AboutBundleData(bundles[i]);
             if (BundleUtility.isReady(data.getState())
                     && !map.containsKey(data.getVersionedId())) {
                 map.put(data.getVersionedId(), data);
             }
         }
         bundleInfos = (AboutBundleData[]) map.values().toArray(
                 new AboutBundleData[0]);
         
         /**
          * 将Eclipse已经加载所有插件名称排序后写入log文件
          * 以方便ci集成后check
          */
         List<String> allPluginsName = new ArrayList<String>(bundleInfos.length);
         for(AboutBundleData aboutBundleInfo : bundleInfos) {
             allPluginsName.add(aboutBundleInfo.getBundle().getSymbolicName());
         }
         Collections.sort(allPluginsName);
         
         StringBuilder sb = new StringBuilder();
         for(String tempPluginName : allPluginsName) {
             sb.append(tempPluginName);
             sb.append("\n");
         }
         String eclipseInsPath = Platform.getInstallLocation().getURL().getPath();
         String allPluginsNameLogFilePath = eclipseInsPath + "/allPlugins.log";
         File allPluginsNameLogFile = new File(allPluginsNameLogFilePath);
         try {
             if(allPluginsNameLogFile.exists()) {
                 allPluginsNameLogFile.delete();
             }
             Writer fWriter = new FileWriter(allPluginsNameLogFile);
             BufferedWriter bfWriter = new BufferedWriter(fWriter);
             bfWriter.write(sb.toString());
             bfWriter.flush();
             bfWriter.close();
             fWriter.close();
         } catch (IOException e) {
             e.printStackTrace();
         }
         
         
         WorkbenchPlugin.class.getSigners();
 
         sashForm = new SashForm(parent, SWT.HORIZONTAL | SWT.SMOOTH);
         FillLayout layout = new FillLayout();
         sashForm.setLayout(layout);
         layout.marginHeight = 0;
         layout.marginWidth = 0;
         GridData data = new GridData(GridData.FILL_BOTH);
         sashForm.setLayoutData(data);
 
         Composite outer = createOuterComposite(sashForm);
         PlatformUI.getWorkbench().getHelpSystem().setHelp(outer, helpContextId);
 
         if (message != null) {
             Label label = new Label(outer, SWT.NONE);
             label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
             label.setFont(parent.getFont());
             label.setText(message);
         }
 
         createTable(outer);
         setControl(outer);
     }
```

 

 

 

代码修改好后，clean 工程使其重新编译，到bin\\org\\eclipse\\ui\\internal\\about 找到AboutPluginsPage几个class(含其内部类编译出来的class)

关闭eclipse

替换掉org.eclipse.ui.workbench\_3.5.2.M20100113-0800.jar包中相应的class文件(附件中是改好的)

eclipse -clean 方式启动eclipse 即可。

 

--EOF--