Groovy实现项目增量发布脚本


package groovy
 
import java.util.ArrayList
 
println("开始获取增量文件》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
 
// 增量导出的文件路径
def zengliangPath = "C:\\Users\\Administrator\\Desktop\\20170119\\admin";
 
// copy 编译后的文件至这个目录
def rootpath  = "C:\\Users\\Administrator\\Desktop\\20170119\\ROOT";
 
def filePathList = new ArrayList();
 
def zlfiles = new File(zengliangPath);
 
// 将增量的文件名称装入 List
zlfiles.eachFileRecurse{file ->
     
    if(file.isFile()){
     
        def fileName = file.getName();
     
        filePathList.add(fileName.substring(0,fileName.lastIndexOf(".")));
    }
}
 
println("获取增量文件完成,开始生成打包增量文件》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
 
// 循环工程目录下文件
def workpath = "C:\\Users\\Administrator\\Desktop\\Admin_new\\admin";
 
def workpathfiles = new File(workpath);
 
//copy 文件的工具类
def ant = new AntBuilder();
 
// 工程目录下所有文件
workpathfiles.eachFileRecurse{file ->
 
    // 获取名字
    def fileName = file.getName();
     
    // 是否是文件并且包含"."
    if(file.isFile() && fileName.indexOf(".") > 1){
         
        // 
        def subFileName = fileName.substring(0,fileName.lastIndexOf("."));
         
        // 循环增量文件集合
        filePathList.each{fname ->
         
            // 包含该文件进入
            if(subFileName.contains(fname)){
                 
                // classes下文件
                if(fileName.endsWith(".class") || fileName.endsWith(".txt") || fileName.endsWith(".properties")){
                     
                    def tofilepath = file.getPath().replace(workpath+"\\build",rootpath+"\\WEB-INF");
                     
                    println("复制:" + file.getPath());
                     
                    // 利用 AntBuilder 拷贝文件
                    ant.copy(file : file.getPath(),tofile : tofilepath);
                     
                    /*
                    // 这种方式 class文件不能被反编译打开
                    // 创建新文件
                    def tofile = createFile(tofilepath,true);
                     
                    tofile.withWriter{ffile ->
                        file.eachByte{bytes ->
                            ffile.write(bytes);
                        }
                    }*/
                     
                }
                // 页面资源文件
                else{
                     
                    def tofilepath = file.getPath().replace(workpath+"\\WebContent",rootpath+"\\");
                     
                    println("复制:" + file.getPath());
                     
                    ant.copy(file : file.getPath(),tofile : tofilepath);
                }
            }
        }
    }
}
 
println("生成打包增量文件结束》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》");
 
/**
 * 创建文件
 */
def createFile(path,createIfNotExist){
     
    def file = new File(path);
     
    if(!file.exists()){
         
        if(createIfNotExist){
             
            if(!file.getParentFile().exists()){
             
                file.getParentFile().mkdirs();
            }
             
            file.createNewFile();
        }else{
             
            throw NullPointerException("Missing File :" + path);
        }
    }
     
    return file;
}

然后保存执行:

104528_Yffw_999575.png

会自动生成ROOT目录

转载于:https://my.oschina.net/asilan/blog/828771

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值