mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] Refactor-simplify git-ssh architecture
Remove GitSSHIdeaService and move everything to GitSSHService. There are no other implementations, and none is planned.
This commit is contained in:
@@ -149,8 +149,8 @@
|
||||
serviceInterface="git4idea.history.wholeTree.GitCommitsSequentially"/>
|
||||
<applicationService serviceInterface="git4idea.config.GitVcsApplicationSettings"
|
||||
serviceImplementation="git4idea.config.GitVcsApplicationSettings"/>
|
||||
<applicationService serviceInterface="git4idea.commands.GitSSHIdeaService"
|
||||
serviceImplementation="git4idea.commands.GitSSHIdeaService"/>
|
||||
<applicationService serviceInterface="org.jetbrains.git4idea.ssh.GitSSHService"
|
||||
serviceImplementation="org.jetbrains.git4idea.ssh.GitSSHService"/>
|
||||
<applicationService serviceInterface="git4idea.rebase.GitRebaseEditorService"
|
||||
serviceImplementation="git4idea.rebase.GitRebaseEditorService"/>
|
||||
<applicationService serviceInterface="git4idea.config.SSHConnectionSettings"
|
||||
|
||||
@@ -418,7 +418,7 @@ public abstract class GitHandler {
|
||||
|
||||
// setup environment
|
||||
if (myRemoteProtocol == GitRemoteProtocol.SSH && myProjectSettings.isIdeaSsh()) {
|
||||
GitSSHService ssh = GitSSHIdeaService.getInstance();
|
||||
GitSSHService ssh = GitSSHService.getInstance();
|
||||
myEnv.put(GitSSHHandler.GIT_SSH_ENV, ssh.getScriptPath().getPath());
|
||||
myHandlerNo = ssh.registerHandler(new GitSSHGUIHandler(myProject, myState));
|
||||
myEnvironmentCleanedUp = false;
|
||||
@@ -490,7 +490,7 @@ public abstract class GitHandler {
|
||||
*/
|
||||
protected synchronized void cleanupEnv() {
|
||||
if (myRemoteProtocol == GitRemoteProtocol.SSH && !myEnvironmentCleanedUp) {
|
||||
GitSSHService ssh = GitSSHIdeaService.getInstance();
|
||||
GitSSHService ssh = GitSSHService.getInstance();
|
||||
myEnvironmentCleanedUp = true;
|
||||
ssh.unregisterHandler(myHandlerNo);
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package git4idea.commands;
|
||||
|
||||
import com.intellij.ide.XmlRpcServer;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.git4idea.ssh.GitSSHHandler;
|
||||
import org.jetbrains.git4idea.ssh.GitSSHService;
|
||||
import org.jetbrains.ide.WebServerManager;
|
||||
|
||||
/**
|
||||
* The git ssh service implementation that uses IDEA XML RCP service
|
||||
*/
|
||||
public class GitSSHIdeaService extends GitSSHService {
|
||||
/**
|
||||
* @return an instance of the server
|
||||
*/
|
||||
@NotNull
|
||||
public static GitSSHIdeaService getInstance() {
|
||||
final GitSSHIdeaService service = ServiceManager.getService(GitSSHIdeaService.class);
|
||||
if (service == null) {
|
||||
throw new IllegalStateException("The service " + GitSSHIdeaService.class.getName() + " cannot be located");
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
public int getXmlRcpPort() {
|
||||
return WebServerManager.getInstance().waitForStart().getPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addInternalHandler() {
|
||||
XmlRpcServer xmlRpcServer = XmlRpcServer.SERVICE.getInstance();
|
||||
if (!xmlRpcServer.hasHandler(GitSSHHandler.HANDLER_NAME)) {
|
||||
xmlRpcServer.addHandler(GitSSHHandler.HANDLER_NAME, new InternalRequestHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.jetbrains.git4idea.ssh;
|
||||
|
||||
import com.intellij.ide.XmlRpcServer;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.trilead.ssh2.KnownHosts;
|
||||
import gnu.trove.THashMap;
|
||||
import org.apache.commons.codec.DecoderException;
|
||||
@@ -22,7 +25,7 @@ import org.apache.xmlrpc.XmlRpcClientLite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.git4idea.util.ScriptGenerator;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import org.jetbrains.ide.WebServerManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -32,7 +35,7 @@ import java.util.Vector;
|
||||
/**
|
||||
* The provider of SSH scripts for the Git
|
||||
*/
|
||||
public abstract class GitSSHService {
|
||||
public class GitSSHService {
|
||||
|
||||
/**
|
||||
* random number generator to use
|
||||
@@ -47,10 +50,17 @@ public abstract class GitSSHService {
|
||||
*/
|
||||
private final THashMap<Integer, Handler> handlers = new THashMap<Integer, Handler>();
|
||||
|
||||
@NotNull
|
||||
public static GitSSHService getInstance() {
|
||||
return ServiceManager.getService(GitSSHService.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the port number for XML RCP
|
||||
*/
|
||||
public abstract int getXmlRcpPort();
|
||||
public int getXmlRcpPort() {
|
||||
return WebServerManager.getInstance().waitForStart().getPort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file to the script service
|
||||
@@ -78,8 +88,6 @@ public abstract class GitSSHService {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract void addInternalHandler();
|
||||
|
||||
/**
|
||||
* Register handler. Note that handlers must be unregistered using {@link #unregisterHandler(int)}.
|
||||
*
|
||||
@@ -87,7 +95,10 @@ public abstract class GitSSHService {
|
||||
* @return an identifier to pass to the environment variable
|
||||
*/
|
||||
public synchronized int registerHandler(@NotNull Handler handler) {
|
||||
addInternalHandler();
|
||||
XmlRpcServer xmlRpcServer = XmlRpcServer.SERVICE.getInstance();
|
||||
if (!xmlRpcServer.hasHandler(GitSSHHandler.HANDLER_NAME)) {
|
||||
xmlRpcServer.addHandler(GitSSHHandler.HANDLER_NAME, new InternalRequestHandler());
|
||||
}
|
||||
|
||||
while (true) {
|
||||
int candidate = RANDOM.nextInt();
|
||||
|
||||
Reference in New Issue
Block a user