<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Java學(xué)習(xí)

    java,spring,structs,hibernate,jsf,ireport,jfreechart,jasperreport,tomcat,jboss -----本博客已經(jīng)搬家了,新的地址是 http://www.javaly.cn 如果有對(duì)文章有任何疑問或者有任何不懂的地方,歡迎到www.javaly.cn (Java樂園)指出,我會(huì)盡力幫助解決。一起進(jìn)步

     

    cruisecontrol、ant、svn持續(xù)集成

    自己兩個(gè)多星期以來對(duì)持續(xù)集成的概念和應(yīng)用有了一些了解。下面主要對(duì)自己配置持續(xù)集成的環(huán)境進(jìn)行總結(jié)。(看上去簡(jiǎn)單,但是對(duì)我開始對(duì)持續(xù)集成都沒什么了解的人來說確實(shí)費(fèi)了不少周折)

    一  本次持續(xù)集成環(huán)境的搭建所使用的工具有

     cruisecontrol、ant、svn、junit、Slik-Subversion-1.5.6-win32、svnant-1.1.0-RC2.zip

     cruisecontrol:是一種持續(xù)集成過程的框架,包括了郵件通知,ant 和各種源碼控  制工具的插 件。并提供了web接口,用于查看當(dāng)前和以前的創(chuàng)建的結(jié)果.

    ant:構(gòu)建工具。

    svn:版本控制工具。

    junit:單元測(cè)試工具。

    slik-subversion:是為了調(diào)用svn的客戶端命令安裝的。

    svnant:主要是用到它里面的lib中的jar包,它具體使用還不是很清楚

    另外本次的輔助環(huán)境還有jdk,相信大家都再也熟悉不過了。

    二 環(huán)境的搭建步驟:

    1. jdk的安裝:根據(jù)jdk安裝包的提示安裝jdk。設(shè)置系統(tǒng)的環(huán)境變量:

    a) JAVA_HOME指明JDK安裝路徑,就是剛才安裝時(shí)所選擇的路徑D:"java"jdk1.5.0_08,此路徑下包括libbinjre等文件夾(此變量最好設(shè)置,因?yàn)橐院筮\(yùn)行tomcat都需要依賴此變量);

    b) Path使得系統(tǒng)可以在任何路徑下識(shí)別java命令,設(shè)為%JAVA_HOME%"bin;%JAVA_HOME%"jre"bin

     c)CLASSPATH為java加載類(class or lib)路徑,只有類在  classpath中,java命令才能識(shí)別,設(shè)為:.;JAVA_HOME"lib"dt.jar;JAVA_HOME%   "lib"tools.jar (要加.表示當(dāng)前路徑);%JAVA_HOME%就是引用前面指定的JAVA_HOME;不過本人還是比較相信絕對(duì)路徑的。 

    2 ant的安裝:ant是集成構(gòu)建工具,想必大家都不太陌生了。只需要到ant.apache.org的網(wǎng)站下載ant的適當(dāng)版本解壓縮后,配置系統(tǒng)的環(huán)境變量:ANT_HOME:d:"apache-ant-1.7.0, path:d:"apache-ant-1.7.0"bin 后,ant就可以在任意目錄下運(yùn)行了,如cmd下運(yùn)行ant,顯示:buildfile:build.xml does not exsit。。。。。

    3 安裝svn,因?yàn)閏ruisecontrol要用到svn(不知道這兩個(gè)有什么先后順序沒,因?yàn)閏c要用svn就先裝cc嘍)。svn的安裝TortoiseSVN-1.5.3.13783-win32-svn-1.5.2.msi安裝提示裝就可以了。

    4 安裝tomcat ,設(shè)置系統(tǒng)環(huán)境變量CATALINA_HOME=c:"tomcat,CLASSPATH=C:"tomcat"common"lib(加載必要的包)。

    5 cuisecontrol的安裝,因?yàn)楸疚氖褂玫?strong style="font-weight: 400;">操作系統(tǒng)為XP,就使用CruiseControl-2.8.2.exe安裝就可以了(.exe文件還是很受大家喜歡的)。配置系統(tǒng)的環(huán)境變量:CC_HOME=d:"cruisecontrol

    6 安裝slik-subversion,它會(huì)自動(dòng)寫入到path=D:"SlikSvn"bin" 如果沒有寫入的話,要麻煩手動(dòng)加入到系統(tǒng)的環(huán)境變量path中,本人曾經(jīng)遇到過,cmd窗口已經(jīng)打開但是配置文件執(zhí)行過程中svn的命令總不能識(shí)別發(fā)現(xiàn)此 處的路徑?jīng)]有加入到path中。

    7下載svnant-1.1.0-RC2.zip,把lib包中的jar考到ant的jar中。

    三 以上的準(zhǔn)備工作已經(jīng)基本搞定,下面就介紹一下配置文件。此次環(huán)境的搭建配置文件是很關(guān)鍵的,因?yàn)樗麄兏髯杂凶约旱臉?biāo)簽,所以還要想達(dá)到什么功能慢慢查找,(如果有時(shí)間系統(tǒng)學(xué)習(xí)一下就好了)。

    1 ant的關(guān)鍵文件為build.xml(當(dāng)然也可以起別的名稱,自己還要改它的啟動(dòng)文件,就用這個(gè)名稱吧)下面是一個(gè)實(shí)例:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>

    定義basedir當(dāng)前的根目錄,default默認(rèn)執(zhí)行的標(biāo)簽,name工程名
    <project basedir="." default="all" name="framework">
     <property environment="env" />

    定義tomcat的安裝目錄
     <property name="TOMCAT_DIR" location="D:/Tomcat 5.5" />

    定義debug的級(jí)別
     <property name="debuglevel" alue="source,lines,vars" />

    為了引用tomcat固有包方便所以增加次屬性
     <property name="coolink.dist.path" location="D:/Tomcat 5.5/webapps/txsd/WEB-INF" />

    指定要編譯的工程目錄
     <property name="CLASS_DIR" location="D:/CruiseControl/projects/framework" />
     <property name="target" value="1.5" />
     <property name="source" value="1.5" />

    編譯時(shí)候所使用的類路徑,id為引用的名稱
     <path id="Apache Tomcat v5.5 [Apache Tomcat v5.5].libraryclasspath">
      <pathelement location="${TOMCAT_DIR}/common/lib/commons-el.jar" />
      ....
      <pathelement location="${TOMCAT_DIR}/common/lib/servlet-api.jar" />
     </path>
     <path id="Web App Libraries.libraryclasspath">
      <pathelement location="${coolink.dist.path}/lib/activation.jar" />
      .............
      <pathelement location="${coolink.dist.path}/lib/xmlParserAPIs.jar" />
     </path>
      <path id="ant.svn.classpath">
      <fileset dir="D:/CruiseControl/apache-ant-1.7.0/lib">
       <include name="*.jar" />
      </fileset>
     </path>
     <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask">
      <classpath refid="ant.svn.classpath" />
     </taskdef>
     <path id="txsd.classpath">
      <path refid="Apache Tomcat v5.5 [Apache Tomcat v5.5].libraryclasspath" />
      <path refid="Web App Libraries.libraryclasspath" />
     </path>

    clean操作,如果build之前不執(zhí)行此操作,build檢查到原有的class文件就不再編譯。
     <target name="clean">
         <delete file="${CLASS_DIR}/longcon-framework.jar" />
         <delete dir="target" quiet="true" />
      <delete dir="${CLASS_DIR}/source/classes" />
     </target>

    要build模塊的名稱build-framework看來可以隨便起名字,但是有人說必須和模塊名稱一致,至今還不知道為什么
     <target name="build-framework">
      <echo message="${ant.project.name}: ${ant.file}" />
      <mkdir dir="${CLASS_DIR}/source/classes" />
      <copy includeemptydirs="false" todir="source/classes">
       <fileset dir="${CLASS_DIR}/source" excludes="**/*.launch, **/*.java" />
      </copy>
      <javac debug="true" debuglevel="${debuglevel}" destdir="${CLASS_DIR}/source/classes" source="${source}" target="${target}" encoding="UTF-8">
       <src path="${CLASS_DIR}/source" />
       <exclude name="**/.svn/**" />
       <classpath refid="txsd.classpath" />
      </javac>
     </target>

    單元測(cè)試的部分
     <target name="test">
      <mkdir dir="target/test-classes" />
      <javac encoding="UTF-8" srcdir="${CLASS_DIR}/test" destdir="target/test-classes">
       <classpath>
        <pathelement location="${CLASS_DIR}/source/classes" />
        <path refid="Apache Tomcat v5.5 [Apache Tomcat v5.5].libraryclasspath" />
              <path refid="Web App Libraries.libraryclasspath" />
       </classpath>
      </javac>

      <mkdir dir="target/test-results" />
      <junit haltonfailure="no" printsummary="on">
       <classpath>
        <pathelement location="${CLASS_DIR}/source/classes" />
        <pathelement location="${coolink.dist.path}/lib/junit.jar" />
        <pathelement location="target/test-classes" />
       </classpath>
       <formatter type="brief" usefile="false" />
       <formatter type="xml" />
       <batchtest todir="target/test-results">
        <fileset dir="target/test-classes" includes="**/*.class" />
       </batchtest>
      </junit>
     </target>

    打包放到指定目錄
     <target name="jar">
      <jar destfile="${CLASS_DIR}/longcon-framework.jar" encoding="UTF-8" update="false" excludes="**/*Test*.class">
       <fileset dir="${CLASS_DIR}/source/classes" />
      </jar>
      <copy includeemptydirs="false" todir="${coolink.dist.path}/lib">
       <fileset file="${CLASS_DIR}/longcon-framework.jar" excludes="**/*.launch, **/*.java" />
      </copy>
     </target>

    調(diào)用svn命令,這與三中的步驟7有密切的聯(lián)系
    <target name="commit">
     <svn username="aaa" password="aaa">
             <commit file="${coolink.dist.path}/lib/longcon-framework.jar" message="${msg.commit}"  />
         </svn>
     </target>
     <target name="all"  depends="clean,build-framework,jar,commit"/>

    </project>
    注釋:

    a設(shè)置編譯所需要的類路徑可以用:                      <classpath>
          <pathelement path="${classpath}"/>
          <fileset dir="lib">
            <include name="**/*.jar"/>
          </fileset>
          <pathelement location="classes"/>
          <dirset dir="build">
            <include name="apps/**/classes"/>
            <exclude name="apps/**/*Test*"/>
          </dirset>
          <filelist refid="third-party_jars"/>

       </classpath>

    b <target name="test" depends="clean">depends表示依賴關(guān)系
     2 cruisecontrol的config文件,CC啟動(dòng)的時(shí)候會(huì)自動(dòng)尋找此文件,當(dāng)然你可以通過修改啟動(dòng)文件修改config.xml名稱,只要兩處一致就能找到,下面是一個(gè)config文件的實(shí)例:

    <cruisecontrol>//cc的固有標(biāo)簽,cc中可以有多個(gè)project

     <project name="framework">// 工程名稱

    <plugin name="labelincrementer" classname="net.sourceforge.cruisecontrol.labelincrementers.SVNLabelIncrementer"/>
           <labelincrementer workingcopypath="projects/${project.name}"/> // 顯示svn的版本號(hào)

    listeners:監(jiān)聽器,來報(bào)告cc的此項(xiàng)目的運(yùn)行信息
      <listeners>
       <currentbuildstatuslistener file="logs/${project.name}/status.txt" />
      </listeners>

    bootstrappers從svn源碼控制程序更新本地版本,據(jù)說還有向其它插件提供當(dāng)前創(chuàng)建的狀態(tài)

      <bootstrappers>
       <svnbootstrapper localWorkingCopy="projects/${project.name}" username="luojing" password="luojing" />
      </bootstrappers>
      <bootstrappers>//向ant提供當(dāng)前信息
       <antbootstrapper anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" target="jar" />
      </bootstrappers>
      <modificationset quietperiod="30">// 通過svn更新原代碼
       <!-- touch any file in connectfour project to trigger a build -->
       <svn localWorkingCopy="projects/${project.name}" username="luojing" password="luojing" />
      </modificationset>

    <schedule interval="28800">設(shè)定檢查編譯build版本的時(shí)間單位s
       <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" />
      </schedule>
      <log>//顯示單元測(cè)試信息
       <merge dir="projects/${project.name}/framework/target/test-results" />
      </log>
      <publishers>//發(fā)布版本
       <onsuccess>//成功,并生成有時(shí)間戳的目錄
        <artifactspublisher dest="D:/CruiseControl/artifacts/${project.name}" file="projects/${project.name}/longcon-framework.jar" />
       </onsuccess>
       <onfailure>//失敗發(fā)送郵件到響應(yīng)的人員
        <htmlemail buildresultsurl="http://localhost:8080/cruisecontrol/buildresults/${project.name}" mailhost="郵件服務(wù)器" password="密碼" username="用戶名" defaultsuffix="@**.com.cn" returnname="PetClinic Continuous Integration" returnaddress="sunny@**.com.cn" charset="UTF-8" skipusers="true" xsldir="webapps/cruisecontrol/xsl" css="webapps/cruisecontrol/css/cruisecontrol.css">
         <always address="接收郵件方的郵箱" />
        </htmlemail>
       </onfailure>
      </publishers>
     </project>
     <project name="site">
      <listeners>
       <currentbuildstatuslistener file="logs/${project.name}/status.txt" />
      </listeners>

      <bootstrappers>
       <svnbootstrapper localWorkingCopy="projects/${project.name}" username="sunny" password="sunny" />
      </bootstrappers>
      <bootstrappers>
       <antbootstrapper anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" target="jar" />
      </bootstrappers>
            <modificationset>//設(shè)置只有framework工程成功了才執(zhí)行此次的操作,體現(xiàn)了project的依賴關(guān)系
               <buildstatus logdir="logs/framework"/>
            </modificationset>
     </project>
    </cruisecontrol>

    四 啟動(dòng)CC可以實(shí)現(xiàn)集成編譯、集成構(gòu)建、單元測(cè)試的功能,對(duì)于持續(xù)構(gòu)建這是最簡(jiǎn)單不過了,要繼續(xù)努力學(xué)習(xí)哦。

    五 持續(xù)集成使用了一段時(shí)間發(fā)現(xiàn)了源代碼目錄總是不能自動(dòng)更新,認(rèn)真查找發(fā)現(xiàn)是因?yàn)樽约簩?duì)標(biāo)簽<svnbootstrapper>的理解不正確,現(xiàn)在就是在ant的build.xml中調(diào)用svn的提交命令來解決的,不知道思路是否正確,請(qǐng)大家指教。

    下面就更清晰的介紹一下常用的標(biāo)簽把。

    CC配置文件范connectfour范例Config.xml如下:

    <cruisecontrol>
        <project name="connectfour">

            <listeners>
                <currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
            </listeners>

            <bootstrappers>
                <antbootstrapper anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" target="clean" />
            </bootstrappers>

            <modificationset quietperiod="30">
                <!-- touch any file in connectfour project to trigger a build -->
                <filesystem folder="projects/${project.name}"/>
            </modificationset>

            <schedule interval="300">
                <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
            </schedule>

            <log>
                <merge dir="projects/${project.name}/target/test-results"/>
            </log>

            <publishers>
                <onsuccess>
                    <artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/target/${project.name}.jar"/>
                </onsuccess>
            </publishers>

        </project>
    </cruisecontrol>

    <cruisecontrol>根元素是<cruisecontrol>,該元素很簡(jiǎn)單,沒什么需要配置的屬性。

    目前CC支持多項(xiàng)目(multiproject),因此可以有多個(gè)并行的<project>元素。支持的子元素包括:
     <project>
         <property/>
         <plugin/>
         <dateformat/>
         <labelincrementer/>
         <listeners>
            <cmsynergysessionmonitor/>
            <currentbuildstatusftplistener/>
            <currentbuildstatuslistener/>
            <currentbuildstatuspagelistener/>
            <lockfilelistener/>
          </listeners>
         <bootstrappers>

            <accurevbootstrapper/>
            <alienbrainbootstrapper/>
            <antbootstrapper/>
            <clearcasebootstrapper/>
            <clearcaseviewstrapper/>
            <cmsynergybootstrapper/>
            <currentbuildstatusbootstrapper/>
            <currentbuildstatusftpbootstrapper/>
            <cvsbootstrapper/>
            <execbootstrapper/>
            <gitbootstrapper/>
            <harvestbootstrapper/>
            <lockfilebootstrapper/>
            <mercurialbootstrapper/>
            <p4bootstrapper/>
            <plasticscmbootstrapper/>
            <snapshotcmbootstrapper/>
            <starteambootstrapper/>
            <surroundbootstrapper/>
            <svnbootstrapper/>
            <tfsbootstrapper/>
            <vssbootstrapper/>
          </bootstrappers>
         <modificationset>

            <accurev>
            <alienbrain/>
            <alwaysbuild/>
            <buildstatus/>
            <clearcase/>
            <cmsynergy/>
            <compound>
               <targets/>
               <triggers/>
             </compound>
            <cvs/>

            <darcs/>
            <filesystem/>
            <forceonly/>
            <git/>
            <harvest/>
            <httpfile/>
            <mavensnapshotdependency/>
            <maven2snapshotdependency/>
            <mercurial/>
            <mks/>
            <p4/>
            <plasticscm/>
            <pvcs/>
            <snapshotcm/>
            <starteam/>
            <store/>
            <surround/>
            <svn/>
            <tfs/>
            <timebuild>
            <ucm>
            <veto/>
            <vss/>
            <vssjournal/>
          </modificationset>
         <schedule>

            <ant/>
            <maven/>
            <maven2/>
            <pause/>
            <nant/>
            <phing/>
            <rake/>
            <exec/>
            <composite/>
          </schedule>
         <log>

            <merge/>
    <gzip/>
    <delete/>
          </log>
         <publishers>

            <antpublisher/>
            <artifactspublisher/>
            <clearcasebaselinepublisher/>
            <cmsynergybaselinepublisher/>
            <cmsynergytaskpublisher/>
            <compoundpublisher/>
            <currentbuildstatuspublisher/>
            <currentbuildstatusftppublisher/>
            <email/>
            <execute/>
            <ftppublisher/>
            <htmlemail/>
            <http>
            <jabber/>
            <onfailure/>
            <onsuccess/>
            <rss/>
            <sametimeannouncement/>
            <scp/>
            <sfeedocman/>
            <sfeefrs/>
            <sfeetracker/>
            <socket/>
            <weblog>
            <x10/>
            <xsltlogpublisher/>
            <yahoopublisher/>
          </publishers>
       </project>

     子元素過多所以詳情可以參看官方文檔的說明。

    這里只介紹幾個(gè)常用的子元素:

    <bootstrappers>:<bootstrappers>在創(chuàng)建之前會(huì)運(yùn)行,相當(dāng)于一個(gè)預(yù)處理的作用,<bootstrappers>下面每個(gè)子元素都是獨(dú)立的,因此可以同時(shí)配置多個(gè)bootstrappers。

    CC提供的bootstrappers包括兩種,一種用于向其他插 件提供項(xiàng)目當(dāng)前創(chuàng)建的狀態(tài),還有一種是從某個(gè)源碼控制系統(tǒng)更新本地文件,其中最常用的就 是<currentbuildstatusbootstrapper> 和<svnbootstrappers>。<currentbuildstatusbootstrapper>指定了狀態(tài)文件的 位置,主要是用來訪問項(xiàng)目當(dāng)前創(chuàng)建的狀態(tài),CC的<currentbuildstatusbootstrapper>會(huì)將創(chuàng)基愛你的狀態(tài)寫入 這個(gè)文件。

    <svnbootstrapper>的作用有點(diǎn)難理解,因?yàn)槲覀兠看雾?xiàng)目的創(chuàng)建都應(yīng)該基于最新的代碼,因此在創(chuàng)建之前就要獲得最新的項(xiàng)目文 件,如果使用的是ant來完成這個(gè)任務(wù),那么buildfile本身在創(chuàng)建開始之前發(fā)生了變化,我們是不是應(yīng)該先更新這個(gè)buildfile,然后才通過 buildfile來對(duì)項(xiàng)目進(jìn)行構(gòu)建呢?<svnbootstrapper>就是為從源碼控制系統(tǒng)更新buildfile文件而設(shè)計(jì)的(還有 一種替代的使用方法是使用wrapper buildfile,這樣就不用使用<svnbootstrapper>了,wrapper buildfile也是推薦的方法,<modificationset>部分會(huì)進(jìn)行詳細(xì)的討論)。

    <modificationset>:包括了SourceControl插件的配置信息,用于檢查各個(gè)源碼控制系統(tǒng)中是否發(fā)生變化,<schedule>會(huì)用到這里的配置信息,如果檢測(cè)到變化,會(huì)觸發(fā)創(chuàng)建過程。

    <modificationset>的屬性quietperiod(單位為秒)定義了一個(gè)時(shí)間值。如果CC檢查到了變化,會(huì)自檢查到變化的源碼控制系統(tǒng)的最后一次check in 的時(shí)間開始等待,等待時(shí)間由quietperiod決定,等待結(jié)束之后才觸發(fā)創(chuàng)建(build)過程,主要是防止有人在check in的過程當(dāng)中就觸發(fā)創(chuàng)建過程(可能check in只做了一半,這個(gè)時(shí)候觸發(fā)創(chuàng)建顯然是不正確的).

    下面是一個(gè)modificationset的例子:

    <modificationset quietperiod="30">
                <svn localworkingcopy="projects/SFA"/>
    </modificationset>


    |

    posted on 2009-11-05 17:50 找個(gè)美女做老婆 閱讀(2297) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計(jì)

    公告

    本blog已經(jīng)搬到新家了, 新家:www.javaly.cn
     http://www.javaly.cn

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲精品网站在线观看不卡无广告| 国产一级婬片A视频免费观看| 在线看片免费人成视久网| 久久亚洲国产成人影院网站| 欧美亚洲国产SUV| 国产精品公开免费视频| 精品亚洲国产成人av| 免费jjzz在线播放国产| 男女污污污超污视频免费在线看| 四虎影视精品永久免费网站| 美女尿口扒开图片免费| 亚洲熟女乱综合一区二区| aa在线免费观看| 亚洲国产精品高清久久久| 外国成人网在线观看免费视频| 亚洲视频一区调教| 国产精彩免费视频| 亚洲av无码专区国产不乱码| 啊v在线免费观看| 97在线免费视频| 中文字幕亚洲精品资源网| 色婷婷7777免费视频在线观看| 亚洲国产精品无码久久久秋霞1| 免费人成激情视频| 久久国产精品免费视频| 亚洲冬月枫中文字幕在线看| 国产成人精品免费视频大全五级| 一区二区三区免费视频观看| 亚洲黄色在线电影| 国产午夜无码视频免费网站 | 国产精品免费电影| 高清永久免费观看| 亚洲最大的黄色网| 亚洲午夜福利精品无码| xx视频在线永久免费观看| 色妞www精品视频免费看| 亚洲AV无码成人专区片在线观看| 毛片大全免费观看| 久久免费99精品国产自在现线| 亚洲乱码一二三四五六区| 亚洲精品麻豆av|