summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThirumala Reddy Mutchukota2013-07-02 08:00:32 (EDT)
committer Markus Keller2013-07-02 10:04:58 (EDT)
commita81cebacbf0361dd2d01e385028159c4776d8b43 (patch)
tree9175ba7262a82ec095a26fd1aef06f299ab94e3b
parenta8d9f126228148d76f67078eaac3e3ee48e11b6e (diff)
downloadeclipse.jdt.ui-a81cebacbf0361dd2d01e385028159c4776d8b43.zip
eclipse.jdt.ui-a81cebacbf0361dd2d01e385028159c4776d8b43.tar.gz
eclipse.jdt.ui-a81cebacbf0361dd2d01e385028159c4776d8b43.tar.bz2
Bug 411841: Rerunning a test from JUnit results view is launching the test on UI thread.
Signed-off-by: Thirumala Reddy Mutchukota <thirumala@google.com>
-rw-r--r--org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java36
-rw-r--r--org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java62
2 files changed, 47 insertions, 51 deletions
diff --git a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java
index 3534d2d..b331768 100644
--- a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java
+++ b/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestRunSession.java
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Achim Demelt <a.demelt@exxcellent.de> - [junit] Separate UI from non-UI code - https://bugs.eclipse.org/bugs/show_bug.cgi?id=278844
+ * Thirumala Reddy Mutchukota <thirumala@google.com> - [JUnit] Avoid rerun test launch on UI thread - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411841
*******************************************************************************/
package org.eclipse.jdt.internal.junit.model;
@@ -31,7 +32,6 @@ import org.eclipse.core.runtime.ListenerList;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchesListener2;
@@ -39,14 +39,11 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
import org.eclipse.jdt.internal.junit.JUnitMessages;
-import org.eclipse.jdt.internal.junit.Messages;
import org.eclipse.jdt.internal.junit.launcher.ITestKind;
import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants;
import org.eclipse.jdt.internal.junit.model.TestElement.Status;
import org.eclipse.jdt.internal.junit.runner.MessageIds;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-
/**
* A test run session holds all information about a test run, i.e.
@@ -451,17 +448,14 @@ public class TestRunSession implements ITestRunSession {
}
/**
- * Reruns the given test method.
+ * Reruns the given test method if the session is kept alive.
*
* @param testId test id
* @param className test class name
* @param testName test method name
- * @param launchMode launch mode, see {@link ILaunchManager}
- * @param buildBeforeLaunch whether a build should be done before launch
* @return <code>false</code> iff the rerun could not be started
- * @throws CoreException if the launch fails
*/
- public boolean rerunTest(String testId, String className, String testName, String launchMode, boolean buildBeforeLaunch) throws CoreException {
+ public boolean rerunTest(String testId, String className, String testName) {
if (isKeptAlive()) {
Status status= ((TestCaseElement) getTestElement(testId)).getStatus();
if (status == Status.ERROR) {
@@ -471,31 +465,7 @@ public class TestRunSession implements ITestRunSession {
}
fTestRunnerClient.rerunTest(testId, className, testName);
return true;
-
- } else if (fLaunch != null) {
- // run the selected test using the previous launch configuration
- ILaunchConfiguration launchConfiguration= fLaunch.getLaunchConfiguration();
- if (launchConfiguration != null) {
-
- String name= className;
- if (testName != null)
- name+= "."+testName; //$NON-NLS-1$
- String configName= Messages.format(JUnitMessages.TestRunnerViewPart_configName, name);
- ILaunchConfigurationWorkingCopy tmp= launchConfiguration.copy(configName);
- // fix for bug: 64838 junit view run single test does not use correct class [JUnit]
- tmp.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, className);
- // reset the container
- tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, ""); //$NON-NLS-1$
- if (testName != null) {
- tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, testName);
- // String args= "-rerun "+testId;
- // tmp.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
- }
- tmp.launch(launchMode, null, buildBeforeLaunch);
- return true;
- }
}
-
return false;
}
diff --git a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java
index 109345c..b22afa0 100644
--- a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java
+++ b/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java
@@ -14,6 +14,7 @@
* - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
* Achim Demelt <a.demelt@exxcellent.de> - [junit] Separate UI from non-UI code - https://bugs.eclipse.org/bugs/show_bug.cgi?id=278844
* Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Rerun failed first does not work with JUnit4 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=140392
+ * Thirumala Reddy Mutchukota <thirumala@google.com> - [JUnit] Avoid rerun test launch on UI thread - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411841
*******************************************************************************/
package org.eclipse.jdt.internal.junit.ui;
@@ -124,7 +125,6 @@ import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.ui.DebugUITools;
-import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jdt.core.ElementChangedEvent;
import org.eclipse.jdt.core.IElementChangedListener;
@@ -146,6 +146,8 @@ import org.eclipse.jdt.internal.junit.model.TestCaseElement;
import org.eclipse.jdt.internal.junit.model.TestElement;
import org.eclipse.jdt.internal.junit.model.TestRunSession;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory;
/**
@@ -2062,25 +2064,49 @@ action enablement
}
public void rerunTest(String testId, String className, String testName, String launchMode) {
- boolean buildBeforeLaunch= Platform.getPreferencesService().getBoolean(IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH, false, null);
- try {
- boolean couldLaunch= fTestRunSession.rerunTest(testId, className, testName, launchMode, buildBeforeLaunch);
- if (! couldLaunch) {
- MessageDialog.openInformation(getSite().getShell(),
- JUnitMessages.TestRunnerViewPart_cannotrerun_title,
- JUnitMessages.TestRunnerViewPart_cannotrerurn_message);
- } else if (fTestRunSession.isKeptAlive()) {
- TestCaseElement testCaseElement= (TestCaseElement) fTestRunSession.getTestElement(testId);
- testCaseElement.setStatus(TestElement.Status.RUNNING, null, null, null);
- fTestViewer.registerViewerUpdate(testCaseElement);
- postSyncProcessChanges();
- }
+ if (lastLaunchIsKeptAlive()) {
+ fTestRunSession.rerunTest(testId, className, testName);
+ TestCaseElement testCaseElement= (TestCaseElement) fTestRunSession.getTestElement(testId);
+ testCaseElement.setStatus(TestElement.Status.RUNNING, null, null, null);
+ fTestViewer.registerViewerUpdate(testCaseElement);
+ postSyncProcessChanges();
+ return;
+ }
- } catch (CoreException e) {
- ErrorDialog.openError(getSite().getShell(),
- JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
- );
+ if (fTestRunSession != null) {
+ ILaunch launch= fTestRunSession.getLaunch();
+ if (launch != null) {
+ // run the selected test using the previous launch configuration
+ ILaunchConfiguration launchConfiguration= launch.getLaunchConfiguration();
+ if (launchConfiguration != null) {
+ try {
+ String name= className;
+ if (testName != null)
+ name+= "."+testName; //$NON-NLS-1$
+ String configName= Messages.format(JUnitMessages.TestRunnerViewPart_configName, name);
+ ILaunchConfigurationWorkingCopy tmp = launchConfiguration.copy(configName);
+ // fix for bug: 64838 junit view run single test does not use correct class [JUnit]
+ tmp.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, className);
+ // reset the container
+ tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_CONTAINER, ""); //$NON-NLS-1$
+ if (testName != null) {
+ tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_TEST_METHOD_NAME, testName);
+ }
+ relaunch(tmp, launchMode);
+ return;
+ } catch (CoreException e) {
+ ErrorDialog.openError(getSite().getShell(),
+ JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
+ );
+ return;
+ }
+ }
+ }
}
+
+ MessageDialog.openInformation(getSite().getShell(),
+ JUnitMessages.TestRunnerViewPart_cannotrerun_title,
+ JUnitMessages.TestRunnerViewPart_cannotrerurn_message);
}
private void postSyncProcessChanges() {