关于Eclipse 3.0中的插件自动构建简介

http://tech.ddvip.com   2007年08月31日    社区交流

内容摘要:Eclipse 提供了在Eclipse IDE外自动构建的能力。Eclipse本身也是采用这种方式构建的。本文将分享Eclipse自动构建的一些经验,详细介绍Eclipse插件开发的自动编译过程。

  2.customTargets.xml ,customTargets.xml文件位于位于d:uildorg.eclipse.releng.eclipsebuilder目录的子目录下。如sdk.examples。org.eclipse.releng.eclipsebuilder是eclipse的release engine。可以从eclipse的cvs中获得。

  3.build.properties ,build.properties文家定义了构建过程中使用的环境变量。你可以根据自己的情况修改。

  4.a shell script, which starts an Eclipse instance as AntRunner。运行Eclipse实例的脚本。在本文的前面已经有过介绍。

  下面是一个Map文件片断的示例,你可以根据你自己的情况修改用户名,密码,package名称,和CVS分支名称。

  feature@org.rubypeople.rdt=HEAD,:ext:cvs.sf.net:/cvsroot/rubyeclipse,,org.rubypeople.rdt-feature

  plugin@org.kxml2=HEAD,:ext:cvs.sf.net:/cvsroot/rubyeclipse,

  plugin@org.rubypeople.rdt=HEAD,:ext:cvs.sf.net:/cvsroot/rubyeclipse,

  plugin@org.rubypeople.rdt.core=HEAD,:ext:cvs.sf.net:/cvsroot/rubyeclipse,

  CustomeTargets.xml提供了构建过程中回调的钩子。CustemerTargets.xml文件的模板在org.eclipse.pde.build插件的script目录下可以找到。下面是customerTargets.xml文件的一个片断。allElements target中定义了你要构建的feature id。这里的feature id不是feature manifest文件中定义的feature,而是用于在map文件中查找cvs信息时使用的id。getMapFiles target会将map文件下载到本地的${buildDirectory}目录下。Assemble target会调用生成的assemble脚本文件对编译结果进行组装。

<target name="allElements">
<ant antfile="${genericTargets}" target="${target}" >
<property name="type" value="feature" />
<property name="id" value="org.rubypeople.rdt" />
</ant>
</target>
<target name="getMapFiles">
<property name="cvsRoot" value=":ext:cvs.sf.net:/cvsroot/rubyeclipse" />
<cvs cvsroot="${cvsRoot}"
dest="${buildDirectory}/maps"
command="export -r ${mapVersionTag} org.rubypeople.rdt.build/map"/>
</target>
<target name="assemble.org.rubypeople.rdt">
<ant antfile="${assembleScriptName}" dir="${buildDirectory}">
<property name="zipargs" value="" />
</ant>
</target>

  结论

  回顾一下整个构建过程,在customTargets.xml文件中我们定义了每一构建过程中供$ECLIPSE_HOMEpluginsorg.eclipse.pde.build_3.0.0scripts下的build.xml文件回调的target。对于一些复杂的通用功能如生成获取cvs中插件代码的fetch.xml文件、生成build.xml文件等由genericTargets.xml来完成。这样一种结构最大限度的保证了customTargets.xml文件的简洁性、可维护性、可扩充性。Eclipse提供了这样一个优雅的构建脚本框架,用户只需要编写自己的customTargets.xml文件。CustomTargets.xml文件的模板可以在$ECLIPSE_HOMEpluginsorg.eclipse.pde.build_3.0.0scripts找到。我们只需要拷贝一个,然后稍加修改就可以完成该项工作。

  CustomTargets.xml文件中预定义了很多和构建过程对应的target。这些target都会被$ECLIPSE_HOMEpluginsorg.eclipse.pde.build_3.0.0scripts调用。一个例子可以很好的说明这种回调的方便性。当我们构建一个包含有help文件的插件时,一个预先要做的工作就是先要将help文件打包成zip文件。我们可以修改customTargets.xml中的preProcess Target:

<target name="preProcess">
<zip destfile="${buildDirectory}/plugins/org.eclipse.sdk.examples/doc.zip"
basedir="${buildDirectory}/plugins/org.eclipse.sdk.examples"
includes="doc/**"/>
</target>

作者:晏斐    责编:豆豆技术应用

正在加载评论...