use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class ProjectFileControl method readFile.
/**
* 读取文件内容 (只能处理文本文件)
*
* @param filePath 相对项目文件的文件夹
* @param filename 读取的文件名
* @return json
*/
@PostMapping(value = "read_file", produces = MediaType.APPLICATION_JSON_VALUE)
public String readFile(String filePath, String filename) {
NodeProjectInfoModel pim = getProjectInfoModel();
filePath = StrUtil.emptyToDefault(filePath, File.separator);
// 判断文件后缀
AgentWhitelist whitelist = whitelistDirectoryService.getWhitelist();
Charset charset = AgentWhitelist.checkFileSuffix(whitelist.getAllowEditSuffix(), filename);
File file = FileUtil.file(pim.allLib(), filePath, filename);
String ymlString = FileUtil.readString(file, charset);
return JsonMessage.getString(200, "", ymlString);
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class ProjectFileControl method deleteFile.
@RequestMapping(value = "deleteFile", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String deleteFile(String filename, String type, String levelName) {
NodeProjectInfoModel pim = getProjectInfoModel();
File file;
if (StrUtil.isEmpty(levelName)) {
file = FileUtil.file(pim.allLib());
} else {
file = FileUtil.file(pim.allLib(), levelName);
}
if ("clear".equalsIgnoreCase(type)) {
// 清空文件
if (FileUtil.clean(file)) {
return JsonMessage.getString(200, "清除成功");
}
boolean run = AbstractProjectCommander.getInstance().isRun(pim, null);
Assert.state(!run, "文件被占用,请先停止项目");
return JsonMessage.getString(500, "删除失败:" + file.getAbsolutePath());
} else {
// 删除文件
Assert.hasText(filename, "请选择要删除的文件");
file = FileUtil.file(file, filename);
if (file.exists()) {
if (FileUtil.del(file)) {
return JsonMessage.getString(200, "删除成功");
}
} else {
return JsonMessage.getString(404, "文件不存在");
}
return JsonMessage.getString(500, "删除失败");
}
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class ProjectFileControl method getFileList.
@RequestMapping(value = "getFileList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getFileList(String id, String path) {
// 查询项目路径
NodeProjectInfoModel pim = projectInfoService.getItem(id);
Assert.notNull(pim, "查询失败:项目不存在");
String lib = pim.allLib();
File fileDir = FileUtil.file(lib, StrUtil.emptyToDefault(path, FileUtil.FILE_SEPARATOR));
boolean exist = FileUtil.exist(fileDir);
if (!exist) {
return JsonMessage.getString(200, "查询成功", new JSONArray());
}
//
File[] filesAll = fileDir.listFiles();
if (ArrayUtil.isEmpty(filesAll)) {
return JsonMessage.getString(200, "查询成功", new JSONArray());
}
JSONArray arrayFile = FileUtils.parseInfo(filesAll, false, lib);
AgentWhitelist whitelist = whitelistDirectoryService.getWhitelist();
for (Object o : arrayFile) {
JSONObject jsonObject = (JSONObject) o;
String filename = jsonObject.getString("filename");
jsonObject.put("textFileEdit", AgentWhitelist.checkSilentFileSuffix(whitelist.getAllowEditSuffix(), filename));
}
return JsonMessage.getString(200, "查询成功", arrayFile);
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class LogBackController method resetLog.
@RequestMapping(value = "resetLog", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String resetLog(String copyId) {
NodeProjectInfoModel pim = getProjectInfoModel();
NodeProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId);
try {
String msg = AbstractProjectCommander.getInstance().backLog(pim, copyItem);
if (msg.contains("ok")) {
return JsonMessage.getString(200, "重置成功");
}
return JsonMessage.getString(201, "重置失败:" + msg);
} catch (Exception e) {
DefaultSystemLog.getLog().error(e.getMessage(), e);
return JsonMessage.getString(500, "重置日志失败");
}
}
use of io.jpom.model.data.NodeProjectInfoModel in project Jpom by dromara.
the class AbstractProjectCommander method getJpomNameByPid.
/**
* 根据指定进程id获取Jpom 名称
*
* @param pid 进程id
* @return false 不是来自Jpom
* @throws IOException 异常
*/
public String getJpomNameByPid(int pid) throws IOException {
String name = PID_JPOM_NAME.get(pid);
if (name != null) {
return name;
}
String virtualMachine = JvmUtil.getPidJpsInfoInfo(pid);
if (virtualMachine == null) {
return StrUtil.DASHED;
}
String tag = JvmUtil.parseCommandJpomTag(virtualMachine);
DefaultSystemLog.getLog().debug("getJpomNameByPid pid: {} {} {}", pid, tag, virtualMachine);
ProjectInfoService projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
NodeProjectInfoModel item = projectInfoService.getItem(tag);
if (item == null) {
return StrUtil.DASHED;
}
name = item.getName();
if (name != null) {
PID_JPOM_NAME.put(pid, name);
return name;
}
return StrUtil.DASHED;
}
Aggregations