Skip to content

Commit

Permalink
CHE-4582: Restore debug state correctly after page is being refreshed (
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoliy Bazko authored Apr 24, 2017
1 parent 8f83a91 commit 87da86d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
@DTO
public interface StorableBreakpointDto {

void setActive(boolean active);

boolean isActive();

void setLineNumber(int lineNumber);

int getLineNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ private void doSetCurrentBreakpoint(VirtualFile activeFile, int lineNumber) {
if (breakpointRenderer != null) {
breakpointRenderer.setLineActive(lineNumber, true);
}

preserveBreakpoints();
}

@Override
Expand Down Expand Up @@ -311,8 +309,6 @@ public void deleteCurrentBreakpoint() {

currentBreakpoint = null;
}

preserveBreakpoints();
}

@Nullable
Expand Down Expand Up @@ -502,10 +498,6 @@ private void preserveBreakpoints() {
List<StorableBreakpointDto> allDtoBreakpoints = new LinkedList<StorableBreakpointDto>();

List<Breakpoint> allBreakpoints = getBreakpointList();
if (currentBreakpoint != null) {
allBreakpoints.add(currentBreakpoint);
}

for (Breakpoint breakpoint : allBreakpoints) {
StorableBreakpointDto dto = dtoFactory.createDto(StorableBreakpointDto.class);
dto.setType(breakpoint.getType());
Expand All @@ -525,9 +517,6 @@ private void preserveBreakpoints() {
dto.setFileProjectConfig(projectDto); //TODO need to think to change argument type from dto to model interface
}
}

dto.setActive(breakpoint.isActive());

allDtoBreakpoints.add(dto);
}

Expand Down Expand Up @@ -558,17 +547,12 @@ public Promise<Void> apply(Void ignored) throws FunctionException {
return appContext.getWorkspaceRoot().getFile(dto.getPath()).then(new Function<Optional<File>, Void>() {
@Override
public Void apply(Optional<File> file) throws FunctionException {
if (!file.isPresent()) {
return null;
}
if (dto.getType() == Type.CURRENT) {
doSetCurrentBreakpoint(file.get(), dto.getLineNumber());
} else {
if (file.isPresent() && dto.getType() == Type.BREAKPOINT) {
addBreakpoint(new Breakpoint(dto.getType(),
dto.getLineNumber(),
dto.getPath(),
file.get(),
dto.isActive()));
false));
}

return null;
Expand Down Expand Up @@ -672,12 +656,10 @@ public void onBreakpointActivated(String filePath, int lineNumber) {
}

@Override
public void onBreakpointDeleted(Breakpoint breakpoint) {
}
public void onBreakpointDeleted(Breakpoint breakpoint) { }

@Override
public void onAllBreakpointsDeleted() {
}
public void onAllBreakpointsDeleted() { }

@Override
public void onPreStepInto() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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.api.promises.client.js.JsPromise;
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;
Expand Down Expand Up @@ -159,17 +158,22 @@ public void onWsAgentStarted(WsAgentStateEvent event) {
String info = debuggerInfo.getName() + " " + debuggerInfo.getVersion();
String address = debuggerInfo.getHost() + ":" + debuggerInfo.getPort();
DebuggerDescriptor debuggerDescriptor = new DebuggerDescriptor(info, address);
JsPromise<Void> promise1 = Promises.resolve(null);

for (DebuggerObserver observer : observers) {
observer.onDebuggerAttached(debuggerDescriptor, promise1);
observer.onDebuggerAttached(debuggerDescriptor, Promises.resolve(null));
}

for (BreakpointDto breakpoint : debugSessionDto.getBreakpoints()) {
onBreakpointActivated(breakpoint.getLocation());
}

if (currentLocation != null) {
openCurrentFile();
}

startCheckingEvents();
}).catchError(error -> {
if (!isConnected()) {
invalidateDebugSession();
}
disconnect();
});
}

Expand Down
4 changes: 4 additions & 0 deletions wsagent/che-core-api-debug-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<packaging>jar</packaging>
<name>Che Core :: API :: Debug :: Shared</name>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-dto</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.eclipse.che.api.debug.shared.model.DebugSession;
import org.eclipse.che.dto.shared.DTO;

import java.util.List;

/**
* @author Anatoliy Bazko
*/
Expand All @@ -35,4 +37,10 @@ public interface DebugSessionDto extends DebugSession {
void setType(String type);

DebugSessionDto withType(String type);

List<BreakpointDto> getBreakpoints();

void setBreakpoints(List<BreakpointDto> breakpoints);

DebugSessionDto withBreakpoints(List<BreakpointDto> breakpoints);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.che.api.debug.shared.model;

import java.util.List;

/**
* Debug session.
*
Expand All @@ -30,4 +32,9 @@ public interface DebugSession {
* Debugger type.
*/
String getType();

/**
* Returns active breakpoints.
*/
List<? extends Breakpoint> getBreakpoints();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,28 @@
*******************************************************************************/
package org.eclipse.che.api.debug.shared.model.impl;

import com.google.common.base.Objects;

import org.eclipse.che.api.debug.shared.model.Breakpoint;
import org.eclipse.che.api.debug.shared.model.DebugSession;
import org.eclipse.che.api.debug.shared.model.DebuggerInfo;

import java.util.List;

/**
* @author Anatoliy Bazko
*/
public class DebugSessionImpl implements DebugSession {
private final DebuggerInfo debuggerInfo;
private final String id;
private final String type;
private final DebuggerInfo debuggerInfo;
private final String id;
private final String type;
private final List<? extends Breakpoint> breakpoints;

public DebugSessionImpl(DebuggerInfo debuggerInfo, String id, String type) {
public DebugSessionImpl(DebuggerInfo debuggerInfo, String id, String type, List<? extends Breakpoint> breakpoints) {
this.debuggerInfo = debuggerInfo;
this.id = id;
this.type = type;
this.breakpoints = breakpoints;
}

@Override
Expand All @@ -42,23 +49,24 @@ public String getType() {
return type;
}

@Override
public List<? extends Breakpoint> getBreakpoints() {
return breakpoints;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DebugSessionImpl)) return false;

DebugSessionImpl that = (DebugSessionImpl)o;

if (debuggerInfo != null ? !debuggerInfo.equals(that.debuggerInfo) : that.debuggerInfo != null) return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
return !(type != null ? !type.equals(that.type) : that.type != null);
return Objects.equal(debuggerInfo, that.debuggerInfo) &&
Objects.equal(id, that.id) &&
Objects.equal(type, that.type) &&
Objects.equal(breakpoints, that.breakpoints);
}

@Override
public int hashCode() {
int result = debuggerInfo != null ? debuggerInfo.hashCode() : 0;
result = 31 * result + (id != null ? id.hashCode() : 0);
result = 31 * result + (type != null ? type.hashCode() : 0);
return result;
return Objects.hashCode(debuggerInfo, id, type, breakpoints);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@

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.VariableDto;
import org.eclipse.che.api.debug.shared.dto.action.ActionDto;
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.VariablePath;
import org.eclipse.che.api.debug.shared.model.action.ResumeAction;
Expand All @@ -30,6 +27,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;
Expand Down Expand Up @@ -94,12 +93,13 @@ public void disconnect(@PathParam("id") String sessionId) throws DebuggerExcepti
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public DebugSessionDto getDebugSession(@PathParam("id") String sessionId) throws DebuggerException {
DebuggerInfo debuggerInfo = debuggerManager.getDebugger(sessionId).getInfo();
Debugger debugger = debuggerManager.getDebugger(sessionId);

DebugSessionDto debugSessionDto = newDto(DebugSessionDto.class);
debugSessionDto.setDebuggerInfo(asDto(debuggerInfo));
debugSessionDto.setDebuggerInfo(asDto(debugger.getInfo()));
debugSessionDto.setId(sessionId);
debugSessionDto.setType(debuggerManager.getDebuggerType(sessionId));
debugSessionDto.setBreakpoints(asBreakpointsDto(debugger.getAllBreakpoints()));

return debugSessionDto;
}
Expand Down

0 comments on commit 87da86d

Please sign in to comment.