mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit: prepare to debug in fork mode
This commit is contained in:
@@ -201,6 +201,7 @@ public abstract class JavaTestFrameworkRunnableState<T extends ModuleBasedConfig
|
||||
return javaParameters;
|
||||
}
|
||||
|
||||
protected ServerSocket myForkSocket;
|
||||
protected void appendForkInfo(Executor executor) throws ExecutionException {
|
||||
final String forkMode = getForkMode();
|
||||
if (Comparing.strEqual(forkMode, "none")) {
|
||||
@@ -250,6 +251,9 @@ public abstract class JavaTestFrameworkRunnableState<T extends ModuleBasedConfig
|
||||
writer.close();
|
||||
}
|
||||
|
||||
if (getRunnerSettings() instanceof DebuggingRunnerData) {
|
||||
myForkSocket = new ServerSocket(0, 0, InetAddress.getByName("127.0.0.1"));
|
||||
}
|
||||
passForkMode(forkMode, tempFile);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -54,6 +54,7 @@ import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.listeners.RefactoringElementListener;
|
||||
import com.intellij.rt.execution.junit.IDEAJUnitListener;
|
||||
import com.intellij.rt.execution.junit.JUnitForkedStarter;
|
||||
import com.intellij.rt.execution.junit.JUnitStarter;
|
||||
import com.intellij.rt.execution.junit.RepeatCount;
|
||||
import com.intellij.util.Function;
|
||||
@@ -478,5 +479,8 @@ public abstract class TestObject extends JavaTestFrameworkRunnableState<JUnitCon
|
||||
|
||||
protected void passForkMode(String forkMode, File tempFile) throws ExecutionException {
|
||||
getJavaParameters().getProgramParametersList().add("@@@" + forkMode + ',' + tempFile.getAbsolutePath());
|
||||
if (myForkSocket != null) {
|
||||
getJavaParameters().getProgramParametersList().add(JUnitForkedStarter.DEBUG_SOCKET + myForkSocket.getLocalPort());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,7 +30,12 @@ import java.util.List;
|
||||
* @since 6.04.2011
|
||||
*/
|
||||
public class JUnitForkedStarter {
|
||||
private JUnitForkedStarter() {
|
||||
|
||||
public static final String DEBUG_SOCKET = "-debugSocket";
|
||||
|
||||
private int myDebugPort = -1;
|
||||
|
||||
JUnitForkedStarter() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
@@ -68,7 +74,7 @@ public class JUnitForkedStarter {
|
||||
}
|
||||
}
|
||||
|
||||
static int startForkedVMs(String workingDirsPath,
|
||||
int startForkedVMs(String workingDirsPath,
|
||||
String[] args,
|
||||
boolean isJUnit4,
|
||||
List listeners,
|
||||
@@ -76,6 +82,17 @@ public class JUnitForkedStarter {
|
||||
Object err,
|
||||
String forkMode,
|
||||
String path) throws Exception {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
if (arg.startsWith(DEBUG_SOCKET)) {
|
||||
final List list = new ArrayList(Arrays.asList(args));
|
||||
list.remove(arg);
|
||||
args = (String[])list.toArray();
|
||||
myDebugPort = Integer.parseInt(arg.substring(DEBUG_SOCKET.length()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
final List parameters = new ArrayList();
|
||||
final BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
|
||||
final String dynamicClasspath = bufferedReader.readLine();
|
||||
@@ -176,7 +193,7 @@ public class JUnitForkedStarter {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int processChildren(boolean isJUnit4,
|
||||
private int processChildren(boolean isJUnit4,
|
||||
List listeners,
|
||||
Object out,
|
||||
Object err,
|
||||
@@ -204,7 +221,7 @@ public class JUnitForkedStarter {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int runChild(boolean isJUnit4,
|
||||
private int runChild(boolean isJUnit4,
|
||||
List listeners,
|
||||
Object out,
|
||||
Object err,
|
||||
@@ -214,6 +231,22 @@ public class JUnitForkedStarter {
|
||||
String startIndex,
|
||||
String classpath,
|
||||
String dynamicClasspath) throws IOException, InterruptedException {
|
||||
parameters = new ArrayList(parameters);
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
String parameter = (String)parameters.get(i);
|
||||
final String debuggerParam = "transport=dt_socket,server=";
|
||||
final int indexOf = parameter.indexOf(debuggerParam);
|
||||
if (indexOf >= 0) {
|
||||
if (myDebugPort > -1) {
|
||||
parameter = parameter.substring(0, indexOf) + "transport=dt_socket,server=n,suspend=n,address=" + myDebugPort;
|
||||
parameters.set(i, parameter);
|
||||
}
|
||||
else {
|
||||
parameters.remove(parameter);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//noinspection SSBasedInspection
|
||||
final File tempFile = File.createTempFile("fork", "test");
|
||||
tempFile.deleteOnExit();
|
||||
|
||||
@@ -221,7 +221,7 @@ public class JUnitStarter {
|
||||
}
|
||||
if (ourCommandFileName != null) {
|
||||
if (!"none".equals(ourForkMode) || ourWorkingDirs != null && new File(ourWorkingDirs).length() > 0) {
|
||||
return JUnitForkedStarter.startForkedVMs(ourWorkingDirs, args, isJUnit4, listeners, name, out, err, ourForkMode, ourCommandFileName);
|
||||
return new JUnitForkedStarter().startForkedVMs(ourWorkingDirs, args, isJUnit4, listeners, name, out, err, ourForkMode, ourCommandFileName);
|
||||
}
|
||||
}
|
||||
testRunner.setStreams(out, err, 0);
|
||||
|
||||
Reference in New Issue
Block a user