通過本地SVN獲得未提交的文件列表獲取工程中最新的class的方式參考:
新寫了一個增強版,根據已提交至SVN的代碼loglist,獲取最新的class方式,同時也支持根據本地未提交列表進行導出。
目的是解決開發過程中的以下問題:
1.在開發過程中,由於部分功能或者流程限制部分代碼遲遲不能提交至生產環境,但是已經在本地積攢了很久,每次都要和其他開發同事人肉合並代碼。
2.代碼老是放在本地,會導致積攢的測試通過和開發中的代碼混合的越來越多。
3.以前是以保證SVN代碼與生產環境的代碼保持同步,作為基線處理,新的方式只需要在上次部署的時間version打上標記即可。
解決思路:
1.建立一個獨立的工程,工程源碼以SVN中最新的文件,不包含任何本地開發的代碼。
2.項目中需要標准的class等,直接使用mklink的方式創建目錄鏈接,避免需要復制標准的class.
3.將源文件的路徑中的java字符串替換為class,路徑替換為class對應目錄
4.執行復制。
5.檢查是否完整復制。
優點:
1.適合於測試通過即可提交SVN,不用將大量代碼攢到本地開發目錄。
2.適合團隊協作,當多人都在修改某個文件時,不再需要層層對比合並。
3.此方法不限於OAF項目,我個人覺得適合所有的需要增量部署的項目,包括其他的java項目。
1.建立新工程
new project ->Business Components Project

2.引入SVN代碼

設置MDS XML Path
 
3.bl_prod目錄下建立標准class及依賴源碼的link目錄鏈接,命令如下
mklink /D C:\JDeveloper\jdevhome\jdev\myprojects\bl_prod\classes\oracle C:\JDeveloper\jdevhome\jdev\myclasses\oracle
mklink /D C:\JDeveloper\jdevhome\jdev\myprojects\bl_prod\src\oracle\ C:\JDeveloper\jdevhome\jdev\myprojects\oracle\
如下:

至此,需要准備的工程結構已就緒。
4.准備需要的objectlists.
SVN:show log->選中需要的文件->右鍵 copy to clipboard->Paths relative to root.
粘貼至objectslist。
注意復制出來的SVN路徑為 / 目錄結構。
使用過程中xcpfile.bat中有三個目錄需要根據自己的使用做調整

此腳本在xcpfile中加入了嚴格校驗所有文件的編譯日期是否為當前日期的功能,根據需要進行注釋,目的是防止忘記更新及編譯。
rem 嚴格校驗編譯時間是否為今天,根據需求選擇是否需要注釋掉此邏輯
rem 建議使用獨立的SVN最新文件的工程
call:checkfilebuildtime !classpath! 
        文件下載:xcpfile_v1.0.zip
