批處理解決Ant自動下載CVS項目並打包

預裝環境:CVS、Ant

實現功能:批處理傳遞項目名稱進去,自動從 CVS server 獲取工程並壓縮。

主要代碼:

@echo off
if "%1"=="-h" goto help
if "%1"=="-p" if "%2" neq "" (
set proname=%2
goto useage
) else (
goto help
)
:help
echo checkout project from cvs
echo getProjectFromCVS [-p] [-h]
echo 	-p specify the project name which you want to checkout
echo 	-h help doucument
goto end
:useage
set tmpfile1=tmptmpbuild.properties
set tmpfile2=tmptmpbuild.xml
rem generate prop file
echo cvs.user = build>>%tmpfile1%
echo cvs.pass = temp4now>>%tmpfile1%
echo cvs.repository = :pserver:${cvs.user}:${cvs.pass}@192.168.42.248:/var/cvs>>%tmpfile1%
echo ci.root = ../CodeRepository>>%tmpfile1%
echo check.outdir = ${ci.root}/CheckOut>>%tmpfile1%
echo build.path = C:/Users/Cui/Desktop>>%tmpfile1%
echo project.name = %proname%>>%tmpfile1%
rem build xml file 
echo ^<?xml version="1.0"?^>>>%tmpfile2%
echo ^<project name="AntCVS" basedir="." default="clean"^>>>%tmpfile2%
echo ^<property file="%tmpfile1%" /^>>>%tmpfile2%
echo ^<target name="init"^>>>%tmpfile2%
echo ^<mkdir dir="${checkout.dir}" /^>>>%tmpfile2%
echo ^<mkdir dir="${build.path}/${project.name}-build" /^>>>%tmpfile2%
echo ^</target^>>>%tmpfile2%
echo ^<target name="checkOut" depends="init" description="CheckOut sources "^>>>%tmpfile2%
echo ^<cvs cvsRoot="${cvs.repository}" package="${project.name}" dest="${checkout.dir}" /^>>>%tmpfile2%
echo ^</target^>>>%tmpfile2%
echo ^<target name="build" depends="checkOut"^>>>%tmpfile2%
echo ^<tstamp^>>>%tmpfile2%
echo ^<format property="CurTime" pattern="yyyy-MM-dd-hh-mm" locale="us"/^>>>%tmpfile2%
echo ^</tstamp^>>>%tmpfile2%
echo ^<tar destfile="${build.path}/${project.name}-build/${project.name}-${CurTime}.tar.gz" basedir="${checkout.dir}"/^>>>%tmpfile2%
echo ^</target^>>>%tmpfile2%
echo ^<target name="clean" depends="build" description=""^>>>%tmpfile2%
echo ^<delete dir="${checkout.dir}" /^>>>%tmpfile2%
echo ^</target^>>>%tmpfile2%
echo ^</project^>>>%tmpfile2%
echo start checkout project %project.name% ...
cmd /c ant -buildfile %tmpfile2%
echo end checkout project ...
echo delete temple file ...
del /f %tmpfile1%
del /f %tmpfile2%
:end
pause

黑體的部分可以自行更改。也可以把這些做成配置文件或者參數。Ant 可以直接獲取 *.properties 的 “變量名字=變量值” 的 “鍵值對”。

運行方式:



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章