CCNet的整体结构就是一个Xml文档,根元素就是cruisecontrol,具体的代码块如下所示:

  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  2. <project name="P1">
  3. <other settings />
  4. </project>
  5. <project name="P2">
  6. <other settings />
  7. </project>
  8. </cruisecontrol>
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
     <project name="P1">
         <other settings />
     </project>
     <project name="P2">
         <other settings />
     </project>
</cruisecontrol>

其中,命名空间标定了CCNet里面的预处理过程(Preprocessor)。

一、预处理:Preprocessor

预处理里面包含三个主要元素:define、include和scope,define用于定义以后扩展的常量、include用于包含其他文件的类容,而scope用于封装现存的常量的值。

1、define元素

define元素可以用来定义一个预处理(Preprocessor)常量。如下所示:

  1. <cb:define foo="bar" />
 <cb:define foo="bar" />

也可以在一行中定义多个常量:

  1. <cb:define a="1" b="2" c="3"/>
<cb:define a="1" b="2" c="3"/>

还可以定义一个xml段:

  1. <cb:define name="baz">
  2. <some_element>
  3. <some_inner_element/>
  4. </some_element>
  5. </cb:define>
<cb:define name="baz">
  <some_element>
    <some_inner_element/>
  </some_element>
</cb:define>

任何有效的xml代码元素都可以包含其中,包括元素、属性、文本节点和注释等。

有两种方式来使用定义的常量:文本引用和xml引用

1)、文本引用的方式如下:$(const_name)

如果常量未定义,系统将搜索系统变量来替换;如果系统变量也不存在,将引发错误。

  1. <pre><code class="xml syntaxhl"><span class="CodeRay"><span class="tag"><cb:define</span> <span class="attribute-name">foo</span>=<span class="string"><span class="delimiter">"</span><span class="content">bar</span><span class="delimiter">"</span></span><span class="tag">/></span></span></code>
<pre><code class="xml syntaxhl"><span class="CodeRay"><span class="tag"><cb:define</span> <span class="attribute-name">foo</span>=<span class="string"><span class="delimiter">"</span><span class="content">bar</span><span class="delimiter">"</span></span><span class="tag">/></span></span></code>

<somexml attr1="$(foo)"/>

<somexml>$(foo)</somexml>
<env dir="$(PATH)"/>

2)、xml引用的方式如下:

如果常量未定义,系统将搜索系统变量来替换;如果系统变量也不存在,将引发错误。

  1. <cb:define foo="bar"/>
  2. <sample>
  3. <cb:foo/>
  4. </sample>
<cb:define foo="bar"/>
<sample>
  <cb:foo/>
</sample>

其效果是直接替换被引用的值,上面结果如下:

  1. <sample>
  2. bar
  3. </sample>
<sample>
  bar
</sample>

3)、常量的嵌套以及参数

常量引用可以嵌套使用,如下所示:

  1. <cb:define alpha="alphaval"/>
  2. <cb:define zed="zedval/$(alpha)"/>
  3. <z>$(zed)</z>
<cb:define alpha="alphaval"/>
<cb:define zed="zedval/$(alpha)"/>

<z>$(zed)</z>

在高层次的嵌套时,在cb:varname这种语法中,常量值是可以传递到调用的元素中去的,如下面的例子:

  1. <cb:define name="beta">
  2. <hello>
  3. <cb:gamma/>
  4. <hi attr1="$(delta)"/>
  5. </hello>
  6. </cb:define>
<cb:define name="beta">
  <hello>
    <cb:gamma/>
    <hi attr1="$(delta)"/>
  </hello>
</cb:define>

此时的gamma和delta都还没有定义

  1. <cb:beta delta="deltaval">
  2. <cb:define name="gamma">
  3. <gamma_element>hi</gamma_element>
  4. </cb:define>
  5. </cb:beta>
<cb:beta delta="deltaval">
  <cb:define name="gamma">
    <gamma_element>hi</gamma_element>
  </cb:define>