使用方法:解壓,更改xcpfile.bat中的tarrootpath,rootpath,sourcerootpath變量。
執行,通過CMD命令行進入到xcpfile所在的目錄,執行xcpfile.bat即可。會自動復制文件,並檢查完整性。最后復制的目標目錄會輸出到屏幕。
xcpfile.bat,以ANSI編碼格式保存
@echo off&setlocal enabledelayedexpansion REM AUTHOR:黃洪波 REM DATE:20171027 REM Version:1.0 REM 根據自己的環境設置目標根目錄和classes長度 rem Update log rem v1.1 使用 xcopy命令 /exclude:exclude.cfg 來排除指定文件 rem v1.3 使用 2>nul 去掉xcopy,dir命令在屏幕上提示運行結果 rem v1.7 本版本將原有的xcpfile和checkfilecount失效了,objectslist.cfg文件來源為SVN log中的路徑,見rootpath,sourcerootpath rem v1.7 SVN showlog中選擇部署文件時需注意,遇到list為目錄的情況,此腳本會直接復制完整的目錄下的文件,請注意遴選 rem v1.7 選擇SVN LOG LIST文件時,不要直接選擇所有,否則delete掉的文件不存在會導致復制失敗 rem v1.7 通過正確的設置rootpath,sourcerootpath,此腳本能同時滿足objlist為服務器路徑和本地路徑的情況 rem v1.8 加入檢查所有被復制的文件的編譯日期為今天,防止漏編譯的情況 rem v1.9 加入源class文件是否存在的判斷,不存在則中止執行,舊版本會繼續往下執行,由xcopy命令會給出提示找不到文件 rem v1.9 此種情況多半是SVN中的更改類型為delete,但是沒有在objectslist中排除該文件導致,檢查objectslist rem v1.10 忽略objectslist.cfg中以#開頭的行 rem v1.11 rootpath不再需要將/替換為\,直接取objectslist中的根目錄string即可。 REM 使用方法,在copy.bat同級目錄下建立文件objectslist.cfg,將需要部署的文件的源文件(java,xml)按行放入cfg文件中 REM 本方法默認cfg中為文件列表,未處理文件夾的情況 REM 配合SVN使用,效果極好,SVN COMMIT,右鍵選擇需要部署的文件,COPY FULL PATHS REM 執行cpfile.bat命令 REM 使用xcopy配合參數來達到遞歸拷貝文件夾的目的 REM 需要排除的文件放入exclude.cfg中 REM 獲取當前日期 YYYYMMDD set datestr=%date:~0,4%%date:~5,2%%date:~8,2% rem echo !datestr! REM 替換為自己想要的目標路徑 set tarrootpath=C:\Work\項目\CUX項目\DEV部署\!datestr!\install\ rem 設置目標根目錄 set tarpath=!tarrootpath!code\oaf\ REM 根據自己的C:\JDeveloper\jdevhome\jdev\myclasses\,myclasses目錄的路徑長度進行設置 rem set sourcerootpath=C:\JDeveloper\jdevhome\jdev\myclasses\ rem 根據SVN目錄處理源路徑和目標路徑 rem 支持windows目錄列表\形式以及linux目錄/形式 rem 本地目錄列表獲取方式,開發目錄,右鍵SVN Commit,選擇需要的文件,右鍵copy to clipboard,full path rem set rootpath=C:\JDeveloper\jdevhome\jdev\myprojects\ rem set sourcerootpath=C:\JDeveloper\jdevhome\jdev\myclasses\ rem SVN最新工程目錄,右鍵SVN LOG,選擇需要的文件,Copy to clipboard, path relative to root set rootpath=/TECH_EBS/OAF_CODE/ set sourcerootpath=C:\JDeveloper\jdevhome\jdev\myprojects\bl_prod\classes\ REM 全局變量 set len= set splitstr= set filecount=0 set copycount=0 rem 將被排除的文件名稱組成字符串,findstr加入""則是判斷字符串,不加則是通過文件進行判斷 set execludestr=" for /f "eol=# tokens=*" %%i in (exclude.cfg) do ( set str=%%i rem echo str !str! set execludestr=!execludestr! !str! ) set execludestr=!execludestr!" rem echo execludestr !execludestr! call:length !sourcerootpath! rem 獲取sourcerootpath的長度 rem 設置lgth為數字型 set /a lgth=!len! rem echo lgth !lgth! rem 判斷目標根目錄是否存在 if not exist !tarpath! ( md !tarpath! ) rem xcopy命令會自動創建目錄 call xcopy /Y /Q /S install.cfg !tarrootpath! >nul call xcopy /Y /Q /S install.pl !tarrootpath! >nul echo 正在復制... call:xcpfile echo 執行檢查... rem 檢查數量 call:checkfilecount goto:eof rem 此方法為最新根據SVN路徑獲取到的文件路徑進行復制 :xcpfile set rootpathtemp=!rootpath:/=\! for /f "eol=# tokens=*" %%i in (objectslist.cfg) do ( set str=%%i rem echo str !str! rem 替換行文本中的myprojects為myclasses set temp=!str:/=\! rem echo temp !temp! rem 替換行文本中的java為class set temp1=!temp:java=class! rem 設置class及xml文件完整文件路徑 set classpath=!temp1:%rootpathtemp%=%sourcerootpath%! rem echo classpath !classpath! rem 得到classpath的長度 call:length !classpath! rem classpath的完整長度賦值給length1 set length1=!len! rem echo length1 is !length1! rem 獲取以\拆分classpath,獲取最后一個"\"字符之后的內容 call:splitstring !classpath! rem echo splitstr is !splitstr! rem 獲取classpath中\后的字符長度 call:length !splitstr! rem 將其賦值給length2 set length2=!len! rem echo length2 is !length2! rem 判斷是否存在 if not exist !classpath! ( echo 該文件或文件夾!classpath!不存在,請檢查文件或者objectslist.cfg rem 檢查該文件或目錄是否存在(使用此命令不能再使用向上回滾出最近運行的命令) cmd /k ) rem 嚴格校驗編譯時間是否為今天,根據需求選擇是否需要注釋掉此邏輯 rem 建議使用獨立的SVN最新文件的工程 rem 檢查到編譯時間錯誤,中止當前腳本運行 call:checkfilebuildtime !classpath! rem 判斷是否為目錄 if exist !classpath!\ ( rem echo !classpath! is dir rem echo lgth is !lgth! rem 獲取類路徑 call set clapth=%%classpath:~!lgth!%% rem echo clapth dir !clapth! ) else ( rem 判斷文件的編譯是否為今天 rem echo !classpath! is file rem 做減法運算 rem 此處的需要根據本地的路徑長度做調整 set /a leng=!length1!-!length2!-!lgth! rem echo leng !leng! rem 獲取類路徑 call set clapth=%%classpath:~!lgth!,!leng!%% rem echo clapth !clapth! ) set targetpath=!tarpath!!clapth! rem echo targetpath !targetpath! rem 判斷目標根目錄是否存在 if not exist !targetpath! ( md !targetpath! rem copy !classpath! !targetpath! REM /S 不復制空目錄 call xcopy /Y /Q /S /exclude:exclude.cfg !classpath! !targetpath! >nul rem set /a copycount=!copycount!+1 ) else ( rem 復制文件 rem copy !classpath! !targetpath! xcopy /Y /Q /S /exclude:exclude.cfg !classpath! !targetpath! >nul rem set /a copycount=!copycount!+1 ) ) goto:eof rem 獲取字符串長度 :length set "str=%~1" for /l %%i in (0,1,200) do if "!str:~%%i,1!"=="" set strlen=%%i && goto :end :end rem echo 字符串長度為 %strlen% set len=%strlen% rem echo 長度為 %len% goto:eof rem 按\拆分字符串 :splitstring set string=%~1 set split= :split for /f "tokens=1,* delims=\" %%i in ("%string%") do ( rem echo %%i set string=%%j set split=%%i ) if not "%string%"=="" goto split rem echo split !split! set splitstr=%split% goto:eof rem 檢查被復制的文件的編譯日期是否為今天 rem 防止忘記編譯的情況 :checkfilebuildtime rem for /f %%a in ('dir /a-d/b/tw exclude.cfg') do set tw=%%~ta rem echo %tw% rem for %%i in (exclude.cfg) do ( rem echo %%~ti rem set updatetime=%%~ti rem ) rem echo updatetime !updatetime! rem set updatestr=%updatetime:~0,4%%updatetime:~5,2%%updatetime:~8,2% rem echo updatestr !updatestr! set str=%~1 rem echo str !str! rem str路徑為目錄 if exist !str!\ ( rem 列出str目錄下所有的文件,並判斷編譯日期 for /f "delims=" %%b in ('dir !str! /b/s/a-d 2^>nul ^| findstr /v !execludestr! ' ) do ( set filestr=%%b rem echo !filestr! call:checkfilebuildtime !filestr! ) ) else ( for %%i in (%str%) do ( rem echo %%~ti set updatetime=%%~ti ) rem echo updatetime !updatetime! set updatestr=!updatetime:~0,4!!updatetime:~5,2!!updatetime:~8,2! rem echo updatestr !updatestr! if !updatestr! NEQ !datestr! ( rem echo errorstr !errorstr! echo 該文件!str!的編譯日期為!updatestr!不是今天,請檢查! rem 檢查到錯誤,暫停運行,但是按任意鍵后仍然會繼續執行 rem pause >nul rem 檢查到編譯時間錯誤,中止當前腳本運行(使用此命令不能再使用向上回滾出最近運行的命令) cmd /k ) ) goto:eof rem 檢查文件數量 :checkfilecount set rootpathtemp=!rootpath:/=\! set notexistscount=0 set errorstr= for /f "eol=# tokens=*" %%i in (objectslist.cfg) do ( set str=%%i rem echo str !str! rem 替換行文本中的myprojects為myclasses set temp=!str:/=\! rem echo temp !temp! rem 替換行文本中的java為class set temp1=!temp:java=class! rem 設置class及xml文件完整文件路徑 set sourcepath=!temp1:%rootpathtemp%=%sourcerootpath%! rem echo classpath !classpath! call set clapth=%%sourcepath:~!lgth!%% set targetpath=!tarpath!!clapth! rem echo sourcepath !sourcepath! targetpath !targetpath! rem 源路徑為文件夾 if exist !sourcepath!\ ( set sourcecount=0 rem 加入2^>nul解決目標文件夾中沒有文件時,屏幕顯示找不到文件的問題 rem 列出sourcepath下所有的文件且排除execludestr for /f "delims=" %%b in ('dir !sourcepath! /b/s/a-d 2^>nul ^| findstr /v !execludestr! ' ) do ( set /a sourcecount+=1 ) rem echo sourcepath !sourcepath! sourcecount !sourcecount! set targetcount=0 rem 加入2^>nul解決目標文件夾中沒有文件時,屏幕顯示找不到文件的問題 for /f "delims=" %%b in ('dir !targetpath! /b/s/a-d 2^>nul ^| findstr /v !execludestr! ' ) do ( set /a targetcount+=1 ) rem echo targetpath !targetpath! targetcount !targetcount! if !sourcecount! NEQ !targetcount! ( rem echo errorstr !errorstr! set errorstr=!errorstr! !sourcepath!中有文件復制失敗 ) ) else ( rem echo file targetpath !targetpath! if not exist !targetpath! ( rem echo errorstr !errorstr! set errorstr=!errorstr! !sourcepath!復制失敗 ) ) ) if "%errorstr%" =="" ( echo 經檢查,已完整復制objectslist中的文件至 !tarpath! 。 ) else ( for %%i in (!errorstr!) do echo %%i ) goto:eof
exclude.cfg
bc4j.xcfg server.xml .zip
objectslist.cfg
/TECH_EBS/OAF_CODE/cux/oracle/apps/pos/test/server/CuxTestAM.xml /TECH_EBS/OAF_CODE/cux/oracle/apps/pos/test/server/CuxTestAMImpl.java /TECH_EBS/OAF_CODE/cux/oracle/apps/pos/test/server/CuxTestVO.xml /TECH_EBS/OAF_CODE/cux/oracle/apps/pos/test/server/CuxTestVOImpl.java /TECH_EBS/OAF_CODE/cux/oracle/apps/pos/test/webui/CuxTestPG.xml /TECH_EBS/OAF_CODE/cux/oracle/apps/pos/test/webui/CuxTestCO.java
