Cleanup git auth manager after run

This commit is contained in:
Ivan Semenov
2018-02-12 13:50:14 +03:00
parent 8c3aa2a7eb
commit 8392d5066a
2 changed files with 6 additions and 4 deletions
@@ -26,7 +26,7 @@ import java.util.UUID;
* Manager for Git remotes authentication.
* Provides necessary handlers and watcher for http auth failure.
*/
class GitHandlerAuthenticationManager {
class GitHandlerAuthenticationManager implements AutoCloseable {
private static final Logger LOG = Logger.getInstance(GitHandlerAuthenticationManager.class);
@NotNull private final GitLineHandler myHandler;
@@ -50,7 +50,8 @@ class GitHandlerAuthenticationManager {
return manager;
}
public void cleanup() {
@Override
public void close() {
cleanupHttpAuth();
cleanupSshAuth();
}
@@ -10,6 +10,7 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.containers.ContainerUtil;
@@ -30,6 +31,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.function.Consumer;
import static git4idea.commands.GitCommand.LockingPolicy.WRITE;
@@ -108,8 +110,7 @@ abstract class GitImplBase implements Git {
private static GitCommandResult run(@NotNull GitLineHandler handler, @NotNull OutputCollector outputCollector) {
Project project = handler.project();
if (project != null && handler.isRemote()) {
try {
GitHandlerAuthenticationManager authenticationManager = GitHandlerAuthenticationManager.prepare(project, handler);
try (GitHandlerAuthenticationManager authenticationManager = GitHandlerAuthenticationManager.prepare(project, handler)){
return GitCommandResult.withAuthentication(doRun(handler, outputCollector), authenticationManager.isHttpAuthFailed());
}
catch (IOException e) {