</cb:beta>

在定义了如下xml段之后,gamma就可以正常被替换了,而且上面没有定义的delta常量,也会通过cb:deta定义的delta常量所替换。最终结果如下:

  1. <hello>
  2. <gamma_element>hi</gamma_element>
  3. <hi attr1="deltaval" />
  4. </hello>
<hello>
  <gamma_element>hi</gamma_element>
  <hi attr1="deltaval" />
</hello>

2、Scope元素

Scope用于控制预处理定义中的范围,在同一个范围里面不可以定义相同的常量,但是在嵌套的范围里面,可以覆盖外层定义的常量,这一点和程序里面的代码段很像。

如下定义:

  1. <cb:scope a="a_val" b="b_val">
  2. <test attr="$(a)" attr2="$(b)"/>
  3. <cb:scope a="a_val_redefined">
  4. <test attr="$(a)" attr2="$(b)"/>
  5. </cb:scope>
  6. </cb:scope>
<cb:scope a="a_val" b="b_val">
  <test attr="$(a)" attr2="$(b)"/>
  <cb:scope a="a_val_redefined">
    <test attr="$(a)" attr2="$(b)"/>
  </cb:scope>
</cb:scope>

其结果为:

  1. <test attr="a_val" att2="b_val"/>
  2. <test attr="a_val_redefined" att2="b_val"/>
<test attr="a_val" att2="b_val"/>
<test attr="a_val_redefined" att2="b_val"/>

其中就覆盖了外层的a常量。

可以将scope应用于CCNet配置文件的Project元素,示例如下:

  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  2. <cb:define WorkingMainDir="C:\Integration\"/>
  3. <cb:define WorkingDir="\WorkingDirectory"/>
  4. <cb:define ArtifactsDir="\Artifacts"/>
  5. <cb:scope ProjectName="Alpha">
  6. <project name="$(ProjectName)" queue="Q1" queuePriority="1">
  7. <workingDirectory>$(WorkingMainDir)$(ProjectName)$(WorkingDir)</workingDirectory>
  8. <artifactDirectory>$(WorkingMainDir)$(ProjectName)$(ArtifactsDir)</artifactDirectory>
  9. </project>
  10. </cb:scope>
  11. <cb:scope ProjectName="Beta">
  12. <project name="$(ProjectName)" queue="Q1" queuePriority="1">
  13. <workingDirectory>$(WorkingMainDir)$(ProjectName)$(WorkingDir)</workingDirectory>
  14. <artifactDirectory>$(WorkingMainDir)$(ProjectName)$(ArtifactsDir)</artifactDirectory>
  15. </project>
  16. </cb:scope>
  17. </cruisecontrol>
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
   <cb:define WorkingMainDir="C:\Integration\"/>
   <cb:define WorkingDir="\WorkingDirectory"/>
   <cb:define ArtifactsDir="\Artifacts"/>

   <cb:scope ProjectName="Alpha">
     <project name="$(ProjectName)" queue="Q1" queuePriority="1">
       <workingDirectory>$(WorkingMainDir)$(ProjectName)$(WorkingDir)</workingDirectory>
       <artifactDirectory>$(WorkingMainDir)$(ProjectName)$(ArtifactsDir)</artifactDirectory>
    </project>
  </cb:scope>

  <cb:scope ProjectName="Beta">
    <project name="$(ProjectName)" queue="Q1" queuePriority="1">
      <workingDirectory>$(WorkingMainDir)$(ProjectName)$(WorkingDir)</workingDirectory>
      <artifactDirectory>$(WorkingMainDir)$(ProjectName)$(ArtifactsDir)</artifactDirectory>
    </project>
  </cb:scope>

</cruisecontrol>

