偶然的机会发现在一个好用的IDEA插件--Bytecode Editor,可以用来快速的修改Java的字节码。推荐大家试试!记得点左上角的重编译按钮哦。
Tag: plugin
Manually uninstall OSGi bundle in the runtime
Sometimes in a RCP application, you may need to uninstall OSGi bundle in the runtime. With BundleContext, it’s doable. Here is a sample.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/** * Uninstall specific bundle by name. * * @param context the bundle context. * @param bundleName the name of bundle. * @return true means the bundle has been uninstalled. */ public static boolean uninstallBundle(BundleContext context, String bundleName) { if (context == null || Strings.isNullOrEmpty(bundleName)) { LOGGER.debug("some argument is null. do nothing."); return false; } Bundle[] bundles = context.getBundles(); if (bundles != null) { for (Bundle bundle : bundles) { if (bundle.getSymbolicName().equals(bundleName)) { LOGGER.debug("Found bundle " + bundleName + ", uninstall it"); try { bundle.uninstall(); return true; } catch (BundleException e) { LOGGER.debug(e.getMessage(), e); return false; } } } } LOGGER.debug("no bundle named " + bundleName + " was found"); return false; } |
As you can see, you need to specify the bundle/plugin name.
How to extend p4eclipse plugin?
What’s p4eclipse?
Perforce provides is a very powerful and handy plugin for Eclipse – p4eclipse. With it, you can do everything in Eclipse enviornment, which is the same as in it p4 command line and p4v (a clicent of perforce).
Why to extend it?
Team also deployed ReviewBoard to do pre-check-in code review. And we have a command-line tool to post review request to it. The input is the id of perforce changelist.
Basically, we can see the changelist in Eclipse. The problem is how to combine them together and allow us to easily post the request from GUI directly.
When you right-click on the changelist, you can see some actions in the context menu.
Can we add another menu item into the context menu and post review request?
Ways to Extend p4eclipse
p4eclipse is also a Eclipse plugin and it follows the basic concept, such as extension, extension point, views and etc. It should be easily extended.
Find which view to extend
First, we need to find out the view class of P4 changelist. Simply move the mouse on view tab and click ATL+SHIFT+F1 to launch “Plug-in Selection Spy“. And the view name is PendingView, contained in plugin-in “com.perforce.team.ui” and the element in tree is P4PendingChangelist.
Create plugin-in project
Now we know to extend which view. It’s time to create our own plugin-in project. And in the MANIFEST.MF, besides basic plugins, we need explicitly declare we need p4eclipse plugins,
- com.perforce.team.ui
- com.perforce.p4api
- com.perfroce.team.core
NOTE: Here is a bug of Eclipse PDE 3.x. Even we declare the com.perforce.team.ui is needed, but Eclipse can’t build through and there will be build errors. The root cause is com.perforce.team.ui is in a unpacking feature and PDE can’t revolve the dependency correctly in such case. To fix it, we have to download the jar file of com.perforce.team.ui to local and put it in to runtime class path manually. Remember, it’s only to fix PDE issue, we don’t need it in packaging.
Add new menu item into the context menu
Open the MANIFEST.MF file and file the context menu extension declaration. It’s in org.eclipse.ui.popupMenus and the menu id is com.perforce.team.core.p4java.IP4PendingChangelist.
Add new action into it,
Next steps are easy
Now we finished the important part. If you are familiar with Eclipse RCP, you should understand next steps are easy. Basically, we need to launch a command line from Java code and implement an action handler for the new created menu item. In my implementation, I also add a new preference page for team to setup the command location.
For details, please refer to my github project p4eclipse_ext.
Extened p4eclipse
After extension, the review request can be posted very easily, just like a build-in function of perforce. 😆