通过本地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:
REM Version:1.0
REM 根据自己的环境设置目标根目录和classes长度
rem Update log
rem v1. 使用 xcopy命令 /exclude:exclude.cfg 来排除指定文件
rem v1. 使用 >nul 去掉xcopy,dir命令在屏幕上提示运行结果
rem v1. 本版本将原有的xcpfile和checkfilecount失效了,objectslist.cfg文件来源为SVN log中的路径,见rootpath,sourcerootpath
rem v1. SVN showlog中选择部署文件时需注意,遇到list为目录的情况,此脚本会直接复制完整的目录下的文件,请注意遴选
rem v1. 选择SVN LOG LIST文件时,不要直接选择所有,否则delete掉的文件不存在会导致复制失败
rem v1. 通过正确的设置rootpath,sourcerootpath,此脚本能同时满足objlist为服务器路径和本地路径的情况
rem v1. 加入检查所有被复制的文件的编译日期为今天,防止漏编译的情况
rem v1. 加入源class文件是否存在的判断,不存在则中止执行,旧版本会继续往下执行,由xcopy命令会给出提示找不到文件
rem v1. 此种情况多半是SVN中的更改类型为delete,但是没有在objectslist中排除该文件导致,检查objectslist
rem v1. 忽略objectslist.cfg中以#开头的行
rem v1. 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:~,%%date:~,%%date:~,%
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=
set copycount= 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!+
) else (
rem 复制文件
rem copy !classpath! !targetpath!
xcopy /Y /Q /S /exclude:exclude.cfg !classpath! !targetpath! >nul
rem set /a copycount=!copycount!+
) )
goto:eof rem 获取字符串长度
:length
set "str=%~1"
for /l %%i in (,,) 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=%~
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:~,%%updatetime:~,%%updatetime:~,%
rem echo updatestr !updatestr! set str=%~
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:~,!!updatetime:~,!!updatetime:~,!
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=
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=
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+=
) rem echo sourcepath !sourcepath! sourcecount !sourcecount! set targetcount=
rem 加入2^>nul解决目标文件夹中没有文件时,屏幕显示找不到文件的问题
for /f "delims=" %%b in ('dir !targetpath! /b/s/a-d 2^>nul ^| findstr /v !execludestr! ' ) do (
set /a targetcount+=
)
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

最新文章

  1. 【转】java架构师之路:JAVA程序员必看的15本书的电子版下载地址
  2. 立体匹配:关于用OpenCV彩色化middlebury网站给定的视差
  3. StringBuilder与StringBuffer的区别(转)
  4. 向大家推荐个android的游戏引擎——cocos2d-x
  5. 一种新的隐藏-显示模式诞生——css3的scale(0)到scale(1)
  6. 点击率模型AUC
  7. 你不知道的JS之作用域和闭包(三)函数 vs. 块级作用域
  8. JS中的一元操作符
  9. MongoDB基础知识(二)
  10. redis-缓存失效三种策略(FIFO 、LRU、LFU)
  11. C# sapnco支持.net 4.5了,真是个意外的发现
  12. hdu-2639 Bone Collector II 背包第K优
  13. VMware Harbor学习
  14. hibernate 验证异常 javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint
  15. Python模块汇总
  16. 使用MyBatis查询 返回类型为int,但是当查询结果为空NULL,报异常的解决方法
  17. day013-流
  18. Android学习笔记_31_通过后台代码生成View对象以及动态加载XML布局文件到LinearLayout
  19. Ubuntu 常见错误及解决方法——长期不定时更新
  20. 20165210 Java第一周学习总结

热门文章

  1. 01: vue.js安装
  2. 20145310《网络对抗》注入shellcode及Return-to-libc
  3. 20145324王嘉澜《网络对抗技术》web安全基础实践
  4. CSAPP 第三章 读书笔记
  5. Visual Leak Detector简明使用教程
  6. linux中C语言发送广播报文
  7. navicat Window . MAC版常用快捷键
  8. codevs 1200 同余方程 逆元
  9. python pandas demo
  10. Jmeter 中多线程并发和循环控制器