而其结果则为:

  1. <cruisecontrol>
  2. <project name="Alpha" queue="Q1" queuePriority="1">
  3. <workingDirectory>C:\Integration\Alpha\WorkingDirectory</workingDirectory>
  4. <artifactDirectory>C:\Integration\Alpha\Artifacts</artifactDirectory>
  5. </project>
  6. <project name="Beta" queue="Q1" queuePriority="1">
  7. <workingDirectory>C:\Integration\Beta\WorkingDirectory</workingDirectory>
  8. <artifactDirectory>C:\Integration\Beta\Artifacts</artifactDirectory>
  9. </project>
  10. </cruisecontrol>
<cruisecontrol>

     <project name="Alpha" queue="Q1" queuePriority="1">
       <workingDirectory>C:\Integration\Alpha\WorkingDirectory</workingDirectory>
       <artifactDirectory>C:\Integration\Alpha\Artifacts</artifactDirectory>
     </project>

     <project name="Beta" queue="Q1" queuePriority="1">
      <workingDirectory>C:\Integration\Beta\WorkingDirectory</workingDirectory>
      <artifactDirectory>C:\Integration\Beta\Artifacts</artifactDirectory>
    </project>

</cruisecontrol>

通过scope,一个变通的定义方式如下:

  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  2. <cb:define WorkingMainDir="C:\Integration\"/>
  3. <cb:define WorkingDir="\WorkingDirectory"/>
  4. <cb:define ArtifactsDir="\Artifacts"/>
  5. <cb:define name="OurProject">
  6. <project name="$(ProjectName)" queue="Q1" queuePriority="1">
  7. <workingDirectory>$(WorkingMainDir)$(ProjectName)$(WorkingDir)</workingDirectory>
  8. <artifactDirectory>$(WorkingMainDir)$(ProjectName)$(ArtifactsDir)</artifactDirectory>
  9. </project>
  10. </cb:define>
  11. <cb:scope ProjectName="Alpha">
  12. <cb:OurProject/>
  13. </cb:scope>
  14. <cb:scope ProjectName="Beta">
  15. <cb:OurProject/>
  16. </cb:scope>
  17. </cruisecontrol>
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  <cb:define WorkingMainDir="C:\Integration\"/>
  <cb:define WorkingDir="\WorkingDirectory"/>
  <cb:define ArtifactsDir="\Artifacts"/>

  <cb:define name="OurProject">
    <project name="$(ProjectName)" queue="Q1" queuePriority="1">
      <workingDirectory>$(WorkingMainDir)$(ProjectName)$(WorkingDir)</workingDirectory>
      <artifactDirectory>$(WorkingMainDir)$(ProjectName)$(ArtifactsDir)</artifactDirectory>
   </project>
 </cb:define>

 <cb:scope ProjectName="Alpha">
   <cb:OurProject/>
 </cb:scope>

 <cb:scope ProjectName="Beta">
   <cb:OurProject/>
 </cb:scope>
</cruisecontrol>

这样则较大的提高了配置的可维护性。

3、include元素

include元素用来包含其他的文件内容,include中根据ccnet.config文件为基准路径进行相对定位,这样就可以在ccnet.config文件里面调用所有其他文件定义的部分,以提高可维护性。如下所示:

  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  2. <cb:include href="Definitions.xml" xmlns:cb="urn:ccnet.config.builder"/>
  3. <cb:include href="CI_Projects.xml" xmlns:cb="urn:ccnet.config.builder"/>
  4. <cb:include href="QA_Projects.xml" xmlns:cb="urn:ccnet.config.builder"/>
  5. </cruisecontrol>
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">

   <cb:include href="Definitions.xml" xmlns:cb="urn:ccnet.config.builder"/>

   <cb:include href="CI_Projects.xml" xmlns:cb="urn:ccnet.config.builder"/>

   <cb:include href="QA_Projects.xml" xmlns:cb="urn:ccnet.config.builder"/>

 </cruisecontrol>

