技术开发 频道

使用Ant,Maven构建Eclipse RCP Product

【IT168技术文档】 
通常我们打包Product的时候,一般都是通过Product的export操作来进行的,但这样的做法,则限制了Continous Integration的自动化执行,那么,应该如何编写自动化构建脚本呢?

一、首先,让我们看一下Eclipse官方的解决方案:

http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.pde.doc.user/guide/tasks/pde_product_build.htm

从 文中我们可以看出,PDE已经为从product文件构建RCP应用做好了一切准备,我们所需要做的,就是搭建目录结构以及构建脚本。但是如果完全按照官 方方案去做的话,只会使得构建更加复杂,更加不可自动化,那么,让我们跟随一个简单的例子来看一下如何完成自动构建吧(在下使用的是 Eclipse3.2,pde的版本号为3.2.0.v20060603,使用其他版本的朋友请自行修改):

1。 使用Hello RCP模版构建一个RCP工程。命名为hellorcp,创建到G:\eclipse\workspace\hellorcp

在这一步,有一个很关键的问题需要注意,我们先来看一下上文中build directory的结构:
buildDirectory/ plugins/ pluginToBuildA pluginToBuildB myProduct.product ... features/ featureToBuild

要想成功build工程的话,那么工程就必须要放到/plugins/的目录结构下,不然pde是找不到工程的plugin id的!我努力了很长时间才无奈的认可了这个事实。

如果我们不想把工程放到一个很复杂的目录结构下,或者对于既有的工程不想做这样的改动,那么就只好用到ant来拷贝了。我的做法是,在工程目录下,创建名为dist\plugins\hellorcp的目录,待一切就绪后,使用ant来把整个工程拷贝到这个目录下。

2。准备脚本

在 工程下,新建buildConfiguration目录,并把\plugins\ org.eclipse.pde.build_3.2.0.v20060603\templates\headless-build下的 build.properties文件拷贝到此目录下,并修改如下设置项:

1).product—— 官方的说法是:the location of your product configuration file in the form "/ /path/to/.product",而我们的buildConfiguration目录和 product文件同处于一个目录下,所以只需要写上product文件的名字即可,如hellorcp.product。
2).baseLocation——官方的说法是:the location of an eclipse install containing all the pre-built features and plug-ins that your product requires in features/ and plugins/ subdirectories. The RCP delta pack (it is available from the eclipse download page) is mandatory as it includes the org.eclipse.platform.launchers feature which contains the launchers and root files necessary for a product. 我们要做的就是把RCP delta pack安装到Eclipse目录下,然后把base location指向Eclipse根目录即可,这里需要绝对路径。
3).buildDirectory——官方的说法是:the directory the build will take place in. Set this to the full path of the build directory created previously. 这里因为最后的目录指向是ant拷贝完成以后的路径,所以应当是G:\eclipse\workspace\hellorcp\dist
4).configs—— list the configurations for which you want your product to be built. You can uncomment the configuration(s) provided (be careful of the line continuations).
5).archivePrefix—— the name of the directory of your product once installed on disk. 如hellorcp
以上为官方给出的配置项,而我们如果使用了1.5或1.6中的新功能的话,还需要到文件的最底部,找到javacSource和javacTarget两个选项,进行对应的修改。

3。ant脚本

在工程目录下新建一个ant脚本,把下面的代码粘贴进去,运行,就可以到dist/I.TestBuild下面找构建后的产品了。

xml version="1.0"?> <project name="project" default="rcpAutomatedBuild"> <property name="eclipse.install" value="G:\eclipse"> <!--</span-->property> <property name="project.dir" value="G:\eclipse\workspace\hellorcp"> <!--</span-->property> <property name="dist.dir" value="${project.dir}\dist\plugins\hellorcp" /> <target name="prepare"> <mkdir dir="${dist.dir}" /> <copy todir="${dist.dir}"> <fileset dir="${project.dir}"> <!--</span-->fileset> <!--</span-->copy> <!--</span-->target> <target name="rcpAutomatedBuild" depends="prepare"> <java classname="org.eclipse.core.launcher.Main" fork="true" failonerror="true"> <arg value="-application" /> <arg value="org.eclipse.ant.core.antRunner" /> <arg value="-buildfile" /> <arg value="${eclipse.install}\plugins\org.eclipse.pde.build_3.2.0.v20060603\scripts\
productBuild\productBuild.xml"
/> <arg value="-Dbuilder=${dist.dir}\buildConfiguration" /> <classpath> <pathelement location="${eclipse.install}\startup.jar" /> <!--</span-->classpath> <!--</span-->java> <!--</span-->target> <!--</span-->project>
构建后的产品是以zip形式存在的,我们还可以根据实际的需要,对build.properties进行更多的修改。

上面的脚本还有一些缺陷,比如绝对位置的使用,但这是无法避免的了.......
0
相关文章