Skip to content

Commit

Permalink
issue #91: add 'Serilization Protocol' combo viewer so that user can …
Browse files Browse the repository at this point in the history
…easily switch the protocol
  • Loading branch information
ntan-ebates committed Aug 3, 2015
1 parent 4cbf7a0 commit 8fa5d08
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
Expand Up @@ -31,6 +31,9 @@ TestNGMainTab.testng.compliance=Annotations compliance level (test sources neede
TestNGMainTab.testng.loglevel=Log level (0-10)
TestNGMainTab.testng.verbose=Verbose
TestNGMainTab.testng.debug=Debug
TestNGMainTab.testng.protocol=Serilization Protocol
TestNGMainTab.testng.protocol.object=Object Serialization
TestNGMainTab.testng.protocol.string=String Serialization (Deprecated)

TestNGMainTab.error.projectnotdefined=Project not specified
TestNGMainTab.error.projectnotexists=Project {0} does not exist
Expand Down
Expand Up @@ -94,6 +94,8 @@ private static String make(String s) {

public static final String DEBUG = make("DEBUG"); //$NON-NLS-1$

public static final String PROTOCOL = make("PROTOCOL"); //$NON-NLS-1$

// public static final String TESTNG_COMPLIANCE_LEVEL_ATTR = make("COMPLIANCE_LEVEL"); //$NON-NLS-1$

public static final String VM_ENABLEASSERTION_OPTION = "-ea";
Expand Down Expand Up @@ -127,5 +129,38 @@ public static LaunchType fromInt(int result) {

public static final String PARAMS = make("PARAMETERS");


public static final Protocols[] SERIALIZATION_PROTOCOLS = {Protocols.OBJECT, Protocols.STRING};
public static final Protocols DEFAULT_SERIALIZATION_PROTOCOL = SERIALIZATION_PROTOCOLS[0];

public static enum Protocols {
OBJECT("object"),
STRING("string");

private final String text;

/**
* @param text
*/
private Protocols(final String text) {
this.text = text;
}

public static Protocols get(String text) {
switch (text) {
case "object":
return OBJECT;
case "string":
return STRING;
default:
throw new IllegalArgumentException("Unrecognized protocol: " + text);
}
}

@Override
public String toString() {
return text;
}
}

}

Expand Up @@ -138,6 +138,13 @@ protected VMRunnerConfiguration launchTypes(final ILaunchConfiguration configura
.append(" ")
.append(TestNGLaunchConfigurationConstants.VM_ENABLEASSERTION_OPTION); // $NON-NLS-1$
addDebugProperties(vmArgs, configuration);
switch (ConfigurationHelper.getProtocol(configuration)) {
case STRING:
vmArgs.append(" -Dtestng.eclipse.stringprotocol");
break;
default:
break;
}
ExecutionArguments execArgs = new ExecutionArguments(vmArgs.toString(), ""); //$NON-NLS-1$
String[] envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);

Expand Down
Expand Up @@ -18,7 +18,12 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
Expand All @@ -40,6 +45,7 @@
import org.eclipse.ui.dialogs.SelectionDialog;
import org.testng.eclipse.TestNGPlugin;
import org.testng.eclipse.launch.TestNGLaunchConfigurationConstants.LaunchType;
import org.testng.eclipse.launch.TestNGLaunchConfigurationConstants.Protocols;
import org.testng.eclipse.launch.components.Filters;
import org.testng.eclipse.ui.Images;
import org.testng.eclipse.ui.util.ConfigurationHelper;
Expand All @@ -58,7 +64,6 @@
*/
public class TestNGMainTab extends AbstractLaunchConfigurationTab implements ILaunchConfigurationTab
{
private static ImageRegistry m_imageRegistry = null;
private static final String UNKNOWN_CONSTANT = "Unknown TestNGLaunchConfigurationConstants: ";

private Text m_projectText;
Expand Down Expand Up @@ -88,6 +93,8 @@ public class TestNGMainTab extends AbstractLaunchConfigurationTab implements ILa

private Button m_debugBtn;

private ComboViewer m_protocolComboViewer;

private List <TestngTestSelector> m_launchSelectors = Lists.newArrayList();
private Map<String, List<String>> m_classMethods;

Expand Down Expand Up @@ -211,6 +218,8 @@ public void initializeFrom(ILaunchConfiguration configuration) {

m_debugBtn.setSelection(ConfigurationHelper.getDebug(configuration));

m_protocolComboViewer.setSelection(new StructuredSelection(ConfigurationHelper.getProtocol(configuration)));

LaunchType type = ConfigurationHelper.getType(configuration);
setType(type);
m_classMethods = ConfigurationHelper.getClassMethods(configuration);
Expand Down Expand Up @@ -253,7 +262,8 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
TestNGLaunchConfigurationConstants.JDK15_COMPLIANCE,
m_logLevelCombo.getText(),
m_verboseBtn.getSelection(),
m_debugBtn.getSelection()));
m_debugBtn.getSelection(),
(Protocols) ((StructuredSelection) m_protocolComboViewer.getSelection()).getFirstElement()));
}

