Skip to content

Commit

Permalink
fixes #219: Add "auto-repeat" button to Integrity Test Runner view
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Jan 30, 2019
1 parent ce9747c commit 02ef90e
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package de.gebit.integrity.eclipse.views;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;

/**
*
*
* @author Rene Schneider - initial API and implementation
*
*/
public class ConnectDialog extends InputDialog {

/**
* Whether auto-retry was chosen.
*/
private boolean autoRetryEnabled;

/**
* @param parentShell
* @param aDialogTitle
* @param aDialogMessage
* @param anInitialValue
* @param aValidator
*/
public ConnectDialog(Shell aParentShell, String anInitialValue, IInputValidator aValidator) {
super(aParentShell, "Connect to test runner", "Please enter the hostname or IP address to connect to",
anInitialValue, null);
}

@Override
protected void createButtonsForButtonBar(Composite aParent) {
super.createButtonsForButtonBar(aParent);

createButton(aParent, IDialogConstants.RETRY_ID, "OK (retry)", false);
}

@Override
protected void buttonPressed(int aButtonId) {
if (aButtonId == IDialogConstants.RETRY_ID) {
autoRetryEnabled = true;
super.buttonPressed(IDialogConstants.OK_ID);
} else {
super.buttonPressed(aButtonId);
}
}

public boolean isAutoRetryEnabled() {
return autoRetryEnabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ArrayContentProvider;
Expand Down Expand Up @@ -641,6 +640,11 @@ public class IntegrityTestRunnerView extends ViewPart {
*/
private ILaunchConfiguration launchConfiguration;

/**
* The currently active autoconnect thread.
*/
private AutoConnectThread autoConnectThread;

/**
* The constructor.
*/
Expand Down Expand Up @@ -1550,8 +1554,7 @@ private void makeActions() {
@Override
public void run() {
if (client == null || !client.isActive()) {
InputDialog tempDialog = new InputDialog(getSite().getShell(), "Connect to test runner",
"Please enter the hostname or IP address to connect to", lastHostname, null);
ConnectDialog tempDialog = new ConnectDialog(getSite().getShell(), lastHostname, null);
if (tempDialog.open() == IStatus.OK && tempDialog.getValue() != null
&& tempDialog.getValue().length() > 0) {
lastHostname = tempDialog.getValue();
Expand All @@ -1569,7 +1572,23 @@ public void run() {
}
tempHost = tempHost.substring(0, tempHost.indexOf(':'));
}
connectToTestRunnerAsync(tempHost, tempPort);

if (tempDialog.isAutoRetryEnabled()) {
if (autoConnectThread != null && autoConnectThread.isAlive()) {
autoConnectThread.kill();
autoConnectThread = null;
}
if (autoConnectThread == null || !autoConnectThread.isAlive()) {
autoConnectThread = new AutoConnectThread(tempHost, tempPort);
autoConnectThread.start();
}
} else {
connectToTestRunnerAsync(tempHost, tempPort);
}
} else {
if (autoConnectThread != null && autoConnectThread.isAlive()) {
autoConnectThread.kill();
}
}
} else {
disconnectFromTestRunner();
Expand Down Expand Up @@ -1709,7 +1728,11 @@ public void run() {
executeTestAction.setEnabled(false);
executeDebugTestAction.setEnabled(false);
final ILaunch tempLaunch = launchConfiguration.launch(ILaunchManager.RUN_MODE, null);
new AutoConnectThread(tempLaunch).start();
if (autoConnectThread != null && autoConnectThread.isAlive()) {
autoConnectThread.kill();
}
autoConnectThread = new AutoConnectThread(tempLaunch);
autoConnectThread.start();
} catch (CoreException exc) {
showException(exc);
}
Expand All @@ -1727,7 +1750,11 @@ public void run() {
executeTestAction.setEnabled(false);
executeDebugTestAction.setEnabled(false);
final ILaunch tempLaunch = launchConfiguration.launch(ILaunchManager.DEBUG_MODE, null);
new AutoConnectThread(tempLaunch).start();
if (autoConnectThread != null && autoConnectThread.isAlive()) {
autoConnectThread.kill();
}
autoConnectThread = new AutoConnectThread(tempLaunch);
autoConnectThread.start();
} catch (CoreException exc) {
showException(exc);
}
Expand Down Expand Up @@ -2854,6 +2881,21 @@ private class AutoConnectThread extends Thread {
*/
private ILaunch launch;

/**
* The host to connect to.
*/
private String host = "localhost";

/**
* The port to connect to.
*/
private int port = IntegrityRemotingConstants.DEFAULT_PORT;

/**
* Used to kill this thread gracefully.
*/
private boolean killSwitch;

/**
* Creates a new instance.
*/
Expand All @@ -2862,15 +2904,28 @@ private class AutoConnectThread extends Thread {
launch = aLaunch;
}

/**
* Creates a new instance.
*/
AutoConnectThread(String aHost, int aPort) {
super("Integrity Autoconnect Thread");
host = aHost;
port = aPort;
}

public void kill() {
killSwitch = true;
}

@Override
public void run() {
boolean tempSuccess = false;

while (!launch.isTerminated()) {
while (!killSwitch && (launch == null || !launch.isTerminated())) {
try {
if (!tempSuccess && !isConnected()) {
// try to connect at least once
connectToTestRunner("localhost", IntegrityRemotingConstants.DEFAULT_PORT);
connectToTestRunner(host, IntegrityRemotingConstants.DEFAULT_PORT);
tempSuccess = true;
} else {
// Now we'll wait until the launch has terminated
Expand All @@ -2893,6 +2948,10 @@ public void run() {
// don't care
}
}

if (!tempSuccess) {
updateStatus("Aborted connection attempts");
}
executeTestAction.setEnabled(true);
executeDebugTestAction.setEnabled(true);
};
Expand Down

0 comments on commit 02ef90e

Please sign in to comment.