mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
@@ -14,6 +14,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.sun.jdi.*;
|
||||
import org.jdom.Element;
|
||||
|
||||
@@ -302,6 +303,8 @@ public abstract class DebuggerUtils implements ApplicationComponent {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int findAvailablePort() throws ExecutionException;
|
||||
|
||||
protected static class ArrayClass {
|
||||
public String className;
|
||||
public int dims;
|
||||
|
||||
@@ -35,7 +35,6 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -324,23 +323,12 @@ public class DebuggerManagerImpl extends DebuggerManagerEx {
|
||||
if (debugPort == null || "".equals(debugPort)) {
|
||||
if(useSockets) {
|
||||
try {
|
||||
ServerSocket serverSocket = new ServerSocket(0);
|
||||
address = Integer.toString(serverSocket.getLocalPort());
|
||||
//workaround for linux : calling close() immediately after opening socket
|
||||
//may result that socket is not closed
|
||||
synchronized(parameters) {
|
||||
try {
|
||||
parameters.wait(1);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
serverSocket.close();
|
||||
final int freePort = DebuggerUtils.getInstance().findAvailablePort();
|
||||
address = Integer.toString(freePort);
|
||||
}
|
||||
catch (IOException e) {
|
||||
catch (ExecutionException e) {
|
||||
if (checkValidity) {
|
||||
throw new ExecutionException(DebugProcessImpl.processError(e));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -363,7 +351,8 @@ public class DebuggerManagerImpl extends DebuggerManagerEx {
|
||||
if(serverMode && useSockets) {
|
||||
try {
|
||||
listenTo = InetAddress.getLocalHost().getHostName() + ":" + address;
|
||||
} catch (UnknownHostException e) {
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
listenTo = "localhost:" + address;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,13 @@ import com.intellij.ide.util.TreeClassChooserDialog;
|
||||
import com.intellij.ide.util.TreeClassChooser;
|
||||
import com.intellij.ide.util.TreeClassChooserFactory;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.sun.jdi.Value;
|
||||
import org.jdom.Element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.net.ServerSocket;
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000-2004 by JetBrains s.r.o. All Rights Reserved.
|
||||
@@ -112,4 +115,27 @@ public class DebuggerUtilsImpl extends DebuggerUtilsEx{
|
||||
public CompletionEditor createEditor(Project project, PsiElement context, String recentsId) {
|
||||
return new DebuggerExpressionComboBox(project, context, recentsId);
|
||||
}
|
||||
|
||||
public final int findAvailablePort() throws ExecutionException {
|
||||
int port;
|
||||
try {
|
||||
final ServerSocket serverSocket = new ServerSocket(0);
|
||||
port = serverSocket.getLocalPort();
|
||||
//workaround for linux : calling close() immediately after opening socket
|
||||
//may result that socket is not closed
|
||||
synchronized(serverSocket) {
|
||||
try {
|
||||
serverSocket.wait(1);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
serverSocket.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ExecutionException(DebugProcessImpl.processError(e));
|
||||
}
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user