Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* The MIT License
*
* Copyright 2022 Karate Labs Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.intuit.karate.debug;
import com.intuit.karate.*;
import com.intuit.karate.cli.IdeMain;
import com.intuit.karate.core.Feature;
import com.intuit.karate.core.Result;
import com.intuit.karate.core.RuntimeHookFactory;
import com.intuit.karate.core.ScenarioEngine;
import com.intuit.karate.core.ScenarioRuntime;
import com.intuit.karate.core.Step;
import com.intuit.karate.core.Variable;
import static com.intuit.karate.core.Variable.Type.LIST;
import static com.intuit.karate.core.Variable.Type.MAP;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author pthomas3
*/
public class DapServerHandler extends SimpleChannelInboundHandler implements RuntimeHookFactory {
private static final Logger logger = LoggerFactory.getLogger(DapServerHandler.class);
private final DapServer server;
private Channel channel;
private int nextSeq;
private long nextFrameId;
private long nextVariablesReference = 1000; // setting to 1000 to avoid collisions with nextFrameId
private long focusedFrameId;
private Thread runnerThread;
private final Map BREAKPOINTS = new ConcurrentHashMap();
protected final Map THREADS = new ConcurrentHashMap();
protected final Map FRAMES = new ConcurrentHashMap();
protected final Map>> FRAME_VARS = new ConcurrentHashMap();
protected final Map> VARIABLES = new ConcurrentHashMap();
private boolean singleFeature;
private String launchCommand;
private String preStep;
public DapServerHandler(DapServer server) {
this.server = server;
}
private static final String TEST_CLASSES = "/test-classes/";
private static final String CLASSES_TEST = "/classes/java/test/";
private static int findPos(String path) {
int pos = path.indexOf(TEST_CLASSES);
if (pos != -1) {
return pos + TEST_CLASSES.length();
}
pos = path.indexOf(CLASSES_TEST);
if (pos != -1) {
return pos + CLASSES_TEST.length();
}
return -1;
}
private SourceBreakpoints lookup(String pathEnd) {
for (Entry entry : BREAKPOINTS.entrySet()) {
if (entry.getKey().endsWith(pathEnd)) {
return entry.getValue();
}
}
return null;
}
protected boolean isBreakpoint(Step step, int line, ScenarioRuntime context) {
Feature feature = step.getFeature();
File file = feature.getResource().getFile();
if (file == null) {
return false;
}
String path = normalizePath(file.getPath());
int pos = findPos(path);
SourceBreakpoints sb;
if (pos != -1) {
sb = lookup(path.substring(pos));
} else {
sb = BREAKPOINTS.get(path);
}
if (sb == null) {
return false;
}
return sb.isBreakpoint(line, context);
}
protected String normalizePath(String path) {
String normalizedPath = Paths.get(path).normalize().toString();
if (FileUtils.isOsWindows() && path.matches("^[a-zA-Z]:\\\\.*")) {
// in Windows if the first character is the drive, let's capitalize it
// Windows paths are case insensitive but in the debugger it mostly comes capitalized but sometimes
// VS Studio sends the paths with the first letter lower case
normalizedPath = normalizedPath.substring(0, 1).toUpperCase() + normalizedPath.substring(1);
}
return normalizedPath;
}
private DebugThread thread(DapMessage dm) {
Number threadId = dm.getThreadId();
if (threadId == null) {
return null;
}
return THREADS.get(threadId.longValue());
}
private List