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,
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.
After extension, the review request can be posted very easily, just like a build-in function of perforce.