From e79881a5986e2e20e124c46f57bd1123a35987aa Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 16 Jan 2017 13:03:44 +0200 Subject: [PATCH 01/38] CHE-3708: Rename method getValue -> getString --- .../debugger/ide/debug/DebuggerPresenter.java | 2 +- .../plugin/gdb/server/GdbDebuggerTest.java | 4 ++-- .../plugin/jdb/server/JavaDebuggerTest.java | 6 ++--- .../plugin/zdb/server/ZendDbgSessionTest.java | 24 +++++++++---------- .../api/debug/shared/dto/SimpleValueDto.java | 8 ++++--- .../api/debug/shared/model/SimpleValue.java | 4 ++-- .../shared/model/impl/SimpleValueImpl.java | 4 ++-- .../che/api/debugger/server/DtoConverter.java | 4 ++-- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 7d4642ad055..705c362d349 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -154,7 +154,7 @@ public void onExpandVariablesTree() { promise.then(new Operation() { @Override public void apply(SimpleValue arg) throws OperationException { - selectedVariable.setValue(arg.getValue()); + selectedVariable.setValue(arg.getString()); view.setVariablesIntoSelectedVariable(arg.getVariables()); view.updateSelectedVariable(); } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java index f766675b0cb..5a48cb218a6 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java @@ -158,13 +158,13 @@ private void doSetAndGetValues() throws DebuggerException { Variable variable = new VariableImpl("int", "i", "2", true, variablePath, Collections.emptyList(), false); SimpleValue value = gdbDebugger.getValue(variablePath); - assertEquals(value.getValue(), "0"); + assertEquals(value.getString(), "0"); gdbDebugger.setValue(variable); value = gdbDebugger.getValue(variablePath); - assertEquals(value.getValue(), "2"); + assertEquals(value.getString(), "2"); String expression = gdbDebugger.evaluate("i"); assertEquals(expression, "2"); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index 4e132716c4c..35071299125 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -237,12 +237,12 @@ public void testEvaluateExpression() throws Exception { @Test(priority = 11) public void testSetAndGetValue() throws Exception { - assertEquals(debugger.getValue(new VariablePathImpl("test")).getValue(), "\"hello\""); - assertEquals(debugger.getValue(new VariablePathImpl("msg")).getValue(), "\"Hello, debugger!\""); + assertEquals(debugger.getValue(new VariablePathImpl("test")).getString(), "\"hello\""); + assertEquals(debugger.getValue(new VariablePathImpl("msg")).getString(), "\"Hello, debugger!\""); debugger.setValue(new VariableImpl("\"new hello\"", (new VariablePathImpl("test")))); - assertEquals(debugger.getValue(new VariablePathImpl("test")).getValue(), "\"new hello\""); + assertEquals(debugger.getValue(new VariablePathImpl("test")).getString(), "\"new hello\""); StackFrameDump stackFrameDump = debugger.dumpStackFrame(); Set vars = stackFrameDump.getVariables().stream().map(Variable::getName).collect(Collectors.toSet()); diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java index eb5ef0496da..29b83090601 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java @@ -10,15 +10,6 @@ *******************************************************************************/ package org.eclipse.che.plugin.zdb.server; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; @@ -33,6 +24,15 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl; import org.testng.annotations.Test; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + /** * Class providing different tests for active Zend Debugger session. * @@ -161,15 +161,15 @@ public void testGetValue() throws Exception { List path = Arrays.asList("0", "0"); variablePath = new VariablePathImpl(path); simpleValue = debugger.getValue(variablePath); - assertEquals(simpleValue.getValue(), "\"A\""); + assertEquals(simpleValue.getString(), "\"A\""); path = Arrays.asList("0", "1"); variablePath = new VariablePathImpl(path); simpleValue = debugger.getValue(variablePath); - assertEquals(simpleValue.getValue(), "123"); + assertEquals(simpleValue.getString(), "123"); path = Arrays.asList("0", "2"); variablePath = new VariablePathImpl(path); simpleValue = debugger.getValue(variablePath); - assertEquals(simpleValue.getValue(), "array [3]"); + assertEquals(simpleValue.getString(), "array [3]"); } @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/SimpleValueDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/SimpleValueDto.java index 5ea0f373232..bba70220ff4 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/SimpleValueDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/SimpleValueDto.java @@ -18,15 +18,17 @@ /** @author andrew00x */ @DTO public interface SimpleValueDto extends SimpleValue { + @Override List getVariables(); void setVariables(List variables); SimpleValueDto withVariables(List variables); - String getValue(); + @Override + String getString(); - void setValue(String value); + void setString(String value); - SimpleValueDto withValue(String value); + SimpleValueDto withString(String value); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/SimpleValue.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/SimpleValue.java index 6800bc71f93..ea4d9c04454 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/SimpleValue.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/SimpleValue.java @@ -22,7 +22,7 @@ public interface SimpleValue { List getVariables(); /** - * The value. + * Returns string representation of the value. */ - String getValue(); + String getString(); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java index 70f6d0a819f..0141d638147 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java @@ -30,7 +30,7 @@ public SimpleValueImpl(List variables, String value) { } public SimpleValueImpl(SimpleValueDto dto) { - this(dto.getVariables(), dto.getValue()); + this(dto.getVariables(), dto.getString()); } @Override @@ -39,7 +39,7 @@ public List getVariables() { } @Override - public String getValue() { + public String getString() { return value; } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index e6846f35211..7d4ad464567 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -85,8 +85,8 @@ public static LocationDto asDto(Location location) { } public static SimpleValueDto asDto(SimpleValue value) { - return newDto(SimpleValueDto.class).withValue(value.getValue()) - .withVariables(asVariablesDto(value.getVariables())); + return newDto(SimpleValueDto.class).withString(value.getString()) + .withVariables(asVariablesDto(value.getVariables())); } public static FieldDto asDto(Field field) { From 26a1c72732e3bc9d77a796677e23ad23bdfba2a8 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 16 Jan 2017 17:32:41 +0200 Subject: [PATCH 02/38] CHE-3708: Variable.getValue() returns instance of SimpleValue instead of String --- .../debugger/ide/debug/AbstractDebugger.java | 39 +++--- .../debugger/ide/debug/DebuggerPresenter.java | 2 +- .../ide/debug/VariableNodeDataAdapter.java | 2 +- .../ide/debug/VariableTreeNodeRenderer.java | 2 +- .../changevalue/ChangeValuePresenter.java | 5 +- .../debugger/ide/ChangeVariableValueTest.java | 9 +- .../debugger/ide/debug/DebuggerTest.java | 21 ++- .../che/plugin/gdb/server/GdbDebugger.java | 10 +- .../plugin/gdb/server/GdbDebuggerTest.java | 5 +- .../che/plugin/jdb/server/JavaDebugger.java | 62 ++++----- .../plugin/jdb/server/JavaDebuggerTest.java | 3 +- .../nodejsdbg/server/NodeJsDebugger.java | 2 +- .../che/plugin/zdb/server/ZendDebugger.java | 120 +++++++++--------- .../zdb/server/variables/ZendDbgVariable.java | 53 ++++---- .../plugin/zdb/server/ZendDbgSessionTest.java | 53 +++++--- .../che/api/debug/shared/dto/FieldDto.java | 6 +- .../che/api/debug/shared/dto/VariableDto.java | 6 +- .../debug/shared/model/MutableVariable.java | 2 +- .../che/api/debug/shared/model/Variable.java | 2 +- .../debug/shared/model/impl/FieldImpl.java | 18 ++- .../model/impl/MutableVariableImpl.java | 9 +- .../shared/model/impl/SimpleValueImpl.java | 4 + .../debug/shared/model/impl/VariableImpl.java | 9 +- .../api/debugger/server/DebuggerService.java | 4 +- .../che/api/debugger/server/DtoConverter.java | 53 +++++--- 25 files changed, 294 insertions(+), 207 deletions(-) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index b4659ad6fb0..75520ebd99c 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -76,6 +76,7 @@ import javax.validation.constraints.NotNull; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -639,7 +640,7 @@ public void setValue(final Variable variable) { @Override public void apply(Void arg) throws OperationException { for (DebuggerObserver observer : observers) { - observer.onValueChanged(variable.getVariablePath().getPath(), variable.getValue()); + observer.onValueChanged(variable.getVariablePath().getPath(), variable.getValue().getString()); } } }).catchError(new Operation() { @@ -739,19 +740,11 @@ protected void restoreDebuggerState() { } } - private VariableDto asDto(Variable variable) { - VariableDto dto = dtoFactory.createDto(VariableDto.class); - dto.withValue(variable.getValue()); - dto.withVariablePath(asDto(variable.getVariablePath())); - dto.withPrimitive(variable.isPrimitive()); - dto.withType(variable.getType()); - dto.withName(variable.getName()); - dto.withExistInformation(variable.isExistInformation()); - dto.withVariables(asDto(variable.getVariables())); - return dto; - } - private List asDto(List variables) { + if (variables == null || variables.isEmpty()) { + return Collections.emptyList(); + } + List dtos = new ArrayList<>(variables.size()); for (Variable v : variables) { dtos.add(asDto(v)); @@ -759,8 +752,24 @@ private List asDto(List variables) { return dtos; } - private VariablePathDto asDto(VariablePath variablePath) { - return dtoFactory.createDto(VariablePathDto.class).withPath(variablePath.getPath()); + private VariableDto asDto(Variable variable) { + SimpleValue simpleValue = variable.getValue(); + VariablePath variablePath = variable.getVariablePath(); + + VariableDto dto = dtoFactory.createDto(VariableDto.class); + dto.withValue(dtoFactory.createDto(SimpleValueDto.class) + .withString(simpleValue.getString()) + .withVariables(asDto(simpleValue.getVariables()))); + + dto.withVariablePath(dtoFactory.createDto(VariablePathDto.class) + .withPath(variablePath.getPath())); + + dto.withPrimitive(variable.isPrimitive()); + dto.withType(variable.getType()); + dto.withName(variable.getName()); + dto.withExistInformation(variable.isExistInformation()); + dto.withVariables(asDto(variable.getVariables())); + return dto; } @Nullable diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 705c362d349..fa5d2e30e44 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -154,7 +154,7 @@ public void onExpandVariablesTree() { promise.then(new Operation() { @Override public void apply(SimpleValue arg) throws OperationException { - selectedVariable.setValue(arg.getString()); + selectedVariable.setValue(arg); view.setVariablesIntoSelectedVariable(arg.getVariables()); view.updateSelectedVariable(); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java index e59576abd3a..bf58dcd92f5 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java @@ -72,7 +72,7 @@ public String getNodeId(@NotNull MutableVariable data) { @Override @NotNull public String getNodeName(@NotNull MutableVariable data) { - return data.getName() + ": " + data.getValue(); + return data.getName() + ": " + data.getValue().getString(); } /** {@inheritDoc} */ diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java index f568f5f0af1..f40279b0e66 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java @@ -61,7 +61,7 @@ public Element getNodeKeyTextContainer(@NotNull SpanElement treeNodeLabel) { public SpanElement renderNodeContents(@NotNull MutableVariable data) { SpanElement root = Elements.createSpanElement(css.variableRoot()); SpanElement label = Elements.createSpanElement(css.variableLabel()); - String content = data.getName() + ": " + data.getValue(); + String content = data.getName() + ": " + data.getValue().getString(); label.setTextContent(content); root.appendChild(label); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java index a805180f54a..712435e50f7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java @@ -14,6 +14,7 @@ import com.google.inject.Singleton; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; import org.eclipse.che.ide.debug.Debugger; import org.eclipse.che.ide.debug.DebuggerManager; @@ -51,7 +52,7 @@ public ChangeValuePresenter(ChangeValueView view, public void showDialog() { variable = debuggerPresenter.getSelectedVariable(); view.setValueTitle(constant.changeValueViewExpressionFieldTitle(variable.getName())); - view.setValue(variable.getValue()); + view.setValue(variable.getValue().getString()); view.focusInValueField(); view.selectAllText(); view.setEnableChangeButton(false); @@ -69,7 +70,7 @@ public void onCancelClicked() { public void onChangeClicked() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { - Variable newVariable = new VariableImpl(view.getValue(), variable.getVariablePath()); + Variable newVariable = new VariableImpl(new SimpleValueImpl(view.getValue()), variable.getVariablePath()); debugger.setValue(newVariable); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java index 545a27205ab..38caa181ce7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.plugin.debugger.ide; +import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; import org.eclipse.che.api.debug.shared.model.MutableVariable; @@ -58,20 +59,23 @@ public class ChangeVariableValueTest extends BaseTest { private MutableVariable variable; @Mock private VariablePathDto variablePathDto; + @Mock + private SimpleValueDto simpleValueDto; @Before public void setUp() { super.setUp(); when(var.getName()).thenReturn(VAR_NAME); - when(var.getValue()).thenReturn(VAR_VALUE); + when(var.getValue()).thenReturn(simpleValueDto); when(var.getVariablePath()).thenReturn(varPath); + when(simpleValueDto.getString()).thenReturn(VAR_VALUE); when(dtoFactory.createDto(VariableDto.class)).thenReturn(mock(VariableDto.class)); } @Test public void shouldShowDialog() throws Exception { when(debuggerPresenter.getSelectedVariable()).thenReturn(variable); - when(variable.getValue()).thenReturn(VAR_VALUE); + when(variable.getValue()).thenReturn(simpleValueDto); presenter.showDialog(); @@ -115,6 +119,7 @@ public void testChangeValueRequest() throws Exception { when(debuggerManager.getActiveDebugger()).thenReturn(debugger); when(view.getValue()).thenReturn(VAR_VALUE); when(variable.getVariablePath()).thenReturn(variablePathDto); + when(variable.getValue()).thenReturn(mock(SimpleValueDto.class)); when(variablePathDto.getPath()).thenReturn(new ArrayList<>()); presenter.showDialog(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index 07277d334ef..82aa103e5a0 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -152,8 +152,6 @@ public class DebuggerTest extends BaseTest { private ArgumentCaptor breakpointCaptor; @Captor private ArgumentCaptor> argumentCaptorFunctionJavaDebugSessionVoid; - @Captor - private ArgumentCaptor> argumentCaptorOperationJavaDebuggerInfo; public final Breakpoint TEST_BREAKPOINT = new Breakpoint(Breakpoint.Type.BREAKPOINT, LINE_NUMBER, PATH, file, true); @@ -487,6 +485,16 @@ public void testGetValue() throws Exception { final Variable variable = mock(Variable.class); final Promise promiseValue = mock(Promise.class); + SimpleValueDto simpleValueDto = mock(SimpleValueDto.class); + doReturn(simpleValueDto).when(dtoFactory).createDto(SimpleValueDto.class); + doReturn(simpleValueDto).when(simpleValueDto).withString(anyString()); + + SimpleValue simpleValue = mock(SimpleValue.class); + doReturn(simpleValue).when(variable).getValue(); + doReturn(Collections.emptyList()).when(variable).getVariables(); + + doReturn(simpleValue).when(variable).getValue(); + doReturn(variableDto).when(dtoFactory).createDto(VariableDto.class); doReturn(mock(VariablePathDto.class)).when(dtoFactory).createDto(VariablePathDto.class); doReturn(mock(VariablePathDto.class)).when(variable).getVariablePath(); @@ -560,10 +568,17 @@ public void testChangeVariableValue() throws Exception { VariableDto variableDto = mock(VariableDto.class); doReturn(variableDto).when(dtoFactory).createDto(VariableDto.class); + SimpleValueDto simpleValueDto = mock(SimpleValueDto.class); + doReturn(simpleValueDto).when(dtoFactory).createDto(SimpleValueDto.class); + doReturn(simpleValueDto).when(simpleValueDto).withString(anyString()); + Variable variable = mock(Variable.class); doReturn(mock(VariablePathDto.class)).when(dtoFactory).createDto(VariablePathDto.class); doReturn(variablePath).when(variable).getVariablePath(); - doReturn(newValue).when(variable).getValue(); + + SimpleValue simpleValue = mock(SimpleValue.class); + doReturn(newValue).when(simpleValue).getString(); + doReturn(simpleValue).when(variable).getValue(); doReturn(Collections.emptyList()).when(variable).getVariables(); doReturn(promiseVoid).when(service).setValue(SESSION_ID, variableDto); diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java index 06d165ca6b5..afb8cbf95b8 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java @@ -382,7 +382,7 @@ public void setValue(Variable variable) throws DebuggerException { if (path.isEmpty()) { throw new DebuggerException("Variable path is empty"); } - gdb.setVar(path.get(0), variable.getValue()); + gdb.setVar(path.get(0), variable.getValue().getString()); } catch (GdbTerminatedException e) { disconnect(); throw e; @@ -444,7 +444,13 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { } VariablePath variablePath = new VariablePathImpl(singletonList(varName)); - VariableImpl variable = new VariableImpl(varType, varName, varValue, true, variablePath, Collections.emptyList(), true); + VariableImpl variable = new VariableImpl(varType, + varName, + new SimpleValueImpl(varValue), + true, + variablePath, + Collections.emptyList(), + true); variables.add(variable); } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java index 5a48cb218a6..088446c06f2 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java @@ -12,6 +12,7 @@ import com.google.common.collect.ImmutableMap; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; import org.eclipse.che.api.debug.shared.model.Breakpoint; @@ -155,7 +156,7 @@ private void stepOver() throws DebuggerException, InterruptedException { private void doSetAndGetValues() throws DebuggerException { VariablePath variablePath = new VariablePathImpl("i"); - Variable variable = new VariableImpl("int", "i", "2", true, variablePath, Collections.emptyList(), false); + Variable variable = new VariableImpl("int", "i", new SimpleValueImpl("2"), true, variablePath, Collections.emptyList(), false); SimpleValue value = gdbDebugger.getValue(variablePath); assertEquals(value.getString(), "0"); @@ -176,7 +177,7 @@ private void doSetAndGetValues() throws DebuggerException { assertTrue(stackFrameDump.getFields().isEmpty()); assertEquals(stackFrameDump.getVariables().size(), 1); assertEquals(stackFrameDump.getVariables().get(0).getName(), "i"); - assertEquals(stackFrameDump.getVariables().get(0).getValue(), "2"); + assertEquals(stackFrameDump.getVariables().get(0).getValue().getString(), "2"); assertEquals(stackFrameDump.getVariables().get(0).getType(), "int"); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 830d92529b5..f945491fd3f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -30,16 +30,15 @@ import com.sun.jdi.request.StepRequest; import org.eclipse.che.api.debug.shared.dto.BreakpointDto; -import org.eclipse.che.api.debug.shared.dto.FieldDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; -import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; -import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; +import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.action.ResumeAction; @@ -52,7 +51,9 @@ import org.eclipse.che.api.debug.shared.model.impl.FieldImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; +import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.DisconnectEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl; @@ -71,6 +72,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -79,7 +81,6 @@ import java.util.concurrent.locks.ReentrantLock; import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; import static org.eclipse.che.dto.server.DtoFactory.newDto; /** @@ -361,11 +362,10 @@ public void resume(ResumeAction action) throws DebuggerException { } @Override - public StackFrameDumpDto dumpStackFrame() throws DebuggerException { + public StackFrameDump dumpStackFrame() throws DebuggerException { lock.lock(); try { final JdiStackFrame currentFrame = getCurrentFrame(); - StackFrameDumpDto dump = newDto(StackFrameDumpDto.class); boolean existInformation = true; JdiLocalVariable[] variables = new JdiLocalVariable[0]; try { @@ -373,31 +373,35 @@ public StackFrameDumpDto dumpStackFrame() throws DebuggerException { } catch (DebuggerAbsentInformationException e) { existInformation = false; } + + List fields = new LinkedList<>(); for (JdiField f : currentFrame.getFields()) { List variablePath = asList(f.isStatic() ? "static" : "this", f.getName()); - dump.getFields().add(newDto(FieldDto.class).withIsFinal(f.isFinal()) - .withIsStatic(f.isStatic()) - .withIsTransient(f.isTransient()) - .withIsVolatile(f.isVolatile()) - .withName(f.getName()) - .withExistInformation(existInformation) - .withValue(f.getValue().getAsString()) - .withType(f.getTypeName()) - .withVariablePath(newDto(VariablePathDto.class).withPath(variablePath)) - .withPrimitive(f.isPrimitive())); + fields.add(new FieldImpl(f.getName(), + existInformation, + new SimpleValueImpl(f.getValue().getAsString()), + f.getTypeName(), + f.isPrimitive(), + Collections.emptyList(), + new VariablePathImpl(variablePath), + f.isFinal(), + f.isStatic(), + f.isTransient(), + f.isVolatile())); } + + List vars = new LinkedList<>(); for (JdiLocalVariable var : variables) { - dump.getVariables().add(newDto(VariableDto.class).withName(var.getName()) - .withExistInformation(existInformation) - .withValue(var.getValue().getAsString()) - .withType(var.getTypeName()) - .withVariablePath( - newDto(VariablePathDto.class) - .withPath(singletonList(var.getName())) - ) - .withPrimitive(var.isPrimitive())); + vars.add(new VariableImpl(var.getTypeName(), + var.getName(), + new SimpleValueImpl(var.getValue().getAsString()), + var.isPrimitive(), + new VariablePathImpl(var.getName()), + Collections.emptyList(), + existInformation)); } - return dump; + + return new StackFrameDumpImpl(fields, vars); } finally { lock.unlock(); } @@ -485,7 +489,7 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException JdiField f = (JdiField)ch; variables.add(new FieldImpl(f.getName(), true, - f.getValue().getAsString(), + new SimpleValueImpl(f.getValue().getAsString()), f.getTypeName(), f.isPrimitive(), Collections.emptyList(), @@ -498,7 +502,7 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException // Array element. variables.add(new VariableImpl(ch.getTypeName(), ch.getName(), - ch.getValue().getAsString(), + new SimpleValueImpl(ch.getValue().getAsString()), ch.isPrimitive(), chPath, Collections.emptyList(), @@ -524,7 +528,7 @@ public void setValue(Variable variable) throws DebuggerException { expression.append(s); } expression.append('='); - expression.append(variable.getValue()); + expression.append(variable.getValue().getString()); evaluate(expression.toString()); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index 35071299125..236c1b3bfe5 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -26,6 +26,7 @@ import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl; @@ -240,7 +241,7 @@ public void testSetAndGetValue() throws Exception { assertEquals(debugger.getValue(new VariablePathImpl("test")).getString(), "\"hello\""); assertEquals(debugger.getValue(new VariablePathImpl("msg")).getString(), "\"Hello, debugger!\""); - debugger.setValue(new VariableImpl("\"new hello\"", (new VariablePathImpl("test")))); + debugger.setValue(new VariableImpl(new SimpleValueImpl("\"new hello\""), (new VariablePathImpl("test")))); assertEquals(debugger.getValue(new VariablePathImpl("test")).getString(), "\"new hello\""); diff --git a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-server/src/main/java/org/eclipse/che/plugin/nodejsdbg/server/NodeJsDebugger.java b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-server/src/main/java/org/eclipse/che/plugin/nodejsdbg/server/NodeJsDebugger.java index 25968b141a7..fd04c6909a6 100644 --- a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-server/src/main/java/org/eclipse/che/plugin/nodejsdbg/server/NodeJsDebugger.java +++ b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-server/src/main/java/org/eclipse/che/plugin/nodejsdbg/server/NodeJsDebugger.java @@ -231,7 +231,7 @@ public void setValue(Variable variable) throws DebuggerException { if (path.isEmpty()) { throw new DebuggerException("Variable path is empty"); } - library.setVar(path.get(0), variable.getValue()); + library.setVar(path.get(0), variable.getValue().getString()); } catch (NodeJsDebuggerTerminatedException e) { disconnect(); throw e; diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java index 90ce910a28a..019410886e8 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java @@ -10,21 +10,6 @@ *******************************************************************************/ package org.eclipse.che.plugin.zdb.server; -import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_READY; -import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_SESSION_STARTED; -import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_SRIPT_ENDED; -import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_START_PROCESS_FILE; -import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.REQUEST_GET_LOCAL_FILE_CONTENT; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; import org.eclipse.che.api.debug.shared.model.Location; @@ -38,7 +23,6 @@ import org.eclipse.che.api.debug.shared.model.action.StepOutAction; import org.eclipse.che.api.debug.shared.model.action.StepOverAction; import org.eclipse.che.api.debug.shared.model.impl.DebuggerInfoImpl; -import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl; @@ -85,6 +69,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_READY; +import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_SESSION_STARTED; +import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_SRIPT_ENDED; +import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_START_PROCESS_FILE; +import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.REQUEST_GET_LOCAL_FILE_CONTENT; + /** * Zend Debugger for PHP. * @@ -136,7 +135,7 @@ public static ZendDbgBreakpoint create(Breakpoint vfsBreakpoint, ZendDbgLocation return new ZendDbgBreakpoint(dbgLocation, vfsBreakpoint); } - private Location dbgLocation; + private Location dbgLocation; private Breakpoint vfsBreakpoint; private ZendDbgBreakpoint(Location dbgLocation, Breakpoint vfsBreakpoint) { @@ -154,23 +153,23 @@ public Breakpoint getVfsBreakpoint() { } - public static final Logger LOG = LoggerFactory.getLogger(ZendDebugger.class); - private static final int SUPPORTED_PROTOCOL_ID = 2012121702; + public static final Logger LOG = LoggerFactory.getLogger(ZendDebugger.class); + private static final int SUPPORTED_PROTOCOL_ID = 2012121702; - private final DebuggerCallback debugCallback; - private final ZendDbgSettings debugSettings; + private final DebuggerCallback debugCallback; + private final ZendDbgSettings debugSettings; private final ZendDbgLocationHandler debugLocationHandler; - private final ZendDbgConnection debugConnection; + private final ZendDbgConnection debugConnection; private final ZendDbgExpressionEvaluator debugExpressionEvaluator; - private VariablesStorage debugVariableStorage; - private String debugStartFile; - private Map breakpoints = new LinkedHashMap<>(); - private Map breakpointIds = new LinkedHashMap<>(); - private Integer breakpointAflId = null; + private VariablesStorage debugVariableStorage; + private String debugStartFile; + private Map breakpoints = new LinkedHashMap<>(); + private Map breakpointIds = new LinkedHashMap<>(); + private Integer breakpointAflId = null; public ZendDebugger(ZendDbgSettings debugSettings, ZendDbgLocationHandler debugLocationHandler, - DebuggerCallback debugCallback) throws DebuggerException { + DebuggerCallback debugCallback) throws DebuggerException { this.debugCallback = debugCallback; this.debugSettings = debugSettings; this.debugLocationHandler = debugLocationHandler; @@ -182,24 +181,24 @@ public ZendDebugger(ZendDbgSettings debugSettings, ZendDbgLocationHandler debugL @Override public void handleNotification(IDbgEngineNotification notification) { switch (notification.getType()) { - case NOTIFICATION_SESSION_STARTED: { - handleSessionStarted((SessionStartedNotification) notification); - break; - } - case NOTIFICATION_START_PROCESS_FILE: { - handleStartProcessFile((StartProcessFileNotification) notification); - break; - } - case NOTIFICATION_READY: { - handleReady((ReadyNotification) notification); - break; - } - case NOTIFICATION_SRIPT_ENDED: { - handleScriptEnded((ScriptEndedNotification) notification); - break; - } - default: - break; + case NOTIFICATION_SESSION_STARTED: { + handleSessionStarted((SessionStartedNotification)notification); + break; + } + case NOTIFICATION_START_PROCESS_FILE: { + handleStartProcessFile((StartProcessFileNotification)notification); + break; + } + case NOTIFICATION_READY: { + handleReady((ReadyNotification)notification); + break; + } + case NOTIFICATION_SRIPT_ENDED: { + handleScriptEnded((ScriptEndedNotification)notification); + break; + } + default: + break; } } @@ -207,8 +206,8 @@ public void handleNotification(IDbgEngineNotification notification) { @Override public T handleRequest(IDbgEngineRequest request) { switch (request.getType()) { - case REQUEST_GET_LOCAL_FILE_CONTENT: - return (T) handleGetLocalFileContent((GetLocalFileContentRequest) request); + case REQUEST_GET_LOCAL_FILE_CONTENT: + return (T)handleGetLocalFileContent((GetLocalFileContentRequest)request); } return null; } @@ -232,7 +231,7 @@ public void disconnect() throws DebuggerException { @Override public DebuggerInfo getInfo() throws DebuggerException { return new DebuggerInfoImpl(debugSettings.getClientHostIP(), debugSettings.getDebugPort(), "Zend Debugger", "", - 0, null); + 0, null); } @Override @@ -245,7 +244,7 @@ public StackFrameDump dumpStackFrame() { public SimpleValue getValue(VariablePath variablePath) { IDbgVariable matchingVariable = debugVariableStorage.findVariable(variablePath); matchingVariable.makeComplete(); - return new SimpleValueImpl(matchingVariable.getVariables(), matchingVariable.getValue()); + return matchingVariable.getValue(); } @Override @@ -310,13 +309,12 @@ public void resume(ResumeAction action) throws DebuggerException { @Override public void setValue(Variable variable) throws DebuggerException { Variable matchingVariable = debugVariableStorage.findVariable(variable.getVariablePath()); - ((ZendDbgVariable) matchingVariable).setValue(variable.getValue()); + ((ZendDbgVariable)matchingVariable).setValue(variable.getValue().getString()); } @Override public String evaluate(String expression) throws DebuggerException { - ZendDbgExpression zendDbgExpression = new ZendDbgExpression(debugExpressionEvaluator, expression, - Collections.emptyList()); + ZendDbgExpression zendDbgExpression = new ZendDbgExpression(debugExpressionEvaluator, expression, Collections.emptyList()); zendDbgExpression.evaluate(); return zendDbgExpression.getValue(); } @@ -324,14 +322,14 @@ public String evaluate(String expression) throws DebuggerException { @Override public String toString() { return "ZendDebugger [clientHostIP=" + debugSettings.getClientHostIP() + ", debugPort=" - + debugSettings.getDebugPort() + ", useSsslEncryption=" + debugSettings.isUseSsslEncryption() + "]"; + + debugSettings.getDebugPort() + ", useSsslEncryption=" + debugSettings.isUseSsslEncryption() + "]"; } private void handleSessionStarted(SessionStartedNotification notification) { if (!sendSetProtocol()) { sendCloseSession(); LOG.error("Unsupported protocol version: " + notification.getServerProtocolID() - + ", only most recent protocol version: " + SUPPORTED_PROTOCOL_ID + " is supported."); + + ", only most recent protocol version: " + SUPPORTED_PROTOCOL_ID + " is supported."); } debugStartFile = notification.getFileName(); if (debugSettings.isBreakAtFirstLine()) { @@ -379,14 +377,14 @@ private GetLocalFileContentResponse handleGetLocalFileContent(GetLocalFileConten byte[] localFileContent = localFileEntry.getVirtualFile().getContentAsBytes(); // Check if remote content is equal to corresponding local one if (ZendDbgConnectionUtils.isRemoteContentEqual(request.getSize(), request.getCheckSum(), - localFileContent)) { + localFileContent)) { // Remote and local contents are identical return new GetLocalFileContentResponse(request.getID(), - GetLocalFileContentResponse.STATUS_FILES_IDENTICAL, null); + GetLocalFileContentResponse.STATUS_FILES_IDENTICAL, null); } // Remote and local contents are different, send local content to the engine return new GetLocalFileContentResponse(request.getID(), GetLocalFileContentResponse.STATUS_SUCCESS, - localFileContent); + localFileContent); } catch (Exception e) { LOG.error(e.getMessage(), e); } @@ -418,7 +416,7 @@ private void sendGetVariables() { if (VariablesStorage.GLOBALS_VARIABLE.equalsIgnoreCase(zendVariableExpression.getExpression())) continue; IDbgVariable variable = new ZendDbgVariable(new VariablePathImpl(String.valueOf(variableId++)), - zendVariableExpression); + zendVariableExpression); if (ZendDbgVariableUtils.isThis(zendVariableExpression.getExpression())) { // $this always on top variables.add(0, variable); @@ -457,7 +455,9 @@ private void sendAddBreakpoints(String remoteFilePath) { private void sendAddBreakpoint(ZendDbgBreakpoint dbgBreakpoint) { AddBreakpointResponse response = debugConnection.sendRequest(new AddBreakpointRequest(1, 2, - dbgBreakpoint.getLocation().getLineNumber(), dbgBreakpoint.getLocation().getResourcePath())); + dbgBreakpoint.getLocation().getLineNumber(), + dbgBreakpoint.getLocation() + .getResourcePath())); if (isOK(response)) { // Breakpoint was successfully registered in active session, send breakpoint activated event breakpointIds.put(dbgBreakpoint, response.getBreakpointID()); diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java index 37b8063e9ee..bb5c4e830b8 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java @@ -10,17 +10,19 @@ *******************************************************************************/ package org.eclipse.che.plugin.zdb.server.variables; -import static org.eclipse.che.plugin.zdb.server.expressions.IDbgDataFacet.Facet.KIND_ARRAY_MEMBER; -import static org.eclipse.che.plugin.zdb.server.expressions.IDbgDataFacet.Facet.KIND_OBJECT_MEMBER; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.VariablePath; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; +import org.eclipse.che.plugin.zdb.server.expressions.IDbgDataType.DataType; +import org.eclipse.che.plugin.zdb.server.expressions.IDbgExpression; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.che.api.debug.shared.model.VariablePath; -import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; -import org.eclipse.che.plugin.zdb.server.expressions.IDbgDataType.DataType; -import org.eclipse.che.plugin.zdb.server.expressions.IDbgExpression; +import static org.eclipse.che.plugin.zdb.server.expressions.IDbgDataFacet.Facet.KIND_ARRAY_MEMBER; +import static org.eclipse.che.plugin.zdb.server.expressions.IDbgDataFacet.Facet.KIND_OBJECT_MEMBER; /** * PHP Zend debugger specific variable. @@ -28,11 +30,11 @@ * @author Bartlomiej Laczkowski */ public class ZendDbgVariable implements IDbgVariable { - private final IDbgExpression zendDbgExpression; - private final VariablePath variablePath; - private final String name; - private List variables; - private boolean isComplete; + private final IDbgExpression zendDbgExpression; + private final VariablePath variablePath; + private final String name; + private List variables; + private boolean isComplete; public ZendDbgVariable(VariablePath variablePath, IDbgExpression zendDbgExpression) { this.variablePath = variablePath; @@ -53,10 +55,11 @@ public String getName() { } @Override - public String getValue() { - if (zendDbgExpression.getDataType() == DataType.PHP_STRING) - return '"' + zendDbgExpression.getValue() + '"'; - return zendDbgExpression.getValue(); + public SimpleValue getValue() { + String value = zendDbgExpression.getDataType() == DataType.PHP_STRING + ? '"' + zendDbgExpression.getValue() + '"' + : zendDbgExpression.getValue(); + return new SimpleValueImpl(variables, value); } @Override @@ -67,15 +70,15 @@ public String getType() { @Override public boolean isPrimitive() { switch (zendDbgExpression.getDataType()) { - case PHP_BOOL: - case PHP_FLOAT: - case PHP_INT: - case PHP_STRING: - case PHP_NULL: - case PHP_UNINITIALIZED: - return true; - default: - return false; + case PHP_BOOL: + case PHP_FLOAT: + case PHP_INT: + case PHP_STRING: + case PHP_NULL: + case PHP_UNINITIALIZED: + return true; + default: + return false; } } @@ -123,5 +126,5 @@ private String createName(IDbgExpression expression) { } return name; } - + } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java index 29b83090601..3bf9179126a 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java @@ -16,6 +16,7 @@ import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl; @@ -35,24 +36,24 @@ /** * Class providing different tests for active Zend Debugger session. - * + * * @author Bartlomiej Laczkowski */ public class ZendDbgSessionTest extends AbstractZendDbgSessionTest { - private final String dbgHelloFile = (new File( + private final String dbgHelloFile = (new File( ZendDbgConfigurationTest.class.getResource("/php/hello.php").getPath())).getAbsolutePath(); private final String dbgClassesFile = (new File( ZendDbgConfigurationTest.class.getResource("/php/classes.php").getPath())).getAbsolutePath(); - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testSslConnection() throws Exception { triggerSession(dbgHelloFile, getDbgSettings(true, true)); awaitSuspend(dbgHelloFile, 2); debugger.resume(new ResumeActionImpl()); } - - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testStepping() throws Exception { triggerSession(dbgHelloFile, getDbgSettings(true, false)); awaitSuspend(dbgHelloFile, 2); @@ -64,7 +65,7 @@ public void testStepping() throws Exception { awaitSuspend(dbgHelloFile, 4); } - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testEvaluation() throws Exception { triggerSession(dbgHelloFile, getDbgSettings(true, false)); awaitSuspend(dbgHelloFile, 2); @@ -76,7 +77,7 @@ public void testEvaluation() throws Exception { assertEquals(result, "null"); } - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testBreakpoints() throws Exception { List breakpoints = new ArrayList<>(); Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgHelloFile, 4)); @@ -100,7 +101,7 @@ public void testBreakpoints() throws Exception { assertTrue(debugger.getAllBreakpoints().isEmpty()); } - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testBreaking() throws Exception { List breakpoints = new ArrayList<>(); Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgHelloFile, 4)); @@ -115,7 +116,7 @@ public void testBreaking() throws Exception { awaitSuspend(dbgClassesFile, 10); } - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testVariables() throws Exception { List breakpoints = new ArrayList<>(); Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgClassesFile, 16)); @@ -129,24 +130,24 @@ public void testVariables() throws Exception { StackFrameDump stackFrameDump = debugger.dumpStackFrame(); assertEquals(stackFrameDump.getVariables().size(), 1); assertEquals(stackFrameDump.getVariables().get(0).getName(), "$this"); - assertEquals(stackFrameDump.getVariables().get(0).getValue(), "A"); + assertEquals(stackFrameDump.getVariables().get(0).getValue().getString(), "A"); assertEquals(stackFrameDump.getVariables().get(0).getType(), "object"); debugger.resume(new ResumeActionImpl()); awaitSuspend(dbgClassesFile, 25); stackFrameDump = debugger.dumpStackFrame(); assertEquals(stackFrameDump.getVariables().size(), 3); assertEquals(stackFrameDump.getVariables().get(0).getName(), "$this"); - assertEquals(stackFrameDump.getVariables().get(0).getValue(), "B"); + assertEquals(stackFrameDump.getVariables().get(0).getValue().getString(), "B"); assertEquals(stackFrameDump.getVariables().get(0).getType(), "object"); assertEquals(stackFrameDump.getVariables().get(1).getName(), "$p"); - assertEquals(stackFrameDump.getVariables().get(1).getValue(), "123"); + assertEquals(stackFrameDump.getVariables().get(1).getValue().getString(), "123"); assertEquals(stackFrameDump.getVariables().get(1).getType(), "int"); assertEquals(stackFrameDump.getVariables().get(2).getName(), "$v"); - assertEquals(stackFrameDump.getVariables().get(2).getValue(), "\"B\""); + assertEquals(stackFrameDump.getVariables().get(2).getValue().getString(), "\"B\""); assertEquals(stackFrameDump.getVariables().get(2).getType(), "string"); } - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testGetValue() throws Exception { List breakpoints = new ArrayList<>(); Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgClassesFile, 16)); @@ -172,7 +173,7 @@ public void testGetValue() throws Exception { assertEquals(simpleValue.getString(), "array [3]"); } - @Test(groups = { "zendDbg" }, dependsOnGroups = { "checkPHP" }) + @Test(groups = {"zendDbg"}, dependsOnGroups = {"checkPHP"}) public void testSetValue() throws Exception { List breakpoints = new ArrayList<>(); Breakpoint bp1 = new BreakpointImpl(ZendDbgLocationHandler.createDBG(dbgHelloFile, 5)); @@ -182,14 +183,24 @@ public void testSetValue() throws Exception { awaitSuspend(dbgHelloFile, 5); StackFrameDump stackFrameDump = debugger.dumpStackFrame(); int lastVar = stackFrameDump.getVariables().size() - 1; - Variable variableToFind = new VariableImpl(null, null, "123", false, - new VariablePathImpl(String.valueOf(lastVar)), Collections.emptyList(), false); + Variable variableToFind = new VariableImpl(null, + null, + new SimpleValueImpl("123"), + false, + new VariablePathImpl(String.valueOf(lastVar)), + Collections.emptyList(), + false); debugger.setValue(variableToFind); - assertEquals(stackFrameDump.getVariables().get(lastVar).getValue(), "123"); - variableToFind = new VariableImpl(null, null, "\"ABC\"", false, - new VariablePathImpl(String.valueOf(lastVar)), Collections.emptyList(), false); + assertEquals(stackFrameDump.getVariables().get(lastVar).getValue().getString(), "123"); + variableToFind = new VariableImpl(null, + null, + new SimpleValueImpl("\"ABC\""), + false, + new VariablePathImpl(String.valueOf(lastVar)), + Collections.emptyList(), + false); debugger.setValue(variableToFind); - assertEquals(stackFrameDump.getVariables().get(lastVar).getValue(), "\"ABC\""); + assertEquals(stackFrameDump.getVariables().get(lastVar).getValue().getString(), "\"ABC\""); } } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java index 77bdfc37799..eb0da8fed5a 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java @@ -54,11 +54,11 @@ public interface FieldDto extends Field { FieldDto withExistInformation(boolean existInformation); - String getValue(); + SimpleValueDto getValue(); - void setValue(String value); + void setValue(SimpleValueDto value); - FieldDto withValue(String value); + FieldDto withValue(SimpleValueDto value); String getType(); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java index a992fdd2932..5f6080bf834 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java @@ -30,11 +30,11 @@ public interface VariableDto extends Variable { VariableDto withExistInformation(boolean existInformation); - String getValue(); + SimpleValueDto getValue(); - void setValue(String value); + void setValue(SimpleValueDto value); - VariableDto withValue(String value); + VariableDto withValue(SimpleValueDto value); String getType(); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java index c4b90899baa..9c387b3280b 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java @@ -25,7 +25,7 @@ public interface MutableVariable extends Variable { /** * Sets the new variable value. */ - void setValue(String value); + void setValue(SimpleValue value); /** * Sets the new list of nested variables. diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java index 6f77e72f9b6..5c1c1ce8479 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java @@ -26,7 +26,7 @@ public interface Variable { /** * The variable value. */ - String getValue(); + SimpleValue getValue(); /** * The variable type. E.g.: String, int etc. diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java index e6c7e441965..8daea8a7f52 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.che.api.debug.shared.model.impl; +import org.eclipse.che.api.debug.shared.model.Field; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; @@ -18,7 +20,7 @@ /** * @author Anatoliy Bazko */ -public class FieldImpl extends VariableImpl { +public class FieldImpl extends VariableImpl implements Field { private boolean isFinal; private boolean isStatic; private boolean isTransient; @@ -26,7 +28,7 @@ public class FieldImpl extends VariableImpl { public FieldImpl(String name, boolean isExistInformation, - String value, + SimpleValue value, String type, boolean isPrimitive, List variables, @@ -42,19 +44,23 @@ public FieldImpl(String name, this.isVolatile = isVolatile; } - public boolean isFinal() { + @Override + public boolean isIsFinal() { return isFinal; } - public boolean isStatic() { + @Override + public boolean isIsStatic() { return isStatic; } - public boolean isTransient() { + @Override + public boolean isIsTransient() { return isTransient; } - public boolean isVolatile() { + @Override + public boolean isIsVolatile() { return isVolatile; } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java index dd9e05ac701..c137bd80e87 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java @@ -11,6 +11,7 @@ package org.eclipse.che.api.debug.shared.model.impl; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; @@ -28,12 +29,12 @@ public class MutableVariableImpl implements MutableVariable { private final boolean isPrimitive; private final VariablePath variablePath; - private String value; + private SimpleValue value; private List variables; public MutableVariableImpl(String type, String name, - String value, + SimpleValue value, VariablePath variablePath, boolean isPrimitive, List variables, @@ -61,7 +62,7 @@ public boolean isExistInformation() { } @Override - public String getValue() { + public SimpleValue getValue() { return value; } @@ -81,7 +82,7 @@ public List getVariables() { } @Override - public void setValue(String value) { + public void setValue(SimpleValue value) { this.value = value; } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java index 0141d638147..6414f8bbcb2 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/SimpleValueImpl.java @@ -29,6 +29,10 @@ public SimpleValueImpl(List variables, String value) { this.value = value; } + public SimpleValueImpl(String value) { + this(Collections.emptyList(), value); + } + public SimpleValueImpl(SimpleValueDto dto) { this(dto.getVariables(), dto.getString()); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java index 7e1bfcb0a54..b586058d896 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.api.debug.shared.model.impl; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.Variable; @@ -22,7 +23,7 @@ public class VariableImpl implements Variable { private final String name; private final boolean isExistInformation; - private final String value; + private final SimpleValue value; private final String type; private final boolean isPrimitive; private final List variables; @@ -30,7 +31,7 @@ public class VariableImpl implements Variable { public VariableImpl(String type, String name, - String value, + SimpleValue value, boolean isPrimitive, VariablePath variablePath, List variables, @@ -44,7 +45,7 @@ public VariableImpl(String type, this.variablePath = variablePath; } - public VariableImpl(String value, VariablePath variablePath) { + public VariableImpl(SimpleValue value, VariablePath variablePath) { this(null, null, value, false, variablePath, Collections.emptyList(), false); } @@ -58,7 +59,7 @@ public boolean isExistInformation() { } @Override - public String getValue() { + public SimpleValue getValue() { return value; } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index ed467678758..4205b1f03eb 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -49,7 +49,7 @@ import java.util.List; import java.util.Map; -import static org.eclipse.che.api.debugger.server.DtoConverter.asBreakpointsDto; +import static org.eclipse.che.api.debugger.server.DtoConverter.breakpointsAsDtos; import static org.eclipse.che.api.debugger.server.DtoConverter.asDto; import static org.eclipse.che.dto.server.DtoFactory.newDto; @@ -143,7 +143,7 @@ public void addBreakpoint(@PathParam("id") String sessionId, BreakpointDto break @Path("{id}/breakpoint") @Produces(MediaType.APPLICATION_JSON) public List getBreakpoints(@PathParam("id") String sessionId) throws DebuggerException { - return asBreakpointsDto(debuggerManager.getDebugger(sessionId).getAllBreakpoints()); + return breakpointsAsDtos(debuggerManager.getDebugger(sessionId).getAllBreakpoints()); } @DELETE diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 7d4ad464567..e4b00fda711 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -29,17 +29,16 @@ import org.eclipse.che.api.debug.shared.model.DebuggerInfo; import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; -import java.util.Collections; +import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; import static org.eclipse.che.dto.server.DtoFactory.newDto; @@ -71,8 +70,15 @@ public static BreakpointDto asDto(Breakpoint breakpoint) { .withLocation(asDto(breakpoint.getLocation())); } - public static List asBreakpointsDto(List breakpoints) { - return breakpoints.stream().map(DtoConverter::asDto).collect(Collectors.toList()); + public static List breakpointsAsDtos(List breakpoints) { + List dtos = new LinkedList<>(); + + if (breakpoints != null) { + for (int i = 0; i < breakpoints.size(); i++) { + dtos.add(asDto(breakpoints.get(i))); + } + } + return dtos; } public static LocationDto asDto(Location location) { @@ -86,7 +92,7 @@ public static LocationDto asDto(Location location) { public static SimpleValueDto asDto(SimpleValue value) { return newDto(SimpleValueDto.class).withString(value.getString()) - .withVariables(asVariablesDto(value.getVariables())); + .withVariables(variablesAsDtos(value.getVariables())); } public static FieldDto asDto(Field field) { @@ -94,21 +100,35 @@ public static FieldDto asDto(Field field) { .withExistInformation(field.isExistInformation()) .withName(field.getName()) .withPrimitive(field.isPrimitive()) - .withValue(field.getValue()) + .withValue(asDto(field.getValue())) .withVariablePath(asDto(field.getVariablePath())) - .withVariables(asVariablesDto(field.getVariables())) + .withVariables(variablesAsDtos(field.getVariables())) .withIsFinal(field.isIsFinal()) .withIsStatic(field.isIsStatic()) .withIsTransient(field.isIsTransient()) .withIsVolatile(field.isIsVolatile()); } - public static List asFieldsDto(List fields) { - return fields.stream().map(DtoConverter::asDto).collect(Collectors.toList()); + public static List fieldsAsDtos(List fields) { + List dtos = new LinkedList<>(); + + if (fields != null) { + for (int i = 0; i < fields.size(); i++) { + dtos.add(asDto(fields.get(i))); + } + } + return dtos; } - public static List asVariablesDto(List variables) { - return variables.stream().map(DtoConverter::asDto).collect(Collectors.toList()); + public static List variablesAsDtos(List variables) { + List dtos = new LinkedList<>(); + + if (variables != null) { + for (int i = 0; i < variables.size(); i++) { + dtos.add(asDto(variables.get(i))); + } + } + return dtos; } public static VariableDto asDto(Variable variable) { @@ -116,10 +136,9 @@ public static VariableDto asDto(Variable variable) { .withExistInformation(variable.isExistInformation()) .withName(variable.getName()) .withPrimitive(variable.isPrimitive()) - .withValue(variable.getValue()) + .withValue(asDto(variable.getValue())) .withVariablePath(asDto(variable.getVariablePath())) - .withVariables(variable.getVariables().isEmpty() ? Collections.emptyList() - : asVariablesDto(variable.getVariables())); + .withVariables(variablesAsDtos(variable.getVariables())); } public static VariablePathDto asDto(VariablePath variablePath) { @@ -127,8 +146,8 @@ public static VariablePathDto asDto(VariablePath variablePath) { } public static StackFrameDumpDto asDto(StackFrameDump stackFrameDump) { - return newDto(StackFrameDumpDto.class).withVariables(asVariablesDto(stackFrameDump.getVariables())) - .withFields(asFieldsDto(stackFrameDump.getFields())); + return newDto(StackFrameDumpDto.class).withVariables(variablesAsDtos(stackFrameDump.getVariables())) + .withFields(fieldsAsDtos(stackFrameDump.getFields())); } public static DebuggerEventDto asDto(DebuggerEvent debuggerEvent) { From 65c403383c9433fd5bbf2619f139fa814c132baf Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Tue, 17 Jan 2017 09:27:32 +0200 Subject: [PATCH 03/38] CHE-3708: Remove Variable.getVariables() method --- .../debugger/ide/debug/AbstractDebugger.java | 1 - .../debugger/ide/debug/DebuggerTest.java | 4 --- .../che/plugin/gdb/server/GdbDebugger.java | 1 - .../plugin/gdb/server/GdbDebuggerTest.java | 2 +- .../che/plugin/jdb/server/JavaDebugger.java | 4 --- .../che/plugin/zdb/server/ZendDebugger.java | 7 ++++- .../zdb/server/variables/IDbgVariable.java | 9 ++---- .../zdb/server/variables/ZendDbgVariable.java | 5 ---- .../plugin/zdb/server/ZendDbgSessionTest.java | 3 -- .../che/api/debug/shared/dto/FieldDto.java | 8 ----- .../che/api/debug/shared/dto/VariableDto.java | 8 ----- .../che/api/debug/shared/model/Variable.java | 7 ----- .../debug/shared/model/impl/FieldImpl.java | 6 +--- .../model/impl/MutableVariableImpl.java | 2 +- .../debug/shared/model/impl/VariableImpl.java | 29 +++++-------------- .../che/api/debugger/server/DtoConverter.java | 4 +-- 16 files changed, 20 insertions(+), 80 deletions(-) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 75520ebd99c..be679501bb3 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -768,7 +768,6 @@ private VariableDto asDto(Variable variable) { dto.withType(variable.getType()); dto.withName(variable.getName()); dto.withExistInformation(variable.isExistInformation()); - dto.withVariables(asDto(variable.getVariables())); return dto; } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index 82aa103e5a0..e08b276bdfa 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -68,7 +68,6 @@ import org.mockito.MockitoAnnotations; import org.mockito.internal.creation.MockSettingsImpl; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -491,14 +490,12 @@ public void testGetValue() throws Exception { SimpleValue simpleValue = mock(SimpleValue.class); doReturn(simpleValue).when(variable).getValue(); - doReturn(Collections.emptyList()).when(variable).getVariables(); doReturn(simpleValue).when(variable).getValue(); doReturn(variableDto).when(dtoFactory).createDto(VariableDto.class); doReturn(mock(VariablePathDto.class)).when(dtoFactory).createDto(VariablePathDto.class); doReturn(mock(VariablePathDto.class)).when(variable).getVariablePath(); - doReturn(Collections.emptyList()).when(variable).getVariables(); doReturn(promiseValue).when(service).getValue(SESSION_ID, variableDto); doReturn(promiseValue).when(promiseValue).then((Function)any()); doReturn(promiseValue).when(promiseValue).catchError((Operation)any()); @@ -579,7 +576,6 @@ public void testChangeVariableValue() throws Exception { SimpleValue simpleValue = mock(SimpleValue.class); doReturn(newValue).when(simpleValue).getString(); doReturn(simpleValue).when(variable).getValue(); - doReturn(Collections.emptyList()).when(variable).getVariables(); doReturn(promiseVoid).when(service).setValue(SESSION_ID, variableDto); doReturn(promiseVoid).when(promiseVoid).then((Operation)any()); diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java index afb8cbf95b8..89ae9266763 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java @@ -449,7 +449,6 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { new SimpleValueImpl(varValue), true, variablePath, - Collections.emptyList(), true); variables.add(variable); } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java index 088446c06f2..4c366e4c9f6 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java @@ -156,7 +156,7 @@ private void stepOver() throws DebuggerException, InterruptedException { private void doSetAndGetValues() throws DebuggerException { VariablePath variablePath = new VariablePathImpl("i"); - Variable variable = new VariableImpl("int", "i", new SimpleValueImpl("2"), true, variablePath, Collections.emptyList(), false); + Variable variable = new VariableImpl("int", "i", new SimpleValueImpl("2"), true, variablePath, false); SimpleValue value = gdbDebugger.getValue(variablePath); assertEquals(value.getString(), "0"); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index f945491fd3f..373251afb44 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -382,7 +382,6 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { new SimpleValueImpl(f.getValue().getAsString()), f.getTypeName(), f.isPrimitive(), - Collections.emptyList(), new VariablePathImpl(variablePath), f.isFinal(), f.isStatic(), @@ -397,7 +396,6 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { new SimpleValueImpl(var.getValue().getAsString()), var.isPrimitive(), new VariablePathImpl(var.getName()), - Collections.emptyList(), existInformation)); } @@ -492,7 +490,6 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException new SimpleValueImpl(f.getValue().getAsString()), f.getTypeName(), f.isPrimitive(), - Collections.emptyList(), chPath, f.isFinal(), f.isStatic(), @@ -505,7 +502,6 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException new SimpleValueImpl(ch.getValue().getAsString()), ch.isPrimitive(), chPath, - Collections.emptyList(), true)); } } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java index 019410886e8..3c6effd3709 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java @@ -77,6 +77,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_READY; import static org.eclipse.che.plugin.zdb.server.connection.ZendDbgEngineMessages.NOTIFICATION_SESSION_STARTED; @@ -117,7 +118,11 @@ IDbgVariable findVariable(VariablePath variablePath) { if (currentVariablePathElement.equals(pathElement)) { matchingVariable = currentVariable; if (pathIterator.hasNext()) { - currentVariables = new ArrayList<>(currentVariable.getVariables()); + currentVariables = currentVariable.getValue() + .getVariables() + .stream() + .map(v -> (IDbgVariable)v) + .collect(Collectors.toList()); } break; } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/IDbgVariable.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/IDbgVariable.java index 508ca82a85f..6c1d7b4f386 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/IDbgVariable.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/IDbgVariable.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.che.plugin.zdb.server.variables; -import java.util.List; - import org.eclipse.che.api.debug.shared.model.Variable; /** @@ -21,19 +19,16 @@ */ public interface IDbgVariable extends Variable { - @Override - List getVariables(); - /** * Requests child variables computation. */ - public void makeComplete(); + void makeComplete(); /** * Assigns new value to this variable. * * @param newValue */ - public void setValue(String newValue); + void setValue(String newValue); } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java index bb5c4e830b8..ce0e4ebe7c6 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java @@ -82,11 +82,6 @@ public boolean isPrimitive() { } } - @Override - public List getVariables() { - return variables; - } - @Override public VariablePath getVariablePath() { return variablePath; diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java index 3bf9179126a..3ad8d27b8b9 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java @@ -28,7 +28,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import static org.testng.Assert.assertEquals; @@ -188,7 +187,6 @@ public void testSetValue() throws Exception { new SimpleValueImpl("123"), false, new VariablePathImpl(String.valueOf(lastVar)), - Collections.emptyList(), false); debugger.setValue(variableToFind); assertEquals(stackFrameDump.getVariables().get(lastVar).getValue().getString(), "123"); @@ -197,7 +195,6 @@ public void testSetValue() throws Exception { new SimpleValueImpl("\"ABC\""), false, new VariablePathImpl(String.valueOf(lastVar)), - Collections.emptyList(), false); debugger.setValue(variableToFind); assertEquals(stackFrameDump.getVariables().get(lastVar).getValue().getString(), "\"ABC\""); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java index eb0da8fed5a..1e22601c564 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java @@ -13,8 +13,6 @@ import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.dto.shared.DTO; -import java.util.List; - /** @author andrew00x */ @DTO public interface FieldDto extends Field { @@ -77,10 +75,4 @@ public interface FieldDto extends Field { void setPrimitive(boolean primitive); FieldDto withPrimitive(boolean primitive); - - List getVariables(); - - void setVariables(List variables); - - FieldDto withVariables(List variables); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java index 5f6080bf834..39b95cefba2 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java @@ -13,8 +13,6 @@ import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.dto.shared.DTO; -import java.util.List; - /** @author andrew00x */ @DTO public interface VariableDto extends Variable { @@ -53,10 +51,4 @@ public interface VariableDto extends Variable { void setPrimitive(boolean primitive); VariableDto withPrimitive(boolean primitive); - - List getVariables(); - - void setVariables(List variables); - - VariableDto withVariables(List variables); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java index 5c1c1ce8479..056466cf468 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.che.api.debug.shared.model; -import java.util.List; - /** * @author Anatoliy Bazko */ @@ -42,9 +40,4 @@ public interface Variable { * Indicates if variable is primitive. */ boolean isPrimitive(); - - /** - * The nested variables. - */ - List getVariables(); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java index 8daea8a7f52..cba5d25be41 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java @@ -12,11 +12,8 @@ import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.SimpleValue; -import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; -import java.util.List; - /** * @author Anatoliy Bazko */ @@ -31,13 +28,12 @@ public FieldImpl(String name, SimpleValue value, String type, boolean isPrimitive, - List variables, VariablePath variablePath, boolean isFinal, boolean isStatic, boolean isTransient, boolean isVolatile) { - super(type, name, value, isPrimitive, variablePath, variables, isExistInformation); + super(type, name, value, isPrimitive, variablePath, isExistInformation); this.isFinal = isFinal; this.isStatic = isStatic; this.isTransient = isTransient; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java index c137bd80e87..1631a5f4165 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java @@ -130,7 +130,7 @@ private static MutableVariable toMutable(Variable variable) { variable.getValue(), variable.getVariablePath(), variable.isPrimitive(), - variable.getVariables(), + variable.getValue().getVariables(), variable.isExistInformation()); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java index b586058d896..648ec11905b 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java @@ -11,42 +11,36 @@ package org.eclipse.che.api.debug.shared.model.impl; import org.eclipse.che.api.debug.shared.model.SimpleValue; -import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.Variable; - -import java.util.Collections; -import java.util.List; +import org.eclipse.che.api.debug.shared.model.VariablePath; /** * @author Anatoliy Bazko */ public class VariableImpl implements Variable { - private final String name; - private final boolean isExistInformation; - private final SimpleValue value; - private final String type; - private final boolean isPrimitive; - private final List variables; - private final VariablePath variablePath; + private final String name; + private final boolean isExistInformation; + private final SimpleValue value; + private final String type; + private final boolean isPrimitive; + private final VariablePath variablePath; public VariableImpl(String type, String name, SimpleValue value, boolean isPrimitive, VariablePath variablePath, - List variables, boolean isExistInformation) { this.name = name; this.isExistInformation = isExistInformation; this.value = value; this.type = type; this.isPrimitive = isPrimitive; - this.variables = variables; this.variablePath = variablePath; } public VariableImpl(SimpleValue value, VariablePath variablePath) { - this(null, null, value, false, variablePath, Collections.emptyList(), false); + this(null, null, value, false, variablePath, false); } @Override @@ -73,11 +67,6 @@ public boolean isPrimitive() { return isPrimitive; } - @Override - public List getVariables() { - return Collections.unmodifiableList(variables); - } - @Override public VariablePath getVariablePath() { return variablePath; @@ -95,7 +84,6 @@ public boolean equals(Object o) { if (name != null ? !name.equals(variable.name) : variable.name != null) return false; if (value != null ? !value.equals(variable.value) : variable.value != null) return false; if (type != null ? !type.equals(variable.type) : variable.type != null) return false; - if (variables != null ? !variables.equals(variable.variables) : variable.variables != null) return false; return !(variablePath != null ? !variablePath.equals(variable.variablePath) : variable.variablePath != null); } @@ -106,7 +94,6 @@ public int hashCode() { result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (isPrimitive ? 1 : 0); - result = 31 * result + (variables != null ? variables.hashCode() : 0); result = 31 * result + (variablePath != null ? variablePath.hashCode() : 0); return result; } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index e4b00fda711..835466f1a15 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -102,7 +102,6 @@ public static FieldDto asDto(Field field) { .withPrimitive(field.isPrimitive()) .withValue(asDto(field.getValue())) .withVariablePath(asDto(field.getVariablePath())) - .withVariables(variablesAsDtos(field.getVariables())) .withIsFinal(field.isIsFinal()) .withIsStatic(field.isIsStatic()) .withIsTransient(field.isIsTransient()) @@ -137,8 +136,7 @@ public static VariableDto asDto(Variable variable) { .withName(variable.getName()) .withPrimitive(variable.isPrimitive()) .withValue(asDto(variable.getValue())) - .withVariablePath(asDto(variable.getVariablePath())) - .withVariables(variablesAsDtos(variable.getVariables())); + .withVariablePath(asDto(variable.getVariablePath())); } public static VariablePathDto asDto(VariablePath variablePath) { From 3c35fcee2854d6aaa41e764c8080e749782e313d Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Tue, 17 Jan 2017 11:09:02 +0200 Subject: [PATCH 04/38] Jdi classes implements model interfaces --- .../che/plugin/jdb/server/JavaDebugger.java | 67 +++-------- .../che/plugin/jdb/server/JdiField.java | 56 --------- .../plugin/jdb/server/JdiStackFrameImpl.java | 112 ------------------ .../che/plugin/jdb/server/JdiVariable.java | 68 ----------- .../jdb/server/{ => jdi}/JdiArrayElement.java | 2 +- .../server/{ => jdi}/JdiArrayElementImpl.java | 17 ++- .../JdiField.java} | 9 +- .../jdb/server/jdi/JdiFieldComparator.java | 34 ++++++ .../jdb/server/{ => jdi}/JdiFieldImpl.java | 45 +++---- .../jdb/server/{ => jdi}/JdiNullValue.java | 28 +++-- .../jdb/server/{ => jdi}/JdiStackFrame.java | 39 +++--- .../jdb/server/jdi/JdiStackFrameImpl.java | 107 +++++++++++++++++ .../plugin/jdb/server/{ => jdi}/JdiType.java | 2 +- .../plugin/jdb/server/{ => jdi}/JdiValue.java | 46 ++++--- .../jdb/server/{ => jdi}/JdiValueImpl.java | 48 ++++---- .../JdiVariable.java} | 16 +-- .../JdiVariableImpl.java} | 26 ++-- 17 files changed, 301 insertions(+), 421 deletions(-) delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiField.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrameImpl.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiVariable.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiArrayElement.java (95%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiArrayElementImpl.java (78%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{JdiLocalVariable.java => jdi/JdiField.java} (71%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiFieldImpl.java (66%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiNullValue.java (58%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiStackFrame.java (52%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiType.java (97%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiValue.java (52%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{ => jdi}/JdiValueImpl.java (60%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{exceptions/DebuggerAbsentInformationException.java => jdi/JdiVariable.java} (60%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{JdiLocalVariableImpl.java => jdi/JdiVariableImpl.java} (69%) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 373251afb44..06f8ed8712c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -35,7 +35,6 @@ import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; -import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; @@ -53,16 +52,18 @@ import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; -import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.DisconnectEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl; import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException; import org.eclipse.che.plugin.jdb.server.expression.Evaluator; import org.eclipse.che.plugin.jdb.server.expression.ExpressionException; import org.eclipse.che.plugin.jdb.server.expression.ExpressionParser; +import org.eclipse.che.plugin.jdb.server.jdi.JdiField; +import org.eclipse.che.plugin.jdb.server.jdi.JdiStackFrame; +import org.eclipse.che.plugin.jdb.server.jdi.JdiStackFrameImpl; +import org.eclipse.che.plugin.jdb.server.jdi.JdiVariable; import org.eclipse.che.plugin.jdb.server.utils.JavaDebuggerUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,7 +73,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -80,7 +80,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import static java.util.Arrays.asList; import static org.eclipse.che.dto.server.DtoFactory.newDto; /** @@ -366,40 +365,7 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { lock.lock(); try { final JdiStackFrame currentFrame = getCurrentFrame(); - boolean existInformation = true; - JdiLocalVariable[] variables = new JdiLocalVariable[0]; - try { - variables = currentFrame.getLocalVariables(); - } catch (DebuggerAbsentInformationException e) { - existInformation = false; - } - - List fields = new LinkedList<>(); - for (JdiField f : currentFrame.getFields()) { - List variablePath = asList(f.isStatic() ? "static" : "this", f.getName()); - fields.add(new FieldImpl(f.getName(), - existInformation, - new SimpleValueImpl(f.getValue().getAsString()), - f.getTypeName(), - f.isPrimitive(), - new VariablePathImpl(variablePath), - f.isFinal(), - f.isStatic(), - f.isTransient(), - f.isVolatile())); - } - - List vars = new LinkedList<>(); - for (JdiLocalVariable var : variables) { - vars.add(new VariableImpl(var.getTypeName(), - var.getName(), - new SimpleValueImpl(var.getValue().getAsString()), - var.isPrimitive(), - new VariablePathImpl(var.getName()), - existInformation)); - } - - return new StackFrameDumpImpl(fields, vars); + return new StackFrameDumpImpl(currentFrame.getFields(), currentFrame.getVariables()); } finally { lock.unlock(); } @@ -463,9 +429,8 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException variable = getCurrentFrame().getFieldByName(path.get(1)); offset = 2; } else { - try { - variable = getCurrentFrame().getLocalVariableByName(path.get(0)); - } catch (DebuggerAbsentInformationException e) { + variable = getCurrentFrame().getVariableByName(path.get(0)); + if (variable == null) { return null; } offset = 1; @@ -487,25 +452,25 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException JdiField f = (JdiField)ch; variables.add(new FieldImpl(f.getName(), true, - new SimpleValueImpl(f.getValue().getAsString()), - f.getTypeName(), + new SimpleValueImpl(f.getValue().getString()), + f.getType(), f.isPrimitive(), chPath, - f.isFinal(), - f.isStatic(), - f.isTransient(), - f.isVolatile())); + f.isIsFinal(), + f.isIsStatic(), + f.isIsTransient(), + f.isIsVolatile())); } else { // Array element. - variables.add(new VariableImpl(ch.getTypeName(), + variables.add(new VariableImpl(ch.getType(), ch.getName(), - new SimpleValueImpl(ch.getValue().getAsString()), + new SimpleValueImpl(ch.getValue().getString()), ch.isPrimitive(), chPath, true)); } } - return new SimpleValueImpl(variables, variable.getValue().getAsString()); + return new SimpleValueImpl(variables, variable.getValue().getString()); } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiField.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiField.java deleted file mode 100644 index 2dacdab65d7..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiField.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; - -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; - -/** - * Instance of class member in debugger JVM. - * - * @author andrew00x - */ -public interface JdiField extends JdiVariable { - /** - * Check is this field is final. - * - * @return true if field is final and false otherwise - * @throws DebuggerException - * if an error occurs - */ - boolean isFinal() throws DebuggerException; - - /** - * Check is this field is static. - * - * @return true if field is static and false otherwise - * @throws DebuggerException - * if an error occurs - */ - boolean isStatic() throws DebuggerException; - - /** - * Check is this transient is transient. - * - * @return true if field is transient and false otherwise - * @throws DebuggerException - * if an error occurs - */ - boolean isTransient() throws DebuggerException; - - /** - * Check is this field is volatile. - * - * @return true if field is volatile and false otherwise - * @throws DebuggerException - * if an error occurs - */ - boolean isVolatile() throws DebuggerException; -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrameImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrameImpl.java deleted file mode 100644 index 9f9185b4d95..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrameImpl.java +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.Field; -import com.sun.jdi.InvalidStackFrameException; -import com.sun.jdi.LocalVariable; -import com.sun.jdi.NativeMethodException; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.ReferenceType; -import com.sun.jdi.StackFrame; - -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException; - -import java.util.Arrays; -import java.util.List; - -/** @author andrew00x */ -public class JdiStackFrameImpl implements JdiStackFrame { - private final StackFrame stackFrame; - private JdiField[] fields; - private JdiLocalVariable[] localVariables; - - public JdiStackFrameImpl(StackFrame stackFrame) { - this.stackFrame = stackFrame; - } - - @Override - public JdiField[] getFields() throws DebuggerException { - if (fields == null) { - try { - ObjectReference object = stackFrame.thisObject(); - if (object == null) { - ReferenceType type = stackFrame.location().declaringType(); - List fs = stackFrame.location().declaringType().allFields(); - fields = new JdiField[fs.size()]; - int i = 0; - for (Field f : fs) { - fields[i++] = new JdiFieldImpl(f, type); - } - } else { - List fs = object.referenceType().allFields(); - fields = new JdiField[fs.size()]; - int i = 0; - for (Field f : fs) { - fields[i++] = new JdiFieldImpl(f, object); - } - } - - Arrays.sort(fields); - } catch (InvalidStackFrameException e) { - throw new DebuggerException(e.getMessage(), e); - } - } - return fields; - } - - @Override - public JdiField getFieldByName(String name) throws DebuggerException { - if (name == null) { - throw new IllegalArgumentException("Field name may not be null. "); - } - for (JdiField f : getFields()) { - if (name.equals(f.getName())) { - return f; - } - } - return null; - } - - @Override - public JdiLocalVariable[] getLocalVariables() throws DebuggerException { - if (localVariables == null) { - try { - List targetVariables = stackFrame.visibleVariables(); - localVariables = new JdiLocalVariable[targetVariables.size()]; - int i = 0; - for (LocalVariable var : targetVariables) { - localVariables[i++] = new JdiLocalVariableImpl(stackFrame, var); - } - } catch (AbsentInformationException e) { - throw new DebuggerAbsentInformationException(e.getMessage(), e); - } catch (InvalidStackFrameException | NativeMethodException e) { - throw new DebuggerException(e.getMessage(), e); - } - } - return localVariables; - } - - @Override - public JdiLocalVariable getLocalVariableByName(String name) throws DebuggerException { - if (name == null) { - throw new IllegalArgumentException("Field name may not be null. "); - } - for (JdiLocalVariable var : getLocalVariables()) { - if (name.equals(var.getName())) { - return var; - } - } - return null; - } -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiVariable.java deleted file mode 100644 index f547df75172..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiVariable.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; - -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; - -/** - * Variable at debuggee JVM. - * - * @author andrew00x - * @see JdiField - * @see JdiLocalVariable - * @see JdiArrayElement - */ -public interface JdiVariable { - /** - * Name of variable. If this variable is element of array then name is: [i], where i - index of element - * - * @return name of variable - * @throws DebuggerException - * if an error occurs - */ - String getName() throws DebuggerException; - - /** - * Check is this variable is array. - * - * @return true if variable is array and false otherwise - * @throws DebuggerException - * if an error occurs - */ - boolean isArray() throws DebuggerException; - - /** - * Check is this variable is primitive. - * - * @return true if variable is primitive and false otherwise - * @throws DebuggerException - * if an error occurs - */ - boolean isPrimitive() throws DebuggerException; - - /** - * Get value of variable. - * - * @return value - * @throws DebuggerException - * if an error occurs - */ - JdiValue getValue() throws DebuggerException; - - /** - * Name of variable type. - * - * @return type name - * @throws DebuggerException - * if an error occurs - */ - String getTypeName() throws DebuggerException; -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiArrayElement.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java similarity index 95% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiArrayElement.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java index d2bb1ea3252..18234cc1862 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiArrayElement.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiArrayElementImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java similarity index 78% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiArrayElementImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java index 9746facb68a..e32bb9e5e9c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiArrayElementImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java @@ -8,12 +8,14 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; -import com.sun.jdi.ArrayReference; import com.sun.jdi.PrimitiveValue; import com.sun.jdi.Value; +import org.eclipse.che.api.debug.shared.model.VariablePath; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; + /** @author andrew00x */ public class JdiArrayElementImpl implements JdiArrayElement { private final int index; @@ -37,8 +39,8 @@ public String getName() { } @Override - public boolean isArray() { - return value instanceof ArrayReference; + public boolean isExistInformation() { + return !getValue().isPrimitive(); } @Override @@ -55,10 +57,15 @@ public JdiValue getValue() { } @Override - public String getTypeName() { + public String getType() { if (value == null) { return "null"; } return value.type().name(); } + + @Override + public VariablePath getVariablePath() { + return new VariablePathImpl(getName()); + } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiLocalVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java similarity index 71% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiLocalVariable.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java index f1dc3a8bd37..272491b20f7 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiLocalVariable.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java @@ -8,12 +8,15 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; + +import org.eclipse.che.api.debug.shared.model.Field; /** - * Local variable in debuggee JVM. + * Wrapper for {@link com.sun.jdi.Field} * * @author andrew00x + * @author Anatolii Bazko */ -public interface JdiLocalVariable extends JdiVariable { +public interface JdiField extends JdiVariable, Field { } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java new file mode 100644 index 00000000000..218a897a24b --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.jdi; + +import java.util.Comparator; + +/** + * @author Anatolii Bazko + */ +public class JdiFieldComparator implements Comparator { + + @Override + public int compare(JdiField o1, JdiField o2) { + final boolean thisStatic = o1.isIsStatic(); + final boolean thatStatic = o2.isIsStatic(); + if (thisStatic && !thatStatic) { + return -1; + } + if (!thisStatic && thatStatic) { + return 1; + } + final String thisName = o1.getName(); + final String thatName = o2.getName(); + return thisName.compareTo(thatName); + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiFieldImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java similarity index 66% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiFieldImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java index 65db4de87d8..687c390f0a9 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiFieldImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java @@ -8,17 +8,20 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; import com.sun.jdi.Field; import com.sun.jdi.ObjectReference; import com.sun.jdi.ReferenceType; import com.sun.jdi.Value; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.api.debug.shared.model.VariablePath; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; + +import static java.util.Arrays.asList; /** @author andrew00x */ -public class JdiFieldImpl implements JdiField, Comparable { +public class JdiFieldImpl implements JdiField { private final Field field; private final ReferenceType type; private final ObjectReference object; @@ -41,32 +44,32 @@ public String getName() { } @Override - public boolean isStatic() { + public boolean isExistInformation() { + return !isPrimitive(); + } + + @Override + public boolean isIsStatic() { return field.isStatic(); } @Override - public boolean isTransient() { + public boolean isIsTransient() { return field.isTransient(); } @Override - public boolean isVolatile() { + public boolean isIsVolatile() { return field.isVolatile(); } @Override - public boolean isFinal() { + public boolean isIsFinal() { return field.isFinal(); } @Override - public boolean isArray() throws DebuggerException { - return JdiType.isArray(field.signature()); - } - - @Override - public boolean isPrimitive() throws DebuggerException { + public boolean isPrimitive() { return JdiType.isPrimitive(field.signature()); } @@ -80,22 +83,12 @@ public JdiValue getValue() { } @Override - public String getTypeName() { + public String getType() { return field.typeName(); } @Override - public int compareTo(JdiFieldImpl o) { - final boolean thisStatic = isStatic(); - final boolean thatStatic = o.isStatic(); - if (thisStatic && !thatStatic) { - return -1; - } - if (!thisStatic && thatStatic) { - return 1; - } - final String thisName = getName(); - final String thatName = o.getName(); - return thisName.compareTo(thatName); + public VariablePath getVariablePath() { + return new VariablePathImpl(asList(isIsStatic() ? "static" : "this", getName())); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiNullValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java similarity index 58% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiNullValue.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java index b4ec1b35faa..bfb7f8d8209 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiNullValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java @@ -8,24 +8,38 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import java.util.Collections; +import java.util.List; -/** @author andrew00x */ +/** + * @author andrew00x + * @author Anatolii Bazko + */ public final class JdiNullValue implements JdiValue { @Override - public String getAsString() throws DebuggerException { + public String getString() { return "null"; } @Override - public JdiVariable[] getVariables() throws DebuggerException { - return new JdiVariable[0]; + public List getVariables() { + return Collections.emptyList(); } @Override - public JdiVariable getVariableByName(String name) throws DebuggerException { + public JdiVariable getVariableByName(String name) { return null; } + + @Override + public boolean isArray() { + return false; + } + + @Override + public boolean isPrimitive() { + return true; + } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java similarity index 52% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrame.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java index bceb34073a0..5bc03162409 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiStackFrame.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java @@ -8,17 +8,19 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.eclipse.che.plugin.jdb.server.exceptions.DebuggerAbsentInformationException; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.commons.annotation.Nullable; + +import java.util.List; /** * State of method invocation. * * @author andrew00x */ -public interface JdiStackFrame { +public interface JdiStackFrame extends StackFrameDump { /** * Get all available instance or class members. * @@ -27,39 +29,26 @@ public interface JdiStackFrame { *
  • static fields should go before non-static fields
  • *
  • fields of the same type should be ordered by name
  • * - * @throws DebuggerException - * if an error occurs */ - JdiField[] getFields() throws DebuggerException; + @Override + List getFields(); /** * Get field by name. * * @return field or null if there is not such field - * @throws DebuggerException - * if an error occurs */ - JdiField getFieldByName(String name) throws DebuggerException; + @Nullable + JdiField getFieldByName(String name); - /** - * Get all available local variables. - * - * @return list of local variables - * @throws DebuggerException - * if an error occurs - * @throws DebuggerAbsentInformationException - * if an error occurs - */ - JdiLocalVariable[] getLocalVariables() throws DebuggerException; + @Override + List getVariables(); /** * Get local variable by name. * * @return local variable or null if there is not such local variable - * @throws DebuggerException - * if an error occurs - * @throws DebuggerAbsentInformationException - * if an error occurs */ - JdiLocalVariable getLocalVariableByName(String name) throws DebuggerException; + @Nullable + JdiVariable getVariableByName(String name); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java new file mode 100644 index 00000000000..85d39e3e5ec --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.jdi; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.Field; +import com.sun.jdi.InvalidStackFrameException; +import com.sun.jdi.NativeMethodException; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.ReferenceType; +import com.sun.jdi.StackFrame; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author andrew00x + * @author Anatolii Bazko + */ +public class JdiStackFrameImpl implements JdiStackFrame { + private final StackFrame stackFrame; + private List fields; + private List variables; + + public JdiStackFrameImpl(StackFrame stackFrame) { + this.stackFrame = stackFrame; + } + + @Override + public List getFields() { + if (fields == null) { + try { + fields = new LinkedList<>(); + + ObjectReference object = stackFrame.thisObject(); + if (object == null) { + ReferenceType type = stackFrame.location().declaringType(); + for (Field f : stackFrame.location().declaringType().allFields()) { + fields.add(new JdiFieldImpl(f, type)); + } + } else { + for (Field f : object.referenceType().allFields()) { + fields.add(new JdiFieldImpl(f, object)); + } + } + + fields.sort(new JdiFieldComparator()); + } catch (InvalidStackFrameException e) { + fields = Collections.emptyList(); + } + } + return fields; + } + + @Override + public JdiField getFieldByName(String name) { + if (name == null) { + throw new IllegalArgumentException("Field name may not be null. "); + } + for (JdiField f : getFields()) { + if (name.equals(f.getName())) { + return f; + } + } + return null; + } + + @Override + public List getVariables() { + if (variables == null) { + try { + variables = stackFrame.visibleVariables() + .stream() + .map(v -> new JdiVariableImpl(stackFrame, v)) + .collect(Collectors.toList()); + } catch (AbsentInformationException | InvalidStackFrameException | NativeMethodException e) { + variables = Collections.emptyList(); + } + } + return variables; + } + + @Override + public JdiVariable getVariableByName(String name) { + if (name == null) { + throw new IllegalArgumentException("Field name may not be null. "); + } + + for (JdiVariable var : getVariables()) { + if (name.equals(var.getName())) { + return var; + } + } + + return null; + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiType.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiType.java similarity index 97% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiType.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiType.java index dc51d6431fe..f39621e6ba7 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiType.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiType.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; /** @author andrew00x */ public class JdiType { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java similarity index 52% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiValue.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java index 797d84e3ddc..e6319ef6098 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java @@ -8,34 +8,23 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.commons.annotation.Nullable; + +import java.util.List; /** - * Value of JdiVariable. + * Wrapper for {@link com.sun.jdi.Value} * * @author andrew00x + * @author Anatolii Bazko */ -public interface JdiValue { - /** - * Get value in String representation. - * - * @return value in String representation - * @throws DebuggerException - * if an error occurs - */ - String getAsString() throws DebuggerException; +public interface JdiValue extends SimpleValue { - /** - * Get nested variables. - * - * @return nested variables. This method always returns empty array for primitive type since primitive type has not - * any fields. If value represents array this method returns array members - * @throws DebuggerException - * if an error occurs - */ - JdiVariable[] getVariables() throws DebuggerException; + @Override + List getVariables(); /** * Get nested variable by name. @@ -44,9 +33,18 @@ public interface JdiValue { * name of variable. Typically it is name of field. If this value represents array then name should be in form: * [i], where i is index of element * @return nested variable with specified name or null if there is no such variable - * @throws DebuggerException - * if an error occurs * @see JdiVariable#getName() */ - JdiVariable getVariableByName(String name) throws DebuggerException; + @Nullable + JdiVariable getVariableByName(String name); + + /** + * Indicates if value is an array. + */ + boolean isArray(); + + /** + * Indicates if value is a primitive type. + */ + boolean isPrimitive(); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiValueImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java similarity index 60% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiValueImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java index 167141312b0..75586cd193f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiValueImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java @@ -8,24 +8,23 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; import com.sun.jdi.ArrayReference; import com.sun.jdi.Field; import com.sun.jdi.ObjectReference; import com.sun.jdi.PrimitiveValue; -import com.sun.jdi.ReferenceType; import com.sun.jdi.Value; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; - -import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; /** @author andrew00x */ public class JdiValueImpl implements JdiValue { - private final Value value; - private JdiVariable[] variables; + private final Value value; + private List variables; public JdiValueImpl(Value value) { if (value == null) { @@ -35,34 +34,31 @@ public JdiValueImpl(Value value) { } @Override - public String getAsString() { + public String getString() { return value.toString(); } @Override - public JdiVariable[] getVariables() { + public List getVariables() { if (variables == null) { if (isPrimitive()) { - variables = new JdiVariable[0]; + variables = Collections.emptyList(); } else { + variables = new LinkedList<>(); if (isArray()) { ArrayReference array = (ArrayReference)value; - int length = array.length(); - variables = new JdiVariable[length]; - for (int i = 0; i < length; i++) { - variables[i] = new JdiArrayElementImpl(i, array.getValue(i)); + for (int i = 0; i < array.length(); i++) { + variables.add(new JdiArrayElementImpl(i, array.getValue(i))); } } else { ObjectReference object = (ObjectReference)value; - ReferenceType type = object.referenceType(); - List fields = type.allFields(); - variables = new JdiVariable[fields.size()]; - int i = 0; - for (Field f : fields) { - variables[i++] = new JdiFieldImpl(f, object); + for (Field f : object.referenceType().allFields()) { + variables.add(new JdiFieldImpl(f, object)); } - // See JdiFieldImpl#compareTo(JdiFieldImpl). - Arrays.sort(variables); + variables = variables.stream() + .map(v -> (JdiField)v) + .sorted(new JdiFieldComparator()) + .collect(Collectors.toList()); } } } @@ -70,7 +66,7 @@ public JdiVariable[] getVariables() { } @Override - public JdiVariable getVariableByName(String name) throws DebuggerException { + public JdiVariable getVariableByName(String name) { if (name == null) { throw new IllegalArgumentException("Variable name may not be null. "); } @@ -82,11 +78,13 @@ public JdiVariable getVariableByName(String name) throws DebuggerException { return null; } - private boolean isArray() { + @Override + public boolean isArray() { return value instanceof ArrayReference; } - private boolean isPrimitive() { + @Override + public boolean isPrimitive() { return value instanceof PrimitiveValue; } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/exceptions/DebuggerAbsentInformationException.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java similarity index 60% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/exceptions/DebuggerAbsentInformationException.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java index 840fadab985..628b8d4281f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/exceptions/DebuggerAbsentInformationException.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java @@ -8,15 +8,17 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.exceptions; +package org.eclipse.che.plugin.jdb.server.jdi; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.api.debug.shared.model.Variable; /** - * @author Anatoliy Bazko + * Wrapper for {@link com.sun.jdi.LocalVariable} + * + * @author andrew00x + * @author Anatolii Bazko */ -public class DebuggerAbsentInformationException extends DebuggerException { - public DebuggerAbsentInformationException(String message, Exception cause) { - super(message, cause); - } +public interface JdiVariable extends Variable { + @Override + JdiValue getValue(); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiLocalVariableImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java similarity index 69% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiLocalVariableImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java index bab5193c2ed..a736152d953 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JdiLocalVariableImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java @@ -8,36 +8,42 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.jdi; import com.sun.jdi.LocalVariable; import com.sun.jdi.StackFrame; import com.sun.jdi.Value; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.api.debug.shared.model.VariablePath; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; /** @author andrew00x */ -public class JdiLocalVariableImpl implements JdiLocalVariable { +public class JdiVariableImpl implements JdiVariable { private final LocalVariable variable; private final StackFrame stackFrame; - public JdiLocalVariableImpl(StackFrame stackFrame, LocalVariable variable) { + @Override + public VariablePath getVariablePath() { + return new VariablePathImpl(getName()); + } + + public JdiVariableImpl(StackFrame stackFrame, LocalVariable variable) { this.stackFrame = stackFrame; this.variable = variable; } @Override - public String getName() { - return variable.name(); + public boolean isExistInformation() { + return !isPrimitive(); } @Override - public boolean isArray() throws DebuggerException { - return JdiType.isArray(variable.signature()); + public String getName() { + return variable.name(); } @Override - public boolean isPrimitive() throws DebuggerException { + public boolean isPrimitive() { return JdiType.isPrimitive(variable.signature()); } @@ -51,7 +57,7 @@ public JdiValue getValue() { } @Override - public String getTypeName() { + public String getType() { return variable.typeName(); } } From 3989395e6b6d1ea0ab26b0a7450b14bb66c53b84 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Tue, 17 Jan 2017 11:50:06 +0200 Subject: [PATCH 05/38] Remove Variable.existsInformation method --- .../debugger/ide/debug/AbstractDebugger.java | 1 - .../che/plugin/gdb/server/GdbDebugger.java | 3 +-- .../che/plugin/gdb/server/GdbDebuggerTest.java | 2 +- .../che/plugin/jdb/server/JavaDebugger.java | 4 +--- .../jdb/server/jdi/JdiArrayElementImpl.java | 5 ----- .../che/plugin/jdb/server/jdi/JdiFieldImpl.java | 5 ----- .../che/plugin/jdb/server/jdi/JdiNullValue.java | 10 ---------- .../che/plugin/jdb/server/jdi/JdiValue.java | 10 ---------- .../che/plugin/jdb/server/jdi/JdiValueImpl.java | 2 -- .../plugin/jdb/server/jdi/JdiVariableImpl.java | 5 ----- .../zdb/server/variables/ZendDbgVariable.java | 5 ----- .../plugin/zdb/server/ZendDbgSessionTest.java | 6 ++---- .../che/api/debug/shared/dto/FieldDto.java | 6 ------ .../che/api/debug/shared/dto/VariableDto.java | 6 ------ .../che/api/debug/shared/model/Variable.java | 2 -- .../api/debug/shared/model/impl/FieldImpl.java | 3 +-- .../shared/model/impl/MutableVariableImpl.java | 16 +++------------- .../debug/shared/model/impl/VariableImpl.java | 13 ++----------- .../che/api/debugger/server/DtoConverter.java | 2 -- 19 files changed, 11 insertions(+), 95 deletions(-) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index be679501bb3..f8f4843b6ce 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -767,7 +767,6 @@ private VariableDto asDto(Variable variable) { dto.withPrimitive(variable.isPrimitive()); dto.withType(variable.getType()); dto.withName(variable.getName()); - dto.withExistInformation(variable.isExistInformation()); return dto; } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java index 89ae9266763..8e257d3936b 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java @@ -448,8 +448,7 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { varName, new SimpleValueImpl(varValue), true, - variablePath, - true); + variablePath); variables.add(variable); } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java index 4c366e4c9f6..6b0865f62d6 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java @@ -156,7 +156,7 @@ private void stepOver() throws DebuggerException, InterruptedException { private void doSetAndGetValues() throws DebuggerException { VariablePath variablePath = new VariablePathImpl("i"); - Variable variable = new VariableImpl("int", "i", new SimpleValueImpl("2"), true, variablePath, false); + Variable variable = new VariableImpl("int", "i", new SimpleValueImpl("2"), true, variablePath); SimpleValue value = gdbDebugger.getValue(variablePath); assertEquals(value.getString(), "0"); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 06f8ed8712c..e6d5ccb32bd 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -451,7 +451,6 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException if (ch instanceof JdiField) { JdiField f = (JdiField)ch; variables.add(new FieldImpl(f.getName(), - true, new SimpleValueImpl(f.getValue().getString()), f.getType(), f.isPrimitive(), @@ -466,8 +465,7 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException ch.getName(), new SimpleValueImpl(ch.getValue().getString()), ch.isPrimitive(), - chPath, - true)); + chPath)); } } return new SimpleValueImpl(variables, variable.getValue().getString()); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java index e32bb9e5e9c..15781d4ba15 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java @@ -38,11 +38,6 @@ public String getName() { return name; } - @Override - public boolean isExistInformation() { - return !getValue().isPrimitive(); - } - @Override public boolean isPrimitive() { return value instanceof PrimitiveValue; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java index 687c390f0a9..793e8714c4d 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java @@ -43,11 +43,6 @@ public String getName() { return field.name(); } - @Override - public boolean isExistInformation() { - return !isPrimitive(); - } - @Override public boolean isIsStatic() { return field.isStatic(); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java index bfb7f8d8209..1a0f9ab739c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java @@ -32,14 +32,4 @@ public List getVariables() { public JdiVariable getVariableByName(String name) { return null; } - - @Override - public boolean isArray() { - return false; - } - - @Override - public boolean isPrimitive() { - return true; - } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java index e6319ef6098..f74e882edfc 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java @@ -37,14 +37,4 @@ public interface JdiValue extends SimpleValue { */ @Nullable JdiVariable getVariableByName(String name); - - /** - * Indicates if value is an array. - */ - boolean isArray(); - - /** - * Indicates if value is a primitive type. - */ - boolean isPrimitive(); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java index 75586cd193f..8d6d3ac6ba3 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java @@ -78,12 +78,10 @@ public JdiVariable getVariableByName(String name) { return null; } - @Override public boolean isArray() { return value instanceof ArrayReference; } - @Override public boolean isPrimitive() { return value instanceof PrimitiveValue; } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java index a736152d953..6c463c00448 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java @@ -32,11 +32,6 @@ public JdiVariableImpl(StackFrame stackFrame, LocalVariable variable) { this.variable = variable; } - @Override - public boolean isExistInformation() { - return !isPrimitive(); - } - @Override public String getName() { return variable.name(); diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java index ce0e4ebe7c6..f383fcfd684 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/variables/ZendDbgVariable.java @@ -44,11 +44,6 @@ public ZendDbgVariable(VariablePath variablePath, IDbgExpression zendDbgExpressi this.isComplete = zendDbgExpression.getChildrenCount() == zendDbgExpression.getChildren().size(); } - @Override - public boolean isExistInformation() { - return true; - } - @Override public String getName() { return name; diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java index 3ad8d27b8b9..e7a481cf7a3 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/ZendDbgSessionTest.java @@ -186,16 +186,14 @@ public void testSetValue() throws Exception { null, new SimpleValueImpl("123"), false, - new VariablePathImpl(String.valueOf(lastVar)), - false); + new VariablePathImpl(String.valueOf(lastVar))); debugger.setValue(variableToFind); assertEquals(stackFrameDump.getVariables().get(lastVar).getValue().getString(), "123"); variableToFind = new VariableImpl(null, null, new SimpleValueImpl("\"ABC\""), false, - new VariablePathImpl(String.valueOf(lastVar)), - false); + new VariablePathImpl(String.valueOf(lastVar))); debugger.setValue(variableToFind); assertEquals(stackFrameDump.getVariables().get(lastVar).getValue().getString(), "\"ABC\""); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java index 1e22601c564..e89b71ea546 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/FieldDto.java @@ -46,12 +46,6 @@ public interface FieldDto extends Field { FieldDto withName(String name); - boolean isExistInformation(); - - void setExistInformation(boolean existInformation); - - FieldDto withExistInformation(boolean existInformation); - SimpleValueDto getValue(); void setValue(SimpleValueDto value); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java index 39b95cefba2..87301cd8449 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/VariableDto.java @@ -22,12 +22,6 @@ public interface VariableDto extends Variable { VariableDto withName(String name); - boolean isExistInformation(); - - void setExistInformation(boolean existInformation); - - VariableDto withExistInformation(boolean existInformation); - SimpleValueDto getValue(); void setValue(SimpleValueDto value); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java index 056466cf468..1f8876f85d2 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Variable.java @@ -19,8 +19,6 @@ public interface Variable { */ String getName(); - boolean isExistInformation(); - /** * The variable value. */ diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java index cba5d25be41..c3ed56ad3df 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/FieldImpl.java @@ -24,7 +24,6 @@ public class FieldImpl extends VariableImpl implements Field { private boolean isVolatile; public FieldImpl(String name, - boolean isExistInformation, SimpleValue value, String type, boolean isPrimitive, @@ -33,7 +32,7 @@ public FieldImpl(String name, boolean isStatic, boolean isTransient, boolean isVolatile) { - super(type, name, value, isPrimitive, variablePath, isExistInformation); + super(type, name, value, isPrimitive, variablePath); this.isFinal = isFinal; this.isStatic = isStatic; this.isTransient = isTransient; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java index 1631a5f4165..2ed626d174a 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java @@ -24,7 +24,6 @@ */ public class MutableVariableImpl implements MutableVariable { private final String name; - private final boolean isExistInformation; private final String type; private final boolean isPrimitive; private final VariablePath variablePath; @@ -37,10 +36,8 @@ public MutableVariableImpl(String type, SimpleValue value, VariablePath variablePath, boolean isPrimitive, - List variables, - boolean isExistInformation) { + List variables) { this.name = name; - this.isExistInformation = isExistInformation; this.value = value; this.type = type; this.isPrimitive = isPrimitive; @@ -49,7 +46,7 @@ public MutableVariableImpl(String type, } public MutableVariableImpl() { - this(null, null, null, null, false, null, false); + this(null, null, null, null, false, null); } @Override @@ -57,10 +54,6 @@ public String getName() { return name; } - public boolean isExistInformation() { - return isExistInformation; - } - @Override public SimpleValue getValue() { return value; @@ -103,7 +96,6 @@ public boolean equals(Object o) { MutableVariableImpl variable = (MutableVariableImpl)o; - if (isExistInformation != variable.isExistInformation) return false; if (isPrimitive != variable.isPrimitive) return false; if (name != null ? !name.equals(variable.name) : variable.name != null) return false; if (value != null ? !value.equals(variable.value) : variable.value != null) return false; @@ -115,7 +107,6 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; - result = 31 * result + (isExistInformation ? 1 : 0); result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (isPrimitive ? 1 : 0); @@ -130,8 +121,7 @@ private static MutableVariable toMutable(Variable variable) { variable.getValue(), variable.getVariablePath(), variable.isPrimitive(), - variable.getValue().getVariables(), - variable.isExistInformation()); + variable.getValue().getVariables()); } private static List toMutable(List variables) { diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java index 648ec11905b..72f13c99785 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/VariableImpl.java @@ -19,7 +19,6 @@ */ public class VariableImpl implements Variable { private final String name; - private final boolean isExistInformation; private final SimpleValue value; private final String type; private final boolean isPrimitive; @@ -29,10 +28,8 @@ public VariableImpl(String type, String name, SimpleValue value, boolean isPrimitive, - VariablePath variablePath, - boolean isExistInformation) { + VariablePath variablePath) { this.name = name; - this.isExistInformation = isExistInformation; this.value = value; this.type = type; this.isPrimitive = isPrimitive; @@ -40,7 +37,7 @@ public VariableImpl(String type, } public VariableImpl(SimpleValue value, VariablePath variablePath) { - this(null, null, value, false, variablePath, false); + this(null, null, value, false, variablePath); } @Override @@ -48,10 +45,6 @@ public String getName() { return name; } - public boolean isExistInformation() { - return isExistInformation; - } - @Override public SimpleValue getValue() { return value; @@ -79,7 +72,6 @@ public boolean equals(Object o) { VariableImpl variable = (VariableImpl)o; - if (isExistInformation != variable.isExistInformation) return false; if (isPrimitive != variable.isPrimitive) return false; if (name != null ? !name.equals(variable.name) : variable.name != null) return false; if (value != null ? !value.equals(variable.value) : variable.value != null) return false; @@ -90,7 +82,6 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = name != null ? name.hashCode() : 0; - result = 31 * result + (isExistInformation ? 1 : 0); result = 31 * result + (value != null ? value.hashCode() : 0); result = 31 * result + (type != null ? type.hashCode() : 0); result = 31 * result + (isPrimitive ? 1 : 0); diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 835466f1a15..6f8cc772f7a 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -97,7 +97,6 @@ public static SimpleValueDto asDto(SimpleValue value) { public static FieldDto asDto(Field field) { return newDto(FieldDto.class).withType(field.getType()) - .withExistInformation(field.isExistInformation()) .withName(field.getName()) .withPrimitive(field.isPrimitive()) .withValue(asDto(field.getValue())) @@ -132,7 +131,6 @@ public static List variablesAsDtos(List variabl public static VariableDto asDto(Variable variable) { return newDto(VariableDto.class).withType(variable.getType()) - .withExistInformation(variable.isExistInformation()) .withName(variable.getName()) .withPrimitive(variable.isPrimitive()) .withValue(asDto(variable.getValue())) From c91483c99b835e0f77cec2b868d4ded9eccd43f8 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Tue, 17 Jan 2017 14:08:57 +0200 Subject: [PATCH 06/38] Introduce ThreadDump data model --- .../jdb/server/utils/JavaDebuggerUtils.java | 4 +- .../zdb/server/ZendDbgLocationHandler.java | 18 ++- .../che/api/debug/shared/dto/LocationDto.java | 11 +- .../che/api/debug/shared/dto/MethodDto.java | 36 ++++++ .../api/debug/shared/dto/ThreadDumpDto.java | 59 ++++++++++ .../che/api/debug/shared/model/Location.java | 8 ++ .../che/api/debug/shared/model/Method.java | 29 +++++ .../api/debug/shared/model/ThreadDump.java | 47 ++++++++ .../api/debug/shared/model/ThreadStatus.java | 21 ++++ .../debug/shared/model/impl/LocationImpl.java | 32 +++--- .../debug/shared/model/impl/MethodImpl.java | 69 ++++++++++++ .../shared/model/impl/ThreadDumpImpl.java | 104 ++++++++++++++++++ .../che/api/debugger/server/DtoConverter.java | 30 ++++- 13 files changed, 439 insertions(+), 29 deletions(-) create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Method.java create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java create mode 100644 wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java index 3e889479557..41753a486fc 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java @@ -81,12 +81,12 @@ public Location getLocation(com.sun.jdi.Location location) throws DebuggerExcept if (type.isBinary()) { IClassFile classFile = type.getClassFile(); int libId = classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode(); - return new LocationImpl(fqn, location.lineNumber(), null, true, libId, typeProjectPath); + return new LocationImpl(fqn, location.lineNumber(), null, true, libId, typeProjectPath, null); } else { ICompilationUnit compilationUnit = type.getCompilationUnit(); typeProjectPath = type.getJavaProject().getPath().toOSString(); String resourcePath = compilationUnit.getPath().toOSString(); - return new LocationImpl(fqn, location.lineNumber(), resourcePath, false, -1, typeProjectPath); + return new LocationImpl(fqn, location.lineNumber(), resourcePath, false, -1, typeProjectPath, null); } } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java index 901fcf35c45..4172cef9205 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java @@ -25,18 +25,17 @@ */ public class ZendDbgLocationHandler { - public static final Location createVFS(String target, String resourcePath, String resourceProjectPath, - int lineNumber) { - return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath); + public static final Location createVFS(String target, String resourcePath, String resourceProjectPath, int lineNumber) { + return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath, null); } public static final Location createDBG(String resourcePath, int lineNumber) { - return new LocationImpl(Path.of(resourcePath).getName(), lineNumber, resourcePath, false, 0, null); + return new LocationImpl(Path.of(resourcePath).getName(), lineNumber, resourcePath, false, 0, null, null); } /** * Convert DBG specific location to VFS one. - * + * * @param dbgLocation * @return VFS specific location. */ @@ -49,19 +48,18 @@ public Location convertToVFS(Location dbgLocation) { String target = localFileEntry.getName(); String resourcePath = localFileEntry.getPath().toString(); int lineNumber = dbgLocation.getLineNumber(); - return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath); + return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath, dbgLocation.getMethod()); } /** * Convert VFS specific location to DBG one. - * - * @param dbgLocation + * + * @param vfsLocation * @return DBG specific location. */ public Location convertToDBG(Location vfsLocation) { String resourcePath = ZendDbgFileUtils.findAbsolutePath(vfsLocation.getResourcePath()); int lineNumber = vfsLocation.getLineNumber(); - return new LocationImpl(null, lineNumber, resourcePath, false, 0, null); + return new LocationImpl(null, lineNumber, resourcePath, false, 0, null, vfsLocation.getMethod()); } - } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java index 742c471f1c8..1315a1364f3 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java @@ -13,7 +13,9 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.dto.shared.DTO; -/** @author andrew00x */ +/** + * @author Anatolii Bazko + */ @DTO public interface LocationDto extends Location { void setTarget(String target); @@ -39,4 +41,11 @@ public interface LocationDto extends Location { void setResourceProjectPath(String resourceProjectPath); LocationDto withResourceProjectPath(String resourceProjectPath); + + @Override + MethodDto getMethod(); + + void setMethod(MethodDto method); + + LocationDto withMethod(MethodDto method); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java new file mode 100644 index 00000000000..d8d7286ba41 --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.dto; + +import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.dto.shared.DTO; + +import java.util.List; + +/** + * @author Anatolii Bazko + */ +@DTO +public interface MethodDto extends Method { + @Override + String getName(); + + void setName(String name); + + MethodDto withName(String name); + + @Override + List getArguments(); + + void setArguments(List arguments); + + MethodDto withArguments(List arguments); +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java new file mode 100644 index 00000000000..85ab0232ab2 --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.dto; + +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadStatus; +import org.eclipse.che.dto.shared.DTO; + +import java.util.List; + +/** + * @author Anatolii Bazko + */ +@DTO +public interface ThreadDumpDto extends ThreadDump { + + @Override + String getName(); + + void setName(String name); + + ThreadDumpDto withName(String name); + + @Override + String getGroupName(); + + void setGroupName(String groupName); + + ThreadDumpDto withGroupName(String groupName); + + @Override + List getFrames(); + + void setFrames(List frames); + + ThreadDumpDto withFrames(List frames); + + @Override + ThreadStatus getStatus(); + + void setStatus(ThreadStatus status); + + ThreadDumpDto withStatus(ThreadStatus status); + + @Override + boolean isSuspended(); + + void setSuspended(boolean suspended); + + ThreadDumpDto withSuspended(boolean suspended); +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java index f9906d34b48..449f1b0c469 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.che.api.debug.shared.model; +import org.eclipse.che.commons.annotation.Nullable; + /** * @author Anatoliy Bazko */ @@ -43,4 +45,10 @@ public interface Location { * Returns project path, for resource which we are debugging now. */ String getResourceProjectPath(); + + /** + * Returns the method is being executed. + */ + @Nullable + Method getMethod(); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Method.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Method.java new file mode 100644 index 00000000000..48b5695b30a --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Method.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.model; + +import java.util.List; + +/** + * @author Anatolii Bazko + */ +public interface Method { + + /** + * Returns the name of the method. + */ + String getName(); + + /** + * Returns the list of the arguments. + */ + List getArguments(); +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java new file mode 100644 index 00000000000..5eedb6a3b2a --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.model; + +import org.eclipse.che.commons.annotation.Nullable; + +import java.util.List; + +/** + * @author Anatoliy Bazko + */ +public interface ThreadDump { + + /** + * Returns thread name. + */ + String getName(); + + /** + * Returns thread group name. + */ + @Nullable + String getGroupName(); + + /** + * Returns list of frames of the thread. + */ + List getFrames(); + + /** + * Returns thread state. + */ + ThreadStatus getStatus(); + + /** + * Indicates if thread is suspended. + */ + boolean isSuspended(); +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java new file mode 100644 index 00000000000..b01d895cc9e --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.model; + +/** + * @author Anatolii Bazko + */ +public enum ThreadStatus { + RUNNABLE, + BLOCKED, + WAITING, + TIMED_WAITING +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java index 01c00243437..10f14a909fa 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java @@ -11,6 +11,7 @@ package org.eclipse.che.api.debug.shared.model.impl; import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.Method; import java.util.Objects; @@ -24,27 +25,30 @@ public class LocationImpl implements Location { private final boolean externalResource; private final int externalResourceId; private final String resourceProjectPath; + private final Method method; public LocationImpl(String target, int lineNumber, String resourcePath, boolean externalResource, int externalResourceId, - String resourceProjectPath) { + String resourceProjectPath, + Method method) { this.target = target; this.lineNumber = lineNumber; this.resourcePath = resourcePath; this.externalResource = externalResource; this.externalResourceId = externalResourceId; this.resourceProjectPath = resourceProjectPath; + this.method = method; } public LocationImpl(String target, int lineNumber) { - this(target, lineNumber, null, false, 0, null); + this(target, lineNumber, null, false, 0, null, null); } public LocationImpl(String target) { - this(target, 0, null, false, 0, null); + this(target, 0, null, false, 0, null, null); } @Override @@ -77,31 +81,28 @@ public String getResourceProjectPath() { return resourceProjectPath; } + @Override + public Method getMethod() { + return method; + } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof LocationImpl)) return false; - LocationImpl location = (LocationImpl)o; - return lineNumber == location.lineNumber && - externalResourceId == location.externalResourceId && externalResource == location.externalResource && - Objects.equals(resourcePath ,location.resourcePath) && + externalResourceId == location.externalResourceId && + Objects.equals(target, location.target) && + Objects.equals(resourcePath, location.resourcePath) && Objects.equals(resourceProjectPath, location.resourceProjectPath) && - !(target != null ? !target.equals(location.target) : location.target != null); + Objects.equals(method, location.method); } @Override public int hashCode() { - int result = target != null ? target.hashCode() : 0; - result = 31 * result + lineNumber; - result = 31 * result + externalResourceId; - result = 31 * result + Objects.hashCode(resourcePath); - result = 31 * result + (externalResource ? 1 : 0); - result = 31 * result + Objects.hashCode(resourceProjectPath); - return result; + return Objects.hash(target, lineNumber, resourcePath, externalResource, externalResourceId, resourceProjectPath, method); } @Override @@ -113,6 +114,7 @@ public String toString() { ", externalResource=" + externalResource + ", externalResourceId=" + externalResourceId + ", resourceProjectPath='" + resourceProjectPath + '\'' + + ", method=" + method + '}'; } } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java new file mode 100644 index 00000000000..59a48659d4d --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.model.impl; + +import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.api.debug.shared.model.Variable; + +import java.util.List; +import java.util.Objects; + +/** + * @author Anatolii Bazko + */ +public class MethodImpl implements Method { + private final String name; + private final List arguments; + + public MethodImpl(String name, List arguments) { + this.name = name; + this.arguments = arguments; + } + + @Override + public String getName() { + return name; + } + + @Override + public List getArguments() { + return arguments; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof MethodImpl)) { + return false; + } + final MethodImpl that = (MethodImpl)obj; + return Objects.equals(name, that.name) + && getArguments().equals(that.getArguments()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + Objects.hashCode(name); + hash = 31 * hash + getArguments().hashCode(); + return hash; + } + + @Override + public String toString() { + return "MethodImpl{" + + "name='" + name + '\'' + + ", arguments=" + arguments + + '}'; + } +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java new file mode 100644 index 00000000000..d904733030a --- /dev/null +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.api.debug.shared.model.impl; + +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadStatus; + +import java.util.List; +import java.util.Objects; + +/** + * @author Anatolii Bazko + */ +public class ThreadDumpImpl implements ThreadDump { + private final String name; + private final String groupName; + private final ThreadStatus status; + private final boolean isSuspended; + private final List frames; + + public ThreadDumpImpl(String name, + String groupName, + ThreadStatus status, + boolean isSuspended, + List frames) { + this.name = name; + this.groupName = groupName; + this.status = status; + this.isSuspended = isSuspended; + this.frames = frames; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getGroupName() { + return groupName; + } + + @Override + public ThreadStatus getStatus() { + return status; + } + + @Override + public boolean isSuspended() { + return isSuspended; + } + + @Override + public List getFrames() { + return frames; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof ThreadDumpImpl)) { + return false; + } + final ThreadDumpImpl that = (ThreadDumpImpl)obj; + return isSuspended == that.isSuspended + && Objects.equals(name, that.name) + && Objects.equals(groupName, that.groupName) + && Objects.equals(status, that.status) + && getFrames().equals(that.getFrames()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + Objects.hashCode(name); + hash = 31 * hash + Objects.hashCode(groupName); + hash = 31 * hash + Objects.hashCode(status); + hash = 31 * hash + Boolean.hashCode(isSuspended); + hash = 31 * hash + getFrames().hashCode(); + return hash; + } + + @Override + public String toString() { + return "ThreadDumpImpl{" + + "name='" + name + '\'' + + ", groupName='" + groupName + '\'' + + ", status=" + status + + ", isSuspended=" + isSuspended + + ", frames=" + frames + + '}'; + } +} diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 6f8cc772f7a..64c17448a65 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -16,8 +16,10 @@ import org.eclipse.che.api.debug.shared.dto.DebuggerInfoDto; import org.eclipse.che.api.debug.shared.dto.FieldDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; +import org.eclipse.che.api.debug.shared.dto.MethodDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; import org.eclipse.che.api.debug.shared.dto.event.BreakpointActivatedEventDto; @@ -29,8 +31,10 @@ import org.eclipse.che.api.debug.shared.model.DebuggerInfo; import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.Method; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; @@ -81,13 +85,19 @@ public static List breakpointsAsDtos(List breakpoints return dtos; } + public static MethodDto asDto(Method method) { + return newDto(MethodDto.class).withName(method.getName()) + .withArguments(variablesAsDtos(method.getArguments())); + } + public static LocationDto asDto(Location location) { return newDto(LocationDto.class).withTarget(location.getTarget()) .withLineNumber(location.getLineNumber()) .withExternalResourceId(location.getExternalResourceId()) .withResourcePath(location.getResourcePath()) .withResourceProjectPath(location.getResourceProjectPath()) - .withExternalResource(location.isExternalResource()); + .withExternalResource(location.isExternalResource()) + .withMethod(asDto(location.getMethod())); } public static SimpleValueDto asDto(SimpleValue value) { @@ -162,6 +172,24 @@ public static DebuggerEventDto asDto(DebuggerEvent debuggerEvent) { } } + public static List framesAsDtos(List frames) { + List dtos = new LinkedList<>(); + + if (frames != null) { + for (int i = 0; i < frames.size(); i++) { + dtos.add(asDto(frames.get(i))); + } + } + return dtos; + } + + public static ThreadDumpDto asDto(ThreadDump threadDump) { + return newDto(ThreadDumpDto.class).withName(threadDump.getName()) + .withGroupName(threadDump.getGroupName()) + .withSuspended(threadDump.isSuspended()) + .withStatus(threadDump.getStatus()) + .withFrames(framesAsDtos(threadDump.getFrames())); + } private DtoConverter() {} } From 7bb0d146974d03b5e5639e678bdd73ba7c74f2e0 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 18 Jan 2017 09:20:04 +0200 Subject: [PATCH 07/38] JDB threaddumps --- .../ide/api/debug/DebuggerServiceClient.java | 9 ++ .../api/debug/DebuggerServiceClientImpl.java | 8 ++ .../che/plugin/jdb/server/JavaDebugger.java | 46 ++++++++-- .../plugin/jdb/server/jdi/JdiLocation.java | 19 +++++ .../jdb/server/jdi/JdiLocationImpl.java | 85 +++++++++++++++++++ .../che/plugin/jdb/server/jdi/JdiMethod.java | 23 +++++ .../plugin/jdb/server/jdi/JdiMethodImpl.java | 67 +++++++++++++++ .../plugin/jdb/server/jdi/JdiStackFrame.java | 4 + .../jdb/server/jdi/JdiStackFrameImpl.java | 16 +++- .../jdb/server/jdi/JdiVariableImpl.java | 24 +++--- .../plugin/jdb/server/JavaDebuggerTest.java | 75 +++++++++++++--- .../debug/shared/dto/StackFrameDumpDto.java | 10 +++ .../debug/shared/model/StackFrameDump.java | 8 ++ .../api/debug/shared/model/ThreadStatus.java | 3 +- .../shared/model/impl/StackFrameDumpImpl.java | 41 ++++++--- .../che/api/debugger/server/Debugger.java | 13 +++ .../api/debugger/server/DebuggerService.java | 17 +++- .../che/api/debugger/server/DtoConverter.java | 14 ++- 18 files changed, 436 insertions(+), 46 deletions(-) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java index b679530d203..150cb67e04c 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java @@ -15,6 +15,7 @@ import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; import org.eclipse.che.api.debug.shared.dto.action.StartActionDto; @@ -126,6 +127,14 @@ public interface DebuggerServiceClient { */ Promise getStackFrameDump(String id); + /** + * Gets thread dumps. + * + * @param id + * debug session id + */ + Promise> getThreadDumps(String id); + /** * Resumes application. * diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java index 9d657914d12..8be4fddd247 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java @@ -19,6 +19,7 @@ import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ActionDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; @@ -132,6 +133,13 @@ public Promise getStackFrameDump(String id) { .send(dtoUnmarshallerFactory.newUnmarshaller(StackFrameDumpDto.class)); } + @Override + public Promise> getThreadDumps(String id) { + final String requestUrl = getBaseUrl(id) + "/threaddumps"; + return asyncRequestFactory.createGetRequest(requestUrl) + .send(dtoUnmarshallerFactory.newListUnmarshaller(ThreadDumpDto.class)); + } + @Override public Promise resume(String id, ResumeActionDto action) { return performAction(id, action); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index e6d5ccb32bd..3be853852d5 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -10,12 +10,15 @@ *******************************************************************************/ package org.eclipse.che.plugin.jdb.server; +import sun.misc.VM; + import com.sun.jdi.AbsentInformationException; import com.sun.jdi.Bootstrap; import com.sun.jdi.ClassNotPreparedException; import com.sun.jdi.IncompatibleThreadStateException; import com.sun.jdi.NativeMethodException; import com.sun.jdi.ReferenceType; +import com.sun.jdi.StackFrame; import com.sun.jdi.ThreadReference; import com.sun.jdi.VMCannotBeModifiedException; import com.sun.jdi.VirtualMachine; @@ -38,6 +41,8 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.action.ResumeAction; @@ -48,9 +53,9 @@ import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.DebuggerInfoImpl; import org.eclipse.che.api.debug.shared.model.impl.FieldImpl; -import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl; +import org.eclipse.che.api.debug.shared.model.impl.ThreadDumpImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.DisconnectEventImpl; @@ -61,6 +66,7 @@ import org.eclipse.che.plugin.jdb.server.expression.ExpressionException; import org.eclipse.che.plugin.jdb.server.expression.ExpressionParser; import org.eclipse.che.plugin.jdb.server.jdi.JdiField; +import org.eclipse.che.plugin.jdb.server.jdi.JdiLocationImpl; import org.eclipse.che.plugin.jdb.server.jdi.JdiStackFrame; import org.eclipse.che.plugin.jdb.server.jdi.JdiStackFrameImpl; import org.eclipse.che.plugin.jdb.server.jdi.JdiVariable; @@ -73,6 +79,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -371,6 +378,36 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { } } + @Override + public List getThreadDumps() throws DebuggerException { + List threadRefs = vm.allThreads(); + List threadDumps = new ArrayList<>(threadRefs.size()); + + for (ThreadReference t : threadRefs) { + ThreadStatus status = ThreadStatus.UNKNOWN; + try { + status = ThreadStatus.valueOf(VM.toThreadState(t.status()).toString()); + } catch (IllegalArgumentException ignored) { + } + + List frames = new LinkedList<>(); + try { + for (StackFrame sf : t.frames()) { + frames.add(new JdiStackFrameImpl(sf)); + } + } catch (IncompatibleThreadStateException ignored) { + } + + threadDumps.add(new ThreadDumpImpl(t.name(), + t.threadGroup().name(), + status, + t.isSuspended(), + frames)); + } + + return threadDumps; + } + /** * Get value of variable with specified path. Each item in path is name of variable. *

    @@ -542,11 +579,10 @@ private boolean processBreakPointEvent(com.sun.jdi.event.BreakpointEvent event) Location location; try { - location = debuggerUtil.getLocation(jdiLocation); - } catch (DebuggerException e) { - location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber()); + location = new JdiLocationImpl(event.thread().frame(0)); + } catch (IncompatibleThreadStateException e) { + location = new JdiLocationImpl(jdiLocation); } - debuggerCallback.onEvent(new SuspendEventImpl(location)); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java new file mode 100644 index 00000000000..2542f21fca8 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.jdi; + +import org.eclipse.che.api.debug.shared.model.Location; + +/** + * @author Anatolii Bazko + */ +public interface JdiLocation extends Location { +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java new file mode 100644 index 00000000000..125346493b7 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.jdi; + +import com.sun.jdi.StackFrame; + +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.plugin.jdb.server.utils.JavaDebuggerUtils; + +/** + * @author Anatolii Bazko + */ +public class JdiLocationImpl implements JdiLocation { + private static final JavaDebuggerUtils debuggerUtil = new JavaDebuggerUtils(); + + private final Method method; + private final Location location; + + public JdiLocationImpl(StackFrame stackFrame) { + com.sun.jdi.Location jdiLocation = stackFrame.location(); + this.location = findLocation(jdiLocation); + this.method = new JdiMethodImpl(stackFrame, jdiLocation.method()); + } + + public JdiLocationImpl(com.sun.jdi.Location jdiLocation) { + this.location = findLocation(jdiLocation); + this.method = new JdiMethodImpl(jdiLocation.method()); + } + + @Override + public String getTarget() { + return location.getTarget(); + } + + @Override + public int getLineNumber() { + return location.getLineNumber(); + } + + @Override + public String getResourcePath() { + return location.getResourcePath(); + } + + @Override + public boolean isExternalResource() { + return location.isExternalResource(); + } + + @Override + public int getExternalResourceId() { + return location.getExternalResourceId(); + } + + @Override + public String getResourceProjectPath() { + return location.getResourceProjectPath(); + } + + @Override + public Method getMethod() { + return method; + } + + private Location findLocation(com.sun.jdi.Location jdiLocation) { + Location location; + try { + location = debuggerUtil.getLocation(jdiLocation); + } catch (DebuggerException e) { + location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber()); + } + return location; + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java new file mode 100644 index 00000000000..71410fa15b7 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.jdi; + +import org.eclipse.che.api.debug.shared.model.Method; + +import java.util.List; + +/** + * @author Anatolii Bazko + */ +public interface JdiMethod extends Method { + @Override + List getArguments(); +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java new file mode 100644 index 00000000000..4f01ef74c8c --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.jdi; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.Method; +import com.sun.jdi.StackFrame; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author Anatolii Bazko + */ +public class JdiMethodImpl implements JdiMethod { + private final String name; + private final List arguments; + + public JdiMethodImpl(StackFrame stackFrame, Method method) { + this.name = method.name(); + + List args; + try { + args = method.arguments() + .stream() + .map(v -> new JdiVariableImpl(stackFrame, v)) + .collect(Collectors.toList()); + } catch (AbsentInformationException e) { + args = Collections.emptyList(); + } + this.arguments = args; + } + + public JdiMethodImpl(Method method) { + this.name = method.name(); + + List args; + try { + args = method.arguments() + .stream() + .map(JdiVariableImpl::new) + .collect(Collectors.toList()); + } catch (AbsentInformationException e) { + args = Collections.emptyList(); + } + this.arguments = args; + } + + @Override + public String getName() { + return name; + } + + @Override + public List getArguments() { + return arguments; + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java index 5bc03162409..00911144049 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java @@ -21,6 +21,7 @@ * @author andrew00x */ public interface JdiStackFrame extends StackFrameDump { + /** * Get all available instance or class members. * @@ -51,4 +52,7 @@ public interface JdiStackFrame extends StackFrameDump { */ @Nullable JdiVariable getVariableByName(String name); + + @Override + JdiLocation getLocation(); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java index 85d39e3e5ec..32ad86ed279 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java @@ -28,9 +28,11 @@ * @author Anatolii Bazko */ public class JdiStackFrameImpl implements JdiStackFrame { - private final StackFrame stackFrame; - private List fields; - private List variables; + private final StackFrame stackFrame; + + private List fields; + private List variables; + private JdiLocation jdiLocation; public JdiStackFrameImpl(StackFrame stackFrame) { this.stackFrame = stackFrame; @@ -104,4 +106,12 @@ public JdiVariable getVariableByName(String name) { return null; } + + @Override + public JdiLocation getLocation() { + if (jdiLocation == null) { + jdiLocation = new JdiLocationImpl(stackFrame); + } + return jdiLocation; + } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java index 6c463c00448..4b6c6365d85 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java @@ -20,16 +20,17 @@ /** @author andrew00x */ public class JdiVariableImpl implements JdiVariable { private final LocalVariable variable; - private final StackFrame stackFrame; + private final JdiValue jdiValue; - @Override - public VariablePath getVariablePath() { - return new VariablePathImpl(getName()); + public JdiVariableImpl(StackFrame stackFrame, LocalVariable variable) { + Value value = stackFrame.getValue(variable); + this.variable = variable; + this.jdiValue = value == null ? new JdiNullValue() : new JdiValueImpl(value); } - public JdiVariableImpl(StackFrame stackFrame, LocalVariable variable) { - this.stackFrame = stackFrame; + public JdiVariableImpl(LocalVariable variable) { this.variable = variable; + this.jdiValue = null; } @Override @@ -44,15 +45,16 @@ public boolean isPrimitive() { @Override public JdiValue getValue() { - Value value = stackFrame.getValue(variable); - if (value == null) { - return new JdiNullValue(); - } - return new JdiValueImpl(value); + return jdiValue; } @Override public String getType() { return variable.typeName(); } + + @Override + public VariablePath getVariablePath() { + return new VariablePathImpl(getName()); + } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index 236c1b3bfe5..84107bed192 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -17,8 +17,13 @@ import org.eclipse.che.api.core.notification.EventService; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; +import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; @@ -63,6 +68,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; @@ -84,7 +90,7 @@ public class JavaDebuggerTest { private BlockingQueue events; - @Test(priority = 1) + @Test(priority = 10) public void testGetInfo() throws Exception { DebuggerInfo info = debugger.getInfo(); @@ -95,7 +101,7 @@ public void testGetInfo() throws Exception { assertNotNull(info.getVersion()); } - @Test(priority = 2) + @Test(priority = 20) public void testStartDebugger() throws Exception { BreakpointImpl breakpoint = new BreakpointImpl(new LocationImpl("com.HelloWorld", 17), false, null); debugger.start(new StartActionImpl(singletonList(breakpoint))); @@ -111,7 +117,7 @@ public void testStartDebugger() throws Exception { assertEquals(location.getTarget(), "com.HelloWorld"); } - @Test(priority = 3) + @Test(priority = 30) public void testAddBreakpoint() throws Exception { int breakpointsCount = debugger.getAllBreakpoints().size(); @@ -128,18 +134,18 @@ public void testAddBreakpoint() throws Exception { assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount + 1); } - @Test(priority = 5, expectedExceptions = DebuggerException.class) + @Test(priority = 50, expectedExceptions = DebuggerException.class) public void testAddBreakpointToUnExistedLocation() throws Exception { debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 1), false, null)); } - @Test(priority = 6) + @Test(priority = 60) public void testRemoveBreakpoint() throws Exception { debugger.deleteBreakpoint(new LocationImpl("com.HelloWorld", 17)); assertEquals(debugger.getAllBreakpoints().size(), 1); } - @Test(priority = 7) + @Test(priority = 70) public void testRemoveUnExistedBreakpoint() throws Exception { int breakpointsCount = debugger.getAllBreakpoints().size(); @@ -148,7 +154,7 @@ public void testRemoveUnExistedBreakpoint() throws Exception { assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount); } - @Test(priority = 8) + @Test(priority = 80) public void testGetAllBreakpoints() throws Exception { assertFalse(debugger.getAllBreakpoints().isEmpty()); @@ -169,7 +175,7 @@ public void testGetAllBreakpoints() throws Exception { assertTrue(breakpoint.isEnabled()); } - @Test(priority = 9) + @Test(priority = 90) public void testSteps() throws Exception { debugger.deleteAllBreakpoints(); @@ -229,14 +235,61 @@ public void testSteps() throws Exception { assertEquals(location.getLineNumber(), 24); } - @Test(priority = 10) + @Test(priority = 95) + public void testGetThreadDumps() throws Exception { + List threadDumps = debugger.getThreadDumps(); + + Optional mainThread = threadDumps.stream().filter(t -> t.getName().equals("main")).findAny(); + assertTrue(mainThread.isPresent()); + + ThreadDump threadDump = mainThread.get(); + assertEquals(threadDump.getName(), "main"); + assertEquals(threadDump.getGroupName(), "main"); + assertTrue(threadDump.isSuspended()); + assertEquals(threadDump.getStatus(), ThreadStatus.RUNNABLE); + + List frames = threadDump.getFrames(); + assertEquals(frames.size(), 1); + + StackFrameDump stackFrameDump = frames.get(0); + + List variables = stackFrameDump.getVariables(); + //TODO + List fields = stackFrameDump.getFields(); + //TODO + + Location location = stackFrameDump.getLocation(); + assertEquals(location.getLineNumber(), 24); + assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getExternalResourceId(), -1); + assertEquals(location.getResourceProjectPath(), "/test"); + assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java"); + + Method method = location.getMethod(); + assertEquals(method.getName(), "main"); + + List arguments = method.getArguments(); + assertEquals(arguments.size(), 1); + + Variable variable = arguments.get(0); + assertEquals(variable.getName(), "args"); + assertEquals(variable.getType(), "java.lang.String[]"); + assertEquals(variable.getVariablePath(), new VariablePathImpl("args")); + + //TODO + SimpleValue value = variable.getValue(); + //TODO + value.getString(); + } + + @Test(priority = 100) public void testEvaluateExpression() throws Exception { assertEquals(debugger.evaluate("2+2"), "4"); assertEquals(debugger.evaluate("\"hello\""), "\"hello\""); assertEquals(debugger.evaluate("test"), "\"hello\""); } - @Test(priority = 11) + @Test(priority = 110) public void testSetAndGetValue() throws Exception { assertEquals(debugger.getValue(new VariablePathImpl("test")).getString(), "\"hello\""); assertEquals(debugger.getValue(new VariablePathImpl("msg")).getString(), "\"Hello, debugger!\""); @@ -252,7 +305,7 @@ public void testSetAndGetValue() throws Exception { assertTrue(vars.contains("test")); } - @Test(priority = 12) + @Test(priority = 120) public void testDisconnect() throws Exception { debugger.disconnect(); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/StackFrameDumpDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/StackFrameDumpDto.java index 47aa3c069ac..d24faffd40e 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/StackFrameDumpDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/StackFrameDumpDto.java @@ -18,15 +18,25 @@ /** @author andrew00x */ @DTO public interface StackFrameDumpDto extends StackFrameDump { + @Override List getFields(); void setFields(List fields); StackFrameDumpDto withFields(List fields); + @Override List getVariables(); void setVariables(List variables); StackFrameDumpDto withVariables(List variables); + + @Override + LocationDto getLocation(); + + void setLocation(LocationDto location); + + StackFrameDumpDto withLocation(LocationDto location); + } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java index 7546a903fcb..d90d2514d3a 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.che.api.debug.shared.model; +import org.eclipse.che.commons.annotation.Nullable; + import java.util.List; /** @@ -25,4 +27,10 @@ public interface StackFrameDump { * The list of local variables. */ List getVariables(); + + /** + * Returns location of the frame. + */ + @Nullable + Location getLocation(); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java index b01d895cc9e..e45b2ae03f7 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java @@ -17,5 +17,6 @@ public enum ThreadStatus { RUNNABLE, BLOCKED, WAITING, - TIMED_WAITING + TIMED_WAITING, + UNKNOWN } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java index 0e626e8706b..9f419ffb85e 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java @@ -12,11 +12,13 @@ import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.model.Field; +import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; import java.util.Collections; import java.util.List; +import java.util.Objects; /** * @author Anatoliy Bazko @@ -24,14 +26,23 @@ public class StackFrameDumpImpl implements StackFrameDump { private final List fields; private final List variables; + private final Location location; - public StackFrameDumpImpl(List fields, List variables) { + public StackFrameDumpImpl(List fields, + List variables, + Location location) { this.fields = fields; this.variables = variables; + this.location = location; + } + + public StackFrameDumpImpl(List fields, + List variables) { + this(fields, variables, null); } public StackFrameDumpImpl(StackFrameDumpDto dto) { - this(dto.getFields(), dto.getVariables()); + this(dto.getFields(), dto.getVariables(), dto.getLocation()); } @Override @@ -44,22 +55,32 @@ public List getVariables() { return Collections.unmodifiableList(variables); } + @Override + public Location getLocation() { + return location; + } + @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof StackFrameDumpImpl)) return false; - StackFrameDumpImpl that = (StackFrameDumpImpl)o; - - if (fields != null ? !fields.equals(that.fields) : that.fields != null) return false; - return !(variables != null ? !variables.equals(that.variables) : that.variables != null); - + return Objects.equals(fields, that.fields) && + Objects.equals(variables, that.variables) && + Objects.equals(location, that.location); } @Override public int hashCode() { - int result = fields != null ? fields.hashCode() : 0; - result = 31 * result + (variables != null ? variables.hashCode() : 0); - return result; + return Objects.hash(fields, variables, location); + } + + @Override + public String toString() { + return "StackFrameDumpImpl{" + + "fields=" + fields + + ", variables=" + variables + + ", location=" + location + + '}'; } } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index bfa1df10eb3..231327d2142 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -11,6 +11,7 @@ package org.eclipse.che.api.debugger.server; import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; @@ -28,6 +29,7 @@ import org.eclipse.che.api.debug.shared.model.event.DisconnectEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; +import java.util.Collections; import java.util.List; /** @@ -202,6 +204,17 @@ default void suspend() throws DebuggerException { */ StackFrameDump dumpStackFrame() throws DebuggerException; + /** + * Gets thread dumps. + * + * @return {@link ThreadDump} + * @throws DebuggerException + * if any error occur + */ + default List getThreadDumps() throws DebuggerException { + return Collections.emptyList(); + } + /** * Is used to send back any events to client. */ diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index 4205b1f03eb..6dd656d1877 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -12,12 +12,11 @@ import com.google.inject.Inject; -import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerNotFoundException; import org.eclipse.che.api.debug.shared.dto.BreakpointDto; import org.eclipse.che.api.debug.shared.dto.DebugSessionDto; +import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ActionDto; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; @@ -30,6 +29,8 @@ import org.eclipse.che.api.debug.shared.model.action.StepOverAction; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerNotFoundException; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -49,8 +50,9 @@ import java.util.List; import java.util.Map; -import static org.eclipse.che.api.debugger.server.DtoConverter.breakpointsAsDtos; import static org.eclipse.che.api.debugger.server.DtoConverter.asDto; +import static org.eclipse.che.api.debugger.server.DtoConverter.breakpointsAsDtos; +import static org.eclipse.che.api.debugger.server.DtoConverter.dumpsAsDtos; import static org.eclipse.che.dto.server.DtoFactory.newDto; /** @@ -166,6 +168,13 @@ public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId) th return asDto(debuggerManager.getDebugger(sessionId).dumpStackFrame()); } + @GET + @Path("{id}/threaddumps") + @Produces(MediaType.APPLICATION_JSON) + public List getThreadDumps(@PathParam("id") String sessionId) throws DebuggerException { + return dumpsAsDtos(debuggerManager.getDebugger(sessionId).getThreadDumps()); + } + @GET @Path("{id}/value") @Produces(MediaType.APPLICATION_JSON) diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 64c17448a65..9445c17e77f 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -153,7 +153,8 @@ public static VariablePathDto asDto(VariablePath variablePath) { public static StackFrameDumpDto asDto(StackFrameDump stackFrameDump) { return newDto(StackFrameDumpDto.class).withVariables(variablesAsDtos(stackFrameDump.getVariables())) - .withFields(fieldsAsDtos(stackFrameDump.getFields())); + .withFields(fieldsAsDtos(stackFrameDump.getFields())) + .withLocation(asDto(stackFrameDump.getLocation())); } public static DebuggerEventDto asDto(DebuggerEvent debuggerEvent) { @@ -183,6 +184,17 @@ public static List framesAsDtos(List dumpsAsDtos(List dumps) { + List dtos = new LinkedList<>(); + + if (dumps != null) { + for (int i = 0; i < dumps.size(); i++) { + dtos.add(asDto(dumps.get(i))); + } + } + return dtos; + } + public static ThreadDumpDto asDto(ThreadDump threadDump) { return newDto(ThreadDumpDto.class).withName(threadDump.getName()) .withGroupName(threadDump.getGroupName()) From 42479fb894d5963bdb27538317a3ea6bb68011b2 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Tue, 13 Jun 2017 16:17:02 +0300 Subject: [PATCH 08/38] Fix up --- .../api/debug/DebuggerServiceClientImpl.java | 2 +- .../debugger/ide/debug/AbstractDebugger.java | 12 +- .../che-plugin-java-debugger-server/pom.xml | 41 ++-- .../che/plugin/jdb/server/JavaDebugger.java | 7 +- .../plugin/jdb/server/jdi/JdiValueImpl.java | 8 +- .../plugin/jdb/server/JavaDebuggerTest.java | 178 +----------------- .../plugin/jdb/server/ProjectApiUtils.java | 148 +++++++++++++++ .../che/plugin/jdb/server/ThreadDumpTest.java | 115 +++++++++++ .../JavaDebuggerIntegrationTestsSuite.xml | 22 +++ .../assembly.xml} | 10 +- .../src/test/resources/findbugs-exclude.xml | 3 +- .../src/test/resources/logback-test.xml | 2 - .../workspace/test/out/com/HelloWorld.class | Bin 975 -> 0 bytes .../test/src/org/eclipse/ThreadDumpTest.java | 45 +++++ .../api/debugger/server/DebuggerService.java | 22 ++- .../che/api/debugger/server/DtoConverter.java | 98 ++++------ 16 files changed, 448 insertions(+), 265 deletions(-) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/{docker-assembly.xml => docker/assembly.xml} (59%) delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/out/com/HelloWorld.class create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest.java diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java index 8be4fddd247..c3a540d2f10 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java @@ -135,7 +135,7 @@ public Promise getStackFrameDump(String id) { @Override public Promise> getThreadDumps(String id) { - final String requestUrl = getBaseUrl(id) + "/threaddumps"; + final String requestUrl = getBaseUrl(id) + "/threaddump"; return asyncRequestFactory.createGetRequest(requestUrl) .send(dtoUnmarshallerFactory.newListUnmarshaller(ThreadDumpDto.class)); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 98c906b6bdd..01ddc10bf62 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -309,7 +309,7 @@ public Promise getValue(Variable variable) { return Promises.reject(JsPromiseError.create("Debugger is not connected")); } - Promise promise = service.getValue(debugSessionDto.getId(), asDto(variable)); + Promise promise = service.getValue(debugSessionDto.getId(), toDto(variable)); return promise.then((Function)SimpleValueImpl::new); } @@ -589,7 +589,7 @@ public Promise evaluate(String expression) { @Override public void setValue(final Variable variable) { if (isConnected()) { - Promise promise = service.setValue(debugSessionDto.getId(), asDto(variable)); + Promise promise = service.setValue(debugSessionDto.getId(), toDto(variable)); promise.then(it -> { for (DebuggerObserver observer : observers) { @@ -689,26 +689,26 @@ protected void restoreDebuggerState() { } } - private List asDto(List variables) { + private List toDto(List variables) { if (variables == null || variables.isEmpty()) { return Collections.emptyList(); } List dtos = new ArrayList<>(variables.size()); for (Variable v : variables) { - dtos.add(asDto(v)); + dtos.add(toDto(v)); } return dtos; } - private VariableDto asDto(Variable variable) { + private VariableDto toDto(Variable variable) { SimpleValue simpleValue = variable.getValue(); VariablePath variablePath = variable.getVariablePath(); VariableDto dto = dtoFactory.createDto(VariableDto.class); dto.withValue(dtoFactory.createDto(SimpleValueDto.class) .withString(simpleValue.getString()) - .withVariables(asDto(simpleValue.getVariables()))); + .withVariables(toDto(simpleValue.getVariables()))); dto.withVariablePath(dtoFactory.createDto(VariablePathDto.class) .withPath(variablePath.getPath())); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml index 9bbc7087af2..9545436579d 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml @@ -11,7 +11,8 @@ Codenvy, S.A. - initial API and implementation --> - + 4.0.0 che-plugin-java-debugger-parent @@ -23,9 +24,7 @@ Che Plugin :: Java :: Java Debugger Server true - ${project.build.testSourceDirectory}/../resources/findbugs-exclude.xml - java-8-jdk:debugger - java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y -Xmx128m com.HelloWorld + ${project.build.testOutputDirectory}/findbugs-exclude.xml @@ -209,11 +208,29 @@ ${debug.port} - - **/JavaDebuggerTest.java - + + ${project.build.testOutputDirectory}/JavaDebuggerIntegrationTestsSuite.xml + + + org.apache.maven.plugins + maven-antrun-plugin + + + copy-sources + process-test-resources + + run + + + + + + + + + io.fabric8 docker-maven-plugin @@ -245,13 +262,16 @@ java - ${java.image.name} + java-8-jdk:debugger java:8-jdk - ${project.build.testOutputDirectory}/docker-assembly.xml + ${project.build.testOutputDirectory}/docker/assembly.xml maven + + ./entrypoint.sh + @@ -264,9 +284,6 @@ always - - ${run.cmd} - diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 3be853852d5..71ff8991649 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -327,7 +327,7 @@ public List getAllBreakpoints() throws DebuggerException { .withLocation(newDto(LocationDto.class).withTarget(location.declaringType().name()) .withLineNumber(location.lineNumber()))); } - Collections.sort(breakPoints, BREAKPOINT_COMPARATOR); + breakPoints.sort(BREAKPOINT_COMPARATOR); return breakPoints; } @@ -384,10 +384,11 @@ public List getThreadDumps() throws DebuggerException { List threadDumps = new ArrayList<>(threadRefs.size()); for (ThreadReference t : threadRefs) { - ThreadStatus status = ThreadStatus.UNKNOWN; + ThreadStatus status; try { status = ThreadStatus.valueOf(VM.toThreadState(t.status()).toString()); - } catch (IllegalArgumentException ignored) { + } catch (IllegalArgumentException e) { + status = ThreadStatus.UNKNOWN; } List frames = new LinkedList<>(); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java index 8d6d3ac6ba3..9215c6ac48b 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java @@ -23,12 +23,13 @@ /** @author andrew00x */ public class JdiValueImpl implements JdiValue { - private final Value value; - private List variables; + private final Value value; + + private List variables; public JdiValueImpl(Value value) { if (value == null) { - throw new IllegalArgumentException("Underlying value may not be null. "); + throw new IllegalArgumentException("Underlying value can not be null. "); } this.value = value; } @@ -70,6 +71,7 @@ public JdiVariable getVariableByName(String name) { if (name == null) { throw new IllegalArgumentException("Variable name may not be null. "); } + for (JdiVariable variable : getVariables()) { if (name.equals(variable.getName())) { return variable; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index 9ff43d994c5..14e73e0e56f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -12,18 +12,10 @@ import com.google.common.collect.ImmutableMap; -import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.core.model.project.ProjectConfig; -import org.eclipse.che.api.core.notification.EventService; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; -import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.Method; -import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; -import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; @@ -41,41 +33,16 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl; import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.eclipse.che.api.project.server.ProjectManager; -import org.eclipse.che.api.project.server.ProjectRegistry; -import org.eclipse.che.api.project.server.WorkspaceProjectsSyncer; -import org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry; -import org.eclipse.che.api.project.server.importer.ProjectImporterRegistry; -import org.eclipse.che.api.project.server.type.ProjectTypeRegistry; -import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler; -import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher; -import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler; -import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider; -import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider; -import org.eclipse.che.api.vfs.watcher.FileWatcherManager; -import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; -import org.eclipse.che.plugin.java.server.projecttype.JavaProjectType; -import org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jdt.internal.core.JavaModelManager; -import org.eclipse.jdt.internal.ui.JavaPlugin; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.io.File; -import java.nio.file.PathMatcher; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.stream.Collectors; import static java.util.Collections.singletonList; -import static org.mockito.Mockito.mock; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -89,6 +56,16 @@ public class JavaDebuggerTest { private Debugger debugger; private BlockingQueue events; + @BeforeClass + protected void setUp() throws Exception { + ProjectApiUtils.ensure(); + + events = new ArrayBlockingQueue<>(10); + Map connectionProperties = ImmutableMap.of("host", "localhost", + "port", System.getProperty("debug.port")); + JavaDebuggerFactory factory = new JavaDebuggerFactory(); + debugger = factory.create(connectionProperties, events::add); + } @Test(priority = 10) public void testGetInfo() throws Exception { @@ -235,53 +212,6 @@ public void testSteps() throws Exception { assertEquals(location.getLineNumber(), 24); } - @Test(priority = 95) - public void testGetThreadDumps() throws Exception { - List threadDumps = debugger.getThreadDumps(); - - Optional mainThread = threadDumps.stream().filter(t -> t.getName().equals("main")).findAny(); - assertTrue(mainThread.isPresent()); - - ThreadDump threadDump = mainThread.get(); - assertEquals(threadDump.getName(), "main"); - assertEquals(threadDump.getGroupName(), "main"); - assertTrue(threadDump.isSuspended()); - assertEquals(threadDump.getStatus(), ThreadStatus.RUNNABLE); - - List frames = threadDump.getFrames(); - assertEquals(frames.size(), 1); - - StackFrameDump stackFrameDump = frames.get(0); - - List variables = stackFrameDump.getVariables(); - //TODO - List fields = stackFrameDump.getFields(); - //TODO - - Location location = stackFrameDump.getLocation(); - assertEquals(location.getLineNumber(), 24); - assertEquals(location.getTarget(), "com.HelloWorld"); - assertEquals(location.getExternalResourceId(), -1); - assertEquals(location.getResourceProjectPath(), "/test"); - assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java"); - - Method method = location.getMethod(); - assertEquals(method.getName(), "main"); - - List arguments = method.getArguments(); - assertEquals(arguments.size(), 1); - - Variable variable = arguments.get(0); - assertEquals(variable.getName(), "args"); - assertEquals(variable.getType(), "java.lang.String[]"); - assertEquals(variable.getVariablePath(), new VariablePathImpl("args")); - - //TODO - SimpleValue value = variable.getValue(); - //TODO - value.getString(); - } - @Test(priority = 100) public void testEvaluateExpression() throws Exception { assertEquals(debugger.evaluate("2+2"), "4"); @@ -313,93 +243,5 @@ public void testDisconnect() throws Exception { assertTrue(debuggerEvent instanceof DisconnectEvent); } - @BeforeClass - protected void initProjectApi() throws Exception { - TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder(new ArrayList<>()); - File root = new File("target/test-classes/workspace"); - assertTrue(root.exists()); - - File indexDir = new File("target/fs_index"); - assertTrue(indexDir.mkdirs()); - - Set filters = new HashSet<>(); - filters.add(path -> true); - FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters); - - EventService eventService = new EventService(); - LocalVirtualFileSystemProvider vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider); - ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>()); - projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory())); - ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>()); - ProjectRegistry projectRegistry = new ProjectRegistry(workspaceHolder, - vfsProvider, - projectTypeRegistry, - projectHandlerRegistry, - eventService); - projectRegistry.initProjects(); - - ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>()); - FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider); - FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler); - ProjectManager projectManager = new ProjectManager(vfsProvider, - projectTypeRegistry, - projectRegistry, - projectHandlerRegistry, - importerRegistry, - fileWatcherNotificationHandler, - fileTreeWatcher, - workspaceHolder, - mock(FileWatcherManager.class)); - - ResourcesPlugin resourcesPlugin = - new ResourcesPlugin("target/index", - root.getAbsolutePath(), - () -> projectRegistry, - () -> projectManager); - resourcesPlugin.start(); - - JavaPlugin javaPlugin = new JavaPlugin(root.getAbsolutePath() + "/.settings", resourcesPlugin, projectRegistry); - javaPlugin.start(); - - projectRegistry.setProjectType("test", "java", false); - - JavaModelManager.getDeltaState().initializeRoots(true); - - events = new ArrayBlockingQueue<>(10); - Map connectionProperties = ImmutableMap.of("host", "localhost", - "port", System.getProperty("debug.port")); - JavaDebuggerFactory factory = new JavaDebuggerFactory(); - debugger = factory.create(connectionProperties, events::add); - } - - private static class TestWorkspaceHolder extends WorkspaceProjectsSyncer { - private List projects; - - TestWorkspaceHolder() { - this.projects = new ArrayList<>(); - } - - TestWorkspaceHolder(List projects) { - this.projects = projects; - } - @Override - public List getProjects() { - return projects; - } - - @Override - public String getWorkspaceId() { - return "id"; - } - - @Override - protected void addProject(ProjectConfig project) throws ServerException {} - - @Override - protected void updateProject(ProjectConfig project) throws ServerException {} - - @Override - protected void removeProject(ProjectConfig project) throws ServerException {} - } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java new file mode 100644 index 00000000000..b6cefaa80bc --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server; + +import org.eclipse.che.api.core.ServerException; +import org.eclipse.che.api.core.model.project.ProjectConfig; +import org.eclipse.che.api.core.notification.EventService; +import org.eclipse.che.api.project.server.ProjectManager; +import org.eclipse.che.api.project.server.ProjectRegistry; +import org.eclipse.che.api.project.server.WorkspaceProjectsSyncer; +import org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry; +import org.eclipse.che.api.project.server.importer.ProjectImporterRegistry; +import org.eclipse.che.api.project.server.type.ProjectTypeRegistry; +import org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler; +import org.eclipse.che.api.vfs.impl.file.FileTreeWatcher; +import org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler; +import org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider; +import org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider; +import org.eclipse.che.api.vfs.watcher.FileWatcherManager; +import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; +import org.eclipse.che.plugin.java.server.projecttype.JavaProjectType; +import org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.ui.JavaPlugin; + +import java.io.File; +import java.nio.file.PathMatcher; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.mockito.Mockito.mock; +import static org.testng.Assert.assertTrue; + +/** + * @author Anatolii Bazko + */ +public class ProjectApiUtils { + + private static final AtomicBoolean initialized = new AtomicBoolean(); + + /** + * Ensures that project api has been initialized only once. + */ + static void ensure() throws Exception { + if (!initialized.get()) { + synchronized (initialized) { + if (!initialized.get()) { + init(); + initialized.set(true); + } + } + } + } + + /** + * Initialize project API for tests. + */ + private static void init() throws Exception { + TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder(new ArrayList<>()); + File root = new File("target/test-classes/workspace"); + assertTrue(root.exists()); + + File indexDir = new File("target/fs_index"); + assertTrue(indexDir.mkdirs()); + + Set filters = new HashSet<>(); + filters.add(path -> true); + FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters); + + EventService eventService = new EventService(); + LocalVirtualFileSystemProvider vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider); + ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>()); + projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory())); + ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>()); + ProjectRegistry projectRegistry = new ProjectRegistry(workspaceHolder, + vfsProvider, + projectTypeRegistry, + projectHandlerRegistry, + eventService); + projectRegistry.initProjects(); + + ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>()); + FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider); + FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler); + ProjectManager projectManager = new ProjectManager(vfsProvider, + projectTypeRegistry, + projectRegistry, + projectHandlerRegistry, + importerRegistry, + fileWatcherNotificationHandler, + fileTreeWatcher, + workspaceHolder, + mock(FileWatcherManager.class)); + + ResourcesPlugin resourcesPlugin = + new ResourcesPlugin("target/index", + root.getAbsolutePath(), + () -> projectRegistry, + () -> projectManager); + resourcesPlugin.start(); + + JavaPlugin javaPlugin = new JavaPlugin(root.getAbsolutePath() + "/.settings", resourcesPlugin, projectRegistry); + javaPlugin.start(); + + projectRegistry.setProjectType("test", "java", false); + + JavaModelManager.getDeltaState().initializeRoots(true); + } + + private static class TestWorkspaceHolder extends WorkspaceProjectsSyncer { + private List projects; + + TestWorkspaceHolder(List projects) { + this.projects = projects; + } + + @Override + public List getProjects() { + return projects; + } + + @Override + public String getWorkspaceId() { + return "id"; + } + + @Override + protected void addProject(ProjectConfig project) throws ServerException {} + + @Override + protected void updateProject(ProjectConfig project) throws ServerException {} + + @Override + protected void removeProject(ProjectConfig project) throws ServerException {} + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java new file mode 100644 index 00000000000..d17ec3c94ae --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server; + +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.model.Field; +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadStatus; +import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; +import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl; +import org.eclipse.che.api.debugger.server.Debugger; +import org.eclipse.che.api.debugger.server.DtoConverter; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Optional; + +import static java.lang.Integer.parseInt; +import static java.util.stream.Collectors.toList; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * @author Anatolii Bazko + */ +public class ThreadDumpTest { + private Debugger debugger; + + @BeforeClass + public void setUp() throws Exception { + ProjectApiUtils.ensure(); + + debugger = new JavaDebugger("localhost", + parseInt(System.getProperty("debug.port")), + event -> { + // ignore + }); + try { + debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("org.eclipse.ThreadDumpTest", 26))); + } catch (DebuggerException ignored) { + // static class has not been loaded yet + } + debugger.resume(new ResumeActionImpl()); + } + + @AfterMethod + public void tearDown() throws Exception { + debugger.resume(new ResumeActionImpl()); + } + + @Test + public void testGetThreadDumps() throws Exception { + List threads = debugger.getThreadDumps().stream().map(DtoConverter::asDto).collect(toList()); + + Optional mainThread = threads.stream().filter(t -> t.getName().equals("main")).findAny(); + assertTrue(mainThread.isPresent()); + + ThreadDump threadDump = mainThread.get(); + assertEquals(threadDump.getName(), "main"); + assertEquals(threadDump.getGroupName(), "main"); + assertTrue(threadDump.isSuspended()); + assertEquals(threadDump.getStatus(), ThreadStatus.RUNNABLE); + + List frames = threadDump.getFrames(); + assertEquals(frames.size(), 1); + + StackFrameDump stackFrameDump = frames.get(0); + + List variables = stackFrameDump.getVariables(); + //TODO + List fields = stackFrameDump.getFields(); + //TODO + + Location location = stackFrameDump.getLocation(); + assertEquals(location.getLineNumber(), 24); + assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getExternalResourceId(), -1); + assertEquals(location.getResourceProjectPath(), "/test"); + assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java"); + + Method method = location.getMethod(); + assertEquals(method.getName(), "main"); + + List arguments = method.getArguments(); + assertEquals(arguments.size(), 1); + + Variable variable = arguments.get(0); + assertEquals(variable.getName(), "args"); + assertEquals(variable.getType(), "java.lang.String[]"); + assertEquals(variable.getVariablePath(), new VariablePathImpl("args")); + + //TODO + SimpleValue value = variable.getValue(); + //TODO + value.getString(); + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml new file mode 100644 index 00000000000..9c5c5a76262 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker-assembly.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml similarity index 59% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker-assembly.xml rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml index 4e3c9022222..33bd14b10a5 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker-assembly.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml @@ -14,8 +14,16 @@ - ${project.build.testOutputDirectory}/workspace/test/out/com/HelloWorld.class + ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/ThreadDumpTest.java + ./org/eclipse + + + ${project.build.testOutputDirectory}/workspace/test/src/com/HelloWorld.java ./com + + ${project.build.testOutputDirectory}/docker/entrypoint.sh + . + diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/findbugs-exclude.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/findbugs-exclude.xml index cb0a70305bf..3228dcf7245 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/findbugs-exclude.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/findbugs-exclude.xml @@ -1,3 +1,4 @@ + - %-41(%date[%.15thread]) %-45([%-5level] [%.30logger{30} %L]) - %msg%n @@ -22,5 +21,4 @@ - diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/out/com/HelloWorld.class b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/out/com/HelloWorld.class deleted file mode 100644 index d8a8eb7c8a9ac1fce5b6b16a639e2c97966f927b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 975 zcmZuvZBNrs7(JK4+SS5XVazGuK)?+K^Zjk;2S|(`=1VezF@EZ{n^MxQr0q1sKc#*c zMiYO4KgxJ+N3!9TW%s$y+j*XIZvXuK`5VA}JTs8RO&uE`!*hv%5~M8HaAysV8&n z&|&AogfyFD8O3VkSS#1`BZp^Xp9yT0$15u1Apy;oQDi%$VKjqY*p@F`#VI>nc~6Zp zF^`fCg}@sqCPPaDV0zbBo5DJ-W0_-B?Fw&G?BwHLEOJO+ ou_*q6{^1-M%jo0EHvg8%qmS9IOpY>J9${8QiGU!$T2i(C4`4#h8vp breakpointsDto = debugger.getAllBreakpoints().stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); + DebugSessionDto debugSessionDto = newDto(DebugSessionDto.class); debugSessionDto.setDebuggerInfo(DtoConverter.asDto(debugger.getInfo())); debugSessionDto.setId(sessionId); debugSessionDto.setType(debuggerManager.getDebuggerType(sessionId)); - debugSessionDto.setBreakpoints(DtoConverter.breakpointsAsDtos(debugger.getAllBreakpoints())); + debugSessionDto.setBreakpoints(breakpointsDto); return debugSessionDto; } @@ -145,7 +149,10 @@ public void addBreakpoint(@PathParam("id") String sessionId, BreakpointDto break @Path("{id}/breakpoint") @Produces(MediaType.APPLICATION_JSON) public List getBreakpoints(@PathParam("id") String sessionId) throws DebuggerException { - return breakpointsAsDtos(debuggerManager.getDebugger(sessionId).getAllBreakpoints()); + return debuggerManager.getDebugger(sessionId).getAllBreakpoints() + .stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); } @DELETE @@ -169,10 +176,13 @@ public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId) th } @GET - @Path("{id}/threaddumps") + @Path("{id}/threaddump") @Produces(MediaType.APPLICATION_JSON) public List getThreadDumps(@PathParam("id") String sessionId) throws DebuggerException { - return dumpsAsDtos(debuggerManager.getDebugger(sessionId).getThreadDumps()); + List threadDumps = debuggerManager.getDebugger(sessionId).getThreadDumps(); + return threadDumps.stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); } @GET diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 9445c17e77f..04f6af2a603 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -41,9 +41,10 @@ import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; -import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; +import static java.util.stream.Collectors.toList; import static org.eclipse.che.dto.server.DtoFactory.newDto; /** @@ -74,20 +75,14 @@ public static BreakpointDto asDto(Breakpoint breakpoint) { .withLocation(asDto(breakpoint.getLocation())); } - public static List breakpointsAsDtos(List breakpoints) { - List dtos = new LinkedList<>(); - - if (breakpoints != null) { - for (int i = 0; i < breakpoints.size(); i++) { - dtos.add(asDto(breakpoints.get(i))); - } - } - return dtos; - } - public static MethodDto asDto(Method method) { + List variablesDto = method.getArguments() + .stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); + return newDto(MethodDto.class).withName(method.getName()) - .withArguments(variablesAsDtos(method.getArguments())); + .withArguments(variablesDto); } public static LocationDto asDto(Location location) { @@ -101,15 +96,24 @@ public static LocationDto asDto(Location location) { } public static SimpleValueDto asDto(SimpleValue value) { + List variablesDto = value.getVariables() + .stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); + return newDto(SimpleValueDto.class).withString(value.getString()) - .withVariables(variablesAsDtos(value.getVariables())); + .withVariables(variablesDto); + } + + public static SimpleValueDto asSimplifiedDto(SimpleValue value) { + return newDto(SimpleValueDto.class).withString(value.getString()); } public static FieldDto asDto(Field field) { return newDto(FieldDto.class).withType(field.getType()) .withName(field.getName()) .withPrimitive(field.isPrimitive()) - .withValue(asDto(field.getValue())) + .withValue(asSimplifiedDto(field.getValue())) .withVariablePath(asDto(field.getVariablePath())) .withIsFinal(field.isIsFinal()) .withIsStatic(field.isIsStatic()) @@ -117,33 +121,11 @@ public static FieldDto asDto(Field field) { .withIsVolatile(field.isIsVolatile()); } - public static List fieldsAsDtos(List fields) { - List dtos = new LinkedList<>(); - - if (fields != null) { - for (int i = 0; i < fields.size(); i++) { - dtos.add(asDto(fields.get(i))); - } - } - return dtos; - } - - public static List variablesAsDtos(List variables) { - List dtos = new LinkedList<>(); - - if (variables != null) { - for (int i = 0; i < variables.size(); i++) { - dtos.add(asDto(variables.get(i))); - } - } - return dtos; - } - public static VariableDto asDto(Variable variable) { return newDto(VariableDto.class).withType(variable.getType()) .withName(variable.getName()) .withPrimitive(variable.isPrimitive()) - .withValue(asDto(variable.getValue())) + .withValue(asSimplifiedDto(variable.getValue())) .withVariablePath(asDto(variable.getVariablePath())); } @@ -152,8 +134,17 @@ public static VariablePathDto asDto(VariablePath variablePath) { } public static StackFrameDumpDto asDto(StackFrameDump stackFrameDump) { - return newDto(StackFrameDumpDto.class).withVariables(variablesAsDtos(stackFrameDump.getVariables())) - .withFields(fieldsAsDtos(stackFrameDump.getFields())) + List fieldsDto = stackFrameDump.getFields() + .stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); + + List variablesDto = stackFrameDump.getVariables().stream() + .map(DtoConverter::asDto) + .collect(Collectors.toList()); + + return newDto(StackFrameDumpDto.class).withVariables(variablesDto) + .withFields(fieldsDto) .withLocation(asDto(stackFrameDump.getLocation())); } @@ -173,34 +164,17 @@ public static DebuggerEventDto asDto(DebuggerEvent debuggerEvent) { } } - public static List framesAsDtos(List frames) { - List dtos = new LinkedList<>(); - - if (frames != null) { - for (int i = 0; i < frames.size(); i++) { - dtos.add(asDto(frames.get(i))); - } - } - return dtos; - } - - public static List dumpsAsDtos(List dumps) { - List dtos = new LinkedList<>(); + public static ThreadDumpDto asDto(ThreadDump threadDump) { + List threads = threadDump.getFrames().stream() + .map(DtoConverter::asDto) + .collect(toList()); - if (dumps != null) { - for (int i = 0; i < dumps.size(); i++) { - dtos.add(asDto(dumps.get(i))); - } - } - return dtos; - } - public static ThreadDumpDto asDto(ThreadDump threadDump) { return newDto(ThreadDumpDto.class).withName(threadDump.getName()) .withGroupName(threadDump.getGroupName()) .withSuspended(threadDump.isSuspended()) .withStatus(threadDump.getStatus()) - .withFrames(framesAsDtos(threadDump.getFrames())); + .withFrames(threads); } private DtoConverter() {} From 2a19dd90b80bf013f77a2d1b64ae171f6b9ce644 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Thu, 15 Jun 2017 11:21:06 +0300 Subject: [PATCH 09/38] Fix tests --- .../che/plugin/jdb/server/JavaDebugger.java | 12 +--- .../che/plugin/jdb/server/ThreadDumpTest.java | 60 +++++++++++-------- .../api/debug/shared/model/ThreadStatus.java | 3 +- .../che/api/debugger/server/DtoConverter.java | 21 ++++++- 4 files changed, 57 insertions(+), 39 deletions(-) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 71ff8991649..e98615c5ff4 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -380,16 +380,10 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { @Override public List getThreadDumps() throws DebuggerException { - List threadRefs = vm.allThreads(); - List threadDumps = new ArrayList<>(threadRefs.size()); + List threadDumps = new LinkedList<>(); - for (ThreadReference t : threadRefs) { - ThreadStatus status; - try { - status = ThreadStatus.valueOf(VM.toThreadState(t.status()).toString()); - } catch (IllegalArgumentException e) { - status = ThreadStatus.UNKNOWN; - } + for (ThreadReference t : vm.allThreads()) { + ThreadStatus status = ThreadStatus.valueOf(VM.toThreadState(t.status()).toString()); List frames = new LinkedList<>(); try { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java index d17ec3c94ae..5b3b41cf0b5 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java @@ -14,15 +14,17 @@ import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.Method; -import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; -import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl; +import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.DtoConverter; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; @@ -30,12 +32,17 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; import static java.lang.Integer.parseInt; +import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; /** @@ -43,22 +50,14 @@ */ public class ThreadDumpTest { private Debugger debugger; + private BlockingQueue events = new ArrayBlockingQueue<>(10); @BeforeClass public void setUp() throws Exception { ProjectApiUtils.ensure(); - debugger = new JavaDebugger("localhost", - parseInt(System.getProperty("debug.port")), - event -> { - // ignore - }); - try { - debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("org.eclipse.ThreadDumpTest", 26))); - } catch (DebuggerException ignored) { - // static class has not been loaded yet - } - debugger.resume(new ResumeActionImpl()); + initJavaDebugger(); + endureSuspendAtDesiredLocation(); } @AfterMethod @@ -85,31 +84,40 @@ public void testGetThreadDumps() throws Exception { StackFrameDump stackFrameDump = frames.get(0); List variables = stackFrameDump.getVariables(); - //TODO + assertFalse(variables.isEmpty()); + List fields = stackFrameDump.getFields(); - //TODO + assertTrue(fields.isEmpty()); Location location = stackFrameDump.getLocation(); - assertEquals(location.getLineNumber(), 24); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getLineNumber(), 26); + assertEquals(location.getTarget(), "org.eclipse.ThreadDumpTest"); assertEquals(location.getExternalResourceId(), -1); assertEquals(location.getResourceProjectPath(), "/test"); - assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java"); + assertEquals(location.getResourcePath(), "/test/src/org/eclipse/ThreadDumpTest.java"); Method method = location.getMethod(); assertEquals(method.getName(), "main"); List arguments = method.getArguments(); assertEquals(arguments.size(), 1); + } + + private void initJavaDebugger() throws DebuggerException, InterruptedException { + debugger = new JavaDebugger("localhost", parseInt(getProperty("debug.port")), events::add); + + BreakpointImpl breakpoint = new BreakpointImpl(new LocationImpl("org.eclipse.ThreadDumpTest", 26)); + debugger.start(new StartActionImpl(Collections.singletonList(breakpoint))); + } + + private void endureSuspendAtDesiredLocation() throws InterruptedException { + DebuggerEvent debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); - Variable variable = arguments.get(0); - assertEquals(variable.getName(), "args"); - assertEquals(variable.getType(), "java.lang.String[]"); - assertEquals(variable.getVariablePath(), new VariablePathImpl("args")); + debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof SuspendEvent); - //TODO - SimpleValue value = variable.getValue(); - //TODO - value.getString(); + SuspendEvent suspendEvent = (SuspendEvent)debuggerEvent; + assertEquals(suspendEvent.getLocation().getLineNumber(), 26); } } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java index e45b2ae03f7..b01d895cc9e 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java @@ -17,6 +17,5 @@ public enum ThreadStatus { RUNNABLE, BLOCKED, WAITING, - TIMED_WAITING, - UNKNOWN + TIMED_WAITING } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 04f6af2a603..47bbb8681e9 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -42,6 +42,7 @@ import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import static java.util.stream.Collectors.toList; @@ -136,11 +137,27 @@ public static VariablePathDto asDto(VariablePath variablePath) { public static StackFrameDumpDto asDto(StackFrameDump stackFrameDump) { List fieldsDto = stackFrameDump.getFields() .stream() - .map(DtoConverter::asDto) + .map(f -> { + try { + return asDto(f); + } catch (Exception e) { + return null; + } + } + ) + .filter(Objects::nonNull) .collect(Collectors.toList()); List variablesDto = stackFrameDump.getVariables().stream() - .map(DtoConverter::asDto) + .map(v -> { + try { + return asDto(v); + } catch (Exception e) { + return null; + } + } + ) + .filter(Objects::nonNull) .collect(Collectors.toList()); return newDto(StackFrameDumpDto.class).withVariables(variablesDto) From 27a5a65e7072dae28ea1a031dd45ac53c1652bf5 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 16 Jun 2017 17:01:04 +0300 Subject: [PATCH 10/38] Refactoring --- .../che/plugin/jdb/server/JavaDebugger.java | 85 +++++++------ .../jdb/server/jdi/JdiArrayElement.java | 29 ----- .../che/plugin/jdb/server/jdi/JdiField.java | 22 ---- .../plugin/jdb/server/jdi/JdiLocation.java | 19 --- .../che/plugin/jdb/server/jdi/JdiMethod.java | 23 ---- .../plugin/jdb/server/jdi/JdiMethodImpl.java | 67 ---------- .../plugin/jdb/server/jdi/JdiStackFrame.java | 58 --------- .../jdb/server/jdi/JdiStackFrameImpl.java | 117 ------------------ .../che/plugin/jdb/server/jdi/JdiValue.java | 40 ------ .../plugin/jdb/server/jdi/JdiVariable.java | 24 ---- .../JdbArrayElement.java} | 46 ++++--- .../JdiFieldImpl.java => model/JdbField.java} | 47 ++++--- .../JdbFieldComparator.java} | 8 +- .../JdbLocation.java} | 15 ++- .../plugin/jdb/server/model/JdbMethod.java | 70 +++++++++++ .../JdbNullValue.java} | 13 +- .../jdb/server/model/JdbStackFrame.java | 115 +++++++++++++++++ .../{jdi/JdiType.java => model/JdbType.java} | 6 +- .../JdiValueImpl.java => model/JdbValue.java} | 35 ++---- .../JdbVariable.java} | 23 ++-- .../che/plugin/jdb/server/ThreadDumpTest.java | 15 +-- .../che/api/debugger/server/DtoConverter.java | 2 +- 22 files changed, 331 insertions(+), 548 deletions(-) delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiArrayElementImpl.java => model/JdbArrayElement.java} (57%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiFieldImpl.java => model/JdbField.java} (60%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiFieldComparator.java => model/JdbFieldComparator.java} (82%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiLocationImpl.java => model/JdbLocation.java} (83%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiNullValue.java => model/JdbNullValue.java} (74%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiType.java => model/JdbType.java} (94%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiValueImpl.java => model/JdbValue.java} (70%) rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/{jdi/JdiVariableImpl.java => model/JdbVariable.java} (69%) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index e98615c5ff4..a0315024be1 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -54,7 +54,6 @@ import org.eclipse.che.api.debug.shared.model.impl.DebuggerInfoImpl; import org.eclipse.che.api.debug.shared.model.impl.FieldImpl; import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; -import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl; import org.eclipse.che.api.debug.shared.model.impl.ThreadDumpImpl; import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl; @@ -65,11 +64,10 @@ import org.eclipse.che.plugin.jdb.server.expression.Evaluator; import org.eclipse.che.plugin.jdb.server.expression.ExpressionException; import org.eclipse.che.plugin.jdb.server.expression.ExpressionParser; -import org.eclipse.che.plugin.jdb.server.jdi.JdiField; -import org.eclipse.che.plugin.jdb.server.jdi.JdiLocationImpl; -import org.eclipse.che.plugin.jdb.server.jdi.JdiStackFrame; -import org.eclipse.che.plugin.jdb.server.jdi.JdiStackFrameImpl; -import org.eclipse.che.plugin.jdb.server.jdi.JdiVariable; +import org.eclipse.che.plugin.jdb.server.model.JdbField; +import org.eclipse.che.plugin.jdb.server.model.JdbLocation; +import org.eclipse.che.plugin.jdb.server.model.JdbMethod; +import org.eclipse.che.plugin.jdb.server.model.JdbStackFrame; import org.eclipse.che.plugin.jdb.server.utils.JavaDebuggerUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,6 +80,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.locks.Lock; @@ -122,7 +121,7 @@ public class JavaDebugger implements EventsHandler, Debugger { /** Current thread. Not null is thread suspended, e.g breakpoint reached. */ private ThreadReference thread; /** Current stack frame. Not null is thread suspended, e.g breakpoint reached. */ - private JdiStackFrame stackFrame; + private JdbStackFrame stackFrame; /** Lock for synchronization debug processes. */ private Lock lock = new ReentrantLock(); @@ -371,8 +370,7 @@ public void resume(ResumeAction action) throws DebuggerException { public StackFrameDump dumpStackFrame() throws DebuggerException { lock.lock(); try { - final JdiStackFrame currentFrame = getCurrentFrame(); - return new StackFrameDumpImpl(currentFrame.getFields(), currentFrame.getVariables()); + return getCurrentFrame(); } finally { lock.unlock(); } @@ -385,10 +383,13 @@ public List getThreadDumps() throws DebuggerException { for (ThreadReference t : vm.allThreads()) { ThreadStatus status = ThreadStatus.valueOf(VM.toThreadState(t.status()).toString()); - List frames = new LinkedList<>(); + List frames = new LinkedList<>(); try { for (StackFrame sf : t.frames()) { - frames.add(new JdiStackFrameImpl(sf)); + frames.add(new JdbStackFrame(sf, + Collections.emptyList(), + Collections.emptyList(), + new JdbLocation(sf, new JdbMethod(sf, Collections.emptyList())))); } } catch (IncompatibleThreadStateException ignored) { } @@ -452,36 +453,46 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException if (path.size() == 0) { throw new IllegalArgumentException("Path to value may not be empty. "); } - JdiVariable variable; + Optional variable; int offset; if ("this".equals(path.get(0)) || "static".equals(path.get(0))) { if (path.size() < 2) { throw new IllegalArgumentException("Name of field required. "); } - variable = getCurrentFrame().getFieldByName(path.get(1)); + + variable = getCurrentFrame().getFields() + .stream() + .filter(f -> f.getName().equals(path.get(1))) + .findAny(); offset = 2; } else { - variable = getCurrentFrame().getVariableByName(path.get(0)); - if (variable == null) { - return null; - } + variable = getCurrentFrame().getVariables() + .stream() + .filter(v -> v.getName().equals(path.get(0))) + .findAny(); + offset = 1; } - for (int i = offset; variable != null && i < path.size(); i++) { - variable = variable.getValue().getVariableByName(path.get(i)); + for (int i = offset; variable.isPresent() && i < path.size(); i++) { + final int index = i; + variable = variable.get().getValue() + .getVariables() + .stream() + .filter(v -> v.getName().equals(path.get(index))) + .findAny(); } - if (variable == null) { + if (!variable.isPresent()) { return null; } List variables = new ArrayList<>(); - for (JdiVariable ch : variable.getValue().getVariables()) { + for (Variable ch : variable.get().getValue().getVariables()) { VariablePathDto chPath = newDto(VariablePathDto.class).withPath(new ArrayList<>(path)); chPath.getPath().add(ch.getName()); - if (ch instanceof JdiField) { - JdiField f = (JdiField)ch; + if (ch instanceof JdbField) { + JdbField f = (JdbField)ch; variables.add(new FieldImpl(f.getName(), new SimpleValueImpl(f.getValue().getString()), f.getType(), @@ -500,7 +511,7 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException chPath)); } } - return new SimpleValueImpl(variables, variable.getValue().getString()); + return new SimpleValueImpl(variables, variable.get().getValue().getString()); } @Override @@ -570,15 +581,12 @@ private boolean processBreakPointEvent(com.sun.jdi.event.BreakpointEvent event) } if (hitBreakpoint) { - com.sun.jdi.Location jdiLocation = event.location(); - - Location location; try { - location = new JdiLocationImpl(event.thread().frame(0)); + Location location = new JdbLocation(event.thread().frame(0)); + debuggerCallback.onEvent(new SuspendEventImpl(location)); } catch (IncompatibleThreadStateException e) { - location = new JdiLocationImpl(jdiLocation); + return true; } - debuggerCallback.onEvent(new SuspendEventImpl(location)); } // Left target JVM in suspended state if result of evaluation of expression is boolean value and true @@ -588,11 +596,16 @@ private boolean processBreakPointEvent(com.sun.jdi.event.BreakpointEvent event) private boolean processStepEvent(com.sun.jdi.event.StepEvent event) throws DebuggerException { setCurrentThread(event.thread()); - com.sun.jdi.Location jdiLocation = event.location(); - Location location = debuggerUtil.getLocation(jdiLocation); - debuggerCallback.onEvent(new SuspendEventImpl(location)); - return false; + try { + StackFrame jdiFrame = event.thread().frame(0); + JdbLocation jdbLocation = new JdbLocation(jdiFrame); + debuggerCallback.onEvent(new SuspendEventImpl(jdbLocation)); + return false; + } catch (IncompatibleThreadStateException e) { + invalidateCurrentThread(); + return true; + } } private boolean processDisconnectEvent() { @@ -690,12 +703,12 @@ private ThreadReference getCurrentThread() throws DebuggerException { return thread; } - private JdiStackFrame getCurrentFrame() throws DebuggerException { + private JdbStackFrame getCurrentFrame() throws DebuggerException { if (stackFrame != null) { return stackFrame; } try { - stackFrame = new JdiStackFrameImpl(getCurrentThread().frame(0)); + stackFrame = new JdbStackFrame(getCurrentThread().frame(0)); } catch (IncompatibleThreadStateException e) { throw new DebuggerException("Thread is not suspended. ", e); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java deleted file mode 100644 index 18234cc1862..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElement.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; - -/** - * Element of array in debuggee JVM. - * - * @author andrew00x - */ -public interface JdiArrayElement extends JdiVariable { - /** - * Get index of this element of array. - * - * @return index of this array element - * @throws DebuggerException - * if an error occurs - */ - int getIndex() throws DebuggerException; -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java deleted file mode 100644 index 272491b20f7..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiField.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debug.shared.model.Field; - -/** - * Wrapper for {@link com.sun.jdi.Field} - * - * @author andrew00x - * @author Anatolii Bazko - */ -public interface JdiField extends JdiVariable, Field { -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java deleted file mode 100644 index 2542f21fca8..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocation.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debug.shared.model.Location; - -/** - * @author Anatolii Bazko - */ -public interface JdiLocation extends Location { -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java deleted file mode 100644 index 71410fa15b7..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethod.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debug.shared.model.Method; - -import java.util.List; - -/** - * @author Anatolii Bazko - */ -public interface JdiMethod extends Method { - @Override - List getArguments(); -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java deleted file mode 100644 index 4f01ef74c8c..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiMethodImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.Method; -import com.sun.jdi.StackFrame; - -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author Anatolii Bazko - */ -public class JdiMethodImpl implements JdiMethod { - private final String name; - private final List arguments; - - public JdiMethodImpl(StackFrame stackFrame, Method method) { - this.name = method.name(); - - List args; - try { - args = method.arguments() - .stream() - .map(v -> new JdiVariableImpl(stackFrame, v)) - .collect(Collectors.toList()); - } catch (AbsentInformationException e) { - args = Collections.emptyList(); - } - this.arguments = args; - } - - public JdiMethodImpl(Method method) { - this.name = method.name(); - - List args; - try { - args = method.arguments() - .stream() - .map(JdiVariableImpl::new) - .collect(Collectors.toList()); - } catch (AbsentInformationException e) { - args = Collections.emptyList(); - } - this.arguments = args; - } - - @Override - public String getName() { - return name; - } - - @Override - public List getArguments() { - return arguments; - } -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java deleted file mode 100644 index 00911144049..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrame.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.commons.annotation.Nullable; - -import java.util.List; - -/** - * State of method invocation. - * - * @author andrew00x - */ -public interface JdiStackFrame extends StackFrameDump { - - /** - * Get all available instance or class members. - * - * @return list of fields. Fields should be ordered: - *

      - *
    • static fields should go before non-static fields
    • - *
    • fields of the same type should be ordered by name
    • - *
    - */ - @Override - List getFields(); - - /** - * Get field by name. - * - * @return field or null if there is not such field - */ - @Nullable - JdiField getFieldByName(String name); - - @Override - List getVariables(); - - /** - * Get local variable by name. - * - * @return local variable or null if there is not such local variable - */ - @Nullable - JdiVariable getVariableByName(String name); - - @Override - JdiLocation getLocation(); -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java deleted file mode 100644 index 32ad86ed279..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiStackFrameImpl.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import com.sun.jdi.AbsentInformationException; -import com.sun.jdi.Field; -import com.sun.jdi.InvalidStackFrameException; -import com.sun.jdi.NativeMethodException; -import com.sun.jdi.ObjectReference; -import com.sun.jdi.ReferenceType; -import com.sun.jdi.StackFrame; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author andrew00x - * @author Anatolii Bazko - */ -public class JdiStackFrameImpl implements JdiStackFrame { - private final StackFrame stackFrame; - - private List fields; - private List variables; - private JdiLocation jdiLocation; - - public JdiStackFrameImpl(StackFrame stackFrame) { - this.stackFrame = stackFrame; - } - - @Override - public List getFields() { - if (fields == null) { - try { - fields = new LinkedList<>(); - - ObjectReference object = stackFrame.thisObject(); - if (object == null) { - ReferenceType type = stackFrame.location().declaringType(); - for (Field f : stackFrame.location().declaringType().allFields()) { - fields.add(new JdiFieldImpl(f, type)); - } - } else { - for (Field f : object.referenceType().allFields()) { - fields.add(new JdiFieldImpl(f, object)); - } - } - - fields.sort(new JdiFieldComparator()); - } catch (InvalidStackFrameException e) { - fields = Collections.emptyList(); - } - } - return fields; - } - - @Override - public JdiField getFieldByName(String name) { - if (name == null) { - throw new IllegalArgumentException("Field name may not be null. "); - } - for (JdiField f : getFields()) { - if (name.equals(f.getName())) { - return f; - } - } - return null; - } - - @Override - public List getVariables() { - if (variables == null) { - try { - variables = stackFrame.visibleVariables() - .stream() - .map(v -> new JdiVariableImpl(stackFrame, v)) - .collect(Collectors.toList()); - } catch (AbsentInformationException | InvalidStackFrameException | NativeMethodException e) { - variables = Collections.emptyList(); - } - } - return variables; - } - - @Override - public JdiVariable getVariableByName(String name) { - if (name == null) { - throw new IllegalArgumentException("Field name may not be null. "); - } - - for (JdiVariable var : getVariables()) { - if (name.equals(var.getName())) { - return var; - } - } - - return null; - } - - @Override - public JdiLocation getLocation() { - if (jdiLocation == null) { - jdiLocation = new JdiLocationImpl(stackFrame); - } - return jdiLocation; - } -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java deleted file mode 100644 index f74e882edfc..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValue.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debug.shared.model.SimpleValue; -import org.eclipse.che.commons.annotation.Nullable; - -import java.util.List; - -/** - * Wrapper for {@link com.sun.jdi.Value} - * - * @author andrew00x - * @author Anatolii Bazko - */ -public interface JdiValue extends SimpleValue { - - @Override - List getVariables(); - - /** - * Get nested variable by name. - * - * @param name - * name of variable. Typically it is name of field. If this value represents array then name should be in form: - * [i], where i is index of element - * @return nested variable with specified name or null if there is no such variable - * @see JdiVariable#getName() - */ - @Nullable - JdiVariable getVariableByName(String name); -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java deleted file mode 100644 index 628b8d4281f..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariable.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; - -import org.eclipse.che.api.debug.shared.model.Variable; - -/** - * Wrapper for {@link com.sun.jdi.LocalVariable} - * - * @author andrew00x - * @author Anatolii Bazko - */ -public interface JdiVariable extends Variable { - @Override - JdiValue getValue(); -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java similarity index 57% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java index 15781d4ba15..fce876bcc41 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiArrayElementImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java @@ -8,29 +8,31 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; import com.sun.jdi.PrimitiveValue; import com.sun.jdi.Value; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; -/** @author andrew00x */ -public class JdiArrayElementImpl implements JdiArrayElement { - private final int index; - private final Value value; - private final String name; - - public JdiArrayElementImpl(int index, Value value) { - this.index = index; - this.value = value; +/** + * @author andrew00x + * @author Anatolii Bazko + */ +public class JdbArrayElement implements Variable { + private final Value jdiValue; + private final SimpleValue value; + private final String name; + private final String type; + + public JdbArrayElement(Value jdiValue, int index) { + this.jdiValue = jdiValue; this.name = "[" + index + "]"; - } - - @Override - public int getIndex() { - return index; + this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue); + this.type = jdiValue == null ? "null" : jdiValue.type().name(); } @Override @@ -40,23 +42,17 @@ public String getName() { @Override public boolean isPrimitive() { - return value instanceof PrimitiveValue; + return jdiValue instanceof PrimitiveValue; } @Override - public JdiValue getValue() { - if (value == null) { - return new JdiNullValue(); - } - return new JdiValueImpl(value); + public SimpleValue getValue() { + return value; } @Override public String getType() { - if (value == null) { - return "null"; - } - return value.type().name(); + return type; } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java similarity index 60% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java index 793e8714c4d..44224c4e24d 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java @@ -8,78 +8,85 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; -import com.sun.jdi.Field; import com.sun.jdi.ObjectReference; import com.sun.jdi.ReferenceType; import com.sun.jdi.Value; +import org.eclipse.che.api.debug.shared.model.Field; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import static java.util.Arrays.asList; -/** @author andrew00x */ -public class JdiFieldImpl implements JdiField { - private final Field field; +/** + * Java debugger implementation of {@link Field} + * + * @author andrew00x + * @author Anatolii Bazko + */ +public class JdbField implements Field { + private final com.sun.jdi.Field jdiField; + private final ReferenceType type; private final ObjectReference object; - public JdiFieldImpl(Field field, ObjectReference object) { - this.field = field; + public JdbField(com.sun.jdi.Field jdiField, ObjectReference object) { + this.jdiField = jdiField; this.object = object; this.type = null; } - public JdiFieldImpl(Field field, ReferenceType type) { - this.field = field; + public JdbField(com.sun.jdi.Field jdiField, ReferenceType type) { + this.jdiField = jdiField; this.type = type; this.object = null; } @Override public String getName() { - return field.name(); + return jdiField.name(); } @Override public boolean isIsStatic() { - return field.isStatic(); + return jdiField.isStatic(); } @Override public boolean isIsTransient() { - return field.isTransient(); + return jdiField.isTransient(); } @Override public boolean isIsVolatile() { - return field.isVolatile(); + return jdiField.isVolatile(); } @Override public boolean isIsFinal() { - return field.isFinal(); + return jdiField.isFinal(); } @Override public boolean isPrimitive() { - return JdiType.isPrimitive(field.signature()); + return JdbType.isPrimitive(jdiField.signature()); } @Override - public JdiValue getValue() { - Value value = object == null ? type.getValue(field) : object.getValue(field); + public SimpleValue getValue() { + Value value = object == null ? type.getValue(jdiField) : object.getValue(jdiField); if (value == null) { - return new JdiNullValue(); + return new JdbNullValue(); } - return new JdiValueImpl(value); + return new JdbValue(value); } @Override public String getType() { - return field.typeName(); + return jdiField.typeName(); } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java similarity index 82% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java index 218a897a24b..14c181ed68c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiFieldComparator.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java @@ -8,17 +8,19 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; + +import org.eclipse.che.api.debug.shared.model.Field; import java.util.Comparator; /** * @author Anatolii Bazko */ -public class JdiFieldComparator implements Comparator { +public class JdbFieldComparator implements Comparator { @Override - public int compare(JdiField o1, JdiField o2) { + public int compare(Field o1, Field o2) { final boolean thisStatic = o1.isIsStatic(); final boolean thatStatic = o2.isIsStatic(); if (thisStatic && !thatStatic) { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java similarity index 83% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java index 125346493b7..13fe0d0bb0a 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiLocationImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; import com.sun.jdi.StackFrame; @@ -19,23 +19,26 @@ import org.eclipse.che.plugin.jdb.server.utils.JavaDebuggerUtils; /** + * {@link org.eclipse.che.api.debug.shared.model.Location} implementation for Java debugger. + * * @author Anatolii Bazko */ -public class JdiLocationImpl implements JdiLocation { +public class JdbLocation implements Location { private static final JavaDebuggerUtils debuggerUtil = new JavaDebuggerUtils(); private final Method method; private final Location location; - public JdiLocationImpl(StackFrame stackFrame) { + public JdbLocation(StackFrame stackFrame) { com.sun.jdi.Location jdiLocation = stackFrame.location(); this.location = findLocation(jdiLocation); - this.method = new JdiMethodImpl(stackFrame, jdiLocation.method()); + this.method = new JdbMethod(stackFrame); } - public JdiLocationImpl(com.sun.jdi.Location jdiLocation) { + public JdbLocation(StackFrame stackFrame, Method method) { + com.sun.jdi.Location jdiLocation = stackFrame.location(); this.location = findLocation(jdiLocation); - this.method = new JdiMethodImpl(jdiLocation.method()); + this.method = method; } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java new file mode 100644 index 00000000000..049da370a6d --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.model; + +import com.sun.jdi.AbsentInformationException; + +import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.api.debug.shared.model.Variable; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +/** + * {@link org.eclipse.che.api.debug.shared.model.Method} implementation for Java Debugger. + * + * @author Anatolii Bazko + */ +public class JdbMethod implements Method { + private final com.sun.jdi.Method method; + private final com.sun.jdi.StackFrame stackFrame; + + private final AtomicReference> arguments; + + public JdbMethod(com.sun.jdi.StackFrame stackFrame) { + this.stackFrame = stackFrame; + this.method = stackFrame.location().method(); + this.arguments = new AtomicReference<>(); + } + + public JdbMethod(com.sun.jdi.StackFrame stackFrame, List arguments) { + this.stackFrame = stackFrame; + this.method = stackFrame.location().method(); + this.arguments = new AtomicReference<>(arguments); + } + + @Override + public String getName() { + return method.name(); + } + + @Override + public List getArguments() { + if (arguments.get() == null) { + synchronized (arguments) { + if (arguments.get() == null) { + try { + arguments.set(method.arguments() + .stream() + .map(v -> new JdbVariable(stackFrame, v)) + .collect(Collectors.toList())); + } catch (AbsentInformationException e) { + arguments.set(Collections.emptyList()); + } + } + } + } + + return arguments.get(); + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbNullValue.java similarity index 74% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbNullValue.java index 1a0f9ab739c..f3094954e82 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiNullValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbNullValue.java @@ -8,7 +8,10 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; + +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.Variable; import java.util.Collections; import java.util.List; @@ -17,19 +20,15 @@ * @author andrew00x * @author Anatolii Bazko */ -public final class JdiNullValue implements JdiValue { +public final class JdbNullValue implements SimpleValue { @Override public String getString() { return "null"; } @Override - public List getVariables() { + public List getVariables() { return Collections.emptyList(); } - @Override - public JdiVariable getVariableByName(String name) { - return null; - } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java new file mode 100644 index 00000000000..f6c0950d97e --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.model; + +import com.sun.jdi.ObjectReference; +import com.sun.jdi.ReferenceType; +import com.sun.jdi.StackFrame; + +import org.eclipse.che.api.debug.shared.model.Field; +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.Variable; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +/** + * @author andrew00x + * @author Anatolii Bazko + */ +public class JdbStackFrame implements StackFrameDump { + private final com.sun.jdi.StackFrame jdiStackFrame; + + private final AtomicReference> fields; + private final AtomicReference> variables; + private final Location location; + + public JdbStackFrame(com.sun.jdi.StackFrame jdiStackFrame) { + this.jdiStackFrame = jdiStackFrame; + this.location = new JdbLocation(jdiStackFrame); + this.variables = new AtomicReference<>(); + this.fields = new AtomicReference<>(); + } + + public JdbStackFrame(StackFrame jdiStackFrame, + List fields, + List variables, + Location location) { + this.jdiStackFrame = jdiStackFrame; + this.fields = new AtomicReference<>(fields); + this.variables = new AtomicReference<>(variables); + this.location = location; + } + + @Override + public List getFields() { + if (fields.get() == null) { + synchronized (fields) { + if (fields.get() == null) { + try { + ObjectReference object = jdiStackFrame.thisObject(); + if (object == null) { + ReferenceType type = jdiStackFrame.location().declaringType(); + fields.set(jdiStackFrame.location() + .declaringType() + .allFields() + .stream() + .map(f -> new JdbField(f, type)) + .sorted(new JdbFieldComparator()) + .collect(Collectors.toList())); + } else { + fields.set(object.referenceType() + .allFields() + .stream() + .map(f -> new JdbField(f, object)) + .sorted(new JdbFieldComparator()) + .collect(Collectors.toList())); + } + + } catch (Exception e) { + fields.set(Collections.emptyList()); + } + + } + } + } + + return fields.get(); + } + + @Override + public List getVariables() { + if (variables.get() == null) { + synchronized (variables) { + if (variables.get() == null) { + try { + variables.set(jdiStackFrame.visibleVariables() + .stream() + .map(v -> new JdbVariable(jdiStackFrame, v)) + .collect(Collectors.toList())); + } catch (Exception e) { + variables.set(Collections.emptyList()); + } + } + } + } + + return variables.get(); + } + + @Override + public Location getLocation() { + return location; + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiType.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbType.java similarity index 94% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiType.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbType.java index f39621e6ba7..16ead424152 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiType.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbType.java @@ -8,11 +8,11 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; /** @author andrew00x */ -public class JdiType { - private JdiType() { +public class JdbType { + private JdbType() { } /** diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java similarity index 70% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java index 9215c6ac48b..46fcc694fa3 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiValueImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; import com.sun.jdi.ArrayReference; import com.sun.jdi.Field; @@ -16,18 +16,21 @@ import com.sun.jdi.PrimitiveValue; import com.sun.jdi.Value; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.Variable; + import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; /** @author andrew00x */ -public class JdiValueImpl implements JdiValue { +public class JdbValue implements SimpleValue { private final Value value; - private List variables; + private List variables; - public JdiValueImpl(Value value) { + public JdbValue(Value value) { if (value == null) { throw new IllegalArgumentException("Underlying value can not be null. "); } @@ -40,7 +43,7 @@ public String getString() { } @Override - public List getVariables() { + public List getVariables() { if (variables == null) { if (isPrimitive()) { variables = Collections.emptyList(); @@ -49,16 +52,16 @@ public List getVariables() { if (isArray()) { ArrayReference array = (ArrayReference)value; for (int i = 0; i < array.length(); i++) { - variables.add(new JdiArrayElementImpl(i, array.getValue(i))); + variables.add(new JdbArrayElement(array.getValue(i), i)); } } else { ObjectReference object = (ObjectReference)value; for (Field f : object.referenceType().allFields()) { - variables.add(new JdiFieldImpl(f, object)); + variables.add(new JdbField(f, object)); } variables = variables.stream() - .map(v -> (JdiField)v) - .sorted(new JdiFieldComparator()) + .map(v -> (org.eclipse.che.plugin.jdb.server.model.JdbField)v) + .sorted(new JdbFieldComparator()) .collect(Collectors.toList()); } } @@ -66,20 +69,6 @@ public List getVariables() { return variables; } - @Override - public JdiVariable getVariableByName(String name) { - if (name == null) { - throw new IllegalArgumentException("Variable name may not be null. "); - } - - for (JdiVariable variable : getVariables()) { - if (name.equals(variable.getName())) { - return variable; - } - } - return null; - } - public boolean isArray() { return value instanceof ArrayReference; } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java similarity index 69% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java index 4b6c6365d85..0fbe79d3b6f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/jdi/JdiVariableImpl.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java @@ -8,29 +8,26 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server.jdi; +package org.eclipse.che.plugin.jdb.server.model; import com.sun.jdi.LocalVariable; import com.sun.jdi.StackFrame; import com.sun.jdi.Value; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; /** @author andrew00x */ -public class JdiVariableImpl implements JdiVariable { +public class JdbVariable implements Variable { private final LocalVariable variable; - private final JdiValue jdiValue; + private final SimpleValue jdbValue; - public JdiVariableImpl(StackFrame stackFrame, LocalVariable variable) { + public JdbVariable(StackFrame stackFrame, LocalVariable variable) { Value value = stackFrame.getValue(variable); this.variable = variable; - this.jdiValue = value == null ? new JdiNullValue() : new JdiValueImpl(value); - } - - public JdiVariableImpl(LocalVariable variable) { - this.variable = variable; - this.jdiValue = null; + this.jdbValue = value == null ? new JdbNullValue() : new JdbValue(value); } @Override @@ -40,12 +37,12 @@ public String getName() { @Override public boolean isPrimitive() { - return JdiType.isPrimitive(variable.signature()); + return JdbType.isPrimitive(variable.signature()); } @Override - public JdiValue getValue() { - return jdiValue; + public SimpleValue getValue() { + return jdbValue; } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java index 5b3b41cf0b5..4a97f1819ce 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java @@ -11,13 +11,11 @@ package org.eclipse.che.plugin.jdb.server; import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; -import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.Method; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.ThreadStatus; -import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; @@ -42,7 +40,6 @@ import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; /** @@ -82,12 +79,8 @@ public void testGetThreadDumps() throws Exception { assertEquals(frames.size(), 1); StackFrameDump stackFrameDump = frames.get(0); - - List variables = stackFrameDump.getVariables(); - assertFalse(variables.isEmpty()); - - List fields = stackFrameDump.getFields(); - assertTrue(fields.isEmpty()); + assertTrue(stackFrameDump.getVariables().isEmpty()); + assertTrue(stackFrameDump.getFields().isEmpty()); Location location = stackFrameDump.getLocation(); assertEquals(location.getLineNumber(), 26); @@ -98,9 +91,7 @@ public void testGetThreadDumps() throws Exception { Method method = location.getMethod(); assertEquals(method.getName(), "main"); - - List arguments = method.getArguments(); - assertEquals(arguments.size(), 1); + assertTrue(method.getArguments().isEmpty()); } private void initJavaDebugger() throws DebuggerException, InterruptedException { diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 47bbb8681e9..1ab6dcf5255 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -93,7 +93,7 @@ public static LocationDto asDto(Location location) { .withResourcePath(location.getResourcePath()) .withResourceProjectPath(location.getResourceProjectPath()) .withExternalResource(location.isExternalResource()) - .withMethod(asDto(location.getMethod())); + .withMethod(location.getMethod() == null ? null : asDto(location.getMethod())); } public static SimpleValueDto asDto(SimpleValue value) { From 7ec32bb3af67453c9f9a312232ba28f0af708131 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 19 Jun 2017 09:03:17 +0300 Subject: [PATCH 11/38] Refactoring --- .../che/plugin/jdb/server/JavaDebugger.java | 14 ++-- .../plugin/jdb/server/model/JdbLocation.java | 15 ++-- .../plugin/jdb/server/model/JdbMethod.java | 27 ++++--- .../jdb/server/model/JdbStackFrame.java | 3 + .../che/plugin/jdb/server/model/JdbValue.java | 72 ++++++++++--------- .../plugin/jdb/server/model/JdbVariable.java | 27 ++++--- 6 files changed, 82 insertions(+), 76 deletions(-) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index a0315024be1..bf0b9c2c84e 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -75,7 +75,6 @@ import java.io.IOException; import java.net.UnknownHostException; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; @@ -86,6 +85,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import static java.util.Collections.emptyList; import static org.eclipse.che.dto.server.DtoFactory.newDto; /** @@ -314,7 +314,7 @@ public List getAllBreakpoints() throws DebuggerException { Throwable cause = e.getCause(); if (cause instanceof VMCannotBeModifiedException) { // If target VM in read-only state then list of break point always empty. - return Collections.emptyList(); + return emptyList(); } throw e; } @@ -385,11 +385,11 @@ public List getThreadDumps() throws DebuggerException { List frames = new LinkedList<>(); try { - for (StackFrame sf : t.frames()) { - frames.add(new JdbStackFrame(sf, - Collections.emptyList(), - Collections.emptyList(), - new JdbLocation(sf, new JdbMethod(sf, Collections.emptyList())))); + for (StackFrame f : t.frames()) { + frames.add(new JdbStackFrame(f, + emptyList(), + emptyList(), + new JdbLocation(f, new JdbMethod(f, emptyList())))); } } catch (IncompatibleThreadStateException ignored) { } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java index 13fe0d0bb0a..c781eb7fe53 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java @@ -30,14 +30,11 @@ public class JdbLocation implements Location { private final Location location; public JdbLocation(StackFrame stackFrame) { - com.sun.jdi.Location jdiLocation = stackFrame.location(); - this.location = findLocation(jdiLocation); - this.method = new JdbMethod(stackFrame); + this(stackFrame, new JdbMethod(stackFrame)); } public JdbLocation(StackFrame stackFrame, Method method) { - com.sun.jdi.Location jdiLocation = stackFrame.location(); - this.location = findLocation(jdiLocation); + this.location = getLocation(stackFrame.location()); this.method = method; } @@ -76,13 +73,11 @@ public Method getMethod() { return method; } - private Location findLocation(com.sun.jdi.Location jdiLocation) { - Location location; + private Location getLocation(com.sun.jdi.Location jdiLocation) { try { - location = debuggerUtil.getLocation(jdiLocation); + return debuggerUtil.getLocation(jdiLocation); } catch (DebuggerException e) { - location = new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber()); + return new LocationImpl(jdiLocation.declaringType().name(), jdiLocation.lineNumber()); } - return location; } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java index 049da370a6d..1a378febaaa 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java @@ -26,26 +26,25 @@ * @author Anatolii Bazko */ public class JdbMethod implements Method { - private final com.sun.jdi.Method method; - private final com.sun.jdi.StackFrame stackFrame; + private final com.sun.jdi.Method jdiMethod; + private final com.sun.jdi.StackFrame jdiStackFrame; private final AtomicReference> arguments; - public JdbMethod(com.sun.jdi.StackFrame stackFrame) { - this.stackFrame = stackFrame; - this.method = stackFrame.location().method(); + public JdbMethod(com.sun.jdi.StackFrame jdiStackFrame) { + this.jdiStackFrame = jdiStackFrame; + this.jdiMethod = jdiStackFrame.location().method(); this.arguments = new AtomicReference<>(); } - public JdbMethod(com.sun.jdi.StackFrame stackFrame, List arguments) { - this.stackFrame = stackFrame; - this.method = stackFrame.location().method(); - this.arguments = new AtomicReference<>(arguments); + public JdbMethod(com.sun.jdi.StackFrame jdiStackFrame, List arguments) { + this(jdiStackFrame); + this.arguments.set(arguments); } @Override public String getName() { - return method.name(); + return jdiMethod.name(); } @Override @@ -54,10 +53,10 @@ public List getArguments() { synchronized (arguments) { if (arguments.get() == null) { try { - arguments.set(method.arguments() - .stream() - .map(v -> new JdbVariable(stackFrame, v)) - .collect(Collectors.toList())); + arguments.set(jdiMethod.arguments() + .stream() + .map(v -> new JdbVariable(jdiStackFrame, v)) + .collect(Collectors.toList())); } catch (AbsentInformationException e) { arguments.set(Collections.emptyList()); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java index f6c0950d97e..cfa74a213a2 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java @@ -25,6 +25,9 @@ import java.util.stream.Collectors; /** + * /** + * {@link org.eclipse.che.api.debug.shared.model.StackFrameDump} implementation for Java Debugger. + * * @author andrew00x * @author Anatolii Bazko */ diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java index 46fcc694fa3..3b1f90572e5 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java @@ -11,7 +11,6 @@ package org.eclipse.che.plugin.jdb.server.model; import com.sun.jdi.ArrayReference; -import com.sun.jdi.Field; import com.sun.jdi.ObjectReference; import com.sun.jdi.PrimitiveValue; import com.sun.jdi.Value; @@ -22,58 +21,63 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -/** @author andrew00x */ +/** + * {@link org.eclipse.che.api.debug.shared.model.SimpleValue} implementation for Java Debugger. + * + * @author Anatolii Bazko + */ public class JdbValue implements SimpleValue { - private final Value value; - - private List variables; + private final Value jdiValue; + private final AtomicReference> variables; - public JdbValue(Value value) { - if (value == null) { - throw new IllegalArgumentException("Underlying value can not be null. "); - } - this.value = value; + public JdbValue(Value jdiValue) { + this.jdiValue = jdiValue; + this.variables = new AtomicReference<>(); } @Override public String getString() { - return value.toString(); + return jdiValue.toString(); } @Override public List getVariables() { - if (variables == null) { - if (isPrimitive()) { - variables = Collections.emptyList(); - } else { - variables = new LinkedList<>(); - if (isArray()) { - ArrayReference array = (ArrayReference)value; - for (int i = 0; i < array.length(); i++) { - variables.add(new JdbArrayElement(array.getValue(i), i)); - } - } else { - ObjectReference object = (ObjectReference)value; - for (Field f : object.referenceType().allFields()) { - variables.add(new JdbField(f, object)); + if (variables.get() == null) { + synchronized (variables) { + if (variables.get() == null) { + if (isPrimitive()) { + variables.set(Collections.emptyList()); + } else if (isArray()) { + variables.set(new LinkedList<>()); + + ArrayReference array = (ArrayReference)jdiValue; + for (int i = 0; i < array.length(); i++) { + variables.get().add(new JdbArrayElement(array.getValue(i), i)); + } + } else { + ObjectReference object = (ObjectReference)jdiValue; + variables.set(object.referenceType() + .allFields() + .stream() + .map(f -> new JdbField(f, object)) + .sorted(new JdbFieldComparator()) + .collect(Collectors.toList())); } - variables = variables.stream() - .map(v -> (org.eclipse.che.plugin.jdb.server.model.JdbField)v) - .sorted(new JdbFieldComparator()) - .collect(Collectors.toList()); } } } - return variables; + + return variables.get(); } - public boolean isArray() { - return value instanceof ArrayReference; + private boolean isArray() { + return jdiValue instanceof ArrayReference; } - public boolean isPrimitive() { - return value instanceof PrimitiveValue; + private boolean isPrimitive() { + return jdiValue instanceof PrimitiveValue; } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java index 0fbe79d3b6f..73fb5018faf 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java @@ -19,35 +19,40 @@ import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; -/** @author andrew00x */ +/** + * {@link org.eclipse.che.api.debug.shared.model.Variable} implementation for Java Debugger. + * + * @author Anatolii Bazko + */ public class JdbVariable implements Variable { - private final LocalVariable variable; - private final SimpleValue jdbValue; + private final LocalVariable jdiVariable; + private final SimpleValue value; + + public JdbVariable(StackFrame jdiStackFrame, LocalVariable jdiVariable) { + Value jdiValue = jdiStackFrame.getValue(jdiVariable); - public JdbVariable(StackFrame stackFrame, LocalVariable variable) { - Value value = stackFrame.getValue(variable); - this.variable = variable; - this.jdbValue = value == null ? new JdbNullValue() : new JdbValue(value); + this.jdiVariable = jdiVariable; + this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue); } @Override public String getName() { - return variable.name(); + return jdiVariable.name(); } @Override public boolean isPrimitive() { - return JdbType.isPrimitive(variable.signature()); + return JdbType.isPrimitive(jdiVariable.signature()); } @Override public SimpleValue getValue() { - return jdbValue; + return value; } @Override public String getType() { - return variable.typeName(); + return jdiVariable.typeName(); } @Override From efe4afbb5b8ececbc3b1c5dbbca8ff06c5c6afde Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 19 Jun 2017 15:36:51 +0300 Subject: [PATCH 12/38] Refactoring --- .../che/plugin/jdb/server/JavaDebugger.java | 55 +++++++++-- .../plugin/jdb/server/JavaDebuggerTest.java | 14 ++- .../plugin/jdb/server/JavaDebuggerUtils.java | 37 ++++++++ ...readDumpTest.java => ThreadDumpTest1.java} | 93 ++++++++++++++++--- .../plugin/jdb/server/ThreadDumpTest2.java | 69 ++++++++++++++ .../JavaDebuggerIntegrationTestsSuite.xml | 3 +- .../src/test/resources/docker/assembly.xml | 6 +- ...readDumpTest.java => ThreadDumpTest1.java} | 2 +- .../test/src/org/eclipse/ThreadDumpTest2.java | 20 ++++ .../api/debug/shared/dto/ThreadDumpDto.java | 7 ++ .../api/debug/shared/model/ThreadDump.java | 5 + .../api/debug/shared/model/ThreadStatus.java | 11 ++- .../shared/model/impl/ThreadDumpImpl.java | 45 ++++----- .../che/api/debugger/server/Debugger.java | 14 +++ .../che/api/debugger/server/DtoConverter.java | 3 +- 15 files changed, 330 insertions(+), 54 deletions(-) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/{ThreadDumpTest.java => ThreadDumpTest1.java} (54%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/{ThreadDumpTest.java => ThreadDumpTest1.java} (97%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest2.java diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index bf0b9c2c84e..ff4f9001c56 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.che.plugin.jdb.server; -import sun.misc.VM; - import com.sun.jdi.AbsentInformationException; import com.sun.jdi.Bootstrap; import com.sun.jdi.ClassNotPreparedException; @@ -85,6 +83,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.String.format; import static java.util.Collections.emptyList; import static org.eclipse.che.dto.server.DtoFactory.newDto; @@ -153,7 +152,7 @@ private void connect() throws DebuggerException { AttachingConnector connector = connector(connectorName); if (connector == null) { throw new DebuggerException( - String.format("Unable connect to target Java VM. Requested connector '%s' not found. ", connectorName)); + format("Unable connect to target Java VM. Requested connector '%s' not found. ", connectorName)); } Map arguments = connector.defaultArguments(); arguments.get("hostname").setValue(host); @@ -376,13 +375,31 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { } } + @Override + public StackFrameDump getStackFrameDump(long threadId, int frameIdx) throws DebuggerException { + lock.lock(); + try { + for (ThreadReference t : vm.allThreads()) { + if (t.uniqueID() == threadId) { + return new JdbStackFrame(t.frame(frameIdx)); + } + } + + throw new DebuggerException(format("Thread %d not found", threadId)); + } catch (IncompatibleThreadStateException e) { + throw new DebuggerException("Thread is not suspended", e); + } catch (IndexOutOfBoundsException e) { + throw new DebuggerException(format("Frame %d in thread %d not found.", frameIdx, threadId)); + } finally { + lock.unlock(); + } + } + @Override public List getThreadDumps() throws DebuggerException { List threadDumps = new LinkedList<>(); for (ThreadReference t : vm.allThreads()) { - ThreadStatus status = ThreadStatus.valueOf(VM.toThreadState(t.status()).toString()); - List frames = new LinkedList<>(); try { for (StackFrame f : t.frames()) { @@ -392,11 +409,13 @@ public List getThreadDumps() throws DebuggerException { new JdbLocation(f, new JdbMethod(f, emptyList())))); } } catch (IncompatibleThreadStateException ignored) { + // Thread isn't suspended. Information isn't available. } - threadDumps.add(new ThreadDumpImpl(t.name(), + threadDumps.add(new ThreadDumpImpl(t.uniqueID(), + t.name(), t.threadGroup().name(), - status, + toThreadStatus(t.status()), t.isSuspended(), frames)); } @@ -736,4 +755,26 @@ private EventRequestManager getEventManager() throws DebuggerException { throw new DebuggerException(e.getMessage(), e); } } + + /** + * @see ThreadReference#status() + */ + private ThreadStatus toThreadStatus(int status) { + switch (status) { + case ThreadReference.THREAD_STATUS_ZOMBIE: + return ThreadStatus.ZOMBIE; + case ThreadReference.THREAD_STATUS_RUNNING: + return ThreadStatus.RUNNING; + case ThreadReference.THREAD_STATUS_SLEEPING: + return ThreadStatus.SLEEPING; + case ThreadReference.THREAD_STATUS_MONITOR: + return ThreadStatus.MONITOR; + case ThreadReference.THREAD_STATUS_WAIT: + return ThreadStatus.WAIT; + case ThreadReference.THREAD_STATUS_NOT_STARTED: + return ThreadStatus.NOT_STARTED; + default: + return ThreadStatus.UNKNOWN; + } + } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index 14e73e0e56f..c9cc2d66685 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -31,8 +31,8 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StepIntoActionImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StepOutActionImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl; -import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -43,6 +43,7 @@ import java.util.stream.Collectors; import static java.util.Collections.singletonList; +import static org.eclipse.che.plugin.jdb.server.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; @@ -53,7 +54,7 @@ */ public class JavaDebuggerTest { - private Debugger debugger; + private JavaDebugger debugger; private BlockingQueue events; @BeforeClass @@ -64,9 +65,16 @@ protected void setUp() throws Exception { Map connectionProperties = ImmutableMap.of("host", "localhost", "port", System.getProperty("debug.port")); JavaDebuggerFactory factory = new JavaDebuggerFactory(); - debugger = factory.create(connectionProperties, events::add); + debugger = (JavaDebugger)factory.create(connectionProperties, events::add); } + + @AfterClass + public void tearDown() throws Exception { + terminateVirtualMachineQuietly(debugger); + } + + @Test(priority = 10) public void testGetInfo() throws Exception { DebuggerInfo info = debugger.getInfo(); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java new file mode 100644 index 00000000000..a50e3bc3ec2 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server; + +import com.sun.jdi.VirtualMachine; + +import java.lang.reflect.Field; + +/** + * @author Anatolii Bazko + */ +public class JavaDebuggerUtils { + + /** + * Terminates Virtual Machine. + * + * @see VirtualMachine#exit(int) + */ + public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) throws Exception { + Field vmField = JavaDebugger.class.getDeclaredField("vm"); + vmField.setAccessible(true); + VirtualMachine vm = (VirtualMachine)vmField.get(javaDebugger); + + try { + vm.exit(0); + } catch (Exception ignored) { + } + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java similarity index 54% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index 4a97f1819ce..aa6a577ce33 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -21,12 +21,10 @@ import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; -import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; -import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.DtoConverter; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -39,14 +37,18 @@ import static java.lang.Integer.parseInt; import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; +import static org.eclipse.che.plugin.jdb.server.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; /** + * Test ThreadDump when all threads are suspended. + * * @author Anatolii Bazko */ -public class ThreadDumpTest { - private Debugger debugger; +public class ThreadDumpTest1 { + private JavaDebugger debugger; private BlockingQueue events = new ArrayBlockingQueue<>(10); @BeforeClass @@ -54,18 +56,24 @@ public void setUp() throws Exception { ProjectApiUtils.ensure(); initJavaDebugger(); - endureSuspendAtDesiredLocation(); + ensureSuspendAtDesiredLocation(); } - @AfterMethod + @AfterClass public void tearDown() throws Exception { - debugger.resume(new ResumeActionImpl()); + terminateVirtualMachineQuietly(debugger); } @Test - public void testGetThreadDumps() throws Exception { + public void shouldGetThreadDump() throws Exception { List threads = debugger.getThreadDumps().stream().map(DtoConverter::asDto).collect(toList()); + validateMainThreadDump(threads); + validateSomeThreadDump(threads); + validateFinalizerThreadDump(threads); + } + + private void validateMainThreadDump(List threads) { Optional mainThread = threads.stream().filter(t -> t.getName().equals("main")).findAny(); assertTrue(mainThread.isPresent()); @@ -73,7 +81,7 @@ public void testGetThreadDumps() throws Exception { assertEquals(threadDump.getName(), "main"); assertEquals(threadDump.getGroupName(), "main"); assertTrue(threadDump.isSuspended()); - assertEquals(threadDump.getStatus(), ThreadStatus.RUNNABLE); + assertEquals(threadDump.getStatus(), ThreadStatus.RUNNING); List frames = threadDump.getFrames(); assertEquals(frames.size(), 1); @@ -84,24 +92,81 @@ public void testGetThreadDumps() throws Exception { Location location = stackFrameDump.getLocation(); assertEquals(location.getLineNumber(), 26); - assertEquals(location.getTarget(), "org.eclipse.ThreadDumpTest"); + assertEquals(location.getTarget(), "org.eclipse.ThreadDumpTest1"); assertEquals(location.getExternalResourceId(), -1); assertEquals(location.getResourceProjectPath(), "/test"); - assertEquals(location.getResourcePath(), "/test/src/org/eclipse/ThreadDumpTest.java"); + assertEquals(location.getResourcePath(), "/test/src/org/eclipse/ThreadDumpTest1.java"); Method method = location.getMethod(); assertEquals(method.getName(), "main"); assertTrue(method.getArguments().isEmpty()); } + private void validateFinalizerThreadDump(List threads) { + Optional finalizerThread = threads.stream().filter(t -> t.getName().equals("Finalizer")).findAny(); + assertTrue(finalizerThread.isPresent()); + + ThreadDump threadDump = finalizerThread.get(); + assertEquals(threadDump.getName(), "Finalizer"); + assertEquals(threadDump.getGroupName(), "system"); + assertTrue(threadDump.isSuspended()); + assertEquals(threadDump.getStatus(), ThreadStatus.WAIT); + + List frames = threadDump.getFrames(); + assertEquals(frames.size(), 4); + + StackFrameDump stackFrameDump = frames.get(0); + assertTrue(stackFrameDump.getVariables().isEmpty()); + assertTrue(stackFrameDump.getFields().isEmpty()); + + Location location = stackFrameDump.getLocation(); + assertEquals(location.getLineNumber(), -1); + assertEquals(location.getTarget(), "java.lang.Object"); + assertNull(location.getResourceProjectPath()); + assertNull(location.getResourcePath()); + + Method method = location.getMethod(); + assertEquals(method.getName(), "wait"); + assertTrue(method.getArguments().isEmpty()); + } + + private void validateSomeThreadDump(List threads) { + Optional someThread = threads.stream().filter(t -> t.getName().equals("SomeThread")).findAny(); + assertTrue(someThread.isPresent()); + + ThreadDump threadDump = someThread.get(); + assertEquals(threadDump.getName(), "SomeThread"); + assertEquals(threadDump.getGroupName(), "main"); + assertTrue(threadDump.isSuspended()); + assertEquals(threadDump.getStatus(), ThreadStatus.RUNNING); + + List frames = threadDump.getFrames(); + assertEquals(frames.size(), 1); + + StackFrameDump stackFrameDump = frames.get(0); + assertTrue(stackFrameDump.getVariables().isEmpty()); + assertTrue(stackFrameDump.getFields().isEmpty()); + + Location location = stackFrameDump.getLocation(); + assertEquals(location.getLineNumber(), 41); + assertEquals(location.getTarget(), "org.eclipse.ThreadDumpTest1$SomeThread"); + assertEquals(location.getExternalResourceId(), -1); + assertEquals(location.getResourceProjectPath(), "/test"); + assertEquals(location.getResourcePath(), "/test/src/org/eclipse/ThreadDumpTest1.java"); + + Method method = location.getMethod(); + assertEquals(method.getName(), "run"); + assertTrue(method.getArguments().isEmpty()); + } + private void initJavaDebugger() throws DebuggerException, InterruptedException { debugger = new JavaDebugger("localhost", parseInt(getProperty("debug.port")), events::add); - BreakpointImpl breakpoint = new BreakpointImpl(new LocationImpl("org.eclipse.ThreadDumpTest", 26)); + BreakpointImpl breakpoint = new BreakpointImpl(new LocationImpl("org.eclipse.ThreadDumpTest1", 26)); debugger.start(new StartActionImpl(Collections.singletonList(breakpoint))); } - private void endureSuspendAtDesiredLocation() throws InterruptedException { + private void ensureSuspendAtDesiredLocation() throws InterruptedException { DebuggerEvent debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java new file mode 100644 index 00000000000..45b5df2bb8f --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server; + +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; +import org.eclipse.che.api.debugger.server.DtoConverter; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +import static java.lang.Integer.parseInt; +import static java.lang.System.getProperty; +import static java.util.stream.Collectors.toList; +import static org.eclipse.che.plugin.jdb.server.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +/** + * Test thread dump feature when none of threads are suspended. + * + * @author Anatolii Bazko + */ +public class ThreadDumpTest2 { + private JavaDebugger debugger; + private BlockingQueue events = new ArrayBlockingQueue<>(10); + + @BeforeClass + public void setUp() throws Exception { + ProjectApiUtils.ensure(); + initJavaDebugger(); + } + + @AfterClass + public void tearDown() throws Exception { + terminateVirtualMachineQuietly(debugger); + } + + @Test + public void shouldGetThreadDump() throws Exception { + List threads = debugger.getThreadDumps().stream().map(DtoConverter::asDto).collect(toList()); + + for (ThreadDump t : threads) { + assertFalse(t.isSuspended()); + assertTrue(t.getFrames().isEmpty()); + } + } + + private void initJavaDebugger() throws DebuggerException, InterruptedException { + debugger = new JavaDebugger("localhost", parseInt(getProperty("debug.port")), events::add); + debugger.start(new StartActionImpl(Collections.emptyList())); + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml index 9c5c5a76262..3c4af317103 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml @@ -15,7 +15,8 @@ - + + diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml index 33bd14b10a5..6299de5f1b1 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml @@ -14,7 +14,11 @@ - ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/ThreadDumpTest.java + ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/ThreadDumpTest1.java + ./org/eclipse + + + ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/ThreadDumpTest2.java ./org/eclipse diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java similarity index 97% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java index 9d1d6f104ad..a28635cc358 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java @@ -12,7 +12,7 @@ import java.util.concurrent.CountDownLatch; -public class ThreadDumpTest { +public class ThreadDumpTest1 { public static void main(String[] args) throws Exception { CountDownLatch latch = new CountDownLatch(1); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest2.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest2.java new file mode 100644 index 00000000000..a7e44c75c1a --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest2.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse; + +public class ThreadDumpTest2 { + + public static void main(String[] args) throws Exception { + for (; ; ) { + + } + } +} diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java index 85ab0232ab2..9a71a62e9bd 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java @@ -22,6 +22,13 @@ @DTO public interface ThreadDumpDto extends ThreadDump { + @Override + long getId(); + + void setId(long id); + + ThreadDumpDto withId(long id); + @Override String getName(); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java index 5eedb6a3b2a..15fe0aefdf1 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java @@ -24,6 +24,11 @@ public interface ThreadDump { */ String getName(); + /** + * Returns thread unique id. + */ + long getId(); + /** * Returns thread group name. */ diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java index b01d895cc9e..279144e9235 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadStatus.java @@ -14,8 +14,11 @@ * @author Anatolii Bazko */ public enum ThreadStatus { - RUNNABLE, - BLOCKED, - WAITING, - TIMED_WAITING + ZOMBIE, + RUNNING, + SLEEPING, + MONITOR, + WAIT, + NOT_STARTED, + UNKNOWN } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java index d904733030a..1bf66607376 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java @@ -10,12 +10,13 @@ *******************************************************************************/ package org.eclipse.che.api.debug.shared.model.impl; +import com.google.common.base.Objects; + import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.ThreadStatus; import java.util.List; -import java.util.Objects; /** * @author Anatolii Bazko @@ -26,8 +27,10 @@ public class ThreadDumpImpl implements ThreadDump { private final ThreadStatus status; private final boolean isSuspended; private final List frames; + private final long id; - public ThreadDumpImpl(String name, + public ThreadDumpImpl(long id, + String name, String groupName, ThreadStatus status, boolean isSuspended, @@ -37,6 +40,12 @@ public ThreadDumpImpl(String name, this.status = status; this.isSuspended = isSuspended; this.frames = frames; + this.id = id; + } + + @Override + public long getId() { + return id; } @Override @@ -65,30 +74,21 @@ public List getFrames() { } @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof ThreadDumpImpl)) { - return false; - } - final ThreadDumpImpl that = (ThreadDumpImpl)obj; - return isSuspended == that.isSuspended - && Objects.equals(name, that.name) - && Objects.equals(groupName, that.groupName) - && Objects.equals(status, that.status) - && getFrames().equals(that.getFrames()); + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ThreadDumpImpl)) return false; + ThreadDumpImpl that = (ThreadDumpImpl)o; + return isSuspended == that.isSuspended && + id == that.id && + Objects.equal(name, that.name) && + Objects.equal(groupName, that.groupName) && + status == that.status && + Objects.equal(frames, that.frames); } @Override public int hashCode() { - int hash = 7; - hash = 31 * hash + Objects.hashCode(name); - hash = 31 * hash + Objects.hashCode(groupName); - hash = 31 * hash + Objects.hashCode(status); - hash = 31 * hash + Boolean.hashCode(isSuspended); - hash = 31 * hash + getFrames().hashCode(); - return hash; + return Objects.hashCode(name, groupName, status, isSuspended, frames, id); } @Override @@ -99,6 +99,7 @@ public String toString() { ", status=" + status + ", isSuspended=" + isSuspended + ", frames=" + frames + + ", id=" + id + '}'; } } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index 231327d2142..b36dd85874a 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -198,12 +198,26 @@ default void suspend() throws DebuggerException { /** * Dump values of local variables, fields and method arguments of the current frame. * + * @deprecated Use {@link #getStackFrameDump(long, int)} + * * @return {@link StackFrameDump} * @throws DebuggerException * if any error occur */ + @Deprecated StackFrameDump dumpStackFrame() throws DebuggerException; + /** + * Dump values of local variables, fields and method arguments of the current frame. + * + * @return {@link StackFrameDump} + * @throws DebuggerException + * if any error occur + */ + default StackFrameDump getStackFrameDump(long threadId, int frameIdx) throws DebuggerException { + throw new DebuggerException("Unsupported operation for current debugger implementation."); + } + /** * Gets thread dumps. * diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 1ab6dcf5255..43e1406dea9 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -187,7 +187,8 @@ public static ThreadDumpDto asDto(ThreadDump threadDump) { .collect(toList()); - return newDto(ThreadDumpDto.class).withName(threadDump.getName()) + return newDto(ThreadDumpDto.class).withId(threadDump.getId()) + .withName(threadDump.getName()) .withGroupName(threadDump.getGroupName()) .withSuspended(threadDump.isSuspended()) .withStatus(threadDump.getStatus()) From a93b45bf1d7fbbbbb510903632d995330e7d54b2 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 19 Jun 2017 17:01:47 +0300 Subject: [PATCH 13/38] StackFrameDump --- .../che/plugin/jdb/server/JavaDebugger.java | 6 +- .../plugin/jdb/server/JavaDebuggerTest.java | 3 +- .../plugin/jdb/server/JavaDebuggerUtils.java | 37 ----- .../jdb/server/StackFrameDumpTest1.java | 137 ++++++++++++++++++ .../plugin/jdb/server/ThreadDumpTest1.java | 3 +- .../plugin/jdb/server/ThreadDumpTest2.java | 3 +- .../jdb/server/util/JavaDebuggerUtils.java | 83 +++++++++++ .../server/{ => util}/ProjectApiUtils.java | 4 +- .../JavaDebuggerIntegrationTestsSuite.xml | 1 + .../src/test/resources/docker/assembly.xml | 4 + .../src/org/eclipse/StackFrameDumpTest1.java | 27 ++++ .../che/api/debugger/server/Debugger.java | 2 +- .../api/debugger/server/DebuggerService.java | 8 +- 13 files changed, 271 insertions(+), 47 deletions(-) delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java rename plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/{ => util}/ProjectApiUtils.java (98%) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index ff4f9001c56..4834d2c0bb4 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -376,12 +376,12 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { } @Override - public StackFrameDump getStackFrameDump(long threadId, int frameIdx) throws DebuggerException { + public StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws DebuggerException { lock.lock(); try { for (ThreadReference t : vm.allThreads()) { if (t.uniqueID() == threadId) { - return new JdbStackFrame(t.frame(frameIdx)); + return new JdbStackFrame(t.frame(frameIndex)); } } @@ -389,7 +389,7 @@ public StackFrameDump getStackFrameDump(long threadId, int frameIdx) throws Debu } catch (IncompatibleThreadStateException e) { throw new DebuggerException("Thread is not suspended", e); } catch (IndexOutOfBoundsException e) { - throw new DebuggerException(format("Frame %d in thread %d not found.", frameIdx, threadId)); + throw new DebuggerException(format("Frame %d in thread %d not found.", frameIndex, threadId)); } finally { lock.unlock(); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index c9cc2d66685..2f7607cc498 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -32,6 +32,7 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StepOutActionImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -43,7 +44,7 @@ import java.util.stream.Collectors; import static java.util.Collections.singletonList; -import static org.eclipse.che.plugin.jdb.server.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java deleted file mode 100644 index a50e3bc3ec2..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; - -import com.sun.jdi.VirtualMachine; - -import java.lang.reflect.Field; - -/** - * @author Anatolii Bazko - */ -public class JavaDebuggerUtils { - - /** - * Terminates Virtual Machine. - * - * @see VirtualMachine#exit(int) - */ - public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) throws Exception { - Field vmField = JavaDebugger.class.getDeclaredField("vm"); - vmField.setAccessible(true); - VirtualMachine vm = (VirtualMachine)vmField.get(javaDebugger); - - try { - vm.exit(0); - } catch (Exception ignored) { - } - } -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java new file mode 100644 index 00000000000..ce9b0b1140e --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server; + +import org.eclipse.che.api.debug.shared.dto.LocationDto; +import org.eclipse.che.api.debug.shared.dto.MethodDto; +import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; +import org.eclipse.che.api.debug.shared.dto.VariableDto; +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +import static java.util.Collections.singletonList; +import static org.eclipse.che.api.debugger.server.DtoConverter.asDto; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.ensureSuspendAtDesiredLocation; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.startJavaDebugger; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +/** + * Test ThreadDump when all threads are suspended. + * + * @author Anatolii Bazko + */ +public class StackFrameDumpTest1 { + private JavaDebugger debugger; + private BlockingQueue callback = new ArrayBlockingQueue<>(10); + + @BeforeClass + public void setUp() throws Exception { + ProjectApiUtils.ensure(); + + Location location = new LocationImpl("org.eclipse.StackFrameDumpTest1", 25); + debugger = startJavaDebugger(new BreakpointImpl(location), callback); + + ensureSuspendAtDesiredLocation(location, callback); + } + + @AfterClass + public void tearDown() throws Exception { + if (debugger != null) { + terminateVirtualMachineQuietly(debugger); + } + } + + @Test + public void shouldGetStackFrameDump() throws Exception { + Optional main = debugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); + assertTrue(main.isPresent()); + + ThreadDump mainThread = main.get(); + assertEquals(mainThread.getFrames().size(), 3); + + validateFrame0(mainThread.getId()); + validateFrame1(mainThread.getId()); + validateFrame2(mainThread.getId()); + } + + private void validateFrame0(long threadId) throws DebuggerException { + StackFrameDumpDto stackFrame = asDto(debugger.getStackFrameDump(threadId, 0)); + + LocationDto location = stackFrame.getLocation(); + assertEquals(location.getLineNumber(), 25); + assertEquals(location.getTarget(), "org.eclipse.StackFrameDumpTest1"); + + MethodDto method = location.getMethod(); + assertEquals(method.getName(), "do2"); + + List arguments = method.getArguments(); + assertEquals(arguments.size(), 1); + + VariableDto variable = arguments.get(0); + assertEquals(variable.getName(), "str"); + assertEquals(variable.getType(), "java.lang.String"); + assertEquals(variable.getVariablePath().getPath(), singletonList("str")); + assertFalse(variable.isPrimitive()); + assertEquals(variable.getValue().getString(), "\"2\""); + assertTrue(variable.getValue().getVariables().isEmpty()); + + assertTrue(stackFrame.getFields().isEmpty()); + + List variables = stackFrame.getVariables(); + variable = variables.get(0); + assertEquals(variable.getName(), "str"); + assertEquals(variable.getType(), "java.lang.String"); + assertEquals(variable.getVariablePath().getPath(), singletonList("str")); + assertFalse(variable.isPrimitive()); + assertEquals(variable.getValue().getString(), "\"2\""); + assertTrue(variable.getValue().getVariables().isEmpty()); + } + + private void validateFrame1(long threadId) throws DebuggerException { + StackFrameDumpDto stackFrame = asDto(debugger.getStackFrameDump(threadId, 1)); + + LocationDto location = stackFrame.getLocation(); + assertEquals(location.getLineNumber(), 21); + assertEquals(location.getTarget(), "org.eclipse.StackFrameDumpTest1"); + + MethodDto method = location.getMethod(); + assertEquals(method.getName(), "do1"); + } + + private void validateFrame2(long threadId) throws DebuggerException { + StackFrameDumpDto stackFrame = asDto(debugger.getStackFrameDump(threadId, 2)); + + LocationDto location = stackFrame.getLocation(); + assertEquals(location.getLineNumber(), 16); + assertEquals(location.getTarget(), "org.eclipse.StackFrameDumpTest1"); + + MethodDto method = location.getMethod(); + assertEquals(method.getName(), "main"); + + } + +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index aa6a577ce33..cd20c4cf679 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -24,6 +24,7 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; import org.eclipse.che.api.debugger.server.DtoConverter; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -37,7 +38,7 @@ import static java.lang.Integer.parseInt; import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; -import static org.eclipse.che.plugin.jdb.server.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java index 45b5df2bb8f..4f593603a19 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java @@ -16,6 +16,7 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; import org.eclipse.che.api.debugger.server.DtoConverter; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -28,7 +29,7 @@ import static java.lang.Integer.parseInt; import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; -import static org.eclipse.che.plugin.jdb.server.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java new file mode 100644 index 00000000000..3b489191daf --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server.util; + +import com.google.common.collect.ImmutableMap; +import com.sun.jdi.VirtualMachine; + +import org.eclipse.che.api.debug.shared.model.Breakpoint; +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; +import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; +import org.eclipse.che.plugin.jdb.server.JavaDebugger; +import org.eclipse.che.plugin.jdb.server.JavaDebuggerFactory; + +import java.lang.reflect.Field; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.BlockingQueue; + +import static java.lang.System.getProperty; + +/** + * @author Anatolii Bazko + */ +public class JavaDebuggerUtils { + + /** + * Terminates Virtual Machine. + * + * @see VirtualMachine#exit(int) + */ + public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) throws Exception { + Field vmField = JavaDebugger.class.getDeclaredField("vm"); + vmField.setAccessible(true); + VirtualMachine vm = (VirtualMachine)vmField.get(javaDebugger); + + try { + vm.exit(0); + } catch (Exception ignored) { + } + } + + /** + * Connects to process and starts debug. + */ + public static JavaDebugger startJavaDebugger(Breakpoint breakpoint, BlockingQueue callback) throws Exception { + Map connectionProperties = ImmutableMap.of("host", "localhost", + "port", getProperty("debug.port")); + + JavaDebuggerFactory factory = new JavaDebuggerFactory(); + JavaDebugger debugger = (JavaDebugger)factory.create(connectionProperties, callback::add); + + debugger.start(new StartActionImpl(Collections.singletonList(breakpoint))); + + return debugger; + } + + public static void ensureSuspendAtDesiredLocation(Location desiredLocation, + BlockingQueue callback) throws InterruptedException { + for (; ; ) { + DebuggerEvent event = callback.take(); + if (event instanceof SuspendEvent) { + SuspendEvent suspendEvent = (SuspendEvent)event; + Location location = suspendEvent.getLocation(); + + if (location.getTarget().equals(desiredLocation.getTarget()) + && location.getLineNumber() == desiredLocation.getLineNumber()) { + + return; + } + } + } + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java similarity index 98% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java index b6cefaa80bc..504b5e1fa07 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ProjectApiUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.jdb.server; +package org.eclipse.che.plugin.jdb.server.util; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.core.model.project.ProjectConfig; @@ -53,7 +53,7 @@ public class ProjectApiUtils { /** * Ensures that project api has been initialized only once. */ - static void ensure() throws Exception { + static public void ensure() throws Exception { if (!initialized.get()) { synchronized (initialized) { if (!initialized.get()) { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml index 3c4af317103..7d9ef680b21 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml @@ -17,6 +17,7 @@ + diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml index 6299de5f1b1..eb0da02d017 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml @@ -21,6 +21,10 @@ ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/ThreadDumpTest2.java ./org/eclipse + + ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/StackFrameDumpTest1.java + ./org/eclipse + ${project.build.testOutputDirectory}/workspace/test/src/com/HelloWorld.java ./com diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java new file mode 100644 index 00000000000..ddebf41ff5c --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse; + +public class StackFrameDumpTest1 { + + public static void main(String[] args) throws Exception { + do1(1); + } + + private static void do1(int i) { + int j = 1; + do2(String.valueOf(i + j)); + } + + private static void do2(String str) { + System.out.println(str); + } +} diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index b36dd85874a..a03348a950e 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -214,7 +214,7 @@ default void suspend() throws DebuggerException { * @throws DebuggerException * if any error occur */ - default StackFrameDump getStackFrameDump(long threadId, int frameIdx) throws DebuggerException { + default StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws DebuggerException { throw new DebuggerException("Unsupported operation for current debugger implementation."); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index 5bdf3331bd3..a6c8693636d 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -171,7 +171,13 @@ public void deleteBreakpoint(@PathParam("id") String sessionId, @GET @Path("{id}/dump") @Produces(MediaType.APPLICATION_JSON) - public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId) throws DebuggerException { + public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId, + @QueryParam("threadId") @DefaultValue("-1") long threadId, + @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex) throws DebuggerException { + if (threadId != -1 || frameIndex != -1) { + return asDto(debuggerManager.getDebugger(sessionId).getStackFrameDump(threadId, frameIndex)); + } + return asDto(debuggerManager.getDebugger(sessionId).dumpStackFrame()); } From f98829e1e38a0e66efaeac65002881eb4484afd8 Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Thu, 15 Jun 2017 15:50:24 +0300 Subject: [PATCH 14/38] CHE-4518: change styles for input boxes Signed-off-by: Oleksii Orel --- .../create-factory/create-factory.html | 36 ++-- .../create-factory/create-factory.styl | 8 + .../git/create-factory-git.html | 29 +-- .../machine-config/machine-config.html | 1 - .../widget/input/che-input-box.directive.ts | 177 ++++-------------- .../widget/input/che-input-box.html | 25 +++ .../widget/input/che-input-box.styl | 138 +++++++------- 7 files changed, 164 insertions(+), 250 deletions(-) create mode 100644 dashboard/src/components/widget/input/che-input-box.html diff --git a/dashboard/src/app/factories/create-factory/create-factory.html b/dashboard/src/app/factories/create-factory/create-factory.html index 64a6c9f6632..dab22b81939 100644 --- a/dashboard/src/app/factories/create-factory/create-factory.html +++ b/dashboard/src/app/factories/create-factory/create-factory.html @@ -25,28 +25,20 @@
    - -
    - -
    A name is required.
    -
    Factory name may contain digits, latin letters, spaces, _ , . , - and should start - only - with digits, latin letters or underscores -
    -
    The name has to be more than 3 characters long.
    -
    The name has to be less than 20 characters long.
    -
    -
    -
    + +
    Factory name may contain digits, latin letters, spaces, _ , . , - and should start only with digits, latin letters or underscores
    +
    The name has to be more than 3 characters long.
    +
    The name has to be less than 20 characters long.
    +
    - +
    -
    - -
    Invalid Git URL
    -
    A repository URL is required.
    -
    -
    + +
    + Invalid Git URL +
    +
    - +
    diff --git a/dashboard/src/app/workspaces/workspace-details/environments/machine-config/machine-config.html b/dashboard/src/app/workspaces/workspace-details/environments/machine-config/machine-config.html index 4c90ff051ae..4d8163bd41d 100644 --- a/dashboard/src/app/workspaces/workspace-details/environments/machine-config/machine-config.html +++ b/dashboard/src/app/workspaces/workspace-details/environments/machine-config/machine-config.html @@ -52,7 +52,6 @@ che-place-holder="Image" che-form="workspaceMachineConfigForm" required> -
    An image is required.
    diff --git a/dashboard/src/components/widget/input/che-input-box.directive.ts b/dashboard/src/components/widget/input/che-input-box.directive.ts index 6b2f3f3b3aa..cd3b8a1f604 100644 --- a/dashboard/src/components/widget/input/che-input-box.directive.ts +++ b/dashboard/src/components/widget/input/che-input-box.directive.ts @@ -10,16 +10,28 @@ */ 'use strict'; +interface IInputBoxScope extends ng.IScope { + valueModel: string; + inputName: string; + labelName?: string; + labelDescription?: string; + placeHolder?: string; + pattern?: string; + myForm: ng.IFormController; + onChange?: Function; +} + /** * Defines a directive for creating input that are working either on desktop or on mobile devices. * It will change upon width of the screen * @author Ann Shumilova + * @author Oleksii Orel */ -export class CheInputBox implements ng.IDirective { - +export class CheInputBox { restrict = 'E'; replace = true; transclude = true; + templateUrl: string = 'components/widget/input/che-input-box.html'; // we require ngModel as we want to use it inside our directive require = ['ngModel']; @@ -27,102 +39,21 @@ export class CheInputBox implements ng.IDirective { // scope values scope = { valueModel: '=ngModel', - inputName: '@cheName', + inputName: '@?cheName', labelName: '@?cheLabelName', - placeHolder: '@chePlaceHolder', - pattern: '@chePattern', + labelDescription: '@?cheLabelDescription', + placeHolder: '@?chePlaceHolder', myForm: '=cheForm', - isChanged: '&ngChange', - readonly: '=cheReadonly', - disabled: '=cheDisabled' + onChange: '&?cheOnChange' }; - /** - * Default constructor that is using resource - * @ngInject for Dependency injection - */ - constructor() { - } - - - /** - * Template for the current toolbar - * @param element - * @param attrs - * @returns {string} the template - */ - template(element, attrs) { - let inputName = attrs.cheName; - let labelName = attrs.cheLabelName || ''; - let placeHolder = attrs.chePlaceHolder; - let pattern = attrs.chePattern; - let isMandatory = angular.isDefined(attrs.required) ? true : false; - - let template = '
    ' - + '' - + '' - + '' - + '' - + '
    ' - + '
    ' - + '' - + '
    ' - + '
    ' - + '' - + '' - + '
    ' - + ''; - if (isMandatory) { - template += '*'; - } - - if (attrs.cheWidth === 'auto') { - template = template + '
    {{valueModel ? valueModel : placeHolder}}
    '; - } - - template = template + '' - + '
    ' - + '
    ' - + '
    ' - + '
    ' - + '
    '; - - return template; - } - - - compile(element, attrs) { - - var keys = Object.keys(attrs); + compile(element: ng.IRootElementService, attrs: ng.IAttributes) { + const keys = Object.keys(attrs); // search the input field - var inputElement = element.find('input'); - - var tabIndex; - - keys.forEach((key) => { - + const inputJqEl = element.find('input'); + let tabIndex; + keys.forEach((key: string) => { // don't reapply internal properties if (key.indexOf('$') === 0) { return; @@ -135,73 +66,39 @@ export class CheInputBox implements ng.IDirective { if ('ngModel' === key) { return; } - // don't reapply ngChange - if ('ngChange' === key) { - return; - } - var value = attrs[key]; - + let value = attrs[key]; // remember tabindex if (key === 'tabindex') { tabIndex = value; } - // handle empty values as boolean if (value === '') { value = 'true'; } - // set the value of the attribute - inputElement.attr(attrs.$attr[key], value); - - - //add also the material version of max length (only one the first input which is the md-input) - if ('ngMaxlength' === key) { - inputElement.eq(0).attr('md-maxlength', value); - } - + inputJqEl.attr(attrs.$attr[key], value); + // add also the material version of max length (only one the first input which is the md-input) element.removeAttr(attrs.$attr[key]); - }); - - - // The focusable element is the input, remove tabIndex from top-level element + // the focusable element is the input, remove tabIndex from top-level element element.attr('tabindex', -1); - // The default value for tabindex on the input is 0 (meaning: set 0 if no value was set) + // the default value for tabindex on the input is 0 (meaning: set 0 if no value was set) if (!tabIndex) { - inputElement.attr('tabindex', 0); + inputJqEl.attr('tabindex', 0); } } /** * Keep reference to the model controller */ - link($scope, element, attr) { - $scope.$watch(function () { - return element.is(':visible'); - }, function () { - //Since there are two inputs (for mobile and desktop versions) - add id attr only for visible one: - if (attr.id) { - element.find('input:hidden').removeAttr('id'); - element.find('input:visible').attr('id', attr.id); - } - }); - - $scope.$watch('myForm.desk' + $scope.inputName + '.$pristine', (isPristine) => { - if (isPristine) { - element.addClass('desktop-pristine'); - } else { - element.removeClass('desktop-pristine'); - } - }); - - if (!attr.ngChange) { - return; + link($scope: IInputBoxScope, element: ng.IRootElementService, attrs: ng.IAttributes) { + const inputJqEl = element.find('input'); + const required = 'required'; + if (angular.isDefined($scope.placeHolder)) { + inputJqEl.attr('placeholder', attrs.$attr[required] === required ? $scope.placeHolder + ' *' : $scope.placeHolder); + } + if (!angular.isFunction($scope.onChange)) { + inputJqEl.removeAttr('ng-change'); } - //for ngChange attribute only - $scope.$watch('valueModel', () => { - $scope.isChanged(); - }); - } } diff --git a/dashboard/src/components/widget/input/che-input-box.html b/dashboard/src/components/widget/input/che-input-box.html new file mode 100644 index 00000000000..ba20fe937a0 --- /dev/null +++ b/dashboard/src/components/widget/input/che-input-box.html @@ -0,0 +1,25 @@ +
    +
    +
    + +
    + +
    + + +
    + +
    +
    +
    +
    +
    {{labelDescription}}
    +
    +
    +
    diff --git a/dashboard/src/components/widget/input/che-input-box.styl b/dashboard/src/components/widget/input/che-input-box.styl index 50a1ac93692..59a15cb1cc6 100644 --- a/dashboard/src/components/widget/input/che-input-box.styl +++ b/dashboard/src/components/widget/input/che-input-box.styl @@ -1,92 +1,84 @@ -.che-input-box .che-input-box-desktop [ng-message], -.che-input-box .che-input-box-desktop [ng-show] - color $error-color +.che-input-box > div + max-width 800px + .che-input-box-desktop + display flex + margin 0 + [ng-message], [ng-show] + color $error-color -.che-input-box-desktop input - border 1px solid $default-border-color - padding 10px - border-radius 2px + input, label, .che-input-area, .che-input-asterisk + position relative + line-height 50px -.che-input-box-desktop input:focus - border-color $primary-color + label.che-input-box-desktop-label + color $primary-color + white-space nowrap + padding-right 10px + overflow hidden + text-overflow ellipsis + margin 0 -.che-input-box-desktop input.ng-invalid:focus - border-color $error-color -.che-input-box-desktop input.ng-pristine.ng-untouched.ng-invalid - border-color $default-border-color + .che-input-box-desktop-value-column + position relative + display inline-block + width 100% + min-height 50px -.che-input-box-desktop - margin-top 5px - margin-bottom 5px + input + width 100% + outline none + box-shadow none + overflow hidden + text-overflow ellipsis + white-space nowrap + background-color inherit + border 1px solid $default-border-color + padding 0 0 0 10px !important + border-radius 5px -.che-input-box input:focus - outline none + &:focus + border-color $primary-color -.che-input-box md-input-container - width 100% + &:focus:not(.ng-invalid) + .che-input-asterisk, &[type=number]:not(.ng-invalid):hover + .che-input-asterisk + display none -.che-input-box md-input-container, -.che-input-box md-input-container label, -.che-input-box md-input-container input - padding-left 0 - margin-bottom 0 + &[required].ng-invalid + &:focus::-webkit-input-placeholder, &.ng-dirty::-webkit-input-placeholder + color $error-color + &:focus::-moz-placeholder, &.ng-dirty::-moz-placeholder + color $error-color -.che-input-box md-input-container.che-input-box-mobile-no-label - margin-top 0 + &[readonly] + box-shadow none + background-color inherit -label.che-input-box-desktop-label - margin-bottom 0 + &[readonly] + .che-input-asterisk + display none -.che-input-box - .che-input-box-desktop-value-column - position relative - width 100% - max-width 400px - height 60px + &[disabled], &[disabled] + .che-input-asterisk + color $disabled-color - textarea - min-width 200px - padding-right 30px + &.ng-invalid:focus, &.ng-invalid.ng-dirty + border-color $error-color !important - input - min-width 200px - padding-right 30px - overflow hidden - text-overflow ellipsis - white-space nowrap - background-color inherit + &.ng-invalid + .che-input-asterisk + color $error-color + + &:not(.ng-invalid) + .che-input-asterisk + color $secondary-color + + &.ng-pristine.ng-untouched.ng-invalid + border-color $default-border-color .che-input-asterisk position absolute + padding 0 top 0 - right 4px - color $error-color - font-size 17px - line-height 48px + right 10px + font-size 12px - .che-input-box-desktop-hidden-text - min-width 170px - overflow hidden - margin-right 30px - height 0 - - .che-input-box-icon, .che-input-box-icon-xs - position absolute - top 2px - right -7px - bottom initial - left initial - color $primary-color - .che-input-box-icon-xs - top 13px - - input[disabled], input[disabled] + .che-input-box-icon + .label-description color $disabled-color - - input[readonly] - box-shadow none - background-color inherit - - input[readonly] + .che-input-box-icon - display none + font-size 10px + padding 5px 20px 0 0 From 1a1166ecfc7aeff8fe8af3828844f2f96affae5a Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Sat, 17 Jun 2017 18:37:20 +0300 Subject: [PATCH 15/38] moved showIDE logic into the routeChange listener Signed-off-by: Oleksii Orel --- .../administration/administration-config.ts | 11 ++----- .../administration.controller.ts | 30 ------------------ .../src/app/dashboard/dashboard-config.ts | 14 +++------ .../dashboard/dashboard.controller.spec.ts | 30 ------------------ .../src/app/dashboard/dashboard.controller.ts | 31 ------------------- .../list-factories.controller.ts | 4 +-- dashboard/src/app/ide/ide.controller.ts | 1 - dashboard/src/app/index.module.ts | 15 +++++---- .../create-project.controller.ts | 2 -- .../list-workspaces.controller.ts | 4 +-- .../widget/input/che-input-box.html | 2 +- 11 files changed, 20 insertions(+), 124 deletions(-) delete mode 100644 dashboard/src/app/administration/administration.controller.ts delete mode 100644 dashboard/src/app/dashboard/dashboard.controller.spec.ts delete mode 100644 dashboard/src/app/dashboard/dashboard.controller.ts diff --git a/dashboard/src/app/administration/administration-config.ts b/dashboard/src/app/administration/administration-config.ts index a4fbcfeff40..0e5c20e2c5d 100644 --- a/dashboard/src/app/administration/administration-config.ts +++ b/dashboard/src/app/administration/administration-config.ts @@ -11,7 +11,6 @@ 'use strict'; -import {AdministrationController} from './administration.controller'; import {DockerRegistryList} from './docker-registry/docker-registry-list/docker-registry-list.directive'; import {DockerRegistryListController} from './docker-registry/docker-registry-list/docker-registry-list.controller'; import {EditRegistryController} from './docker-registry/docker-registry-list/edit-registry/edit-registry.controller'; @@ -19,21 +18,17 @@ import {EditRegistryController} from './docker-registry/docker-registry-list/edi export class AdministrationConfig { - constructor(register) { - register.controller('AdministrationController', AdministrationController); - + constructor(register: che.IRegisterService) { register.directive('dockerRegistryList', DockerRegistryList); register.controller('DockerRegistryListController', DockerRegistryListController); register.controller('EditRegistryController', EditRegistryController); // config routes - register.app.config(($routeProvider) => { + register.app.config(($routeProvider: ng.route.IRouteProvider) => { $routeProvider.accessWhen('/administration', { title: 'Administration', - templateUrl: 'app/administration/administration.html', - controller: 'AdministrationController', - controllerAs: 'administrationController' + templateUrl: 'app/administration/administration.html' }); }); diff --git a/dashboard/src/app/administration/administration.controller.ts b/dashboard/src/app/administration/administration.controller.ts deleted file mode 100644 index 0c0b39b2746..00000000000 --- a/dashboard/src/app/administration/administration.controller.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - */ -'use strict'; - -/** - * @ngdoc controller - * @name administration.controller:AdministrationController - * @description This class is handling the controller of the administration - * @author Oleksii Orel - */ -export class AdministrationController { - - - /** - * Default constructor - * @ngInject for Dependency injection - */ - constructor($rootScope) { - 'ngInject'; - $rootScope.showIDE = false; - } -} diff --git a/dashboard/src/app/dashboard/dashboard-config.ts b/dashboard/src/app/dashboard/dashboard-config.ts index 208ecd5eab2..c970afbae81 100644 --- a/dashboard/src/app/dashboard/dashboard-config.ts +++ b/dashboard/src/app/dashboard/dashboard-config.ts @@ -10,34 +10,30 @@ */ 'use strict'; -import {DashboardController} from './dashboard.controller'; import {DashboardLastWorkspacesController} from './last-workspaces/last-workspaces.controller'; import {DashboardLastWorkspaces} from './last-workspaces/last-workspaces.directive'; import {DashboardPanel} from './dashboard-panel/dashboard-panel.directive'; +import {CheService} from '../../components/api/che-service.factory'; +import {CheWorkspace} from '../../components/api/che-workspace.factory'; export class DashboardConfig { - constructor(register) { + constructor(register: che.IRegisterService) { // last workspaces register.controller('DashboardLastWorkspacesController', DashboardLastWorkspacesController); register.directive('dashboardLastWorkspaces', DashboardLastWorkspaces); - // controller - register.controller('DashboardController', DashboardController); - // panel of last used entries register.directive('dashboardPanel', DashboardPanel); // config routes - register.app.config(($routeProvider) => { + register.app.config(($routeProvider: ng.route.IRouteProvider) => { $routeProvider.accessWhen('/', { title: 'Dashboard', templateUrl: 'app/dashboard/dashboard.html', - controller: 'DashboardController', - controllerAs: 'dashboardController', resolve: { - check: ['$q', '$location', 'cheWorkspace', 'cheService', ($q, $location, cheWorkspace, cheService) => { + check: ['$q', '$location', 'cheWorkspace', 'cheService', ($q: ng.IQService, $location: ng.ILocationService, cheWorkspace: CheWorkspace, cheService: CheService) => { cheWorkspace.fetchWorkspaces().then(() => { if (cheWorkspace.getWorkspaces().length === 0) { $location.path('/create-project'); diff --git a/dashboard/src/app/dashboard/dashboard.controller.spec.ts b/dashboard/src/app/dashboard/dashboard.controller.spec.ts deleted file mode 100644 index f8ecb57ad02..00000000000 --- a/dashboard/src/app/dashboard/dashboard.controller.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - */ -'use strict'; - -describe('controllers', function(){ - var scope; - - beforeEach(angular.mock.module('userDashboard')); - - beforeEach(inject(function($rootScope) { - scope = $rootScope.$new(); - })); - - it('empty', inject(function($controller) { - expect(scope.awesomeThings).toBeUndefined(); - - $controller('DashboardController', { - $scope: scope - }); - - })); -}); diff --git a/dashboard/src/app/dashboard/dashboard.controller.ts b/dashboard/src/app/dashboard/dashboard.controller.ts deleted file mode 100644 index e0ff9980231..00000000000 --- a/dashboard/src/app/dashboard/dashboard.controller.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015-2017 Codenvy, S.A. - * 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 - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - */ -'use strict'; - -/** - * @ngdoc controller - * @name dashboard.controller:DashboardController - * @description This class is handling the controller of the dashboard - * @author Florent Benoit - */ -export class DashboardController { - - - /** - * Default constructor - * @ngInject for Dependency injection - */ - constructor($rootScope) { - 'ngInject'; - $rootScope.showIDE = false; - - } -} diff --git a/dashboard/src/app/factories/list-factories/list-factories.controller.ts b/dashboard/src/app/factories/list-factories/list-factories.controller.ts index ce02a1677b3..473069b6d12 100644 --- a/dashboard/src/app/factories/list-factories/list-factories.controller.ts +++ b/dashboard/src/app/factories/list-factories/list-factories.controller.ts @@ -40,7 +40,7 @@ export class ListFactoriesController { * Default constructor that is using resource injection * @ngInject for Dependency injection */ - constructor($q: ng.IQService, $log: ng.ILogService, cheAPI: CheAPI, cheNotification: CheNotification, $rootScope: che.IRootScopeService, + constructor($q: ng.IQService, $log: ng.ILogService, cheAPI: CheAPI, cheNotification: CheNotification, confirmDialogService: ConfirmDialogService, $scope: ng.IScope, cheListHelperFactory: che.widget.ICheListHelperFactory) { this.$q = $q; this.$log = $log; @@ -72,8 +72,6 @@ export class ListFactoriesController { }); this.pagesInfo = cheAPI.getFactory().getPagesInfo(); - - $rootScope.showIDE = false; } /** diff --git a/dashboard/src/app/ide/ide.controller.ts b/dashboard/src/app/ide/ide.controller.ts index 0ee2aae762e..f9c4b0d4217 100644 --- a/dashboard/src/app/ide/ide.controller.ts +++ b/dashboard/src/app/ide/ide.controller.ts @@ -46,7 +46,6 @@ class IdeCtrl { this.cheWorkspace = cheWorkspace; this.$timeout = $timeout; - this.$rootScope.showIDE = false; this.$rootScope.wantTokeepLoader = true; this.selectedWorkspaceExists = true; diff --git a/dashboard/src/app/index.module.ts b/dashboard/src/app/index.module.ts index be870a482d8..2a273798a72 100644 --- a/dashboard/src/app/index.module.ts +++ b/dashboard/src/app/index.module.ts @@ -143,14 +143,17 @@ initModule.run(['$rootScope', '$location', '$routeParams', 'routingRedirect', '$ } }); - - $rootScope.$on('$routeChangeSuccess', (event, next) => { - if (next.$$route.title && angular.isFunction(next.$$route.title)) { - $rootScope.currentPage = next.$$route.title($routeParams); + $rootScope.$on('$routeChangeSuccess', (event: ng.IAngularEvent, next: ng.route.IRoute) => { + const route = (next).$$route; + if (angular.isFunction(route.title)) { + $rootScope.currentPage = route.title($routeParams); } else { - $rootScope.currentPage = next.$$route.title || 'Dashboard'; + $rootScope.currentPage = route.title || 'Dashboard'; + } + const originalPath: string = route.originalPath; + if (originalPath && originalPath.indexOf('/ide/') === -1) { + $rootScope.showIDE = false; } - // when a route is about to change, notify the routing redirect node if (next.resolve) { if (DEV) { diff --git a/dashboard/src/app/projects/create-project/create-project.controller.ts b/dashboard/src/app/projects/create-project/create-project.controller.ts index 579789ddff2..903b8784eff 100755 --- a/dashboard/src/app/projects/create-project/create-project.controller.ts +++ b/dashboard/src/app/projects/create-project/create-project.controller.ts @@ -221,8 +221,6 @@ export class CreateProjectController { cheAPI.getWorkspace().getWorkspaces(); - $rootScope.showIDE = false; - this.isHandleClose = true; this.connectionClosed = () => { if (!this.isHandleClose) { diff --git a/dashboard/src/app/workspaces/list-workspaces/list-workspaces.controller.ts b/dashboard/src/app/workspaces/list-workspaces/list-workspaces.controller.ts index 6b1a217d17e..01eb600f533 100644 --- a/dashboard/src/app/workspaces/list-workspaces/list-workspaces.controller.ts +++ b/dashboard/src/app/workspaces/list-workspaces/list-workspaces.controller.ts @@ -56,7 +56,7 @@ export class ListWorkspacesCtrl { * @ngInject for Dependency injection */ constructor($log: ng.ILogService, $mdDialog: ng.material.IDialogService, $q: ng.IQService, lodash: any, - $rootScope: che.IRootScopeService, cheAPI: CheAPI, cheNotification: CheNotification, cheBranding: CheBranding, + cheAPI: CheAPI, cheNotification: CheNotification, cheBranding: CheBranding, cheWorkspace: CheWorkspace, cheNamespaceRegistry: CheNamespaceRegistry, confirmDialogService: ConfirmDialogService, $scope: ng.IScope, cheListHelperFactory: che.widget.ICheListHelperFactor) { this.cheAPI = cheAPI; @@ -90,8 +90,6 @@ export class ListWorkspacesCtrl { this.getUserWorkspaces(); - $rootScope.showIDE = false; - this.cheNamespaceRegistry.fetchNamespaces().then(() => { this.namespaceLabels = this.getNamespaceLabelsList(); }); diff --git a/dashboard/src/components/widget/input/che-input-box.html b/dashboard/src/components/widget/input/che-input-box.html index ba20fe937a0..02140aa3c78 100644 --- a/dashboard/src/components/widget/input/che-input-box.html +++ b/dashboard/src/components/widget/input/che-input-box.html @@ -9,7 +9,7 @@
    From 8d4646188b334d00cb8b06fdb44b8ee80bb048a6 Mon Sep 17 00:00:00 2001 From: Igor Vinokur Date: Tue, 20 Jun 2017 09:39:57 +0300 Subject: [PATCH 16/38] CHE-5390: Fix bug when failed to commit renamed files (#5394) --- .../eclipse/che/ide/ext/git/client/commit/CommitPresenter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java index 1f22262ab76..52f9bf637b6 100644 --- a/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java +++ b/plugins/plugin-git/che-plugin-git-ext-git/src/main/java/org/eclipse/che/ide/ext/git/client/commit/CommitPresenter.java @@ -115,7 +115,7 @@ public void showDialog(Project project) { view.setEnableAmendCheckBox(true); view.setEnablePushAfterCommitCheckBox(true); view.setEnableRemoteBranchesDropDownLis(false); - service.diff(appContext.getDevMachine(), project.getLocation(), null, NAME_STATUS, false, 0, "HEAD", false) + service.diff(appContext.getDevMachine(), project.getLocation(), null, NAME_STATUS, true, 0, "HEAD", false) .then(diff -> { service.log(appContext.getDevMachine(), project.getLocation(), null, -1, 1, false) .then(arg -> { From ad15101dd311dc992b7c2682dbba815e0d603088 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 21 Jun 2017 11:15:42 +0300 Subject: [PATCH 17/38] StackFrameDump --- .../plugin/jdb/server/model/JdbMethod.java | 4 +- .../plugin/jdb/server/model/JdbVariable.java | 5 + .../jdb/server/StackFrameDumpTest1.java | 102 +++++++++++++++++- .../jdb/server/util/JavaDebuggerUtils.java | 1 + .../src/org/eclipse/StackFrameDumpTest1.java | 2 +- .../che/api/debugger/server/DtoConverter.java | 2 +- 6 files changed, 109 insertions(+), 7 deletions(-) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java index 1a378febaaa..93e073dd1b0 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java @@ -13,6 +13,7 @@ import com.sun.jdi.AbsentInformationException; import org.eclipse.che.api.debug.shared.model.Method; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; import java.util.Collections; @@ -53,9 +54,10 @@ public List getArguments() { synchronized (arguments) { if (arguments.get() == null) { try { + // to reduce unnecessary requests. Value can be retrieved on demand throw Debugger.getValue() method arguments.set(jdiMethod.arguments() .stream() - .map(v -> new JdbVariable(jdiStackFrame, v)) + .map(v -> new JdbVariable((SimpleValue)null, v)) .collect(Collectors.toList())); } catch (AbsentInformationException e) { arguments.set(Collections.emptyList()); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java index 73fb5018faf..5510ff56a96 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java @@ -35,6 +35,11 @@ public JdbVariable(StackFrame jdiStackFrame, LocalVariable jdiVariable) { this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue); } + public JdbVariable(SimpleValue value, LocalVariable jdiVariable) { + this.jdiVariable = jdiVariable; + this.value = value; + } + @Override public String getName() { return jdiVariable.name(); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java index ce9b0b1140e..15d1539b9dc 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.che.plugin.jdb.server; +import com.google.common.collect.ImmutableList; + +import org.eclipse.che.api.debug.shared.dto.FieldDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.MethodDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; @@ -37,6 +40,7 @@ import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; /** @@ -96,12 +100,11 @@ private void validateFrame0(long threadId) throws DebuggerException { assertEquals(variable.getType(), "java.lang.String"); assertEquals(variable.getVariablePath().getPath(), singletonList("str")); assertFalse(variable.isPrimitive()); - assertEquals(variable.getValue().getString(), "\"2\""); - assertTrue(variable.getValue().getVariables().isEmpty()); - - assertTrue(stackFrame.getFields().isEmpty()); + assertNull(variable.getValue()); List variables = stackFrame.getVariables(); + assertEquals(variables.size(), 1); + variable = variables.get(0); assertEquals(variable.getName(), "str"); assertEquals(variable.getType(), "java.lang.String"); @@ -109,6 +112,20 @@ private void validateFrame0(long threadId) throws DebuggerException { assertFalse(variable.isPrimitive()); assertEquals(variable.getValue().getString(), "\"2\""); assertTrue(variable.getValue().getVariables().isEmpty()); + + List fields = stackFrame.getFields(); + assertEquals(fields.size(), 1); + + FieldDto field = fields.get(0); + assertEquals(field.getName(), "v"); + assertEquals(field.getType(), "java.lang.String"); + assertEquals(field.getVariablePath().getPath(), ImmutableList.of("static", "v")); + assertFalse(field.isPrimitive()); + assertTrue(field.isIsStatic()); + assertFalse(field.isIsFinal()); + assertFalse(field.isIsTransient()); + assertEquals(field.getValue().getString(), "\"something\""); + assertTrue(field.getValue().getVariables().isEmpty()); } private void validateFrame1(long threadId) throws DebuggerException { @@ -120,6 +137,49 @@ private void validateFrame1(long threadId) throws DebuggerException { MethodDto method = location.getMethod(); assertEquals(method.getName(), "do1"); + + List arguments = method.getArguments(); + assertEquals(arguments.size(), 1); + + VariableDto variable = arguments.get(0); + assertEquals(variable.getName(), "i"); + assertEquals(variable.getType(), "int"); + assertEquals(variable.getVariablePath().getPath(), singletonList("i")); + assertTrue(variable.isPrimitive()); + assertNull(variable.getValue()); + + List variables = stackFrame.getVariables(); + assertEquals(variables.size(), 2); + + variable = variables.get(0); + assertEquals(variable.getName(), "i"); + assertEquals(variable.getType(), "int"); + assertEquals(variable.getVariablePath().getPath(), singletonList("i")); + assertTrue(variable.isPrimitive()); + assertEquals(variable.getValue().getString(), "1"); + assertTrue(variable.getValue().getVariables().isEmpty()); + + variable = variables.get(1); + assertEquals(variable.getName(), "j"); + assertEquals(variable.getType(), "int"); + assertEquals(variable.getVariablePath().getPath(), singletonList("j")); + assertTrue(variable.isPrimitive()); + assertEquals(variable.getValue().getString(), "1"); + assertTrue(variable.getValue().getVariables().isEmpty()); + + List fields = stackFrame.getFields(); + assertEquals(fields.size(), 1); + + FieldDto field = fields.get(0); + assertEquals(field.getName(), "v"); + assertEquals(field.getType(), "java.lang.String"); + assertEquals(field.getVariablePath().getPath(), ImmutableList.of("static", "v")); + assertFalse(field.isPrimitive()); + assertTrue(field.isIsStatic()); + assertFalse(field.isIsFinal()); + assertFalse(field.isIsTransient()); + assertEquals(field.getValue().getString(), "\"something\""); + assertTrue(field.getValue().getVariables().isEmpty()); } private void validateFrame2(long threadId) throws DebuggerException { @@ -132,6 +192,40 @@ private void validateFrame2(long threadId) throws DebuggerException { MethodDto method = location.getMethod(); assertEquals(method.getName(), "main"); + List arguments = method.getArguments(); + assertEquals(arguments.size(), 1); + + VariableDto variable = arguments.get(0); + assertEquals(variable.getName(), "args"); + assertEquals(variable.getType(), "java.lang.String[]"); + assertEquals(variable.getVariablePath().getPath(), singletonList("args")); + assertFalse(variable.isPrimitive()); + assertNull(variable.getValue()); + + List variables = stackFrame.getVariables(); + assertEquals(variables.size(), 1); + + variable = variables.get(0); + assertEquals(variable.getName(), "args"); + assertEquals(variable.getType(), "java.lang.String[]"); + assertEquals(variable.getVariablePath().getPath(), singletonList("args")); + assertFalse(variable.isPrimitive()); + assertTrue(variable.getValue().getString().contains("java.lang.String[0]")); + assertTrue(variable.getValue().getVariables().isEmpty()); + + List fields = stackFrame.getFields(); + assertEquals(fields.size(), 1); + + FieldDto field = fields.get(0); + assertEquals(field.getName(), "v"); + assertEquals(field.getType(), "java.lang.String"); + assertEquals(field.getVariablePath().getPath(), ImmutableList.of("static", "v")); + assertFalse(field.isPrimitive()); + assertTrue(field.isIsStatic()); + assertFalse(field.isIsFinal()); + assertFalse(field.isIsTransient()); + assertEquals(field.getValue().getString(), "\"something\""); + assertTrue(field.getValue().getVariables().isEmpty()); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java index 3b489191daf..c0d80060b5b 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java @@ -45,6 +45,7 @@ public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) thr try { vm.exit(0); + vm.process().waitFor(); } catch (Exception ignored) { } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java index ddebf41ff5c..73233300ebc 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java @@ -11,7 +11,7 @@ package org.eclipse; public class StackFrameDumpTest1 { - + private static String v = "something"; public static void main(String[] args) throws Exception { do1(1); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 43e1406dea9..79ce89a1f2a 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -126,7 +126,7 @@ public static VariableDto asDto(Variable variable) { return newDto(VariableDto.class).withType(variable.getType()) .withName(variable.getName()) .withPrimitive(variable.isPrimitive()) - .withValue(asSimplifiedDto(variable.getValue())) + .withValue(variable.getValue() == null ? null : asSimplifiedDto(variable.getValue())) .withVariablePath(asDto(variable.getVariablePath())); } From 1bb2aaf22ac547fa412341f89b82d189e8a718f8 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 17 Jul 2017 10:09:27 +0300 Subject: [PATCH 18/38] Fix up --- .../che/plugin/jdb/server/JavaDebugger.java | 45 ++++++++++++ .../che/plugin/jdb/server/GetValueTest1.java | 68 +++++++++++++++++++ .../jdb/server/util/JavaDebuggerUtils.java | 2 +- .../JavaDebuggerIntegrationTestsSuite.xml | 1 + .../src/test/resources/docker/assembly.xml | 4 ++ .../test/src/org/eclipse/GetValueTest1.java | 26 +++++++ .../che/api/debugger/server/Debugger.java | 30 ++++++++ .../api/debugger/server/DebuggerService.java | 13 ++-- 8 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 4834d2c0bb4..ab1339a3eaa 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -533,6 +533,51 @@ public SimpleValue getValue(VariablePath variablePath) throws DebuggerException return new SimpleValueImpl(variables, variable.get().getValue().getString()); } + @Override + public SimpleValue getValue(VariablePath variablePath, long threadId, int frameIndex) throws DebuggerException { + JdbStackFrame jdbStackFrame = null; + try { + for (ThreadReference t : vm.allThreads()) { + if (t.uniqueID() == threadId) { + jdbStackFrame = new JdbStackFrame(t.frame(frameIndex)); + break; + } + } + + if (jdbStackFrame == null) { + throw new DebuggerException(format("Frame %d in thread %d not found.", frameIndex, threadId)); + } + } catch (IncompatibleThreadStateException e) { + throw new DebuggerException("Thread is not suspended", e); + } catch (IndexOutOfBoundsException e) { + throw new DebuggerException(format("Frame %d in thread %d not found.", frameIndex, threadId)); + } + + Optional targetVar; + + List path = variablePath.getPath(); + if ("this".equals(path.get(0)) || "static".equals(path.get(0))) { + targetVar = jdbStackFrame.getFields() + .stream() + .filter(f -> f.getVariablePath().equals(variablePath)) + .findAny(); + } else { + targetVar = jdbStackFrame.getVariables() + .stream() + .filter(v -> v.getVariablePath().equals(variablePath)) + .findAny(); + } + + if (!targetVar.isPresent()) { + throw new DebuggerException(format("Variable %s in the frame %d of the thread %d not found.", + variablePath.getPath().toString(), + frameIndex, + threadId)); + } + + return targetVar.get().getValue(); + } + @Override public void setValue(Variable variable) throws DebuggerException { StringBuilder expression = new StringBuilder(); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java new file mode 100644 index 00000000000..2a0a42c5ad4 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.jdb.server; + +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; +import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Optional; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.ensureSuspendAtDesiredLocation; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.startJavaDebugger; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.testng.Assert.assertTrue; + +/** + * Test ThreadDump when all threads are suspended. + * + * @author Anatolii Bazko + */ +public class GetValueTest1 { + private JavaDebugger debugger; + private BlockingQueue callback = new ArrayBlockingQueue<>(10); + + @BeforeClass + public void setUp() throws Exception { + ProjectApiUtils.ensure(); + + Location location = new LocationImpl("org.eclipse.GetValueTest1", 23); + debugger = startJavaDebugger(new BreakpointImpl(location), callback); + + ensureSuspendAtDesiredLocation(location, callback); + } + + @AfterClass + public void tearDown() throws Exception { + if (debugger != null) { + terminateVirtualMachineQuietly(debugger); + } + } + + @Test + public void testGetValue() throws Exception { + Optional main = debugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); + assertTrue(main.isPresent()); + + ThreadDump mainThread = main.get(); + + +// debugger.getValue() + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java index c0d80060b5b..daac7f09d3e 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java @@ -45,8 +45,8 @@ public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) thr try { vm.exit(0); - vm.process().waitFor(); } catch (Exception ignored) { + // quietly ignore exception, if VM has been already terminated } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml index 7d9ef680b21..158dd53067a 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerIntegrationTestsSuite.xml @@ -18,6 +18,7 @@ + diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml index eb0da02d017..fd923b36208 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml @@ -25,6 +25,10 @@ ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/StackFrameDumpTest1.java ./org/eclipse + + ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/GetValueTest1.java + ./org/eclipse + ${project.build.testOutputDirectory}/workspace/test/src/com/HelloWorld.java ./com diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java new file mode 100644 index 00000000000..48c4901c603 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012-2017 Codenvy, S.A. + * 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 + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse; + +public class GetValueTest1 { + private static String v = "something"; + + public static void main(String[] args) throws Exception { + do1(1); + } + + private static void do1(int i) { + String v = "test"; + i = 2; + System.out.println("Set breakpoint here."); + } +} + diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index a03348a950e..bf4f68d5cfc 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -122,14 +122,40 @@ default void suspend() throws DebuggerException { /** * Gets the current value of the given variable. * + * @deprecated + * @see #getValue(VariablePath, long, int) + * * @param variablePath * the path to the variable * @return {@link SimpleValue} * @throws DebuggerException * if any error occur */ + @Deprecated SimpleValue getValue(VariablePath variablePath) throws DebuggerException; + + /** + * Gets the value of the given variable. + * + * @param variablePath + * the path to the variable + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index inside thread + * @return {@link SimpleValue} + * @throws DebuggerException + * if any error occur + */ + default SimpleValue getValue(VariablePath variablePath, long threadId, int frameIndex) throws DebuggerException { + if (threadId == -1 || frameIndex == -1) { + return getValue(variablePath); + } + + throw new DebuggerException("Unsupported operation for current debugger implementation."); + } + /** * Sets the new value {@link Variable#getValue()} of the variable {@link Variable#getVariablePath()}. * @@ -215,6 +241,10 @@ default void suspend() throws DebuggerException { * if any error occur */ default StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws DebuggerException { + if (threadId == -1 || frameIndex == -1) { + return dumpStackFrame(); + } + throw new DebuggerException("Unsupported operation for current debugger implementation."); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index a6c8693636d..4f159dd2a6d 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -174,11 +174,7 @@ public void deleteBreakpoint(@PathParam("id") String sessionId, public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId, @QueryParam("threadId") @DefaultValue("-1") long threadId, @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex) throws DebuggerException { - if (threadId != -1 || frameIndex != -1) { - return asDto(debuggerManager.getDebugger(sessionId).getStackFrameDump(threadId, frameIndex)); - } - - return asDto(debuggerManager.getDebugger(sessionId).dumpStackFrame()); + return asDto(debuggerManager.getDebugger(sessionId).getStackFrameDump(threadId, frameIndex)); } @GET @@ -194,7 +190,10 @@ public List getThreadDumps(@PathParam("id") String sessionId) thr @GET @Path("{id}/value") @Produces(MediaType.APPLICATION_JSON) - public SimpleValueDto getValue(@PathParam("id") String sessionId, @Context UriInfo uriInfo) throws DebuggerException { + public SimpleValueDto getValue(@PathParam("id") String sessionId, + @QueryParam("threadId") @DefaultValue("-1") long threadId, + @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex, + @Context UriInfo uriInfo) throws DebuggerException { List path = new ArrayList<>(); MultivaluedMap parameters = uriInfo.getQueryParameters(); @@ -206,7 +205,7 @@ public SimpleValueDto getValue(@PathParam("id") String sessionId, @Context UriIn } VariablePath variablePath = new VariablePathImpl(path); - return asDto(debuggerManager.getDebugger(sessionId).getValue(variablePath)); + return asDto(debuggerManager.getDebugger(sessionId).getValue(variablePath, threadId, frameIndex)); } @PUT From 5aa3983d680928260d8a96a1b43062bcc57a7e03 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 16 Aug 2017 17:46:21 +0300 Subject: [PATCH 19/38] Fix up --- .../che-plugin-java-debugger-server/pom.xml | 1 - .../che/plugin/jdb/server/JavaDebugger.java | 12 +---- .../jdb/server/model/JdbArrayElement.java | 21 +++++--- .../che/plugin/jdb/server/model/JdbField.java | 23 +++++++-- .../jdb/server/model/JdbStackFrame.java | 5 +- .../che/plugin/jdb/server/model/JdbValue.java | 9 ++-- .../plugin/jdb/server/model/JdbVariable.java | 2 +- .../che/plugin/jdb/server/GetValueTest1.java | 50 +++++++++++++------ .../jdb/server/util/JavaDebuggerUtils.java | 14 ++++++ .../che/api/debugger/server/Debugger.java | 17 ------- .../api/debugger/server/DebuggerService.java | 18 ++++++- 11 files changed, 109 insertions(+), 63 deletions(-) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml index d9ad74bb5aa..92108dc4081 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml @@ -23,7 +23,6 @@ jar Che Plugin :: Java :: Java Debugger Server - true ${project.build.testOutputDirectory}/findbugs-exclude.xml diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index f0beb87ad63..8dbace3a72e 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -374,17 +374,7 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { public StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws DebuggerException { lock.lock(); try { - for (ThreadReference t : vm.allThreads()) { - if (t.uniqueID() == threadId) { - return new JdbStackFrame(t.frame(frameIndex)); - } - } - - throw new DebuggerException(format("Thread %d not found", threadId)); - } catch (IncompatibleThreadStateException e) { - throw new DebuggerException("Thread is not suspended", e); - } catch (IndexOutOfBoundsException e) { - throw new DebuggerException(format("Frame %d in thread %d not found.", frameIndex, threadId)); + return new JdbStackFrame(getJdiStackFrame(threadId, frameIndex)); } finally { lock.unlock(); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java index c50934f370f..92c0ff93f65 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java @@ -18,20 +18,25 @@ import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; +import java.util.LinkedList; +import java.util.List; + /** * @author andrew00x * @author Anatolii Bazko */ public class JdbArrayElement implements Variable { - private final Value jdiValue; - private final SimpleValue value; - private final String name; - private final String type; + private final Value jdiValue; + private final SimpleValue value; + private final String name; + private final String type; + private final VariablePath parentPath; - public JdbArrayElement(Value jdiValue, int index) { + public JdbArrayElement(Value jdiValue, int index, VariablePath parentPath) { this.jdiValue = jdiValue; this.name = "[" + index + "]"; - this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue); + this.parentPath = parentPath; + this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue, getVariablePath()); this.type = jdiValue == null ? "null" : jdiValue.type().name(); } @@ -57,6 +62,8 @@ public String getType() { @Override public VariablePath getVariablePath() { - return new VariablePathImpl(getName()); + List pathEntries = new LinkedList<>(parentPath.getPath()); + pathEntries.add(getName()); + return new VariablePathImpl(pathEntries); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java index aa304aada8a..2f9ed5e4589 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java @@ -19,7 +19,8 @@ import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; -import static java.util.Arrays.asList; +import java.util.LinkedList; +import java.util.List; /** * Java debugger implementation of {@link Field} @@ -32,17 +33,20 @@ public class JdbField implements Field { private final ReferenceType type; private final ObjectReference object; + private final VariablePath parentPath; - public JdbField(com.sun.jdi.Field jdiField, ObjectReference object) { + public JdbField(com.sun.jdi.Field jdiField, ObjectReference object, VariablePath parentPath) { this.jdiField = jdiField; this.object = object; this.type = null; + this.parentPath = parentPath; } - public JdbField(com.sun.jdi.Field jdiField, ReferenceType type) { + public JdbField(com.sun.jdi.Field jdiField, ReferenceType type, VariablePath parentPath) { this.jdiField = jdiField; this.type = type; this.object = null; + this.parentPath = parentPath; } @Override @@ -81,7 +85,7 @@ public SimpleValue getValue() { if (value == null) { return new JdbNullValue(); } - return new JdbValue(value); + return new JdbValue(value, getVariablePath()); } @Override @@ -91,6 +95,15 @@ public String getType() { @Override public VariablePath getVariablePath() { - return new VariablePathImpl(asList(isIsStatic() ? "static" : "this", getName())); + List pathEntries = new LinkedList<>(); + + if (parentPath.getPath().isEmpty()) { + pathEntries.add(isIsStatic() ? "static" : "this"); + } else { + pathEntries.addAll(parentPath.getPath()); + } + pathEntries.add(getName()); + + return new VariablePathImpl(pathEntries); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java index c44f861683a..9977ee544d4 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java @@ -18,6 +18,7 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import java.util.Collections; import java.util.List; @@ -68,14 +69,14 @@ public List getFields() { .declaringType() .allFields() .stream() - .map(f -> new JdbField(f, type)) + .map(f -> new JdbField(f, type, new VariablePathImpl(Collections.emptyList()))) .sorted(new JdbFieldComparator()) .collect(Collectors.toList())); } else { fields.set(object.referenceType() .allFields() .stream() - .map(f -> new JdbField(f, object)) + .map(f -> new JdbField(f, object, new VariablePathImpl(Collections.emptyList()))) .sorted(new JdbFieldComparator()) .collect(Collectors.toList())); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java index 2dabdced5a0..8e0c25ab3e9 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java @@ -17,6 +17,7 @@ import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.VariablePath; import java.util.Collections; import java.util.LinkedList; @@ -32,10 +33,12 @@ public class JdbValue implements SimpleValue { private final Value jdiValue; private final AtomicReference> variables; + private final VariablePath variablePath; - public JdbValue(Value jdiValue) { + public JdbValue(Value jdiValue, VariablePath variablePath) { this.jdiValue = jdiValue; this.variables = new AtomicReference<>(); + this.variablePath = variablePath; } @Override @@ -55,14 +58,14 @@ public List getVariables() { ArrayReference array = (ArrayReference)jdiValue; for (int i = 0; i < array.length(); i++) { - variables.get().add(new JdbArrayElement(array.getValue(i), i)); + variables.get().add(new JdbArrayElement(array.getValue(i), i, variablePath)); } } else { ObjectReference object = (ObjectReference)jdiValue; variables.set(object.referenceType() .allFields() .stream() - .map(f -> new JdbField(f, object)) + .map(f -> new JdbField(f, object, variablePath)) .sorted(new JdbFieldComparator()) .collect(Collectors.toList())); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java index a94af5c750b..8f262782eec 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java @@ -32,7 +32,7 @@ public JdbVariable(StackFrame jdiStackFrame, LocalVariable jdiVariable) { Value jdiValue = jdiStackFrame.getValue(jdiVariable); this.jdiVariable = jdiVariable; - this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue); + this.value = jdiValue == null ? new JdbNullValue() : new JdbValue(jdiValue, getVariablePath()); } public JdbVariable(SimpleValue value, LocalVariable jdiVariable) { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java index ba3b1d4b8e3..24586fbee40 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java @@ -14,7 +14,7 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; @@ -28,14 +28,15 @@ import org.testng.annotations.Test; import java.util.List; -import java.util.Optional; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.ensureSuspendAtDesiredLocation; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.findMainThreadId; import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.startJavaDebugger; import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @@ -48,6 +49,7 @@ public class GetValueTest1 { private JavaDebugger debugger; private BlockingQueue debuggerEvents; + private long mainThreadId; @BeforeClass public void setUp() throws Exception { @@ -59,6 +61,8 @@ public void setUp() throws Exception { debugger = startJavaDebugger(new BreakpointImpl(location), debuggerEvents); ensureSuspendAtDesiredLocation(location, debuggerEvents); + + mainThreadId = findMainThreadId(debugger); } @AfterClass @@ -70,12 +74,7 @@ public void tearDown() throws Exception { @Test(dataProvider = "getVariablePaths") public void shouldGetValue(List path, int frameIndex, String value) throws Exception { - Optional main = debugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); - assertTrue(main.isPresent()); - - ThreadDump mainThread = main.get(); - - SimpleValue debuggerValue = debugger.getValue(new VariablePathImpl(path), mainThread.getId(), frameIndex); + SimpleValue debuggerValue = debugger.getValue(new VariablePathImpl(path), mainThreadId, frameIndex); if (debuggerValue == null) { assertNull(value); @@ -96,17 +95,38 @@ public static Object[][] getVariablePaths() { {ImmutableList.of("args"), 0, null}}; } + @Test + public void shouldGetNestedVariables() throws Exception { + SimpleValue debuggerValue = debugger.getValue(new VariablePathImpl(ImmutableList.of("var1")), mainThreadId, 0); + + assertEquals(debuggerValue.getString(), "\"var1\""); + + Variable hashVar = debuggerValue.getVariables() + .stream() + .filter(v -> v.getName().equals("value")) + .findAny() + .get(); + assertNotNull(hashVar); + assertEquals(hashVar.getType(), "char[]"); + assertEquals(hashVar.getName(), "value"); + assertTrue(hashVar.getValue().getString().contains("instance of char[4]")); + assertEquals(hashVar.getVariablePath().getPath(), ImmutableList.of("var1", "value")); + + List valueVariables = hashVar.getValue().getVariables(); + for (int i = 0; i < 4; i++) { + Variable variable = valueVariables.get(i); + assertEquals(variable.getVariablePath().getPath(), ImmutableList.of("var1", "value", "[" + i + "]")); + assertEquals(variable.getValue().getString(), "var1".substring(i, i)); + } + } + @Test(dataProvider = "setVariable") public void shouldSetValue(List path, String newValue, int frameIndex) throws Exception { - Optional main = debugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); - assertTrue(main.isPresent()); - - ThreadDump mainThread = main.get(); + final VariablePathImpl variablePath = new VariablePathImpl(path); - VariablePathImpl variablePath = new VariablePathImpl(path); - debugger.setValue(new VariableImpl(new SimpleValueImpl(newValue), variablePath), mainThread.getId(), frameIndex); + debugger.setValue(new VariableImpl(new SimpleValueImpl(newValue), variablePath), mainThreadId, frameIndex); - SimpleValue debuggerValue = debugger.getValue(variablePath, mainThread.getId(), frameIndex); + SimpleValue debuggerValue = debugger.getValue(variablePath, mainThreadId, frameIndex); assertEquals(debuggerValue.getString(), newValue); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java index ac82af79309..3460e9195ec 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java @@ -11,18 +11,22 @@ package org.eclipse.che.plugin.jdb.server.util; import com.google.common.collect.ImmutableMap; +import com.sun.jdi.ThreadReference; import com.sun.jdi.VirtualMachine; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; import org.eclipse.che.plugin.jdb.server.JavaDebugger; import org.eclipse.che.plugin.jdb.server.JavaDebuggerFactory; import java.lang.reflect.Field; import java.util.Map; +import java.util.Optional; import java.util.concurrent.BlockingQueue; import static java.lang.System.getProperty; @@ -81,4 +85,14 @@ public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) thr // quietly ignore exception, if VM has been already terminated } } + + /** + * Iterates threads until main is found and returns its id. + * @see ThreadReference#uniqueID() + */ + public static long findMainThreadId(JavaDebugger javaDebugger) throws DebuggerException { + Optional main = javaDebugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); + main.orElseThrow(() -> new DebuggerException("Main thread not found")); + return main.get().getId(); + } } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index 734c7436734..861e9869ab1 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -149,10 +149,6 @@ default void suspend() throws DebuggerException { * if any error occur */ default SimpleValue getValue(VariablePath variablePath, long threadId, int frameIndex) throws DebuggerException { - if (threadId == -1 || frameIndex == -1) { - return getValue(variablePath); - } - throw new DebuggerException("Unsupported operation for current debugger implementation."); } @@ -183,11 +179,6 @@ default SimpleValue getValue(VariablePath variablePath, long threadId, int frame * if any error occur */ default void setValue(Variable variable, long threadId, int frameIndex) throws DebuggerException { - if (threadId == -1 || frameIndex == -1) { - setValue(variable); - return; - } - throw new DebuggerException("Unsupported operation for current debugger implementation."); } @@ -220,10 +211,6 @@ default void setValue(Variable variable, long threadId, int frameIndex) throws D * if any error occur */ default String evaluate(String expression, long threadId, int frameIndex) throws DebuggerException { - if (threadId == -1 || frameIndex == -1) { - return evaluate(expression); - } - throw new DebuggerException("Unsupported operation for current debugger implementation."); } @@ -292,10 +279,6 @@ default String evaluate(String expression, long threadId, int frameIndex) throws * if any error occur */ default StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws DebuggerException { - if (threadId == -1 || frameIndex == -1) { - return dumpStackFrame(); - } - throw new DebuggerException("Unsupported operation for current debugger implementation."); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index 92374264ada..d3f053b7a9d 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -174,6 +174,10 @@ public void deleteBreakpoint(@PathParam("id") String sessionId, public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId, @QueryParam("threadId") @DefaultValue("-1") long threadId, @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex) throws DebuggerException { + if (threadId == -1) { + return asDto(debuggerManager.getDebugger(sessionId).dumpStackFrame()); + + } return asDto(debuggerManager.getDebugger(sessionId).getStackFrameDump(threadId, frameIndex)); } @@ -205,6 +209,10 @@ public SimpleValueDto getValue(@PathParam("id") String sessionId, } VariablePath variablePath = new VariablePathImpl(path); + if (threadId == -1) { + return asDto(debuggerManager.getDebugger(sessionId).getValue(variablePath)); + } + return asDto(debuggerManager.getDebugger(sessionId).getValue(variablePath, threadId, frameIndex)); } @@ -215,7 +223,11 @@ public void setValue(@PathParam("id") String sessionId, @QueryParam("threadId") @DefaultValue("-1") long threadId, @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex, VariableDto variable) throws DebuggerException { - debuggerManager.getDebugger(sessionId).setValue(variable, threadId, frameIndex); + if (threadId == -1) { + debuggerManager.getDebugger(sessionId).setValue(variable); + } else { + debuggerManager.getDebugger(sessionId).setValue(variable, threadId, frameIndex); + } } @GET @@ -225,6 +237,10 @@ public String expression(@PathParam("id") String sessionId, @QueryParam("threadId") @DefaultValue("-1") long threadId, @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex, @QueryParam("expression") String expression) throws DebuggerException { + if (threadId == -1) { + return debuggerManager.getDebugger(sessionId).evaluate(expression); + } + return debuggerManager.getDebugger(sessionId).evaluate(expression, threadId, frameIndex); } } From 8ac3ddf9fc92b8ec0c5a91d0334f6908f5bd89de Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 18 Aug 2017 09:50:15 +0300 Subject: [PATCH 20/38] FixUp --- .../ide/api/debug/DebuggerServiceClient.java | 6 +- .../api/debug/DebuggerServiceClientImpl.java | 2 +- .../che/ide/debug/BreakpointManagerImpl.java | 5 +- .../org/eclipse/che/ide/debug/Debugger.java | 9 +- .../che/ide/debug/DebuggerObserver.java | 3 +- .../ide/DebuggerLocalizationConstant.java | 3 + .../debugger/ide/debug/AbstractDebugger.java | 38 ++-- .../debugger/ide/debug/DebuggerPresenter.java | 28 ++- .../debugger/ide/debug/DebuggerView.java | 18 ++ .../debugger/ide/debug/DebuggerViewImpl.java | 190 ++++++++++++------ .../ide/debug/DebuggerViewImpl.ui.xml | 17 ++ .../DebuggerLocalizationConstant.properties | 7 +- .../ide/debug/DebuggerPresenterTest.java | 6 +- .../plugin/jdb/server/model/JdbLocation.java | 27 ++- .../jdb/server/utils/JavaDebuggerUtils.java | 4 +- .../zdb/server/ZendDbgLocationHandler.java | 8 +- .../che/api/debug/shared/dto/LocationDto.java | 7 + .../che/api/debug/shared/model/Location.java | 5 + .../debug/shared/model/impl/LocationImpl.java | 29 ++- 19 files changed, 293 insertions(+), 119 deletions(-) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java index 8570184e865..071fd1afa5d 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java @@ -13,8 +13,8 @@ import org.eclipse.che.api.debug.shared.dto.BreakpointDto; import org.eclipse.che.api.debug.shared.dto.DebugSessionDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; -import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; +import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; @@ -128,12 +128,12 @@ public interface DebuggerServiceClient { Promise getStackFrameDump(String id); /** - * Gets thread dumps. + * Gets thread dump. * * @param id * debug session id */ - Promise> getThreadDumps(String id); + Promise> getThreadDump(String id); /** * Resumes application. diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java index 6effda393ce..3f3f5e54394 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java @@ -134,7 +134,7 @@ public Promise getStackFrameDump(String id) { } @Override - public Promise> getThreadDumps(String id) { + public Promise> getThreadDump(String id) { final String requestUrl = getBaseUrl(id) + "/threaddump"; return asyncRequestFactory.createGetRequest(requestUrl) .send(dtoUnmarshallerFactory.newListUnmarshaller(ThreadDumpDto.class)); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java index 1653244e9b4..9a423450a31 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java @@ -14,6 +14,7 @@ import com.google.inject.Inject; import com.google.web.bindery.event.shared.EventBus; +import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; import org.eclipse.che.commons.annotation.Nullable; @@ -601,8 +602,8 @@ public void onPreResume() { } @Override - public void onBreakpointStopped(String filePath, String className, int lineNumber) { - setCurrentBreakpoint(filePath, lineNumber - 1); + public void onBreakpointStopped(String filePath, Location location) { + setCurrentBreakpoint(filePath, location.getLineNumber() - 1); } @Override diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 73bf65a9938..07b4706f5aa 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -10,12 +10,14 @@ *******************************************************************************/ package org.eclipse.che.ide.debug; -import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.ide.api.resources.VirtualFile; +import java.util.List; import java.util.Map; /** @@ -108,6 +110,11 @@ public interface Debugger extends DebuggerObservable { */ Promise dumpStackFrame(); + /** + * Gets thread dump. + */ + Promise> getThreadDump(); + /** * Updates the value of the given variable. * diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java index 5b9391c7acd..44ec1ff3290 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.ide.debug; +import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.ide.api.debug.Breakpoint; @@ -73,7 +74,7 @@ public interface DebuggerObserver { /** * Event happens when debugger stopped at breakpoint. */ - void onBreakpointStopped(String filePath, String className, int lineNumber); + void onBreakpointStopped(String filePath, Location location); /** * Event happens when value changed. diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.java index 9d0c046f721..69d17b16250 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.java @@ -199,4 +199,7 @@ public interface DebuggerLocalizationConstant extends com.google.gwt.i18n.client @Key("view.editConfigurations.saveChanges.discard") String editConfigurationsSaveChangesDiscard(); + + @Key("debugger.frames.title") + String debuggerFramesTitle(); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index c75e87129e6..71a22784d3f 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -22,6 +22,7 @@ import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; @@ -173,7 +174,7 @@ public void onWsAgentStarted(WsAgentStateEvent event) { } if (currentLocation != null) { - openCurrentFile(); + openCurrentFile(currentLocation); } startCheckingEvents(); @@ -189,11 +190,10 @@ public void onWsAgentStopped(WsAgentStateEvent event) { } private void onEventListReceived(@NotNull DebuggerEventDto event) { - LocationDto newLocationDto; - switch (event.getType()) { case SUSPEND: - newLocationDto = ((SuspendEventDto)event).getLocation(); + currentLocation = ((SuspendEventDto)event).getLocation(); + openCurrentFile(currentLocation); break; case BREAKPOINT_ACTIVATED: BreakpointDto breakpointDto = ((BreakpointActivatedEventDto)event).getBreakpoint(); @@ -207,42 +207,31 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) { return; } - if (newLocationDto != null) { - currentLocation = newLocationDto; - openCurrentFile(); - } - preserveDebuggerState(); } - private void openCurrentFile() { + private void openCurrentFile(Location location) { //todo we need add possibility to handle few files try { - activeFileHandler.openFile(currentLocation, + activeFileHandler.openFile(location, new AsyncCallback() { @Override public void onFailure(Throwable caught) { for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(currentLocation.getTarget(), - currentLocation.getTarget(), - currentLocation.getLineNumber()); + observer.onBreakpointStopped(location.getTarget(), location); } } @Override public void onSuccess(VirtualFile result) { for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(result.getLocation().toString(), - currentLocation.getTarget(), - currentLocation.getLineNumber()); + observer.onBreakpointStopped(result.getLocation().toString(), location); } } }); } catch (Exception e) { for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(currentLocation.getTarget(), - currentLocation.getTarget(), - currentLocation.getLineNumber()); + observer.onBreakpointStopped(location.getTarget(), location); } } } @@ -331,6 +320,15 @@ public Promise dumpStackFrame() { return stackFrameDump.then((Function)StackFrameDumpImpl::new); } + @Override + public Promise> getThreadDump() { + if (!isConnected()) { + return Promises.reject(JsPromiseError.create("Debugger is not connected")); + } + + return service.getThreadDump(debugSessionDto.getId()); + } + @Override public void addBreakpoint(final VirtualFile file, final int lineNumber) { if (isConnected()) { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index e851bbdf92d..6dccf58156f 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -19,8 +19,8 @@ import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; -import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.Promise; @@ -47,6 +47,7 @@ import javax.validation.constraints.NotNull; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; @@ -82,6 +83,7 @@ public class DebuggerPresenter extends BasePresenter implements DebuggerView.Act private MutableVariable selectedVariable; private List variables; + private List threadDump; private DebuggerDescriptor debuggerDescriptor; private Location executionPoint; @@ -104,6 +106,7 @@ public DebuggerPresenter(final DebuggerView view, this.constant = constant; this.breakpointManager = breakpointManager; this.variables = new ArrayList<>(); + this.threadDump = new ArrayList<>(); this.notificationManager = notificationManager; this.addRule(ProjectPerspective.PROJECT_PERSPECTIVE_ID); @@ -191,9 +194,12 @@ public boolean isDebuggerPanelPresent() { private void resetStates() { variables.clear(); + threadDump.clear(); view.setVariables(variables); view.setVMName(""); view.setExecutionPoint(null); + view.clearThreads(); + view.setFrames(Collections.emptyList()); selectedVariable = null; executionPoint = null; } @@ -208,6 +214,8 @@ public void showAndUpdateView() { view.setExecutionPoint(executionPoint); } view.setBreakpoints(breakpointManager.getBreakpointList()); + + updateThreadDump(); updateStackFrameDump(); showView(); @@ -228,6 +236,20 @@ public void showView() { } } + private void updateThreadDump() { + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null && executionPoint != null) { + debugger.getThreadDump() + .then(threadDump -> { + view.setThreads(threadDump, executionPoint.getThreadId()); + view.setFrames(threadDump.get(0).getFrames()); + }) + .catchError(error -> { + Log.error(DebuggerPresenter.class, error.getCause()); + }); + } + } + private void updateStackFrameDump() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null && executionPoint != null) { @@ -340,8 +362,8 @@ public void onPreResume() { } @Override - public void onBreakpointStopped(String filePath, String className, int lineNumber) { - executionPoint = new LocationImpl(className, lineNumber); + public void onBreakpointStopped(String filePath, Location location) { + executionPoint = location; showAndUpdateView(); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index a1b40f805fb..abeb6c341fc 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -14,6 +14,8 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.ide.api.mvp.View; import org.eclipse.che.ide.api.parts.base.BaseActionDelegate; @@ -68,6 +70,22 @@ interface ActionDelegate extends BaseActionDelegate { */ void setBreakpoints(@NotNull List breakPoints); + /** + * Sets the list of the threads and select the one + * with {@link ThreadDump#getId()} equal to {@code activeThreadId}. + */ + void setThreads(@NotNull List threadDumps, long activeThreadId); + + /** + * Clears the list of threads. + */ + void clearThreads(); + + /** + * Sets the list of frames for selected thread. + */ + void setFrames(@NotNull List stackFrameDumps); + /** * Sets java virtual machine name and version. * diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 548e6a51e71..08f14cc64f4 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -21,6 +21,7 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.ui.AcceptsOneWidget; import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.ScrollPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.SplitLayoutPanel; @@ -30,13 +31,15 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.impl.MutableVariableImpl; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.Resources; +import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.parts.PartStackUIResources; import org.eclipse.che.ide.api.parts.base.BaseView; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.ui.list.SimpleList; import org.eclipse.che.ide.ui.tree.Tree; import org.eclipse.che.ide.ui.tree.TreeNodeElement; @@ -47,6 +50,7 @@ import org.vectomatic.dom.svg.ui.SVGResource; import javax.validation.constraints.NotNull; +import java.util.ArrayList; import java.util.List; /** @@ -77,10 +81,15 @@ interface DebuggerViewImplUiBinder extends UiBinder { Resources coreRes; @UiField(provided = true) SplitLayoutPanel splitPanel = new SplitLayoutPanel(3); + @UiField + ListBox threads; + @UiField + ScrollPanel framesPanel; - private final Tree variables; - private final SimpleList breakpoints; - private final DebuggerResources res; + private final Tree variables; + private final SimpleList breakpoints; + private final SimpleList frames; + private final DebuggerResources res; private TreeNodeElement selectedVariable; @@ -99,6 +108,66 @@ protected DebuggerViewImpl(PartStackUIResources partStackUIResources, setContentWidget(uiBinder.createAndBindUi(this)); + this.breakpoints = createBreakpointSimpleList(); + this.breakpointsPanel.add(breakpoints); + + this.frames = createFramesSimpleList(); + this.framesPanel.add(frames); + + this.variables = Tree.create(rendererResources, new VariableNodeDataAdapter(), new VariableTreeNodeRenderer(rendererResources)); + this.variables.setTreeEventHandler(new Tree.Listener() { + @Override + public void onNodeAction(@NotNull TreeNodeElement node) { + } + + @Override + public void onNodeClosed(@NotNull TreeNodeElement node) { + selectedVariable = null; + } + + @Override + public void onNodeContextMenu(int mouseX, int mouseY, @NotNull TreeNodeElement node) { + } + + @Override + public void onNodeDragStart(@NotNull TreeNodeElement node, @NotNull MouseEvent event) { + } + + @Override + public void onNodeDragDrop(@NotNull TreeNodeElement node, @NotNull MouseEvent event) { + } + + @Override + public void onNodeExpanded(@NotNull final TreeNodeElement node) { + selectedVariable = node; + delegate.onSelectedVariableElement(selectedVariable.getData()); + delegate.onExpandVariablesTree(); + } + + @Override + public void onNodeSelected(@NotNull TreeNodeElement node, @NotNull SignalEvent event) { + selectedVariable = node; + delegate.onSelectedVariableElement(selectedVariable.getData()); + } + + @Override + public void onRootContextMenu(int mouseX, int mouseY) { + } + + @Override + public void onRootDragDrop(@NotNull MouseEvent event) { + } + + @Override + public void onKeyboard(@NotNull KeyboardEvent event) { + } + }); + + this.variablesPanel.add(variables); + minimizeButton.ensureDebugId("debugger-minimizeBut"); + } + + private SimpleList createBreakpointSimpleList() { TableElement breakPointsElement = Elements.createTableElement(); breakPointsElement.setAttribute("style", "width: 100%"); SimpleList.ListEventDelegate breakpointListEventDelegate = new SimpleList.ListEventDelegate() { @@ -147,65 +216,53 @@ public Element createElement() { } }; - breakpoints = SimpleList.create((SimpleList.View)breakPointsElement, - coreRes.defaultSimpleListCss(), - breakpointListItemRenderer, - breakpointListEventDelegate); - this.breakpointsPanel.add(breakpoints); - this.variables = Tree.create(rendererResources, new VariableNodeDataAdapter(), new VariableTreeNodeRenderer(rendererResources)); - this.variables.setTreeEventHandler(new Tree.Listener() { - @Override - public void onNodeAction(@NotNull TreeNodeElement node) { - } - - @Override - public void onNodeClosed(@NotNull TreeNodeElement node) { - selectedVariable = null; - } - - @Override - public void onNodeContextMenu(int mouseX, int mouseY, @NotNull TreeNodeElement node) { - } + return SimpleList.create((SimpleList.View)breakPointsElement, + coreRes.defaultSimpleListCss(), + breakpointListItemRenderer, + breakpointListEventDelegate); + } - @Override - public void onNodeDragStart(@NotNull TreeNodeElement node, @NotNull MouseEvent event) { - } + private SimpleList createFramesSimpleList() { + TableElement frameElement = Elements.createTableElement(); + frameElement.setAttribute("style", "width: 100%"); - @Override - public void onNodeDragDrop(@NotNull TreeNodeElement node, @NotNull MouseEvent event) { + SimpleList.ListEventDelegate frameListEventDelegate = new SimpleList.ListEventDelegate() { + public void onListItemClicked(Element itemElement, StackFrameDump itemData) { + frames.getSelectionModel().setSelectedItem(itemData); } - @Override - public void onNodeExpanded(@NotNull final TreeNodeElement node) { - selectedVariable = node; - delegate.onSelectedVariableElement(selectedVariable.getData()); - delegate.onExpandVariablesTree(); - } + public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) { } + }; - @Override - public void onNodeSelected(@NotNull TreeNodeElement node, @NotNull SignalEvent event) { - selectedVariable = node; - delegate.onSelectedVariableElement(selectedVariable.getData()); - } + SimpleList.ListItemRenderer frameListItemRenderer = new + SimpleList.ListItemRenderer() { + @Override + public void render(Element itemElement, StackFrameDump itemData) { + TableCellElement label = Elements.createTDElement(); - @Override - public void onRootContextMenu(int mouseX, int mouseY) { - } + SafeHtmlBuilder sb = new SafeHtmlBuilder(); + sb.appendEscaped(itemData.getLocation().getMethod().getName()); + sb.appendEscaped("():"); + sb.append(itemData.getLocation().getLineNumber()); + sb.appendEscaped(", "); + sb.appendEscaped(itemData.getLocation().getTarget()); - @Override - public void onRootDragDrop(@NotNull MouseEvent event) { - } + label.setInnerHTML(sb.toSafeHtml().asString()); + itemElement.appendChild(label); + } - @Override - public void onKeyboard(@NotNull KeyboardEvent event) { - } - }); + @Override + public Element createElement() { + return Elements.createTRElement(); + } + }; - this.variablesPanel.add(variables); - minimizeButton.ensureDebugId("debugger-minimizeBut"); + return SimpleList.create((SimpleList.View)frameElement, + coreRes.defaultSimpleListCss(), + frameListItemRenderer, + frameListEventDelegate); } - /** {@inheritDoc} */ @Override public void setExecutionPoint(@Nullable Location location) { StringBuilder labelText = new StringBuilder(); @@ -216,7 +273,6 @@ public void setExecutionPoint(@Nullable Location location) { executionPoint.setText(labelText.toString()); } - /** {@inheritDoc} */ @Override public void setVariables(@NotNull List variables) { MutableVariable root = this.variables.getModel().getRoot(); @@ -228,26 +284,46 @@ public void setVariables(@NotNull List variables) { this.variables.renderTree(0); } - /** {@inheritDoc} */ @Override public void setBreakpoints(@NotNull List breakpoints) { this.breakpoints.render(breakpoints); } - /** {@inheritDoc} */ + @Override + public void setThreads(List threadDumps, long activeThreadId) { + clearThreads(); + + for (int i = 0; i < threadDumps.size(); i++) { + ThreadDump threadDump = threadDumps.get(i); + + threads.addItem(threadDump.getName(), String.valueOf(threadDump.getId())); + if (threadDump.getId() == activeThreadId) { + threads.setSelectedIndex(i); + } + } + } + + @Override + public void clearThreads() { + threads.clear(); + } + + @Override + public void setFrames(List stackFrameDumps) { + frames.render(new ArrayList<>(stackFrameDumps)); + } + @Override public void setVMName(@NotNull String name) { vmName.setText(name); } - /** {@inheritDoc} */ @Override public void updateSelectedVariable() { variables.closeNode(selectedVariable); variables.expandNode(selectedVariable); } - /** {@inheritDoc} */ @Override public void setVariablesIntoSelectedVariable(@NotNull List variables) { MutableVariable rootVariable = selectedVariable.getData(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml index 52f2e77285f..bc603c664ed 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml @@ -58,6 +58,23 @@ + + + + + + + + + + + + + + + diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/resources/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.properties b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/resources/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.properties index 7849f1e70fd..56091b9458a 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/resources/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.properties +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/resources/org/eclipse/che/plugin/debugger/ide/DebuggerLocalizationConstant.properties @@ -11,9 +11,9 @@ ##### Actions ##### editDebugConfigurationsActionTitle=Edit Debug Configurations... -breakpoints = Breakpoints +breakpoints = Breakpoints: debug = Debug -variables = Variables +variables = Variables: host = Host: port = Port: debugActionTitle=Debug @@ -80,3 +80,6 @@ view.editConfigurations.remove.confirmation=Do you want to remove the {0} view.editConfigurations.saveChanges.title=Unsaved changes view.editConfigurations.saveChanges.text=Configuration {0} has been changed.
    Do you want to save it? view.editConfigurations.saveChanges.discard=Discard changes + +############### ThreadDumps ################ +debugger.frames.title=Frames: diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index 1174808516b..f4f0fd7def7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -278,9 +278,7 @@ public void testOnAllBreakpointsDeleted() { @Test public void testOnBreakpointStopped() { - String filePath = "filePath"; - String className = "className"; - int lineNumber = 40; + final String filePath = "filePath"; LocationDto executionPoint = mock(LocationDto.class); doReturn(executionPoint).when(dtoFactory).createDto(LocationDto.class); @@ -288,7 +286,7 @@ public void testOnBreakpointStopped() { doReturn(promiseString).when(debugger).dumpStackFrame(); doReturn(promiseString).when(promiseString).then((Operation)any()); - presenter.onBreakpointStopped(filePath, className, lineNumber); + presenter.onBreakpointStopped(filePath, executionPoint); verify(presenter).showAndUpdateView(); verify(view).setExecutionPoint(any(Location.class)); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java index a4af9be03f8..a24a2d2fc86 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java @@ -26,46 +26,48 @@ public class JdbLocation implements Location { private static final JavaDebuggerUtils debuggerUtil = new JavaDebuggerUtils(); - private final Method method; - private final Location location; + private final Method method; + private final Location internal; + private final StackFrame jdiStackFrame; public JdbLocation(StackFrame stackFrame) { this(stackFrame, new JdbMethod(stackFrame)); } - public JdbLocation(StackFrame stackFrame, Method method) { - this.location = getLocation(stackFrame.location()); + public JdbLocation(StackFrame jdiStackFrame, Method method) { + this.jdiStackFrame = jdiStackFrame; + this.internal = getLocation(jdiStackFrame.location()); this.method = method; } @Override public String getTarget() { - return location.getTarget(); + return internal.getTarget(); } @Override public int getLineNumber() { - return location.getLineNumber(); + return internal.getLineNumber(); } @Override public String getResourcePath() { - return location.getResourcePath(); + return internal.getResourcePath(); } @Override public boolean isExternalResource() { - return location.isExternalResource(); + return internal.isExternalResource(); } @Override public int getExternalResourceId() { - return location.getExternalResourceId(); + return internal.getExternalResourceId(); } @Override public String getResourceProjectPath() { - return location.getResourceProjectPath(); + return internal.getResourceProjectPath(); } @Override @@ -73,6 +75,11 @@ public Method getMethod() { return method; } + @Override + public long getThreadId() { + return jdiStackFrame.thread().uniqueID(); + } + private Location getLocation(com.sun.jdi.Location jdiLocation) { try { return debuggerUtil.getLocation(jdiLocation); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java index 201639623b9..d5c89e3c6de 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java @@ -81,12 +81,12 @@ public Location getLocation(com.sun.jdi.Location location) throws DebuggerExcept if (type.isBinary()) { IClassFile classFile = type.getClassFile(); int libId = classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode(); - return new LocationImpl(fqn, location.lineNumber(), null, true, libId, typeProjectPath, null); + return new LocationImpl(fqn, location.lineNumber(), null, true, libId, typeProjectPath, null, -1); } else { ICompilationUnit compilationUnit = type.getCompilationUnit(); typeProjectPath = type.getJavaProject().getPath().toOSString(); String resourcePath = compilationUnit.getPath().toOSString(); - return new LocationImpl(fqn, location.lineNumber(), resourcePath, false, -1, typeProjectPath, null); + return new LocationImpl(fqn, location.lineNumber(), resourcePath, false, -1, typeProjectPath, null, -1); } } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java index 4172cef9205..3c6c6646235 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java @@ -26,11 +26,11 @@ public class ZendDbgLocationHandler { public static final Location createVFS(String target, String resourcePath, String resourceProjectPath, int lineNumber) { - return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath, null); + return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath, null, -1); } public static final Location createDBG(String resourcePath, int lineNumber) { - return new LocationImpl(Path.of(resourcePath).getName(), lineNumber, resourcePath, false, 0, null, null); + return new LocationImpl(Path.of(resourcePath).getName(), lineNumber, resourcePath, false, 0, null, null, -1); } /** @@ -48,7 +48,7 @@ public Location convertToVFS(Location dbgLocation) { String target = localFileEntry.getName(); String resourcePath = localFileEntry.getPath().toString(); int lineNumber = dbgLocation.getLineNumber(); - return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath, dbgLocation.getMethod()); + return new LocationImpl(target, lineNumber, resourcePath, false, 0, resourceProjectPath, dbgLocation.getMethod(), dbgLocation.getThreadId()); } /** @@ -60,6 +60,6 @@ public Location convertToVFS(Location dbgLocation) { public Location convertToDBG(Location vfsLocation) { String resourcePath = ZendDbgFileUtils.findAbsolutePath(vfsLocation.getResourcePath()); int lineNumber = vfsLocation.getLineNumber(); - return new LocationImpl(null, lineNumber, resourcePath, false, 0, null, vfsLocation.getMethod()); + return new LocationImpl(null, lineNumber, resourcePath, false, 0, null, vfsLocation.getMethod(), vfsLocation.getThreadId()); } } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java index 90506d5abaf..5caffa97a3d 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java @@ -48,4 +48,11 @@ public interface LocationDto extends Location { void setMethod(MethodDto method); LocationDto withMethod(MethodDto method); + + @Override + long getThreadId(); + + void setThreadId(long threadId); + + LocationDto withThreadId(long threadId); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java index 0023a9adfeb..1f00da3d4ba 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java @@ -51,4 +51,9 @@ public interface Location { */ @Nullable Method getMethod(); + + /** + * Returns thread id. + */ + long getThreadId(); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java index 0708210552d..6c36cc5a75c 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java @@ -13,7 +13,7 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.Method; -import java.util.Objects; +import static com.google.common.base.Objects.equal; /** * @author Anatoliy Bazko @@ -26,6 +26,7 @@ public class LocationImpl implements Location { private final int externalResourceId; private final String resourceProjectPath; private final Method method; + private final long threadId; public LocationImpl(String target, int lineNumber, @@ -33,7 +34,8 @@ public LocationImpl(String target, boolean externalResource, int externalResourceId, String resourceProjectPath, - Method method) { + Method method, + long threadId) { this.target = target; this.lineNumber = lineNumber; this.resourcePath = resourcePath; @@ -41,14 +43,15 @@ public LocationImpl(String target, this.externalResourceId = externalResourceId; this.resourceProjectPath = resourceProjectPath; this.method = method; + this.threadId = threadId; } public LocationImpl(String target, int lineNumber) { - this(target, lineNumber, null, false, 0, null, null); + this(target, lineNumber, null, false, 0, null, null, -1); } public LocationImpl(String target) { - this(target, 0, null, false, 0, null, null); + this(target, 0, null, false, 0, null, null, -1); } @Override @@ -86,6 +89,11 @@ public Method getMethod() { return method; } + @Override + public long getThreadId() { + return threadId; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -94,15 +102,17 @@ public boolean equals(Object o) { return lineNumber == location.lineNumber && externalResource == location.externalResource && externalResourceId == location.externalResourceId && - Objects.equals(target, location.target) && - Objects.equals(resourcePath, location.resourcePath) && - Objects.equals(resourceProjectPath, location.resourceProjectPath) && - Objects.equals(method, location.method); + threadId == location.threadId && + equal(target, location.target) && + equal(resourcePath, location.resourcePath) && + equal(resourceProjectPath, location.resourceProjectPath) && + equal(method, location.method); } @Override public int hashCode() { - return Objects.hash(target, lineNumber, resourcePath, externalResource, externalResourceId, resourceProjectPath, method); + return com.google.common.base.Objects + .hashCode(target, lineNumber, resourcePath, externalResource, externalResourceId, resourceProjectPath, method, threadId); } @Override @@ -115,6 +125,7 @@ public String toString() { ", externalResourceId=" + externalResourceId + ", resourceProjectPath='" + resourceProjectPath + '\'' + ", method=" + method + + ", threadId=" + threadId + '}'; } } From 70b4d1484c7ef91e04c5cf69d757735ad42192c5 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 18 Aug 2017 11:01:51 +0300 Subject: [PATCH 21/38] Fix tests --- .../che-plugin-java-debugger-server/pom.xml | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml index 92108dc4081..f6efe7466af 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml @@ -296,9 +296,6 @@ Listening for transport dt_socket at address: 8001 - - always - From 1c55a7634e7511cf9ce8b31275dc2b9806666c89 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 18 Aug 2017 17:13:32 +0300 Subject: [PATCH 22/38] Client side part --- .../ide/api/debug/DebuggerServiceClient.java | 33 +++- .../api/debug/DebuggerServiceClientImpl.java | 21 +- .../org/eclipse/che/ide/debug/Debugger.java | 35 +++- .../actions/ShowHideDebuggerPanelAction.java | 2 +- .../debugger/ide/debug/AbstractDebugger.java | 16 +- .../debugger/ide/debug/DebuggerPresenter.java | 186 +++++++++--------- .../debugger/ide/debug/DebuggerView.java | 21 +- .../debugger/ide/debug/DebuggerViewImpl.java | 76 +++---- .../ide/debug/DebuggerViewImpl.ui.xml | 10 +- .../changevalue/ChangeValuePresenter.java | 10 +- .../EvaluateExpressionPresenter.java | 40 ++-- .../ide/debug/DebuggerPresenterTest.java | 10 +- .../debugger/ide/debug/DebuggerTest.java | 10 +- .../che-plugin-java-debugger-server/pom.xml | 16 -- .../che/plugin/jdb/server/JavaDebugger.java | 5 +- .../plugin/jdb/server/model/JdbMethod.java | 9 +- .../jdb/server/model/JdbStackFrame.java | 3 +- .../api/debugger/server/DebuggerService.java | 18 +- .../che/api/debugger/server/DtoConverter.java | 1 + 19 files changed, 278 insertions(+), 244 deletions(-) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java index 071fd1afa5d..fa6ce852243 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java @@ -120,12 +120,17 @@ public interface DebuggerServiceClient { Promise> getAllBreakpoints(String id); /** - * Gets dump of fields and local variables of the current frame. + * Gets the stack frame dump. * * @param id * debug session id + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread + * */ - Promise getStackFrameDump(String id); + Promise getStackFrameDump(String id, long threadId, int frameIndex); /** * Gets thread dump. @@ -144,20 +149,28 @@ public interface DebuggerServiceClient { Promise resume(String id, ResumeActionDto action); /** - * Returns a value of the variable. + * Returns a value of the variable in the specific frame. * * @param id * debug session id + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - Promise getValue(String id, VariableDto variableDto); + Promise getValue(String id, VariableDto variableDto, long threadId, int frameIndex); /** - * Sets the new value of the variable. + * Sets the new value of the variable in the specific frame. * * @param id * debug session id + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - Promise setValue(String id, VariableDto variableDto); + Promise setValue(String id, VariableDto variableDto, long threadId, int frameIndex); /** * Does step into. @@ -190,12 +203,16 @@ public interface DebuggerServiceClient { Promise stepOut(String id, StepOutActionDto action); /** - * Evaluate the expression. + * Evaluate the expression inside specific frame. * * @param id * debug session id * @param expression * the expression to evaluate + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - Promise evaluate(String id, String expression); + Promise evaluate(String id, String expression, long threadId, int frameIndex); } diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java index 3f3f5e54394..7d0269bf849 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java @@ -127,8 +127,8 @@ public Promise deleteAllBreakpoints(String id) { } @Override - public Promise getStackFrameDump(String id) { - final String requestUrl = getBaseUrl(id) + "/dump"; + public Promise getStackFrameDump(String id, long threadId, int frameIndex) { + final String requestUrl = getBaseUrl(id) + "/stackframedump?thread=" + threadId + "&frame=" + frameIndex; return asyncRequestFactory.createGetRequest(requestUrl) .send(dtoUnmarshallerFactory.newUnmarshaller(StackFrameDumpDto.class)); } @@ -146,14 +146,13 @@ public Promise resume(String id, ResumeActionDto action) { } @Override - public Promise getValue(String id, VariableDto variableDto) { - final String requestUrl = getBaseUrl(id) + "/value"; + public Promise getValue(String id, VariableDto variableDto, long threadId, int frameIndex) { + final String requestUrl = getBaseUrl(id) + "/value?thread=" + threadId + "&frame=" + frameIndex; List path = variableDto.getVariablePath().getPath(); StringBuilder params = new StringBuilder(); for (int i = 0; i < path.size(); i++) { - params.append(i == 0 ? "?" : "&"); - params.append("path"); + params.append("&path"); params.append(i); params.append("="); params.append(path.get(i)); @@ -164,8 +163,8 @@ public Promise getValue(String id, VariableDto variableDto) { } @Override - public Promise setValue(String id, VariableDto variableDto) { - final String requestUrl = getBaseUrl(id) + "/value"; + public Promise setValue(String id, VariableDto variableDto, long threadId, int frameIndex) { + final String requestUrl = getBaseUrl(id) + "/value?thread=" + threadId + "&frame=" + frameIndex; return asyncRequestFactory.createPutRequest(requestUrl, variableDto) .send(); } @@ -186,9 +185,9 @@ public Promise stepOut(String id, StepOutActionDto action) { } @Override - public Promise evaluate(String id, String expression) { - String requestUrl = getBaseUrl(id) + "/evaluation"; - String params = "?expression=" + URL.encodeQueryString(expression); + public Promise evaluate(String id, String expression, long threadId, int frameIndex) { + String requestUrl = getBaseUrl(id) + "/evaluation?thread=" + threadId + "&frame=" + frameIndex; + String params = "&expression=" + URL.encodeQueryString(expression); return asyncRequestFactory.createGetRequest(requestUrl + params) .loader(loaderFactory.newLoader()) .send(new StringUnmarshaller()); diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 07b4706f5aa..841868ee899 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -96,19 +96,36 @@ public interface Debugger extends DebuggerObservable { void suspend(); /** - * Evaluates the given expression + * Evaluates the given expression inside specific frame. + * + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - Promise evaluate(String expression); + Promise evaluate(String expression, long threadId, int frameIndex); /** - * Gets the value of the given variable. + * Gets the value of the given variable inside specific frame. + * + * @param variable + * the variable to get value from + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - Promise getValue(Variable variable); + Promise getValue(Variable variable, long threadId, int frameIndex); /** - * Gets dump the current frame. + * Gets stack frame dump. + * + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - Promise dumpStackFrame(); + Promise getStackFrameDump(long threadId, int frameIndex); /** * Gets thread dump. @@ -120,8 +137,12 @@ public interface Debugger extends DebuggerObservable { * * @param variable * the variable to update + * @param threadId + * the unique thread id + * @param frameIndex + * the frame index in the thread */ - void setValue(Variable variable); + void setValue(Variable variable, long threadId, int frameIndex); /** * Indicates if connection is established with the server. diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java index 8a5deb7412c..ac98015af14 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java @@ -43,7 +43,7 @@ public void actionPerformed(ActionEvent e) { debuggerPresenter.showDebuggerPanel(); } } else { - debuggerPresenter.showAndUpdateView(); + debuggerPresenter.updateView(); debuggerPresenter.showDebuggerPanel(); } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 71a22784d3f..7c60e42a1f2 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -301,22 +301,22 @@ private void unsubscribeFromDebuggerEvents() { } @Override - public Promise getValue(Variable variable) { + public Promise getValue(Variable variable, long threadId, int frameIndex) { if (!isConnected()) { return Promises.reject(JsPromiseError.create("Debugger is not connected")); } - Promise promise = service.getValue(debugSessionDto.getId(), toDto(variable)); + Promise promise = service.getValue(debugSessionDto.getId(), toDto(variable), threadId, frameIndex); return promise.then((Function)SimpleValueImpl::new); } @Override - public Promise dumpStackFrame() { + public Promise getStackFrameDump(long threadId, int frameIndex) { if (!isConnected()) { return Promises.reject(JsPromiseError.create("Debugger is not connected")); } - Promise stackFrameDump = service.getStackFrameDump(debugSessionDto.getId()); + Promise stackFrameDump = service.getStackFrameDump(debugSessionDto.getId(), threadId, frameIndex); return stackFrameDump.then((Function)StackFrameDumpImpl::new); } @@ -584,18 +584,18 @@ public void suspend() { } @Override - public Promise evaluate(String expression) { + public Promise evaluate(String expression, long threadId, int frameIndex) { if (isConnected()) { - return service.evaluate(debugSessionDto.getId(), expression); + return service.evaluate(debugSessionDto.getId(), expression, threadId, frameIndex); } return Promises.reject(JsPromiseError.create("Debugger is not connected")); } @Override - public void setValue(final Variable variable) { + public void setValue(final Variable variable,long threadId, int frameIndex) { if (isConnected()) { - Promise promise = service.setValue(debugSessionDto.getId(), toDto(variable)); + Promise promise = service.setValue(debugSessionDto.getId(), toDto(variable), threadId, frameIndex); promise.then(it -> { for (DebuggerObserver observer : observers) { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 6dccf58156f..cf3203095c9 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -21,10 +21,7 @@ import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; -import org.eclipse.che.api.promises.client.Operation; -import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.Promise; -import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointManager; @@ -47,9 +44,9 @@ import javax.validation.constraints.NotNull; import java.util.ArrayList; -import java.util.Collections; import java.util.List; +import static java.util.Collections.emptyList; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; @@ -81,11 +78,13 @@ public class DebuggerPresenter extends BasePresenter implements DebuggerView.Act private final DebuggerManager debuggerManager; private final WorkspaceAgent workspaceAgent; - private MutableVariable selectedVariable; - private List variables; - private List threadDump; - private DebuggerDescriptor debuggerDescriptor; - private Location executionPoint; + private MutableVariable selectedVariable; + private List variables; + private List threadDump; + private DebuggerDescriptor debuggerDescriptor; + private Location executionPoint; + private long selectedThreadId; + private int selectedFrameIndex; @Inject public DebuggerPresenter(final DebuggerView view, @@ -105,17 +104,13 @@ public DebuggerPresenter(final DebuggerView view, this.view.setTitle(TITLE); this.constant = constant; this.breakpointManager = breakpointManager; - this.variables = new ArrayList<>(); - this.threadDump = new ArrayList<>(); this.notificationManager = notificationManager; this.addRule(ProjectPerspective.PROJECT_PERSPECTIVE_ID); - this.debuggerManager.addObserver(this); this.breakpointManager.addObserver(this); - if (!breakpointManager.getBreakpointList().isEmpty()) { - updateBreakpoints(); - } + resetState(); + updateBreakpoints(); } @Override @@ -141,7 +136,6 @@ public String getTitleToolTip() { @Override public void go(AcceptsOneWidget container) { view.setBreakpoints(breakpointManager.getBreakpointList()); - view.setVariables(variables); container.setWidget(view); debuggerToolbar.go(view.getDebuggerToolbarPanel()); } @@ -152,20 +146,14 @@ public void onExpandVariablesTree() { if (rootVariables.isEmpty()) { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { - Promise promise = debugger.getValue(selectedVariable); - - promise.then(new Operation() { - @Override - public void apply(SimpleValue arg) throws OperationException { - selectedVariable.setValue(arg); - view.setVariablesIntoSelectedVariable(arg.getVariables()); - view.updateSelectedVariable(); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError arg) throws OperationException { - notificationManager.notify(constant.failedToGetVariableValueTitle(), arg.getMessage(), FAIL, FLOAT_MODE); - } + Promise promise = debugger.getValue(selectedVariable, selectedThreadId, selectedFrameIndex); + + promise.then(value -> { + selectedVariable.setValue(value); + view.setVariablesIntoSelectedVariable(value.getVariables()); + view.updateSelectedVariable(); + }).catchError(error -> { + notificationManager.notify(constant.failedToGetVariableValueTitle(), error.getMessage(), FAIL, FLOAT_MODE); }); } } @@ -176,6 +164,33 @@ public void onSelectedVariableElement(@NotNull MutableVariable variable) { this.selectedVariable = variable; } + @Override + public void onSelectedThread(long threadId) { + selectedThreadId = threadId; + selectedFrameIndex = 0; + + for (ThreadDump td : threadDump) { + if (td.getId() == selectedThreadId) { + view.setFrames(td.getFrames()); + } + } + updateStackFrameDump(); + } + + @Override + public void onSelectedFrame(int frameIndex) { + selectedFrameIndex = frameIndex; + updateStackFrameDump(); + } + + public long getSelectedThreadId() { + return selectedThreadId; + } + + public int getSelectedFrameIndex() { + return selectedFrameIndex; + } + public void showDebuggerPanel() { partStack.setActivePart(this); } @@ -192,27 +207,30 @@ public boolean isDebuggerPanelPresent() { return partStack != null && partStack.containsPart(this); } - private void resetStates() { - variables.clear(); - threadDump.clear(); - view.setVariables(variables); - view.setVMName(""); - view.setExecutionPoint(null); - view.clearThreads(); - view.setFrames(Collections.emptyList()); + private void resetState() { + variables = new ArrayList<>(); + threadDump = new ArrayList<>(); + selectedThreadId = -1; + selectedFrameIndex = -1; selectedVariable = null; executionPoint = null; + debuggerDescriptor = null; + + view.setVariables(emptyList()); + view.setVMName(""); + view.setExecutionPoint(null); + view.setThreads(emptyList(), -1); + view.setFrames(emptyList()); } - public void showAndUpdateView() { + public void updateView() { if (debuggerDescriptor == null) { view.setVMName(""); } else { view.setVMName(debuggerDescriptor.getInfo()); } - if (executionPoint != null) { - view.setExecutionPoint(executionPoint); - } + + view.setExecutionPoint(executionPoint); view.setBreakpoints(breakpointManager.getBreakpointList()); updateThreadDump(); @@ -224,7 +242,7 @@ public void showAndUpdateView() { protected void updateBreakpoints() { view.setBreakpoints(breakpointManager.getBreakpointList()); - if (!isDebuggerPanelPresent()) { + if (!breakpointManager.getBreakpointList().isEmpty() && !isDebuggerPanelPresent()) { showView(); showDebuggerPanel(); } @@ -236,13 +254,14 @@ public void showView() { } } - private void updateThreadDump() { + protected void updateThreadDump() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null && executionPoint != null) { debugger.getThreadDump() .then(threadDump -> { - view.setThreads(threadDump, executionPoint.getThreadId()); - view.setFrames(threadDump.get(0).getFrames()); + DebuggerPresenter.this.threadDump = threadDump; + view.setThreads(threadDump, selectedThreadId); + onSelectedThread(selectedThreadId); }) .catchError(error -> { Log.error(DebuggerPresenter.class, error.getCause()); @@ -250,24 +269,17 @@ private void updateThreadDump() { } } - private void updateStackFrameDump() { + protected void updateStackFrameDump() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null && executionPoint != null) { - Promise promise = debugger.dumpStackFrame(); - promise.then(new Operation() { - @Override - public void apply(StackFrameDump arg) throws OperationException { - variables = new ArrayList<>(); - variables.addAll(arg.getFields()); - variables.addAll(arg.getVariables()); - - view.setVariables(variables); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError arg) throws OperationException { - Log.error(DebuggerPresenter.class, arg.getCause()); - } + Promise promise = debugger.getStackFrameDump(selectedThreadId, selectedFrameIndex); + promise.then(stackFrameDump -> { + variables = new ArrayList<>(); + variables.addAll(stackFrameDump.getFields()); + variables.addAll(stackFrameDump.getVariables()); + view.setVariables(variables); + }).catchError(error -> { + Log.error(DebuggerPresenter.class, error.getCause()); }); } } @@ -288,25 +300,19 @@ public void onDebuggerAttached(final DebuggerDescriptor debuggerDescriptor, Prom final String address = debuggerDescriptor.getAddress(); final StatusNotification notification = notificationManager.notify(constant.debuggerConnectingTitle(address), PROGRESS, FLOAT_MODE); - connect.then(new Operation() { - @Override - public void apply(Void arg) throws OperationException { - DebuggerPresenter.this.debuggerDescriptor = debuggerDescriptor; + connect.then(aVoid -> { + DebuggerPresenter.this.debuggerDescriptor = debuggerDescriptor; - notification.setTitle(constant.debuggerConnectedTitle()); - notification.setContent(constant.debuggerConnectedDescription(address)); - notification.setStatus(SUCCESS); + notification.setTitle(constant.debuggerConnectedTitle()); + notification.setContent(constant.debuggerConnectedDescription(address)); + notification.setStatus(SUCCESS); - showAndUpdateView(); - showDebuggerPanel(); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError arg) throws OperationException { - notification.setTitle(constant.failedToConnectToRemoteDebuggerDescription(address, arg.getMessage())); - notification.setStatus(FAIL); - notification.setDisplayMode(FLOAT_MODE); - } + updateView(); + showDebuggerPanel(); + }).catchError(error -> { + notification.setTitle(constant.failedToConnectToRemoteDebuggerDescription(address, error.getMessage())); + notification.setStatus(FAIL); + notification.setDisplayMode(FLOAT_MODE); }); } @@ -316,11 +322,8 @@ public void onDebuggerDisconnected() { String content = constant.debuggerDisconnectedDescription(address); notificationManager.notify(constant.debuggerDisconnectedTitle(), content, SUCCESS, NOT_EMERGE_MODE); - executionPoint = null; - debuggerDescriptor = null; - - resetStates(); - showAndUpdateView(); + resetState(); + updateView(); } @Override @@ -343,33 +346,36 @@ public void onAllBreakpointsDeleted() { @Override public void onPreStepInto() { - resetStates(); + resetState(); } @Override public void onPreStepOut() { - resetStates(); + resetState(); } @Override public void onPreStepOver() { - resetStates(); + resetState(); } @Override public void onPreResume() { - resetStates(); + resetState(); } @Override public void onBreakpointStopped(String filePath, Location location) { executionPoint = location; - showAndUpdateView(); + selectedThreadId = executionPoint.getThreadId(); + selectedFrameIndex = 0; + + updateView(); } @Override public void onValueChanged(List path, String newValue) { - updateStackFrameDump(); + updateStackFrameDump(); // TODO } @Override diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index abeb6c341fc..02dbf2095bc 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -17,6 +17,7 @@ import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.api.mvp.View; import org.eclipse.che.ide.api.parts.base.BaseActionDelegate; import org.eclipse.che.ide.api.debug.Breakpoint; @@ -44,6 +45,17 @@ interface ActionDelegate extends BaseActionDelegate { * variable that is selected */ void onSelectedVariableElement(@NotNull MutableVariable variable); + + /** + * Is invoked when a new thread is selected. + */ + void onSelectedThread(long threadId); + + /** + * Is invoked when a new frame is selected. + */ + void onSelectedFrame(int frameIndex); + } /** @@ -76,12 +88,7 @@ interface ActionDelegate extends BaseActionDelegate { */ void setThreads(@NotNull List threadDumps, long activeThreadId); - /** - * Clears the list of threads. - */ - void clearThreads(); - - /** + /** * Sets the list of frames for selected thread. */ void setFrames(@NotNull List stackFrameDumps); @@ -92,7 +99,7 @@ interface ActionDelegate extends BaseActionDelegate { * @param name * virtual machine name */ - void setVMName(@NotNull String name); + void setVMName(@Nullable String name); /** * Sets title. diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 08f14cc64f4..a361a3d6c6d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -16,9 +16,11 @@ import elemental.html.TableCellElement; import elemental.html.TableElement; +import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.user.client.ui.AcceptsOneWidget; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.ListBox; @@ -108,17 +110,16 @@ protected DebuggerViewImpl(PartStackUIResources partStackUIResources, setContentWidget(uiBinder.createAndBindUi(this)); - this.breakpoints = createBreakpointSimpleList(); + this.breakpoints = createBreakpointList(); this.breakpointsPanel.add(breakpoints); - this.frames = createFramesSimpleList(); + this.frames = createFramesList(); this.framesPanel.add(frames); this.variables = Tree.create(rendererResources, new VariableNodeDataAdapter(), new VariableTreeNodeRenderer(rendererResources)); this.variables.setTreeEventHandler(new Tree.Listener() { @Override - public void onNodeAction(@NotNull TreeNodeElement node) { - } + public void onNodeAction(@NotNull TreeNodeElement node) {} @Override public void onNodeClosed(@NotNull TreeNodeElement node) { @@ -126,16 +127,13 @@ public void onNodeClosed(@NotNull TreeNodeElement node) { } @Override - public void onNodeContextMenu(int mouseX, int mouseY, @NotNull TreeNodeElement node) { - } + public void onNodeContextMenu(int mouseX, int mouseY, @NotNull TreeNodeElement node) {} @Override - public void onNodeDragStart(@NotNull TreeNodeElement node, @NotNull MouseEvent event) { - } + public void onNodeDragStart(@NotNull TreeNodeElement node, @NotNull MouseEvent event) {} @Override - public void onNodeDragDrop(@NotNull TreeNodeElement node, @NotNull MouseEvent event) { - } + public void onNodeDragDrop(@NotNull TreeNodeElement node, @NotNull MouseEvent event) {} @Override public void onNodeExpanded(@NotNull final TreeNodeElement node) { @@ -151,23 +149,20 @@ public void onNodeSelected(@NotNull TreeNodeElement node, @NotN } @Override - public void onRootContextMenu(int mouseX, int mouseY) { - } + public void onRootContextMenu(int mouseX, int mouseY) {} @Override - public void onRootDragDrop(@NotNull MouseEvent event) { - } + public void onRootDragDrop(@NotNull MouseEvent event) {} @Override - public void onKeyboard(@NotNull KeyboardEvent event) { - } + public void onKeyboard(@NotNull KeyboardEvent event) {} }); this.variablesPanel.add(variables); minimizeButton.ensureDebugId("debugger-minimizeBut"); } - private SimpleList createBreakpointSimpleList() { + private SimpleList createBreakpointList() { TableElement breakPointsElement = Elements.createTableElement(); breakPointsElement.setAttribute("style", "width: 100%"); SimpleList.ListEventDelegate breakpointListEventDelegate = new SimpleList.ListEventDelegate() { @@ -175,9 +170,7 @@ public void onListItemClicked(Element itemElement, Breakpoint itemData) { breakpoints.getSelectionModel().setSelectedItem(itemData); } - public void onListItemDoubleClicked(Element listItemBase, Breakpoint itemData) { - // TODO: implement 'go to breakpoint source' feature - } + public void onListItemDoubleClicked(Element listItemBase, Breakpoint itemData) {} }; SimpleList.ListItemRenderer breakpointListItemRenderer = new @@ -222,13 +215,14 @@ public Element createElement() { breakpointListEventDelegate); } - private SimpleList createFramesSimpleList() { + private SimpleList createFramesList() { TableElement frameElement = Elements.createTableElement(); frameElement.setAttribute("style", "width: 100%"); SimpleList.ListEventDelegate frameListEventDelegate = new SimpleList.ListEventDelegate() { public void onListItemClicked(Element itemElement, StackFrameDump itemData) { frames.getSelectionModel().setSelectedItem(itemData); + delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); } public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) { } @@ -242,7 +236,19 @@ public void render(Element itemElement, StackFrameDump itemData) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendEscaped(itemData.getLocation().getMethod().getName()); - sb.appendEscaped("():"); + sb.appendEscaped("("); + + List arguments = itemData.getLocation().getMethod().getArguments(); + for (int i = 0; i < arguments.size(); i++) { + String[] classTypeEntries = arguments.get(i).getType().split("\\."); + sb.appendEscaped(classTypeEntries[classTypeEntries.length - 1]); + + if (i != arguments.size() - 1) { + sb.appendEscaped(", "); + } + } + + sb.appendEscaped("):"); sb.append(itemData.getLocation().getLineNumber()); sb.appendEscaped(", "); sb.appendEscaped(itemData.getLocation().getTarget()); @@ -291,31 +297,30 @@ public void setBreakpoints(@NotNull List breakpoints) { @Override public void setThreads(List threadDumps, long activeThreadId) { - clearThreads(); + threads.clear(); for (int i = 0; i < threadDumps.size(); i++) { - ThreadDump threadDump = threadDumps.get(i); + ThreadDump td = threadDumps.get(i); + String item = "\"" + td.getName() + "\"@" + td.getId() + " in group \"" + td.getGroupName() + "\": " + td.getStatus(); - threads.addItem(threadDump.getName(), String.valueOf(threadDump.getId())); - if (threadDump.getId() == activeThreadId) { + threads.addItem(item, String.valueOf(td.getId())); + if (td.getId() == activeThreadId) { threads.setSelectedIndex(i); } } } - @Override - public void clearThreads() { - threads.clear(); - } - @Override public void setFrames(List stackFrameDumps) { frames.render(new ArrayList<>(stackFrameDumps)); + if (!stackFrameDumps.isEmpty()) { + frames.getSelectionModel().setSelectedItem(0); + } } @Override - public void setVMName(@NotNull String name) { - vmName.setText(name); + public void setVMName(@Nullable String name) { + vmName.setText(name == null ? "" : name); } @Override @@ -342,4 +347,9 @@ public MutableVariable getSelectedDebuggerVariable() { public AcceptsOneWidget getDebuggerToolbarPanel() { return toolbarPanel; } + + @UiHandler({"threads"}) + void onThreadChanged(ChangeEvent event) { + delegate.onSelectedThread(Integer.parseInt(threads.getSelectedValue())); + } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml index bc603c664ed..755d14b7cd5 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml @@ -33,6 +33,10 @@ position: absolute; right: 6px; } + + .marginBottom { + margin-bottom: 10px; + } @@ -45,7 +49,7 @@ - + @@ -58,14 +62,14 @@ - + - diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java index 75a557abb8b..b299e2e30ea 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java @@ -35,7 +35,6 @@ public class ChangeValuePresenter implements ChangeValueView.ActionDelegate { private Variable variable; - /** Create presenter. */ @Inject public ChangeValuePresenter(ChangeValueView view, DebuggerLocalizationConstant constant, @@ -48,7 +47,6 @@ public ChangeValuePresenter(ChangeValueView view, this.constant = constant; } - /** Show dialog. */ public void showDialog() { variable = debuggerPresenter.getSelectedVariable(); view.setValueTitle(constant.changeValueViewExpressionFieldTitle(variable.getName())); @@ -59,25 +57,25 @@ public void showDialog() { view.showDialog(); } - /** {@inheritDoc} */ @Override public void onCancelClicked() { view.close(); } - /** {@inheritDoc} */ @Override public void onChangeClicked() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { Variable newVariable = new VariableImpl(new SimpleValueImpl(view.getValue()), variable.getVariablePath()); - debugger.setValue(newVariable); + final long threadId = debuggerPresenter.getSelectedThreadId(); + final int frameIndex = debuggerPresenter.getSelectedFrameIndex(); + + debugger.setValue(newVariable, threadId, frameIndex); } view.close(); } - /** {@inheritDoc} */ @Override public void onVariableValueChanged() { final String value = view.getValue(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/expression/EvaluateExpressionPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/expression/EvaluateExpressionPresenter.java index 3f772a87dfc..84a59128cfe 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/expression/EvaluateExpressionPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/expression/EvaluateExpressionPresenter.java @@ -13,12 +13,10 @@ import com.google.inject.Inject; import com.google.inject.Singleton; -import org.eclipse.che.api.promises.client.Operation; -import org.eclipse.che.api.promises.client.OperationException; -import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.ide.debug.Debugger; import org.eclipse.che.ide.debug.DebuggerManager; import org.eclipse.che.plugin.debugger.ide.DebuggerLocalizationConstant; +import org.eclipse.che.plugin.debugger.ide.debug.DebuggerPresenter; /** * Presenter for evaluating an expression. @@ -27,16 +25,19 @@ */ @Singleton public class EvaluateExpressionPresenter implements EvaluateExpressionView.ActionDelegate { - private DebuggerManager debuggerManager; - private EvaluateExpressionView view; - private DebuggerLocalizationConstant constant; + private final DebuggerManager debuggerManager; + private final EvaluateExpressionView view; + private final DebuggerLocalizationConstant constant; + private final DebuggerPresenter debuggerPresenter; @Inject public EvaluateExpressionPresenter(EvaluateExpressionView view, DebuggerLocalizationConstant constant, - DebuggerManager debuggerManager) { + DebuggerManager debuggerManager, + DebuggerPresenter debuggerPresenter) { this.view = view; this.debuggerManager = debuggerManager; + this.debuggerPresenter = debuggerPresenter; this.view.setDelegate(this); this.constant = constant; } @@ -48,41 +49,34 @@ public void showDialog() { view.focusInExpressionField(); } - /** Close dialog. */ public void closeDialog() { view.close(); } - /** {@inheritDoc} */ @Override public void onCloseClicked() { view.close(); } - /** {@inheritDoc} */ @Override public void onEvaluateClicked() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { view.setEnableEvaluateButton(false); - debugger.evaluate(view.getExpression()).then(new Operation() { - @Override - public void apply(String result) throws OperationException { - view.setResult(result); - view.setEnableEvaluateButton(true); - } - }).catchError(new Operation() { - @Override - public void apply(PromiseError error) throws OperationException { - view.setResult(constant.evaluateExpressionFailed(error.getMessage())); - view.setEnableEvaluateButton(true); - } + final long threadId = debuggerPresenter.getSelectedThreadId(); + final int frameIndex = debuggerPresenter.getSelectedFrameIndex(); + + debugger.evaluate(view.getExpression(), threadId, frameIndex).then(result -> { + view.setResult(result); + view.setEnableEvaluateButton(true); + }).catchError(error -> { + view.setResult(constant.evaluateExpressionFailed(error.getMessage())); + view.setEnableEvaluateButton(true); }); } } - /** {@inheritDoc} */ @Override public void onExpressionValueChanged() { final String expression = view.getExpression(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index f4f0fd7def7..d1e291c403c 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -50,6 +50,8 @@ import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; @@ -174,7 +176,7 @@ public void testOnExpandVariablesTree() throws OperationException { @Test public void testShowAndUpdateView() { - presenter.showAndUpdateView(); + presenter.updateView(); verify(view).setVMName(eq("")); } @@ -283,18 +285,18 @@ public void testOnBreakpointStopped() { LocationDto executionPoint = mock(LocationDto.class); doReturn(executionPoint).when(dtoFactory).createDto(LocationDto.class); - doReturn(promiseString).when(debugger).dumpStackFrame(); + doReturn(promiseString).when(debugger).getStackFrameDump(anyLong(), anyInt()); doReturn(promiseString).when(promiseString).then((Operation)any()); presenter.onBreakpointStopped(filePath, executionPoint); - verify(presenter).showAndUpdateView(); + verify(presenter).updateView(); verify(view).setExecutionPoint(any(Location.class)); } @Test public void testOnValueChanged() { - doReturn(promiseString).when(debugger).dumpStackFrame(); + doReturn(promiseString).when(debugger).getStackFrameDump(anyLong(), anyInt()); doReturn(promiseString).when(promiseString).then((Operation)any()); ArrayList path = new ArrayList<>(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index b66747b5f3a..f12e9d91d4c 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -80,6 +80,8 @@ import static org.junit.Assert.fail; import static org.mockito.Answers.RETURNS_DEEP_STUBS; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -536,11 +538,11 @@ public void testGetStackFrameDump() throws Exception { final String json = "json"; doReturn(json).when(dtoFactory).toJson(mockStackFrameDumpDto); - doReturn(promiseStackFrameDump).when(service).getStackFrameDump(SESSION_ID); + doReturn(promiseStackFrameDump).when(service).getStackFrameDump(SESSION_ID, anyLong(), anyInt()); doReturn(promiseStackFrameDump).when(promiseStackFrameDump).then((Function)any()); doReturn(promiseStackFrameDump).when(promiseStackFrameDump).catchError((Operation)any()); - Promise result = debugger.dumpStackFrame(); + Promise result = debugger.getStackFrameDump(anyLong(), anyInt()); assertEquals(promiseStackFrameDump, result); } @@ -548,9 +550,9 @@ public void testGetStackFrameDump() throws Exception { public void testGetStackFrameDumpWithoutConnection() throws Exception { debugger.setDebugSession(null); - debugger.dumpStackFrame(); + debugger.getStackFrameDump(anyLong(), anyInt()); - verify(service, never()).getStackFrameDump(any()); + verify(service, never()).getStackFrameDump(any(), anyLong(), anyInt()); } @Test diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml index f6efe7466af..5b9226b2070 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml @@ -179,25 +179,9 @@ **/*.tokens **/*.g **/*.txt - **/*.class - - - - - - - - - - - - - - - diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 8dbace3a72e..05ccd6ecb5a 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -388,10 +388,7 @@ public List getThreadDumps() throws DebuggerException { List frames = new LinkedList<>(); try { for (StackFrame f : t.frames()) { - frames.add(new JdbStackFrame(f, - emptyList(), - emptyList(), - new JdbLocation(f, new JdbMethod(f, emptyList())))); + frames.add(new JdbStackFrame(f, emptyList(), emptyList(), new JdbLocation(f, new JdbMethod(f)))); } } catch (IncompatibleThreadStateException ignored) { // Thread isn't suspended. Information isn't available. diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java index bc9b86e795a..2ec1e1dfb99 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java @@ -27,22 +27,15 @@ * @author Anatolii Bazko */ public class JdbMethod implements Method { - private final com.sun.jdi.Method jdiMethod; - private final com.sun.jdi.StackFrame jdiStackFrame; + private final com.sun.jdi.Method jdiMethod; private final AtomicReference> arguments; public JdbMethod(com.sun.jdi.StackFrame jdiStackFrame) { - this.jdiStackFrame = jdiStackFrame; this.jdiMethod = jdiStackFrame.location().method(); this.arguments = new AtomicReference<>(); } - public JdbMethod(com.sun.jdi.StackFrame jdiStackFrame, List arguments) { - this(jdiStackFrame); - this.arguments.set(arguments); - } - @Override public String getName() { return jdiMethod.name(); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java index 9977ee544d4..99e370b2885 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java @@ -12,7 +12,6 @@ import com.sun.jdi.ObjectReference; import com.sun.jdi.ReferenceType; -import com.sun.jdi.StackFrame; import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; @@ -46,7 +45,7 @@ public JdbStackFrame(com.sun.jdi.StackFrame jdiStackFrame) { this.fields = new AtomicReference<>(); } - public JdbStackFrame(StackFrame jdiStackFrame, + public JdbStackFrame(com.sun.jdi.StackFrame jdiStackFrame, List fields, List variables, Location location) { diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index d3f053b7a9d..ec86e8139e1 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -169,11 +169,11 @@ public void deleteBreakpoint(@PathParam("id") String sessionId, } @GET - @Path("{id}/dump") + @Path("{id}/stackframedump") @Produces(MediaType.APPLICATION_JSON) public StackFrameDumpDto getStackFrameDump(@PathParam("id") String sessionId, - @QueryParam("threadId") @DefaultValue("-1") long threadId, - @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex) throws DebuggerException { + @QueryParam("thread") @DefaultValue("-1") long threadId, + @QueryParam("frame") @DefaultValue("-1") int frameIndex) throws DebuggerException { if (threadId == -1) { return asDto(debuggerManager.getDebugger(sessionId).dumpStackFrame()); @@ -195,8 +195,8 @@ public List getThreadDumps(@PathParam("id") String sessionId) thr @Path("{id}/value") @Produces(MediaType.APPLICATION_JSON) public SimpleValueDto getValue(@PathParam("id") String sessionId, - @QueryParam("threadId") @DefaultValue("-1") long threadId, - @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex, + @QueryParam("thread") @DefaultValue("-1") long threadId, + @QueryParam("frame") @DefaultValue("-1") int frameIndex, @Context UriInfo uriInfo) throws DebuggerException { List path = new ArrayList<>(); @@ -220,8 +220,8 @@ public SimpleValueDto getValue(@PathParam("id") String sessionId, @Path("{id}/value") @Consumes(MediaType.APPLICATION_JSON) public void setValue(@PathParam("id") String sessionId, - @QueryParam("threadId") @DefaultValue("-1") long threadId, - @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex, + @QueryParam("thread") @DefaultValue("-1") long threadId, + @QueryParam("frame") @DefaultValue("-1") int frameIndex, VariableDto variable) throws DebuggerException { if (threadId == -1) { debuggerManager.getDebugger(sessionId).setValue(variable); @@ -234,8 +234,8 @@ public void setValue(@PathParam("id") String sessionId, @Path("{id}/evaluation") @Produces(MediaType.TEXT_PLAIN) public String expression(@PathParam("id") String sessionId, - @QueryParam("threadId") @DefaultValue("-1") long threadId, - @QueryParam("frameIndex") @DefaultValue("-1") int frameIndex, + @QueryParam("thread") @DefaultValue("-1") long threadId, + @QueryParam("frame") @DefaultValue("-1") int frameIndex, @QueryParam("expression") String expression) throws DebuggerException { if (threadId == -1) { return debuggerManager.getDebugger(sessionId).evaluate(expression); diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 665ed3d1523..b97ab8dec9f 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -88,6 +88,7 @@ public static MethodDto asDto(Method method) { public static LocationDto asDto(Location location) { return newDto(LocationDto.class).withTarget(location.getTarget()) + .withThreadId(location.getThreadId()) .withLineNumber(location.getLineNumber()) .withExternalResourceId(location.getExternalResourceId()) .withResourcePath(location.getResourcePath()) From ff5b5d4288e1be6c8f9637e69172a86ef9da4432 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Sat, 19 Aug 2017 08:33:22 +0300 Subject: [PATCH 23/38] Debugger Resource Handler --- .../debugger/ide/debug/AbstractDebugger.java | 10 ++-- .../ide/debug/BasicActiveFileHandler.java | 7 ++- .../debugger/ide/debug/DebuggerPresenter.java | 50 +++++++++++++++---- ...dler.java => DebuggerResourceHandler.java} | 6 +-- .../debug/DebuggerResourceHandlerManager.java | 33 ++++++++++++ .../debugger/ide/debug/DebuggerView.java | 10 ++-- .../debugger/ide/debug/DebuggerViewImpl.java | 17 +++++-- .../ide/debug/DebuggerPresenterTest.java | 2 +- .../debugger/ide/debug/DebuggerTest.java | 8 +-- .../ide/debug/JavaDebuggerFileHandler.java | 2 +- 10 files changed, 110 insertions(+), 35 deletions(-) rename plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/{ActiveFileHandler.java => DebuggerResourceHandler.java} (87%) create mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 7c60e42a1f2..a55201515e8 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -105,7 +105,7 @@ public abstract class AbstractDebugger implements Debugger, DebuggerObservable { private final DebuggerServiceClient service; private final LocalStorageProvider localStorageProvider; private final EventBus eventBus; - private final ActiveFileHandler activeFileHandler; + private final DebuggerResourceHandler debuggerResourceHandler; private final DebuggerManager debuggerManager; private final BreakpointManager breakpointManager; private final String debuggerType; @@ -121,7 +121,7 @@ public AbstractDebugger(DebuggerServiceClient service, DtoFactory dtoFactory, LocalStorageProvider localStorageProvider, EventBus eventBus, - ActiveFileHandler activeFileHandler, + DebuggerResourceHandler debuggerResourceHandler, DebuggerManager debuggerManager, NotificationManager notificationManager, BreakpointManager breakpointManager, @@ -133,7 +133,7 @@ public AbstractDebugger(DebuggerServiceClient service, this.dtoFactory = dtoFactory; this.localStorageProvider = localStorageProvider; this.eventBus = eventBus; - this.activeFileHandler = activeFileHandler; + this.debuggerResourceHandler = debuggerResourceHandler; this.debuggerManager = debuggerManager; this.notificationManager = notificationManager; this.breakpointManager = breakpointManager; @@ -213,8 +213,8 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) { private void openCurrentFile(Location location) { //todo we need add possibility to handle few files try { - activeFileHandler.openFile(location, - new AsyncCallback() { + debuggerResourceHandler.open(location, + new AsyncCallback() { @Override public void onFailure(Throwable caught) { for (DebuggerObserver observer : observers) { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java index 62076287959..32b71bb4bd9 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java @@ -17,7 +17,6 @@ import com.google.inject.Singleton; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.project.shared.dto.SearchResultDto; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.ide.api.app.AppContext; @@ -37,7 +36,7 @@ * @author Anatoliy Bazko */ @Singleton -public class BasicActiveFileHandler implements ActiveFileHandler { +public class BasicActiveFileHandler implements DebuggerResourceHandler { private final EditorAgent editorAgent; private final AppContext appContext; @@ -57,10 +56,10 @@ public BasicActiveFileHandler(EditorAgent editorAgent, AppContext appContext) { * {@link BasicActiveFileHandler#findInWorkspace(Location, AsyncCallback)} * {@link BasicActiveFileHandler#searchSource(Location, AsyncCallback)} * - * @see ActiveFileHandler#openFile(Location, AsyncCallback) + * @see DebuggerResourceHandler#open(Location, AsyncCallback) */ @Override - public void openFile(final Location location, final AsyncCallback callback) { + public void open(final Location location, final AsyncCallback callback) { findInOpenedEditors(location, new AsyncCallback() { @Override public void onSuccess(VirtualFile result) { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index cf3203095c9..db6b6e23ff9 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.che.plugin.debugger.ide.debug; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.AcceptsOneWidget; import com.google.gwt.user.client.ui.IsWidget; import com.google.inject.Inject; @@ -31,6 +32,7 @@ import org.eclipse.che.ide.api.parts.PartStackType; import org.eclipse.che.ide.api.parts.WorkspaceAgent; import org.eclipse.che.ide.api.parts.base.BasePresenter; +import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.Debugger; import org.eclipse.che.ide.debug.DebuggerDescriptor; import org.eclipse.che.ide.debug.DebuggerManager; @@ -69,14 +71,15 @@ public class DebuggerPresenter extends BasePresenter implements DebuggerView.Act BreakpointManagerObserver { private static final String TITLE = "Debug"; - private final DebuggerResources debuggerResources; - private final ToolbarPresenter debuggerToolbar; - private final BreakpointManager breakpointManager; - private final NotificationManager notificationManager; - private final DebuggerLocalizationConstant constant; - private final DebuggerView view; - private final DebuggerManager debuggerManager; - private final WorkspaceAgent workspaceAgent; + private final DebuggerResources debuggerResources; + private final ToolbarPresenter debuggerToolbar; + private final BreakpointManager breakpointManager; + private final NotificationManager notificationManager; + private final DebuggerLocalizationConstant constant; + private final DebuggerView view; + private final DebuggerManager debuggerManager; + private final WorkspaceAgent workspaceAgent; + private final DebuggerResourceHandlerManager resourceHandlerManager; private MutableVariable selectedVariable; private List variables; @@ -94,12 +97,14 @@ public DebuggerPresenter(final DebuggerView view, final DebuggerResources debuggerResources, final @DebuggerToolbar ToolbarPresenter debuggerToolbar, final DebuggerManager debuggerManager, - final WorkspaceAgent workspaceAgent) { + final WorkspaceAgent workspaceAgent, + final DebuggerResourceHandlerManager resourceHandlerManager) { this.view = view; this.debuggerResources = debuggerResources; this.debuggerToolbar = debuggerToolbar; this.debuggerManager = debuggerManager; this.workspaceAgent = workspaceAgent; + this.resourceHandlerManager = resourceHandlerManager; this.view.setDelegate(this); this.view.setTitle(TITLE); this.constant = constant; @@ -178,9 +183,32 @@ public void onSelectedThread(long threadId) { } @Override - public void onSelectedFrame(int frameIndex) { + public void onSelectedFrame(int frameIndex, boolean jumpTo) { + if (selectedFrameIndex != frameIndex) { + updateStackFrameDump(); + } + selectedFrameIndex = frameIndex; - updateStackFrameDump(); + + if (jumpTo) { + for (ThreadDump td : threadDump) { + if (td.getId() == selectedThreadId) { + final StackFrameDump stackFrameDump = td.getFrames().get(selectedFrameIndex); + + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null) { + DebuggerResourceHandler handler = resourceHandlerManager.get(debugger.getDebuggerType()); + handler.open(stackFrameDump.getLocation(), new AsyncCallback() { + @Override + public void onFailure(Throwable caught) {} + + @Override + public void onSuccess(VirtualFile result) {} + }); + } + } + } + } } public long getSelectedThreadId() { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/ActiveFileHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java similarity index 87% rename from plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/ActiveFileHandler.java rename to plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java index bfa532b79fe..e336290ede0 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/ActiveFileHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java @@ -23,7 +23,7 @@ * * @author Anatoliy Bazko */ -public interface ActiveFileHandler { +public interface DebuggerResourceHandler { /** * Opens resource is being debugged and scrolls to the position {@link Location#getLineNumber()}. @@ -31,9 +31,9 @@ public interface ActiveFileHandler { * and {@link AsyncCallback#onFailure(Throwable)} otherwise. * * @param location - * the location of the resource is being debugged + * the location of the resource * @param callback * the callback */ - void openFile(Location location, AsyncCallback callback); + void open(Location location, AsyncCallback callback); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java new file mode 100644 index 00000000000..602084886af --- /dev/null +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) [2012] - [2017] Red Hat, Inc. + * 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 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.plugin.debugger.ide.debug; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import java.util.Set; + +/** + * @author Anatolii Bazko + */ +@Singleton +public class DebuggerResourceHandlerManager { + + @Inject + public DebuggerResourceHandlerManager(Set handlers) { + } + + public DebuggerResourceHandler get(String debuggerType) { + return null; + } + + // TODO bind +} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index 02dbf2095bc..0725bf6b521 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -53,9 +53,13 @@ interface ActionDelegate extends BaseActionDelegate { /** * Is invoked when a new frame is selected. + * + * @param frameIndex + * the frame index inside thread + * @param jumpTo + * indicates if it is necessary to open location in the editor belonging to the current frame */ - void onSelectedFrame(int frameIndex); - + void onSelectedFrame(int frameIndex, boolean jumpTo); } /** @@ -88,7 +92,7 @@ interface ActionDelegate extends BaseActionDelegate { */ void setThreads(@NotNull List threadDumps, long activeThreadId); - /** + /** * Sets the list of frames for selected thread. */ void setFrames(@NotNull List stackFrameDumps); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index a361a3d6c6d..bdd85942400 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -222,10 +222,12 @@ private SimpleList createFramesList() { SimpleList.ListEventDelegate frameListEventDelegate = new SimpleList.ListEventDelegate() { public void onListItemClicked(Element itemElement, StackFrameDump itemData) { frames.getSelectionModel().setSelectedItem(itemData); - delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); + delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex(), false); } - public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) { } + public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) { + delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex(), true); + } }; SimpleList.ListItemRenderer frameListItemRenderer = new @@ -251,7 +253,16 @@ public void render(Element itemElement, StackFrameDump itemData) { sb.appendEscaped("):"); sb.append(itemData.getLocation().getLineNumber()); sb.appendEscaped(", "); - sb.appendEscaped(itemData.getLocation().getTarget()); + + String classFqn = itemData.getLocation().getTarget(); + int classNameIndex = classFqn.lastIndexOf("."); + String className = classFqn.substring(classNameIndex + 1); + String packageName = classFqn.substring(0, classNameIndex); + + sb.appendEscaped(className); + sb.appendEscaped(" ("); + sb.appendEscaped(packageName); + sb.appendEscaped(") "); label.setInnerHTML(sb.toSafeHtml().asString()); itemElement.appendChild(label); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index d1e291c403c..687bb241c4d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -124,7 +124,7 @@ public void setup() { doReturn(ERROR_MESSAGE).when(promiseError).getMessage(); presenter = spy(new DebuggerPresenter(view, constant, breakpointManager, notificationManager, debuggerResources, debuggerToolbar, - debuggerManager, workspaceAgent)); + debuggerManager, workspaceAgent, resourceHandlerManager)); doNothing().when(presenter).showDebuggerPanel(); presenter.onSelectedVariableElement(selectedVariable); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index f12e9d91d4c..00ac0ba8fde 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -118,7 +118,7 @@ public class DebuggerTest extends BaseTest { @Mock private EventBus eventBus; @Mock - private ActiveFileHandler activeFileHandler; + private DebuggerResourceHandler debuggerResourceHandler; @Mock private DebuggerManager debuggerManager; @Mock @@ -188,7 +188,7 @@ public void setUp() { doReturn(Path.valueOf(PATH)).when(file).getLocation(); debugger = new TestDebugger(service, transmitter, configurator, dtoFactory, localStorageProvider, eventBus, - activeFileHandler, debuggerManager, notificationManager, "id"); + debuggerResourceHandler, debuggerManager, notificationManager, "id"); doReturn(promiseInfo).when(service).getSessionInfo(SESSION_ID); doReturn(promiseInfo).when(promiseInfo).then(any(Operation.class)); @@ -617,7 +617,7 @@ public TestDebugger(DebuggerServiceClient service, DtoFactory dtoFactory, LocalStorageProvider localStorageProvider, EventBus eventBus, - ActiveFileHandler activeFileHandler, + DebuggerResourceHandler debuggerResourceHandler, DebuggerManager debuggerManager, NotificationManager notificationManager, String id) { @@ -627,7 +627,7 @@ public TestDebugger(DebuggerServiceClient service, dtoFactory, localStorageProvider, eventBus, - activeFileHandler, + debuggerResourceHandler, debuggerManager, notificationManager, breakpointManager, diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java index f40c5afa0cb..02f0c455048 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java @@ -47,7 +47,7 @@ public JavaDebuggerFileHandler(EditorAgent editorAgent, } @Override - public void openFile(Location location, AsyncCallback callback) { + public void open(Location location, AsyncCallback callback) { findInOpenedEditors(location, new AsyncCallback() { @Override public void onSuccess(VirtualFile result) { From 1bebe3a3429ec05ea52c1df389e4668c5fc1617b Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Sat, 19 Aug 2017 15:03:46 +0300 Subject: [PATCH 24/38] FixUP --- .../debugger/ide/debug/AbstractDebugger.java | 6 +-- .../debug/DebuggerResourceHandlerManager.java | 40 +++++++++---------- ...va => DefaultDebuggerResourceHandler.java} | 12 +++--- .../debugger/ide/EvaluateExpressionTest.java | 10 +++-- .../ide/debug/DebuggerPresenterTest.java | 3 +- .../che/plugin/gdb/ide/GdbDebugger.java | 4 +- .../plugin/jdb/ide/debug/JavaDebugger.java | 7 ++-- .../ide/debug/JavaDebuggerFileHandler.java | 4 +- .../plugin/nodejsdbg/ide/NodeJsDebugger.java | 4 +- .../che/plugin/zdb/ide/ZendDebugger.java | 4 +- 10 files changed, 48 insertions(+), 46 deletions(-) rename plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/{BasicActiveFileHandler.java => DefaultDebuggerResourceHandler.java} (94%) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index a55201515e8..a30dab28c81 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -121,19 +121,19 @@ public AbstractDebugger(DebuggerServiceClient service, DtoFactory dtoFactory, LocalStorageProvider localStorageProvider, EventBus eventBus, - DebuggerResourceHandler debuggerResourceHandler, DebuggerManager debuggerManager, NotificationManager notificationManager, BreakpointManager breakpointManager, String type, - RequestHandlerManager requestHandlerManager) { + RequestHandlerManager requestHandlerManager, + DebuggerResourceHandlerManager debuggerResourceHandlerManager) { this.service = service; this.transmitter = transmitter; this.configurator = configurator; this.dtoFactory = dtoFactory; this.localStorageProvider = localStorageProvider; this.eventBus = eventBus; - this.debuggerResourceHandler = debuggerResourceHandler; + this.debuggerResourceHandler = debuggerResourceHandlerManager.get(getDebuggerType()); this.debuggerManager = debuggerManager; this.notificationManager = notificationManager; this.breakpointManager = breakpointManager; diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java index 602084886af..e695d02fa12 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandlerManager.java @@ -1,33 +1,31 @@ -/******************************************************************************* - * Copyright (c) [2012] - [2017] Red Hat, Inc. - * 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 +/** + * ***************************************************************************** Copyright (c) + * [2012] - [2017] Red Hat, Inc. 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 * - * Contributors: - * Red Hat, Inc. - initial API and implementation - *******************************************************************************/ + *

    Contributors: Red Hat, Inc. - initial API and implementation + * ***************************************************************************** + */ package org.eclipse.che.plugin.debugger.ide.debug; import com.google.inject.Inject; import com.google.inject.Singleton; -import java.util.Set; - -/** - * @author Anatolii Bazko - */ +/** @author Anatolii Bazko */ @Singleton public class DebuggerResourceHandlerManager { - @Inject - public DebuggerResourceHandlerManager(Set handlers) { - } + @Inject + public DebuggerResourceHandlerManager(DefaultDebuggerResourceHandler defautlHandler) {} + + public DebuggerResourceHandler get(String debuggerType) { + return null; + } + + public void register(DebuggerResourceHandler handler, String debuggerType) { - public DebuggerResourceHandler get(String debuggerType) { - return null; - } + } - // TODO bind + // TODO bind } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java similarity index 94% rename from plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java rename to plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java index 32b71bb4bd9..f1738a5a820 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BasicActiveFileHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java @@ -36,13 +36,13 @@ * @author Anatoliy Bazko */ @Singleton -public class BasicActiveFileHandler implements DebuggerResourceHandler { +public class DefaultDebuggerResourceHandler implements DebuggerResourceHandler { private final EditorAgent editorAgent; private final AppContext appContext; @Inject - public BasicActiveFileHandler(EditorAgent editorAgent, AppContext appContext) { + public DefaultDebuggerResourceHandler(EditorAgent editorAgent, AppContext appContext) { this.editorAgent = editorAgent; this.appContext = appContext; } @@ -51,10 +51,10 @@ public BasicActiveFileHandler(EditorAgent editorAgent, AppContext appContext) { * Tries to find file and open it. * To perform the operation the following sequence of methods invocation are processed: * - * {@link BasicActiveFileHandler#findInOpenedEditors(Location, AsyncCallback)} - * {@link BasicActiveFileHandler#findInProject(Location, AsyncCallback)} - * {@link BasicActiveFileHandler#findInWorkspace(Location, AsyncCallback)} - * {@link BasicActiveFileHandler#searchSource(Location, AsyncCallback)} + * {@link DefaultDebuggerResourceHandler#findInOpenedEditors(Location, AsyncCallback)} + * {@link DefaultDebuggerResourceHandler#findInProject(Location, AsyncCallback)} + * {@link DefaultDebuggerResourceHandler#findInWorkspace(Location, AsyncCallback)} + * {@link DefaultDebuggerResourceHandler#searchSource(Location, AsyncCallback)} * * @see DebuggerResourceHandler#open(Location, AsyncCallback) */ diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java index ce00e83ab42..f1dde1309bb 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java @@ -25,6 +25,8 @@ import org.mockito.Mock; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -102,7 +104,7 @@ public void shouldEnableEvaluateButtonIfExpressionNotEmpty() throws Exception { @Test public void testEvaluateExpressionRequestIsSuccessful() throws Exception { - when(debugger.evaluate(anyString())).thenReturn(promise); + when(debugger.evaluate(anyString(), anyLong(), anyInt())).thenReturn(promise); when(view.getExpression()).thenReturn(EXPRESSION); when(promise.then(any(Operation.class))).thenReturn(promise); @@ -112,13 +114,13 @@ public void testEvaluateExpressionRequestIsSuccessful() throws Exception { presenter.onEvaluateClicked(); verify(view, atLeastOnce()).setEnableEvaluateButton(eq(DISABLE_BUTTON)); - verify(debugger).evaluate(eq(EXPRESSION)); + verify(debugger).evaluate(eq(EXPRESSION), anyLong(), anyInt()); } @Test public void testEvaluateExpressionRequestIsFailed() throws Exception { when(view.getExpression()).thenReturn(EXPRESSION); - when(debugger.evaluate(view.getExpression())).thenReturn(promise); + when(debugger.evaluate(view.getExpression(), anyLong(), anyInt())).thenReturn(promise); when(promise.then((Operation)anyObject())).thenReturn(promise); when(promise.catchError(Matchers.>anyObject())).thenReturn(promise); when(debuggerManager.getActiveDebugger()).thenReturn(debugger); @@ -128,7 +130,7 @@ public void testEvaluateExpressionRequestIsFailed() throws Exception { presenter.onEvaluateClicked(); verify(view, atLeastOnce()).setEnableEvaluateButton(eq(DISABLE_BUTTON)); - verify(debugger).evaluate(eq(EXPRESSION)); + verify(debugger).evaluate(eq(EXPRESSION), anyLong(), anyInt()); verify(promise).catchError(errorCaptor.capture()); errorCaptor.getValue().apply(promiseError); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index 687bb241c4d..4b2904adaf5 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -124,7 +124,8 @@ public void setup() { doReturn(ERROR_MESSAGE).when(promiseError).getMessage(); presenter = spy(new DebuggerPresenter(view, constant, breakpointManager, notificationManager, debuggerResources, debuggerToolbar, - debuggerManager, workspaceAgent, resourceHandlerManager)); + debuggerManager, workspaceAgent, + resourceHandlerManager)); doNothing().when(presenter).showDebuggerPanel(); presenter.onSelectedVariableElement(selectedVariable); diff --git a/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java index 7994b49da64..a23e3c60dcb 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java @@ -32,7 +32,7 @@ import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; -import org.eclipse.che.plugin.debugger.ide.debug.BasicActiveFileHandler; +import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; import javax.validation.constraints.NotNull; import java.util.Map; @@ -62,7 +62,7 @@ public GdbDebugger(DebuggerServiceClient service, DtoFactory dtoFactory, LocalStorageProvider localStorageProvider, EventBus eventBus, - BasicActiveFileHandler activeFileHandler, + DefaultDebuggerResourceHandler activeFileHandler, DebuggerManager debuggerManager, NotificationManager notificationManager, BreakpointManager breakpointManager, diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java index 0cf94628857..0d60351a845 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java @@ -27,6 +27,7 @@ import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; +import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerManager; import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolver; import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolverFactory; @@ -57,7 +58,7 @@ public JavaDebugger(DebuggerServiceClient service, LocalStorageProvider localStorageProvider, EventBus eventBus, FqnResolverFactory fqnResolverFactory, - JavaDebuggerFileHandler javaDebuggerFileHandler, + DebuggerResourceHandlerManager debuggerResourceHandlerManager, DebuggerManager debuggerManager, NotificationManager notificationManager, FileTypeRegistry fileTypeRegistry, @@ -69,12 +70,12 @@ public JavaDebugger(DebuggerServiceClient service, dtoFactory, localStorageProvider, eventBus, - javaDebuggerFileHandler, debuggerManager, notificationManager, breakpointManager, ID, - requestHandlerManager); + requestHandlerManager, + debuggerResourceHandlerManager); this.fqnResolverFactory = fqnResolverFactory; this.fileTypeRegistry = fileTypeRegistry; } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java index 02f0c455048..c0b1b35a09c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java @@ -22,7 +22,7 @@ import org.eclipse.che.ide.ext.java.client.tree.JavaNodeFactory; import org.eclipse.che.ide.ext.java.client.tree.library.JarFileNode; import org.eclipse.che.ide.resource.Path; -import org.eclipse.che.plugin.debugger.ide.debug.BasicActiveFileHandler; +import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; /** * Responsible to open files in editor when debugger stopped at breakpoint. @@ -30,7 +30,7 @@ * @author Anatoliy Bazko */ @Singleton -public class JavaDebuggerFileHandler extends BasicActiveFileHandler { +public class JavaDebuggerFileHandler extends DefaultDebuggerResourceHandler { private final JavaNavigationService javaNavigationService; private final JavaNodeFactory nodeFactory; diff --git a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java index c5937ebf54e..db50f159c96 100644 --- a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java +++ b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java @@ -26,7 +26,7 @@ import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; -import org.eclipse.che.plugin.debugger.ide.debug.BasicActiveFileHandler; +import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; import javax.validation.constraints.NotNull; import java.util.Map; @@ -47,7 +47,7 @@ public NodeJsDebugger(DebuggerServiceClient service, DtoFactory dtoFactory, LocalStorageProvider localStorageProvider, EventBus eventBus, - BasicActiveFileHandler activeFileHandler, + DefaultDebuggerResourceHandler activeFileHandler, DebuggerManager debuggerManager, NotificationManager notificationManager, BreakpointManager breakpointManager, diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java index 2f08c94801a..0b595b41a8a 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java @@ -26,7 +26,7 @@ import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; -import org.eclipse.che.plugin.debugger.ide.debug.BasicActiveFileHandler; +import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; import org.eclipse.che.plugin.zdb.ide.configuration.ZendDbgConfigurationType; import javax.validation.constraints.NotNull; @@ -48,7 +48,7 @@ public ZendDebugger(DebuggerServiceClient service, DtoFactory dtoFactory, LocalStorageProvider localStorageProvider, EventBus eventBus, - BasicActiveFileHandler activeFileHandler, + DefaultDebuggerResourceHandler activeFileHandler, NotificationManager notificationManager, DebuggerManager debuggerManager, BreakpointManager breakpointManager, From cb699883bad60b3d47519b3b558c7d2ab099d894 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Sat, 19 Aug 2017 16:30:19 +0300 Subject: [PATCH 25/38] Fix up --- .../debugger/ide/debug/DebuggerPresenter.java | 38 +++++++++---------- .../debugger/ide/debug/DebuggerView.java | 6 +-- .../debugger/ide/debug/DebuggerViewImpl.java | 9 ++--- .../ide/debug/DebuggerViewImpl.ui.xml | 2 +- .../debug/DefaultDebuggerResourceHandler.java | 2 +- .../plugin/jdb/ide/JavaDebuggerExtension.java | 6 +-- ....java => JavaDebuggerResourceHandler.java} | 4 +- 7 files changed, 31 insertions(+), 36 deletions(-) rename plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/{JavaDebuggerFileHandler.java => JavaDebuggerResourceHandler.java} (96%) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 68a69c3e870..a014f2bba36 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -193,32 +193,30 @@ public void onSelectedThread(long threadId) { } @Override - public void onSelectedFrame(int frameIndex, boolean jumpTo) { + public void onSelectedFrame(int frameIndex) { if (selectedFrameIndex != frameIndex) { updateStackFrameDump(); } selectedFrameIndex = frameIndex; - if (jumpTo) { - for (ThreadDump td : threadDump) { - if (td.getId() == selectedThreadId) { - final StackFrameDump stackFrameDump = td.getFrames().get(selectedFrameIndex); - - Debugger debugger = debuggerManager.getActiveDebugger(); - if (debugger != null) { - DebuggerResourceHandler handler = - resourceHandlerManager.getOrDefault(debugger.getDebuggerType()); - handler.open( - stackFrameDump.getLocation(), - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) {} - - @Override - public void onSuccess(VirtualFile result) {} - }); - } + for (ThreadDump td : threadDump) { + if (td.getId() == selectedThreadId) { + final StackFrameDump stackFrameDump = td.getFrames().get(selectedFrameIndex); + + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null) { + DebuggerResourceHandler handler = + resourceHandlerManager.getOrDefault(debugger.getDebuggerType()); + handler.open( + stackFrameDump.getLocation(), + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) {} + + @Override + public void onSuccess(VirtualFile result) {} + }); } } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index c642b5b8965..5fea22d6426 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -52,12 +52,10 @@ interface ActionDelegate extends BaseActionDelegate { /** * Is invoked when a new frame is selected. + * @param frameIndex the frame index inside thread * - * @param frameIndex the frame index inside thread - * @param jumpTo indicates if it is necessary to open location in the editor belonging to the - * current frame */ - void onSelectedFrame(int frameIndex, boolean jumpTo); + void onSelectedFrame(int frameIndex); } /** diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 4be7c2fade0..8e2d496615e 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -199,9 +199,8 @@ public void render(Element itemElement, Breakpoint itemData) { String path = itemData.getPath(); sb.appendEscaped( path.substring(path.lastIndexOf("/") + 1) - + " - [line: " - + String.valueOf(itemData.getLineNumber() + 1) - + "]"); + + ":" + + String.valueOf(itemData.getLineNumber() + 1)); sb.appendHtmlConstant(""); label.setInnerHTML(sb.toSafeHtml().asString()); @@ -230,11 +229,11 @@ private SimpleList createFramesList() { new SimpleList.ListEventDelegate() { public void onListItemClicked(Element itemElement, StackFrameDump itemData) { frames.getSelectionModel().setSelectedItem(itemData); - delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex(), false); + delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); } public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) { - delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex(), true); + delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); } }; diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml index 755d14b7cd5..12f8673d42d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.ui.xml @@ -49,7 +49,7 @@ - + diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java index e8ca55332ca..25e3f8a701f 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java @@ -260,7 +260,7 @@ public void onInitializationFailed() { protected void scrollToLine(EditorPartPresenter editor, int lineNumber) { if (editor instanceof TextEditor) { TextEditor textEditor = (TextEditor) editor; - textEditor.setCursorPosition(new TextPosition(lineNumber + 1, 0)); + textEditor.setCursorPosition(new TextPosition(lineNumber - 1, 0)); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java index 7c46470ed1d..55a34c63fc3 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java @@ -17,7 +17,7 @@ import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerFactory; import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolverFactory; import org.eclipse.che.plugin.jdb.ide.debug.JavaDebugger; -import org.eclipse.che.plugin.jdb.ide.debug.JavaDebuggerFileHandler; +import org.eclipse.che.plugin.jdb.ide.debug.JavaDebuggerResourceHandler; import org.eclipse.che.plugin.jdb.ide.fqn.JavaClassFqnResolver; import org.eclipse.che.plugin.jdb.ide.fqn.JavaFqnResolver; @@ -42,11 +42,11 @@ public JavaDebuggerExtension( JavaFqnResolver javaFqnResolver, JavaClassFqnResolver javaClassFqnResolver, DebuggerResourceHandlerFactory debuggerResourceHandlerFactory, - JavaDebuggerFileHandler javaDebuggerFileHandler) { + JavaDebuggerResourceHandler javaDebuggerResourceHandler) { debuggerManager.registeredDebugger(JavaDebugger.ID, javaDebugger); resolverFactory.addResolver("java", javaFqnResolver); resolverFactory.addResolver("class", javaClassFqnResolver); - debuggerResourceHandlerFactory.register(JavaDebugger.ID, javaDebuggerFileHandler); + debuggerResourceHandlerFactory.register(JavaDebugger.ID, javaDebuggerResourceHandler); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java similarity index 96% rename from plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java rename to plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java index f174981a88e..31c55369a72 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerFileHandler.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java @@ -29,13 +29,13 @@ * @author Anatoliy Bazko */ @Singleton -public class JavaDebuggerFileHandler extends DefaultDebuggerResourceHandler { +public class JavaDebuggerResourceHandler extends DefaultDebuggerResourceHandler { private final JavaNavigationService javaNavigationService; private final JavaNodeFactory nodeFactory; @Inject - public JavaDebuggerFileHandler( + public JavaDebuggerResourceHandler( EditorAgent editorAgent, AppContext appContext, JavaNavigationService javaNavigationService, From ac282ed1c073c83ace49d825adebc8621d32e1a4 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Sat, 19 Aug 2017 16:43:04 +0300 Subject: [PATCH 26/38] Fix up --- .../ide/debug/BreakpointItemRender.java | 67 +++++++++++++ .../debugger/ide/debug/DebuggerViewImpl.java | 95 +------------------ .../debugger/ide/debug/FrameItemRender.java | 61 ++++++++++++ .../ide/debug/VariableTreeNodeRenderer.java | 5 +- 4 files changed, 134 insertions(+), 94 deletions(-) create mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java create mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java new file mode 100644 index 00000000000..4107b881d54 --- /dev/null +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.plugin.debugger.ide.debug; + +import elemental.dom.Element; +import elemental.html.TableCellElement; + +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.ide.api.debug.Breakpoint; +import org.eclipse.che.ide.ui.list.SimpleList; +import org.eclipse.che.ide.util.dom.Elements; +import org.eclipse.che.plugin.debugger.ide.DebuggerResources; +import org.vectomatic.dom.svg.ui.SVGResource; + +/** @author Anatolii Bazko */ +public class BreakpointItemRender extends SimpleList.ListItemRenderer { + + private final DebuggerResources debuggerResources; + + public BreakpointItemRender(DebuggerResources debuggerResources) { + this.debuggerResources = debuggerResources; + } + + @Override + public void render(Element itemElement, Breakpoint itemData) { + TableCellElement label = Elements.createTDElement(); + + SafeHtmlBuilder sb = new SafeHtmlBuilder(); + // Add icon + sb.appendHtmlConstant(""); + + // Add title + sb.appendHtmlConstant("
    "); + SVGResource icon = debuggerResources.breakpoint(); + if (icon != null) { + sb.appendHtmlConstant(""); + } + sb.appendHtmlConstant(""); + + String path = itemData.getPath(); + sb.appendEscaped( + path.substring(path.lastIndexOf("/") + 1) + + ":" + + String.valueOf(itemData.getLineNumber() + 1)); + sb.appendHtmlConstant("
    "); + + label.setInnerHTML(sb.toSafeHtml().asString()); + + itemElement.appendChild(label); + } + + @Override + public Element createElement() { + return Elements.createTRElement(); + } +} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 8e2d496615e..8f00cb6bab7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -11,7 +11,6 @@ package org.eclipse.che.plugin.debugger.ide.debug; import com.google.gwt.event.dom.client.ChangeEvent; -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; @@ -27,7 +26,6 @@ import elemental.dom.Element; import elemental.events.KeyboardEvent; import elemental.events.MouseEvent; -import elemental.html.TableCellElement; import elemental.html.TableElement; import java.util.ArrayList; import java.util.List; @@ -50,7 +48,6 @@ import org.eclipse.che.ide.util.input.SignalEvent; import org.eclipse.che.plugin.debugger.ide.DebuggerLocalizationConstant; import org.eclipse.che.plugin.debugger.ide.DebuggerResources; -import org.vectomatic.dom.svg.ui.SVGResource; /** * The class business logic which allow us to change visual representation of debugger panel. @@ -85,7 +82,7 @@ interface DebuggerViewImplUiBinder extends UiBinder {} private final Tree variables; private final SimpleList breakpoints; private final SimpleList frames; - private final DebuggerResources res; + private final DebuggerResources debuggerResources; private TreeNodeElement selectedVariable; @@ -100,7 +97,7 @@ protected DebuggerViewImpl( super(partStackUIResources); this.locale = locale; - this.res = resources; + this.debuggerResources = resources; this.coreRes = coreRes; setContentWidget(uiBinder.createAndBindUi(this)); @@ -178,46 +175,10 @@ public void onListItemClicked(Element itemElement, Breakpoint itemData) { public void onListItemDoubleClicked(Element listItemBase, Breakpoint itemData) {} }; - SimpleList.ListItemRenderer breakpointListItemRenderer = - new SimpleList.ListItemRenderer() { - @Override - public void render(Element itemElement, Breakpoint itemData) { - TableCellElement label = Elements.createTDElement(); - - SafeHtmlBuilder sb = new SafeHtmlBuilder(); - // Add icon - sb.appendHtmlConstant(""); - - // Add title - sb.appendHtmlConstant("
    "); - SVGResource icon = res.breakpoint(); - if (icon != null) { - sb.appendHtmlConstant(""); - } - sb.appendHtmlConstant(""); - - String path = itemData.getPath(); - sb.appendEscaped( - path.substring(path.lastIndexOf("/") + 1) - + ":" - + String.valueOf(itemData.getLineNumber() + 1)); - sb.appendHtmlConstant("
    "); - - label.setInnerHTML(sb.toSafeHtml().asString()); - - itemElement.appendChild(label); - } - - @Override - public Element createElement() { - return Elements.createTRElement(); - } - }; - return SimpleList.create( (SimpleList.View) breakPointsElement, coreRes.defaultSimpleListCss(), - breakpointListItemRenderer, + new BreakpointItemRender(debuggerResources), breakpointListEventDelegate); } @@ -232,59 +193,13 @@ public void onListItemClicked(Element itemElement, StackFrameDump itemData) { delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); } - public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) { - delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); - } - }; - - SimpleList.ListItemRenderer frameListItemRenderer = - new SimpleList.ListItemRenderer() { - @Override - public void render(Element itemElement, StackFrameDump itemData) { - TableCellElement label = Elements.createTDElement(); - - SafeHtmlBuilder sb = new SafeHtmlBuilder(); - sb.appendEscaped(itemData.getLocation().getMethod().getName()); - sb.appendEscaped("("); - - List arguments = itemData.getLocation().getMethod().getArguments(); - for (int i = 0; i < arguments.size(); i++) { - String[] classTypeEntries = arguments.get(i).getType().split("\\."); - sb.appendEscaped(classTypeEntries[classTypeEntries.length - 1]); - - if (i != arguments.size() - 1) { - sb.appendEscaped(", "); - } - } - - sb.appendEscaped("):"); - sb.append(itemData.getLocation().getLineNumber()); - sb.appendEscaped(", "); - - String classFqn = itemData.getLocation().getTarget(); - int classNameIndex = classFqn.lastIndexOf("."); - String className = classFqn.substring(classNameIndex + 1); - String packageName = classFqn.substring(0, classNameIndex); - - sb.appendEscaped(className); - sb.appendEscaped(" ("); - sb.appendEscaped(packageName); - sb.appendEscaped(") "); - - label.setInnerHTML(sb.toSafeHtml().asString()); - itemElement.appendChild(label); - } - - @Override - public Element createElement() { - return Elements.createTRElement(); - } + public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) {} }; return SimpleList.create( (SimpleList.View) frameElement, coreRes.defaultSimpleListCss(), - frameListItemRenderer, + new FrameItemRender(), frameListEventDelegate); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java new file mode 100644 index 00000000000..d0f5c842335 --- /dev/null +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.plugin.debugger.ide.debug; + +import elemental.dom.Element; +import elemental.html.TableCellElement; + +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; + +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.ide.ui.list.SimpleList; +import org.eclipse.che.ide.util.dom.Elements; + +import java.util.List; + +/** @author Anatolii Bazko */ +public class FrameItemRender extends SimpleList.ListItemRenderer { + + @Override + public void render(Element itemElement, StackFrameDump itemData) { + TableCellElement label = Elements.createTDElement(); + + SafeHtmlBuilder sb = new SafeHtmlBuilder(); + sb.appendEscaped(itemData.getLocation().getMethod().getName()); + sb.appendEscaped("("); + + List arguments = itemData.getLocation().getMethod().getArguments(); + for (int i = 0; i < arguments.size(); i++) { + String type = arguments.get(i).getType(); + sb.appendEscaped(type.substring(type.lastIndexOf(".") + 1)); + + if (i != arguments.size() - 1) { + sb.appendEscaped(", "); + } + } + + sb.appendEscaped("):"); + sb.append(itemData.getLocation().getLineNumber()); + sb.appendEscaped(", "); + + String target = itemData.getLocation().getTarget(); + int classNameIndex = target.lastIndexOf("."); + + sb.appendEscaped(target.substring(classNameIndex + 1)); + sb.appendEscaped(" ("); + sb.appendEscaped(target.substring(0, classNameIndex)); + sb.appendEscaped(") "); + + label.setInnerHTML(sb.toSafeHtml().asString()); + itemElement.appendChild(label); + } +} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java index f9ba5493eca..63a1005502c 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java @@ -46,18 +46,16 @@ public VariableTreeNodeRenderer(@NotNull Resources res) { this.css.ensureInjected(); } - /** {@inheritDoc} */ @Override public Element getNodeKeyTextContainer(@NotNull SpanElement treeNodeLabel) { return (Element) treeNodeLabel.getChildNodes().item(1); } - /** {@inheritDoc} */ @Override public SpanElement renderNodeContents(@NotNull MutableVariable data) { SpanElement root = Elements.createSpanElement(css.variableRoot()); SpanElement label = Elements.createSpanElement(css.variableLabel()); - String content = data.getName() + ": " + data.getValue().getString(); + String content = data.getName() + "=" + data.getValue().getString(); label.setTextContent(content); root.appendChild(label); @@ -65,7 +63,6 @@ public SpanElement renderNodeContents(@NotNull MutableVariable data) { return root; } - /** {@inheritDoc} */ @Override public void updateNodeContents(@NotNull TreeNodeElement treeNode) { // do nothing From 47570ecafafc1e133f9f3da8298600a4f4632d7b Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 21 Aug 2017 09:13:00 +0300 Subject: [PATCH 27/38] Fix up --- .../ide/api/debug/DebuggerServiceClient.java | 21 ++++++++-------- .../che/ide/debug/BreakpointManagerImpl.java | 1 - .../org/eclipse/che/ide/debug/Debugger.java | 25 ++++++++++--------- .../debugger/ide/debug/AbstractDebugger.java | 11 ++++---- .../ide/debug/BreakpointItemRender.java | 13 +++++----- .../debugger/ide/debug/DebuggerView.java | 5 ++-- .../debugger/ide/debug/DebuggerViewImpl.java | 6 +++-- .../debugger/ide/debug/FrameItemRender.java | 14 ++++++----- .../ide/debug/VariableTreeNodeRenderer.java | 5 ++-- .../debugger/ide/ChangeVariableValueTest.java | 19 +++++++------- .../debugger/ide/debug/DebuggerTest.java | 4 +-- .../che/plugin/gdb/ide/GdbDebugger.java | 5 ++-- .../plugin/jdb/ide/JavaDebuggerExtension.java | 2 +- .../plugin/jdb/ide/debug/JavaDebugger.java | 4 +-- .../che/plugin/jdb/server/JavaDebugger.java | 25 +++++++++++++------ .../jdb/server/model/JdbArrayElement.java | 15 +++++------ .../che/plugin/jdb/server/model/JdbField.java | 15 +++++------ .../jdb/server/model/JdbFieldComparator.java | 15 +++++------ .../plugin/jdb/server/model/JdbLocation.java | 15 +++++------ .../plugin/jdb/server/model/JdbMethod.java | 15 +++++------ .../jdb/server/model/JdbStackFrame.java | 15 +++++------ .../che/plugin/jdb/server/model/JdbValue.java | 15 +++++------ .../plugin/jdb/server/model/JdbVariable.java | 15 +++++------ .../jdb/server/EvaluateExpressionTest1.java | 15 +++++------ .../che/plugin/jdb/server/GetValueTest1.java | 15 +++++------ .../jdb/server/StackFrameDumpTest1.java | 15 +++++------ .../plugin/jdb/server/ThreadDumpTest1.java | 15 +++++------ .../plugin/jdb/server/ThreadDumpTest2.java | 15 +++++------ .../jdb/server/util/JavaDebuggerUtils.java | 15 +++++------ .../jdb/server/util/ProjectApiUtils.java | 15 +++++------ .../org/eclipse/EvaluateExpressionTest1.java | 4 +-- .../test/src/org/eclipse/GetValueTest1.java | 4 +-- .../src/org/eclipse/StackFrameDumpTest1.java | 4 +-- .../test/src/org/eclipse/ThreadDumpTest1.java | 4 +-- .../plugin/nodejsdbg/ide/NodeJsDebugger.java | 5 ++-- .../che/plugin/zdb/ide/ZendDebugger.java | 5 ++-- .../che/api/debug/shared/dto/MethodDto.java | 15 +++++------ .../api/debug/shared/dto/ThreadDumpDto.java | 15 +++++------ .../api/debug/shared/model/ThreadDump.java | 15 +++++------ .../debug/shared/model/impl/MethodImpl.java | 15 +++++------ .../shared/model/impl/StackFrameDumpImpl.java | 1 - .../shared/model/impl/ThreadDumpImpl.java | 15 +++++------ .../che/api/debugger/server/Debugger.java | 1 - .../che/api/debugger/server/DtoConverter.java | 11 ++++---- 44 files changed, 264 insertions(+), 235 deletions(-) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java index c589f400784..59f66f4a019 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java @@ -25,6 +25,7 @@ import org.eclipse.che.api.debug.shared.dto.action.StepOutActionDto; import org.eclipse.che.api.debug.shared.dto.action.StepOverActionDto; import org.eclipse.che.api.debug.shared.dto.action.SuspendActionDto; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.promises.client.Promise; /** @@ -108,8 +109,8 @@ public interface DebuggerServiceClient { * Gets the stack frame dump. * * @param id debug session id - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise getStackFrameDump(String id, long threadId, int frameIndex); @@ -128,21 +129,21 @@ public interface DebuggerServiceClient { Promise resume(String id, ResumeActionDto action); /** - * Returns a value of the variable in the specific frame. + * Returns a value of the variable inside the specific frame. * * @param id debug session id - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise getValue( String id, VariableDto variableDto, long threadId, int frameIndex); /** - * Sets the new value of the variable in the specific frame. + * Sets the new value of the variable inside the specific frame. * * @param id debug session id - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise setValue(String id, VariableDto variableDto, long threadId, int frameIndex); @@ -175,8 +176,8 @@ Promise getValue( * * @param id debug session id * @param expression the expression to evaluate - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise evaluate(String id, String expression, long threadId, int frameIndex); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java index 89f7a6b2173..1150a2b11a5 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java @@ -24,7 +24,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.logging.Logger; - import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index c4fa37c0ca6..06f44881148 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -15,6 +15,7 @@ import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.ide.api.resources.VirtualFile; @@ -78,27 +79,27 @@ public interface Debugger extends DebuggerObservable { void suspend(); /** - * Evaluates the given expression inside specific frame. + * Evaluates the given expression inside a specific frame. * - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise evaluate(String expression, long threadId, int frameIndex); /** - * Gets the value of the given variableinside specific frame. + * Gets the value of the given variable inside a specific frame. * * @param variable the variable to get value from - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise getValue(Variable variable, long threadId, int frameIndex); /** - * Gets stack framedump. + * Gets a stack frame dump. * - * @param threadId the unique thread id - * @param frameIndex the frameindex in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ Promise getStackFrameDump(long threadId, int frameIndex); @@ -106,11 +107,11 @@ public interface Debugger extends DebuggerObservable { Promise> getThreadDump(); /** - * Updates the value of the given variable. + * Sets a new value in the variable inside a specific frame. * * @param variable the variable to update - * @param threadId the unique thread id - * @param frameIndex the frame index in the thread + * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param frameIndex the frame index inside the thread */ void setValue(Variable variable, long threadId, int frameIndex); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index d80d6b299f4..5b01f203ad4 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -122,9 +122,9 @@ public AbstractDebugger( DebuggerManager debuggerManager, NotificationManager notificationManager, BreakpointManager breakpointManager, - String type, RequestHandlerManager requestHandlerManager, - DebuggerResourceHandlerFactory debuggerResourceHandlerFactory) { + DebuggerResourceHandlerFactory debuggerResourceHandlerFactory, + String type) { this.service = service; this.transmitter = transmitter; this.configurator = configurator; @@ -175,7 +175,7 @@ public void onWsAgentStarted(WsAgentStateEvent event) { } if (currentLocation != null) { - openCurrentFile(currentLocation); + open(currentLocation); } startCheckingEvents(); @@ -196,7 +196,7 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) { switch (event.getType()) { case SUSPEND: currentLocation = ((SuspendEventDto) event).getLocation(); - openCurrentFile(currentLocation); + open(currentLocation); break; case BREAKPOINT_ACTIVATED: BreakpointDto breakpointDto = ((BreakpointActivatedEventDto) event).getBreakpoint(); @@ -214,8 +214,7 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) { preserveDebuggerState(); } - private void openCurrentFile(Location location) { - //todo we need add possibility to handle few files + private void open(Location location) { try { debuggerResourceHandler.open( location, diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java index 4107b881d54..dadc8e22eac 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java @@ -10,20 +10,21 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import elemental.dom.Element; import elemental.html.TableCellElement; - -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; -import com.google.inject.Inject; -import com.google.inject.Singleton; - import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.ui.list.SimpleList; import org.eclipse.che.ide.util.dom.Elements; import org.eclipse.che.plugin.debugger.ide.DebuggerResources; import org.vectomatic.dom.svg.ui.SVGResource; -/** @author Anatolii Bazko */ +/** + * Renders breakpoint item the panel. + * + * @see Breakpoint + * @author Anatolii Bazko + */ public class BreakpointItemRender extends SimpleList.ListItemRenderer { private final DebuggerResources debuggerResources; diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index 5fea22d6426..843b4ed9f9b 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -47,13 +47,14 @@ interface ActionDelegate extends BaseActionDelegate { * @param variable variable that is selected */ void onSelectedVariableElement(@NotNull MutableVariable variable); + /** Is invoked when a new thread is selected. */ void onSelectedThread(long threadId); /** * Is invoked when a new frame is selected. - * @param frameIndex the frame index inside thread * + * @param frameIndex the frame index inside a thread */ void onSelectedFrame(int frameIndex); } @@ -83,7 +84,7 @@ interface ActionDelegate extends BaseActionDelegate { * Sets the list of the threads and select the one with {@link ThreadDump#getId()} equal to {@code * activeThreadId}. */ - void setThreads(@NotNull List threadDumps, long activeThreadId); + void setThreads(@NotNull List threadDumps, long threadIdToSelect); /** Sets the list of frames for selected thread. */ void setFrames(@NotNull List stackFrameDumps); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 8f00cb6bab7..b9f9829c2fd 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -166,6 +166,7 @@ public void onKeyboard(@NotNull KeyboardEvent event) {} private SimpleList createBreakpointList() { TableElement breakPointsElement = Elements.createTableElement(); breakPointsElement.setAttribute("style", "width: 100%"); + SimpleList.ListEventDelegate breakpointListEventDelegate = new SimpleList.ListEventDelegate() { public void onListItemClicked(Element itemElement, Breakpoint itemData) { @@ -235,7 +236,7 @@ public void setBreakpoints(@NotNull List breakpoints) { } @Override - public void setThreads(List threadDumps, long activeThreadId) { + public void setThreads(List threadDumps, long threadIdToSelect) { threads.clear(); for (int i = 0; i < threadDumps.size(); i++) { @@ -250,7 +251,8 @@ public void setThreads(List threadDumps, long activeThread + "\": " + td.getStatus(); threads.addItem(item, String.valueOf(td.getId())); - if (td.getId() == activeThreadId) { + + if (td.getId() == threadIdToSelect) { threads.setSelectedIndex(i); } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java index d0f5c842335..6dc9824dda4 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java @@ -10,19 +10,21 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import elemental.dom.Element; import elemental.html.TableCellElement; - -import com.google.gwt.safehtml.shared.SafeHtmlBuilder; - +import java.util.List; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.ide.ui.list.SimpleList; import org.eclipse.che.ide.util.dom.Elements; -import java.util.List; - -/** @author Anatolii Bazko */ +/** + * Renders stack frame item the panel. + * + * @see StackFrameDump + * @author Anatolii Bazko + */ public class FrameItemRender extends SimpleList.ListItemRenderer { @Override diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java index 63a1005502c..aea30244044 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java @@ -21,9 +21,10 @@ import org.eclipse.che.ide.util.dom.Elements; /** - * The rendered for debug variable node. + * Renders variable item the panel. * - * @author Andrey Plotnikov @@author Dmitry Shnurenko + * @see MutableVariable + * @author Anatolii Bazko */ public class VariableTreeNodeRenderer implements NodeRenderer { public interface Css extends CssResource { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java index d0811f96a5f..493e6d89823 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java @@ -19,7 +19,6 @@ import static org.mockito.Mockito.when; import java.util.ArrayList; - import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; @@ -43,16 +42,16 @@ public class ChangeVariableValueTest extends BaseTest { private static final String VAR_VALUE = "var_value"; private static final String VAR_NAME = "var_name"; private static final String EMPTY_VALUE = ""; - @Mock private ChangeValueView view; + @Mock private ChangeValueView view; @InjectMocks private ChangeValuePresenter presenter; - @Mock private VariableDto var; - @Mock private VariablePathDto varPath; - @Mock private DebuggerManager debuggerManager; - @Mock private Debugger debugger; - @Mock private DebuggerPresenter debuggerPresenter; - @Mock private MutableVariable variable; - @Mock private VariablePathDto variablePathDto; - @Mock private SimpleValueDto simpleValueDto; + @Mock private VariableDto var; + @Mock private VariablePathDto varPath; + @Mock private DebuggerManager debuggerManager; + @Mock private Debugger debugger; + @Mock private DebuggerPresenter debuggerPresenter; + @Mock private MutableVariable variable; + @Mock private VariablePathDto variablePathDto; + @Mock private SimpleValueDto simpleValueDto; @Before public void setUp() { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index 74993a7d65a..0add2fae27b 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -635,9 +635,9 @@ public TestDebugger( debuggerManager, notificationManager, breakpointManager, - id, requestHandlerManager, - debuggerResourceHandlerFactory); + debuggerResourceHandlerFactory, + id); } @Override diff --git a/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java index 1ece598a12f..1fbb88a7735 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java @@ -38,7 +38,6 @@ import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerFactory; -import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; /** * The GDB debugger client. @@ -78,9 +77,9 @@ public GdbDebugger( debuggerManager, notificationManager, breakpointManager, - ID, requestHandlerManager, - debuggerResourceHandlerFactory); + debuggerResourceHandlerFactory, + ID); this.locale = locale; this.appContext = appContext; } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java index 55a34c63fc3..3624aaba14b 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java @@ -46,7 +46,7 @@ public JavaDebuggerExtension( debuggerManager.registeredDebugger(JavaDebugger.ID, javaDebugger); resolverFactory.addResolver("java", javaFqnResolver); resolverFactory.addResolver("class", javaClassFqnResolver); - + debuggerResourceHandlerFactory.register(JavaDebugger.ID, javaDebuggerResourceHandler); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java index 0486cbc7589..befdb176176 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java @@ -72,9 +72,9 @@ public JavaDebugger( debuggerManager, notificationManager, breakpointManager, - ID, requestHandlerManager, - debuggerResourceHandlerFactory); + debuggerResourceHandlerFactory, + ID); this.fqnResolverFactory = fqnResolverFactory; this.fileTypeRegistry = fileTypeRegistry; } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index f7cc544e8ab..0a79acbd733 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -413,19 +413,19 @@ public List getThreadDumps() throws DebuggerException { /** * Get value of variable with specified path. Each item in path is name of variable. * - *

    Path must be specified according to the following rules: * + *

    Path must be specified according to the following rules: * *

      - *
    1. If need to get field of this object of current frame then first element in array always* + *
    2. If need to get field of this object of current frame then first element in array always * should be 'this'. *
    3. If need to get static field in current frame then first element in array always should * be* 'static'. - *
    4. If need to get local variable in current frame then first element should be the name of* + *
    5. If need to get local variable in current frame then first element should be the name of * local variable. *
    * * Here is example.
    - * Assume we have next hierarchy of classes and breakpoint set in line: // breakpoint: * + * Assume we have next hierarchy of classes and breakpoint set in line: // breakpoint: * *
        *    class A {
    @@ -446,7 +446,7 @@ public List getThreadDumps() throws DebuggerException {
        *    }
        * 
    * - * * There are two ways to access variable str in class A: * + * * There are two ways to access variable str in class A: * *
      *
    1. Through field a in class B: ['this', 'a', 'str'] @@ -457,10 +457,14 @@ public List getThreadDumps() throws DebuggerException { * @return variable or null if variable not found * @throws DebuggerException when any other errors occur when try to access the variable */ - @Override public SimpleValue getValue(VariablePath variablePath) throws DebuggerException { - return getValue(variablePath, getCurrentThread().uniqueID(), 0); + lock.lock(); + try { + return getValue(variablePath, getCurrentThread().uniqueID(), 0); + } finally { + lock.unlock(); + } } @Override @@ -683,7 +687,12 @@ private void clearSteps() throws DebuggerException { @Override public String evaluate(String expression) throws DebuggerException { - return evaluate(expression, getCurrentThread().uniqueID(), 0); + lock.lock(); + try { + return evaluate(expression, getCurrentThread().uniqueID(), 0); + } finally { + lock.unlock(); + } } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java index 7e6846c84a9..c8260abe23a 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbArrayElement.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java index 01221915f54..7dd7c51a555 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbField.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java index 0e956547c35..a7961e66625 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbFieldComparator.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java index 29c573662cd..199c9438515 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java index 86accf89b3b..900f169075a 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbMethod.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java index 80142d37ada..ccb0f14d66a 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbStackFrame.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java index 770804efe96..18ac53092ea 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbValue.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java index 8ea9eba80d1..4d0e3044a96 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbVariable.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.model; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java index 33b741ce5ba..a815d9e351d 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java index 4421138571f..a6910228047 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java index a893003aa97..03ac8838673 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index b19647ff8b4..8beb90b1943 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java index de3627ad6f3..2fdcccabf62 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java index 1befc77f9bb..6af57cedb78 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.util; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java index 774e5404a0b..4d639d15445 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/ProjectApiUtils.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.plugin.jdb.server.util; diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/EvaluateExpressionTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/EvaluateExpressionTest1.java index fd7a9248420..0cdd84a19e8 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/EvaluateExpressionTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/EvaluateExpressionTest1.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * Copyright (c) 2012-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,7 @@ * * Contributors: * Red Hat, Inc. - initial API and implementation - *******************************************************************************/ + */ package org.eclipse; public class EvaluateExpressionTest1 { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java index c2aeae016ba..b6da5e12df1 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/GetValueTest1.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * Copyright (c) 2012-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,7 @@ * * Contributors: * Red Hat, Inc. - initial API and implementation - *******************************************************************************/ + */ package org.eclipse; public class GetValueTest1 { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java index d3f6d56cb0f..5ce18877b8f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/StackFrameDumpTest1.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * Copyright (c) 2012-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,7 @@ * * Contributors: * Red Hat, Inc. - initial API and implementation - *******************************************************************************/ + */ package org.eclipse; public class StackFrameDumpTest1 { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java index 71d774949b8..637be08f80c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/ThreadDumpTest1.java @@ -1,4 +1,4 @@ -/******************************************************************************* +/* * Copyright (c) 2012-2017 Red Hat, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,7 +7,7 @@ * * Contributors: * Red Hat, Inc. - initial API and implementation - *******************************************************************************/ + */ package org.eclipse; import java.util.concurrent.CountDownLatch; diff --git a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java index 1a23c2c7073..ea3b687aded 100644 --- a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java +++ b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java @@ -28,7 +28,6 @@ import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerFactory; -import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; /** * The NodeJs Debugger Client. @@ -63,9 +62,9 @@ public NodeJsDebugger( debuggerManager, notificationManager, breakpointManager, - ID, requestHandlerManager, - debuggerResourceHandlerFactory); + debuggerResourceHandlerFactory, + ID); } @Override diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java index 69c139df112..8b5dbcf0328 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java @@ -27,7 +27,6 @@ import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerFactory; -import org.eclipse.che.plugin.debugger.ide.debug.DefaultDebuggerResourceHandler; import org.eclipse.che.plugin.zdb.ide.configuration.ZendDbgConfigurationType; /** @@ -62,9 +61,9 @@ public ZendDebugger( debuggerManager, notificationManager, breakpointManager, - ID, requestHandlerManager, - debuggerResourceHandlerFactory); + debuggerResourceHandlerFactory, + ID); } @Override diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java index 2504d23fb7a..35548acc19a 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/MethodDto.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.api.debug.shared.dto; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java index aff7321af79..3370c8d0c27 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.api.debug.shared.dto; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java index ff1a3b9482c..7125e92a922 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.api.debug.shared.model; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java index 04fbc495945..6f99f86abf0 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MethodImpl.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.api.debug.shared.model.impl; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java index 404df413a24..1b044b13279 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/StackFrameDumpImpl.java @@ -13,7 +13,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; - import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.model.Field; import org.eclipse.che.api.debug.shared.model.Location; diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java index 76ccb330eb6..fcbd3890846 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java @@ -1,11 +1,12 @@ -/** - * ***************************************************************************** Copyright (c) - * 2012-2017 Red Hat, Inc. 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 +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 * - *

      Contributors: Red Hat, Inc. - initial API and implementation - * ***************************************************************************** + * Contributors: + * Red Hat, Inc. - initial API and implementation */ package org.eclipse.che.api.debug.shared.model.impl; diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index 3d5ebddd41e..ba8ac5cd2f1 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -139,7 +139,6 @@ default SimpleValue getValue(VariablePath variablePath, long threadId, int frame * @param variable the variable to update * @throws DebuggerException if any error occur */ - @Deprecated void setValue(Variable variable) throws DebuggerException; diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 4463c0ca7bc..3e407d8320b 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -10,6 +10,11 @@ */ package org.eclipse.che.api.debugger.server; +import static java.util.stream.Collectors.toList; +import static org.eclipse.che.dto.server.DtoFactory.newDto; + +import java.util.List; +import java.util.Objects; import org.eclipse.che.api.debug.shared.dto.BreakpointDto; import org.eclipse.che.api.debug.shared.dto.DebugSessionDto; import org.eclipse.che.api.debug.shared.dto.DebuggerInfoDto; @@ -40,12 +45,6 @@ import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; -import java.util.List; -import java.util.Objects; - -import static java.util.stream.Collectors.toList; -import static org.eclipse.che.dto.server.DtoFactory.newDto; - /** * Helps to convert to/from DTOs related to debugger. * From eefdc753f7b5ff4508d4a7752fd3f7bc0fa8617f Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 21 Aug 2017 12:14:23 +0300 Subject: [PATCH 28/38] Fix up --- .../org/eclipse/che/ide/debug/Debugger.java | 4 +-- .../debugger/ide/debug/AbstractDebugger.java | 16 +++------- .../debugger/ide/debug/DebuggerPresenter.java | 4 +-- .../debugger/ide/EvaluateExpressionTest.java | 22 +++++++++---- .../ide/debug/DebuggerPresenterTest.java | 7 ++-- .../debugger/ide/debug/DebuggerTest.java | 32 +++++++++---------- .../che/plugin/jdb/server/GetValueTest1.java | 2 +- .../plugin/jdb/server/ThreadDumpTest1.java | 1 - 8 files changed, 46 insertions(+), 42 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 06f44881148..8f0cbf1d872 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -93,7 +93,7 @@ public interface Debugger extends DebuggerObservable { * @param threadId the unique thread id {@link ThreadDump#getId()} * @param frameIndex the frame index inside the thread */ - Promise getValue(Variable variable, long threadId, int frameIndex); + Promise getValue(Variable variable, long threadId, int frameIndex); /** * Gets a stack frame dump. @@ -101,7 +101,7 @@ public interface Debugger extends DebuggerObservable { * @param threadId the unique thread id {@link ThreadDump#getId()} * @param frameIndex the frame index inside the thread */ - Promise getStackFrameDump(long threadId, int frameIndex); + Promise getStackFrameDump(long threadId, int frameIndex); /** Gets thread dump. */ Promise> getThreadDump(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 5b01f203ad4..ec44ca6f5f0 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -28,7 +28,6 @@ import org.eclipse.che.api.debug.shared.dto.DebugSessionDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; -import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; @@ -49,8 +48,6 @@ import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.action.Action; -import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; -import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl; import org.eclipse.che.api.promises.client.Function; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; @@ -315,26 +312,21 @@ private void unsubscribeFromDebuggerEvents() { } @Override - public Promise getValue(Variable variable, long threadId, int frameIndex) { + public Promise getValue(Variable variable, long threadId, int frameIndex) { if (!isConnected()) { return Promises.reject(JsPromiseError.create("Debugger is not connected")); } - Promise promise = - service.getValue(debugSessionDto.getId(), toDto(variable), threadId, frameIndex); - return promise.then((Function) SimpleValueImpl::new); + return service.getValue(debugSessionDto.getId(), toDto(variable), threadId, frameIndex); } @Override - public Promise getStackFrameDump(long threadId, int frameIndex) { + public Promise getStackFrameDump(long threadId, int frameIndex) { if (!isConnected()) { return Promises.reject(JsPromiseError.create("Debugger is not connected")); } - Promise stackFrameDump = - service.getStackFrameDump(debugSessionDto.getId(), threadId, frameIndex); - return stackFrameDump.then( - (Function) StackFrameDumpImpl::new); + return service.getStackFrameDump(debugSessionDto.getId(), threadId, frameIndex); } @Override diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index a014f2bba36..77c04162c6d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -152,7 +152,7 @@ public void onExpandVariablesTree() { if (rootVariables.isEmpty()) { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { - Promise promise = + Promise promise = debugger.getValue(selectedVariable, selectedThreadId, selectedFrameIndex); promise @@ -313,7 +313,7 @@ protected void updateThreadDump() { protected void updateStackFrameDump() { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null && debugger.isSuspended()) { - Promise promise = + Promise promise = debugger.getStackFrameDump(selectedThreadId, selectedFrameIndex); promise .then( diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java index 3839386488f..95b2fb0128a 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java @@ -11,8 +11,6 @@ package org.eclipse.che.plugin.debugger.ide; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -25,8 +23,10 @@ import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.ide.debug.Debugger; import org.eclipse.che.ide.debug.DebuggerManager; +import org.eclipse.che.plugin.debugger.ide.debug.DebuggerPresenter; import org.eclipse.che.plugin.debugger.ide.debug.expression.EvaluateExpressionPresenter; import org.eclipse.che.plugin.debugger.ide.debug.expression.EvaluateExpressionView; +import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -44,15 +44,25 @@ public class EvaluateExpressionTest extends BaseTest { private static final String EMPTY_EXPRESSION = ""; private static final String EVALUATION_RESULT = "result"; private static final String FAIL_REASON = "reason"; + private static final long THREAD_ID = 1; + private static final int FRAME_INDEX = 0; @Mock private EvaluateExpressionView view; @Mock private DebuggerManager debuggerManager; @Mock private Debugger debugger; @Mock private Promise promise; @Mock private PromiseError promiseError; + @Mock private DebuggerPresenter debuggerPresenter; @Captor private ArgumentCaptor> errorCaptor; @InjectMocks private EvaluateExpressionPresenter presenter; + @Override + @Before + public void setUp() { + when(debuggerPresenter.getSelectedThreadId()).thenReturn(THREAD_ID); + when(debuggerPresenter.getSelectedFrameIndex()).thenReturn(FRAME_INDEX); + } + @Test public void shouldShowDialog() throws Exception { presenter.showDialog(); @@ -97,7 +107,7 @@ public void shouldEnableEvaluateButtonIfExpressionNotEmpty() throws Exception { @Test public void testEvaluateExpressionRequestIsSuccessful() throws Exception { - when(debugger.evaluate(anyString(), anyLong(), anyInt())).thenReturn(promise); + when(debugger.evaluate(anyString(), eq(THREAD_ID), eq(FRAME_INDEX))).thenReturn(promise); when(view.getExpression()).thenReturn(EXPRESSION); when(promise.then(any(Operation.class))).thenReturn(promise); @@ -107,13 +117,13 @@ public void testEvaluateExpressionRequestIsSuccessful() throws Exception { presenter.onEvaluateClicked(); verify(view, atLeastOnce()).setEnableEvaluateButton(eq(DISABLE_BUTTON)); - verify(debugger).evaluate(eq(EXPRESSION), anyLong(), anyInt()); + verify(debugger).evaluate(EXPRESSION, THREAD_ID, FRAME_INDEX); } @Test public void testEvaluateExpressionRequestIsFailed() throws Exception { when(view.getExpression()).thenReturn(EXPRESSION); - when(debugger.evaluate(view.getExpression(), anyLong(), anyInt())).thenReturn(promise); + when(debugger.evaluate(view.getExpression(), THREAD_ID, FRAME_INDEX)).thenReturn(promise); when(promise.then((Operation) anyObject())).thenReturn(promise); when(promise.catchError(Matchers.>anyObject())).thenReturn(promise); when(debuggerManager.getActiveDebugger()).thenReturn(debugger); @@ -123,7 +133,7 @@ public void testEvaluateExpressionRequestIsFailed() throws Exception { presenter.onEvaluateClicked(); verify(view, atLeastOnce()).setEnableEvaluateButton(eq(DISABLE_BUTTON)); - verify(debugger).evaluate(eq(EXPRESSION), anyLong(), anyInt()); + verify(debugger).evaluate(EXPRESSION, THREAD_ID, FRAME_INDEX); verify(promise).catchError(errorCaptor.capture()); errorCaptor.getValue().apply(promiseError); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index 9b87fcb9fed..3cadcbb2dd9 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -57,6 +57,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; +import org.mockito.Mockito; /** * Testing {@link DebuggerPresenter} functionality. @@ -118,6 +119,9 @@ public void setup() { FileType fileType = mock(FileType.class); doReturn("java").when(fileType).getExtension(); doReturn(fileType).when(fileTypeRegistry).getFileTypeByFile(eq(file)); + + Mockito.reset(view); + Mockito.reset(breakpointManager); } @Test @@ -131,7 +135,6 @@ public void testGo() { presenter.go(container); verify(view).setBreakpoints(breakpoints); - verify(view).setVariables(any()); verify(container).setWidget(view); verify(debuggerToolbar).go(container); } @@ -144,7 +147,7 @@ public void testOnExpandVariablesTree() throws OperationException { doReturn(true).when(rootVariables).isEmpty(); doReturn(rootVariables).when(selectedVariable).getVariables(); - doReturn(promiseValue).when(debugger).getValue(selectedVariable, anyLong(), anyInt()); + doReturn(promiseValue).when(debugger).getValue(eq(selectedVariable), anyLong(), anyInt()); doReturn(promiseValue).when(promiseValue).then((Operation) any()); presenter.onExpandVariablesTree(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index 0add2fae27b..2b12aec7c81 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -16,8 +16,6 @@ import static org.junit.Assert.fail; import static org.mockito.Answers.RETURNS_DEEP_STUBS; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; @@ -102,6 +100,8 @@ public class DebuggerTest extends BaseTest { private static final String DEBUG_INFO = "debug_info"; private static final String SESSION_ID = "debugger_id"; + private static final long THREAD_ID = 1; + private static final int FRAME_INDEX = 0; public static final int LINE_NUMBER = 20; public static final String FQN = "org.test.Test"; @@ -513,11 +513,11 @@ public void testGetValue() throws Exception { doReturn(mock(VariablePathDto.class)).when(dtoFactory).createDto(VariablePathDto.class); doReturn(mock(VariablePathDto.class)).when(variable).getVariablePath(); - doReturn(promiseValue).when(service).getValue(SESSION_ID, variableDto, anyLong(), anyInt()); + doReturn(promiseValue).when(service).getValue(SESSION_ID, variableDto, THREAD_ID, FRAME_INDEX); doReturn(promiseValue).when(promiseValue).then((Function) any()); doReturn(promiseValue).when(promiseValue).catchError((Operation) any()); - Promise result = debugger.getValue(variable, anyLong(), anyInt()); + Promise result = debugger.getValue(variable, THREAD_ID, FRAME_INDEX); assertEquals(promiseValue, result); } @@ -525,9 +525,9 @@ public void testGetValue() throws Exception { public void testGetValueWithoutConnection() throws Exception { debugger.setDebugSession(null); - debugger.getValue(null, anyLong(), anyInt()); + debugger.getValue(null, THREAD_ID, FRAME_INDEX); - verify(service, never()).getValue(any(), any(), anyLong(), anyInt()); + verify(service, never()).getValue(any(), any(), eq(THREAD_ID), eq(FRAME_INDEX)); } @Test @@ -539,7 +539,7 @@ public void testGetStackFrameDump() throws Exception { doReturn(promiseStackFrameDump) .when(service) - .getStackFrameDump(SESSION_ID, anyLong(), anyInt()); + .getStackFrameDump(SESSION_ID, THREAD_ID, FRAME_INDEX); doReturn(promiseStackFrameDump) .when(promiseStackFrameDump) .then((Function) any()); @@ -547,7 +547,7 @@ public void testGetStackFrameDump() throws Exception { .when(promiseStackFrameDump) .catchError((Operation) any()); - Promise result = debugger.getStackFrameDump(anyLong(), anyInt()); + Promise result = debugger.getStackFrameDump(THREAD_ID, FRAME_INDEX); assertEquals(promiseStackFrameDump, result); } @@ -555,26 +555,26 @@ public void testGetStackFrameDump() throws Exception { public void testGetStackFrameDumpWithoutConnection() throws Exception { debugger.setDebugSession(null); - debugger.getStackFrameDump(anyLong(), anyInt()); + debugger.getStackFrameDump(THREAD_ID, FRAME_INDEX); - verify(service, never()).getStackFrameDump(any(), anyLong(), anyInt()); + verify(service, never()).getStackFrameDump(any(), eq(THREAD_ID), eq(FRAME_INDEX)); } @Test public void testEvaluateExpression() throws Exception { final String expression = "a = 1"; Promise promiseString = mock(Promise.class); - doReturn(promiseString).when(service).evaluate(SESSION_ID, expression, anyLong(), anyInt()); + doReturn(promiseString).when(service).evaluate(SESSION_ID, expression, THREAD_ID, FRAME_INDEX); - Promise result = debugger.evaluate(expression, anyLong(), anyInt()); + Promise result = debugger.evaluate(expression, THREAD_ID, FRAME_INDEX); assertEquals(promiseString, result); } @Test public void testEvaluateExpressionWithoutConnection() throws Exception { debugger.setDebugSession(null); - debugger.evaluate("any", anyLong(), anyInt()); - verify(service, never()).evaluate(any(), any(), anyLong(), anyInt()); + debugger.evaluate("any", THREAD_ID, FRAME_INDEX); + verify(service, never()).evaluate(any(), any(), eq(THREAD_ID), eq(FRAME_INDEX)); } @Test @@ -598,10 +598,10 @@ public void testChangeVariableValue() throws Exception { doReturn(newValue).when(simpleValue).getString(); doReturn(simpleValue).when(variable).getValue(); - doReturn(promiseVoid).when(service).setValue(SESSION_ID, variableDto, anyLong(), anyInt()); + doReturn(promiseVoid).when(service).setValue(SESSION_ID, variableDto, THREAD_ID, FRAME_INDEX); doReturn(promiseVoid).when(promiseVoid).then((Operation) any()); - debugger.setValue(variable, anyLong(), anyInt()); + debugger.setValue(variable, THREAD_ID, FRAME_INDEX); verify(promiseVoid).then(operationVoidCaptor.capture()); operationVoidCaptor.getValue().apply(null); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java index a6910228047..37b1fc52d29 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java @@ -121,7 +121,7 @@ public void shouldGetNestedVariables() throws Exception { Variable variable = valueVariables.get(i); assertEquals( variable.getVariablePath().getPath(), ImmutableList.of("var1", "value", "[" + i + "]")); - assertEquals(variable.getValue().getString(), "var1".substring(i, i)); + assertEquals(variable.getValue().getString(), "var1".substring(i, i + 1)); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index 8beb90b1943..f80f8f2a6a6 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -101,7 +101,6 @@ private void validateMainThreadDump(List threads) { Method method = location.getMethod(); assertEquals(method.getName(), "main"); - assertTrue(method.getArguments().isEmpty()); } private void validateFinalizerThreadDump(List threads) { From 2d33bd917e3b1adaefa755321db0a81ca82007cc Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 23 Aug 2017 16:23:21 +0300 Subject: [PATCH 29/38] Refactoring --- .../che/ide/debug/BreakpointManagerImpl.java | 5 +- .../che/ide/debug/DebuggerObserver.java | 4 +- .../actions/ShowHideDebuggerPanelAction.java | 9 +- .../debugger/ide/debug/AbstractDebugger.java | 23 +- .../debugger/ide/debug/DebuggerPresenter.java | 263 +++++++++--------- .../debugger/ide/debug/DebuggerView.java | 34 +-- .../debugger/ide/debug/DebuggerViewImpl.java | 158 ++++++----- .../ide/debug/VariableNodeDataAdapter.java | 16 +- .../changevalue/ChangeValuePresenter.java | 30 +- .../ide/debug/DebuggerPresenterTest.java | 17 +- .../debugger/ide/debug/DebuggerTest.java | 2 +- .../debug/shared/model/MutableVariable.java | 8 - .../model/impl/MutableVariableImpl.java | 79 ++---- 13 files changed, 311 insertions(+), 337 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java index 1150a2b11a5..67b58110e8d 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java @@ -25,6 +25,9 @@ import java.util.Set; import java.util.logging.Logger; import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; import org.eclipse.che.commons.annotation.Nullable; @@ -616,7 +619,7 @@ public void onBreakpointStopped(String filePath, Location location) { } @Override - public void onValueChanged(List path, String newValue) {} + public void onValueChanged(Variable variable, long threadId, int frameIndex) {} @Override public void addObserver(BreakpointManagerObserver observer) { diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java index 192f4d44544..36c76fd839f 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java @@ -10,8 +10,8 @@ */ package org.eclipse.che.ide.debug; -import java.util.List; import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.ide.api.debug.Breakpoint; @@ -52,5 +52,5 @@ public interface DebuggerObserver { void onBreakpointStopped(String filePath, Location location); /** Event happens when value changed. */ - void onValueChanged(List path, String newValue); + void onValueChanged(Variable variable, long threadId, int frameIndex); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java index 3e9565c8a18..1eb18ea7df1 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/actions/ShowHideDebuggerPanelAction.java @@ -35,14 +35,9 @@ public ShowHideDebuggerPanelAction( @Override public void actionPerformed(ActionEvent e) { - if (debuggerPresenter.isDebuggerPanelPresent()) { - if (debuggerPresenter.isDebuggerPanelOpened()) { - debuggerPresenter.hideDebuggerPanel(); - } else { - debuggerPresenter.showDebuggerPanel(); - } + if (debuggerPresenter.isDebuggerPanelOpened()) { + debuggerPresenter.hideDebuggerPanel(); } else { - debuggerPresenter.updateView(); debuggerPresenter.showDebuggerPanel(); } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index ec44ca6f5f0..1861ced23d5 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -10,17 +10,10 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; - import com.google.common.base.Optional; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import javax.validation.constraints.NotNull; + import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; @@ -75,6 +68,15 @@ import org.eclipse.che.ide.util.storage.LocalStorage; import org.eclipse.che.ide.util.storage.LocalStorageProvider; +import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; + /** * The common debugger. * @@ -646,7 +648,7 @@ public Promise evaluate(String expression, long threadId, int frameIndex } @Override - public void setValue(final Variable variable, long threadId, int frameIndex) { + public void setValue(final Variable variable, final long threadId, final int frameIndex) { if (isConnected()) { Promise promise = service.setValue(debugSessionDto.getId(), toDto(variable), threadId, frameIndex); @@ -655,8 +657,7 @@ public void setValue(final Variable variable, long threadId, int frameIndex) { .then( it -> { for (DebuggerObserver observer : observers) { - observer.onValueChanged( - variable.getVariablePath().getPath(), variable.getValue().getString()); + observer.onValueChanged(variable, threadId, frameIndex); } }) .catchError( diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 77c04162c6d..5457d0f560f 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -23,8 +23,9 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; -import javax.validation.constraints.NotNull; + import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; @@ -78,12 +79,9 @@ public class DebuggerPresenter extends BasePresenter private final WorkspaceAgent workspaceAgent; private final DebuggerResourceHandlerFactory resourceHandlerManager; - private MutableVariable selectedVariable; private List variables; private List threadDump; private Location executionPoint; - private long selectedThreadId; - private int selectedFrameIndex; private DebuggerDescriptor debuggerDescriptor; @Inject @@ -114,8 +112,8 @@ public DebuggerPresenter( this.debuggerManager.addObserver(this); this.breakpointManager.addObserver(this); - resetState(); - updateBreakpoints(); + resetView(); + addDebuggerPanel(); } @Override @@ -140,156 +138,79 @@ public String getTitleToolTip() { @Override public void go(AcceptsOneWidget container) { - view.setBreakpoints(breakpointManager.getBreakpointList()); - container.setWidget(view); debuggerToolbar.go(view.getDebuggerToolbarPanel()); } @Override - public void onExpandVariablesTree() { - List rootVariables = selectedVariable.getVariables(); + public void onExpandVariablesTree(MutableVariable variable) { + List rootVariables = variable.getValue().getVariables(); if (rootVariables.isEmpty()) { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { Promise promise = - debugger.getValue(selectedVariable, selectedThreadId, selectedFrameIndex); + debugger.getValue(variable, view.getSelectedThreadId(), view.getSelectedFrameIndex()); promise .then( value -> { - selectedVariable.setValue(value); - view.setVariablesIntoSelectedVariable(value.getVariables()); - view.updateSelectedVariable(); + view.setVariableValue(variable, value); }) .catchError( error -> { - notificationManager.notify( - constant.failedToGetVariableValueTitle(), - error.getMessage(), - FAIL, - FLOAT_MODE); + Log.error(DebuggerPresenter.class, error.getCause()); }); } } } @Override - public void onSelectedVariableElement(@NotNull MutableVariable variable) { - this.selectedVariable = variable; + public void onSelectedThread(long threadId) { + updateStackFrameDump(threadId); + updateVariables(threadId, 0); } @Override - public void onSelectedThread(long threadId) { - selectedThreadId = threadId; - selectedFrameIndex = 0; + public void onSelectedFrame(int frameIndex) { + long selectedThreadId = view.getSelectedThreadId(); + updateVariables(selectedThreadId, frameIndex); for (ThreadDump td : threadDump) { if (td.getId() == selectedThreadId) { - view.setFrames(td.getFrames()); + StackFrameDump stackFrameDump = td.getFrames().get(frameIndex); + open(stackFrameDump.getLocation()); } } - updateStackFrameDump(); } - @Override - public void onSelectedFrame(int frameIndex) { - if (selectedFrameIndex != frameIndex) { - updateStackFrameDump(); - } - - selectedFrameIndex = frameIndex; - - for (ThreadDump td : threadDump) { - if (td.getId() == selectedThreadId) { - final StackFrameDump stackFrameDump = td.getFrames().get(selectedFrameIndex); - - Debugger debugger = debuggerManager.getActiveDebugger(); - if (debugger != null) { - DebuggerResourceHandler handler = - resourceHandlerManager.getOrDefault(debugger.getDebuggerType()); - handler.open( - stackFrameDump.getLocation(), - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) {} - - @Override - public void onSuccess(VirtualFile result) {} - }); - } - } + private void open(Location location) { + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null) { + DebuggerResourceHandler handler = + resourceHandlerManager.getOrDefault(debugger.getDebuggerType()); + + handler.open( + location, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) {} + + @Override + public void onSuccess(VirtualFile result) {} + }); } } public long getSelectedThreadId() { - return selectedThreadId; + return view.getSelectedThreadId(); } public int getSelectedFrameIndex() { - return selectedFrameIndex; - } - - public void showDebuggerPanel() { - partStack.setActivePart(this); - } - - public void hideDebuggerPanel() { - partStack.minimize(); - } - - public boolean isDebuggerPanelOpened() { - return partStack.getActivePart() == this; - } - - public boolean isDebuggerPanelPresent() { - return partStack != null && partStack.containsPart(this); - } - - private void resetState() { - variables = new ArrayList<>(); - threadDump = new ArrayList<>(); - selectedThreadId = -1; - selectedFrameIndex = -1; - selectedVariable = null; - executionPoint = null; - debuggerDescriptor = null; - view.setVariables(emptyList()); - view.setVMName(""); - view.setExecutionPoint(null); - view.setThreads(emptyList(), -1); - view.setFrames(emptyList()); - } - - public void updateView() { - if (debuggerDescriptor == null) { - view.setVMName(""); - } else { - view.setVMName(debuggerDescriptor.getInfo()); - } - - view.setExecutionPoint(executionPoint); - - view.setBreakpoints(breakpointManager.getBreakpointList()); - updateThreadDump(); - updateStackFrameDump(); - - showView(); + return view.getSelectedFrameIndex(); } protected void updateBreakpoints() { view.setBreakpoints(breakpointManager.getBreakpointList()); - - if (!breakpointManager.getBreakpointList().isEmpty() && !isDebuggerPanelPresent()) { - showView(); - showDebuggerPanel(); - } - } - - public void showView() { - if (partStack == null || !partStack.containsPart(this)) { - workspaceAgent.openPart(this, PartStackType.INFORMATION); - } } protected void updateThreadDump() { @@ -300,8 +221,11 @@ protected void updateThreadDump() { .then( threadDump -> { DebuggerPresenter.this.threadDump = threadDump; - view.setThreads(threadDump, selectedThreadId); - onSelectedThread(selectedThreadId); + if (executionPoint != null) { + view.setThreads(threadDump, executionPoint.getThreadId()); + updateStackFrameDump(executionPoint.getThreadId()); + updateVariables(executionPoint.getThreadId(), 0); + } }) .catchError( error -> { @@ -310,19 +234,29 @@ protected void updateThreadDump() { } } - protected void updateStackFrameDump() { + protected void updateStackFrameDump(long threadId) { + for (ThreadDump td : threadDump) { + if (td.getId() == threadId) { + view.setFrames(td.getFrames()); + } + } + } + + protected void updateVariables(long threadId, int frameIndex) { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null && debugger.isSuspended()) { - Promise promise = - debugger.getStackFrameDump(selectedThreadId, selectedFrameIndex); + Promise promise = debugger.getStackFrameDump(threadId, frameIndex); promise .then( stackFrameDump -> { - variables = new ArrayList<>(); - variables.addAll(stackFrameDump.getFields()); - variables.addAll(stackFrameDump.getVariables()); - - view.setVariables(variables); + if (threadId == view.getSelectedThreadId() + && frameIndex == view.getSelectedFrameIndex()) { + + variables = new LinkedList<>(); + variables.addAll(stackFrameDump.getFields()); + variables.addAll(stackFrameDump.getVariables()); + view.setVariables(variables); + } }) .catchError( error -> { @@ -331,9 +265,8 @@ protected void updateStackFrameDump() { } } - /** @return selected variable in variables tree or null if no selected variables */ public Variable getSelectedVariable() { - return selectedVariable; + return view.getSelectedDebuggerVariable(); } public ToolbarPresenter getDebuggerToolbar() { @@ -343,6 +276,7 @@ public ToolbarPresenter getDebuggerToolbar() { @Override public void onDebuggerAttached( final DebuggerDescriptor debuggerDescriptor, Promise connect) { + final String address = debuggerDescriptor.getAddress(); final StatusNotification notification = notificationManager.notify(constant.debuggerConnectingTitle(address), PROGRESS, FLOAT_MODE); @@ -356,7 +290,7 @@ public void onDebuggerAttached( notification.setContent(constant.debuggerConnectedDescription(address)); notification.setStatus(SUCCESS); - updateView(); + view.setVMName(debuggerDescriptor.getInfo()); showDebuggerPanel(); }) .catchError( @@ -372,11 +306,11 @@ public void onDebuggerAttached( public void onDebuggerDisconnected() { String address = debuggerDescriptor != null ? debuggerDescriptor.getAddress() : ""; String content = constant.debuggerDisconnectedDescription(address); + notificationManager.notify( constant.debuggerDisconnectedTitle(), content, SUCCESS, NOT_EMERGE_MODE); - resetState(); - updateView(); + resetView(); } @Override @@ -399,38 +333,91 @@ public void onAllBreakpointsDeleted() { @Override public void onPreStepInto() { - resetState(); + clearExecutionPoint(); } @Override public void onPreStepOut() { - resetState(); + clearExecutionPoint(); } @Override public void onPreStepOver() { - resetState(); + clearExecutionPoint(); } @Override public void onPreResume() { - resetState(); + clearExecutionPoint(); + } + + private void clearExecutionPoint() { + executionPoint = null; + variables = new ArrayList<>(); + threadDump = new ArrayList<>(); + view.setExecutionPoint(null); + view.setThreads(emptyList(), -1); + view.setFrames(emptyList()); + view.setVariables(emptyList()); + } + + private void resetView() { + variables = new ArrayList<>(); + threadDump = new ArrayList<>(); + executionPoint = null; + debuggerDescriptor = null; + updateBreakpoints(); + view.setVMName(""); + view.setExecutionPoint(null); + view.setThreads(emptyList(), -1); + view.setFrames(emptyList()); + view.setVariables(emptyList()); } @Override public void onBreakpointStopped(String filePath, Location location) { executionPoint = location; - selectedThreadId = executionPoint.getThreadId(); - selectedFrameIndex = 0; - - updateView(); + view.setExecutionPoint(executionPoint); + updateThreadDump(); } @Override - public void onValueChanged(List path, String newValue) { - updateStackFrameDump(); // TODO + public void onValueChanged(Variable variable, long threadId, int frameIndex) { + if (view.getSelectedThreadId() == threadId && view.getSelectedFrameIndex() == frameIndex) { + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null && debugger.isSuspended()) { + Promise promise = debugger.getValue(variable, threadId, frameIndex); + promise + .then( + value -> { + view.setVariableValue(variable, value); + }) + .catchError( + error -> { + Log.error(DebuggerPresenter.class, error.getCause()); + }); + } + } } @Override public void onActiveDebuggerChanged(@Nullable Debugger activeDebugger) {} + + public void addDebuggerPanel() { + if (partStack == null || !partStack.containsPart(this)) { + workspaceAgent.openPart(this, PartStackType.INFORMATION); + } + } + + public void showDebuggerPanel() { + partStack.setActivePart(this); + } + + public void hideDebuggerPanel() { + partStack.minimize(); + } + + public boolean isDebuggerPanelOpened() { + return partStack.getActivePart() == this; + } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index 843b4ed9f9b..9e4d9cb7ae4 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -15,9 +15,11 @@ import javax.validation.constraints.NotNull; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.mvp.View; @@ -38,15 +40,7 @@ interface ActionDelegate extends BaseActionDelegate { * Performs any actions appropriate in response to the user having pressed the expand button in * variables tree. */ - void onExpandVariablesTree(); - - /** - * Performs any actions appropriate in response to the user having selected variable in* - * variables tree. - * - * @param variable variable that is selected - */ - void onSelectedVariableElement(@NotNull MutableVariable variable); + void onExpandVariablesTree(MutableVariable variable); /** Is invoked when a new thread is selected. */ void onSelectedThread(long threadId); @@ -73,6 +67,9 @@ interface ActionDelegate extends BaseActionDelegate { */ void setVariables(@NotNull List variables); + /** Updates variable in the list */ + void setVariableValue(@NotNull Variable variable, @NotNull SimpleValue value); + /** * Sets breakpoints. * @@ -103,22 +100,11 @@ interface ActionDelegate extends BaseActionDelegate { */ void setTitle(@NotNull String title); - /** Update contents for selected variable. */ - void updateSelectedVariable(); + /** Returns selected thread id {@link ThreadDump#getId()} or -1 if there is no selection. */ + long getSelectedThreadId(); - /** - * Add elements into selected variable. - * - * @param variables variable what need to add into - */ - void setVariablesIntoSelectedVariable(@NotNull List variables); - - /** - * Sets whether this object is visible. - * - * @param visible true to show the tab, false to hide it - */ - void setVisible(boolean visible); + /** Returns selected frame index inside thread or -1 if there is no selection. */ + int getSelectedFrameIndex(); /** * Returns selected variable in the variables list on debugger panel or null if no selection. diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index b9f9829c2fd..370f06605bd 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -10,6 +10,12 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; +import elemental.dom.Element; +import elemental.events.KeyboardEvent; +import elemental.events.MouseEvent; +import elemental.html.SpanElement; +import elemental.html.TableElement; + import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -23,19 +29,15 @@ import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; import com.google.inject.Singleton; -import elemental.dom.Element; -import elemental.events.KeyboardEvent; -import elemental.events.MouseEvent; -import elemental.html.TableElement; -import java.util.ArrayList; -import java.util.List; -import javax.validation.constraints.NotNull; + import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadDump; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.impl.MutableVariableImpl; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.Resources; import org.eclipse.che.ide.api.debug.Breakpoint; @@ -49,6 +51,10 @@ import org.eclipse.che.plugin.debugger.ide.DebuggerLocalizationConstant; import org.eclipse.che.plugin.debugger.ide.DebuggerResources; +import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.List; + /** * The class business logic which allow us to change visual representation of debugger panel. * @@ -120,7 +126,7 @@ public void onNodeAction(@NotNull TreeNodeElement node) {} @Override public void onNodeClosed(@NotNull TreeNodeElement node) { - selectedVariable = null; + selectedVariable = node; } @Override @@ -138,15 +144,13 @@ public void onNodeDragDrop( @Override public void onNodeExpanded(@NotNull final TreeNodeElement node) { selectedVariable = node; - delegate.onSelectedVariableElement(selectedVariable.getData()); - delegate.onExpandVariablesTree(); + delegate.onExpandVariablesTree(node.getData()); } @Override public void onNodeSelected( @NotNull TreeNodeElement node, @NotNull SignalEvent event) { selectedVariable = node; - delegate.onSelectedVariableElement(selectedVariable.getData()); } @Override @@ -163,47 +167,6 @@ public void onKeyboard(@NotNull KeyboardEvent event) {} minimizeButton.ensureDebugId("debugger-minimizeBut"); } - private SimpleList createBreakpointList() { - TableElement breakPointsElement = Elements.createTableElement(); - breakPointsElement.setAttribute("style", "width: 100%"); - - SimpleList.ListEventDelegate breakpointListEventDelegate = - new SimpleList.ListEventDelegate() { - public void onListItemClicked(Element itemElement, Breakpoint itemData) { - breakpoints.getSelectionModel().setSelectedItem(itemData); - } - - public void onListItemDoubleClicked(Element listItemBase, Breakpoint itemData) {} - }; - - return SimpleList.create( - (SimpleList.View) breakPointsElement, - coreRes.defaultSimpleListCss(), - new BreakpointItemRender(debuggerResources), - breakpointListEventDelegate); - } - - private SimpleList createFramesList() { - TableElement frameElement = Elements.createTableElement(); - frameElement.setAttribute("style", "width: 100%"); - - SimpleList.ListEventDelegate frameListEventDelegate = - new SimpleList.ListEventDelegate() { - public void onListItemClicked(Element itemElement, StackFrameDump itemData) { - frames.getSelectionModel().setSelectedItem(itemData); - delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); - } - - public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) {} - }; - - return SimpleList.create( - (SimpleList.View) frameElement, - coreRes.defaultSimpleListCss(), - new FrameItemRender(), - frameListEventDelegate); - } - @Override public void setExecutionPoint(@Nullable Location location) { StringBuilder labelText = new StringBuilder(); @@ -226,10 +189,35 @@ public void setVariables(@NotNull List variables) { root = new MutableVariableImpl(); this.variables.getModel().setRoot(root); } - root.setVariables(variables); + root.setValue(new SimpleValueImpl(variables, null)); this.variables.renderTree(0); } + @Override + public void setVariableValue(Variable variable, SimpleValue value) { + MutableVariableImpl nodeData = new MutableVariableImpl(variable); + + TreeNodeElement node = variables.getNode(nodeData); + if (node != null) { + node.getData().setValue(value); + + SpanElement element = variables.getModel().getNodeRenderer().renderNodeContents(nodeData); + node.getNodeLabel().setInnerHTML(element.getInnerHTML()); + + for (Variable nestedVariable : value.getVariables()) { + setVariableValue(nestedVariable, nestedVariable.getValue()); + } + + if (node.isOpen()) { + if (value.getVariables().isEmpty()) { + variables.closeNode(node); + } else { + variables.expandNode(node); + } + } + } + } + @Override public void setBreakpoints(@NotNull List breakpoints) { this.breakpoints.render(breakpoints); @@ -271,18 +259,6 @@ public void setVMName(@Nullable String name) { vmName.setText(name == null ? "" : name); } - @Override - public void updateSelectedVariable() { - variables.closeNode(selectedVariable); - variables.expandNode(selectedVariable); - } - - @Override - public void setVariablesIntoSelectedVariable(@NotNull List variables) { - MutableVariable rootVariable = selectedVariable.getData(); - rootVariable.setVariables(variables); - } - @Override public MutableVariable getSelectedDebuggerVariable() { if (selectedVariable != null) { @@ -296,8 +272,60 @@ public AcceptsOneWidget getDebuggerToolbarPanel() { return toolbarPanel; } + @Override + public long getSelectedThreadId() { + String selectedValue = threads.getSelectedValue(); + return selectedValue == null ? -1 : Integer.parseInt(selectedValue); + } + + @Override + public int getSelectedFrameIndex() { + return frames.getSelectionModel().getSelectedIndex(); + } + @UiHandler({"threads"}) void onThreadChanged(ChangeEvent event) { delegate.onSelectedThread(Integer.parseInt(threads.getSelectedValue())); } + + private SimpleList createBreakpointList() { + TableElement breakPointsElement = Elements.createTableElement(); + breakPointsElement.setAttribute("style", "width: 100%"); + + SimpleList.ListEventDelegate breakpointListEventDelegate = + new SimpleList.ListEventDelegate() { + public void onListItemClicked(Element itemElement, Breakpoint itemData) { + breakpoints.getSelectionModel().setSelectedItem(itemData); + } + + public void onListItemDoubleClicked(Element listItemBase, Breakpoint itemData) {} + }; + + return SimpleList.create( + (SimpleList.View) breakPointsElement, + coreRes.defaultSimpleListCss(), + new BreakpointItemRender(debuggerResources), + breakpointListEventDelegate); + } + + private SimpleList createFramesList() { + TableElement frameElement = Elements.createTableElement(); + frameElement.setAttribute("style", "width: 100%"); + + SimpleList.ListEventDelegate frameListEventDelegate = + new SimpleList.ListEventDelegate() { + public void onListItemClicked(Element itemElement, StackFrameDump itemData) { + frames.getSelectionModel().setSelectedItem(itemData); + delegate.onSelectedFrame(frames.getSelectionModel().getSelectedIndex()); + } + + public void onListItemDoubleClicked(Element listItemBase, StackFrameDump itemData) {} + }; + + return SimpleList.create( + (SimpleList.View) frameElement, + coreRes.defaultSimpleListCss(), + new FrameItemRender(), + frameListEventDelegate); + } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java index e576e54157a..4974597a2b7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableNodeDataAdapter.java @@ -13,8 +13,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; import javax.validation.constraints.NotNull; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.impl.MutableVariableImpl; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.ui.tree.NodeDataAdapter; import org.eclipse.che.ide.ui.tree.TreeNodeElement; @@ -57,7 +59,11 @@ public boolean hasChildren(@NotNull MutableVariable data) { @Override @NotNull public List getChildren(@NotNull MutableVariable data) { - return data.getVariables(); + return data.getValue() + .getVariables() + .stream() + .map(MutableVariableImpl::new) + .collect(Collectors.toList()); } /** {@inheritDoc} */ @@ -124,7 +130,13 @@ public MutableVariable getNodeByPath( for (int i = 0; i < relativeNodePath.size(); i++) { String path = relativeNodePath.get(i); if (localRoot != null) { - List variables = new ArrayList<>(localRoot.getVariables()); + List variables = + localRoot + .getValue() + .getVariables() + .stream() + .map(MutableVariableImpl::new) + .collect(Collectors.toList()); localRoot = null; for (int j = 0; j < variables.size(); j++) { MutableVariable variable = variables.get(j); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java index aab48e64582..4bf60a4ac2a 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/changevalue/ChangeValuePresenter.java @@ -32,8 +32,6 @@ public class ChangeValuePresenter implements ChangeValueView.ActionDelegate { private final DebuggerPresenter debuggerPresenter; private final DebuggerLocalizationConstant constant; - private Variable variable; - @Inject public ChangeValuePresenter( ChangeValueView view, @@ -48,9 +46,9 @@ public ChangeValuePresenter( } public void showDialog() { - variable = debuggerPresenter.getSelectedVariable(); - view.setValueTitle(constant.changeValueViewExpressionFieldTitle(variable.getName())); - view.setValue(variable.getValue().getString()); + Variable selectedVariable = debuggerPresenter.getSelectedVariable(); + view.setValueTitle(constant.changeValueViewExpressionFieldTitle(selectedVariable.getName())); + view.setValue(selectedVariable.getValue().getString()); view.focusInValueField(); view.selectAllText(); view.setEnableChangeButton(false); @@ -65,12 +63,22 @@ public void onCancelClicked() { @Override public void onChangeClicked() { Debugger debugger = debuggerManager.getActiveDebugger(); - if (debugger != null) { - Variable newVariable = - new VariableImpl(new SimpleValueImpl(view.getValue()), variable.getVariablePath()); - final long threadId = debuggerPresenter.getSelectedThreadId(); - final int frameIndex = debuggerPresenter.getSelectedFrameIndex(); - debugger.setValue(newVariable, threadId, frameIndex); + if (debugger != null && debugger.isSuspended()) { + Variable selectedVariable = debuggerPresenter.getSelectedVariable(); + + if (selectedVariable != null) { + Variable newVariable = + new VariableImpl( + selectedVariable.getType(), + selectedVariable.getName(), + new SimpleValueImpl(view.getValue()), + selectedVariable.isPrimitive(), + selectedVariable.getVariablePath()); + + final long threadId = debuggerPresenter.getSelectedThreadId(); + final int frameIndex = debuggerPresenter.getSelectedFrameIndex(); + debugger.setValue(newVariable, threadId, frameIndex); + } } view.close(); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index 3cadcbb2dd9..17bb34de771 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -33,6 +33,10 @@ import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; +import org.eclipse.che.api.debug.shared.model.SimpleValue; +import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; +import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; +import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.Promise; @@ -66,6 +70,8 @@ */ public class DebuggerPresenterTest extends BaseTest { public static final String ERROR_MESSAGE = "error message"; + private static final long THREAD_ID = 1; + private static final int FRAME_INDEX = 0; @Mock private DebuggerView view; @Mock private DebuggerLocalizationConstant constant; @@ -165,7 +171,7 @@ public void testOnExpandVariablesTree() throws OperationException { @Test public void testShowAndUpdateView() { - presenter.updateView(); + presenter.refreshState(); verify(view).setVMName(eq("")); } @@ -279,17 +285,20 @@ public void testOnBreakpointStopped() { presenter.onBreakpointStopped(filePath, executionPoint); - verify(presenter).updateView(); + verify(presenter).refreshState(); verify(view).setExecutionPoint(any(Location.class)); } @Test public void testOnValueChanged() { - doReturn(promiseString).when(debugger).getStackFrameDump(anyLong(), anyInt()); + doReturn(promiseString).when(debugger).getStackFrameDump(THREAD_ID, FRAME_INDEX); doReturn(promiseString).when(promiseString).then((Operation) any()); ArrayList path = new ArrayList<>(); String newValue = "newValue"; - presenter.onValueChanged(path, newValue); + presenter.onValueChanged( + new VariableImpl(new SimpleValueImpl(newValue), new VariablePathImpl(path)), + THREAD_ID, + FRAME_INDEX); } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index 2b12aec7c81..2638fb74fd7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -605,7 +605,7 @@ public void testChangeVariableValue() throws Exception { verify(promiseVoid).then(operationVoidCaptor.capture()); operationVoidCaptor.getValue().apply(null); - verify(observer).onValueChanged(path, newValue); + verify(observer).onValueChanged(variable, THREAD_ID, FRAME_INDEX); verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture()); operationPromiseErrorCaptor.getValue().apply(promiseError); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java index eda9131f765..709e2b157ed 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/MutableVariable.java @@ -10,17 +10,9 @@ */ package org.eclipse.che.api.debug.shared.model; -import java.util.List; - /** @author Anatoliy Bazko */ public interface MutableVariable extends Variable { - /** The nested variables. */ - List getVariables(); - /** Sets the new variable value. */ void setValue(SimpleValue value); - - /** Sets the new list of nested variables. */ - void setVariables(List variables); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java index 0fc6d836afd..5232711f92f 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java @@ -10,9 +10,8 @@ */ package org.eclipse.che.api.debug.shared.model.impl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import com.google.common.base.Objects; + import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; @@ -24,32 +23,30 @@ public class MutableVariableImpl implements MutableVariable { private final String type; private final boolean isPrimitive; private final VariablePath variablePath; - private SimpleValue value; - private List variables; public MutableVariableImpl( - String type, - String name, - SimpleValue value, - VariablePath variablePath, - boolean isPrimitive, - List variables) { + String type, String name, SimpleValue value, VariablePath variablePath, boolean isPrimitive) { this.name = name; this.value = value; this.type = type; this.isPrimitive = isPrimitive; - this.variables = - variables == null || variables.isEmpty() - ? Collections.emptyList() - : toMutable(variables); this.variablePath = variablePath; } + public MutableVariableImpl(Variable variable) { + this( + variable.getType(), + variable.getName(), + variable.getValue(), + variable.getVariablePath(), + variable.isPrimitive()); + } + public MutableVariableImpl() { - this(null, null, null, null, false, null); + this(null, null, null, null, false); } @Override @@ -72,21 +69,11 @@ public boolean isPrimitive() { return isPrimitive; } - @Override - public List getVariables() { - return variables; - } - @Override public void setValue(SimpleValue value) { this.value = value; } - @Override - public void setVariables(List variables) { - this.variables = toMutable(variables); - } - @Override public VariablePath getVariablePath() { return variablePath; @@ -96,46 +83,12 @@ public VariablePath getVariablePath() { public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof MutableVariableImpl)) return false; - - MutableVariableImpl variable = (MutableVariableImpl) o; - - if (isPrimitive != variable.isPrimitive) return false; - if (name != null ? !name.equals(variable.name) : variable.name != null) return false; - if (value != null ? !value.equals(variable.value) : variable.value != null) return false; - if (type != null ? !type.equals(variable.type) : variable.type != null) return false; - if (variables != null ? !variables.equals(variable.variables) : variable.variables != null) - return false; - return !(variablePath != null - ? !variablePath.equals(variable.variablePath) - : variable.variablePath != null); + MutableVariableImpl that = (MutableVariableImpl) o; + return Objects.equal(variablePath, that.variablePath); } @Override public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (value != null ? value.hashCode() : 0); - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (isPrimitive ? 1 : 0); - result = 31 * result + (variables != null ? variables.hashCode() : 0); - result = 31 * result + (variablePath != null ? variablePath.hashCode() : 0); - return result; - } - - private static MutableVariable toMutable(Variable variable) { - return new MutableVariableImpl( - variable.getType(), - variable.getName(), - variable.getValue(), - variable.getVariablePath(), - variable.isPrimitive(), - variable.getValue().getVariables()); - } - - private static List toMutable(List variables) { - List mv = new ArrayList<>(variables.size()); - for (Variable v : variables) { - mv.add(toMutable(v)); - } - return mv; + return Objects.hashCode(variablePath); } } From 63b3f877a79d3b7e6a3797f9f074b1cd26ea862f Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 23 Aug 2017 16:51:10 +0300 Subject: [PATCH 30/38] Rename ThreadDump model class to ThreadState --- .../ide/api/debug/DebuggerServiceClient.java | 14 ++--- .../api/debug/DebuggerServiceClientImpl.java | 6 +- .../org/eclipse/che/ide/debug/Debugger.java | 14 ++--- .../debugger/ide/debug/AbstractDebugger.java | 4 +- .../debugger/ide/debug/DebuggerPresenter.java | 28 +++++----- .../debugger/ide/debug/DebuggerView.java | 9 ++- .../debugger/ide/debug/DebuggerViewImpl.java | 20 +++---- .../che/plugin/jdb/server/JavaDebugger.java | 14 ++--- .../jdb/server/EvaluateExpressionTest1.java | 8 +-- .../jdb/server/StackFrameDumpTest1.java | 8 +-- .../plugin/jdb/server/ThreadDumpTest1.java | 56 +++++++++---------- .../plugin/jdb/server/ThreadDumpTest2.java | 10 ++-- .../jdb/server/util/JavaDebuggerUtils.java | 6 +- ...ThreadDumpDto.java => ThreadStateDto.java} | 16 +++--- .../{ThreadDump.java => ThreadState.java} | 4 +- ...readDumpImpl.java => ThreadStateImpl.java} | 10 ++-- .../che/api/debugger/server/Debugger.java | 8 +-- .../api/debugger/server/DebuggerService.java | 10 ++-- .../che/api/debugger/server/DtoConverter.java | 22 ++++---- 19 files changed, 133 insertions(+), 134 deletions(-) rename wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/{ThreadDumpDto.java => ThreadStateDto.java} (72%) rename wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/{ThreadDump.java => ThreadState.java} (93%) rename wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/{ThreadDumpImpl.java => ThreadStateImpl.java} (90%) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java index 59f66f4a019..eccdbd9ffca 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java @@ -17,7 +17,7 @@ import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; import org.eclipse.che.api.debug.shared.dto.action.StartActionDto; @@ -25,7 +25,7 @@ import org.eclipse.che.api.debug.shared.dto.action.StepOutActionDto; import org.eclipse.che.api.debug.shared.dto.action.StepOverActionDto; import org.eclipse.che.api.debug.shared.dto.action.SuspendActionDto; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.promises.client.Promise; /** @@ -109,7 +109,7 @@ public interface DebuggerServiceClient { * Gets the stack frame dump. * * @param id debug session id - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise getStackFrameDump(String id, long threadId, int frameIndex); @@ -119,7 +119,7 @@ public interface DebuggerServiceClient { * * @param id debug session id */ - Promise> getThreadDump(String id); + Promise> getThreadDump(String id); /** * Resumes application. @@ -132,7 +132,7 @@ public interface DebuggerServiceClient { * Returns a value of the variable inside the specific frame. * * @param id debug session id - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise getValue( @@ -142,7 +142,7 @@ Promise getValue( * Sets the new value of the variable inside the specific frame. * * @param id debug session id - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise setValue(String id, VariableDto variableDto, long threadId, int frameIndex); @@ -176,7 +176,7 @@ Promise getValue( * * @param id debug session id * @param expression the expression to evaluate - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise evaluate(String id, String expression, long threadId, int frameIndex); diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java index e3031ee1aa2..e931b8b3fbd 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java @@ -23,7 +23,7 @@ import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ActionDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; @@ -140,11 +140,11 @@ public Promise getStackFrameDump(String id, long threadId, in } @Override - public Promise> getThreadDump(String id) { + public Promise> getThreadDump(String id) { final String requestUrl = getBaseUrl(id) + "/threaddump"; return asyncRequestFactory .createGetRequest(requestUrl) - .send(dtoUnmarshallerFactory.newListUnmarshaller(ThreadDumpDto.class)); + .send(dtoUnmarshallerFactory.newListUnmarshaller(ThreadStateDto.class)); } @Override diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 8f0cbf1d872..8ee0a8f7fab 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -12,10 +12,10 @@ import java.util.List; import java.util.Map; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.ide.api.resources.VirtualFile; @@ -81,7 +81,7 @@ public interface Debugger extends DebuggerObservable { /** * Evaluates the given expression inside a specific frame. * - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise evaluate(String expression, long threadId, int frameIndex); @@ -90,7 +90,7 @@ public interface Debugger extends DebuggerObservable { * Gets the value of the given variable inside a specific frame. * * @param variable the variable to get value from - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise getValue(Variable variable, long threadId, int frameIndex); @@ -98,19 +98,19 @@ public interface Debugger extends DebuggerObservable { /** * Gets a stack frame dump. * - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ Promise getStackFrameDump(long threadId, int frameIndex); /** Gets thread dump. */ - Promise> getThreadDump(); + Promise> getThreadDump(); /** * Sets a new value in the variable inside a specific frame. * * @param variable the variable to update - * @param threadId the unique thread id {@link ThreadDump#getId()} + * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ void setValue(Variable variable, long threadId, int frameIndex); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 1861ced23d5..76bbfb0c961 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -21,7 +21,7 @@ import org.eclipse.che.api.debug.shared.dto.DebugSessionDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; @@ -332,7 +332,7 @@ public Promise getStackFrameDump(long threadId, int fr } @Override - public Promise> getThreadDump() { + public Promise> getThreadDump() { if (!isConnected()) { return Promises.reject(JsPromiseError.create("Debugger is not connected")); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 5457d0f560f..e03e695635a 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -30,7 +30,7 @@ import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.commons.annotation.Nullable; @@ -79,10 +79,10 @@ public class DebuggerPresenter extends BasePresenter private final WorkspaceAgent workspaceAgent; private final DebuggerResourceHandlerFactory resourceHandlerManager; - private List variables; - private List threadDump; - private Location executionPoint; - private DebuggerDescriptor debuggerDescriptor; + private List variables; + private List threadDump; + private Location executionPoint; + private DebuggerDescriptor debuggerDescriptor; @Inject public DebuggerPresenter( @@ -175,9 +175,9 @@ public void onSelectedFrame(int frameIndex) { long selectedThreadId = view.getSelectedThreadId(); updateVariables(selectedThreadId, frameIndex); - for (ThreadDump td : threadDump) { - if (td.getId() == selectedThreadId) { - StackFrameDump stackFrameDump = td.getFrames().get(frameIndex); + for (ThreadState ts : threadDump) { + if (ts.getId() == selectedThreadId) { + StackFrameDump stackFrameDump = ts.getFrames().get(frameIndex); open(stackFrameDump.getLocation()); } } @@ -222,7 +222,7 @@ protected void updateThreadDump() { threadDump -> { DebuggerPresenter.this.threadDump = threadDump; if (executionPoint != null) { - view.setThreads(threadDump, executionPoint.getThreadId()); + view.setThreadDump(threadDump, executionPoint.getThreadId()); updateStackFrameDump(executionPoint.getThreadId()); updateVariables(executionPoint.getThreadId(), 0); } @@ -235,9 +235,9 @@ protected void updateThreadDump() { } protected void updateStackFrameDump(long threadId) { - for (ThreadDump td : threadDump) { - if (td.getId() == threadId) { - view.setFrames(td.getFrames()); + for (ThreadState ts : threadDump) { + if (ts.getId() == threadId) { + view.setFrames(ts.getFrames()); } } } @@ -356,7 +356,7 @@ private void clearExecutionPoint() { variables = new ArrayList<>(); threadDump = new ArrayList<>(); view.setExecutionPoint(null); - view.setThreads(emptyList(), -1); + view.setThreadDump(emptyList(), -1); view.setFrames(emptyList()); view.setVariables(emptyList()); } @@ -369,7 +369,7 @@ private void resetView() { updateBreakpoints(); view.setVMName(""); view.setExecutionPoint(null); - view.setThreads(emptyList(), -1); + view.setThreadDump(emptyList(), -1); view.setFrames(emptyList()); view.setVariables(emptyList()); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index 9e4d9cb7ae4..471abbebd35 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -17,9 +17,8 @@ import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; -import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.mvp.View; @@ -78,10 +77,10 @@ interface ActionDelegate extends BaseActionDelegate { void setBreakpoints(@NotNull List breakPoints); /** - * Sets the list of the threads and select the one with {@link ThreadDump#getId()} equal to {@code + * Sets thread dump and select the thread with {@link ThreadState#getId()} equal to {@code * activeThreadId}. */ - void setThreads(@NotNull List threadDumps, long threadIdToSelect); + void setThreadDump(@NotNull List threadDump, long threadIdToSelect); /** Sets the list of frames for selected thread. */ void setFrames(@NotNull List stackFrameDumps); @@ -100,7 +99,7 @@ interface ActionDelegate extends BaseActionDelegate { */ void setTitle(@NotNull String title); - /** Returns selected thread id {@link ThreadDump#getId()} or -1 if there is no selection. */ + /** Returns selected thread id {@link ThreadState#getId()} or -1 if there is no selection. */ long getSelectedThreadId(); /** Returns selected frame index inside thread or -1 if there is no selection. */ diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 370f06605bd..7f32fdfca93 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -34,7 +34,7 @@ import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.impl.MutableVariableImpl; import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; @@ -224,23 +224,23 @@ public void setBreakpoints(@NotNull List breakpoints) { } @Override - public void setThreads(List threadDumps, long threadIdToSelect) { + public void setThreadDump(List threadDump, long threadIdToSelect) { threads.clear(); - for (int i = 0; i < threadDumps.size(); i++) { - ThreadDump td = threadDumps.get(i); + for (int i = 0; i < threadDump.size(); i++) { + ThreadState ts = threadDump.get(i); String item = "\"" - + td.getName() + + ts.getName() + "\"@" - + td.getId() + + ts.getId() + " in group \"" - + td.getGroupName() + + ts.getGroupName() + "\": " - + td.getStatus(); - threads.addItem(item, String.valueOf(td.getId())); + + ts.getStatus(); + threads.addItem(item, String.valueOf(ts.getId())); - if (td.getId() == threadIdToSelect) { + if (ts.getId() == threadIdToSelect) { threads.setSelectedIndex(i); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 0a79acbd733..34fbc50c69d 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -53,7 +53,7 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; @@ -64,7 +64,7 @@ import org.eclipse.che.api.debug.shared.model.action.StepOverAction; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.DebuggerInfoImpl; -import org.eclipse.che.api.debug.shared.model.impl.ThreadDumpImpl; +import org.eclipse.che.api.debug.shared.model.impl.ThreadStateImpl; import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.DisconnectEventImpl; import org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl; @@ -384,8 +384,8 @@ public StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws De } @Override - public List getThreadDumps() throws DebuggerException { - List threadDumps = new LinkedList<>(); + public List getThreadDump() throws DebuggerException { + List threadStates = new LinkedList<>(); for (ThreadReference t : vm.allThreads()) { List frames = new LinkedList<>(); @@ -398,8 +398,8 @@ public List getThreadDumps() throws DebuggerException { // Thread isn't suspended. Information isn't available. } - threadDumps.add( - new ThreadDumpImpl( + threadStates.add( + new ThreadStateImpl( t.uniqueID(), t.name(), t.threadGroup().name(), @@ -408,7 +408,7 @@ public List getThreadDumps() throws DebuggerException { frames)); } - return threadDumps; + return threadStates; } /** * Get value of variable with specified path. Each item in path is name of variable. diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java index a815d9e351d..a6fb7847381 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java @@ -20,7 +20,7 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; @@ -62,11 +62,11 @@ public void tearDown() throws Exception { @Test(dataProvider = "evaluateExpression") public void shouldEvaluateExpression(String expression, String expectedResult, int frameIndex) throws Exception { - Optional main = - debugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); + Optional main = + debugger.getThreadDump().stream().filter(t -> t.getName().equals("main")).findAny(); assertTrue(main.isPresent()); - ThreadDump mainThread = main.get(); + ThreadState mainThread = main.get(); String actualResult = debugger.evaluate(expression, mainThread.getId(), frameIndex); assertEquals(actualResult, expectedResult); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java index 03ac8838673..5c55315b656 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java @@ -31,7 +31,7 @@ import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; @@ -69,11 +69,11 @@ public void tearDown() throws Exception { @Test public void shouldGetStackFrameDump() throws Exception { - Optional main = - debugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); + Optional main = + debugger.getThreadDump().stream().filter(t -> t.getName().equals("main")).findAny(); assertTrue(main.isPresent()); - ThreadDump mainThread = main.get(); + ThreadState mainThread = main.get(); assertEquals(mainThread.getFrames().size(), 3); validateFrame0(mainThread.getId()); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index f80f8f2a6a6..192236ed70b 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -23,11 +23,11 @@ import java.util.Optional; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.Method; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; @@ -66,26 +66,26 @@ public void tearDown() throws Exception { @Test public void shouldGetThreadDump() throws Exception { - List threads = - debugger.getThreadDumps().stream().map(DtoConverter::asDto).collect(toList()); + List threads = + debugger.getThreadDump().stream().map(DtoConverter::asDto).collect(toList()); validateMainThreadDump(threads); validateSomeThreadDump(threads); validateFinalizerThreadDump(threads); } - private void validateMainThreadDump(List threads) { - Optional mainThread = + private void validateMainThreadDump(List threads) { + Optional mainThread = threads.stream().filter(t -> t.getName().equals("main")).findAny(); assertTrue(mainThread.isPresent()); - ThreadDump threadDump = mainThread.get(); - assertEquals(threadDump.getName(), "main"); - assertEquals(threadDump.getGroupName(), "main"); - assertTrue(threadDump.isSuspended()); - assertEquals(threadDump.getStatus(), ThreadStatus.RUNNING); + ThreadState threadState = mainThread.get(); + assertEquals(threadState.getName(), "main"); + assertEquals(threadState.getGroupName(), "main"); + assertTrue(threadState.isSuspended()); + assertEquals(threadState.getStatus(), ThreadStatus.RUNNING); - List frames = threadDump.getFrames(); + List frames = threadState.getFrames(); assertEquals(frames.size(), 1); StackFrameDump stackFrameDump = frames.get(0); @@ -103,18 +103,18 @@ private void validateMainThreadDump(List threads) { assertEquals(method.getName(), "main"); } - private void validateFinalizerThreadDump(List threads) { - Optional finalizerThread = + private void validateFinalizerThreadDump(List threads) { + Optional finalizerThread = threads.stream().filter(t -> t.getName().equals("Finalizer")).findAny(); assertTrue(finalizerThread.isPresent()); - ThreadDump threadDump = finalizerThread.get(); - assertEquals(threadDump.getName(), "Finalizer"); - assertEquals(threadDump.getGroupName(), "system"); - assertTrue(threadDump.isSuspended()); - assertEquals(threadDump.getStatus(), ThreadStatus.WAIT); + ThreadState threadState = finalizerThread.get(); + assertEquals(threadState.getName(), "Finalizer"); + assertEquals(threadState.getGroupName(), "system"); + assertTrue(threadState.isSuspended()); + assertEquals(threadState.getStatus(), ThreadStatus.WAIT); - List frames = threadDump.getFrames(); + List frames = threadState.getFrames(); assertEquals(frames.size(), 4); StackFrameDump stackFrameDump = frames.get(0); @@ -132,18 +132,18 @@ private void validateFinalizerThreadDump(List threads) { assertTrue(method.getArguments().isEmpty()); } - private void validateSomeThreadDump(List threads) { - Optional someThread = + private void validateSomeThreadDump(List threads) { + Optional someThread = threads.stream().filter(t -> t.getName().equals("SomeThread")).findAny(); assertTrue(someThread.isPresent()); - ThreadDump threadDump = someThread.get(); - assertEquals(threadDump.getName(), "SomeThread"); - assertEquals(threadDump.getGroupName(), "main"); - assertTrue(threadDump.isSuspended()); - assertEquals(threadDump.getStatus(), ThreadStatus.RUNNING); + ThreadState threadState = someThread.get(); + assertEquals(threadState.getName(), "SomeThread"); + assertEquals(threadState.getGroupName(), "main"); + assertTrue(threadState.isSuspended()); + assertEquals(threadState.getStatus(), ThreadStatus.RUNNING); - List frames = threadDump.getFrames(); + List frames = threadState.getFrames(); assertEquals(frames.size(), 1); StackFrameDump stackFrameDump = frames.get(0); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java index 2fdcccabf62..38bdde64e77 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest2.java @@ -21,8 +21,8 @@ import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; import org.eclipse.che.api.debugger.server.DtoConverter; @@ -54,10 +54,10 @@ public void tearDown() throws Exception { @Test public void shouldGetThreadDump() throws Exception { - List threads = - debugger.getThreadDumps().stream().map(DtoConverter::asDto).collect(toList()); + List threads = + debugger.getThreadDump().stream().map(DtoConverter::asDto).collect(toList()); - for (ThreadDump t : threads) { + for (ThreadState t : threads) { assertFalse(t.isSuspended()); assertTrue(t.getFrames().isEmpty()); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java index 6af57cedb78..bbc5a2c1c98 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/util/JavaDebuggerUtils.java @@ -22,7 +22,7 @@ import java.util.concurrent.BlockingQueue; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; @@ -89,8 +89,8 @@ public static void terminateVirtualMachineQuietly(JavaDebugger javaDebugger) thr * @see ThreadReference#uniqueID() */ public static long findMainThreadId(JavaDebugger javaDebugger) throws DebuggerException { - Optional main = - javaDebugger.getThreadDumps().stream().filter(t -> t.getName().equals("main")).findAny(); + Optional main = + javaDebugger.getThreadDump().stream().filter(t -> t.getName().equals("main")).findAny(); main.orElseThrow(() -> new DebuggerException("Main thread not found")); return main.get().getId(); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadStateDto.java similarity index 72% rename from wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java rename to wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadStateDto.java index 3370c8d0c27..9d18036adcd 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadDumpDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/ThreadStateDto.java @@ -11,53 +11,53 @@ package org.eclipse.che.api.debug.shared.dto; import java.util.List; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.ThreadStatus; import org.eclipse.che.dto.shared.DTO; /** @author Anatolii Bazko */ @DTO -public interface ThreadDumpDto extends ThreadDump { +public interface ThreadStateDto extends ThreadState { @Override long getId(); void setId(long id); - ThreadDumpDto withId(long id); + ThreadStateDto withId(long id); @Override String getName(); void setName(String name); - ThreadDumpDto withName(String name); + ThreadStateDto withName(String name); @Override String getGroupName(); void setGroupName(String groupName); - ThreadDumpDto withGroupName(String groupName); + ThreadStateDto withGroupName(String groupName); @Override List getFrames(); void setFrames(List frames); - ThreadDumpDto withFrames(List frames); + ThreadStateDto withFrames(List frames); @Override ThreadStatus getStatus(); void setStatus(ThreadStatus status); - ThreadDumpDto withStatus(ThreadStatus status); + ThreadStateDto withStatus(ThreadStatus status); @Override boolean isSuspended(); void setSuspended(boolean suspended); - ThreadDumpDto withSuspended(boolean suspended); + ThreadStateDto withSuspended(boolean suspended); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadState.java similarity index 93% rename from wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java rename to wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadState.java index 7125e92a922..5415a5b925b 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadDump.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/ThreadState.java @@ -14,7 +14,7 @@ import org.eclipse.che.commons.annotation.Nullable; /** @author Anatoliy Bazko */ -public interface ThreadDump { +public interface ThreadState { /** Returns thread name. */ String getName(); @@ -29,7 +29,7 @@ public interface ThreadDump { /** Returns list of frames of the thread. */ List getFrames(); - /** Returns thread state. */ + /** Returns thread status. */ ThreadStatus getStatus(); /** Indicates if thread is suspended. */ diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadStateImpl.java similarity index 90% rename from wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java rename to wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadStateImpl.java index fcbd3890846..868e867c16d 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadDumpImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/ThreadStateImpl.java @@ -13,11 +13,11 @@ import com.google.common.base.Objects; import java.util.List; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.ThreadStatus; /** @author Anatolii Bazko */ -public class ThreadDumpImpl implements ThreadDump { +public class ThreadStateImpl implements ThreadState { private final String name; private final String groupName; private final ThreadStatus status; @@ -25,7 +25,7 @@ public class ThreadDumpImpl implements ThreadDump { private final List frames; private final long id; - public ThreadDumpImpl( + public ThreadStateImpl( long id, String name, String groupName, @@ -73,8 +73,8 @@ public List getFrames() { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof ThreadDumpImpl)) return false; - ThreadDumpImpl that = (ThreadDumpImpl) o; + if (!(o instanceof ThreadStateImpl)) return false; + ThreadStateImpl that = (ThreadStateImpl) o; return isSuspended == that.isSuspended && id == that.id && Objects.equal(name, that.name) diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index ba8ac5cd2f1..1fadbb2cfb7 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -17,7 +17,7 @@ import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.action.ResumeAction; @@ -235,12 +235,12 @@ default StackFrameDump getStackFrameDump(long threadId, int frameIndex) throws D } /** - * Gets thread dumps. + * Gets a thread dump. * - * @return {@link ThreadDump} + * @return snapshot of the state of all threads * @throws DebuggerException if any error occur */ - default List getThreadDumps() throws DebuggerException { + default List getThreadDump() throws DebuggerException { return Collections.emptyList(); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index e2e35d11cf0..53cffb77277 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -36,11 +36,11 @@ import org.eclipse.che.api.debug.shared.dto.DebugSessionDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.action.ActionDto; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.action.ResumeAction; import org.eclipse.che.api.debug.shared.model.action.StartAction; @@ -190,10 +190,10 @@ public StackFrameDumpDto getStackFrameDump( @GET @Path("{id}/threaddump") @Produces(MediaType.APPLICATION_JSON) - public List getThreadDumps(@PathParam("id") String sessionId) + public List getThreadDump(@PathParam("id") String sessionId) throws DebuggerException { - List threadDumps = debuggerManager.getDebugger(sessionId).getThreadDumps(); - return threadDumps.stream().map(DtoConverter::asDto).collect(Collectors.toList()); + List threadStates = debuggerManager.getDebugger(sessionId).getThreadDump(); + return threadStates.stream().map(DtoConverter::asDto).collect(Collectors.toList()); } @GET diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 3e407d8320b..3c8e270530f 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -23,7 +23,7 @@ import org.eclipse.che.api.debug.shared.dto.MethodDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.dto.StackFrameDumpDto; -import org.eclipse.che.api.debug.shared.dto.ThreadDumpDto; +import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; import org.eclipse.che.api.debug.shared.dto.VariableDto; import org.eclipse.che.api.debug.shared.dto.VariablePathDto; import org.eclipse.che.api.debug.shared.dto.event.BreakpointActivatedEventDto; @@ -38,7 +38,7 @@ import org.eclipse.che.api.debug.shared.model.Method; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; -import org.eclipse.che.api.debug.shared.model.ThreadDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; @@ -184,16 +184,16 @@ public static DebuggerEventDto asDto(DebuggerEvent debuggerEvent) { } } - public static ThreadDumpDto asDto(ThreadDump threadDump) { + public static ThreadStateDto asDto(ThreadState threadState) { List threads = - threadDump.getFrames().stream().map(DtoConverter::asDto).collect(toList()); - - return newDto(ThreadDumpDto.class) - .withId(threadDump.getId()) - .withName(threadDump.getName()) - .withGroupName(threadDump.getGroupName()) - .withSuspended(threadDump.isSuspended()) - .withStatus(threadDump.getStatus()) + threadState.getFrames().stream().map(DtoConverter::asDto).collect(toList()); + + return newDto(ThreadStateDto.class) + .withId(threadState.getId()) + .withName(threadState.getName()) + .withGroupName(threadState.getGroupName()) + .withSuspended(threadState.isSuspended()) + .withStatus(threadState.getStatus()) .withFrames(threads); } From 7bbc09cecc44d119d18b1f68bae3d7a59210cbdc Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 23 Aug 2017 17:15:50 +0300 Subject: [PATCH 31/38] Fix up --- .../ide/api/debug/DebuggerServiceClient.java | 1 + .../org/eclipse/che/ide/debug/Debugger.java | 1 + .../debugger/ide/debug/DebuggerViewImpl.java | 21 ++++++++++--------- .../ide/debug/VariableTreeNodeRenderer.java | 2 +- .../che/plugin/jdb/server/JavaDebugger.java | 2 +- .../che/api/debug/shared/model/Location.java | 1 - .../debug/shared/model/StackFrameDump.java | 1 - .../che/api/debugger/server/Debugger.java | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java index eccdbd9ffca..d48bb688616 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClient.java @@ -132,6 +132,7 @@ public interface DebuggerServiceClient { * Returns a value of the variable inside the specific frame. * * @param id debug session id + * @param variableDto the variable to get value from * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 8ee0a8f7fab..6264ababf1e 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -81,6 +81,7 @@ public interface Debugger extends DebuggerObservable { /** * Evaluates the given expression inside a specific frame. * + * @param expression the expression to evaluate * @param threadId the unique thread id {@link ThreadState#getId()} * @param frameIndex the frame index inside the thread */ diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index 7f32fdfca93..b61df1d1a69 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -229,17 +229,18 @@ public void setThreadDump(List threadDump, long threadIdT for (int i = 0; i < threadDump.size(); i++) { ThreadState ts = threadDump.get(i); - String item = - "\"" - + ts.getName() - + "\"@" - + ts.getId() - + " in group \"" - + ts.getGroupName() - + "\": " - + ts.getStatus(); - threads.addItem(item, String.valueOf(ts.getId())); + StringBuilder title = new StringBuilder(); + title.append("\""); + title.append(ts.getName()); + title.append("\"@"); + title.append(ts.getId()); + title.append(" in group \""); + title.append(ts.getGroupName()); + title.append("\": "); + title.append(ts.getStatus()); + + threads.addItem(title.toString(), String.valueOf(ts.getId())); if (ts.getId() == threadIdToSelect) { threads.setSelectedIndex(i); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java index aea30244044..2d785a434d7 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/VariableTreeNodeRenderer.java @@ -21,7 +21,7 @@ import org.eclipse.che.ide.util.dom.Elements; /** - * Renders variable item the panel. + * Renders variable item on the debugger panel. * * @see MutableVariable * @author Anatolii Bazko diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 34fbc50c69d..6dd1e4f83f0 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -419,7 +419,7 @@ public List getThreadDump() throws DebuggerException { *

    2. If need to get field of this object of current frame then first element in array always * should be 'this'. *
    3. If need to get static field in current frame then first element in array always should - * be* 'static'. + * be 'static'. *
    4. If need to get local variable in current frame then first element should be the name of * local variable. *
    diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java index 4afa5e61c1a..4c27421904a 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java @@ -33,7 +33,6 @@ public interface Location { String getResourceProjectPath(); /** Returns the method is being executed. */ - @Nullable Method getMethod(); /** Returns thread id. */ diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java index 96658f787a4..a0330396aee 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java @@ -22,6 +22,5 @@ public interface StackFrameDump { List getVariables(); /** Returns location of the frame. */ - @Nullable Location getLocation(); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java index 1fadbb2cfb7..c5476a229b1 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/Debugger.java @@ -131,7 +131,7 @@ default SimpleValue getValue(VariablePath variablePath, long threadId, int frame throw new DebuggerException("Unsupported operation for current debugger implementation."); } /** - * Sets the new value {@link Variable#getValue()} of the variable {@link* + * Sets the new value {@link Variable#getValue()} of the variable {@link * Variable#getVariablePath()}. * * @deprecated From 1c2d4abfb6215d0730af04e98f1fbe841462a6c1 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 6 Sep 2017 13:52:11 +0300 Subject: [PATCH 32/38] Refactoring --- .../eclipse/che/ide/api/debug/Breakpoint.java | 105 ----- .../che/ide/api/debug/BreakpointManager.java | 1 + .../api/debug/BreakpointManagerObserver.java | 2 + .../che/ide/api/debug/BreakpointStorage.java | 11 +- .../che/ide/debug/BreakpointManagerImpl.java | 441 +++++++----------- .../che/ide/debug/BreakpointStorageImpl.java | 217 +++------ .../org/eclipse/che/ide/debug/Debugger.java | 17 +- .../che/ide/debug/DebuggerObserver.java | 2 +- .../debugger/ide/debug/AbstractDebugger.java | 106 ++--- .../ide/debug/BreakpointItemRender.java | 6 +- .../debugger/ide/debug/DebuggerPresenter.java | 40 +- .../debugger/ide/debug/DebuggerView.java | 2 +- .../debugger/ide/debug/DebuggerViewImpl.java | 21 +- .../debug/DefaultDebuggerResourceHandler.java | 12 +- .../plugin/debugger/ide/fqn/FqnResolver.java | 20 - .../debugger/ide/fqn/FqnResolverFactory.java | 60 --- .../ide/fqn/FqnResolverObservable.java | 21 - .../debugger/ide/fqn/FqnResolverObserver.java | 18 - .../debugger/ide/ChangeVariableValueTest.java | 1 + .../debugger/ide/EvaluateExpressionTest.java | 1 - .../ide/debug/DebuggerPresenterTest.java | 256 ++++------ .../debugger/ide/debug/DebuggerTest.java | 77 +-- .../che/plugin/gdb/ide/GdbDebugger.java | 34 +- .../plugin/jdb/ide/JavaDebuggerExtension.java | 9 - .../plugin/jdb/ide/debug/JavaDebugger.java | 31 -- .../jdb/ide/fqn/JavaClassFqnResolver.java | 31 -- .../plugin/jdb/ide/fqn/JavaFqnResolver.java | 38 -- .../che-plugin-java-debugger-server/pom.xml | 1 + .../che/plugin/jdb/server/JavaDebugger.java | 23 +- .../plugin/jdb/server/model/JdbLocation.java | 17 +- .../jdb/server/utils/JavaDebuggerUtils.java | 49 +- .../plugin/jdb/server/BreakpointsTest.java | 228 +++++++++ .../jdb/server/EvaluateExpressionTest1.java | 6 +- .../che/plugin/jdb/server/GetValueTest1.java | 5 +- .../plugin/jdb/server/JavaDebuggerTest.java | 76 +-- .../jdb/server/StackFrameDumpTest1.java | 10 +- .../plugin/jdb/server/ThreadDumpTest1.java | 44 +- .../test/resources/JavaDebuggerTestsSuite.xml | 1 + .../src/test/resources/docker/assembly.xml | 4 + .../src/test/resources/docker/entrypoint.sh | 16 +- .../test/src/org/eclipse/BreakpointsTest.java | 43 ++ .../plugin/nodejsdbg/ide/NodeJsDebugger.java | 13 - .../che-plugin-zend-debugger-ide/pom.xml | 4 - .../che/plugin/zdb/ide/ZendDebugger.java | 14 - .../zdb/server/ZendDbgLocationHandler.java | 22 +- .../che/plugin/zdb/server/ZendDebugger.java | 6 +- .../server/AbstractZendDbgSessionTest.java | 2 +- .../che/api/debug/shared/dto/LocationDto.java | 4 - .../che/api/debug/shared/model/Location.java | 5 - .../debug/shared/model/StackFrameDump.java | 1 - .../debug/shared/model/impl/LocationImpl.java | 17 +- .../model/impl/MutableVariableImpl.java | 1 - .../che/api/debugger/server/DtoConverter.java | 1 - 53 files changed, 832 insertions(+), 1361 deletions(-) delete mode 100644 ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/Breakpoint.java delete mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolver.java delete mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverFactory.java delete mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObservable.java delete mode 100644 plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObserver.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaClassFqnResolver.java delete mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaFqnResolver.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java create mode 100644 plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/BreakpointsTest.java diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/Breakpoint.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/Breakpoint.java deleted file mode 100644 index 4dccf355be4..00000000000 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/Breakpoint.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.ide.api.debug; - -import java.util.Objects; -import org.eclipse.che.ide.api.resources.VirtualFile; - -/** - * Immutable object represents a breakpoint. - * - * @author Evgen Vidolob - * @author Anatoliy Bazko - */ -public class Breakpoint { - protected int lineNumber; - protected VirtualFile file; - private Type type; - private String path; - - /** Breakpoint becomes active if is added to a JVM, otherwise it is just a user mark. */ - private boolean active; - - public Breakpoint(Type type, int lineNumber, String path, VirtualFile file, boolean active) { - this.type = type; - this.lineNumber = lineNumber; - this.path = path; - this.file = file; - this.active = active; - } - - /** Getter for {@link #active} */ - public boolean isActive() { - return active; - } - - /** @return the type */ - public Type getType() { - return type; - } - - /** @return the lineNumber */ - public int getLineNumber() { - return lineNumber; - } - - /** @return file path */ - public String getPath() { - return path; - } - - /** - * Returns the file with which this breakpoint is associated. - * - * @return file with which this breakpoint is associated - */ - public VirtualFile getFile() { - return file; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder - .append("Breakpoint [lineNumber=") - .append(lineNumber) - .append(", type=") - .append(type) - .append(", active=") - .append(active) - .append(", path=") - .append(path) - .append("]"); - return builder.toString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Breakpoint)) return false; - - Breakpoint that = (Breakpoint) o; - - return lineNumber == that.lineNumber && Objects.equals(path, that.path); - } - - @Override - public int hashCode() { - int result = lineNumber; - result = 31 * result + (path != null ? path.hashCode() : 0); - return result; - } - - public enum Type { - BREAKPOINT, - CURRENT - } -} diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManager.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManager.java index 64fd92b7ad5..ba5d0b55cd1 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManager.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManager.java @@ -11,6 +11,7 @@ package org.eclipse.che.ide.api.debug; import java.util.List; +import org.eclipse.che.api.debug.shared.model.Breakpoint; /** * Breakpoint manager. diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManagerObserver.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManagerObserver.java index 33014a3f9c7..06418ed3dc6 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManagerObserver.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointManagerObserver.java @@ -10,6 +10,8 @@ */ package org.eclipse.che.ide.api.debug; +import org.eclipse.che.api.debug.shared.model.Breakpoint; + /** @author Anatoliy Bazko */ public interface BreakpointManagerObserver { diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointStorage.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointStorage.java index cfddc8c38ca..98129298d6c 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointStorage.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/BreakpointStorage.java @@ -11,7 +11,8 @@ package org.eclipse.che.ide.api.debug; import java.util.List; -import org.eclipse.che.api.promises.client.Promise; +import java.util.Optional; +import org.eclipse.che.api.debug.shared.model.Breakpoint; /** * Preserves and loads breakpoints for the active workspace. @@ -51,10 +52,16 @@ public interface BreakpointStorage { /** Clears storage. */ void clear(); + /** Gets all breakpoints that are set for given file. */ + List getByPath(String filePath); + + /** Returns breakpoints that is set for given file and at a given line number. */ + Optional get(String filePath, int lineNumber); + /** * Loads all breakpoints out of the storage. * * @return the list of the breakpoints */ - Promise> readAll(); + List getAll(); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java index 67b58110e8d..a5cfcf2f5b6 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java @@ -10,28 +10,22 @@ */ package org.eclipse.che.ide.debug; -import static org.eclipse.che.ide.api.debug.Breakpoint.Type.BREAKPOINT; - import com.google.gwt.user.client.Timer; import com.google.inject.Inject; import com.google.web.bindery.event.shared.EventBus; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; +import java.util.Optional; import java.util.logging.Logger; +import java.util.stream.Collectors; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; -import org.eclipse.che.api.debug.shared.model.VariablePath; +import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto; import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.BreakpointManagerObservable; import org.eclipse.che.ide.api.debug.BreakpointManagerObserver; @@ -52,7 +46,6 @@ import org.eclipse.che.ide.api.resources.ResourceChangedEvent; import org.eclipse.che.ide.api.resources.ResourceDelta; import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent; import org.eclipse.che.ide.resource.Path; /** @@ -70,13 +63,12 @@ public class BreakpointManagerImpl private static final Logger LOG = Logger.getLogger(BreakpointManagerImpl.class.getName()); - private final Map> breakpoints; private final EditorAgent editorAgent; private final DebuggerManager debuggerManager; private final BreakpointStorage breakpointStorage; private final List observers; - private Breakpoint currentBreakpoint; + private Location suspendedLocation; @Inject public BreakpointManagerImpl( @@ -86,11 +78,10 @@ public BreakpointManagerImpl( BreakpointStorage breakpointStorage) { this.editorAgent = editorAgent; this.breakpointStorage = breakpointStorage; - this.breakpoints = new HashMap<>(); this.debuggerManager = debuggerManager; this.observers = new ArrayList<>(); - this.debuggerManager.addObserver(this); + registerEventHandlers(eventBus); } @@ -102,31 +93,28 @@ public void changeBreakpointState(final int lineNumber) { } final VirtualFile activeFile = editor.getEditorInput().getFile(); + Optional existedBreakpoint = + breakpointStorage.get(activeFile.getLocation().toString(), lineNumber); - List pathBreakpoints = breakpoints.get(activeFile.getLocation().toString()); - if (pathBreakpoints != null) { - for (final Breakpoint breakpoint : pathBreakpoints) { - if (breakpoint.getLineNumber() == lineNumber) { - // breakpoint already exists at given line - breakpointStorage.delete(breakpoint); - deleteBreakpoint(activeFile, breakpoint); - return; - } + if (existedBreakpoint.isPresent()) { + deleteBreakpoint(activeFile, existedBreakpoint.get()); + } else { + if (isLineNotEmpty(activeFile, lineNumber)) { + addBreakpoint( + activeFile, + new BreakpointImpl(new LocationImpl(activeFile.getLocation().toString(), lineNumber))); } } - - if (isLineNotEmpty(activeFile, lineNumber)) { - Breakpoint breakpoint = - new Breakpoint( - BREAKPOINT, lineNumber, activeFile.getLocation().toString(), activeFile, false); - addBreakpoint(breakpoint); - breakpointStorage.add(breakpoint); - } } - /** Deletes breakpoint from the list and JVM. Removes breakpoint mark. */ + /** Deletes breakpoint. Removes breakpoint mark. */ private void deleteBreakpoint(final VirtualFile activeFile, final Breakpoint breakpoint) { - doDeleteBreakpoint(breakpoint); + breakpointStorage.delete(breakpoint); + + BreakpointRenderer renderer = getBreakpointRendererForFile(activeFile.getLocation().toString()); + if (renderer != null) { + renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber()); + } for (BreakpointManagerObserver observer : observers) { observer.onBreakpointDeleted(breakpoint); @@ -134,55 +122,18 @@ private void deleteBreakpoint(final VirtualFile activeFile, final Breakpoint bre Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { - debugger.deleteBreakpoint(activeFile, breakpoint.getLineNumber()); - } - } - - /** Deletes breakpoint from the list. */ - private void doDeleteBreakpoint(Breakpoint breakpoint) { - BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(breakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.removeBreakpointMark(breakpoint.getLineNumber()); - } - - String path = breakpoint.getPath(); - - List pathBreakpoints = breakpoints.get(path); - if (pathBreakpoints != null) { - pathBreakpoints.remove(breakpoint); - if (pathBreakpoints.isEmpty()) { - breakpoints.remove(breakpoint.getPath()); - } + debugger.deleteBreakpoint(activeFile, breakpoint); } } - /** Deletes breakpoints linked to paths from the list and JVM. Removes breakpoints' marks. */ - private void deleteBreakpoints(final Set paths) { - for (String path : paths) { - if (!breakpoints.containsKey(path)) { - continue; - } - - List breakpointsToDelete = new ArrayList<>(breakpoints.get(path)); - breakpointStorage.deleteAll(breakpointsToDelete); - breakpointsToDelete.forEach(breakpoint -> deleteBreakpoint(breakpoint.getFile(), breakpoint)); - } - } + private void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { + breakpointStorage.add(breakpoint); - /** Adds breakpoint to the list and JVM. */ - private void addBreakpoint(final Breakpoint breakpoint) { - List pathBreakpoints = - breakpoints.computeIfAbsent(breakpoint.getPath(), k -> new ArrayList<>()); - if (!pathBreakpoints.contains(breakpoint)) { - pathBreakpoints.add(breakpoint); - } + final BreakpointRenderer renderer = getBreakpointRendererForFile(file.getLocation().toString()); - final BreakpointRenderer breakpointRenderer = - getBreakpointRendererForFile(breakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.addBreakpointMark( - breakpoint.getLineNumber(), BreakpointManagerImpl.this::onLineChange); - breakpointRenderer.setBreakpointActive(breakpoint.getLineNumber(), breakpoint.isActive()); + if (renderer != null) { + renderer.addBreakpointMark( + breakpoint.getLocation().getLineNumber(), BreakpointManagerImpl.this::onLineChange); } for (BreakpointManagerObserver observer : observers) { @@ -191,7 +142,7 @@ private void addBreakpoint(final Breakpoint breakpoint) { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { - debugger.addBreakpoint(breakpoint.getFile(), breakpoint.getLineNumber()); + debugger.addBreakpoint(file, breakpoint); } } @@ -206,51 +157,41 @@ private boolean isLineNotEmpty(final VirtualFile activeFile, int lineNumber) { return false; } - private void removeBreakpointsForPath(final List pathBreakpoints) { - for (final Breakpoint breakpoint : pathBreakpoints) { - BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(breakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.removeBreakpointMark(breakpoint.getLineNumber()); - } - } - } - @Override public List getBreakpointList() { - final List result = new ArrayList<>(); - for (final List fileBreakpoints : breakpoints.values()) { - result.addAll(fileBreakpoints); - } - return result; + return breakpointStorage.getAll(); } - private void setCurrentBreakpoint(String filePath, int lineNumber) { - deleteCurrentBreakpoint(); - currentBreakpoint = new Breakpoint(Breakpoint.Type.CURRENT, lineNumber, filePath, null, true); + private void setSuspendedLocation(Location location) { + deleteSuspendedLocation(); + suspendedLocation = location; - EditorPartPresenter editor = getEditorForFile(filePath); + EditorPartPresenter editor = getEditorForFile(location.getTarget()); if (editor != null) { VirtualFile activeFile = editor.getEditorInput().getFile(); - doSetCurrentBreakpoint(activeFile, lineNumber); - } - } - private void doSetCurrentBreakpoint(VirtualFile activeFile, int lineNumber) { - BreakpointRenderer breakpointRenderer = - getBreakpointRendererForFile(activeFile.getLocation().toString()); - if (breakpointRenderer != null) { - breakpointRenderer.setLineActive(lineNumber, true); + BreakpointRenderer renderer = + getBreakpointRendererForFile(activeFile.getLocation().toString()); + if (renderer != null) { + renderer.setLineActive(location.getLineNumber(), true); + } } } @Override public void deleteAllBreakpoints() { - for (List pathBreakpoints : breakpoints.values()) { - removeBreakpointsForPath(pathBreakpoints); - } + breakpointStorage + .getAll() + .forEach( + breakpoint -> { + BreakpointRenderer renderer = + getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); + if (renderer != null) { + renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber()); + } + }); breakpointStorage.clear(); - breakpoints.clear(); for (BreakpointManagerObserver observer : observers) { observer.onAllBreakpointsDeleted(); @@ -262,16 +203,25 @@ public void deleteAllBreakpoints() { } } - private void deleteCurrentBreakpoint() { - if (currentBreakpoint != null) { - int oldLineNumber = currentBreakpoint.getLineNumber(); - BreakpointRenderer breakpointRenderer = - getBreakpointRendererForFile(currentBreakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.setLineActive(oldLineNumber, false); + private void deleteBreakpoints(String parentPath) { + List breakpoints2delete = + breakpointStorage + .getAll() + .stream() + .filter(breakpoint -> breakpoint.getLocation().getTarget().startsWith(parentPath)) + .collect(Collectors.toList()); + + breakpoints2delete.forEach(breakpointStorage::delete); + } + + private void deleteSuspendedLocation() { + if (suspendedLocation != null) { + BreakpointRenderer renderer = getBreakpointRendererForFile(suspendedLocation.getTarget()); + if (renderer != null) { + renderer.setLineActive(suspendedLocation.getLineNumber(), false); } - currentBreakpoint = null; + suspendedLocation = null; } } @@ -305,7 +255,9 @@ private BreakpointRenderer getBreakpointRendererForEditor(final EditorPartPresen @Override public void onLineChange( final VirtualFile file, final int firstLine, final int linesAdded, final int linesRemoved) { - final List fileBreakpoints = breakpoints.get(file.getLocation().toString()); + + final List fileBreakpoints = + breakpointStorage.getByPath(file.getLocation().toString()); final int delta = linesAdded - linesRemoved; if (fileBreakpoints != null) { @@ -315,39 +267,43 @@ public void onLineChange( final List toAdd = new ArrayList<>(); for (final Breakpoint breakpoint : fileBreakpoints) { - final int lineNumber = breakpoint.getLineNumber(); - if (lineNumber < firstLine) { - // we're before any change + final int lineNumber = breakpoint.getLocation().getLineNumber(); + + // before any change + if (firstLine > lineNumber) { continue; } - toRemove.add(breakpoint); - toAdd.add( - new Breakpoint( - breakpoint.getType(), - breakpoint.getLineNumber() + delta, - breakpoint.getPath(), - breakpoint.getFile(), - breakpoint.isActive())); + // in the middle + if (firstLine + Math.abs(delta) > lineNumber && lineNumber >= firstLine) { + toRemove.add(breakpoint); + toAdd.add(breakpoint); + + } else { + Location currentLocation = breakpoint.getLocation(); + Location newLocation = + new LocationImpl( + currentLocation.getTarget(), + currentLocation.getLineNumber() + delta, + currentLocation.isExternalResource(), + currentLocation.getExternalResourceId(), + currentLocation.getResourceProjectPath(), + currentLocation.getMethod(), + currentLocation.getThreadId()); + + toRemove.add(breakpoint); + toAdd.add( + new BreakpointImpl(newLocation, breakpoint.isEnabled(), breakpoint.getCondition())); + } } for (final Breakpoint breakpoint : toRemove) { - breakpointStorage.delete(breakpoint); deleteBreakpoint(file, breakpoint); } for (final Breakpoint breakpoint : toAdd) { - if (isLineNotEmpty(file, breakpoint.getLineNumber())) { - Breakpoint newBreakpoint = - new Breakpoint( - breakpoint.getType(), - breakpoint.getLineNumber(), - breakpoint.getPath(), - file, - false); - - addBreakpoint(newBreakpoint); - breakpointStorage.add(newBreakpoint); + if (isLineNotEmpty(file, breakpoint.getLocation().getLineNumber())) { + addBreakpoint(file, breakpoint); } } } @@ -355,44 +311,24 @@ public void onLineChange( /** Registers events handlers. */ private void registerEventHandlers(EventBus eventBus) { - eventBus.addHandler( - WorkspaceReadyEvent.getType(), - new WorkspaceReadyEvent.WorkspaceReadyHandler() { - @Override - public void onWorkspaceReady(WorkspaceReadyEvent event) { - breakpointStorage - .readAll() - .then( - breakpoints -> { - breakpoints.forEach(BreakpointManagerImpl.this::addBreakpoint); - }); - } - }); - eventBus.addHandler( EditorOpenedEvent.TYPE, event -> onOpenEditor(event.getFile().getLocation().toString(), event.getEditor())); + eventBus.addHandler(FileContentUpdateEvent.TYPE, this::onFileContentUpdate); + eventBus.addHandler( DeleteProjectEvent.TYPE, event -> { - if (breakpoints.isEmpty()) { - return; - } - ProjectConfigDto config = event.getProjectConfig(); String path = config.getPath() + "/"; - deleteBreakpoints(getBreakpointPaths(path)); + deleteBreakpoints(path); }); eventBus.addHandler( ResourceChangedEvent.getType(), event -> { if (event.getDelta().getKind() == ResourceDelta.REMOVED) { - if (breakpoints.isEmpty()) { - return; - } - final Resource resource = event.getDelta().getResource(); Path path = resource.getLocation(); @@ -400,9 +336,9 @@ public void onWorkspaceReady(WorkspaceReadyEvent event) { if (resource.isFolder()) { path.addTrailingSeparator(); - deleteBreakpoints(getBreakpointPaths(path.toString())); + deleteBreakpoints(path.toString()); } else if (resource.isFile()) { - deleteBreakpoints(Collections.singleton(path.toString())); + deleteBreakpoints(path.toString()); } } }); @@ -414,7 +350,7 @@ public void onWorkspaceReady(WorkspaceReadyEvent event) { */ private void onFileContentUpdate(FileContentUpdateEvent event) { String filePath = event.getFilePath(); - if (currentBreakpoint != null && currentBreakpoint.getPath().equals(filePath)) { + if (suspendedLocation != null && suspendedLocation.getTarget().equals(filePath)) { EditorPartPresenter editor = getEditorForFile(filePath); if (editor instanceof TextEditor) { @@ -434,21 +370,21 @@ private void onFileContentUpdate(FileContentUpdateEvent event) { .getFile() .getLocation() .toString(); - if (currentBreakpoint == null - || !currentBreakpoint.getPath().equals(changedFilePath)) { + if (suspendedLocation == null + || !suspendedLocation.getTarget().equals(changedFilePath)) { return; } BreakpointRenderer breakpointRenderer = getBreakpointRendererForEditor(editor); if (breakpointRenderer != null) { - breakpointRenderer.setLineActive(currentBreakpoint.getLineNumber(), false); - breakpointRenderer.setLineActive(currentBreakpoint.getLineNumber(), true); + breakpointRenderer.setLineActive(suspendedLocation.getLineNumber(), false); + breakpointRenderer.setLineActive(suspendedLocation.getLineNumber(), true); new Timer() { @Override public void run() { textEditor.setCursorPosition( - new TextPosition(currentBreakpoint.getLineNumber() + 1, 0)); + new TextPosition(suspendedLocation.getLineNumber() + 1, 0)); } }.schedule(300); } @@ -457,52 +393,36 @@ public void run() { } } - /** - * @param pathToFind examples: "/test-spring/", "/test-spring/src/", - * "/test-spring/src/main/java/Test.java" - * @return set of breakpoint paths which related to pathToFind - */ - private Set getBreakpointPaths(String pathToFind) { - Set foundPaths = new HashSet<>(breakpoints.size()); - for (Entry> breakpointsForPath : breakpoints.entrySet()) { - String path = breakpointsForPath.getKey(); - if (path.startsWith(pathToFind)) { - foundPaths.add(path); - } - } - - return foundPaths; - } - /** The new file has been opened in the editor. Method reads breakpoints. */ - private void onOpenEditor(String path, EditorPartPresenter editor) { - final List fileBreakpoints = breakpoints.get(path); - - if (fileBreakpoints != null) { - final BreakpointRenderer breakpointRenderer = getBreakpointRendererForEditor(editor); - - if (breakpointRenderer != null) { - for (final Breakpoint breakpoint : fileBreakpoints) { - reAddBreakpointMark(breakpointRenderer, breakpoint); - } + private void onOpenEditor(String filePath, EditorPartPresenter editor) { + final BreakpointRenderer renderer = getBreakpointRendererForEditor(editor); + if (renderer != null) { + breakpointStorage + .getByPath(filePath) + .forEach( + breakpoint -> + renderer.addBreakpointMark( + breakpoint.getLocation().getLineNumber(), + BreakpointManagerImpl.this::onLineChange)); + + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null) { + debugger + .getAllBreakpoints() + .then( + breakpoints -> { + for (Breakpoint breakpoint : breakpoints) { + renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber(), true); + } + }); } - } - if (currentBreakpoint != null && path.equals(currentBreakpoint.getPath())) { - BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(path); - if (breakpointRenderer != null) { - breakpointRenderer.setLineActive(currentBreakpoint.getLineNumber(), true); + if (suspendedLocation != null && suspendedLocation.getTarget().equals(filePath)) { + renderer.setLineActive(suspendedLocation.getLineNumber(), true); } } } - private void reAddBreakpointMark(BreakpointRenderer breakpointRenderer, Breakpoint breakpoint) { - int lineNumber = breakpoint.getLineNumber(); - - breakpointRenderer.addBreakpointMark(lineNumber, this::onLineChange); - breakpointRenderer.setBreakpointActive(lineNumber, breakpoint.isActive()); - } - // Debugger events @Override @@ -513,78 +433,35 @@ public void onDebuggerAttached(DebuggerDescriptor debuggerDescriptor, Promise> entry : breakpoints.entrySet()) { - List breakpointsForPath = entry.getValue(); - - for (int i = 0; i < breakpointsForPath.size(); i++) { - Breakpoint breakpoint = breakpointsForPath.get(i); - - if (breakpoint.isActive()) { - Breakpoint newInactiveBreakpoint = - new Breakpoint( - breakpoint.getType(), - breakpoint.getLineNumber(), - breakpoint.getPath(), - breakpoint.getFile(), - false); - breakpointsForPath.set(i, newInactiveBreakpoint); - - BreakpointRenderer breakpointRenderer = - getBreakpointRendererForFile(breakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.setBreakpointActive(breakpoint.getLineNumber(), false); - } - } - } - } + breakpointStorage + .getAll() + .forEach( + breakpoint -> { + BreakpointRenderer renderer = + getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); + if (renderer != null) { + renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber(), false); + } + }); - deleteCurrentBreakpoint(); + deleteSuspendedLocation(); } @Override - public void onBreakpointAdded(Breakpoint breakpoint) { - String path = breakpoint.getPath(); - List breakpointsForPath = breakpoints.computeIfAbsent(path, k -> new ArrayList<>()); - - int i = breakpointsForPath.indexOf(breakpoint); - if (i == -1) { - breakpointsForPath.add(breakpoint); - } else { - breakpointsForPath.set(i, breakpoint); - } - - BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(breakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.setBreakpointActive(breakpoint.getLineNumber(), breakpoint.isActive()); - } - } + public void onBreakpointAdded(Breakpoint breakpoint) {} @Override public void onBreakpointActivated(String filePath, int lineNumber) { - List breakpointsForPath = breakpoints.get(filePath); - if (breakpointsForPath == null) { - return; - } - - for (int i = 0; i < breakpointsForPath.size(); i++) { - Breakpoint breakpoint = breakpointsForPath.get(i); - - if (breakpoint.getLineNumber() == lineNumber) { - Breakpoint newActiveBreakpoint = - new Breakpoint( - breakpoint.getType(), - breakpoint.getLineNumber(), - breakpoint.getPath(), - breakpoint.getFile(), - true); - breakpointsForPath.set(i, newActiveBreakpoint); - - BreakpointRenderer breakpointRenderer = getBreakpointRendererForFile(breakpoint.getPath()); - if (breakpointRenderer != null) { - breakpointRenderer.setBreakpointActive(breakpoint.getLineNumber(), true); - } - } - } + breakpointStorage + .get(filePath, lineNumber) + .ifPresent( + breakpoint -> { + BreakpointRenderer renderer = + getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); + if (renderer != null) { + renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber(), true); + } + }); } @Override @@ -595,27 +472,27 @@ public void onAllBreakpointsDeleted() {} @Override public void onPreStepInto() { - deleteCurrentBreakpoint(); + deleteSuspendedLocation(); } @Override public void onPreStepOut() { - deleteCurrentBreakpoint(); + deleteSuspendedLocation(); } @Override public void onPreStepOver() { - deleteCurrentBreakpoint(); + deleteSuspendedLocation(); } @Override public void onPreResume() { - deleteCurrentBreakpoint(); + deleteSuspendedLocation(); } @Override public void onBreakpointStopped(String filePath, Location location) { - setCurrentBreakpoint(filePath, location.getLineNumber() - 1); + setSuspendedLocation(location); } @Override diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointStorageImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointStorageImpl.java index f837cf30ff7..540b151c470 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointStorageImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointStorageImpl.java @@ -10,32 +10,24 @@ */ package org.eclipse.che.ide.debug; -import static org.eclipse.che.ide.api.debug.Breakpoint.Type.BREAKPOINT; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; -import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.web.bindery.event.shared.EventBus; -import elemental.js.util.JsArrayOf; -import elemental.util.ArrayOf; -import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Optional; import java.util.logging.Logger; +import java.util.stream.Collectors; import org.eclipse.che.api.debug.shared.dto.BreakpointDto; import org.eclipse.che.api.debug.shared.dto.LocationDto; -import org.eclipse.che.api.promises.client.Function; +import org.eclipse.che.api.debug.shared.model.Breakpoint; +import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.promises.client.Promise; -import org.eclipse.che.api.promises.client.js.Executor; -import org.eclipse.che.api.promises.client.js.JsPromiseProvider; -import org.eclipse.che.api.promises.client.js.ResolveFunction; import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto; -import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.api.app.AppContext; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointStorage; -import org.eclipse.che.ide.api.resources.File; -import org.eclipse.che.ide.api.workspace.WorkspaceReadyEvent; import org.eclipse.che.ide.api.workspace.WorkspaceServiceClient; import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.util.storage.LocalStorage; @@ -52,108 +44,93 @@ public class BreakpointStorageImpl implements BreakpointStorage { private static final Logger LOG = Logger.getLogger(BreakpointStorageImpl.class.getName()); private static final String LOCAL_STORAGE_BREAKPOINTS_KEY_PREFIX = "che-breakpoints-"; - private final AppContext appContext; private final DtoFactory dtoFactory; private final LocalStorage storage; private final WorkspaceServiceClient workspaceServiceClient; - private final JsPromiseProvider promiseProvider; - private final Promise readAllBreakpointMarker; private final List breakpoints; - private final EventBus eventBus; private final String storageKey; @Inject public BreakpointStorageImpl( AppContext appContext, DtoFactory dtoFactory, - WorkspaceServiceClient workspaceServiceClient, - JsPromiseProvider promiseProvider, LocalStorageProvider localStorageProvider, - EventBus eventBus) { - this.appContext = appContext; + WorkspaceServiceClient workspaceServiceClient) { + + this.storageKey = LOCAL_STORAGE_BREAKPOINTS_KEY_PREFIX + appContext.getWorkspaceId(); this.dtoFactory = dtoFactory; - this.workspaceServiceClient = workspaceServiceClient; - this.promiseProvider = promiseProvider; - this.eventBus = eventBus; this.storage = localStorageProvider.get(); - this.breakpoints = new LinkedList<>(); - this.storageKey = LOCAL_STORAGE_BREAKPOINTS_KEY_PREFIX + appContext.getWorkspaceId(); + this.workspaceServiceClient = workspaceServiceClient; + this.breakpoints = new LinkedList<>(readAll()); if (storage == null) { LOG.warning("Local storage is not supported. Breakpoints won't be preserved."); - this.readAllBreakpointMarker = promiseProvider.resolve(null); } else { - this.readAllBreakpointMarker = getReadAllBreakpointsMarker(); - this.readAllBreakpointMarker.then( - onFulfilled -> { - preserve(); - }); - clearOutdatedRecords(); } } @Override public void addAll(final List breakpoints) { - readAllBreakpointMarker.then( - onFulfilled -> { - BreakpointStorageImpl.this.breakpoints.addAll(breakpoints); - - preserve(); - }); + this.breakpoints.addAll(breakpoints); + preserve(); } @Override public void add(final Breakpoint breakpoint) { - readAllBreakpointMarker.then( - onFulfilled -> { - BreakpointStorageImpl.this.breakpoints.add(breakpoint); - - preserve(); - }); + breakpoints.add(breakpoint); + preserve(); } @Override public void delete(final Breakpoint breakpoint) { - readAllBreakpointMarker.then( - onFulfilled -> { - BreakpointStorageImpl.this.breakpoints.removeIf( - b -> - b.getLineNumber() == breakpoint.getLineNumber() - && b.getPath().equals(breakpoint.getPath())); - - preserve(); - }); + breakpoints.removeIf( + b -> + b.getLocation().getLineNumber() == breakpoint.getLocation().getLineNumber() + && b.getLocation().getTarget().equals(breakpoint.getLocation().getTarget())); + preserve(); } @Override public void deleteAll(final List breakpoints) { - readAllBreakpointMarker.then( - onFulfilled -> { - for (Breakpoint breakpoint : breakpoints) { - BreakpointStorageImpl.this.breakpoints.removeIf( - b -> - b.getLineNumber() == breakpoint.getLineNumber() - && b.getPath().equals(breakpoint.getPath())); - } + for (Breakpoint breakpoint : breakpoints) { + breakpoints.removeIf( + b -> + b.getLocation().getLineNumber() == breakpoint.getLocation().getLineNumber() + && b.getLocation().getTarget().equals(breakpoint.getLocation().getTarget())); + } - preserve(); - }); + preserve(); } @Override public void clear() { - readAllBreakpointMarker.then( - onFulfilled -> { - BreakpointStorageImpl.this.breakpoints.clear(); - preserve(); - }); + breakpoints.clear(); + preserve(); } @Override - public Promise> readAll() { - return readAllBreakpointMarker.then( - onFulfilled -> breakpoints, onRejected -> Collections.emptyList()); + public List getAll() { + return unmodifiableList(breakpoints); + } + + @Override + public List getByPath(String filePath) { + return breakpoints + .stream() + .filter(b -> b.getLocation().getTarget().equals(filePath)) + .collect(Collectors.toList()); + } + + @Override + public Optional get(String filePath, int lineNumber) { + return breakpoints + .stream() + .filter( + b -> + b.getLocation().getLineNumber() == lineNumber + && b.getLocation().getTarget().equals(filePath)) + .findAny(); } private void preserve() { @@ -162,87 +139,24 @@ private void preserve() { } List breakpoints2save = new LinkedList<>(); - for (Breakpoint breakpoint : breakpoints) { - breakpoints2save.add( - dtoFactory - .createDto(BreakpointDto.class) - .withLocation( - dtoFactory - .createDto(LocationDto.class) - .withTarget(breakpoint.getPath()) - .withLineNumber(breakpoint.getLineNumber()))); + breakpoints2save.add(toDto(breakpoint)); } storage.setItem(storageKey, dtoFactory.toJson(breakpoints2save)); } - private Promise getReadAllBreakpointsMarker() { - return promiseProvider.create( - Executor.create((resolve, reject) -> addWorkspaceHandler(resolve))); - } - - private void addWorkspaceHandler(final ResolveFunction readAllMarkerResolveFunc) { - eventBus.addHandler( - WorkspaceReadyEvent.getType(), - event -> BreakpointStorageImpl.this.onWorkspaceReady(readAllMarkerResolveFunc)); - } - - private void onWorkspaceReady(ResolveFunction readAllMarkerResolveFunc) { - ArrayOf> breakpointPromises = prepareBreakpointPromises(); - - promiseProvider - .all2(breakpointPromises) - .then( - breakpoints -> { - for (int i = 0; i < breakpoints.length(); i++) { - Breakpoint breakpoint = (Breakpoint) breakpoints.get(i); - if (breakpoint != null) { - BreakpointStorageImpl.this.breakpoints.add(breakpoint); - } - } - readAllMarkerResolveFunc.apply(null); - }) - .catchError( - arg -> { - readAllMarkerResolveFunc.apply(null); - }); - } - - private ArrayOf> prepareBreakpointPromises() { - ArrayOf> breakpointPromises = JsArrayOf.create(); + private List readAll() { + if (storage == null) { + return emptyList(); + } String json = storage.getItem(storageKey); if (json == null) { - return breakpointPromises; - } - - for (BreakpointDto dto : dtoFactory.createListDtoFromJson(json, BreakpointDto.class)) { - Promise> filePromise = - appContext.getWorkspaceRoot().getFile(dto.getLocation().getTarget()); - breakpointPromises.push(toBreakpointPromise(filePromise, dto)); + return emptyList(); } - return breakpointPromises; - } - - private Promise toBreakpointPromise( - Promise> filePromise, BreakpointDto dto) { - return filePromise - .then((Function, Breakpoint>) file -> createBreakpoint(file.get(), dto)) - .catchError(error -> null); - } - - @Nullable - private Breakpoint createBreakpoint(@Nullable File file, BreakpointDto dto) { - return file == null - ? null - : new Breakpoint( - BREAKPOINT, - dto.getLocation().getLineNumber(), - dto.getLocation().getTarget(), - file, - false); + return dtoFactory.createListDtoFromJson(json, BreakpointDto.class); } /** @@ -265,4 +179,21 @@ private void clearOutdatedRecords() { } } } + + private BreakpointDto toDto(Breakpoint breakpoint) { + Location location = breakpoint.getLocation(); + + LocationDto locationDto = + dtoFactory + .createDto(LocationDto.class) + .withTarget(location.getTarget()) + .withLineNumber(location.getLineNumber()) + .withExternalResourceId(location.getExternalResourceId()) + .withExternalResource(location.isExternalResource()); + + return dtoFactory + .createDto(BreakpointDto.class) + .withLocation(locationDto) + .withCondition(breakpoint.getCondition()); + } } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 6264ababf1e..7763f78d358 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -12,7 +12,9 @@ import java.util.List; import java.util.Map; +import org.eclipse.che.api.debug.shared.dto.BreakpointDto; import org.eclipse.che.api.debug.shared.dto.ThreadStateDto; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadState; @@ -34,22 +36,25 @@ public interface Debugger extends DebuggerObservable { /** * Adds new breakpoint. * - * @param file the file - * @param lineNumber the line number + * @param file the file where breakpoint will be added + * @param breakpoint the breakpoint to add */ - void addBreakpoint(VirtualFile file, int lineNumber); + void addBreakpoint(VirtualFile file, Breakpoint breakpoint); /** * Deletes the given breakpoint on server. * - * @param file the file - * @param lineNumber the line number + * @param file the file where breakpoint will be removed from + * @param breakpoint the breakpoint to delete */ - void deleteBreakpoint(VirtualFile file, int lineNumber); + void deleteBreakpoint(VirtualFile file, Breakpoint breakpoint); /** Deletes all breakpoints. */ void deleteAllBreakpoints(); + /** Returns breakpoints. */ + Promise> getAllBreakpoints(); + /** * Connects to server. * diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java index 36c76fd839f..42ac9c1f608 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/DebuggerObserver.java @@ -10,10 +10,10 @@ */ package org.eclipse.che.ide.debug; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; -import org.eclipse.che.ide.api.debug.Breakpoint; /** @author Anatoliy Bazko */ public interface DebuggerObserver { diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 76bbfb0c961..c10581c37db 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -10,10 +10,16 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; -import com.google.common.base.Optional; +import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; +import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; + import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.web.bindery.event.shared.EventBus; - +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; @@ -34,6 +40,7 @@ import org.eclipse.che.api.debug.shared.dto.event.DebuggerEventDto; import org.eclipse.che.api.debug.shared.dto.event.DisconnectEventDto; import org.eclipse.che.api.debug.shared.dto.event.SuspendEventDto; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; @@ -49,7 +56,6 @@ import org.eclipse.che.api.promises.client.js.JsPromiseError; import org.eclipse.che.api.promises.client.js.Promises; import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent; @@ -68,15 +74,6 @@ import org.eclipse.che.ide.util.storage.LocalStorage; import org.eclipse.che.ide.util.storage.LocalStorageProvider; -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; - /** * The common debugger. * @@ -246,9 +243,8 @@ public void onSuccess(VirtualFile result) { *
  • etc */ private void onBreakpointActivated(LocationDto locationDto) { - String filePath = fqnToPath(locationDto); for (DebuggerObserver observer : observers) { - observer.onBreakpointActivated(filePath, locationDto.getLineNumber() - 1); + observer.onBreakpointActivated(locationDto.getTarget(), locationDto.getLineNumber() - 1); } } @@ -341,20 +337,13 @@ public Promise> getThreadDump() { } @Override - public void addBreakpoint(final VirtualFile file, final int lineNumber) { + public void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { if (isConnected()) { - String fqn = pathToFqn(file); - if (fqn == null) { - return; - } - - final String filePath = file.getLocation().toString(); LocationDto locationDto = dtoFactory .createDto(LocationDto.class) - .withLineNumber(lineNumber + 1) - .withTarget(fqn) - .withResourcePath(filePath) + .withLineNumber(breakpoint.getLocation().getLineNumber() + 1) + .withTarget(breakpoint.getLocation().getTarget()) .withResourceProjectPath(getProject(file).getPath()); BreakpointDto breakpointDto = @@ -364,8 +353,6 @@ public void addBreakpoint(final VirtualFile file, final int lineNumber) { promise .then( it -> { - Breakpoint breakpoint = - new Breakpoint(Breakpoint.Type.BREAKPOINT, lineNumber, filePath, file, true); for (DebuggerObserver observer : observers) { observer.onBreakpointAdded(breakpoint); } @@ -374,42 +361,23 @@ public void addBreakpoint(final VirtualFile file, final int lineNumber) { error -> { Log.error(AbstractDebugger.class, error.getMessage()); }); - } else { - Breakpoint breakpoint = - new Breakpoint( - Breakpoint.Type.BREAKPOINT, lineNumber, file.getLocation().toString(), file, false); - for (DebuggerObserver observer : observers) { - observer.onBreakpointAdded(breakpoint); - } } } @Override - public void deleteBreakpoint(final VirtualFile file, final int lineNumber) { + public void deleteBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { if (!isConnected()) { return; } LocationDto locationDto = dtoFactory.createDto(LocationDto.class); - locationDto.setLineNumber(lineNumber + 1); - - String fqn = pathToFqn(file); - if (fqn == null) { - return; - } - locationDto.setTarget(fqn); + locationDto.setLineNumber(breakpoint.getLocation().getLineNumber() + 1); + locationDto.setTarget(breakpoint.getLocation().getTarget()); Promise promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto); promise .then( it -> { for (DebuggerObserver observer : observers) { - Breakpoint breakpoint = - new Breakpoint( - Breakpoint.Type.BREAKPOINT, - lineNumber, - file.getLocation().toString(), - file, - false); observer.onBreakpointDeleted(breakpoint); } }) @@ -439,6 +407,15 @@ public void deleteAllBreakpoints() { }); } + @Override + public Promise> getAllBreakpoints() { + if (!isConnected()) { + return Promises.reject(JsPromiseError.create("Debugger is not connected")); + } + + return service.getAllBreakpoints(debugSessionDto.getId()); + } + @Override public Promise connect(Map connectionProperties) { if (isConnected()) { @@ -487,20 +464,13 @@ protected void startDebugger(final DebugSessionDto debugSessionDto) { LocationDto locationDto = dtoFactory .createDto(LocationDto.class) - .withLineNumber(breakpoint.getLineNumber() + 1) - .withResourcePath(breakpoint.getPath()) - .withResourceProjectPath(getProject(breakpoint.getFile()).getPath()); - - String target = pathToFqn(breakpoint.getFile()); - if (target != null) { - locationDto.setTarget(target); - - BreakpointDto breakpointDto = dtoFactory.createDto(BreakpointDto.class); - breakpointDto.setLocation(locationDto); - breakpointDto.setEnabled(true); + .withTarget(breakpoint.getLocation().getTarget()) + .withLineNumber(breakpoint.getLocation().getLineNumber() + 1); - breakpoints.add(breakpointDto); - } + BreakpointDto breakpointDto = dtoFactory.createDto(BreakpointDto.class); + breakpointDto.setLocation(locationDto); + breakpointDto.setEnabled(true); + breakpoints.add(breakpointDto); } StartActionDto action = dtoFactory.createDto(StartActionDto.class); @@ -782,22 +752,12 @@ private VariableDto toDto(Variable variable) { } @Nullable - private Project getProject(VirtualFile virtualFile) { + protected Project getProject(VirtualFile virtualFile) { if (virtualFile instanceof Resource) { - Optional projectOptional = ((Resource) virtualFile).getRelatedProject(); - if (projectOptional.isPresent()) { - return projectOptional.get(); - } + return ((Resource) virtualFile).getProject(); } return null; } - /** Transforms FQN to file path. */ - protected abstract String fqnToPath(@NotNull Location location); - - /** Transforms file path to FQN> */ - @Nullable - protected abstract String pathToFqn(VirtualFile file); - protected abstract DebuggerDescriptor toDescriptor(Map connectionProperties); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java index dadc8e22eac..3502fb13497 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java @@ -13,7 +13,7 @@ import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import elemental.dom.Element; import elemental.html.TableCellElement; -import org.eclipse.che.ide.api.debug.Breakpoint; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.ide.ui.list.SimpleList; import org.eclipse.che.ide.util.dom.Elements; import org.eclipse.che.plugin.debugger.ide.DebuggerResources; @@ -49,11 +49,11 @@ public void render(Element itemElement, Breakpoint itemData) { // Add title sb.appendHtmlConstant(""); - String path = itemData.getPath(); + String path = itemData.getLocation().getTarget(); sb.appendEscaped( path.substring(path.lastIndexOf("/") + 1) + ":" - + String.valueOf(itemData.getLineNumber() + 1)); + + String.valueOf(itemData.getLocation().getLineNumber() + 1)); sb.appendHtmlConstant(""); label.setInnerHTML(sb.toSafeHtml().asString()); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index e03e695635a..897321c437d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -25,7 +25,7 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; - +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; @@ -34,7 +34,6 @@ import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.BreakpointManagerObserver; import org.eclipse.che.ide.api.notification.NotificationManager; @@ -79,10 +78,10 @@ public class DebuggerPresenter extends BasePresenter private final WorkspaceAgent workspaceAgent; private final DebuggerResourceHandlerFactory resourceHandlerManager; - private List variables; + private List variables; private List threadDump; - private Location executionPoint; - private DebuggerDescriptor debuggerDescriptor; + private Location executionPoint; + private DebuggerDescriptor debuggerDescriptor; @Inject public DebuggerPresenter( @@ -144,23 +143,20 @@ public void go(AcceptsOneWidget container) { @Override public void onExpandVariablesTree(MutableVariable variable) { - List rootVariables = variable.getValue().getVariables(); - if (rootVariables.isEmpty()) { - Debugger debugger = debuggerManager.getActiveDebugger(); - if (debugger != null) { - Promise promise = - debugger.getValue(variable, view.getSelectedThreadId(), view.getSelectedFrameIndex()); + Debugger debugger = debuggerManager.getActiveDebugger(); + if (debugger != null && debugger.isSuspended()) { + Promise promise = + debugger.getValue(variable, view.getSelectedThreadId(), view.getSelectedFrameIndex()); - promise - .then( - value -> { - view.setVariableValue(variable, value); - }) - .catchError( - error -> { - Log.error(DebuggerPresenter.class, error.getCause()); - }); - } + promise + .then( + value -> { + view.setVariableValue(variable, value); + }) + .catchError( + error -> { + Log.error(DebuggerPresenter.class, error.getCause()); + }); } } @@ -183,7 +179,7 @@ public void onSelectedFrame(int frameIndex) { } } - private void open(Location location) { + protected void open(Location location) { Debugger debugger = debuggerManager.getActiveDebugger(); if (debugger != null) { DebuggerResourceHandler handler = diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java index 471abbebd35..953ef8053f9 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerView.java @@ -13,6 +13,7 @@ import com.google.gwt.user.client.ui.AcceptsOneWidget; import java.util.List; import javax.validation.constraints.NotNull; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; @@ -20,7 +21,6 @@ import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.mvp.View; import org.eclipse.che.ide.api.parts.base.BaseActionDelegate; diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index b61df1d1a69..c707e5ccd24 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -10,12 +10,6 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; -import elemental.dom.Element; -import elemental.events.KeyboardEvent; -import elemental.events.MouseEvent; -import elemental.html.SpanElement; -import elemental.html.TableElement; - import com.google.gwt.event.dom.client.ChangeEvent; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -29,7 +23,15 @@ import com.google.gwt.user.client.ui.Widget; import com.google.inject.Inject; import com.google.inject.Singleton; - +import elemental.dom.Element; +import elemental.events.KeyboardEvent; +import elemental.events.MouseEvent; +import elemental.html.SpanElement; +import elemental.html.TableElement; +import java.util.ArrayList; +import java.util.List; +import javax.validation.constraints.NotNull; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; @@ -40,7 +42,6 @@ import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.Resources; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.parts.PartStackUIResources; import org.eclipse.che.ide.api.parts.base.BaseView; import org.eclipse.che.ide.ui.list.SimpleList; @@ -51,10 +52,6 @@ import org.eclipse.che.plugin.debugger.ide.DebuggerLocalizationConstant; import org.eclipse.che.plugin.debugger.ide.DebuggerResources; -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; - /** * The class business logic which allow us to change visual representation of debugger panel. * diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java index 25e3f8a701f..64ca766c560 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java @@ -117,7 +117,7 @@ protected void findInOpenedEditors( VirtualFile file = editor.getEditorInput().getFile(); String filePath = file.getLocation().toString(); - if (filePath.equals(location.getResourcePath()) || filePath.equals(location.getTarget())) { + if (filePath.equals(location.getTarget())) { openFileAndScrollToLine(file, location.getLineNumber(), callback); return; } @@ -141,7 +141,7 @@ protected void findInProject(final Location location, final AsyncCallback { if (file.isPresent()) { @@ -161,7 +161,7 @@ protected void findInWorkspace( appContext .getWorkspaceRoot() - .getFile(getPath(location)) + .getFile(location.getTarget()) .then( file -> { if (file.isPresent()) { @@ -179,7 +179,7 @@ protected void findInWorkspace( protected void searchSource(final Location location, final AsyncCallback callback) { appContext .getWorkspaceRoot() - .search(getPath(location), "") + .search(location.getTarget(), "") .then( new Operation>() { @Override @@ -263,8 +263,4 @@ protected void scrollToLine(EditorPartPresenter editor, int lineNumber) { textEditor.setCursorPosition(new TextPosition(lineNumber - 1, 0)); } } - - protected String getPath(Location location) { - return location.getResourcePath() != null ? location.getResourcePath() : location.getTarget(); - } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolver.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolver.java deleted file mode 100644 index 0780a8dda72..00000000000 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolver.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.debugger.ide.fqn; - -import javax.validation.constraints.NotNull; -import org.eclipse.che.ide.api.resources.VirtualFile; - -/** @author Evgen Vidolob */ -public interface FqnResolver { - @NotNull - String resolveFqn(@NotNull VirtualFile file); -} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverFactory.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverFactory.java deleted file mode 100644 index 3b3ebd92d30..00000000000 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.debugger.ide.fqn; - -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import javax.validation.constraints.NotNull; -import org.eclipse.che.commons.annotation.Nullable; - -/** @author Evgen Vidolob */ -@Singleton -public class FqnResolverFactory implements FqnResolverObservable { - private final List listeners; - private final Map resolvers; - - /** Create factory. */ - @Inject - protected FqnResolverFactory() { - this.resolvers = new HashMap<>(); - this.listeners = new LinkedList<>(); - } - - public void addResolver(@NotNull String fileExtension, @NotNull FqnResolver resolver) { - resolvers.put(fileExtension, resolver); - onFqnResolverAdded(resolver); - } - - private void onFqnResolverAdded(@NotNull FqnResolver resolver) { - for (FqnResolverObserver fqnResolverObserver : listeners) { - fqnResolverObserver.onFqnResolverAdded(resolver); - } - } - - @Nullable - public FqnResolver getResolver(@NotNull String fileExtension) { - return resolvers.get(fileExtension); - } - - @Override - public void addFqnResolverObserver(FqnResolverObserver fqnResolverObserver) { - listeners.add(fqnResolverObserver); - } - - @Override - public void removeFqnResolverObserver(FqnResolverObserver fqnResolverObserver) { - listeners.remove(fqnResolverObserver); - } -} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObservable.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObservable.java deleted file mode 100644 index 78a2c1122cb..00000000000 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObservable.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.debugger.ide.fqn; - -/** @author Anatoliy Bazko */ -public interface FqnResolverObservable { - - /** Adds new listener. */ - void addFqnResolverObserver(FqnResolverObserver fqnResolverObserver); - - /** Removes listener. */ - void removeFqnResolverObserver(FqnResolverObserver fqnResolverObserver); -} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObserver.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObserver.java deleted file mode 100644 index 98ca113decb..00000000000 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/fqn/FqnResolverObserver.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.debugger.ide.fqn; - -/** @author Anatoliy Bazko */ -public interface FqnResolverObserver { - - /** Is invoked when a new resolver added to the factory. */ - void onFqnResolverAdded(FqnResolver fqnResolver); -} diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java index 493e6d89823..febf2f9119c 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/ChangeVariableValueTest.java @@ -61,6 +61,7 @@ public void setUp() { when(var.getVariablePath()).thenReturn(varPath); when(simpleValueDto.getString()).thenReturn(VAR_VALUE); when(dtoFactory.createDto(VariableDto.class)).thenReturn(mock(VariableDto.class)); + when(debugger.isSuspended()).thenReturn(true); } @Test diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java index 95b2fb0128a..261a4454a5d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/EvaluateExpressionTest.java @@ -42,7 +42,6 @@ public class EvaluateExpressionTest extends BaseTest { private static final String EXPRESSION = "expression"; private static final String EMPTY_EXPRESSION = ""; - private static final String EVALUATION_RESULT = "result"; private static final String FAIL_REASON = "reason"; private static final long THREAD_ID = 1; private static final int FRAME_INDEX = 0; diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java index 17bb34de771..5f1b7216130 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenterTest.java @@ -10,48 +10,35 @@ */ package org.eclipse.che.plugin.debugger.ide.debug; -import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE; import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL; -import static org.eclipse.che.ide.api.notification.StatusNotification.Status.PROGRESS; import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import com.google.gwt.user.client.ui.AcceptsOneWidget; -import java.util.ArrayList; import java.util.List; -import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.SimpleValueDto; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.MutableVariable; -import org.eclipse.che.api.debug.shared.model.SimpleValue; -import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl; -import org.eclipse.che.api.debug.shared.model.impl.VariableImpl; -import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl; +import org.eclipse.che.api.debug.shared.model.StackFrameDump; +import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.Promise; -import org.eclipse.che.api.promises.client.PromiseError; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointManager; -import org.eclipse.che.ide.api.filetypes.FileType; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; +import org.eclipse.che.ide.api.notification.StatusNotification; import org.eclipse.che.ide.api.parts.WorkspaceAgent; -import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.Debugger; import org.eclipse.che.ide.debug.DebuggerDescriptor; import org.eclipse.che.ide.debug.DebuggerManager; -import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.ui.toolbar.ToolbarPresenter; import org.eclipse.che.plugin.debugger.ide.BaseTest; import org.eclipse.che.plugin.debugger.ide.DebuggerLocalizationConstant; @@ -69,7 +56,6 @@ * @author Dmytro Nochevnov */ public class DebuggerPresenterTest extends BaseTest { - public static final String ERROR_MESSAGE = "error message"; private static final long THREAD_ID = 1; private static final int FRAME_INDEX = 0; @@ -79,32 +65,32 @@ public class DebuggerPresenterTest extends BaseTest { @Mock private NotificationManager notificationManager; @Mock private DebuggerResources debuggerResources; @Mock @DebuggerToolbar private ToolbarPresenter debuggerToolbar; - @Mock private DtoFactory dtoFactory; @Mock private DebuggerManager debuggerManager; @Mock private WorkspaceAgent workspaceAgent; - @Mock private FileTypeRegistry fileTypeRegistry; @Mock private DebuggerResourceHandlerFactory debuggerResourceHandlerFactory; @Mock private Debugger debugger; @Mock private MutableVariable selectedVariable; - @Mock private VirtualFile file; + @Mock private List threadDump; + @Mock private StackFrameDump stackFrame; - @Mock private Promise promiseString; @Mock private Promise promiseValue; + @Mock private Promise> promiseThreadDump; + @Mock private Promise promiseStackFrame; @Mock private Promise promiseVoid; - @Mock private PromiseError promiseError; - @Captor private ArgumentCaptor> operationPromiseErrorCaptor; @Captor private ArgumentCaptor> operationVoidCaptor; - @Captor private ArgumentCaptor> operationStringCaptor; + @Captor private ArgumentCaptor>> operationThreadDumpCaptor; + @Captor private ArgumentCaptor> operationStackFrameCaptor; @Captor private ArgumentCaptor> operationValueCaptor; private DebuggerPresenter presenter; @Before public void setup() { - doReturn(debugger).when(debuggerManager).getActiveDebugger(); - doReturn(ERROR_MESSAGE).when(promiseError).getMessage(); + when(debuggerManager.getActiveDebugger()).thenReturn(debugger); + when(debugger.isSuspended()).thenReturn(true); + doReturn(true).when(debugger).isSuspended(); presenter = spy( @@ -118,187 +104,127 @@ public void setup() { debuggerManager, workspaceAgent, debuggerResourceHandlerFactory)); - doNothing().when(presenter).showDebuggerPanel(); - - presenter.onSelectedVariableElement(selectedVariable); - - FileType fileType = mock(FileType.class); - doReturn("java").when(fileType).getExtension(); - doReturn(fileType).when(fileTypeRegistry).getFileTypeByFile(eq(file)); Mockito.reset(view); - Mockito.reset(breakpointManager); - } - - @Test - public void testGo() { - AcceptsOneWidget container = mock(AcceptsOneWidget.class); - List breakpoints = new ArrayList<>(); - - doReturn(breakpoints).when(breakpointManager).getBreakpointList(); - doReturn(container).when(view).getDebuggerToolbarPanel(); - - presenter.go(container); + when(view.getSelectedThreadId()).thenReturn(THREAD_ID); + when(view.getSelectedFrameIndex()).thenReturn(FRAME_INDEX); - verify(view).setBreakpoints(breakpoints); - verify(container).setWidget(view); - verify(debuggerToolbar).go(container); + doNothing().when(presenter).showDebuggerPanel(); } @Test - public void testOnExpandVariablesTree() throws OperationException { + public void shouldSetNestedVariablesWhenNodeIsExpended() throws OperationException { SimpleValueDto valueDto = mock(SimpleValueDto.class); - - List rootVariables = mock(List.class); - doReturn(true).when(rootVariables).isEmpty(); - doReturn(rootVariables).when(selectedVariable).getVariables(); - - doReturn(promiseValue).when(debugger).getValue(eq(selectedVariable), anyLong(), anyInt()); + doReturn(promiseValue) + .when(debugger) + .getValue(eq(selectedVariable), eq(THREAD_ID), eq(FRAME_INDEX)); doReturn(promiseValue).when(promiseValue).then((Operation) any()); - presenter.onExpandVariablesTree(); + presenter.onExpandVariablesTree(selectedVariable); verify(promiseValue).then(operationValueCaptor.capture()); operationValueCaptor.getValue().apply(valueDto); - verify(view).setVariablesIntoSelectedVariable(any()); - verify(view).updateSelectedVariable(); - - verify(promiseValue).catchError(operationPromiseErrorCaptor.capture()); - operationPromiseErrorCaptor.getValue().apply(promiseError); - notificationManager.notify(any(), eq(ERROR_MESSAGE), eq(FAIL), eq(FLOAT_MODE)); - verify(constant).failedToGetVariableValueTitle(); - } - - @Test - public void testShowAndUpdateView() { - presenter.refreshState(); - verify(view).setVMName(eq("")); - } - - @Test - public void testOnDebuggerAttached() { - DebuggerDescriptor debuggerDescriptor = mock(DebuggerDescriptor.class); - final String address = "address"; - doReturn(address).when(debuggerDescriptor).getAddress(); - - doReturn(promiseVoid).when(promiseVoid).then((Operation) any()); - - String title = "title"; - doReturn(title).when(this.constant).debuggerConnectingTitle(address); - presenter.onDebuggerAttached(debuggerDescriptor, promiseVoid); - notificationManager.notify(eq(address), eq(PROGRESS), eq(FLOAT_MODE)); + verify(debugger).getValue(eq(selectedVariable), eq(THREAD_ID), eq(FRAME_INDEX)); + verify(view).setVariableValue(selectedVariable, valueDto); } @Test - public void testOnDebuggerDisconnected() { - final String address = ""; - String title = "title"; - doReturn(title).when(this.constant).debuggerDisconnectedTitle(); - String description = "description"; - doReturn(description).when(this.constant).debuggerDisconnectedDescription(address); + public void shouldUpdateStackFrameDumpAndVariablesOnNewSelectedThread() throws Exception { + doNothing().when(presenter).updateStackFrameDump(THREAD_ID); + doNothing().when(presenter).updateVariables(THREAD_ID, 0); - presenter.onDebuggerDisconnected(); - notificationManager.notify(eq(title), eq(description), eq(SUCCESS), eq(NOT_EMERGE_MODE)); - } - - @Test - public void testOnPreIn() { - presenter.onPreStepInto(); + presenter.onSelectedThread(THREAD_ID); - verify(view).setVariables(any()); - verify(view).setVMName(eq("")); - verify(view).setExecutionPoint(eq(null)); + verify(presenter).updateStackFrameDump(THREAD_ID); + verify(presenter).updateVariables(THREAD_ID, 0); } @Test - public void testOnPreOut() { - presenter.onPreStepOut(); - - verify(view).setVariables(any()); - verify(view).setVMName(eq("")); - verify(view).setExecutionPoint(eq(null)); - } + public void shouldUpdateVariablesOnSelectedFrame() throws Exception { + doNothing().when(presenter).updateVariables(THREAD_ID, FRAME_INDEX); - @Test - public void testOnPreOver() { - presenter.onPreStepOver(); + presenter.onSelectedFrame(FRAME_INDEX); - verify(view).setVariables(any()); - verify(view).setVMName(eq("")); - verify(view).setExecutionPoint(eq(null)); + verify(presenter).updateVariables(THREAD_ID, FRAME_INDEX); } @Test - public void testOnPreResume() { - presenter.onPreResume(); - - verify(view).setVariables(any()); - verify(view).setVMName(eq("")); - verify(view).setExecutionPoint(eq(null)); + public void whenDebuggerStoppedThenPresenterShouldUpdateFramesAndVariables() throws Exception { + Location executionPoint = mock(Location.class); + doReturn(THREAD_ID).when(executionPoint).getThreadId(); + doReturn(promiseThreadDump).when(debugger).getThreadDump(); + doReturn(promiseThreadDump).when(promiseThreadDump).then((Operation>) any()); + doNothing().when(presenter).updateStackFrameDump(THREAD_ID); + doNothing().when(presenter).updateVariables(THREAD_ID, 0); + + presenter.onBreakpointStopped(null, executionPoint); + + verify(promiseThreadDump).then(operationThreadDumpCaptor.capture()); + operationThreadDumpCaptor.getValue().apply(threadDump); + verify(presenter).updateStackFrameDump(THREAD_ID); + verify(presenter).updateVariables(THREAD_ID, 0); + verify(view).setThreadDump(eq(threadDump), anyInt()); } @Test - public void testOnBreakpointAdded() { - Breakpoint breakpoint = mock(Breakpoint.class); + public void updateVariablesShouldUpdateView() throws Exception { + doReturn(promiseStackFrame).when(debugger).getStackFrameDump(THREAD_ID, FRAME_INDEX); + doReturn(promiseStackFrame).when(promiseStackFrame).then((Operation) any()); - List breakpoints = new ArrayList<>(); - doReturn(breakpoints).when(breakpointManager).getBreakpointList(); + presenter.updateVariables(THREAD_ID, FRAME_INDEX); - presenter.onBreakpointAdded(breakpoint); - verify(presenter).updateBreakpoints(); - verify(breakpointManager, times(2)).getBreakpointList(); - verify(view).setBreakpoints(any()); + verify(promiseStackFrame).then(operationStackFrameCaptor.capture()); + operationStackFrameCaptor.getValue().apply(stackFrame); + verify(view).setVariables(stackFrame.getVariables()); } @Test - public void testOnBreakpointDeleted() { - Breakpoint breakpoint = mock(Breakpoint.class); + public void showDebuggerPanelAndSetVMNameOnDebuggerAttached() throws Exception { + DebuggerDescriptor debuggerDescriptor = mock(DebuggerDescriptor.class); + when(debuggerDescriptor.getAddress()).thenReturn("address"); + when(debuggerDescriptor.getInfo()).thenReturn("info"); + doReturn(promiseVoid).when(promiseVoid).then((Operation) any()); + doNothing().when(presenter).showDebuggerPanel(); + when(notificationManager.notify( + anyString(), + any(StatusNotification.Status.class), + any(StatusNotification.DisplayMode.class))) + .thenReturn(mock(StatusNotification.class)); - List breakpoints = new ArrayList<>(); - doReturn(breakpoints).when(breakpointManager).getBreakpointList(); + presenter.onDebuggerAttached(debuggerDescriptor, promiseVoid); - presenter.onBreakpointDeleted(breakpoint); - verify(breakpointManager, times(2)).getBreakpointList(); - verify(view).setBreakpoints(any()); + verify(promiseVoid).then(operationVoidCaptor.capture()); + operationVoidCaptor.getValue().apply(null); + verify(presenter).showDebuggerPanel(); + verify(view).setVMName("info"); } @Test - public void testOnAllBreakpointsDeleted() { - List breakpoints = new ArrayList<>(); - doReturn(breakpoints).when(breakpointManager).getBreakpointList(); + public void testOnDebuggerDisconnected() { + final String address = ""; + String title = "title"; + doReturn(title).when(this.constant).debuggerDisconnectedTitle(); + String description = "description"; + doReturn(description).when(this.constant).debuggerDisconnectedDescription(address); - presenter.onAllBreakpointsDeleted(); - verify(breakpointManager, times(2)).getBreakpointList(); - verify(view).setBreakpoints(any()); + presenter.onDebuggerDisconnected(); + notificationManager.notify(eq(title), eq(description), eq(SUCCESS), eq(NOT_EMERGE_MODE)); } @Test - public void testOnBreakpointStopped() { - final String filePath = "filePath"; - - LocationDto executionPoint = mock(LocationDto.class); - doReturn(executionPoint).when(dtoFactory).createDto(LocationDto.class); - - doReturn(promiseString).when(debugger).getStackFrameDump(anyLong(), anyInt()); - doReturn(promiseString).when(promiseString).then((Operation) any()); - - presenter.onBreakpointStopped(filePath, executionPoint); + public void shouldSetNewValueOnValueChanged() throws Exception { + SimpleValueDto valueDto = mock(SimpleValueDto.class); + doReturn(promiseValue) + .when(debugger) + .getValue(eq(selectedVariable), eq(THREAD_ID), eq(FRAME_INDEX)); + doReturn(promiseValue).when(promiseValue).then((Operation) any()); - verify(presenter).refreshState(); - verify(view).setExecutionPoint(any(Location.class)); - } + presenter.onValueChanged(selectedVariable, THREAD_ID, FRAME_INDEX); - @Test - public void testOnValueChanged() { - doReturn(promiseString).when(debugger).getStackFrameDump(THREAD_ID, FRAME_INDEX); - doReturn(promiseString).when(promiseString).then((Operation) any()); - - ArrayList path = new ArrayList<>(); - String newValue = "newValue"; - presenter.onValueChanged( - new VariableImpl(new SimpleValueImpl(newValue), new VariablePathImpl(path)), - THREAD_ID, - FRAME_INDEX); + verify(promiseValue).then(operationValueCaptor.capture()); + operationValueCaptor.getValue().apply(valueDto); + verify(debugger).getValue(eq(selectedVariable), eq(THREAD_ID), eq(FRAME_INDEX)); + verify(view).setVariableValue(selectedVariable, valueDto); } } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index 2638fb74fd7..cd9a35286f9 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -49,8 +50,8 @@ import org.eclipse.che.api.debug.shared.dto.action.StepIntoActionDto; import org.eclipse.che.api.debug.shared.dto.action.StepOutActionDto; import org.eclipse.che.api.debug.shared.dto.action.StepOverActionDto; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; -import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; @@ -60,8 +61,6 @@ import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.api.promises.client.Promise; import org.eclipse.che.api.promises.client.PromiseError; -import org.eclipse.che.commons.annotation.Nullable; -import org.eclipse.che.ide.api.debug.Breakpoint; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; import org.eclipse.che.ide.api.filetypes.FileType; @@ -104,7 +103,6 @@ public class DebuggerTest extends BaseTest { private static final int FRAME_INDEX = 0; public static final int LINE_NUMBER = 20; - public static final String FQN = "org.test.Test"; public static final String PATH = "test/src/main/java/Test.java"; @Mock private DebuggerServiceClient service; @@ -144,8 +142,6 @@ public class DebuggerTest extends BaseTest { @Captor private ArgumentCaptor> argumentCaptorOperationJavaDebuggerInfo; - public final Breakpoint TEST_BREAKPOINT = - new Breakpoint(Breakpoint.Type.BREAKPOINT, LINE_NUMBER, PATH, file, true); public DebuggerDescriptor debuggerDescriptor; private AbstractDebugger debugger; @@ -173,17 +169,18 @@ public void setUp() { doReturn(Path.valueOf(PATH)).when(file).getLocation(); debugger = - new TestDebugger( - service, - transmitter, - configurator, - dtoFactory, - localStorageProvider, - eventBus, - debuggerManager, - notificationManager, - "id", - debuggerResourceHandlerFactory); + spy( + new TestDebugger( + service, + transmitter, + configurator, + dtoFactory, + localStorageProvider, + eventBus, + debuggerManager, + notificationManager, + "id", + debuggerResourceHandlerFactory)); doReturn(promiseInfo).when(service).getSessionInfo(SESSION_ID); doReturn(promiseInfo).when(promiseInfo).then(any(Operation.class)); @@ -392,6 +389,7 @@ public void testAddBreakpoint() throws Exception { MockSettings mockSettings = new MockSettingsImpl<>().defaultAnswer(RETURNS_SMART_NULLS).extraInterfaces(Resource.class); Project project = mock(Project.class); + doReturn(project).when(debugger).getProject(any()); when(optional.isPresent()).thenReturn(true); when(optional.get()).thenReturn(project); when(project.getPath()).thenReturn(PATH); @@ -407,56 +405,36 @@ public void testAddBreakpoint() throws Exception { doReturn(promiseVoid).when(service).addBreakpoint(SESSION_ID, breakpointDto); doReturn(promiseVoid).when(promiseVoid).then((Operation) any()); when(locationDto.withLineNumber(LINE_NUMBER + 1)).thenReturn(locationDto); - when(locationDto.withResourcePath(PATH)).thenReturn(locationDto); when(locationDto.withResourceProjectPath(PATH)).thenReturn(locationDto); when(locationDto.withTarget(anyString())).thenReturn(locationDto); + when(breakpointDto.getLocation().getLineNumber()).thenReturn(LINE_NUMBER); when(breakpointDto.withLocation(locationDto)).thenReturn(breakpointDto); when(breakpointDto.withEnabled(true)).thenReturn(breakpointDto); - debugger.addBreakpoint(virtualFile, LINE_NUMBER); - - verify(locationDto).withLineNumber(LINE_NUMBER + 1); - verify(locationDto).withTarget(FQN); - verify(locationDto).withResourcePath(PATH); - verify(locationDto).withResourceProjectPath(PATH); - - verify(breakpointDto).withLocation(locationDto); - verify(breakpointDto).withEnabled(true); + debugger.addBreakpoint(virtualFile, breakpointDto); + verify(service).addBreakpoint(SESSION_ID, breakpointDto); verify(promiseVoid).then(operationVoidCaptor.capture()); operationVoidCaptor.getValue().apply(null); verify(observer).onBreakpointAdded(breakpointCaptor.capture()); - assertEquals(breakpointCaptor.getValue(), TEST_BREAKPOINT); + assertEquals(breakpointCaptor.getValue(), breakpointDto); verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture()); operationPromiseErrorCaptor.getValue().apply(promiseError); verify(promiseError).getMessage(); } - @Test - public void testAddBreakpointWithoutConnection() throws Exception { - debugger.setDebugSession(null); - debugger.addBreakpoint(file, LINE_NUMBER); - - verify(service, never()).addBreakpoint(any(), any()); - verify(observer).onBreakpointAdded(breakpointCaptor.capture()); - assertEquals(breakpointCaptor.getValue(), TEST_BREAKPOINT); - } - @Test public void testDeleteBreakpoint() throws Exception { doReturn(promiseVoid).when(service).deleteBreakpoint(SESSION_ID, locationDto); doReturn(promiseVoid).when(promiseVoid).then((Operation) any()); - debugger.deleteBreakpoint(file, LINE_NUMBER); - - verify(locationDto).setLineNumber(LINE_NUMBER + 1); - verify(locationDto).setTarget(FQN); + debugger.deleteBreakpoint(file, breakpointDto); verify(promiseVoid).then(operationVoidCaptor.capture()); operationVoidCaptor.getValue().apply(null); verify(observer).onBreakpointDeleted(breakpointCaptor.capture()); - assertEquals(TEST_BREAKPOINT, breakpointCaptor.getValue()); + assertEquals(breakpointDto, breakpointCaptor.getValue()); verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture()); operationPromiseErrorCaptor.getValue().apply(promiseError); @@ -466,7 +444,7 @@ public void testDeleteBreakpoint() throws Exception { @Test public void testDeleteBreakpointWithoutConnection() throws Exception { debugger.setDebugSession(null); - debugger.deleteBreakpoint(file, LINE_NUMBER); + debugger.deleteBreakpoint(file, breakpointDto); verify(service, never()).deleteBreakpoint(any(), any()); } @@ -640,17 +618,6 @@ public TestDebugger( id); } - @Override - protected String fqnToPath(Location location) { - return PATH; - } - - @Nullable - @Override - protected String pathToFqn(VirtualFile file) { - return FQN; - } - @Override protected DebuggerDescriptor toDescriptor(Map connectionProperties) { return debuggerDescriptor; diff --git a/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java index 1fbb88a7735..717e70d0545 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-ide/src/main/java/org/eclipse/che/plugin/gdb/ide/GdbDebugger.java @@ -15,22 +15,17 @@ import static org.eclipse.che.plugin.gdb.ide.GdbDebugger.ConnectionProperties.HOST; import static org.eclipse.che.plugin.gdb.ide.GdbDebugger.ConnectionProperties.PORT; -import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.web.bindery.event.shared.EventBus; import java.util.Map; -import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; -import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.commons.annotation.Nullable; +import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.Project; -import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.DebuggerDescriptor; import org.eclipse.che.ide.debug.DebuggerManager; @@ -85,35 +80,12 @@ public GdbDebugger( } @Override - protected String fqnToPath(@NotNull Location location) { - final Resource resource = appContext.getResource(); - - if (resource == null) { - return location.getTarget(); - } - - final Optional project = resource.getRelatedProject(); - - if (project.isPresent()) { - return project.get().getLocation().append(location.getTarget()).toString(); - } - - return location.getTarget(); - } - - @Nullable - @Override - protected String pathToFqn(VirtualFile file) { - return file.getName(); - } - - @Override - public void addBreakpoint(final VirtualFile file, final int lineNumber) { + public void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { if (isConnected() && !isSuspended()) { notificationManager.notify(locale.messageSuspendToActivateBreakpoints(), FAIL, FLOAT_MODE); } - super.addBreakpoint(file, lineNumber); + super.addBreakpoint(file, breakpoint); } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java index 3624aaba14b..7fe7e7e102d 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/JavaDebuggerExtension.java @@ -15,11 +15,8 @@ import org.eclipse.che.ide.api.extension.Extension; import org.eclipse.che.ide.debug.DebuggerManager; import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerFactory; -import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolverFactory; import org.eclipse.che.plugin.jdb.ide.debug.JavaDebugger; import org.eclipse.che.plugin.jdb.ide.debug.JavaDebuggerResourceHandler; -import org.eclipse.che.plugin.jdb.ide.fqn.JavaClassFqnResolver; -import org.eclipse.che.plugin.jdb.ide.fqn.JavaFqnResolver; /** * Extension allows debug Java web applications. @@ -38,15 +35,9 @@ public class JavaDebuggerExtension { public JavaDebuggerExtension( DebuggerManager debuggerManager, JavaDebugger javaDebugger, - FqnResolverFactory resolverFactory, - JavaFqnResolver javaFqnResolver, - JavaClassFqnResolver javaClassFqnResolver, DebuggerResourceHandlerFactory debuggerResourceHandlerFactory, JavaDebuggerResourceHandler javaDebuggerResourceHandler) { debuggerManager.registeredDebugger(JavaDebugger.ID, javaDebugger); - resolverFactory.addResolver("java", javaFqnResolver); - resolverFactory.addResolver("class", javaClassFqnResolver); - debuggerResourceHandlerFactory.register(JavaDebugger.ID, javaDebuggerResourceHandler); } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java index befdb176176..28b51c35f34 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebugger.java @@ -16,24 +16,18 @@ import com.google.inject.Inject; import com.google.web.bindery.event.shared.EventBus; import java.util.Map; -import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; -import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; -import org.eclipse.che.ide.api.filetypes.FileTypeRegistry; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.DebuggerDescriptor; import org.eclipse.che.ide.debug.DebuggerManager; import org.eclipse.che.ide.dto.DtoFactory; import org.eclipse.che.ide.util.storage.LocalStorageProvider; import org.eclipse.che.plugin.debugger.ide.debug.AbstractDebugger; import org.eclipse.che.plugin.debugger.ide.debug.DebuggerResourceHandlerFactory; -import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolver; -import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolverFactory; /** * The java debugger. @@ -44,9 +38,6 @@ public class JavaDebugger extends AbstractDebugger { public static final String ID = "jdb"; - public final FqnResolverFactory fqnResolverFactory; - public final FileTypeRegistry fileTypeRegistry; - @Inject public JavaDebugger( DebuggerServiceClient service, @@ -55,11 +46,9 @@ public JavaDebugger( RequestHandlerConfigurator configurator, LocalStorageProvider localStorageProvider, EventBus eventBus, - FqnResolverFactory fqnResolverFactory, DebuggerResourceHandlerFactory debuggerResourceHandlerFactory, DebuggerManager debuggerManager, NotificationManager notificationManager, - FileTypeRegistry fileTypeRegistry, BreakpointManager breakpointManager, RequestHandlerManager requestHandlerManager) { super( @@ -75,26 +64,6 @@ public JavaDebugger( requestHandlerManager, debuggerResourceHandlerFactory, ID); - this.fqnResolverFactory = fqnResolverFactory; - this.fileTypeRegistry = fileTypeRegistry; - } - - @Override - protected String fqnToPath(@NotNull Location location) { - String resourcePath = location.getResourcePath(); - return resourcePath != null ? resourcePath : location.getTarget(); - } - - @Override - protected String pathToFqn(VirtualFile file) { - String fileExtension = fileTypeRegistry.getFileTypeByFile(file).getExtension(); - - FqnResolver resolver = fqnResolverFactory.getResolver(fileExtension); - if (resolver != null) { - return resolver.resolveFqn(file); - } - - return null; } @Override diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaClassFqnResolver.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaClassFqnResolver.java deleted file mode 100644 index 545b39a39c7..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaClassFqnResolver.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.jdb.ide.fqn; - -import com.google.inject.Singleton; -import javax.validation.constraints.NotNull; -import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolver; - -/** - * FQN resolver for {@link org.eclipse.che.ide.MimeType#APPLICATION_JAVA_CLASS} nodes. - * - * @author Anatoliy Bazko - */ -@Singleton -public class JavaClassFqnResolver implements FqnResolver { - - @NotNull - @Override - public String resolveFqn(@NotNull final VirtualFile file) { - return file.getLocation().toString(); - } -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaFqnResolver.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaFqnResolver.java deleted file mode 100644 index e81b54a97a9..00000000000 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/fqn/JavaFqnResolver.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * 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 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.jdb.ide.fqn; - -import com.google.inject.Singleton; -import javax.validation.constraints.NotNull; -import org.eclipse.che.ide.api.resources.Resource; -import org.eclipse.che.ide.api.resources.VirtualFile; -import org.eclipse.che.ide.ext.java.client.util.JavaUtil; -import org.eclipse.che.plugin.debugger.ide.fqn.FqnResolver; - -/** - * @author Evgen Vidolob - * @author Anatoliy Bazko - * @author Vlad Zhukovskyi - */ -@Singleton -public class JavaFqnResolver implements FqnResolver { - - /** {@inheritDoc} */ - @NotNull - @Override - public String resolveFqn(@NotNull final VirtualFile file) { - if (file instanceof Resource) { - return JavaUtil.resolveFQN(file); - } else { - return file.getName(); - } - } -} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml index bb576127611..31c082b53f6 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/pom.xml @@ -22,6 +22,7 @@ jar Che Plugin :: Java :: Java Debugger Server + true ${project.build.testOutputDirectory}/findbugs-exclude.xml diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 6dd1e4f83f0..e05b761fd24 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -12,6 +12,7 @@ import static java.lang.String.format; import static java.util.Collections.emptyList; +import static org.eclipse.che.api.debugger.server.DtoConverter.asDto; import static org.eclipse.che.dto.server.DtoFactory.newDto; import com.sun.jdi.AbsentInformationException; @@ -46,7 +47,6 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.eclipse.che.api.debug.shared.dto.BreakpointDto; -import org.eclipse.che.api.debug.shared.dto.LocationDto; import org.eclipse.che.api.debug.shared.dto.action.ResumeActionDto; import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; @@ -210,12 +210,12 @@ public void disconnect() throws DebuggerException { @Override public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { - final String className = findFQN(breakpoint); + final String className = findFQN(breakpoint.getLocation()); final int lineNumber = breakpoint.getLocation().getLineNumber(); List classes = vm.classesByName(className); // it may mean that class doesn't loaded by a target JVM yet if (classes.isEmpty()) { - deferBreakpoint(breakpoint); + deferBreakpoint(className, breakpoint); throw new DebuggerException("Class not loaded"); } @@ -267,8 +267,7 @@ public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { LOG.debug("Add breakpoint: {}", location); } - private String findFQN(Breakpoint breakpoint) throws DebuggerException { - Location location = breakpoint.getLocation(); + private String findFQN(Location location) throws DebuggerException { final String parentFqn = location.getTarget(); final String projectPath = location.getResourceProjectPath(); int lineNumber = location.getLineNumber(); @@ -276,8 +275,7 @@ private String findFQN(Breakpoint breakpoint) throws DebuggerException { return debuggerUtil.findFqnByPosition(projectPath, parentFqn, lineNumber); } - private void deferBreakpoint(Breakpoint breakpoint) throws DebuggerException { - final String className = breakpoint.getLocation().getTarget(); + private void deferBreakpoint(String className, Breakpoint breakpoint) throws DebuggerException { List newList = new ArrayList<>(); List list = deferredBreakpoints.putIfAbsent(className, newList); if (list == null) { @@ -317,10 +315,7 @@ public List getAllBreakpoints() throws DebuggerException { breakPoints.add( newDto(BreakpointDto.class) .withEnabled(true) - .withLocation( - newDto(LocationDto.class) - .withTarget(location.declaringType().name()) - .withLineNumber(location.lineNumber()))); + .withLocation(asDto(new JdbLocation(location)))); } breakPoints.sort(BREAKPOINT_COMPARATOR); return breakPoints; @@ -330,7 +325,7 @@ public List getAllBreakpoints() throws DebuggerException { @Override public void deleteBreakpoint(Location location) throws DebuggerException { - final String className = location.getTarget(); + final String className = findFQN(location); final int lineNumber = location.getLineNumber(); EventRequestManager requestManager = getEventManager(); List snapshot = new ArrayList<>(requestManager.breakpointRequests()); @@ -418,8 +413,8 @@ public List getThreadDump() throws DebuggerException { *
      *
    1. If need to get field of this object of current frame then first element in array always * should be 'this'. - *
    2. If need to get static field in current frame then first element in array always should - * be 'static'. + *
    3. If need to get static field in current frame then first element in array always should be + * 'static'. *
    4. If need to get local variable in current frame then first element should be the name of * local variable. *
    diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java index 199c9438515..2035ec3dd18 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/model/JdbLocation.java @@ -33,6 +33,16 @@ public JdbLocation(StackFrame stackFrame) { this(stackFrame, new JdbMethod(stackFrame)); } + /** + * Intends to create location when thread is not suspended. Information concerning thread and + * frame are not available. + */ + public JdbLocation(com.sun.jdi.Location jdiLocation) { + this.internal = getLocation(jdiLocation); + this.method = null; + this.jdiStackFrame = null; + } + public JdbLocation(StackFrame jdiStackFrame, Method method) { this.jdiStackFrame = jdiStackFrame; this.internal = getLocation(jdiStackFrame.location()); @@ -49,11 +59,6 @@ public int getLineNumber() { return internal.getLineNumber(); } - @Override - public String getResourcePath() { - return internal.getResourcePath(); - } - @Override public boolean isExternalResource() { return internal.isExternalResource(); @@ -76,7 +81,7 @@ public Method getMethod() { @Override public long getThreadId() { - return jdiStackFrame.thread().uniqueID(); + return jdiStackFrame == null ? -1 : jdiStackFrame.thread().uniqueID(); } private Location getLocation(com.sun.jdi.Location jdiLocation) { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java index 12c45d67f33..bc57a5a5cb6 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java @@ -21,8 +21,11 @@ import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.commons.lang.Pair; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IJavaProject; @@ -37,6 +40,7 @@ import org.eclipse.jdt.core.search.TypeNameMatchRequestor; import org.eclipse.jdt.internal.core.JavaModel; import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IRegion; @@ -78,14 +82,13 @@ public Location getLocation(com.sun.jdi.Location location) throws DebuggerExcept if (type.isBinary()) { IClassFile classFile = type.getClassFile(); int libId = classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode(); - return new LocationImpl( - fqn, location.lineNumber(), null, true, libId, typeProjectPath, null, -1); + return new LocationImpl(fqn, location.lineNumber(), true, libId, typeProjectPath, null, -1); } else { ICompilationUnit compilationUnit = type.getCompilationUnit(); typeProjectPath = type.getJavaProject().getPath().toOSString(); String resourcePath = compilationUnit.getPath().toOSString(); return new LocationImpl( - fqn, location.lineNumber(), resourcePath, false, -1, typeProjectPath, null, -1); + resourcePath, location.lineNumber(), false, -1, typeProjectPath, null, -1); } } @@ -145,25 +148,51 @@ public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { * return outer class fqn. * * @param projectPath project path which contains class with {@code outerClassFqn} - * @param outerClassFqn fqn outer class + * @param filePath path to the file * @param lineNumber line position to search * @throws DebuggerException */ - public String findFqnByPosition(String projectPath, String outerClassFqn, int lineNumber) + public String findFqnByPosition(String projectPath, String filePath, int lineNumber) throws DebuggerException { + if (projectPath == null) { - return outerClassFqn; + return filePath; } IJavaProject project = MODEL.getJavaProject(projectPath); + IPath path = Path.fromOSString(filePath); + + String fqn = null; + for (int i = path.segmentCount(); i > 0; i--) { + try { + IClasspathEntry classpathEntry = + ((JavaProject) project).getClasspathEntryFor(path.removeLastSegments(i)); + + if (classpathEntry != null) { + fqn = + path.removeFirstSegments(path.segmentCount() - i) + .removeFileExtension() + .toString() + .replace("/", "."); + break; + } + } catch (JavaModelException e) { + return filePath; + } + } + + if (fqn == null) { + return filePath; + } + IType outerClass; IMember iMember; try { - outerClass = project.findType(outerClassFqn); + outerClass = project.findType(fqn); if (outerClass == null) { - return outerClassFqn; + return filePath; } String source; @@ -185,7 +214,7 @@ public String findFqnByPosition(String projectPath, String outerClassFqn, int li throw new DebuggerException( format( "Unable to find source for class with fqn '%s' in the project '%s'", - outerClassFqn, project), + filePath, project), e); } catch (BadLocationException e) { throw new DebuggerException("Unable to calculate breakpoint location", e); @@ -198,7 +227,7 @@ public String findFqnByPosition(String projectPath, String outerClassFqn, int li return iMember.getDeclaringType().getFullyQualifiedName(); } - return outerClassFqn; + return filePath; } /** diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java new file mode 100644 index 00000000000..685101f0df0 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.plugin.jdb.server; + +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.ensureSuspendAtDesiredLocation; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.startJavaDebugger; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.util.List; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import org.eclipse.che.api.debug.shared.model.Breakpoint; +import org.eclipse.che.api.debug.shared.model.Location; +import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; +import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; +import org.eclipse.che.api.debug.shared.model.impl.action.ResumeActionImpl; +import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; +import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** @author Anatolii Bazko */ +public class BreakpointsTest { + + private JavaDebugger debugger; + private BlockingQueue events; + + @BeforeClass + public void setUp() throws Exception { + ProjectApiUtils.ensure(); + + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 19, false, -1, "/test", null, -1); + + events = new ArrayBlockingQueue<>(10); + debugger = startJavaDebugger(new BreakpointImpl(location), events); + + ensureSuspendAtDesiredLocation(location, events); + } + + @AfterClass + public void tearDown() throws Exception { + if (debugger != null) { + terminateVirtualMachineQuietly(debugger); + } + } + + @Test + public void shouldAddBreakpointInsideMethod() throws Exception { + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 35, false, -1, "/test", null, -1); + + try { + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + } catch (DebuggerException e) { + // class might not be loaded yet + } + + debugger.resume(new ResumeActionImpl()); + + DebuggerEvent debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); + + Breakpoint actualBreakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint(); + Location actualLocation = actualBreakpoint.getLocation(); + assertEquals(actualLocation.getLineNumber(), 35); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + assertTrue(actualBreakpoint.isEnabled()); + + debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof SuspendEvent); + + Location suspendLocation = ((SuspendEvent) debuggerEvent).getLocation(); + assertEquals(suspendLocation.getLineNumber(), 35); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + } + + @Test(priority = 1) + public void shouldAddBreakpointInsideInnerClass() throws Exception { + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 40, false, -1, "/test", null, -1); + + try { + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + } catch (DebuggerException e) { + // class might not be loaded yet + } + + debugger.resume(new ResumeActionImpl()); + + DebuggerEvent debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); + + Breakpoint actualBreakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint(); + Location actualLocation = actualBreakpoint.getLocation(); + assertEquals(actualLocation.getLineNumber(), 40); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + assertTrue(actualBreakpoint.isEnabled()); + + debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof SuspendEvent); + + Location suspendLocation = ((SuspendEvent) debuggerEvent).getLocation(); + assertEquals(suspendLocation.getLineNumber(), 40); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + } + + @Test(priority = 2) + public void shouldAddBreakpointInsideAnonymousClass() throws Exception { + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 24, false, -1, "/test", null, -1); + + try { + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + } catch (DebuggerException e) { + // class might not be loaded yet + } + + debugger.resume(new ResumeActionImpl()); + + DebuggerEvent debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); + + Breakpoint actualBreakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint(); + Location actualLocation = actualBreakpoint.getLocation(); + assertEquals(actualLocation.getLineNumber(), 24); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + assertTrue(actualBreakpoint.isEnabled()); + + debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof SuspendEvent); + + Location suspendLocation = ((SuspendEvent) debuggerEvent).getLocation(); + assertEquals(suspendLocation.getLineNumber(), 24); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + } + + @Test(priority = 2) + public void shouldAddBreakpointInsideLambdaFunction() throws Exception { + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 30, false, -1, "/test", null, -1); + + try { + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + } catch (DebuggerException e) { + // class might not be loaded yet + } + + debugger.resume(new ResumeActionImpl()); + + DebuggerEvent debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); + + Breakpoint actualBreakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint(); + Location actualLocation = actualBreakpoint.getLocation(); + assertEquals(actualLocation.getLineNumber(), 30); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + assertTrue(actualBreakpoint.isEnabled()); + + debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof SuspendEvent); + + Location suspendLocation = ((SuspendEvent) debuggerEvent).getLocation(); + assertEquals(suspendLocation.getLineNumber(), 30); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + } + + @Test(priority = 3) + public void shouldRemoveAllBreakpoints() throws Exception { + assertFalse(debugger.getAllBreakpoints().isEmpty()); + + debugger.deleteAllBreakpoints(); + + assertTrue(debugger.getAllBreakpoints().isEmpty()); + } + + @Test(priority = 5) + public void shouldRemoveBreakpoint() throws Exception { + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 35, false, -1, "/test", null, -1); + + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + assertEquals(debugger.getAllBreakpoints().size(), 1); + + debugger.deleteBreakpoint(location); + assertTrue(debugger.getAllBreakpoints().isEmpty()); + } + + @Test(priority = 6) + public void shouldReturnAllBreakpoints() throws Exception { + Location location = + new LocationImpl( + "/test/src/org/eclipse/BreakpointsTest.java", 35, false, -1, "/test", null, -1); + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + + List breakpoints = debugger.getAllBreakpoints(); + assertEquals(breakpoints.size(), 1); + + Breakpoint actualBreakpoint = breakpoints.get(0); + Location actualLocation = actualBreakpoint.getLocation(); + + assertEquals(actualLocation.getLineNumber(), 35); + assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); + assertEquals(actualLocation.getResourceProjectPath(), "/test"); + assertTrue(actualBreakpoint.isEnabled()); + } +} diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java index a6fb7847381..c2b48b07c71 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/EvaluateExpressionTest1.java @@ -44,11 +44,11 @@ public class EvaluateExpressionTest1 { public void setUp() throws Exception { ProjectApiUtils.ensure(); - Location location = new LocationImpl("org.eclipse.EvaluateExpressionTest1", 21); - + Location location = + new LocationImpl( + "/test/src/org/eclipse/EvaluateExpressionTest1.java", 21, false, -1, "/test", null, -1); debuggerEvents = new ArrayBlockingQueue<>(10); debugger = startJavaDebugger(new BreakpointImpl(location), debuggerEvents); - ensureSuspendAtDesiredLocation(location, debuggerEvents); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java index 37b1fc52d29..4bc03e3dd33 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/GetValueTest1.java @@ -53,8 +53,9 @@ public class GetValueTest1 { public void setUp() throws Exception { ProjectApiUtils.ensure(); - Location location = new LocationImpl("org.eclipse.GetValueTest1", 26); - + Location location = + new LocationImpl( + "/test/src/org/eclipse/GetValueTest1.java", 26, false, -1, "/test", null, -1); debuggerEvents = new ArrayBlockingQueue<>(10); debugger = startJavaDebugger(new BreakpointImpl(location), debuggerEvents); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java index ab09a9b935c..e4c886d7fe9 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/JavaDebuggerTest.java @@ -13,7 +13,6 @@ import static java.util.Collections.singletonList; import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; @@ -21,7 +20,6 @@ import java.util.Map; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; -import org.eclipse.che.api.debug.shared.model.Breakpoint; import org.eclipse.che.api.debug.shared.model.DebuggerInfo; import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; @@ -35,7 +33,6 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StepIntoActionImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StepOutActionImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -88,65 +85,7 @@ public void testStartDebugger() throws Exception { Location location = ((SuspendEvent) debuggerEvent).getLocation(); assertEquals(location.getLineNumber(), 17); - assertEquals(location.getTarget(), "com.HelloWorld"); - } - - @Test(priority = 30) - public void testAddBreakpoint() throws Exception { - int breakpointsCount = debugger.getAllBreakpoints().size(); - - debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null)); - - DebuggerEvent debuggerEvent = events.take(); - assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); - - Breakpoint breakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint(); - assertEquals(breakpoint.getLocation().getLineNumber(), 18); - assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld"); - assertTrue(breakpoint.isEnabled()); - - assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount + 1); - } - - @Test(priority = 50, expectedExceptions = DebuggerException.class) - public void testAddBreakpointToUnExistedLocation() throws Exception { - debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 1), false, null)); - } - - @Test(priority = 60) - public void testRemoveBreakpoint() throws Exception { - debugger.deleteBreakpoint(new LocationImpl("com.HelloWorld", 17)); - assertEquals(debugger.getAllBreakpoints().size(), 1); - } - - @Test(priority = 70) - public void testRemoveUnExistedBreakpoint() throws Exception { - int breakpointsCount = debugger.getAllBreakpoints().size(); - - debugger.deleteBreakpoint(new LocationImpl("com.HelloWorld", 2)); - - assertEquals(debugger.getAllBreakpoints().size(), breakpointsCount); - } - - @Test(priority = 80) - public void testGetAllBreakpoints() throws Exception { - assertFalse(debugger.getAllBreakpoints().isEmpty()); - - debugger.deleteAllBreakpoints(); - - assertTrue(debugger.getAllBreakpoints().isEmpty()); - - debugger.addBreakpoint(new BreakpointImpl(new LocationImpl("com.HelloWorld", 18), false, null)); - - DebuggerEvent debuggerEvent = events.take(); - assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); - - assertEquals(debugger.getAllBreakpoints().size(), 1); - - Breakpoint breakpoint = debugger.getAllBreakpoints().get(0); - assertEquals(breakpoint.getLocation().getLineNumber(), 18); - assertEquals(breakpoint.getLocation().getTarget(), "com.HelloWorld"); - assertTrue(breakpoint.isEnabled()); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); } @Test(priority = 90) @@ -162,18 +101,17 @@ public void testSteps() throws Exception { DebuggerEvent debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof SuspendEvent); Location location = ((SuspendEvent) debuggerEvent).getLocation(); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); assertEquals(location.getLineNumber(), 20); assertEquals(location.getExternalResourceId(), -1); assertEquals(location.getResourceProjectPath(), "/test"); - assertEquals(location.getResourcePath(), "/test/src/com/HelloWorld.java"); debugger.stepInto(new StepIntoActionImpl()); debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof SuspendEvent); location = ((SuspendEvent) debuggerEvent).getLocation(); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); assertEquals(location.getLineNumber(), 28); debugger.stepOut(new StepOutActionImpl()); @@ -181,7 +119,7 @@ public void testSteps() throws Exception { debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof SuspendEvent); location = ((SuspendEvent) debuggerEvent).getLocation(); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); assertEquals(location.getLineNumber(), 20); debugger.stepOver(new StepOverActionImpl()); @@ -189,7 +127,7 @@ public void testSteps() throws Exception { debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof SuspendEvent); location = ((SuspendEvent) debuggerEvent).getLocation(); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); assertEquals(location.getLineNumber(), 21); debugger.stepOver(new StepOverActionImpl()); @@ -197,7 +135,7 @@ public void testSteps() throws Exception { debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof SuspendEvent); location = ((SuspendEvent) debuggerEvent).getLocation(); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); assertEquals(location.getLineNumber(), 23); debugger.stepOver(new StepOverActionImpl()); @@ -205,7 +143,7 @@ public void testSteps() throws Exception { debuggerEvent = events.take(); assertTrue(debuggerEvent instanceof SuspendEvent); location = ((SuspendEvent) debuggerEvent).getLocation(); - assertEquals(location.getTarget(), "com.HelloWorld"); + assertEquals(location.getTarget(), "/test/src/com/HelloWorld.java"); assertEquals(location.getLineNumber(), 24); } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java index 5c55315b656..ce8a15ebf03 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/StackFrameDumpTest1.java @@ -54,7 +54,9 @@ public class StackFrameDumpTest1 { public void setUp() throws Exception { ProjectApiUtils.ensure(); - Location location = new LocationImpl("org.eclipse.StackFrameDumpTest1", 25); + Location location = + new LocationImpl( + "/test/src/org/eclipse/StackFrameDumpTest1.java", 25, false, -1, "/test", null, -1); debugger = startJavaDebugger(new BreakpointImpl(location), callback); ensureSuspendAtDesiredLocation(location, callback); @@ -86,7 +88,7 @@ private void validateFrame0(long threadId) throws DebuggerException { LocationDto location = stackFrame.getLocation(); assertEquals(location.getLineNumber(), 25); - assertEquals(location.getTarget(), "org.eclipse.StackFrameDumpTest1"); + assertEquals(location.getTarget(), "/test/src/org/eclipse/StackFrameDumpTest1.java"); MethodDto method = location.getMethod(); assertEquals(method.getName(), "do2"); @@ -132,7 +134,7 @@ private void validateFrame1(long threadId) throws DebuggerException { LocationDto location = stackFrame.getLocation(); assertEquals(location.getLineNumber(), 21); - assertEquals(location.getTarget(), "org.eclipse.StackFrameDumpTest1"); + assertEquals(location.getTarget(), "/test/src/org/eclipse/StackFrameDumpTest1.java"); MethodDto method = location.getMethod(); assertEquals(method.getName(), "do1"); @@ -186,7 +188,7 @@ private void validateFrame2(long threadId) throws DebuggerException { LocationDto location = stackFrame.getLocation(); assertEquals(location.getLineNumber(), 16); - assertEquals(location.getTarget(), "org.eclipse.StackFrameDumpTest1"); + assertEquals(location.getTarget(), "/test/src/org/eclipse/StackFrameDumpTest1.java"); MethodDto method = location.getMethod(); assertEquals(method.getName(), "main"); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index 192236ed70b..cd4b658d994 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -13,6 +13,7 @@ import static java.lang.Integer.parseInt; import static java.lang.System.getProperty; import static java.util.stream.Collectors.toList; +import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.ensureSuspendAtDesiredLocation; import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; @@ -29,14 +30,11 @@ import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.ThreadState; import org.eclipse.che.api.debug.shared.model.ThreadStatus; -import org.eclipse.che.api.debug.shared.model.event.BreakpointActivatedEvent; import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; -import org.eclipse.che.api.debug.shared.model.event.SuspendEvent; import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; import org.eclipse.che.api.debugger.server.DtoConverter; -import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; import org.eclipse.che.plugin.jdb.server.util.ProjectApiUtils; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -55,13 +53,21 @@ public class ThreadDumpTest1 { public void setUp() throws Exception { ProjectApiUtils.ensure(); - initJavaDebugger(); - ensureSuspendAtDesiredLocation(); + debugger = new JavaDebugger("localhost", parseInt(getProperty("debug.port")), events::add); + Location location = + new LocationImpl( + "/test/src/org/eclipse/ThreadDumpTest1.java", 26, false, -1, "/test", null, -1); + BreakpointImpl breakpoint = new BreakpointImpl(location); + + debugger.start(new StartActionImpl(Collections.singletonList(breakpoint))); + ensureSuspendAtDesiredLocation(location, events); } @AfterClass public void tearDown() throws Exception { - terminateVirtualMachineQuietly(debugger); + if (debugger != null) { + terminateVirtualMachineQuietly(debugger); + } } @Test @@ -94,10 +100,9 @@ private void validateMainThreadDump(List threads) { Location location = stackFrameDump.getLocation(); assertEquals(location.getLineNumber(), 26); - assertEquals(location.getTarget(), "org.eclipse.ThreadDumpTest1"); + assertEquals(location.getTarget(), "/test/src/org/eclipse/ThreadDumpTest1.java"); assertEquals(location.getExternalResourceId(), -1); assertEquals(location.getResourceProjectPath(), "/test"); - assertEquals(location.getResourcePath(), "/test/src/org/eclipse/ThreadDumpTest1.java"); Method method = location.getMethod(); assertEquals(method.getName(), "main"); @@ -125,7 +130,6 @@ private void validateFinalizerThreadDump(List threads) { assertEquals(location.getLineNumber(), -1); assertEquals(location.getTarget(), "java.lang.Object"); assertNull(location.getResourceProjectPath()); - assertNull(location.getResourcePath()); Method method = location.getMethod(); assertEquals(method.getName(), "wait"); @@ -152,32 +156,12 @@ private void validateSomeThreadDump(List threads) { Location location = stackFrameDump.getLocation(); assertEquals(location.getLineNumber(), 41); - assertEquals(location.getTarget(), "org.eclipse.ThreadDumpTest1$SomeThread"); + assertEquals(location.getTarget(), "/test/src/org/eclipse/ThreadDumpTest1.java"); assertEquals(location.getExternalResourceId(), -1); assertEquals(location.getResourceProjectPath(), "/test"); - assertEquals(location.getResourcePath(), "/test/src/org/eclipse/ThreadDumpTest1.java"); Method method = location.getMethod(); assertEquals(method.getName(), "run"); assertTrue(method.getArguments().isEmpty()); } - - private void initJavaDebugger() throws DebuggerException, InterruptedException { - debugger = new JavaDebugger("localhost", parseInt(getProperty("debug.port")), events::add); - - BreakpointImpl breakpoint = - new BreakpointImpl(new LocationImpl("org.eclipse.ThreadDumpTest1", 26)); - debugger.start(new StartActionImpl(Collections.singletonList(breakpoint))); - } - - private void ensureSuspendAtDesiredLocation() throws InterruptedException { - DebuggerEvent debuggerEvent = events.take(); - assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); - - debuggerEvent = events.take(); - assertTrue(debuggerEvent instanceof SuspendEvent); - - SuspendEvent suspendEvent = (SuspendEvent) debuggerEvent; - assertEquals(suspendEvent.getLocation().getLineNumber(), 26); - } } diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerTestsSuite.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerTestsSuite.xml index 557586e96a8..1c7960410be 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerTestsSuite.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/JavaDebuggerTestsSuite.xml @@ -15,6 +15,7 @@ + diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml index 2e01417bf76..7fa126ff35c 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/assembly.xml @@ -33,6 +33,10 @@ ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/EvaluateExpressionTest1.java ./org/eclipse + + ${project.build.testOutputDirectory}/workspace/test/src/org/eclipse/BreakpointsTest.java + ./org/eclipse + ${project.build.testOutputDirectory}/workspace/test/src/com/HelloWorld.java ./com diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/entrypoint.sh b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/entrypoint.sh index fac3f530076..d380d58bf59 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/entrypoint.sh +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/docker/entrypoint.sh @@ -17,10 +17,14 @@ javac -g org/eclipse/StackFrameDumpTest1.java javac -g org/eclipse/GetValueTest1.java javac -g org/eclipse/EvaluateExpressionTest1.java javac -g com/HelloWorld.java +javac -g org/eclipse/BreakpointsTest.java -java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y org.eclipse.ThreadDumpTest1 -java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y org.eclipse.ThreadDumpTest2 -java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y org.eclipse.StackFrameDumpTest1 -java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y org.eclipse.GetValueTest1 -java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y org.eclipse.EvaluateExpressionTest1 -java -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y com.HelloWorld +DEBUG_OPT="-Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y" + +java ${DEBUG_OPT} org.eclipse.BreakpointsTest +java ${DEBUG_OPT} org.eclipse.ThreadDumpTest1 +java ${DEBUG_OPT} org.eclipse.ThreadDumpTest2 +java ${DEBUG_OPT} org.eclipse.StackFrameDumpTest1 +java ${DEBUG_OPT} org.eclipse.GetValueTest1 +java ${DEBUG_OPT} org.eclipse.EvaluateExpressionTest1 +java ${DEBUG_OPT} com.HelloWorld diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/BreakpointsTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/BreakpointsTest.java new file mode 100644 index 00000000000..3eede294bf0 --- /dev/null +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/resources/workspace/test/src/org/eclipse/BreakpointsTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse; + +import java.util.stream.Stream; + +/** @author Anatolii Bazko */ +public class BreakpointsTest { + + public static void main(String[] args) { + sayHello(); + new InnerClass().sayHello(); + new Thread() { + @Override + public void run() { + System.out.println("Hello"); + } + }.run(); + Stream.of("a", "b") + .forEach( + v -> { + System.out.println(v); + }); + } + + private static void sayHello() { + System.out.println("Hello"); + } + + private static class InnerClass { + public void sayHello() { + System.out.println("Hello"); + } + } +} diff --git a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java index ea3b687aded..3b4687936b1 100644 --- a/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java +++ b/plugins/plugin-nodejs-debugger/che-plugin-nodejs-debugger-ide/src/main/java/org/eclipse/che/plugin/nodejsdbg/ide/NodeJsDebugger.java @@ -13,15 +13,12 @@ import com.google.inject.Inject; import com.google.web.bindery.event.shared.EventBus; import java.util.Map; -import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; -import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.DebuggerDescriptor; import org.eclipse.che.ide.debug.DebuggerManager; import org.eclipse.che.ide.dto.DtoFactory; @@ -67,16 +64,6 @@ public NodeJsDebugger( ID); } - @Override - protected String fqnToPath(@NotNull Location location) { - return location.getResourcePath() == null ? location.getTarget() : location.getResourcePath(); - } - - @Override - protected String pathToFqn(VirtualFile file) { - return file.getLocation().toString(); - } - @Override protected DebuggerDescriptor toDescriptor(Map connectionProperties) { StringBuilder sb = new StringBuilder(); diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/pom.xml b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/pom.xml index 15a39af5bd4..cd933ebd470 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/pom.xml +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/pom.xml @@ -35,10 +35,6 @@ org.eclipse.che.core che-core-api-core - - org.eclipse.che.core - che-core-api-debug-shared - org.eclipse.che.core che-core-commons-gwt diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java index 8b5dbcf0328..18946b01c77 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-ide/src/main/java/org/eclipse/che/plugin/zdb/ide/ZendDebugger.java @@ -12,15 +12,12 @@ import com.google.inject.Inject; import com.google.web.bindery.event.shared.EventBus; import java.util.Map; -import javax.validation.constraints.NotNull; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator; import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerManager; import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter; -import org.eclipse.che.api.debug.shared.model.Location; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.DebuggerDescriptor; import org.eclipse.che.ide.debug.DebuggerManager; import org.eclipse.che.ide.dto.DtoFactory; @@ -66,17 +63,6 @@ public ZendDebugger( ID); } - @Override - protected String fqnToPath(@NotNull Location location) { - String resourcePath = location.getResourcePath(); - return resourcePath != null ? resourcePath : location.getTarget(); - } - - @Override - protected String pathToFqn(VirtualFile file) { - return file.getName(); - } - @Override protected DebuggerDescriptor toDescriptor(Map connectionProperties) { return new DebuggerDescriptor( diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java index 3ab5ba4e8c8..1d25a0abc44 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java @@ -25,14 +25,12 @@ public class ZendDbgLocationHandler { public static final Location createVFS( - String target, String resourcePath, String resourceProjectPath, int lineNumber) { - return new LocationImpl( - target, lineNumber, resourcePath, false, 0, resourceProjectPath, null, -1); + String target, String resourceProjectPath, int lineNumber) { + return new LocationImpl(target, lineNumber, false, 0, resourceProjectPath, null, -1); } public static final Location createDBG(String resourcePath, int lineNumber) { - return new LocationImpl( - Path.of(resourcePath).getName(), lineNumber, resourcePath, false, 0, null, null, -1); + return new LocationImpl(Path.of(resourcePath).getName(), lineNumber, false, 0, null, null, -1); } /** @@ -43,18 +41,16 @@ public static final Location createDBG(String resourcePath, int lineNumber) { */ public Location convertToVFS(Location dbgLocation) { VirtualFileEntry localFileEntry = - ZendDbgFileUtils.findVirtualFileEntry(dbgLocation.getResourcePath()); + ZendDbgFileUtils.findVirtualFileEntry(dbgLocation.getTarget()); if (localFileEntry == null) { return null; } String resourceProjectPath = localFileEntry.getProject(); String target = localFileEntry.getName(); - String resourcePath = localFileEntry.getPath().toString(); int lineNumber = dbgLocation.getLineNumber(); return new LocationImpl( target, lineNumber, - resourcePath, false, 0, resourceProjectPath, @@ -69,16 +65,8 @@ public Location convertToVFS(Location dbgLocation) { * @return DBG specific location. */ public Location convertToDBG(Location vfsLocation) { - String resourcePath = ZendDbgFileUtils.findAbsolutePath(vfsLocation.getResourcePath()); int lineNumber = vfsLocation.getLineNumber(); return new LocationImpl( - null, - lineNumber, - resourcePath, - false, - 0, - null, - vfsLocation.getMethod(), - vfsLocation.getThreadId()); + null, lineNumber, false, 0, null, vfsLocation.getMethod(), vfsLocation.getThreadId()); } } diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java index fe03b9347d9..d6d180a480c 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDebugger.java @@ -462,7 +462,7 @@ private void sendGetVariables() { private void sendAddBreakpointFiles() { Set breakpointFiles = new HashSet<>(); for (ZendDbgBreakpoint dbgBreakpoint : breakpoints.values()) { - breakpointFiles.add(dbgBreakpoint.getLocation().getResourcePath()); + breakpointFiles.add(dbgBreakpoint.getLocation().getTarget()); } debugConnection.sendRequest(new AddFilesRequest(breakpointFiles)); } @@ -470,7 +470,7 @@ private void sendAddBreakpointFiles() { private void sendAddBreakpoints(String remoteFilePath) { List fileBreakpoints = new ArrayList<>(); for (ZendDbgBreakpoint dbgBreakpoint : breakpoints.values()) { - if (dbgBreakpoint.getLocation().getResourcePath().equals(remoteFilePath)) { + if (dbgBreakpoint.getLocation().getTarget().equals(remoteFilePath)) { fileBreakpoints.add(dbgBreakpoint); } } @@ -494,7 +494,7 @@ private void sendAddBreakpoint(ZendDbgBreakpoint dbgBreakpoint) { 1, 2, dbgBreakpoint.getLocation().getLineNumber(), - dbgBreakpoint.getLocation().getResourcePath())); + dbgBreakpoint.getLocation().getTarget())); if (isOK(response)) { // Breakpoint was successfully registered in active session, send breakpoint activated event breakpointIds.put(dbgBreakpoint, response.getBreakpointID()); diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/AbstractZendDbgSessionTest.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/AbstractZendDbgSessionTest.java index e5663bf02ea..78061b1394a 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/AbstractZendDbgSessionTest.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/test/java/org/eclipse/che/plugin/zdb/server/AbstractZendDbgSessionTest.java @@ -73,7 +73,7 @@ protected void awaitSuspend(String dbgFile, int lineNumber) throws Exception { } assertTrue(debuggerEvent instanceof SuspendEvent); SuspendEvent suspendEvent = (SuspendEvent) debuggerEvent; - assertEquals(suspendEvent.getLocation().getResourcePath(), dbgFile); + assertEquals(suspendEvent.getLocation().getTarget(), dbgFile); assertEquals(suspendEvent.getLocation().getLineNumber(), lineNumber); } diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java index 53ce29dad22..b10bbecafba 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/dto/LocationDto.java @@ -26,10 +26,6 @@ public interface LocationDto extends Location { void setExternalResource(boolean externalResource); - void setResourcePath(String resourcePath); - - LocationDto withResourcePath(String resourcePath); - LocationDto withExternalResource(boolean externalResource); void setExternalResourceId(int externalResourceId); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java index 4c27421904a..94a9d722c16 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/Location.java @@ -10,8 +10,6 @@ */ package org.eclipse.che.api.debug.shared.model; -import org.eclipse.che.commons.annotation.Nullable; - /** @author Anatoliy Bazko */ public interface Location { /** The target, e.g.: file, fqn, memory address etc. */ @@ -20,9 +18,6 @@ public interface Location { /** The line number in a file or in a class. */ int getLineNumber(); - /** Returns path to the resource. */ - String getResourcePath(); - /** Returns true if breakpoint resource is external resource, or false otherwise. */ boolean isExternalResource(); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java index a0330396aee..edd01e7e223 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/StackFrameDump.java @@ -11,7 +11,6 @@ package org.eclipse.che.api.debug.shared.model; import java.util.List; -import org.eclipse.che.commons.annotation.Nullable; /** @author Anatoliy Bazko */ public interface StackFrameDump { diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java index b42fbf47f25..2562f34cdc2 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java @@ -19,7 +19,6 @@ public class LocationImpl implements Location { private final String target; private final int lineNumber; - private final String resourcePath; private final boolean externalResource; private final int externalResourceId; private final String resourceProjectPath; @@ -29,7 +28,6 @@ public class LocationImpl implements Location { public LocationImpl( String target, int lineNumber, - String resourcePath, boolean externalResource, int externalResourceId, String resourceProjectPath, @@ -37,7 +35,6 @@ public LocationImpl( long threadId) { this.target = target; this.lineNumber = lineNumber; - this.resourcePath = resourcePath; this.externalResource = externalResource; this.externalResourceId = externalResourceId; this.resourceProjectPath = resourceProjectPath; @@ -46,11 +43,11 @@ public LocationImpl( } public LocationImpl(String target, int lineNumber) { - this(target, lineNumber, null, false, 0, null, null, -1); + this(target, lineNumber, false, 0, null, null, -1); } public LocationImpl(String target) { - this(target, 0, null, false, 0, null, null, -1); + this(target, 0, false, 0, null, null, -1); } @Override @@ -63,11 +60,6 @@ public int getLineNumber() { return lineNumber; } - @Override - public String getResourcePath() { - return resourcePath; - } - @Override public boolean isExternalResource() { return externalResource; @@ -103,7 +95,6 @@ public boolean equals(Object o) { && externalResourceId == location.externalResourceId && threadId == location.threadId && equal(target, location.target) - && equal(resourcePath, location.resourcePath) && equal(resourceProjectPath, location.resourceProjectPath) && equal(method, location.method); } @@ -113,7 +104,6 @@ public int hashCode() { return com.google.common.base.Objects.hashCode( target, lineNumber, - resourcePath, externalResource, externalResourceId, resourceProjectPath, @@ -129,9 +119,6 @@ public String toString() { + '\'' + ", lineNumber=" + lineNumber - + ", resourcePath='" - + resourcePath - + '\'' + ", externalResource=" + externalResource + ", externalResourceId=" diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java index 5232711f92f..8c4104f6163 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/MutableVariableImpl.java @@ -11,7 +11,6 @@ package org.eclipse.che.api.debug.shared.model.impl; import com.google.common.base.Objects; - import org.eclipse.che.api.debug.shared.model.MutableVariable; import org.eclipse.che.api.debug.shared.model.SimpleValue; import org.eclipse.che.api.debug.shared.model.Variable; diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java index 3c8e270530f..50c79c219eb 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DtoConverter.java @@ -88,7 +88,6 @@ public static LocationDto asDto(Location location) { .withThreadId(location.getThreadId()) .withLineNumber(location.getLineNumber()) .withExternalResourceId(location.getExternalResourceId()) - .withResourcePath(location.getResourcePath()) .withResourceProjectPath(location.getResourceProjectPath()) .withExternalResource(location.isExternalResource()) .withMethod(location.getMethod() == null ? null : asDto(location.getMethod())); From ed918da91225afcf11d0e4432fccb3153461b872 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Thu, 7 Sep 2017 11:22:56 +0300 Subject: [PATCH 33/38] Fix up --- .../che/plugin/debugger/ide/debug/AbstractDebugger.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index c10581c37db..608f867f5b5 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -369,9 +369,12 @@ public void deleteBreakpoint(final VirtualFile file, final Breakpoint breakpoint if (!isConnected()) { return; } + Location location = breakpoint.getLocation(); + LocationDto locationDto = dtoFactory.createDto(LocationDto.class); - locationDto.setLineNumber(breakpoint.getLocation().getLineNumber() + 1); - locationDto.setTarget(breakpoint.getLocation().getTarget()); + locationDto.setLineNumber(location.getLineNumber() + 1); + locationDto.setTarget(location.getTarget()); + locationDto.setResourceProjectPath(getProject(file).getPath()); Promise promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto); promise From f36d60755c2930ac47e7469d250bf5554323cc61 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Thu, 7 Sep 2017 14:27:57 +0300 Subject: [PATCH 34/38] Fix up --- .../che/ide/debug/BreakpointManagerImpl.java | 28 ++++++++++------- .../debugger/ide/debug/AbstractDebugger.java | 9 +++--- .../ide/debug/BreakpointItemRender.java | 2 +- .../che/plugin/jdb/server/JavaDebugger.java | 3 +- .../jdb/server/utils/JavaDebuggerUtils.java | 31 +++++++++++++------ 5 files changed, 43 insertions(+), 30 deletions(-) diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java index a5cfcf2f5b6..40e382a67c0 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java @@ -12,6 +12,7 @@ import com.google.gwt.user.client.Timer; import com.google.inject.Inject; +import com.google.inject.Singleton; import com.google.web.bindery.event.shared.EventBus; import java.util.ArrayList; import java.util.List; @@ -55,6 +56,7 @@ * @author Valeriy Svydenko * @author Dmytro Nochevnov */ +@Singleton public class BreakpointManagerImpl implements BreakpointManager, LineChangeAction, @@ -94,7 +96,7 @@ public void changeBreakpointState(final int lineNumber) { final VirtualFile activeFile = editor.getEditorInput().getFile(); Optional existedBreakpoint = - breakpointStorage.get(activeFile.getLocation().toString(), lineNumber); + breakpointStorage.get(activeFile.getLocation().toString(), lineNumber + 1); if (existedBreakpoint.isPresent()) { deleteBreakpoint(activeFile, existedBreakpoint.get()); @@ -102,7 +104,8 @@ public void changeBreakpointState(final int lineNumber) { if (isLineNotEmpty(activeFile, lineNumber)) { addBreakpoint( activeFile, - new BreakpointImpl(new LocationImpl(activeFile.getLocation().toString(), lineNumber))); + new BreakpointImpl( + new LocationImpl(activeFile.getLocation().toString(), lineNumber + 1))); } } } @@ -113,7 +116,7 @@ private void deleteBreakpoint(final VirtualFile activeFile, final Breakpoint bre BreakpointRenderer renderer = getBreakpointRendererForFile(activeFile.getLocation().toString()); if (renderer != null) { - renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber()); + renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber() - 1); } for (BreakpointManagerObserver observer : observers) { @@ -133,7 +136,7 @@ private void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) if (renderer != null) { renderer.addBreakpointMark( - breakpoint.getLocation().getLineNumber(), BreakpointManagerImpl.this::onLineChange); + breakpoint.getLocation().getLineNumber() - 1, BreakpointManagerImpl.this::onLineChange); } for (BreakpointManagerObserver observer : observers) { @@ -173,7 +176,7 @@ private void setSuspendedLocation(Location location) { BreakpointRenderer renderer = getBreakpointRendererForFile(activeFile.getLocation().toString()); if (renderer != null) { - renderer.setLineActive(location.getLineNumber(), true); + renderer.setLineActive(location.getLineNumber() - 1, true); } } } @@ -187,7 +190,7 @@ public void deleteAllBreakpoints() { BreakpointRenderer renderer = getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); if (renderer != null) { - renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber()); + renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber() - 1); } }); @@ -218,7 +221,7 @@ private void deleteSuspendedLocation() { if (suspendedLocation != null) { BreakpointRenderer renderer = getBreakpointRendererForFile(suspendedLocation.getTarget()); if (renderer != null) { - renderer.setLineActive(suspendedLocation.getLineNumber(), false); + renderer.setLineActive(suspendedLocation.getLineNumber() - 1, false); } suspendedLocation = null; @@ -402,7 +405,7 @@ private void onOpenEditor(String filePath, EditorPartPresenter editor) { .forEach( breakpoint -> renderer.addBreakpointMark( - breakpoint.getLocation().getLineNumber(), + breakpoint.getLocation().getLineNumber() - 1, BreakpointManagerImpl.this::onLineChange)); Debugger debugger = debuggerManager.getActiveDebugger(); @@ -412,13 +415,14 @@ private void onOpenEditor(String filePath, EditorPartPresenter editor) { .then( breakpoints -> { for (Breakpoint breakpoint : breakpoints) { - renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber(), true); + renderer.setBreakpointActive( + breakpoint.getLocation().getLineNumber() - 1, true); } }); } if (suspendedLocation != null && suspendedLocation.getTarget().equals(filePath)) { - renderer.setLineActive(suspendedLocation.getLineNumber(), true); + renderer.setLineActive(suspendedLocation.getLineNumber() - 1, true); } } } @@ -440,7 +444,7 @@ public void onDebuggerDisconnected() { BreakpointRenderer renderer = getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); if (renderer != null) { - renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber(), false); + renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber() - 1, false); } }); @@ -459,7 +463,7 @@ public void onBreakpointActivated(String filePath, int lineNumber) { BreakpointRenderer renderer = getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); if (renderer != null) { - renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber(), true); + renderer.setBreakpointActive(breakpoint.getLocation().getLineNumber() - 1, true); } }); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 608f867f5b5..0d4b6b076cd 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -244,7 +244,7 @@ public void onSuccess(VirtualFile result) { */ private void onBreakpointActivated(LocationDto locationDto) { for (DebuggerObserver observer : observers) { - observer.onBreakpointActivated(locationDto.getTarget(), locationDto.getLineNumber() - 1); + observer.onBreakpointActivated(locationDto.getTarget(), locationDto.getLineNumber()); } } @@ -342,7 +342,7 @@ public void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { LocationDto locationDto = dtoFactory .createDto(LocationDto.class) - .withLineNumber(breakpoint.getLocation().getLineNumber() + 1) + .withLineNumber(breakpoint.getLocation().getLineNumber()) .withTarget(breakpoint.getLocation().getTarget()) .withResourceProjectPath(getProject(file).getPath()); @@ -372,9 +372,8 @@ public void deleteBreakpoint(final VirtualFile file, final Breakpoint breakpoint Location location = breakpoint.getLocation(); LocationDto locationDto = dtoFactory.createDto(LocationDto.class); - locationDto.setLineNumber(location.getLineNumber() + 1); + locationDto.setLineNumber(location.getLineNumber()); locationDto.setTarget(location.getTarget()); - locationDto.setResourceProjectPath(getProject(file).getPath()); Promise promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto); promise @@ -468,7 +467,7 @@ protected void startDebugger(final DebugSessionDto debugSessionDto) { dtoFactory .createDto(LocationDto.class) .withTarget(breakpoint.getLocation().getTarget()) - .withLineNumber(breakpoint.getLocation().getLineNumber() + 1); + .withLineNumber(breakpoint.getLocation().getLineNumber()); BreakpointDto breakpointDto = dtoFactory.createDto(BreakpointDto.class); breakpointDto.setLocation(locationDto); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java index 3502fb13497..41814bf9e6d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/BreakpointItemRender.java @@ -53,7 +53,7 @@ public void render(Element itemElement, Breakpoint itemData) { sb.appendEscaped( path.substring(path.lastIndexOf("/") + 1) + ":" - + String.valueOf(itemData.getLocation().getLineNumber() + 1)); + + String.valueOf(itemData.getLocation().getLineNumber())); sb.appendHtmlConstant(""); label.setInnerHTML(sb.toSafeHtml().asString()); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index e05b761fd24..1200a7218c0 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -269,10 +269,9 @@ public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { private String findFQN(Location location) throws DebuggerException { final String parentFqn = location.getTarget(); - final String projectPath = location.getResourceProjectPath(); int lineNumber = location.getLineNumber(); - return debuggerUtil.findFqnByPosition(projectPath, parentFqn, lineNumber); + return debuggerUtil.findFqnByPosition(parentFqn, lineNumber); } private void deferBreakpoint(String className, Breakpoint breakpoint) throws DebuggerException { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java index bc57a5a5cb6..326ba11dd7e 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java @@ -147,21 +147,13 @@ public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { * Return nested class fqn if line with number {@code lineNumber} contains such element, otherwise * return outer class fqn. * - * @param projectPath project path which contains class with {@code outerClassFqn} * @param filePath path to the file * @param lineNumber line position to search * @throws DebuggerException */ - public String findFqnByPosition(String projectPath, String filePath, int lineNumber) - throws DebuggerException { - - if (projectPath == null) { - return filePath; - } - - IJavaProject project = MODEL.getJavaProject(projectPath); - + public String findFqnByPosition(String filePath, int lineNumber) throws DebuggerException { IPath path = Path.fromOSString(filePath); + IJavaProject project = getJavaProject(path); String fqn = null; for (int i = path.segmentCount(); i > 0; i--) { @@ -230,6 +222,25 @@ public String findFqnByPosition(String projectPath, String filePath, int lineNum return filePath; } + private IJavaProject getJavaProject(IPath path) throws DebuggerException { + IJavaProject project = null; + outer: + for (int i = 1; i < path.segmentCount(); i++) { + IPath projectPath = path.removeLastSegments(i); + try { + for (IJavaProject p : MODEL.getJavaProjects()) { + if (p.getPath().equals(projectPath)) { + project = p; + break outer; + } + } + } catch (JavaModelException e) { + throw new DebuggerException(e.getMessage(), e); + } + } + return project; + } + /** * Searches the given source range of the container for a member that is not the same as the given * type. From 11fabb0108ee95492e28eb934fc1d0789b3509d5 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Mon, 11 Sep 2017 15:46:46 +0300 Subject: [PATCH 35/38] Fix tests --- .../api/debug/DebuggerServiceClientImpl.java | 7 +- .../che/ide/debug/BreakpointManagerImpl.java | 61 +++++++++----- .../org/eclipse/che/ide/debug/Debugger.java | 3 + .../debugger/ide/debug/AbstractDebugger.java | 81 ++++++++++--------- .../debugger/ide/debug/DebuggerViewImpl.java | 3 +- .../debugger/ide/debug/FrameItemRender.java | 16 ++-- .../debugger/ide/debug/DebuggerTest.java | 4 +- .../che/plugin/jdb/server/JavaDebugger.java | 11 +-- .../jdb/server/utils/JavaDebuggerUtils.java | 25 +++--- .../plugin/jdb/server/BreakpointsTest.java | 38 ++++++++- .../zdb/server/ZendDbgLocationHandler.java | 9 ++- .../selenium/pageobject/CodenvyEditor.java | 8 ++ .../selenium/pageobject/debug/DebugPanel.java | 4 +- .../ChangeVariableWithEvaluatingTest.java | 18 ++--- .../debugger/CheckBreakPointStateTest.java | 13 ++- .../debugger/DebugExternalClassTest.java | 4 +- .../InnerClassAndLambdaDebuggingTest.java | 22 ++--- .../MultimoduleProjectDebuggingTest.java | 26 ++++-- .../selenium/debugger/NodeJsDebugTest.java | 4 +- ...pOverStepReturnWithChangeVariableTest.java | 8 +- .../src/main/java/test/App.java | 2 +- .../debug/shared/model/impl/LocationImpl.java | 4 + .../api/debugger/server/DebuggerService.java | 5 +- .../pom.xml | 2 +- 24 files changed, 235 insertions(+), 143 deletions(-) diff --git a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java index e931b8b3fbd..b692f036ca3 100644 --- a/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java +++ b/ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/debug/DebuggerServiceClientImpl.java @@ -120,7 +120,12 @@ public Promise> getAllBreakpoints(String id) { public Promise deleteBreakpoint(String id, LocationDto locationDto) { final String requestUrl = getBaseUrl(id) + "/breakpoint"; final String params = - "?target=" + locationDto.getTarget() + "&line=" + locationDto.getLineNumber(); + "?target=" + + locationDto.getTarget() + + "&line=" + + locationDto.getLineNumber() + + "&project=" + + locationDto.getResourceProjectPath(); return asyncRequestFactory.createDeleteRequest(requestUrl + params).send(); } diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java index 40e382a67c0..60270663f94 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/BreakpointManagerImpl.java @@ -47,6 +47,7 @@ import org.eclipse.che.ide.api.resources.ResourceChangedEvent; import org.eclipse.che.ide.api.resources.ResourceDelta; import org.eclipse.che.ide.api.resources.VirtualFile; +import org.eclipse.che.ide.project.node.SyntheticNode; import org.eclipse.che.ide.resource.Path; /** @@ -101,12 +102,22 @@ public void changeBreakpointState(final int lineNumber) { if (existedBreakpoint.isPresent()) { deleteBreakpoint(activeFile, existedBreakpoint.get()); } else { - if (isLineNotEmpty(activeFile, lineNumber)) { - addBreakpoint( - activeFile, - new BreakpointImpl( - new LocationImpl(activeFile.getLocation().toString(), lineNumber + 1))); + String project = null; + if (activeFile instanceof SyntheticNode) { + project = ((SyntheticNode) activeFile).getProject().toString(); + } else if (activeFile instanceof Resource) { + project = ((Resource) activeFile).getProject().getPath(); } + + if (project == null) { + LOG.warning("Impossible to figure out project for: " + activeFile.getLocation().toString()); + return; + } + + addBreakpoint( + activeFile, + new BreakpointImpl( + new LocationImpl(activeFile.getLocation().toString(), lineNumber + 1, project))); } } @@ -130,6 +141,9 @@ private void deleteBreakpoint(final VirtualFile activeFile, final Breakpoint bre } private void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { + if (isLineEmpty(file, breakpoint.getLocation().getLineNumber())) { + return; + } breakpointStorage.add(breakpoint); final BreakpointRenderer renderer = getBreakpointRendererForFile(file.getLocation().toString()); @@ -150,11 +164,11 @@ private void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) } /** Indicates if line of code to add breakpoint at is executable. */ - private boolean isLineNotEmpty(final VirtualFile activeFile, int lineNumber) { + private boolean isLineEmpty(final VirtualFile activeFile, int lineNumber) { EditorPartPresenter editor = getEditorForFile(activeFile.getLocation().toString()); if (editor instanceof TextEditor) { Document document = ((TextEditor) editor).getDocument(); - return !document.getLineContent(lineNumber).trim().isEmpty(); + return document.getLineContent(lineNumber - 1).trim().isEmpty(); } return false; @@ -214,7 +228,19 @@ private void deleteBreakpoints(String parentPath) { .filter(breakpoint -> breakpoint.getLocation().getTarget().startsWith(parentPath)) .collect(Collectors.toList()); - breakpoints2delete.forEach(breakpointStorage::delete); + for (Breakpoint breakpoint : breakpoints2delete) { + breakpointStorage.delete(breakpoint); + + BreakpointRenderer renderer = + getBreakpointRendererForFile(breakpoint.getLocation().getTarget()); + if (renderer != null) { + renderer.removeBreakpointMark(breakpoint.getLocation().getLineNumber() - 1); + } + + for (BreakpointManagerObserver observer : observers) { + observer.onBreakpointDeleted(breakpoint); + } + } } private void deleteSuspendedLocation() { @@ -305,9 +331,7 @@ public void onLineChange( } for (final Breakpoint breakpoint : toAdd) { - if (isLineNotEmpty(file, breakpoint.getLocation().getLineNumber())) { - addBreakpoint(file, breakpoint); - } + addBreakpoint(file, breakpoint); } } } @@ -335,11 +359,8 @@ private void registerEventHandlers(EventBus eventBus) { final Resource resource = event.getDelta().getResource(); Path path = resource.getLocation(); - if (resource.isFolder()) { - path.addTrailingSeparator(); - - deleteBreakpoints(path.toString()); + deleteBreakpoints(path.addTrailingSeparator().toString()); } else if (resource.isFile()) { deleteBreakpoints(path.toString()); } @@ -380,14 +401,13 @@ private void onFileContentUpdate(FileContentUpdateEvent event) { BreakpointRenderer breakpointRenderer = getBreakpointRendererForEditor(editor); if (breakpointRenderer != null) { - breakpointRenderer.setLineActive(suspendedLocation.getLineNumber(), false); - breakpointRenderer.setLineActive(suspendedLocation.getLineNumber(), true); - new Timer() { @Override public void run() { + breakpointRenderer.setLineActive( + suspendedLocation.getLineNumber() - 1, true); textEditor.setCursorPosition( - new TextPosition(suspendedLocation.getLineNumber() + 1, 0)); + new TextPosition(suspendedLocation.getLineNumber(), 0)); } }.schedule(300); } @@ -496,7 +516,8 @@ public void onPreResume() { @Override public void onBreakpointStopped(String filePath, Location location) { - setSuspendedLocation(location); + setSuspendedLocation( + new LocationImpl(filePath, location.getLineNumber(), location.getResourceProjectPath())); } @Override diff --git a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java index 7763f78d358..71c75f24f3d 100644 --- a/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java +++ b/ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/debug/Debugger.java @@ -33,6 +33,9 @@ public interface Debugger extends DebuggerObservable { /** Returns debugger type */ String getDebuggerType(); + /** Creates breakpoint. */ + Breakpoint createBreakpoint(VirtualFile file, int lineNumber); + /** * Adds new breakpoint. * diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index 0d4b6b076cd..b98d474648c 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -48,6 +48,8 @@ import org.eclipse.che.api.debug.shared.model.Variable; import org.eclipse.che.api.debug.shared.model.VariablePath; import org.eclipse.che.api.debug.shared.model.action.Action; +import org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl; +import org.eclipse.che.api.debug.shared.model.impl.LocationImpl; import org.eclipse.che.api.promises.client.Function; import org.eclipse.che.api.promises.client.Operation; import org.eclipse.che.api.promises.client.OperationException; @@ -55,14 +57,11 @@ import org.eclipse.che.api.promises.client.PromiseError; import org.eclipse.che.api.promises.client.js.JsPromiseError; import org.eclipse.che.api.promises.client.js.Promises; -import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.ide.api.debug.BreakpointManager; import org.eclipse.che.ide.api.debug.DebuggerServiceClient; import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent; import org.eclipse.che.ide.api.machine.events.WsAgentStateHandler; import org.eclipse.che.ide.api.notification.NotificationManager; -import org.eclipse.che.ide.api.resources.Project; -import org.eclipse.che.ide.api.resources.Resource; import org.eclipse.che.ide.api.resources.VirtualFile; import org.eclipse.che.ide.debug.Debugger; import org.eclipse.che.ide.debug.DebuggerDescriptor; @@ -99,7 +98,7 @@ public abstract class AbstractDebugger implements Debugger, DebuggerObservable { private final DebuggerServiceClient service; private final LocalStorageProvider localStorageProvider; private final EventBus eventBus; - private final DebuggerResourceHandler debuggerResourceHandler; + private final DebuggerResourceHandlerFactory debuggerResourceHandlerFactory; private final DebuggerManager debuggerManager; private final BreakpointManager breakpointManager; private final String debuggerType; @@ -127,7 +126,7 @@ public AbstractDebugger( this.dtoFactory = dtoFactory; this.localStorageProvider = localStorageProvider; this.eventBus = eventBus; - this.debuggerResourceHandler = debuggerResourceHandlerFactory.getOrDefault(getDebuggerType()); + this.debuggerResourceHandlerFactory = debuggerResourceHandlerFactory; this.debuggerManager = debuggerManager; this.notificationManager = notificationManager; this.breakpointManager = breakpointManager; @@ -212,23 +211,25 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) { private void open(Location location) { try { - debuggerResourceHandler.open( - location, - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(location.getTarget(), location); - } - } + debuggerResourceHandlerFactory + .getOrDefault(getDebuggerType()) + .open( + location, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + for (DebuggerObserver observer : observers) { + observer.onBreakpointStopped(location.getTarget(), location); + } + } - @Override - public void onSuccess(VirtualFile result) { - for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(result.getLocation().toString(), location); - } - } - }); + @Override + public void onSuccess(VirtualFile result) { + for (DebuggerObserver observer : observers) { + observer.onBreakpointStopped(result.getLocation().toString(), location); + } + } + }); } catch (Exception e) { for (DebuggerObserver observer : observers) { observer.onBreakpointStopped(location.getTarget(), location); @@ -336,15 +337,20 @@ public Promise> getThreadDump() { return service.getThreadDump(debugSessionDto.getId()); } + @Override + public Breakpoint createBreakpoint(VirtualFile file, int lineNumber) { + return new BreakpointImpl(new LocationImpl(file.getLocation().toString(), lineNumber)); + } + @Override public void addBreakpoint(final VirtualFile file, final Breakpoint breakpoint) { if (isConnected()) { - LocationDto locationDto = - dtoFactory - .createDto(LocationDto.class) - .withLineNumber(breakpoint.getLocation().getLineNumber()) - .withTarget(breakpoint.getLocation().getTarget()) - .withResourceProjectPath(getProject(file).getPath()); + Location location = breakpoint.getLocation(); + + LocationDto locationDto = dtoFactory.createDto(LocationDto.class); + locationDto.setLineNumber(location.getLineNumber()); + locationDto.setTarget(location.getTarget()); + locationDto.setResourceProjectPath(location.getResourceProjectPath()); BreakpointDto breakpointDto = dtoFactory.createDto(BreakpointDto.class).withLocation(locationDto).withEnabled(true); @@ -374,6 +380,7 @@ public void deleteBreakpoint(final VirtualFile file, final Breakpoint breakpoint LocationDto locationDto = dtoFactory.createDto(LocationDto.class); locationDto.setLineNumber(location.getLineNumber()); locationDto.setTarget(location.getTarget()); + locationDto.setResourceProjectPath(location.getResourceProjectPath()); Promise promise = service.deleteBreakpoint(debugSessionDto.getId(), locationDto); promise @@ -463,15 +470,17 @@ public Promise connect(Map connectionProperties) { protected void startDebugger(final DebugSessionDto debugSessionDto) { List breakpoints = new ArrayList<>(); for (Breakpoint breakpoint : breakpointManager.getBreakpointList()) { - LocationDto locationDto = - dtoFactory - .createDto(LocationDto.class) - .withTarget(breakpoint.getLocation().getTarget()) - .withLineNumber(breakpoint.getLocation().getLineNumber()); + Location location = breakpoint.getLocation(); + + LocationDto locationDto = dtoFactory.createDto(LocationDto.class); + locationDto.setLineNumber(location.getLineNumber()); + locationDto.setTarget(location.getTarget()); + locationDto.setResourceProjectPath(location.getResourceProjectPath()); BreakpointDto breakpointDto = dtoFactory.createDto(BreakpointDto.class); breakpointDto.setLocation(locationDto); breakpointDto.setEnabled(true); + breakpoints.add(breakpointDto); } @@ -753,13 +762,5 @@ private VariableDto toDto(Variable variable) { return dto; } - @Nullable - protected Project getProject(VirtualFile virtualFile) { - if (virtualFile instanceof Resource) { - return ((Resource) virtualFile).getProject(); - } - return null; - } - protected abstract DebuggerDescriptor toDescriptor(Map connectionProperties); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java index c707e5ccd24..a961e3891a5 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerViewImpl.java @@ -44,6 +44,7 @@ import org.eclipse.che.ide.Resources; import org.eclipse.che.ide.api.parts.PartStackUIResources; import org.eclipse.che.ide.api.parts.base.BaseView; +import org.eclipse.che.ide.resource.Path; import org.eclipse.che.ide.ui.list.SimpleList; import org.eclipse.che.ide.ui.tree.Tree; import org.eclipse.che.ide.ui.tree.TreeNodeElement; @@ -170,7 +171,7 @@ public void setExecutionPoint(@Nullable Location location) { if (location != null) { labelText .append("{") - .append(location.getTarget()) + .append(Path.valueOf(location.getTarget()).lastSegment()) .append(":") .append(location.getLineNumber()) .append("} "); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java index 6dc9824dda4..fc1b2f92fee 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/FrameItemRender.java @@ -16,6 +16,7 @@ import java.util.List; import org.eclipse.che.api.debug.shared.model.StackFrameDump; import org.eclipse.che.api.debug.shared.model.Variable; +import org.eclipse.che.ide.resource.Path; import org.eclipse.che.ide.ui.list.SimpleList; import org.eclipse.che.ide.util.dom.Elements; @@ -49,13 +50,16 @@ public void render(Element itemElement, StackFrameDump itemData) { sb.append(itemData.getLocation().getLineNumber()); sb.appendEscaped(", "); - String target = itemData.getLocation().getTarget(); - int classNameIndex = target.lastIndexOf("."); + Path path = Path.valueOf(itemData.getLocation().getTarget()); - sb.appendEscaped(target.substring(classNameIndex + 1)); - sb.appendEscaped(" ("); - sb.appendEscaped(target.substring(0, classNameIndex)); - sb.appendEscaped(") "); + String className; + if (path.isAbsolute()) { + className = path.removeFileExtension().lastSegment(); + } else { + className = path.lastSegment(); + } + + sb.appendEscaped(className); label.setInnerHTML(sb.toSafeHtml().asString()); itemElement.appendChild(label); diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java index cd9a35286f9..1ebd1c7d25d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/test/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerTest.java @@ -389,7 +389,6 @@ public void testAddBreakpoint() throws Exception { MockSettings mockSettings = new MockSettingsImpl<>().defaultAnswer(RETURNS_SMART_NULLS).extraInterfaces(Resource.class); Project project = mock(Project.class); - doReturn(project).when(debugger).getProject(any()); when(optional.isPresent()).thenReturn(true); when(optional.get()).thenReturn(project); when(project.getPath()).thenReturn(PATH); @@ -404,8 +403,7 @@ public void testAddBreakpoint() throws Exception { when(resource.getRelatedProject()).thenReturn(optional); doReturn(promiseVoid).when(service).addBreakpoint(SESSION_ID, breakpointDto); doReturn(promiseVoid).when(promiseVoid).then((Operation) any()); - when(locationDto.withLineNumber(LINE_NUMBER + 1)).thenReturn(locationDto); - when(locationDto.withResourceProjectPath(PATH)).thenReturn(locationDto); + when(locationDto.withLineNumber(LINE_NUMBER)).thenReturn(locationDto); when(locationDto.withTarget(anyString())).thenReturn(locationDto); when(breakpointDto.getLocation().getLineNumber()).thenReturn(LINE_NUMBER); when(breakpointDto.withLocation(locationDto)).thenReturn(breakpointDto); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java index 1200a7218c0..69dcd2ba0bc 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/JavaDebugger.java @@ -210,7 +210,7 @@ public void disconnect() throws DebuggerException { @Override public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { - final String className = findFQN(breakpoint.getLocation()); + final String className = debuggerUtil.findFqnByPosition(breakpoint.getLocation()); final int lineNumber = breakpoint.getLocation().getLineNumber(); List classes = vm.classesByName(className); // it may mean that class doesn't loaded by a target JVM yet @@ -267,13 +267,6 @@ public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { LOG.debug("Add breakpoint: {}", location); } - private String findFQN(Location location) throws DebuggerException { - final String parentFqn = location.getTarget(); - int lineNumber = location.getLineNumber(); - - return debuggerUtil.findFqnByPosition(parentFqn, lineNumber); - } - private void deferBreakpoint(String className, Breakpoint breakpoint) throws DebuggerException { List newList = new ArrayList<>(); List list = deferredBreakpoints.putIfAbsent(className, newList); @@ -324,7 +317,7 @@ public List getAllBreakpoints() throws DebuggerException { @Override public void deleteBreakpoint(Location location) throws DebuggerException { - final String className = findFQN(location); + final String className = debuggerUtil.findFqnByPosition(location); final int lineNumber = location.getLineNumber(); EventRequestManager requestManager = getEventManager(); List snapshot = new ArrayList<>(requestManager.breakpointRequests()); diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java index 326ba11dd7e..998a93b320f 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/main/java/org/eclipse/che/plugin/jdb/server/utils/JavaDebuggerUtils.java @@ -147,13 +147,18 @@ public void acceptTypeNameMatch(TypeNameMatch typeNameMatch) { * Return nested class fqn if line with number {@code lineNumber} contains such element, otherwise * return outer class fqn. * - * @param filePath path to the file - * @param lineNumber line position to search * @throws DebuggerException */ - public String findFqnByPosition(String filePath, int lineNumber) throws DebuggerException { - IPath path = Path.fromOSString(filePath); + public String findFqnByPosition(Location location) throws DebuggerException { + IPath path = Path.fromOSString(location.getTarget()); IJavaProject project = getJavaProject(path); + if (project == null) { + if (location.getResourceProjectPath() != null) { + project = MODEL.getJavaProject(location.getResourceProjectPath()); + } else { + return location.getTarget(); + } + } String fqn = null; for (int i = path.segmentCount(); i > 0; i--) { @@ -170,12 +175,12 @@ public String findFqnByPosition(String filePath, int lineNumber) throws Debugger break; } } catch (JavaModelException e) { - return filePath; + return location.getTarget(); } } if (fqn == null) { - return filePath; + return location.getTarget(); } IType outerClass; @@ -184,7 +189,7 @@ public String findFqnByPosition(String filePath, int lineNumber) throws Debugger outerClass = project.findType(fqn); if (outerClass == null) { - return filePath; + return location.getTarget(); } String source; @@ -197,7 +202,7 @@ public String findFqnByPosition(String filePath, int lineNumber) throws Debugger } Document document = new Document(source); - IRegion region = document.getLineInformation(lineNumber); + IRegion region = document.getLineInformation(location.getLineNumber()); int start = region.getOffset(); int end = start + region.getLength(); @@ -206,7 +211,7 @@ public String findFqnByPosition(String filePath, int lineNumber) throws Debugger throw new DebuggerException( format( "Unable to find source for class with fqn '%s' in the project '%s'", - filePath, project), + location.getTarget(), project), e); } catch (BadLocationException e) { throw new DebuggerException("Unable to calculate breakpoint location", e); @@ -219,7 +224,7 @@ public String findFqnByPosition(String filePath, int lineNumber) throws Debugger return iMember.getDeclaringType().getFullyQualifiedName(); } - return filePath; + return location.getTarget(); } private IJavaProject getJavaProject(IPath path) throws DebuggerException { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java index 685101f0df0..34f62222728 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/BreakpointsTest.java @@ -93,6 +93,38 @@ public void shouldAddBreakpointInsideMethod() throws Exception { } @Test(priority = 1) + public void shouldAddBreakpointByFqn() throws Exception { + Location location = + new LocationImpl("org.eclipse.BreakpointsTest", 20, false, -1, "/test", null, -1); + + try { + debugger.addBreakpoint(new BreakpointImpl(location, false, null)); + } catch (DebuggerException e) { + // class might not be loaded yet + } + + debugger.resume(new ResumeActionImpl()); + + DebuggerEvent debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof BreakpointActivatedEvent); + + Breakpoint actualBreakpoint = ((BreakpointActivatedEvent) debuggerEvent).getBreakpoint(); + Location actualLocation = actualBreakpoint.getLocation(); + assertEquals(actualLocation.getLineNumber(), 20); + assertEquals(actualLocation.getTarget(), "org.eclipse.BreakpointsTest"); + assertEquals(actualLocation.getResourceProjectPath(), "/test"); + assertTrue(actualBreakpoint.isEnabled()); + + debuggerEvent = events.take(); + assertTrue(debuggerEvent instanceof SuspendEvent); + + Location suspendLocation = ((SuspendEvent) debuggerEvent).getLocation(); + assertEquals(suspendLocation.getLineNumber(), 20); + assertEquals(actualLocation.getTarget(), "org.eclipse.BreakpointsTest"); + assertEquals(actualLocation.getResourceProjectPath(), "/test"); + } + + @Test(priority = 2) public void shouldAddBreakpointInsideInnerClass() throws Exception { Location location = new LocationImpl( @@ -123,7 +155,7 @@ public void shouldAddBreakpointInsideInnerClass() throws Exception { assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); } - @Test(priority = 2) + @Test(priority = 3) public void shouldAddBreakpointInsideAnonymousClass() throws Exception { Location location = new LocationImpl( @@ -154,7 +186,7 @@ public void shouldAddBreakpointInsideAnonymousClass() throws Exception { assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); } - @Test(priority = 2) + @Test(priority = 4) public void shouldAddBreakpointInsideLambdaFunction() throws Exception { Location location = new LocationImpl( @@ -185,7 +217,7 @@ public void shouldAddBreakpointInsideLambdaFunction() throws Exception { assertEquals(actualLocation.getTarget(), "/test/src/org/eclipse/BreakpointsTest.java"); } - @Test(priority = 3) + @Test(priority = 4) public void shouldRemoveAllBreakpoints() throws Exception { assertFalse(debugger.getAllBreakpoints().isEmpty()); diff --git a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java index 1d25a0abc44..99e3223c138 100644 --- a/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java +++ b/plugins/plugin-zend-debugger/che-plugin-zend-debugger-server/src/main/java/org/eclipse/che/plugin/zdb/server/ZendDbgLocationHandler.java @@ -65,8 +65,13 @@ public Location convertToVFS(Location dbgLocation) { * @return DBG specific location. */ public Location convertToDBG(Location vfsLocation) { - int lineNumber = vfsLocation.getLineNumber(); return new LocationImpl( - null, lineNumber, false, 0, null, vfsLocation.getMethod(), vfsLocation.getThreadId()); + vfsLocation.getTarget(), + vfsLocation.getLineNumber(), + false, + 0, + vfsLocation.getResourceProjectPath(), + null, + -1); } } diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java index 0ad028f3853..59705a9c9e6 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java @@ -1040,6 +1040,14 @@ public void setBreakPointAndWaitActiveState(int position) { waitBreakPointWithActiveState(position); } + public void setBreakpoint(int position) { + waitActiveEditor(); + waitDebugerLineIsVisible(position); + seleniumWebDriver + .findElement(By.xpath(String.format(Locators.DEBUGGER_PREFIX_XPATH, position))) + .click(); + } + /** * wait breakpoint with active state in defined position * diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java index fa2ea9d03fa..7bde6e387f7 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java @@ -332,7 +332,9 @@ public void waitBreakPointHighlighterInDefinedPosition(int numOfPosition) { /** Open debug panel by clicking on "Debug" tab. */ public void openDebugPanel() { - debuggerTab.click(); + if (!isDebuggerBtnPanelPresent()) { + debuggerTab.click(); + } } /** diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java index 9ceb8b8423e..2be629bfa54 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java @@ -12,12 +12,12 @@ import static org.testng.Assert.assertTrue; -import com.google.common.base.Splitter; import com.google.inject.Inject; import java.net.URL; import java.nio.file.Paths; -import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.che.commons.lang.NameGenerator; import org.eclipse.che.selenium.core.client.TestCommandServiceClient; import org.eclipse.che.selenium.core.client.TestProjectServiceClient; @@ -107,9 +107,6 @@ public void prepare() throws Exception { @AfterMethod public void shutDownTomCatAndCleanWebApp() throws Exception { debugPanel.stopDebuggerWithUiAndCleanUpTomcat(CLEAN_TOMCAT_COMMAND_NAME); - testCommandServiceClient.deleteCommand(START_DEBUG_COMMAND_NAME, ws.getId()); - testCommandServiceClient.deleteCommand(CLEAN_TOMCAT_COMMAND_NAME, ws.getId()); - testCommandServiceClient.deleteCommand(BUILD_COMMAND_NAME, ws.getId()); } @Test @@ -137,13 +134,14 @@ public void changeVariableTest() throws Exception { editor.waitBreakPointWithActiveState(34); CompletableFuture instToRequestThread = debuggerUtils.gotoDebugAppAndSendRequest(appUrl, requestMess); + debugPanel.openDebugPanel(); debugPanel.waitDebugHighlightedText("result = \"Sorry, you failed. Try again later!\";"); debugPanel.waitVariablesPanel(); - debugPanel.selectVarInVariablePanel("numGuessByUser: \"11\""); + debugPanel.selectVarInVariablePanel("numGuessByUser=\"11\""); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.CHANGE_VARIABLE); String secretNum = getValueOfSecretNumFromVarWidget().trim(); debugPanel.typeAndChangeVariable(secretNum); - debugPanel.selectVarInVariablePanel(String.format("numGuessByUser: %s", secretNum)); + debugPanel.selectVarInVariablePanel(String.format("numGuessByUser=%s", secretNum)); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.EVALUATE_EXPRESSIONS); debugPanel.typeEvaluateExpression("numGuessByUser.length()"); debugPanel.clickEvaluateBtn(); @@ -168,8 +166,8 @@ private void buildProjectAndOpenMainClass() { } private String getValueOfSecretNumFromVarWidget() { - Map values = - Splitter.on("\n").withKeyValueSeparator(":").split(debugPanel.getTextFromVariablePanel()); - return values.get("secretNum"); + Pattern compile = Pattern.compile("secretNum=(.*)\n"); + Matcher matcher = compile.matcher(debugPanel.getTextFromVariablePanel()); + return matcher.find() ? matcher.group(1) : null; } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java index 2cf09db09a6..15cea069f19 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java @@ -66,12 +66,10 @@ public void setUp() throws Exception { @Test public void checkStateAfterDeletionFileAndFolder() throws Exception { String expectedBreakpointsForAdditionalClass = - "AdditonalClass.java - [line: 7]\n" + "AdditonalClass.java - [line: 9]"; + "AdditonalClass.java:7\n" + "AdditonalClass.java:9"; String expectedBreakpointsForGreetingClass = - "AppController.java - [line: 29]\n" - + "AppController.java - [line: 30]\n" - + "AppController.java - [line: 31]"; + "AppController.java:29\n" + "AppController.java:30\n" + "AppController.java:31"; projectExplorer.waitItem(PROJECT_NAME_2); projectExplorer.quickExpandWithJavaScript(); @@ -79,6 +77,7 @@ public void checkStateAfterDeletionFileAndFolder() throws Exception { editor.waitActiveEditor(); editor.setBreakPointAndWaitInactiveState(7); editor.setBreakPointAndWaitInactiveState(9); + debugPanel.openDebugPanel(); debugPanel.waitContentInBreakPointPanel(expectedBreakpointsForAdditionalClass); projectExplorer.selectItem(PATH_TO_PROJECT_WITH_TWO_CLASSES + "AdditonalClass.java"); menu.runCommand(TestMenuCommandsConstants.Edit.EDIT, TestMenuCommandsConstants.Edit.DELETE); @@ -91,6 +90,7 @@ public void checkStateAfterDeletionFileAndFolder() throws Exception { editor.setBreakPointAndWaitInactiveState(29); editor.setBreakPointAndWaitInactiveState(30); editor.setBreakPointAndWaitInactiveState(31); + debugPanel.openDebugPanel(); debugPanel.waitContentInBreakPointPanel(expectedBreakpointsForGreetingClass); projectExplorer.selectItem(PROJECT_NAME_2 + "/src/main/java"); menu.runCommand(TestMenuCommandsConstants.Edit.EDIT, TestMenuCommandsConstants.Edit.DELETE); @@ -105,14 +105,13 @@ public void checkStateAfterDeletionFileAndFolder() throws Exception { @Test(priority = 1) public void checkStateAfterDeletionProject() { String expectedBreakpointsForGreetingClass = - "AppController.java - [line: 29]\n" - + "AppController.java - [line: 31]\n" - + "AppController.java - [line: 34]"; + "AppController.java:29\n" + "AppController.java:31\n" + "AppController.java:34"; projectExplorer.openItemByPath(PATH_TO_PROJECT_WITH_ONE_CLASS + "AppController.java"); editor.setCursorToLine(35); editor.setBreakPointAndWaitInactiveState(29); editor.setBreakPointAndWaitInactiveState(31); editor.setBreakPointAndWaitInactiveState(34); + debugPanel.openDebugPanel(); debugPanel.waitContentInBreakPointPanel(expectedBreakpointsForGreetingClass); projectExplorer.selectItem(PROJECT_NAME); menu.runCommand(TestMenuCommandsConstants.Edit.EDIT, TestMenuCommandsConstants.Edit.DELETE); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java index 1e188bd34c0..f8508a4f418 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java @@ -137,7 +137,7 @@ public void shouldDebugJreClass() { debugPanel.waitDebugHighlightedText( " "); // we can't rely on concrete code of external library which can be changed in future debugPanel.waitTextInVariablesPanel( - ": \"Info from java logger\""); // there should be at least parameter with value "Info from java logger" + "=\"Info from java logger\""); // there should be at least parameter with value "Info from java logger" // when debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); @@ -167,7 +167,7 @@ public void shouldDebugMavenArtifactClassWithSources() { debugPanel.waitDebugHighlightedText( "filterAndLog_1(FQCN, null, Level.INFO, format, arg, null);"); debugPanel.waitTextInVariablesPanel( - ": \"Info from {}\""); // there should be at least parameter with value "Info from {}" + "=\"Info from {}\""); // there should be at least parameter with value "Info from {}" // when debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OVER); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java index 80d02b77cde..53ff146b7f1 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java @@ -121,48 +121,48 @@ public void stopDebug() { public void shouldDebugAnonymousClass() { // when editor.setCursorToLine(37); - editor.setBreakPointAndWaitActiveState(37); + editor.setBreakpoint(37); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then editor.waitBreakPointWithActiveState(37); - debugPanel.waitTextInVariablesPanel("anonym: \"App anonym\""); + debugPanel.waitTextInVariablesPanel("anonym=\"App anonym\""); } @Test(priority = 1) public void shouldDebugMethodLocalInnerClass() { // when editor.setCursorToLine(53); - editor.setBreakPointAndWaitActiveState(53); + editor.setBreakpoint(53); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then editor.waitBreakPointWithActiveState(53); - debugPanel.waitTextInVariablesPanel("methodValue: \"App method local inner test\""); + debugPanel.waitTextInVariablesPanel("methodValue=\"App method local inner test\""); } @Test(priority = 2) public void shouldDebugInnerClass() { // when editor.setCursorToLine(64); - editor.setBreakPointAndWaitActiveState(64); + editor.setBreakpoint(64); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then editor.waitBreakPointWithActiveState(64); - debugPanel.waitTextInVariablesPanel("innerValue: \"App inner value\""); + debugPanel.waitTextInVariablesPanel("innerValue=\"App inner value\""); } @Test(priority = 3) public void shouldDebugStaticInnerClass() { // when editor.setCursorToLine(72); - editor.setBreakPointAndWaitActiveState(72); + editor.setBreakpoint(72); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then editor.waitBreakPointWithActiveState(72); - debugPanel.waitTextInVariablesPanel("staticInnerValue: \"App static inner value\""); + debugPanel.waitTextInVariablesPanel("staticInnerValue=\"App static inner value\""); } @Test(priority = 4) @@ -175,20 +175,20 @@ public void shouldDebugLambdaExpressions() { // then editor.waitBreakPointWithActiveState(79); - debugPanel.waitTextInVariablesPanel("j: 1"); + debugPanel.waitTextInVariablesPanel("j=1"); // when debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then editor.waitBreakPointWithActiveState(79); - debugPanel.waitTextInVariablesPanel("j: 2"); + debugPanel.waitTextInVariablesPanel("j=2"); // when debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then editor.waitBreakPointWithActiveState(87); - debugPanel.waitTextInVariablesPanel("j: 2"); + debugPanel.waitTextInVariablesPanel("j=2"); } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java index bf6b6d2c288..47b20f5afdf 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java @@ -127,10 +127,19 @@ public void shouldGoIntoConstructor() { debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); // then + try { + editor.waitTabFileWithSavedStatus("ClassLoader"); + debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OUT); + debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OUT); + debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); + } catch (Exception e) { + } + editor.waitTabFileWithSavedStatus("BookImpl"); + debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OVER); debugPanel.waitDebugHighlightedText("this.title = title;"); - - debugPanel.waitTextInVariablesPanel("title: \"java\"\n" + "author: \"oracle\""); + debugPanel.waitTextInVariablesPanel("title=\"java\""); + debugPanel.waitTextInVariablesPanel("author=\"oracle\""); } @Test @@ -146,7 +155,8 @@ public void shouldStopInsideConstructor() { // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); editor.waitBreakPointWithActiveState(18); - debugPanel.waitTextInVariablesPanel("title: \"java\"\n" + "author: \"oracle\""); + debugPanel.waitTextInVariablesPanel("title=\"java\""); + debugPanel.waitTextInVariablesPanel("author=\"oracle\""); } @Test @@ -162,7 +172,8 @@ public void shouldDebugInstanceMethod() { // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); editor.waitBreakPointWithActiveState(23); - debugPanel.waitTextInVariablesPanel("author: \"google\"\n" + "title: \"go\""); + debugPanel.waitTextInVariablesPanel("author=\"google\""); + debugPanel.waitTextInVariablesPanel("title=\"go\""); } @Test @@ -179,7 +190,8 @@ public void shouldDebugStaticMethod() { // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); editor.waitBreakPointWithActiveState(41); - debugPanel.waitTextInVariablesPanel("author: \"google\"\n" + "title: \"go\""); + debugPanel.waitTextInVariablesPanel("author=\"google\""); + debugPanel.waitTextInVariablesPanel("title=\"go\""); } @Test @@ -194,7 +206,7 @@ public void shouldDebugDefaultMethod() { // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); editor.waitBreakPointWithActiveState(30); - debugPanel.waitTextInVariablesPanel("o: instance of multimodule.model.BookImpl"); + debugPanel.waitTextInVariablesPanel("o=instance of multimodule.model.BookImpl"); } @Test @@ -210,7 +222,7 @@ public void shouldDebugStaticDefaultMethod() { // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); editor.waitBreakPointWithActiveState(43); - debugPanel.waitTextInVariablesPanel("book: instance of multimodule.model.BookImpl"); + debugPanel.waitTextInVariablesPanel("book=instance of multimodule.model.BookImpl"); } private String getXpathForDebugConfigurationMenuItem() { diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/NodeJsDebugTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/NodeJsDebugTest.java index 59045f80f0d..c5ce4bce43a 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/NodeJsDebugTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/NodeJsDebugTest.java @@ -91,7 +91,7 @@ public void debugNodeJsTest() new WebDriverWait(ide.driver(), REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( ExpectedConditions.invisibilityOfElementLocated( - By.xpath("//div[text()='{" + PROJECT_NAME + "/app.js:13} ']"))); + By.xpath("//div[text()='{/app.js:13} ']"))); debugPanel.waitBreakPointsPanelIsEmpty(); } @@ -122,7 +122,7 @@ private void checkDebugStepsFeatures() { new WebDriverWait(ide.driver(), REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until( ExpectedConditions.visibilityOfElementLocated( - By.xpath("//div[text()='{" + PROJECT_NAME + "/app.js:13} ']"))); + By.xpath("//div[text()='{app.js:13} ']"))); debugPanel.clickOnButton(DebuggerButtonsPanel.STEP_OVER); } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java index 567c12de8c8..0dc13b1f93c 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java @@ -137,13 +137,13 @@ public void changeVariableTest() throws Exception { debugPanel.waitDebugHighlightedText(" someStr.toLowerCase();"); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OVER); debugPanel.waitDebugHighlightedText("Operation.valueOf(\"SUBTRACT\").toString();"); - debugPanel.waitTextInVariablesPanel("someStr: \"hello Cdenvy\""); + debugPanel.waitTextInVariablesPanel("someStr=\"hello Cdenvy\""); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OUT); - debugPanel.waitTextInVariablesPanel("secretNum:"); - debugPanel.selectVarInVariablePanel("numGuessByUser: \"6\""); + debugPanel.waitTextInVariablesPanel("secretNum="); + debugPanel.selectVarInVariablePanel("numGuessByUser=\"6\""); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.CHANGE_VARIABLE); debugPanel.typeAndChangeVariable("\"7\""); - debugPanel.waitTextInVariablesPanel("numGuessByUser: \"7\""); + debugPanel.waitTextInVariablesPanel("numGuessByUser=\"7\""); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); assertTrue(instToRequestThread.get().contains("")); } diff --git a/selenium/che-selenium-test/src/test/resources/projects/plugins/DebuggerPlugin/java-inner-lambda/src/main/java/test/App.java b/selenium/che-selenium-test/src/test/resources/projects/plugins/DebuggerPlugin/java-inner-lambda/src/main/java/test/App.java index 321d6761d9a..a25447c9321 100644 --- a/selenium/che-selenium-test/src/test/resources/projects/plugins/DebuggerPlugin/java-inner-lambda/src/main/java/test/App.java +++ b/selenium/che-selenium-test/src/test/resources/projects/plugins/DebuggerPlugin/java-inner-lambda/src/main/java/test/App.java @@ -39,7 +39,7 @@ String getAnonymValue() { }; System.out.println(anonym.getAppValue()); - + System.out.println(new App().getAppValue()); System.out.println(anonym.new Inner().getInnerValue()); System.out.println(new StaticInner().getStaticInnerValue()); diff --git a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java index 2562f34cdc2..ea80cf2e993 100644 --- a/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java +++ b/wsagent/che-core-api-debug-shared/src/main/java/org/eclipse/che/api/debug/shared/model/impl/LocationImpl.java @@ -42,6 +42,10 @@ public LocationImpl( this.threadId = threadId; } + public LocationImpl(String target, int lineNumber, String resourceProjectPath) { + this(target, lineNumber, false, 0, resourceProjectPath, null, -1); + } + public LocationImpl(String target, int lineNumber) { this(target, lineNumber, false, 0, null, null, -1); } diff --git a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java index 53cffb77277..2c1b8c96011 100644 --- a/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java +++ b/wsagent/che-core-api-debug/src/main/java/org/eclipse/che/api/debugger/server/DebuggerService.java @@ -163,12 +163,13 @@ public List getBreakpoints(@PathParam("id") String sessionId) public void deleteBreakpoint( @PathParam("id") String sessionId, @QueryParam("target") String target, - @QueryParam("line") @DefaultValue("0") int lineNumber) + @QueryParam("line") @DefaultValue("0") int lineNumber, + @QueryParam("project") String project) throws DebuggerException { if (target == null) { debuggerManager.getDebugger(sessionId).deleteAllBreakpoints(); } else { - Location location = new LocationImpl(target, lineNumber); + Location location = new LocationImpl(target, lineNumber, project); debuggerManager.getDebugger(sessionId).deleteBreakpoint(location); } } diff --git a/wsagent/che-core-api-languageserver-shared/pom.xml b/wsagent/che-core-api-languageserver-shared/pom.xml index 0660cc32731..c24ec63fbdb 100644 --- a/wsagent/che-core-api-languageserver-shared/pom.xml +++ b/wsagent/che-core-api-languageserver-shared/pom.xml @@ -28,7 +28,7 @@ org.eclipse.lsp4j org.eclipse.lsp4j - + junit junit From aa30693ac2d111bb7e5bc397ab49cbefb403fce5 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Tue, 12 Sep 2017 11:38:44 +0300 Subject: [PATCH 36/38] Add selenium test --- dashboard/pom.xml | 4 +- .../debugger/ide/debug/DebuggerPresenter.java | 2 +- .../selenium/pageobject/CodenvyEditor.java | 6 +- .../eclipse/che/selenium/pageobject/Menu.java | 1 - .../selenium/pageobject/debug/DebugPanel.java | 67 +++++++- .../ChangeVariableWithEvaluatingTest.java | 6 +- .../debugger/CheckBreakPointStateTest.java | 16 +- .../debugger/CppProjectDebuggingTest.java | 2 +- .../debugger/DebugExternalClassTest.java | 12 +- .../InnerClassAndLambdaDebuggingTest.java | 18 +-- .../MultimoduleProjectDebuggingTest.java | 24 +-- ...pOverStepReturnWithChangeVariableTest.java | 10 +- .../che/selenium/debugger/ThreadDumpTest.java | 148 ++++++++++++++++++ .../src/test/resources/suites/CheSuite.xml | 1 + 14 files changed, 265 insertions(+), 52 deletions(-) create mode 100644 selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ThreadDumpTest.java diff --git a/dashboard/pom.xml b/dashboard/pom.xml index e1acea90226..7740d898890 100644 --- a/dashboard/pom.xml +++ b/dashboard/pom.xml @@ -221,8 +221,8 @@ - - + + diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java index 897321c437d..c264fa5190a 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerPresenter.java @@ -163,7 +163,7 @@ public void onExpandVariablesTree(MutableVariable variable) { @Override public void onSelectedThread(long threadId) { updateStackFrameDump(threadId); - updateVariables(threadId, 0); + onSelectedFrame(0); } @Override diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java index 59705a9c9e6..2fb59c38c27 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/CodenvyEditor.java @@ -1016,7 +1016,7 @@ public void waitBreakPointWithInactiveState(int position) { * * @param position position of the breakpoint */ - public void setBreakPointAndWaitInactiveState(int position) { + public void setInactiveBreakpoint(int position) { waitActiveEditor(); waitDebugerLineIsVisible(position); seleniumWebDriver @@ -1037,7 +1037,7 @@ public void setBreakPointAndWaitActiveState(int position) { seleniumWebDriver .findElement(By.xpath(String.format(Locators.DEBUGGER_PREFIX_XPATH, position))) .click(); - waitBreakPointWithActiveState(position); + waitAcitveBreakpoint(position); } public void setBreakpoint(int position) { @@ -1053,7 +1053,7 @@ public void setBreakpoint(int position) { * * @param position the position in the codenvy - editor */ - public void waitBreakPointWithActiveState(int position) { + public void waitAcitveBreakpoint(int position) { redrawDriverWait.until( visibilityOfElementLocated( By.xpath(String.format(Locators.DEBUGGER_BREAK_POINT_ACTIVE, position)))); diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Menu.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Menu.java index 18382e5d6c1..4fcfbff3d9a 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Menu.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/Menu.java @@ -159,7 +159,6 @@ public void runCommand(String idTopMenuCommand, String idCommandName, String idS new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) .until(ExpectedConditions.visibilityOfElementLocated(By.id(idSubCommandName))); } catch (TimeoutException e) { - LOG.error(e.getLocalizedMessage(), e); WaitUtils.sleepQuietly(1); seleniumWebDriver.findElement(By.id(idCommandName)).click(); new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java index 7bde6e387f7..836d22874f2 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/debug/DebugPanel.java @@ -14,6 +14,7 @@ import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.MINIMUM_SEC; import static org.eclipse.che.selenium.core.constant.TestTimeoutsConstants.REDRAW_UI_ELEMENTS_TIMEOUT_SEC; +import com.google.common.base.Function; import com.google.inject.Inject; import com.google.inject.Singleton; import java.util.List; @@ -61,6 +62,8 @@ public DebugPanel( private interface Locators { String DEBUGGER_BREAKPOINTS_PANEL_ID = "gwt-debug-debugger-breakpointsPanel"; String DEBUGGER_PANEL_TAB = "gwt-debug-partButton-Debug"; + String FRAMES_LIST_ID = "gwt-debug-debugger-frames-list"; + String THREADS_LIST_ID = "gwt-debug-debugger-threads-list"; String VARIABLES_PANEL_ID = "gwt-debug-debugger-variablesPanel"; String VARIABLE_PANEL_SELECT_VAL = "//div[@id='gwt-debug-debugger-variablesPanel']//span[text()='%s']"; @@ -102,6 +105,12 @@ public interface DebuggerButtonsPanel { @FindBy(xpath = LocatorsChangeVariable.CANCEL_BTN) WebElement cancelVariableBtn; + @FindBy(id = Locators.FRAMES_LIST_ID) + WebElement frames; + + @FindBy(id = Locators.THREADS_LIST_ID) + WebElement threads; + /** Wait while debugger panel will be clear for all breakpoints */ public void waitWhileAllBreakPointsOnEditorPanelDisapper() { new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) @@ -381,8 +390,64 @@ public void stopDebuggerWithUiAndCleanUpTomcat(String cleanUpTomcat) { } } - public String getTextFromVariablePanel() { + public String getVariables() { waitVariablesPanel(); return variablesPanel.getText(); } + + public void waitFramesListPanelReady() { + new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until((Function) webDriver -> !frames.getText().isEmpty()); + } + + public String[] getFrames() { + waitFramesListPanelReady(); + return frames.getText().split("\n"); + } + + /** Waits */ + public void waitThreadListPanelReady() { + new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until((Function) webDriver -> !threads.getText().isEmpty()); + } + + public void selectFrame(int frameIndex) { + waitFramesListPanelReady(); + + new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until( + ExpectedConditions.visibilityOfElementLocated( + By.xpath("//td[text()='" + getFrames()[frameIndex] + "']"))) + .click(); + } + + public String[] getThreads() { + waitThreadListPanelReady(); + return threads.getText().split("\n"); + } + + public String getSelectedThread() { + waitThreadListPanelReady(); + + String selectedThreadId = threads.getAttribute("value"); + for (String thread : getThreads()) { + if (thread.contains("@" + selectedThreadId + " in")) { + return thread; + } + } + + return null; + } + + public void selectThread(String threadName) { + waitThreadListPanelReady(); + + threads.click(); + new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC) + .until( + ExpectedConditions.visibilityOfElementLocated( + By.xpath("//*[contains(text(),'\"" + threadName + "\"@')]"))) + .click(); + threads.click(); + } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java index 2be629bfa54..068bd8ccd38 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ChangeVariableWithEvaluatingTest.java @@ -116,7 +116,7 @@ public void changeVariableTest() throws Exception { commandsPalette.startCommandByDoubleClick(START_DEBUG_COMMAND_NAME); consoles.waitExpectedTextIntoConsole(" Server startup in"); editor.setCursorToLine(34); - editor.setBreakPointAndWaitInactiveState(34); + editor.setInactiveBreakpoint(34); menu.runCommand( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.EDIT_DEBUG_CONFIGURATION); @@ -131,7 +131,7 @@ public void changeVariableTest() throws Exception { + workspaceServiceClient.getServerAddressByPort(ws.getId(), 8080) + "/spring/guess"; String requestMess = "11"; - editor.waitBreakPointWithActiveState(34); + editor.waitAcitveBreakpoint(34); CompletableFuture instToRequestThread = debuggerUtils.gotoDebugAppAndSendRequest(appUrl, requestMess); debugPanel.openDebugPanel(); @@ -167,7 +167,7 @@ private void buildProjectAndOpenMainClass() { private String getValueOfSecretNumFromVarWidget() { Pattern compile = Pattern.compile("secretNum=(.*)\n"); - Matcher matcher = compile.matcher(debugPanel.getTextFromVariablePanel()); + Matcher matcher = compile.matcher(debugPanel.getVariables()); return matcher.find() ? matcher.group(1) : null; } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java index 15cea069f19..ba933816ba4 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CheckBreakPointStateTest.java @@ -75,8 +75,8 @@ public void checkStateAfterDeletionFileAndFolder() throws Exception { projectExplorer.quickExpandWithJavaScript(); projectExplorer.openItemByPath(PATH_TO_PROJECT_WITH_TWO_CLASSES + "AdditonalClass.java"); editor.waitActiveEditor(); - editor.setBreakPointAndWaitInactiveState(7); - editor.setBreakPointAndWaitInactiveState(9); + editor.setInactiveBreakpoint(7); + editor.setInactiveBreakpoint(9); debugPanel.openDebugPanel(); debugPanel.waitContentInBreakPointPanel(expectedBreakpointsForAdditionalClass); projectExplorer.selectItem(PATH_TO_PROJECT_WITH_TWO_CLASSES + "AdditonalClass.java"); @@ -87,9 +87,9 @@ public void checkStateAfterDeletionFileAndFolder() throws Exception { PATH_TO_PROJECT_WITH_TWO_CLASSES + "AdditonalClass.java"); debugPanel.waitBreakPointsPanelIsEmpty(); projectExplorer.openItemByPath(PATH_TO_PROJECT_WITH_TWO_CLASSES + "AppController.java"); - editor.setBreakPointAndWaitInactiveState(29); - editor.setBreakPointAndWaitInactiveState(30); - editor.setBreakPointAndWaitInactiveState(31); + editor.setInactiveBreakpoint(29); + editor.setInactiveBreakpoint(30); + editor.setInactiveBreakpoint(31); debugPanel.openDebugPanel(); debugPanel.waitContentInBreakPointPanel(expectedBreakpointsForGreetingClass); projectExplorer.selectItem(PROJECT_NAME_2 + "/src/main/java"); @@ -108,9 +108,9 @@ public void checkStateAfterDeletionProject() { "AppController.java:29\n" + "AppController.java:31\n" + "AppController.java:34"; projectExplorer.openItemByPath(PATH_TO_PROJECT_WITH_ONE_CLASS + "AppController.java"); editor.setCursorToLine(35); - editor.setBreakPointAndWaitInactiveState(29); - editor.setBreakPointAndWaitInactiveState(31); - editor.setBreakPointAndWaitInactiveState(34); + editor.setInactiveBreakpoint(29); + editor.setInactiveBreakpoint(31); + editor.setInactiveBreakpoint(34); debugPanel.openDebugPanel(); debugPanel.waitContentInBreakPointPanel(expectedBreakpointsForGreetingClass); projectExplorer.selectItem(PROJECT_NAME); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java index 753bf9fd552..2934024451a 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java @@ -103,7 +103,7 @@ public void removeConfig() { public void shouldDebugCppProject() { // when projectExplorer.openItemByPath(PATH_TO_PROGRAM); - editor.setBreakPointAndWaitInactiveState(22); + editor.setInactiveBreakpoint(22); editor.closeAllTabs(); commandsPalette.openCommandPalette(); commandsPalette.startCommandByDoubleClick(MAKE_AND_DEBUG_COMMAND_NAME); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java index f8508a4f418..2f0eee86004 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/DebugExternalClassTest.java @@ -122,14 +122,14 @@ public void stopDebug() { @Test public void shouldDebugJreClass() { // when - editor.setBreakPointAndWaitInactiveState(19); + editor.setInactiveBreakpoint(19); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, debugConfig.getXpathToІRunDebugCommand(PROJECT)); notifications.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(19); + editor.waitAcitveBreakpoint(19); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); // then @@ -149,14 +149,14 @@ public void shouldDebugJreClass() { @Test(priority = 1) public void shouldDebugMavenArtifactClassWithSources() { // when - editor.setBreakPointAndWaitInactiveState(23); + editor.setInactiveBreakpoint(23); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, debugConfig.getXpathToІRunDebugCommand(PROJECT)); notifications.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(23); + editor.waitAcitveBreakpoint(23); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); // then @@ -188,14 +188,14 @@ public void shouldDebugMavenArtifactClassWithSources() { @Test(priority = 2) public void shouldHandleDebugOfMavenArtifactWithoutSources() { // when - editor.setBreakPointAndWaitInactiveState(27); + editor.setInactiveBreakpoint(27); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, debugConfig.getXpathToІRunDebugCommand(PROJECT)); notifications.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(27); + editor.waitAcitveBreakpoint(27); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); // then diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java index 53ff146b7f1..3aeb46cb5d6 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java @@ -99,7 +99,7 @@ public void startDebug() { // set breakpoints editor.waitActiveEditor(); editor.setCursorToLine(41); - editor.setBreakPointAndWaitInactiveState(41); + editor.setInactiveBreakpoint(41); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, @@ -107,7 +107,7 @@ public void startDebug() { "//*[@id=\"%1$s/%2$s\" or @id=\"topmenu/Run/Debug/Debug '%2$s'\"]", TestMenuCommandsConstants.Run.DEBUG, PROJECT)); notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(41); + editor.waitAcitveBreakpoint(41); } @AfterMethod @@ -125,7 +125,7 @@ public void shouldDebugAnonymousClass() { debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(37); + editor.waitAcitveBreakpoint(37); debugPanel.waitTextInVariablesPanel("anonym=\"App anonym\""); } @@ -137,7 +137,7 @@ public void shouldDebugMethodLocalInnerClass() { debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(53); + editor.waitAcitveBreakpoint(53); debugPanel.waitTextInVariablesPanel("methodValue=\"App method local inner test\""); } @@ -149,7 +149,7 @@ public void shouldDebugInnerClass() { debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(64); + editor.waitAcitveBreakpoint(64); debugPanel.waitTextInVariablesPanel("innerValue=\"App inner value\""); } @@ -161,7 +161,7 @@ public void shouldDebugStaticInnerClass() { debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(72); + editor.waitAcitveBreakpoint(72); debugPanel.waitTextInVariablesPanel("staticInnerValue=\"App static inner value\""); } @@ -174,21 +174,21 @@ public void shouldDebugLambdaExpressions() { debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(79); + editor.waitAcitveBreakpoint(79); debugPanel.waitTextInVariablesPanel("j=1"); // when debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(79); + editor.waitAcitveBreakpoint(79); debugPanel.waitTextInVariablesPanel("j=2"); // when debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); // then - editor.waitBreakPointWithActiveState(87); + editor.waitAcitveBreakpoint(87); debugPanel.waitTextInVariablesPanel("j=2"); } } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java index 47b20f5afdf..db5f0f87251 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/MultimoduleProjectDebuggingTest.java @@ -117,13 +117,13 @@ public void stopDebug() { public void shouldGoIntoConstructor() { // when projectExplorer.openItemByPath(PATH_TO_APP_CLASS); - editor.setBreakPointAndWaitInactiveState(19); + editor.setInactiveBreakpoint(19); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, getXpathForDebugConfigurationMenuItem()); notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(19); + editor.waitAcitveBreakpoint(19); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); // then @@ -146,7 +146,7 @@ public void shouldGoIntoConstructor() { public void shouldStopInsideConstructor() { // when projectExplorer.openItemByPath(PATH_TO_BOOK_IMPL_CLASS); - editor.setBreakPointAndWaitInactiveState(18); + editor.setInactiveBreakpoint(18); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, @@ -154,7 +154,7 @@ public void shouldStopInsideConstructor() { getXpathForDebugConfigurationMenuItem()); // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(18); + editor.waitAcitveBreakpoint(18); debugPanel.waitTextInVariablesPanel("title=\"java\""); debugPanel.waitTextInVariablesPanel("author=\"oracle\""); } @@ -163,7 +163,7 @@ public void shouldStopInsideConstructor() { public void shouldDebugInstanceMethod() { // when projectExplorer.openItemByPath(PATH_TO_BOOK_IMPL_CLASS); - editor.setBreakPointAndWaitInactiveState(23); + editor.setInactiveBreakpoint(23); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, @@ -171,7 +171,7 @@ public void shouldDebugInstanceMethod() { getXpathForDebugConfigurationMenuItem()); // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(23); + editor.waitAcitveBreakpoint(23); debugPanel.waitTextInVariablesPanel("author=\"google\""); debugPanel.waitTextInVariablesPanel("title=\"go\""); } @@ -181,7 +181,7 @@ public void shouldDebugStaticMethod() { // when projectExplorer.openItemByPath(PATH_TO_BOOK_IMPL_CLASS); editor.setCursorToLine(41); - editor.setBreakPointAndWaitInactiveState(41); + editor.setInactiveBreakpoint(41); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, @@ -189,7 +189,7 @@ public void shouldDebugStaticMethod() { getXpathForDebugConfigurationMenuItem()); // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(41); + editor.waitAcitveBreakpoint(41); debugPanel.waitTextInVariablesPanel("author=\"google\""); debugPanel.waitTextInVariablesPanel("title=\"go\""); } @@ -198,14 +198,14 @@ public void shouldDebugStaticMethod() { public void shouldDebugDefaultMethod() { // when projectExplorer.openItemByPath(PATH_TO_BOOK_INTERFACE); - editor.setBreakPointAndWaitInactiveState(30); + editor.setInactiveBreakpoint(30); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, getXpathForDebugConfigurationMenuItem()); // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(30); + editor.waitAcitveBreakpoint(30); debugPanel.waitTextInVariablesPanel("o=instance of multimodule.model.BookImpl"); } @@ -214,14 +214,14 @@ public void shouldDebugStaticDefaultMethod() { // when projectExplorer.openItemByPath(PATH_TO_BOOK_INTERFACE); editor.setCursorToLine(43); - editor.setBreakPointAndWaitInactiveState(43); + editor.setInactiveBreakpoint(43); menu.runCommandByXpath( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, getXpathForDebugConfigurationMenuItem()); // then notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); - editor.waitBreakPointWithActiveState(43); + editor.waitAcitveBreakpoint(43); debugPanel.waitTextInVariablesPanel("book=instance of multimodule.model.BookImpl"); } diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java index 0dc13b1f93c..c87c7b1b0c9 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/StepIntoStepOverStepReturnWithChangeVariableTest.java @@ -111,7 +111,7 @@ public void changeVariableTest() throws Exception { commandsPalette.startCommandByDoubleClick(START_DEBUG); consoles.waitExpectedTextIntoConsole(" Server startup in"); editor.setCursorToLine(34); - editor.setBreakPointAndWaitInactiveState(34); + editor.setInactiveBreakpoint(34); menu.runCommand( TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.EDIT_DEBUG_CONFIGURATION); @@ -120,7 +120,7 @@ public void changeVariableTest() throws Exception { TestMenuCommandsConstants.Run.RUN_MENU, TestMenuCommandsConstants.Run.DEBUG, TestMenuCommandsConstants.Run.DEBUG + "/" + PROJECT); - editor.waitBreakPointWithActiveState(34); + editor.waitAcitveBreakpoint(34); String appUrl = "http" + "://" @@ -129,7 +129,7 @@ public void changeVariableTest() throws Exception { String requestMess = "6"; CompletableFuture instToRequestThread = debugUtils.gotoDebugAppAndSendRequest(appUrl, requestMess); - editor.waitBreakPointWithActiveState(34); + editor.waitAcitveBreakpoint(34); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_OVER); debugPanel.waitDebugHighlightedText("AdditonalClass.check();"); debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.STEP_INTO); @@ -154,12 +154,12 @@ public void shouldOpenDebuggingFile() { commandsPalette.openCommandPalette(); commandsPalette.startCommandByDoubleClick(START_DEBUG); consoles.waitExpectedTextIntoConsole(" Server startup in"); - editor.setBreakPointAndWaitInactiveState(26); + editor.setInactiveBreakpoint(26); seleniumWebDriver .switchTo() .activeElement() .sendKeys(Keys.SHIFT.toString() + Keys.F9.toString()); - editor.waitBreakPointWithActiveState(26); + editor.waitAcitveBreakpoint(26); } private void buildProjectAndOpenMainClass() { diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ThreadDumpTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ThreadDumpTest.java new file mode 100644 index 00000000000..95f89857c80 --- /dev/null +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/ThreadDumpTest.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * 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 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.selenium.debugger; + +import static org.eclipse.che.selenium.core.constant.TestCommandsConstants.MAVEN; +import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.DEBUG; +import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.EDIT_DEBUG_CONFIGURATION; +import static org.eclipse.che.selenium.core.constant.TestMenuCommandsConstants.Run.RUN_MENU; +import static org.eclipse.che.selenium.core.project.ProjectTemplates.CONSOLE_JAVA_SIMPLE; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import com.google.inject.Inject; +import java.nio.file.Paths; +import org.eclipse.che.commons.lang.NameGenerator; +import org.eclipse.che.selenium.core.client.TestCommandServiceClient; +import org.eclipse.che.selenium.core.client.TestProjectServiceClient; +import org.eclipse.che.selenium.core.constant.TestBuildConstants; +import org.eclipse.che.selenium.core.workspace.TestWorkspace; +import org.eclipse.che.selenium.pageobject.CodenvyEditor; +import org.eclipse.che.selenium.pageobject.Consoles; +import org.eclipse.che.selenium.pageobject.Ide; +import org.eclipse.che.selenium.pageobject.Loader; +import org.eclipse.che.selenium.pageobject.Menu; +import org.eclipse.che.selenium.pageobject.NotificationsPopupPanel; +import org.eclipse.che.selenium.pageobject.ProjectExplorer; +import org.eclipse.che.selenium.pageobject.debug.DebugPanel; +import org.eclipse.che.selenium.pageobject.debug.JavaDebugConfig; +import org.eclipse.che.selenium.pageobject.intelligent.CommandsPalette; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** @author Anatolii Bazko */ +public class ThreadDumpTest { + private static final String PROJECT = NameGenerator.generate("project", 2); + private static final String DEBUG_COMMAND = "debug"; + + @Inject private TestWorkspace ws; + @Inject private Ide ide; + + @Inject private ProjectExplorer projectExplorer; + @Inject private Loader loader; + @Inject private DebugPanel debugPanel; + @Inject private JavaDebugConfig debugConfig; + @Inject private NotificationsPopupPanel notificationPopup; + @Inject private Menu menu; + @Inject private CodenvyEditor editor; + @Inject private Consoles consoles; + @Inject private TestCommandServiceClient testCommandServiceClient; + @Inject private TestProjectServiceClient testProjectServiceClient; + @Inject private CommandsPalette commandsPalette; + + @BeforeClass + public void setUp() throws Exception { + testProjectServiceClient.importProject( + ws.getId(), + Paths.get( + getClass().getResource("/projects/plugins/DebuggerPlugin/java-multimodule").toURI()), + PROJECT, + CONSOLE_JAVA_SIMPLE); + + testCommandServiceClient.createCommand( + "mvn -f ${current.project.path} clean install &&" + + " java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" + + " -classpath ${current.project.path}/app/target/classes/:${current.project.path}/model/target/classes multimodule.App", + DEBUG_COMMAND, + MAVEN, + ws.getId()); + + // open IDE + ide.open(ws); + loader.waitOnClosed(); + projectExplorer.waitItem(PROJECT); + notificationPopup.waitProgressPopupPanelClose(); + + // open project tree + projectExplorer.quickExpandWithJavaScript(); + projectExplorer.waitVisibleItem(PROJECT); + projectExplorer.selectItem(PROJECT); + + startDebuggingApp(); + } + + @Test + public void shouldShowAndNavigateByThreadDump() { + assertTrue(debugPanel.getSelectedThread().contains("\"main\"@")); + + String[] frames = debugPanel.getFrames(); + assertEquals(frames.length, 1); + assertTrue(frames[0].contains("main(String[]):19, App")); + + debugPanel.clickOnButton(DebugPanel.DebuggerButtonsPanel.RESUME_BTN_ID); + debugPanel.waitDebugHighlightedText("this.title = title;"); + + frames = debugPanel.getFrames(); + assertEquals(frames.length, 2); + assertTrue(frames[0].contains("(String, String):18, BookImpl")); + assertTrue(frames[1].contains("main(String[]):19, App")); + + editor.closeAllTabs(); + + debugPanel.selectFrame(0); + editor.waitActiveTabFileName("BookImpl"); + assertTrue(debugPanel.getVariables().contains("title=\"java\"")); + + debugPanel.selectFrame(1); + editor.waitActiveTabFileName("App"); + assertTrue(debugPanel.getVariables().contains("args=instance of java.lang.String[0]")); + + debugPanel.selectThread("Finalizer"); + editor.waitActiveTabFileName("Object"); + assertTrue(debugPanel.getVariables().isEmpty()); + + debugPanel.selectThread("main"); + editor.waitActiveTabFileName("BookImpl"); + assertTrue(debugPanel.getVariables().contains("title=\"java\"")); + } + + private void startDebuggingApp() { + menu.runCommand(RUN_MENU, EDIT_DEBUG_CONFIGURATION); + debugConfig.createConfig(PROJECT); + + // starts application in debug mode + commandsPalette.openCommandPalette(); + commandsPalette.startCommandByDoubleClick(DEBUG_COMMAND); + consoles.waitExpectedTextIntoConsole(TestBuildConstants.LISTENING_AT_ADDRESS_8000); + + // stops at breakpoint + projectExplorer.openItemByPath(PROJECT + "/app/src/main/java/multimodule/App.java"); + editor.setInactiveBreakpoint(19); + + projectExplorer.openItemByPath( + PROJECT + "/model/src/main/java/multimodule/model/BookImpl.java"); + editor.setInactiveBreakpoint(18); + + menu.runCommand(RUN_MENU, DEBUG, DEBUG + "/" + PROJECT); + notificationPopup.waitExpectedMessageOnProgressPanelAndClosed("Remote debugger connected"); + editor.waitAcitveBreakpoint(19); + } +} diff --git a/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml b/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml index a9236de596d..1bb9f19af77 100644 --- a/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml +++ b/selenium/che-selenium-test/src/test/resources/suites/CheSuite.xml @@ -138,6 +138,7 @@ + From 89c264eae56977b6b6a11940dc2e854460b79ac2 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 13 Sep 2017 10:55:39 +0300 Subject: [PATCH 37/38] Fix up --- .../debugger/ide/debug/AbstractDebugger.java | 60 ++++++---- .../ide/debug/DebuggerResourceHandler.java | 10 ++ .../debug/DefaultDebuggerResourceHandler.java | 110 ++++++++++-------- .../debug/JavaDebuggerResourceHandler.java | 20 ++-- 4 files changed, 116 insertions(+), 84 deletions(-) diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java index b98d474648c..35051a4ee61 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/AbstractDebugger.java @@ -170,7 +170,27 @@ public void onWsAgentStarted(WsAgentStateEvent event) { } if (currentLocation != null) { - open(currentLocation); + debuggerResourceHandlerFactory + .getOrDefault(getDebuggerType()) + .find( + currentLocation, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + for (DebuggerObserver observer : observers) { + observer.onBreakpointStopped( + currentLocation.getTarget(), currentLocation); + } + } + + @Override + public void onSuccess(VirtualFile result) { + for (DebuggerObserver observer : observers) { + observer.onBreakpointStopped( + result.getLocation().toString(), currentLocation); + } + } + }); } startCheckingEvents(); @@ -210,31 +230,25 @@ private void onEventListReceived(@NotNull DebuggerEventDto event) { } private void open(Location location) { - try { - debuggerResourceHandlerFactory - .getOrDefault(getDebuggerType()) - .open( - location, - new AsyncCallback() { - @Override - public void onFailure(Throwable caught) { - for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(location.getTarget(), location); - } + debuggerResourceHandlerFactory + .getOrDefault(getDebuggerType()) + .open( + location, + new AsyncCallback() { + @Override + public void onFailure(Throwable caught) { + for (DebuggerObserver observer : observers) { + observer.onBreakpointStopped(location.getTarget(), location); } + } - @Override - public void onSuccess(VirtualFile result) { - for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(result.getLocation().toString(), location); - } + @Override + public void onSuccess(VirtualFile result) { + for (DebuggerObserver observer : observers) { + observer.onBreakpointStopped(result.getLocation().toString(), location); } - }); - } catch (Exception e) { - for (DebuggerObserver observer : observers) { - observer.onBreakpointStopped(location.getTarget(), location); - } - } + } + }); } /** diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java index 67435a9e59f..cddb5d4ed9d 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DebuggerResourceHandler.java @@ -32,4 +32,14 @@ public interface DebuggerResourceHandler { * @param callback the callback */ void open(Location location, AsyncCallback callback); + + /** + * Finds resource denoted by {@code #location}. If resource has been found then {@link + * AsyncCallback#onSuccess(Object)} must be invoked and {@link AsyncCallback#onFailure(Throwable)} + * otherwise. + * + * @param location the location of the resource + * @param callback the callback + */ + void find(Location location, AsyncCallback callback); } diff --git a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java index 64ca766c560..c872f6ecb2e 100644 --- a/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java +++ b/plugins/plugin-debugger/che-plugin-debugger-ide/src/main/java/org/eclipse/che/plugin/debugger/ide/debug/DefaultDebuggerResourceHandler.java @@ -15,19 +15,14 @@ import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.inject.Inject; import com.google.inject.Singleton; -import java.util.List; import org.eclipse.che.api.debug.shared.model.Location; -import org.eclipse.che.api.promises.client.Operation; -import org.eclipse.che.api.promises.client.OperationException; import org.eclipse.che.ide.api.app.AppContext; import org.eclipse.che.ide.api.editor.EditorAgent; import org.eclipse.che.ide.api.editor.EditorPartPresenter; import org.eclipse.che.ide.api.editor.text.TextPosition; import org.eclipse.che.ide.api.editor.texteditor.TextEditor; -import org.eclipse.che.ide.api.resources.File; import org.eclipse.che.ide.api.resources.Project; import org.eclipse.che.ide.api.resources.Resource; -import org.eclipse.che.ide.api.resources.SearchResult; import org.eclipse.che.ide.api.resources.VirtualFile; /** @author Anatoliy Bazko */ @@ -56,33 +51,42 @@ public DefaultDebuggerResourceHandler(EditorAgent editorAgent, AppContext appCon */ @Override public void open(final Location location, final AsyncCallback callback) { - findInOpenedEditors( + find( location, new AsyncCallback() { @Override - public void onSuccess(VirtualFile result) { - callback.onSuccess(result); + public void onFailure(Throwable caught) { + callback.onFailure(caught); } @Override - public void onFailure(Throwable caught) { - findSourceToOpen(location, callback); + public void onSuccess(VirtualFile result) { + openFileAndScrollToLine(result, location.getLineNumber(), callback); } }); } - protected void findSourceToOpen(Location location, AsyncCallback callback) { - findInProject( + @Override + public void find(Location location, AsyncCallback callback) { + try { + doFind(location, callback); + } catch (Exception e) { + callback.onFailure(e); + } + } + + private void doFind(Location location, AsyncCallback callback) { + findInOpenedEditors( location, new AsyncCallback() { @Override - public void onSuccess(VirtualFile virtualFile) { - callback.onSuccess(virtualFile); + public void onSuccess(VirtualFile result) { + callback.onSuccess(result); } @Override public void onFailure(Throwable caught) { - findInWorkspace( + findInProject( location, new AsyncCallback() { @Override @@ -92,17 +96,29 @@ public void onSuccess(VirtualFile virtualFile) { @Override public void onFailure(Throwable caught) { - searchSource( + findInWorkspace( location, new AsyncCallback() { @Override - public void onSuccess(VirtualFile result) { - callback.onSuccess(result); + public void onSuccess(VirtualFile virtualFile) { + callback.onSuccess(virtualFile); } @Override - public void onFailure(Throwable error) { - callback.onFailure(error); + public void onFailure(Throwable caught) { + searchSource( + location, + new AsyncCallback() { + @Override + public void onSuccess(VirtualFile result) { + callback.onSuccess(result); + } + + @Override + public void onFailure(Throwable error) { + callback.onFailure(error); + } + }); } }); } @@ -118,7 +134,7 @@ protected void findInOpenedEditors( String filePath = file.getLocation().toString(); if (filePath.equals(location.getTarget())) { - openFileAndScrollToLine(file, location.getLineNumber(), callback); + callback.onSuccess(file); return; } } @@ -145,7 +161,7 @@ protected void findInProject(final Location location, final AsyncCallback { if (file.isPresent()) { - openFileAndScrollToLine(file.get(), location.getLineNumber(), callback); + callback.onSuccess(file.get()); } else { callback.onFailure(new IllegalArgumentException(location + " not found.")); } @@ -165,7 +181,7 @@ protected void findInWorkspace( .then( file -> { if (file.isPresent()) { - openFileAndScrollToLine(file.get(), location.getLineNumber(), callback); + callback.onSuccess(file.get()); } else { callback.onFailure(new IllegalArgumentException(location + " not found.")); } @@ -181,37 +197,29 @@ protected void searchSource(final Location location, final AsyncCallback>() { - @Override - public void apply(List resources) throws OperationException { - if (resources.isEmpty()) { - callback.onFailure( - new IllegalArgumentException(location.getTarget() + " not found.")); - return; - } + resources -> { + if (resources.isEmpty()) { + callback.onFailure( + new IllegalArgumentException(location.getTarget() + " not found.")); + return; + } - appContext - .getWorkspaceRoot() - .getFile(resources.get(0).getPath()) - .then( - new Operation>() { - @Override - public void apply(Optional file) throws OperationException { - if (file.isPresent()) { - openFileAndScrollToLine( - file.get(), location.getLineNumber(), callback); - } else { - callback.onFailure( - new IllegalArgumentException(location + " not found.")); - } - } - }) - .catchError( - error -> { + appContext + .getWorkspaceRoot() + .getFile(resources.get(0).getPath()) + .then( + file -> { + if (file.isPresent()) { + callback.onSuccess(file.get()); + } else { callback.onFailure( new IllegalArgumentException(location + " not found.")); - }); - } + } + }) + .catchError( + error -> { + callback.onFailure(new IllegalArgumentException(location + " not found.")); + }); }) .catchError( error -> { diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java index 31c55369a72..5239bb218d6 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-ide/src/main/java/org/eclipse/che/plugin/jdb/ide/debug/JavaDebuggerResourceHandler.java @@ -47,27 +47,27 @@ public JavaDebuggerResourceHandler( } @Override - public void open(Location location, AsyncCallback callback) { + public void find(Location location, AsyncCallback callback) { findInOpenedEditors( location, new AsyncCallback() { - @Override - public void onSuccess(VirtualFile result) { - callback.onSuccess(result); - } - @Override public void onFailure(Throwable caught) { if (location.isExternalResource()) { - openExternalResource(location, callback); + findExternalResource(location, callback); } else { - findSourceToOpen(location, callback); + JavaDebuggerResourceHandler.super.find(location, callback); } } + + @Override + public void onSuccess(VirtualFile result) { + callback.onSuccess(result); + } }); } - private void openExternalResource( + private void findExternalResource( final Location location, final AsyncCallback callback) { final String className = extractOuterClassFqn(location.getTarget()); final int libId = location.getExternalResourceId(); @@ -79,7 +79,7 @@ private void openExternalResource( jarEntry -> { final JarFileNode file = nodeFactory.newJarFileNode(jarEntry, libId, projectPath, null); - openFileAndScrollToLine(file, location.getLineNumber(), callback); + callback.onSuccess(file); }) .catchError( error -> { From 08ab0c730df4e9249a24bc1869fb2624d7534811 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Wed, 13 Sep 2017 12:13:00 +0300 Subject: [PATCH 38/38] Fix up --- .../org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java | 3 ++- .../selenium/debugger/InnerClassAndLambdaDebuggingTest.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java index cd4b658d994..c724509ed97 100644 --- a/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java +++ b/plugins/plugin-java-debugger/che-plugin-java-debugger-server/src/test/java/org/eclipse/che/plugin/jdb/server/ThreadDumpTest1.java @@ -16,6 +16,7 @@ import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.ensureSuspendAtDesiredLocation; import static org.eclipse.che.plugin.jdb.server.util.JavaDebuggerUtils.terminateVirtualMachineQuietly; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @@ -148,7 +149,7 @@ private void validateSomeThreadDump(List threads) { assertEquals(threadState.getStatus(), ThreadStatus.RUNNING); List frames = threadState.getFrames(); - assertEquals(frames.size(), 1); + assertFalse(frames.isEmpty()); StackFrameDump stackFrameDump = frames.get(0); assertTrue(stackFrameDump.getVariables().isEmpty()); diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java index 3aeb46cb5d6..1c3e728e760 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/InnerClassAndLambdaDebuggingTest.java @@ -129,7 +129,7 @@ public void shouldDebugAnonymousClass() { debugPanel.waitTextInVariablesPanel("anonym=\"App anonym\""); } - @Test(priority = 1) + @Test(priority = 1, enabled = false) public void shouldDebugMethodLocalInnerClass() { // when editor.setCursorToLine(53);