其中Definitions.xml文件定义如下:

  1. <cb:config-template xmlns:cb="urn:ccnet.config.builder">
  2. <queue name="Q1" duplicates="UseFirst" lockqueues="Q2, Q4" />
  3. <cb:define name="EmailPublisher">
  4. <email from="buildmaster@mycompany.com"
  5. mailhost="localhost"
  6. mailhostUsername="TheMailer"
  7. mailhostPassword="JohnWayne"
  8. includeDetails="TRUE">
  9. <users />
  10. <groups />
  11. <modifierNotificationTypes>
  12. <NotificationType>Failed</NotificationType>
  13. <NotificationType>Fixed</NotificationType>
  14. </modifierNotificationTypes>
  15. </email>
  16. </cb:define>
  17. <cb:define name="common_publishers">
  18. <artifactcleanup cleanUpMethod="KeepMaximumXHistoryDataEntries" cleanUpValue="500" />
  19. <xmllogger />
  20. <statistics />
  21. <modificationHistory  onlyLogWhenChangesFound="true" />
  22. <rss/>
  23. </cb:define>
  24. <cb:define name="common_nant">
  25. <executable>c:\nant\nant.exe</executable>
  26. <nologo>true</nologo>
  27. <buildTimeoutSeconds>240</buildTimeoutSeconds>
  28. </cb:define>
  29. <cb:define name="nant_args_CI">
  30. <buildArgs>clean compile</buildArgs>
  31. </cb:define>
  32. </cb:config-template>
<cb:config-template xmlns:cb="urn:ccnet.config.builder">

  <queue name="Q1" duplicates="UseFirst" lockqueues="Q2, Q4" />

  <cb:define name="EmailPublisher">
    <email from="buildmaster@mycompany.com"
          mailhost="localhost"
          mailhostUsername="TheMailer"
          mailhostPassword="JohnWayne"
          includeDetails="TRUE">
    <users />
        <groups />

        <modifierNotificationTypes>
          <NotificationType>Failed</NotificationType>
          <NotificationType>Fixed</NotificationType>
        </modifierNotificationTypes>

    </email>
  </cb:define>

  <cb:define name="common_publishers">
    <artifactcleanup cleanUpMethod="KeepMaximumXHistoryDataEntries" cleanUpValue="500" />
    <xmllogger />
    <statistics />
    <modificationHistory  onlyLogWhenChangesFound="true" />
    <rss/>
  </cb:define>

  <cb:define name="common_nant">
       <executable>c:\nant\nant.exe</executable>
       <nologo>true</nologo>
    <buildTimeoutSeconds>240</buildTimeoutSeconds>
  </cb:define>

  <cb:define name="nant_args_CI">
      <buildArgs>clean compile</buildArgs>
  </cb:define>

</cb:config-template>

在Definitions.xml文件里面,需要使用db:config-template作为根元素使用。

本文转载自:http://blog.csdn.net/yant255/article/details/43306227

CI学习 CCNET Config 第一天的更多相关文章

  1. Beego学习笔记——Config

    配置文件解析 这是一个用来解析文件的库,它的设计思路来自于database/sql,目前支持解析的文件格式有ini.json.xml.yaml,可以通过如下方式进行安装: go get github. ...

  2. Stealth视频教程学习笔记(第一章)

    Stealth视频教程学习笔记(第一章) 本文是对Unity官方视频教程Stealth的学习笔记.在此之前,本人整理了Stealth视频的英文字幕,并放到了优酷上.本文将分别对各个视频进行学习总结,提 ...

  3. 20145330《Java学习笔记》第一章课后练习8知识总结以及IDEA初次尝试

    20145330<Java学习笔记>第一章课后练习8知识总结以及IDEA初次尝试 题目: 如果C:\workspace\Hello\src中有Main.java如下: package cc ...

  4. (转)神经网络和深度学习简史(第一部分):从感知机到BP算法

    深度|神经网络和深度学习简史(第一部分):从感知机到BP算法 2016-01-23 机器之心 来自Andrey Kurenkov 作者:Andrey Kurenkov 机器之心编译出品 参与:chen ...

  5. web前端学习python之第一章_基础语法(二)

    web前端学习python之第一章_基础语法(二) 前言:最近新做了一个管理系统,前端已经基本完成, 但是后端人手不足没人给我写接口,自力更生丰衣足食, 所以决定自学python自己给自己写接口哈哈哈 ...

  6. web前端学习python之第一章_基础语法(一)

    web前端学习python之第一章_基础语法(一) 前言:最近新做了一个管理系统,前端已经基本完成, 但是后端人手不足没人给我写接口,自力更生丰衣足食, 所以决定自学python自己给自己写接口哈哈哈 ...

  7. 学习Nodejs的第一步

    最近看了几本关于Node.js的书,本来个人技术分享网站http://yuanbo88.com/是打算用Node.js作为服务器端语言来处理后台的,后来又改成了PHP(也是自己研究,毕竟网上DEMO多 ...

  8. C#开发学习人工智能的第一步

    前言 作为一个软件开发者,我们除了要学会复制,黏贴,还要学会调用API和优秀的开源类库. 也许,有人说C#做不了人工智能,如果你相信了,那只能说明你的思想还是狭隘的. 做不了人工智能的不是C#这种语言 ...

  9. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数 学习目标: 学习如何使用几何学和数字描述 Vecto ...

