use of cn.hutool.core.io.FileUtil in project Jpom by dromara.
the class JpomApplicationEvent method clearOldJar.
private static void clearOldJar() {
File oldJars = JpomManifest.getOldJarsPath();
List<File> files = FileUtil.loopFiles(oldJars, 1, file -> StrUtil.endWith(file.getName(), FileUtil.JAR_FILE_EXT, true));
if (CollUtil.isEmpty(files)) {
return;
}
// 排序
files.sort((o1, o2) -> FileUtil.lastModifiedTime(o2).compareTo(FileUtil.lastModifiedTime(o1)));
// 截取
int size = CollUtil.size(files);
files = CollUtil.sub(files, ExtConfigBean.getInstance().getOldJarsCount(), size);
// 删除文件
files.forEach(FileUtil::del);
}
use of cn.hutool.core.io.FileUtil in project Jpom by dromara.
the class AutoBackLog method checkProject.
private static void checkProject(NodeProjectInfoModel nodeProjectInfoModel, NodeProjectInfoModel.JavaCopyItem javaCopyItem) {
File file = javaCopyItem == null ? new File(nodeProjectInfoModel.getLog()) : nodeProjectInfoModel.getLog(javaCopyItem);
if (!file.exists()) {
return;
}
long len = file.length();
if (len > MAX_SIZE.getSize()) {
try {
AbstractProjectCommander.getInstance().backLog(nodeProjectInfoModel, javaCopyItem);
} catch (Exception ignored) {
}
}
// 清理过期的文件
File logFile = javaCopyItem == null ? nodeProjectInfoModel.getLogBack() : nodeProjectInfoModel.getLogBack(javaCopyItem);
DateTime nowTime = DateTime.now();
List<File> files = FileUtil.loopFiles(logFile, pathname -> {
DateTime dateTime = DateUtil.date(pathname.lastModified());
long days = DateUtil.betweenDay(dateTime, nowTime, false);
long saveDays = AgentExtConfigBean.getInstance().getLogSaveDays();
return days > saveDays;
});
files.forEach(FileUtil::del);
}
use of cn.hutool.core.io.FileUtil in project Jpom by dromara.
the class JpomApplicationEvent method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
// 启动最后的预加载
if (event instanceof ApplicationReadyEvent) {
//
checkPath();
JpomManifest jpomManifest = JpomManifest.getInstance();
ConfigBean instance = ConfigBean.getInstance();
// 清理旧进程新文件
File dataDir = FileUtil.file(instance.getDataPath());
List<File> files = FileUtil.loopFiles(dataDir, 1, pathname -> pathname.getName().startsWith("pid."));
files.forEach(FileUtil::del);
try {
this.lockFile(jpomManifest.getPid());
} catch (IOException e) {
DefaultSystemLog.getLog().error("lockFile", e);
}
// 写入Jpom 信息 、 写入全局信息
File appJpomFile = instance.getApplicationJpomInfo(JpomApplication.getAppType());
FileUtil.writeString(jpomManifest.toString(), appJpomFile, CharsetUtil.CHARSET_UTF_8);
// 检查更新文件
checkUpdate();
//
if (ApplicationEventLoad.class.isAssignableFrom(JpomApplication.getAppClass())) {
ApplicationEventLoad eventLoad = (ApplicationEventLoad) SpringUtil.getBean(JpomApplication.getAppClass());
eventLoad.applicationLoad();
}
Console.log("Jpom Successful start preparation. start loading module");
} else if (event instanceof ContextClosedEvent) {
// 应用关闭
this.unLockFile();
//
ConfigBean instance = ConfigBean.getInstance();
FileUtil.del(instance.getPidFile());
//
File appJpomFile = instance.getApplicationJpomInfo(JpomApplication.getAppType());
FileUtil.del(appJpomFile);
}
}
Aggregations