/**
Expand Down Expand Up @@ -505,6 +515,26 @@ public void widgetDefaultSelected(SelectionEvent e) {
}
});


Label label = new Label(group, SWT.NONE);
label.setText(ResourceUtil.getString("TestNGMainTab.testng.protocol"));

m_protocolComboViewer = new ComboViewer(group, SWT.READ_ONLY);
GridDataFactory.fillDefaults().span(2, SWT.None).applyTo(m_protocolComboViewer.getCombo());
m_protocolComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateLaunchConfigurationDialog();
}
});
m_protocolComboViewer.setContentProvider(ArrayContentProvider.getInstance());
m_protocolComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ResourceUtil.getString("TestNGMainTab.testng.protocol." + element);
}
});
m_protocolComboViewer.setInput(TestNGLaunchConfigurationConstants.SERIALIZATION_PROTOCOLS);
}

private void createProjectSelectionGroup(Composite comp) {
Expand Down
Expand Up @@ -27,6 +27,7 @@
import org.testng.eclipse.TestNGPluginConstants;
import org.testng.eclipse.launch.TestNGLaunchConfigurationConstants;
import org.testng.eclipse.launch.TestNGLaunchConfigurationConstants.LaunchType;
import org.testng.eclipse.launch.TestNGLaunchConfigurationConstants.Protocols;
import org.testng.eclipse.ui.RunInfo;
import org.testng.eclipse.util.StringUtils;
import org.testng.eclipse.util.SuiteGenerator;
Expand All @@ -52,7 +53,8 @@ public static class LaunchInfo {
private String m_logLevel;
private boolean m_verbose;
private boolean m_debug;

private Protocols m_protocol;

public LaunchInfo(String projectName,
LaunchType launchType,
Collection<String> classNames,
Expand All @@ -63,7 +65,8 @@ public LaunchInfo(String projectName,
String complianceLevel,
String logLevel,
boolean verbose,
boolean debug) {
boolean debug,
Protocols protocol) {
m_projectName= projectName;
m_launchType= launchType;
m_classNames= classNames;
Expand All @@ -75,6 +78,7 @@ public LaunchInfo(String projectName,
m_packageNames = packageNames;
m_verbose = verbose;
m_debug = debug;
m_protocol = protocol;
}
}

Expand All @@ -96,6 +100,11 @@ public static boolean getDebug(ILaunchConfiguration config) {
return getBooleanAttribute(config, TestNGLaunchConfigurationConstants.DEBUG);
}

public static Protocols getProtocol(ILaunchConfiguration config) {
String stringResult = getStringAttribute(config, TestNGLaunchConfigurationConstants.PROTOCOL);
return null == stringResult ? TestNGLaunchConfigurationConstants.DEFAULT_SERIALIZATION_PROTOCOL : Protocols.get(stringResult);
}

public static String getSourcePath(ILaunchConfiguration config) {
return getStringAttribute(config, TestNGLaunchConfigurationConstants.DIRECTORY_TEST_LIST);
}
Expand Down Expand Up @@ -592,5 +601,6 @@ public static void updateLaunchConfiguration(ILaunchConfigurationWorkingCopy con
launchInfo.m_logLevel);
configuration.setAttribute(TestNGLaunchConfigurationConstants.VERBOSE, launchInfo.m_verbose);
configuration.setAttribute(TestNGLaunchConfigurationConstants.DEBUG, launchInfo.m_debug);
configuration.setAttribute(TestNGLaunchConfigurationConstants.PROTOCOL, launchInfo.m_protocol.toString());
}
}

0 comments on commit 8fa5d08

Please sign in to comment.