Groovy实现项目增量发布脚本
发布时间:2020-12-14 16:42:25 所属栏目:大数据 来源:网络整理
导读:package groovy import java.util.ArrayList println("开始获取增量文件》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》"); // 增量导出的文件路径def zengliangPath = "C:UsersAdministratorDesktop20170119admin"; // copy
package groovy import java.util.ArrayList println("开始获取增量文件》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》"); // 增量导出的文件路径 def zengliangPath = "C:UsersAdministratorDesktop20170119admin"; // copy 编译后的文件至这个目录 def rootpath = "C:UsersAdministratorDesktop20170119ROOT"; 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:UsersAdministratorDesktopAdmin_newadmin"; 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; } 然后保存执行: 会自动生成ROOT目录 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |