Search in sources :

Example 1 with NodeJsDebuggerParseException

use of org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException in project che by eclipse.

the class NodeJsBreakpointsParser method parse.

@Override
public Breakpoints parse(NodeJsOutput nodeJsOutput) throws NodeJsDebuggerParseException {
    final List<Breakpoint> breakpoints = new ArrayList<>();
    JsonObject json = new JsonParser().parse(nodeJsOutput.getOutput()).getAsJsonObject();
    if (json.has("breakpoints")) {
        Iterator<JsonElement> iter = json.getAsJsonArray("breakpoints").iterator();
        while (iter.hasNext()) {
            JsonObject item = iter.next().getAsJsonObject();
            try {
                final String condition = item.has("condition") && !item.get("condition").isJsonNull() ? item.get("condition").getAsString() : null;
                final boolean isEnabled = item.has("active") && !item.get("active").isJsonNull() && item.get("active").getAsBoolean();
                final int lineNumber = item.get("line").getAsInt();
                final String target;
                String targetType = item.get("type").getAsString();
                switch(targetType) {
                    case "scriptId":
                        target = String.valueOf(item.get("script_id").getAsInt());
                        break;
                    case "scriptRegExp":
                        target = item.get("script_regexp").getAsString();
                        break;
                    default:
                        throw new IllegalArgumentException("Unsupported 'type' value: " + targetType);
                }
                Location location = new LocationImpl(targetType + ":" + target, lineNumber + 1);
                Breakpoint breakpoint = new BreakpointImpl(location, isEnabled, condition);
                breakpoints.add(breakpoint);
            } catch (Exception e) {
                LOG.error("Failed to parse breakpoint: " + item.toString(), e);
            }
        }
    }
    return new Breakpoints(breakpoints);
}
Also used : Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) BreakpointImpl(org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Breakpoint(org.eclipse.che.api.debug.shared.model.Breakpoint) NodeJsDebuggerParseException(org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException) JsonElement(com.google.gson.JsonElement) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl) JsonParser(com.google.gson.JsonParser) Location(org.eclipse.che.api.debug.shared.model.Location)

Example 2 with NodeJsDebuggerParseException

use of org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException in project che by eclipse.

the class NodeJsStepParser method parse.

@Override
public Location parse(NodeJsOutput nodeJsOutput) throws NodeJsDebuggerParseException {
    String output = nodeJsOutput.getOutput();
    for (String line : output.split("\n")) {
        Matcher matcher = PATTERN.matcher(line);
        if (matcher.find()) {
            String file = matcher.group(1);
            String lineNumber = matcher.group(2);
            return new LocationImpl(file, Integer.parseInt(lineNumber));
        }
    }
    throw new NodeJsDebuggerParseException(Location.class, output);
}
Also used : NodeJsDebuggerParseException(org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException) Matcher(java.util.regex.Matcher) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl)

Example 3 with NodeJsDebuggerParseException

use of org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException in project che by eclipse.

the class NodeJsBackTraceParser method parse.

@Override
public Location parse(NodeJsOutput nodeJsOutput) throws NodeJsDebuggerParseException {
    String output = nodeJsOutput.getOutput();
    for (String line : output.split("\n")) {
        Matcher matcher = PATTERN.matcher(line);
        if (matcher.find()) {
            String file = matcher.group(2);
            String lineNumber = matcher.group(3);
            return new LocationImpl(file, Integer.parseInt(lineNumber));
        }
    }
    throw new NodeJsDebuggerParseException(Location.class, output);
}
Also used : NodeJsDebuggerParseException(org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException) Matcher(java.util.regex.Matcher) LocationImpl(org.eclipse.che.api.debug.shared.model.impl.LocationImpl)

Aggregations

LocationImpl (org.eclipse.che.api.debug.shared.model.impl.LocationImpl)3 NodeJsDebuggerParseException (org.eclipse.che.plugin.nodejsdbg.server.exception.NodeJsDebuggerParseException)3 Matcher (java.util.regex.Matcher)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ArrayList (java.util.ArrayList)1 Breakpoint (org.eclipse.che.api.debug.shared.model.Breakpoint)1 Location (org.eclipse.che.api.debug.shared.model.Location)1 BreakpointImpl (org.eclipse.che.api.debug.shared.model.impl.BreakpointImpl)1