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;
}
然后保存执行:
会自动生成ROOT目录