From 4f19472debb804a614b7d772d796331c9b8ab3c9 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 24 Sep 2013 18:05:50 +0200 Subject: [PATCH] CR-IC-2485 (deprecation policy specified; deprecated API usage upgraded) --- .../com/intellij/execution/util/ExecUtil.java | 31 +++++++------------ .../ide/actions/CreateDesktopEntryAction.java | 5 +-- .../actions/CreateLauncherScriptAction.java | 6 ++-- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java index 4ee30df1025c..dc27fa2d59a3 100644 --- a/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java +++ b/platform/platform-api/src/com/intellij/execution/util/ExecUtil.java @@ -177,7 +177,8 @@ public class ExecUtil { * @return the results of running the process */ @NotNull - public static ProcessOutput sudoAndGetOutput(@NotNull List command, @NotNull String prompt, + public static ProcessOutput sudoAndGetOutput(@NotNull List command, + @NotNull String prompt, @Nullable String workDir) throws IOException, ExecutionException { if (SystemInfo.isMac) { final String escapedCommandLine = StringUtil.join(command, new Function() { @@ -242,22 +243,16 @@ public class ExecUtil { return "'" + arg.replace("'", "\\'") + "'"; } - /** - * @deprecated It relies on platform-dependent escaping, use {@link #sudoAndGetOutput(java.util.List, String, String)} instead - */ - @NotNull - public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, - @NotNull final String prompt) throws IOException, ExecutionException { + /** @deprecated relies on platform-dependent escaping, use {@link #sudoAndGetOutput(List, String, String)} instead (to remove in IDEA 14) */ + @SuppressWarnings({"UnusedDeclaration", "deprecation"}) + public static ProcessOutput sudoAndGetOutput(@NotNull String scriptPath, @NotNull String prompt) throws IOException, ExecutionException { return sudoAndGetOutput(scriptPath, prompt, null); } - /** - * @param scriptPath is already escaped file path - * @deprecated It relies on platform-dependent escaping, use {@link #sudoAndGetOutput(java.util.List, String, String)} instead - */ + /** @deprecated relies on platform-dependent escaping, use {@link #sudoAndGetOutput(List, String, String)} instead (to remove in IDEA 14) */ @NotNull - public static ProcessOutput sudoAndGetOutput(@NotNull final String scriptPath, - @NotNull final String prompt, + public static ProcessOutput sudoAndGetOutput(@NotNull String scriptPath, + @NotNull String prompt, @Nullable String workDir) throws IOException, ExecutionException { if (SystemInfo.isMac) { final String script = "do shell script \"" + scriptPath + "\" with administrator privileges"; @@ -288,12 +283,10 @@ public class ExecUtil { throw new UnsupportedSystemException(); } - /** - * @deprecated It relies on platform-dependent escaping, use {@link #sudoAndGetOutput(java.util.List, String, String)} instead - */ - public static int sudoAndGetResult(@NotNull final String scriptPath, - @NotNull final String prompt) throws IOException, ExecutionException { - return sudoAndGetOutput(scriptPath, prompt).getExitCode(); + /** @deprecated relies on platform-dependent escaping, use {@link #sudoAndGetOutput(List, String, String)} instead (to remove in IDEA 14) */ + @SuppressWarnings({"UnusedDeclaration", "deprecation"}) + public static int sudoAndGetResult(@NotNull String scriptPath, @NotNull String prompt) throws IOException, ExecutionException { + return sudoAndGetOutput(scriptPath, prompt, null).getExitCode(); } public static boolean hasTerminalApp() { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java index c84f7e203931..5f259bfe18d1 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateDesktopEntryAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -211,7 +211,8 @@ public class CreateDesktopEntryAction extends DumbAwareAction { "xdg-desktop-menu forceupdate --mode system\n" + "exit $RV\n"); script.deleteOnExit(); - final int result = ExecUtil.sudoAndGetResult(script.getAbsolutePath(), ApplicationBundle.message("desktop.entry.sudo.prompt")); + final String prompt = ApplicationBundle.message("desktop.entry.sudo.prompt"); + final int result = ExecUtil.sudoAndGetOutput(asList(script.getPath()), prompt, null).getExitCode(); if (result != 0) throw new RuntimeException("'" + script.getAbsolutePath() + "' : " + result); } else { diff --git a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java index 8644cd53c3b8..315e3ad5a9fa 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,8 +112,8 @@ public class CreateLauncherScriptAction extends DumbAwareAction { // copy file and change ownership to root (UID 0 = root, GID 0 = root (wheel on Macs)) "install -g 0 -o 0 \"" + scriptFile.getCanonicalPath() + "\" \"" + pathName + "\""; final File installationScript = ExecUtil.createTempExecutableScript("launcher_installer", ".sh", installationScriptSrc); - ExecUtil.sudoAndGetResult(installationScript.getAbsolutePath(), - ApplicationBundle.message("launcher.script.sudo.prompt", launcherScriptContainingDirPath)); + final String prompt = ApplicationBundle.message("launcher.script.sudo.prompt", launcherScriptContainingDirPath); + ExecUtil.sudoAndGetOutput(asList(installationScript.getPath()), prompt, null); } } catch (Exception e) {