Set of P4 Command Alias

VirtualBox果然还是不及VMware, 越用越慢,让人崩溃啊。现在公司又不让自己装软件了(正版也不行),只好另辟蹊径。好在Java可以跨平台,于是便在Window 7里新搭了开发环境,在Window下写代码和Unit Test,去Linux下编译验证,代码通过P4 Shelve传递。几次下来,发现P4 Command挺方便,总结几个Alias和大家分享。 😆

 

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.

2014-07-28_13-57-09

When you right-click on the changelist, you can see some actions in the context menu.

2014-07-28_14-02-55

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.

2014-07-28_14-08-36

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

2014-07-28_14-16-31

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.

2014-07-28_14-22-41

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.

2014-07-28_14-26-35

Add new action into it,

2014-07-28_14-29-12

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. 😆

 

ReivewBoard+Perforce代码评审平台搭建

前言:这是我放在CSDN博客里点击最好一篇文章。今天把它搬过来。 团队在应用RB的这几年,有很多变化。代码评审的习惯已经早已深得人心,工具的变化给Team也带来很多变化!Thanks to RB. 🙂

原文

代码评审(Code Review)是敏捷开发很重要的一环,是保证软件质量的最佳实践之一。要做好Code Review, 就需要有一套简单,高效,功能完善且界面友好的工具链支持。

我所在的团队原来一直使用Code Striker做为Code Reivew的平台,但其对Perforce支持的不好,且界面不很友好,给我们带来不少麻烦,使用效果也打了折扣。从去年底,我们开始使用功能和界面都 全面增强的Review Board,同时再加上少量的工具配置,就可以实现非常高效的Code Review平台。我刚刚完成服务器的迁移,所以写些心得,一来做为日后参考,二来也和各位朋友分享。

1. Review Board简介

Review Board(简称RB)是基于Django的网络应用,界面非常友好,功能也非常强大,包含一套完整的Review流程,支持现在几种流行的SCM工具和 数据库。最感谢它网站FAQ里的一句,”Review Board is absolutely free for commercial use!“。它的开发人员来自大名鼎鼎的VMWare,其mail-list非常活跃,老大Christian Hammond(chipx86@chipx86.com )也非常乐于助人。

2. 服务器安装

RB可以安装在多种平台。本文是在WinXP SP3上安装, 其他平台请参考网站上其他文档。

请先安装Python 2.5和Apache Http Server 2.2。他们的安装略去不表,但请保证“C:/Python25;C:/Python25/Scripts”在你的环境变量里 。其他软件(针对Python2.5)我已上传到http://download.csdn.net/source/2403641。

0)安装和Python相关的一些东东

在软件包中,请安装mod_python, PIL,setuptools。这几个都是双击之后,一路NEXT即可。

1)安装memcached for windows(在软件包中)

先使用命令行memcached.exe -d install

安装服务,再去WinXP服务管理界面启动该服务。

然后用命令行

安装python-memcached. (NOTE: 最近发现easy_install也被墙了,所以用easy_install时可能有点问题。如果是那样,请找个代理,然后设置HTTP_PROXY环境变量翻墙)。

2)安装数据库SQLITE(在软件包中)

软件包中是SQLITE,但RB还支持其他数据库。请到它家的网站找,安装也不困难。

SQLITE的安装很简单,只需把它的EXE放到PATH中某个路径即可。你可以直接扔到C:/Windows/system32下。呵呵。

然后再用 easy_install pysqlite, 安装相对应的python module.

3)安装GNU patch(在软件包中)

它的安装也是一路NEXT。安装完成之后,把它EXE所在的路径放到PATH里。

4)安装p4python25(在软件包中)

一路NEXT!如果你不是在使用p4,请去RB网站看其他SCM的安装方法。

5)安装RB

RB团队已经把它放到easy_install的源里了,所以可以用 easy_install ReviewBoard 安装,很方便吧。

好了,该装的都OK,下一站就是建站。

 

3. 建站

RB建站很简单,在命令行中打一句命令

rb-site install “站名”

4. RB中添加Repository

在建站完成后,你应该可以访问到RBweb页面。

添加Repository, 需要用admin用户。这里就说说Perforce的配置吧。

首先有你在建站时用的admin用户登录,然后就会进入到Admin的页面(最上面有一个Admin的链接)。

5. 如何发布一个Review Request

关于这个问题,RB提供了一个好用的工具叫post-review。 对于使用Perforce的团队来说,这个工具更是极其好用。只要用这个post-review加上checklist-id就OK了。

下面让我们来配置一下这个工具(有些是专门针对Perforce的配置):

1) 保证在”cmd”下,p4命令是可用的。

2) 保证P4的几个相关环境变量设置了(P4USER, P4PASSWD, P4CLIENT, P4PORT )

3) 用”easy_install -U RBTools“ 安装post-review工具

4) 修改post-review的相关脚本(主要是我开始是配置在老版本的RB上,新的还不太知道能不能用,但我的一定可用。:) 大家到这个地方去下载http://download.csdn.net/source/2856000。) 修改分三步,第一,到C:/Python25/Scripts,删掉post-review.py, post-review.bat, post-review.exe; 第二,拷贝压缩包里的文件到C:/Python25/Scripts); 第三,打开post-review.py, 然后修改REVIEWBOARD_URL 那一行,用真实的URL替换。

5) 安装GNUDiff,这是用来生成diff文件的时候用的。别忘了,把diff加到PATH里,一般是这个路径”C:/Program files/GnuWin32/bin”。

好了,都配好了,下面让我们来post review吧。

1) 在你建的RB上,注册一个新账号;

2) 打开cmd, 用命令”post-review PendingChangelistId -o

3) 第一次用这个命令,它会让你输入username和passwd,以后就不会了。

4) 上传DIFF之后,它会用默认的浏览器打开网页, 显示你刚上传的Request, 这时它处于draft状态。

5) 加上一些必要的信息, 比如谁来review之类的,然后就Pulish吧!

6. 关于和P4V的集成

使用其它SCM的这一段就不用读了。

P4V是一个非常好用的工用,它也非常容易和post-review集成,那就是使用external tools. 步骤如下:

1) 打开P4V
2) 选择menu Tools->Manage Custom Tools… 打开窗口


3) New->Tool… and 打开窗口


4) 可以按如下填写


如果用<strong>”%p -o”</strong>
打开浏览器。

5) 然后在P4V里就可以使用了,如下图。


6) Post-review之后就可以在RB里看到了。

7 总结

RB的基础配置就这么多,它的网站上还有更丰富的内容,包括其他代码服务器的配置,RB升级,搬移等等。总的来说都是非常容易的。

BTW,用Perforce的朋友在提交Request时,可能会遇到一些关于权限的问题。我猜和P4服务配置有关。我问过chipx86, 他说会fix。不过在最新1.5中还没有改,所以我只好还用我自己的hack过的文件。如果有朋友遇到,可以告诉我,我会把文件发给你。