diff --git a/community-resources/src/idea/IdeaApplicationInfo.xml b/community-resources/src/idea/IdeaApplicationInfo.xml index 27cec7489b9a..70aa80ac7035 100644 --- a/community-resources/src/idea/IdeaApplicationInfo.xml +++ b/community-resources/src/idea/IdeaApplicationInfo.xml @@ -7,7 +7,7 @@ - + diff --git a/platform/platform-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java b/platform/platform-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java index e8fdcdc5af7c..9cd6853425dc 100644 --- a/platform/platform-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java +++ b/platform/platform-api/src/com/intellij/openapi/application/ApplicationNamesInfo.java @@ -29,10 +29,12 @@ public class ApplicationNamesInfo { @NonNls private static final String ELEMENT_NAMES = "names"; @NonNls private static final String ATTRIBUTE_PRODUCT = "product"; @NonNls private static final String ATTRIBUTE_FULL_NAME = "fullname"; + @NonNls private static final String ATTRIBUTE_SCRIPT = "script"; private String myProductName; private String myFullProductName; private String myLowercaseProductName; + private String myScriptName; private static class ApplicationNamesInfoHolder { private static final ApplicationNamesInfo ourInstance = new ApplicationNamesInfo(); @@ -60,6 +62,7 @@ public class ApplicationNamesInfo { myProductName = names.getAttributeValue(ATTRIBUTE_PRODUCT); myFullProductName = names.getAttributeValue(ATTRIBUTE_FULL_NAME); myLowercaseProductName = StringUtil.capitalize(myProductName.toLowerCase()); + myScriptName = names.getAttributeValue(ATTRIBUTE_SCRIPT); } /** @@ -83,6 +86,13 @@ public class ApplicationNamesInfo { return myLowercaseProductName; } + /** + * @return "idea" + */ + public String getScriptName() { + return myScriptName; + } + public static String getComponentName() { final String prefix = System.getProperty("idea.platform.prefix"); if (prefix != null) { 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 223f1a11a8ef..2860c4753c9d 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/CreateLauncherScriptAction.java @@ -28,6 +28,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.CharsetToolkit; import javax.script.ScriptEngine; @@ -60,10 +61,11 @@ public class CreateLauncherScriptAction extends AnAction { createLauncherScript(project, new File(dialog.myPathField.getText(), dialog.myNameField.getText()).getPath()); } - public static void createLauncherScript(Project project, String pathname) { + public static void createLauncherScript(Project project, String pathName) { + if (!SystemInfo.isUnix) return; try { final File scriptFile = createLauncherScriptFile(); - File scriptTarget = new File(pathname); + final File scriptTarget = new File(pathName); if (scriptTarget.exists()) { int rc = Messages.showOkCancelDialog(project, "The file " + scriptTarget + " already exists. Would you like to overwrite it?", "Create Launcher Script", Messages.getQuestionIcon()); @@ -72,22 +74,22 @@ public class CreateLauncherScriptAction extends AnAction { } } - if (!scriptFile.renameTo(scriptTarget)) { - if (SystemInfo.isUnix) { - final String launcherScriptContainingDirPath = scriptTarget.getParent(); - final String installationScriptSrc = - // create all intermediate folders - "mkdir -p " + launcherScriptContainingDirPath + "\n" + - // Copy file & change owner to root - // uid 0 = root - // gid 0 = root || wheel (MacOS) - "install -g 0 -o 0 " + scriptFile.getCanonicalPath() + " " + pathname; - final File installationScript = createTempExecutableScript("launcher_installer", installationScriptSrc); + final File launcherScriptContainingDir = scriptTarget.getParentFile(); + if (!(launcherScriptContainingDir.exists() || launcherScriptContainingDir.mkdirs()) || + !scriptFile.renameTo(scriptTarget)) { + final String launcherScriptContainingDirPath = launcherScriptContainingDir.getCanonicalPath(); + final String installationScriptSrc = + // create all intermediate folders + "mkdir -p " + launcherScriptContainingDirPath + "\n" + + // Copy file & change owner to root + // uid 0 = root + // gid 0 = root || wheel (MacOS) + "install -g 0 -o 0 " + scriptFile.getCanonicalPath() + " " + pathName; + final File installationScript = createTempExecutableScript("launcher_installer", installationScriptSrc); - sudo(installationScript.getCanonicalPath(), - installationScriptSrc, - "In order to create a launcher script in " + launcherScriptContainingDirPath + ", please enter your administrator password:"); - } + sudo(installationScript.getCanonicalPath(), + installationScriptSrc, + "Please enter your password to create a launcher script in a " + launcherScriptContainingDirPath); } } catch (Exception e) { @@ -96,8 +98,8 @@ public class CreateLauncherScriptAction extends AnAction { } } - private static boolean sudo(String installationScriptPath, - String installScriptSrc, + private static boolean sudo(final String installationScriptPath, + final String installScriptSrc, final String prompt) throws IOException, ScriptException, ExecutionException { if (SystemInfo.isMac) { final ScriptEngine engine = new ScriptEngineManager(null).getEngineByName("AppleScript"); @@ -106,7 +108,7 @@ public class CreateLauncherScriptAction extends AnAction { } engine.eval("do shell script \"" + installationScriptPath + "\" with administrator privileges"); } - else if (SystemInfo.isUnix) { + else { GeneralCommandLine cmdLine = new GeneralCommandLine(); if (SystemInfo.isGnome) { cmdLine.setExePath("gksudo"); @@ -131,18 +133,20 @@ public class CreateLauncherScriptAction extends AnAction { final File tempFile = FileUtil.createTempFile("launcher", ""); final InputStream stream = CreateLauncherScriptAction.class.getClassLoader().getResourceAsStream("launcher.py"); + @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") String launcherContents = FileUtil.loadTextAndClose(new InputStreamReader(stream)); launcherContents = launcherContents.replace("$CONFIG_PATH$", PathManager.getConfigPath()); String homePath = PathManager.getHomePath(); - String productName = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(); if (SystemInfo.isMac) { // Just use "*.app" launcherContents = launcherContents.replace("$RUN_PATH$", homePath); } else { + String productName = ApplicationNamesInfo.getInstance().getProductName().toLowerCase(); launcherContents = launcherContents.replace("$RUN_PATH$", homePath + "/bin/" + productName + ".sh"); } + FileUtil.writeToFile(tempFile, launcherContents.getBytes(CharsetToolkit.UTF8_CHARSET)); if (!tempFile.setExecutable(true)) { throw new IOException("Failed to mark the launcher script as executable"); @@ -161,19 +165,13 @@ public class CreateLauncherScriptAction extends AnAction { } public static String defaultScriptName() { - String productName = ApplicationNamesInfo.getInstance().getProductName(); - if (productName.equalsIgnoreCase("RubyMine")) { - return "mine"; - } - else if (productName.equalsIgnoreCase("PyCharm")) { - return "charm"; - } - return "idea"; + final String productName = ApplicationNamesInfo.getInstance().getScriptName(); + return StringUtil.isEmptyOrSpaces(productName) ? "idea" : productName; } @Override public void update(AnActionEvent e) { - boolean canCreateScript = SystemInfo.isUnix || SystemInfo.isMac; + final boolean canCreateScript = SystemInfo.isUnix; e.getPresentation().setVisible(canCreateScript); }