随机推荐

  1. Web桌面应用框架3:Web桌面应用开发的N种Style

    研究Web桌面应用开发有一段时间了,总结了Web桌面应用开发的一些主流方式. 一.前端Style 这种方式的就是直接实现一个Web程序,再封装一个浏览器展示,相当粗暴和有效.著名的框架就是Electr ...

  2. Django----中间件详解

    Django中间件 在http请求 到达视图函数之前   和视图函数return之后,django会根据自己的规则在合适的时机执行中间件中相应的方法. 中间件的执行流程 1.执行完所有的request ...

  3. canvas图表(2) - 折线图

    原文地址:canvas图表(2) - 折线图 话说这天气一冷啊, 就患懒癌, 就不想码代码, 就想着在床上舒舒服服看视频. 那顺便就看blender视频, 学习下3D建模, 如果学会了建3D模型, 那 ...

  4. Android 使用GangSDK创建第三方家族公会系统经验分享

    由于需要对之前的游戏加入一个家族系统,想到这块儿可能会有大量的工作需要自己做,就偷了个懒去网上搜罗了一波,有没有类似现成的系统?结果让我惊奇的发现,目前市面上居然真的有类似的服务,虽然是小公司开发的, ...

  5. 【Java疑难杂症】有return的情况下try catch finally的执行顺序

    有这样一个问题,异常处理大家应该都不陌生,类似如下代码: public class Test { public static void main(String[] args) { int d1 = 0 ...

  6. 机器学习算法--Perceptron(感知机)算法

    感知机: 假设输入空间是\(\chi\subseteq R^n\),输出空间是\(\gamma =\left( +1,-1\right)\).输入\(\chi\in X\)表示实例的特征向量,对应于输 ...

  7. PHP时间戳和日期互转换

    在php中我们要把时间戳转换日期可以直接使用date函数来实现,如果要把日期转换成时间戳可以使用strtotime()函数实现,下面我来给大家举例说明. 1.php中时间转换函数 strtotime ...

  8. 免费人脸识别APi

    今天对应一些免费的人脸识别的api 做了一下简单的对比,觉得百度开发出来的人脸识别接口还是最符合的我的要求,简单易用,容易上手. 据说百度的一些门禁也使用上了人脸识别的功能了,功能很强大,而且能识别出 ...

  9. Python将纳入高考?

    最近,"Python将纳入高考"的消息,狠狠地刷了朋友圈. 尽管这则消息目前还未得到官方的确认,但人们对于Python的火热关注度,还是引来众程序员热议. 虽然小编资历尚浅,但还是 ...

  10. 51Nod 1352 集合计数 扩展欧几里得

    基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个固定集合{1,N},{2,N-1},{3,N-2},...,{N-1,2},{N,1}.求出有多少个集合满足 ...