Java Code Examples for cn.hutool.core.util.RuntimeUtil#execForStr()

The following examples show how to use cn.hutool.core.util.RuntimeUtil#execForStr() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThemeController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 在线拉取主题
 *
 * @param remoteAddr 远程地址
 * @param themeName  主题名称
 *
 * @return JsonResult
 */
@PostMapping(value = "/clone")
@ResponseBody
public JsonResult cloneFromRemote(@RequestParam(value = "remoteAddr") String remoteAddr,
                                  @RequestParam(value = "themeName") String themeName) {
    if (StrUtil.isBlank(remoteAddr) || StrUtil.isBlank(themeName)) {
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.info-no-complete"));
    }
    try {
        final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
        final File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
        final String cmdResult = RuntimeUtil.execForStr("git clone " + remoteAddr + " " + themePath.getAbsolutePath() + "/" + themeName);
        if (NOT_FOUND_GIT.equals(cmdResult)) {
            return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.no-git"));
        }
        HaloConst.THEMES.clear();
        HaloConst.THEMES = HaloUtils.getThemes();
    } catch (FileNotFoundException e) {
        log.error("Cloning theme failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.clone-theme-failed") + e.getMessage());
    }
    return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.install-success"));
}
 
Example 2
Source File: ThemeController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 更新主题
 *
 * @param themeName 主题名
 *
 * @return JsonResult
 */
@GetMapping(value = "/pull")
@ResponseBody
public JsonResult pullFromRemote(@RequestParam(value = "themeName") String themeName) {
    try {
        final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
        final File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
        final String cmdResult = RuntimeUtil.execForStr("cd " + themePath.getAbsolutePath() + "/" + themeName + " && git pull");
        if (NOT_FOUND_GIT.equals(cmdResult)) {
            return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.no-git"));
        }
        HaloConst.THEMES.clear();
        HaloConst.THEMES = HaloUtils.getThemes();
    } catch (Exception e) {
        log.error("Update theme failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.update-theme-failed") + e.getMessage());
    }
    return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.update-success"));
}
 
Example 3
Source File: ThemeController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 在线拉取主题
 *
 * @param remoteAddr 远程地址
 * @param themeName  主题名称
 * @return JsonResult
 */
@PostMapping(value = "/clone")
@ResponseBody
public JsonResult cloneFromRemote(@RequestParam(value = "remoteAddr") String remoteAddr,
                                  @RequestParam(value = "themeName") String themeName) {
    if (StrUtil.isBlank(remoteAddr) || StrUtil.isBlank(themeName)) {
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.info-no-complete"));
    }
    try {
        File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
        File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
        String cmdResult = RuntimeUtil.execForStr("git clone " + remoteAddr + " " + themePath.getAbsolutePath() + "/" + themeName);
        if (NOT_FOUND_GIT.equals(cmdResult)) {
            return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.no-git"));
        }
        HaloConst.THEMES.clear();
        HaloConst.THEMES = HaloUtils.getThemes();
    } catch (FileNotFoundException e) {
        log.error("Cloning theme failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.clone-theme-failed") + e.getMessage());
    }
    return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.install-success"));
}
 
Example 4
Source File: ThemeController.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 更新主题
 *
 * @param themeName 主题名
 * @return JsonResult
 */
@GetMapping(value = "/pull")
@ResponseBody
public JsonResult pullFromRemote(@RequestParam(value = "themeName") String themeName) {
    try {
        File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
        File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
        String cmdResult = RuntimeUtil.execForStr("cd " + themePath.getAbsolutePath() + "/" + themeName + " && git pull");
        if (NOT_FOUND_GIT.equals(cmdResult)) {
            return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.no-git"));
        }
        HaloConst.THEMES.clear();
        HaloConst.THEMES = HaloUtils.getThemes();
    } catch (Exception e) {
        log.error("Update theme failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.update-theme-failed") + e.getMessage());
    }
    return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.update-success"));
}