diff --git a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java index 09fe8fec03fb..264a81c20bdd 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestPackage.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestPackage.java @@ -73,6 +73,7 @@ public class TestPackage extends TestObject { @Override protected JUnitProcessHandler createHandler() throws ExecutionException { final JUnitProcessHandler handler = super.createHandler(); + final MySearchForTestsTask[] tasks = new MySearchForTestsTask[1]; handler.addProcessListener(new ProcessAdapter() { @Override public void startNotified(ProcessEvent event) { @@ -86,7 +87,7 @@ public class TestPackage extends TestObject { //should not happen return; } - findTestsWithProgress(new FindCallback() { + tasks[0] = findTestsWithProgress(new FindCallback() { public void found(@NotNull final Collection classes, final boolean isJunit4) { addClassesListToJavaParameters(classes, new Function() { @Nullable @@ -112,6 +113,9 @@ public class TestPackage extends TestObject { handler.removeProcessListener(this); if (mySearchForTestsIndicator != null && !mySearchForTestsIndicator.isCanceled()) { mySearchForTestsIndicator.cancel(); //ensure that search for tests stops anyway + if (tasks[0] != null) { + tasks[0].connect(); + } } } }); @@ -211,73 +215,18 @@ public class TestPackage extends TestObject { } } - private void findTestsWithProgress(final FindCallback callback, final TestClassFilter classFilter) { + private MySearchForTestsTask findTestsWithProgress(final FindCallback callback, final TestClassFilter classFilter) { if (isSyncSearch()) { THashSet classes = new THashSet(); boolean isJUnit4 = ConfigurationUtil.findAllTestClasses(classFilter, classes); callback.found(classes, isJUnit4); - return; + return null; } final THashSet classes = new THashSet(); final boolean[] isJunit4 = new boolean[1]; - final Task.Backgroundable task = - new Task.Backgroundable(classFilter.getProject(), ExecutionBundle.message("seaching.test.progress.title"), true) { - private Socket mySocket; - - - public void run(@NotNull ProgressIndicator indicator) { - try { - mySocket = myServerSocket.accept(); - } - catch (IOException e) { - LOG.info(e); - } - isJunit4[0] = ConfigurationUtil.findAllTestClasses(classFilter, classes); - } - - @Override - public void onSuccess() { - callback.found(classes, isJunit4[0]); - connect(); - } - - @Override - public void onCancel() { - connect(); - } - - @Override - public DumbModeAction getDumbModeAction() { - return DumbModeAction.WAIT; - } - - private void connect() { - DataOutputStream os = null; - try { - os = new DataOutputStream(mySocket.getOutputStream()); - os.writeBoolean(true); - } - catch (Throwable e) { - LOG.info(e); - } - finally { - try { - if (os != null) os.close(); - } - catch (Throwable e) { - LOG.info(e); - } - - try { - myServerSocket.close(); - } - catch (Throwable e) { - LOG.info(e); - } - } - } - }; + final MySearchForTestsTask task = + new MySearchForTestsTask(classFilter, isJunit4, classes, callback); mySearchForTestsIndicator = new BackgroundableProcessIndicator(task) { @Override public void cancel() { @@ -293,6 +242,7 @@ public class TestPackage extends TestObject { } }; ProgressManagerImpl.runProcessWithProgressAsynchronously(task, mySearchForTestsIndicator); + return task; } private static boolean isSyncSearch() { @@ -305,4 +255,73 @@ public class TestPackage extends TestObject { */ void found(@NotNull Collection classes, final boolean isJunit4); } + + private class MySearchForTestsTask extends Task.Backgroundable { + private Socket mySocket; + private final TestClassFilter myClassFilter; + private final boolean[] myJunit4; + private final THashSet myClasses; + private final FindCallback myCallback; + + public MySearchForTestsTask(TestClassFilter classFilter, boolean[] junit4, THashSet classes, FindCallback callback) { + super(classFilter.getProject(), ExecutionBundle.message("seaching.test.progress.title"), true); + myClassFilter = classFilter; + myJunit4 = junit4; + myClasses = classes; + myCallback = callback; + } + + + public void run(@NotNull ProgressIndicator indicator) { + try { + mySocket = myServerSocket.accept(); + } + catch (IOException e) { + LOG.info(e); + } + myJunit4[0] = ConfigurationUtil.findAllTestClasses(myClassFilter, myClasses); + } + + @Override + public void onSuccess() { + myCallback.found(myClasses, myJunit4[0]); + connect(); + } + + @Override + public void onCancel() { + connect(); + } + + @Override + public DumbModeAction getDumbModeAction() { + return DumbModeAction.WAIT; + } + + private void connect() { + DataOutputStream os = null; + try { + os = new DataOutputStream(mySocket.getOutputStream()); + os.writeBoolean(true); + } + catch (Throwable e) { + LOG.info(e); + } + finally { + try { + if (os != null) os.close(); + } + catch (Throwable e) { + LOG.info(e); + } + + try { + myServerSocket.close(); + } + catch (Throwable e) { + LOG.info(e); + } + } + } + } } diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java index 8d40947c7286..9328dd215b64 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java @@ -115,7 +115,7 @@ public class SearchingForTestsTask extends Task.Backgroundable { return DumbModeAction.WAIT; } - private void connect() { + public void connect() { DataOutputStream os = null; try { os = new DataOutputStream(mySocket.getOutputStream()); diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java index 3571721636a3..7e499c6e5824 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java +++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java @@ -133,9 +133,16 @@ public class TestNGRunnableState extends JavaCommandLineState { for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) { ext.handleStartProcess(config, processHandler); } + final SearchingForTestsTask task = createSearchingForTestsTask(myServerSocket, config, myTempFile); processHandler.addProcessListener(new ProcessAdapter() { @Override public void processTerminated(final ProcessEvent event) { + unboundOutputRoot.flush(); + + if (mySearchForTestIndicator != null && !mySearchForTestIndicator.isCanceled()) { + mySearchForTestIndicator.cancel(); + task.connect(); + } SwingUtilities.invokeLater(new Runnable() { public void run() { @@ -164,7 +171,6 @@ public class TestNGRunnableState extends JavaCommandLineState { public void startNotified(final ProcessEvent event) { TestNGRemoteListener listener = new TestNGRemoteListener(console, unboundOutputRoot); client.prepareListening(listener, port); - final SearchingForTestsTask task = createSearchingForTestsTask(myServerSocket, config, myTempFile); mySearchForTestIndicator = new BackgroundableProcessIndicator(task) { @Override public void cancel() { diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java index c0bb1ebb7533..20b58ee7f3ac 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGConsoleView.java @@ -26,6 +26,7 @@ import com.intellij.execution.Executor; import com.intellij.execution.configurations.ConfigurationPerRunnerSettings; import com.intellij.execution.configurations.RunnerSettings; import com.intellij.execution.process.ProcessHandler; +import com.intellij.execution.testframework.AbstractTestProxy; import com.intellij.execution.testframework.TestTreeView; import com.intellij.execution.testframework.ui.BaseTestsOutputConsoleView; import com.intellij.execution.testframework.ui.TestResultsPanel; @@ -46,6 +47,7 @@ public class TestNGConsoleView extends BaseTestsOutputConsoleView { private final TestNGConfiguration myConfiguration; private final RunnerSettings myRunnerSettings; private final ConfigurationPerRunnerSettings myConfigurationPerRunnerSettings; + private final TreeRootNode myUnboundOutput; public TestNGConsoleView(TestNGConfiguration config, final RunnerSettings runnerSettings, @@ -56,6 +58,7 @@ public class TestNGConsoleView extends BaseTestsOutputConsoleView { myConfiguration = config; myRunnerSettings = runnerSettings; myConfigurationPerRunnerSettings = configurationPerRunnerSettings; + myUnboundOutput = unboundOutputRoot; } protected TestResultsPanel createTestResultsPanel() { @@ -63,6 +66,10 @@ public class TestNGConsoleView extends BaseTestsOutputConsoleView { return testNGResults; } + public TreeRootNode getUnboundOutput() { + return myUnboundOutput; + } + @Override public void initUI() { super.initUI(); diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java index cf36f89d88ea..77779fec36ff 100644 --- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java +++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java @@ -117,6 +117,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn } }); rootNode = new TreeRootNode(); + console.getUnboundOutput().addChild(rootNode); } protected JComponent createTestTreeView() {