Search in sources :

Example 16 with NodeProjectInfoModel

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);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) Charset(java.nio.charset.Charset) AgentWhitelist(io.jpom.model.data.AgentWhitelist) File(java.io.File)

Example 17 with NodeProjectInfoModel

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, "删除失败");
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) File(java.io.File)

Example 18 with NodeProjectInfoModel

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);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) AgentWhitelist(io.jpom.model.data.AgentWhitelist) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File)

Example 19 with NodeProjectInfoModel

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, "重置日志失败");
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with NodeProjectInfoModel

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;
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) ProjectInfoService(io.jpom.service.manage.ProjectInfoService)

Aggregations

NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)40 File (java.io.File)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)18 JSONObject (com.alibaba.fastjson.JSONObject)11 JSONArray (com.alibaba.fastjson.JSONArray)7 AgentWhitelist (io.jpom.model.data.AgentWhitelist)6 AbstractProjectCommander (io.jpom.common.commander.AbstractProjectCommander)5 Charset (java.nio.charset.Charset)5 DiffFileVo (io.jpom.controller.manage.vo.DiffFileVo)4 ConsoleService (io.jpom.service.manage.ConsoleService)4 CollStreamUtil (cn.hutool.core.collection.CollStreamUtil)3 CollUtil (cn.hutool.core.collection.CollUtil)3 Convert (cn.hutool.core.convert.Convert)3 FileUtil (cn.hutool.core.io.FileUtil)3 ThreadUtil (cn.hutool.core.thread.ThreadUtil)3 ArrayUtil (cn.hutool.core.util.ArrayUtil)3 BooleanUtil (cn.hutool.core.util.BooleanUtil)3 StrUtil (cn.hutool.core.util.StrUtil)3 SecureUtil (cn.hutool.crypto.SecureUtil)3 ServletUtil (cn.hutool.extra.servlet.ServletUtil)3