cn.hutool.core.util.RuntimeUtil Java Examples

The following examples show how to use cn.hutool.core.util.RuntimeUtil. 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"));
}
 
Example #5
Source File: TabListener.java    From MooTool with MIT License 4 votes vote down vote up
public static void addListeners() {
    MainWindow.getInstance().getTabbedPane().addChangeListener(new ChangeListener() {
        /**
         * Invoked when the target of the listener has changed its state.
         *
         * @param e a ChangeEvent object
         */
        @Override
        public void stateChanged(ChangeEvent e) {
            int index = MainWindow.getInstance().getTabbedPane().getSelectedIndex();
            switch (index) {
                case 9:
                    try {
                        String ipConfigStr;
                        if (SystemUtil.isWindowsOs()) {
                            ipConfigStr = RuntimeUtil.execForStr("ipconfig");
                        } else {
                            ipConfigStr = RuntimeUtil.execForStr("ifconfig");
                        }
                        NetForm.getInstance().getIpConfigTextArea().setText(ipConfigStr);
                        NetForm.getInstance().getIpConfigTextArea().setCaretPosition(0);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        log.error(ExceptionUtils.getStackTrace(ex));
                    }
                    break;
                case 12:
                case 13:
                case 14:
                    if (warnFlag) {
                        JOptionPane.showMessageDialog(MainWindow.getInstance().getSettingPanel(), "\n该功能尚未实现,目前仅供UI预览\n" +
                                        "\n", "预览提示",
                                JOptionPane.INFORMATION_MESSAGE);
                    }
                    break;
                default:
                    break;
            }
        }
    });
}
 
Example #6
Source File: CommandUtil.java    From Jpom with MIT License 2 votes vote down vote up
/**
 * 执行命令
 *
 * @param cmd 命令行
 * @return 结果
 * @throws IOException IO
 */
private static String exec(String[] cmd, File file) throws IOException {
    DefaultSystemLog.getLog().info(Arrays.toString(cmd));
    Process process = new ProcessBuilder(cmd).directory(file).redirectErrorStream(true).start();
    return RuntimeUtil.getResult(process);
}