• 通过SVN获取变更列表,得到对应的最新class


    通过本地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:JDeveloperjdevhomejdevmyprojectsl_prodclassesoracle C:JDeveloperjdevhomejdevmyclassesoracle
    mklink /D C:JDeveloperjdevhomejdevmyprojectsl_prodsrcoracle C:JDeveloperjdevhomejdevmyprojectsoracle

    如下:

    至此,需要准备的工程结构已就绪。

    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!codeoaf
    
    REM 根据自己的C:JDeveloperjdevhomejdevmyclasses,myclasses目录的路径长度进行设置
    rem set sourcerootpath=C:JDeveloperjdevhomejdevmyclasses
    
    rem 根据SVN目录处理源路径和目标路径
    rem 支持windows目录列表形式以及linux目录/形式
    
    rem 本地目录列表获取方式,开发目录,右键SVN Commit,选择需要的文件,右键copy to clipboard,full path
    rem set rootpath=C:JDeveloperjdevhomejdevmyprojects
    rem set sourcerootpath=C:JDeveloperjdevhomejdevmyclasses
    
    rem SVN最新工程目录,右键SVN LOG,选择需要的文件,Copy to clipboard, path relative to root
    set rootpath=/TECH_EBS/OAF_CODE/
    set sourcerootpath=C:JDeveloperjdevhomejdevmyprojectsl_prodclasses
    
    
    
    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
  • 相关阅读:
    02 树莓派的远程连接
    01 树莓派系统安装
    Python正课110 —— Django入门
    作业7 答案
    作业8
    作业7
    作业6
    文件操作
    字符编码
    基本数据类型之集合
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/8025228.html
Copyright © 2020-2023  润新知