diff --git a/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGenerator.java b/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGenerator.java index 82c109b4c71a..5b7981c0076a 100644 --- a/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGenerator.java +++ b/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGenerator.java @@ -1,9 +1,7 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.externalProcessAuthHelper; -import com.intellij.openapi.application.PathManager; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtil; @@ -15,7 +13,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; -import java.io.IOException; import java.util.ArrayList; /** @@ -23,10 +20,6 @@ import java.util.ArrayList; * are removed after application ends. */ public class ScriptGenerator { - /** - * The script prefix - */ - private final String myPrefix; /** * The scripts may class */ @@ -41,13 +34,9 @@ public class ScriptGenerator { private final ArrayList myInternalParameters = new ArrayList<>(); /** - * A constructor - * - * @param prefix the script prefix * @param mainClass the script main class */ - public ScriptGenerator(@NotNull @NonNls String prefix, @NotNull Class mainClass) { - myPrefix = prefix; + public ScriptGenerator(@NotNull Class mainClass) { myMainClass = mainClass; addClasses(myMainClass); addClasses(ExternalApp.class); @@ -80,37 +69,6 @@ public class ScriptGenerator { return this; } - @NotNull - private static File generateBatch(@NotNull @NonNls String fileName, @NotNull @NonNls String commandLine) throws IOException { - @NonNls StringBuilder sb = new StringBuilder(); - sb.append("@echo off").append("\n"); - sb.append(commandLine).append(" %*").append("\n"); - return createTempExecutable(fileName + ".bat", sb.toString()); - } - - @NotNull - private static File generateShell(@NotNull @NonNls String fileName, @NotNull @NonNls String commandLine) throws IOException { - @NonNls StringBuilder sb = new StringBuilder(); - sb.append("#!/bin/sh").append("\n"); - sb.append(commandLine).append(" \"$@\"").append("\n"); - return createTempExecutable(fileName + ".sh", sb.toString()); - } - - @NotNull - private static File createTempExecutable(@NotNull @NonNls String fileName, @NotNull @NonNls String content) throws IOException { - File file = new File(PathManager.getTempPath(), fileName); - FileUtil.writeToFile(file, content); - FileUtil.setExecutable(file); - return file; - } - - @NotNull - public File generate(boolean useBatchFile, @Nullable CustomScriptCommandLineBuilder customBuilder) throws IOException { - String commandLine = commandLine(customBuilder); - return useBatchFile ? generateBatch(myPrefix, commandLine) - : generateShell(myPrefix, commandLine); - } - /** * @return a command line for the customCmdBuilder program */ diff --git a/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGeneratorUtil.java b/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGeneratorUtil.java new file mode 100644 index 000000000000..8074c1908539 --- /dev/null +++ b/platform/external-process-auth-helper/src/externalProcessAuthHelper/ScriptGeneratorUtil.java @@ -0,0 +1,43 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.externalProcessAuthHelper; + +import com.intellij.openapi.application.PathManager; +import com.intellij.openapi.util.io.FileUtil; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.io.IOException; + +public class ScriptGeneratorUtil { + @NotNull + private static File createBatchScript(@NotNull @NonNls String fileName, @NotNull @NonNls String commandLine) throws IOException { + @NonNls StringBuilder sb = new StringBuilder(); + sb.append("@echo off").append("\n"); + sb.append(commandLine).append(" %*").append("\n"); + return createTempExecutable(fileName + ".bat", sb.toString()); + } + + @NotNull + private static File createShellScript(@NotNull @NonNls String fileName, @NotNull @NonNls String commandLine) throws IOException { + @NonNls StringBuilder sb = new StringBuilder(); + sb.append("#!/bin/sh").append("\n"); + sb.append(commandLine).append(" \"$@\"").append("\n"); + return createTempExecutable(fileName + ".sh", sb.toString()); + } + + @NotNull + private static File createTempExecutable(@NotNull @NonNls String fileName, @NotNull @NonNls String content) throws IOException { + File file = new File(PathManager.getTempPath(), fileName); + FileUtil.writeToFile(file, content); + FileUtil.setExecutable(file); + return file; + } + + @NotNull + public static File createTempScript(@NotNull String commandLine, @NotNull String fileNamePrefix, boolean useBatchFile) + throws IOException { + return useBatchFile ? createBatchScript(fileNamePrefix, commandLine) + : createShellScript(fileNamePrefix, commandLine); + } +} diff --git a/platform/external-process-auth-helper/src/externalProcessAuthHelper/XmlRpcHandlerService.java b/platform/external-process-auth-helper/src/externalProcessAuthHelper/XmlRpcHandlerService.java index bae5ac776909..320a2693a7e6 100644 --- a/platform/external-process-auth-helper/src/externalProcessAuthHelper/XmlRpcHandlerService.java +++ b/platform/external-process-auth-helper/src/externalProcessAuthHelper/XmlRpcHandlerService.java @@ -79,8 +79,9 @@ public abstract class XmlRpcHandlerService implements Disposable { String id = scriptId + (useBatchFile ? "-bat" : ""); //NON-NLS File scriptPath = myScriptPaths.get(id); if (scriptPath == null || !scriptPath.exists()) { - ScriptGenerator generator = new ScriptGenerator(myScriptTempFilePrefix + "-" + scriptId, myScriptMainClass); - scriptPath = generator.generate(useBatchFile, customCmdBuilder); + ScriptGenerator generator = new ScriptGenerator(myScriptMainClass); + String commandLine = generator.commandLine(customCmdBuilder); + scriptPath = ScriptGeneratorUtil.createTempScript(commandLine, myScriptTempFilePrefix + "-" + scriptId, useBatchFile); myScriptPaths.put(id, scriptPath); } return scriptPath; diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.java index 2e9c458ad064..714fb240d33f 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditorService.java @@ -11,7 +11,6 @@ import git4idea.commands.GitHandler; import git4idea.config.GitExecutable; import git4idea.editor.GitRebaseEditorApp; import git4idea.editor.GitRebaseEditorXmlRpcHandler; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.ide.BuiltInServerManager; @@ -37,10 +36,6 @@ public final class GitRebaseEditorService implements Disposable { * The lock for the handlers */ private final Object myHandlersLock = new Object(); - /** - * The prefix for rebase editors - */ - @NonNls private static final String GIT_REBASE_EDITOR_PREFIX = "git-rebase-editor-"; /** * @return an instance of the server @@ -77,7 +72,7 @@ public final class GitRebaseEditorService implements Disposable { @NotNull public synchronized String getEditorCommand(@NotNull GitExecutable executable) { synchronized (myScriptLock) { - ScriptGenerator generator = new ScriptGenerator(GIT_REBASE_EDITOR_PREFIX, GitRebaseEditorApp.class); + ScriptGenerator generator = new ScriptGenerator(GitRebaseEditorApp.class); generator.addInternal(Integer.toString(BuiltInServerManager.getInstance().waitForStart().getPort())); return generator.commandLine(executable instanceof ScriptGenerator.CustomScriptCommandLineBuilder ? (ScriptGenerator.CustomScriptCommandLineBuilder)executable : null);