use of com.github.cameltooling.idea.runner.debugger.breakpoint.CamelBreakpoint in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method getCamelBreakpointById.
@Nullable
private CamelBreakpoint getCamelBreakpointById(String id) throws Exception {
String path = "//*[@id='" + id + "']";
// Find node with this ID in the document
XPath xPath = XPathFactory.newInstance().newXPath();
Node tagNode = (Node) xPath.evaluate(path, routesDOMDocument, XPathConstants.NODE);
if (tagNode == null) {
return null;
}
Element tag = (Element) tagNode;
String filePath = tag.getAttribute("sourceLocation");
String lineNumber = tag.getAttribute("sourceLineNumber");
if (StringUtils.isEmpty(filePath)) {
return null;
}
if (StringUtils.isEmpty(lineNumber) || "-1".equals(lineNumber.trim())) {
return null;
}
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
if (!filePath.startsWith("file:") && !filePath.startsWith("classpath:")) {
// This is Java class
PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(fileName, GlobalSearchScope.everythingScope(project));
VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
XSourcePosition position = XDebuggerUtil.getInstance().createPosition(virtualFile, new Integer(lineNumber) - 1);
Map<String, PsiElement> breakpointElement = createBreakpointElementFromPosition(position);
return new CamelBreakpoint(id, breakpointElement.get(id), position);
} else {
PsiFile[] psiFiles = FilenameIndex.getFilesByName(project, fileName, GlobalSearchScope.everythingScope(project));
if (psiFiles == null || psiFiles.length < 1) {
return null;
}
for (PsiFile psiFile : psiFiles) {
VirtualFile virtualFile = psiFile.getVirtualFile();
String url = virtualFile.getPresentableUrl();
if (virtualFile.isInLocalFileSystem()) {
// TODO - we need a better way to match source to target
// file:/absolute/path/to/file.xml
url = "file:" + url.replace("src/main/resources", "target/classes");
} else {
// Then it must be a Jar
url = "classpath:" + url.substring(url.lastIndexOf("!") + 2);
}
if (filePath.equals(url)) {
// We found our file, let's get a source position
XSourcePosition position = XDebuggerUtil.getInstance().createPosition(virtualFile, new Integer(lineNumber) - 1);
Map<String, PsiElement> breakpointElement = createBreakpointElementFromPosition(position);
return new CamelBreakpoint(id, breakpointElement.get(id), position);
}
}
}
return null;
}
use of com.github.cameltooling.idea.runner.debugger.breakpoint.CamelBreakpoint in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method toggleBreakpoint.
private boolean toggleBreakpoint(@NotNull XLineBreakpoint<XBreakpointProperties> xBreakpoint, boolean toggleOn) {
XSourcePosition position = xBreakpoint.getSourcePosition();
Map<String, PsiElement> breakpointElement = createBreakpointElementFromPosition(position);
if (breakpointElement != null) {
String breakpointId = breakpointElement.keySet().iterator().next();
PsiElement psiElement = breakpointElement.get(breakpointId);
if (toggleOn) {
XExpression condition = xBreakpoint.getConditionExpression();
if (condition == null) {
backlogDebugger.addBreakpoint(breakpointId);
} else {
backlogDebugger.addConditionalBreakpoint(breakpointId, condition.getLanguage().getID(), condition.getExpression());
}
explicitBreakpointIDs.add(breakpointId);
} else {
backlogDebugger.removeBreakpoint(breakpointId);
explicitBreakpointIDs.remove(breakpointId);
}
breakpoints.put(breakpointId, new CamelBreakpoint(breakpointId, psiElement, position));
return true;
}
// Breakpoint is invalid
xDebugSession.setBreakpointInvalid(xBreakpoint, "Camel EIP ID not found");
return false;
}
use of com.github.cameltooling.idea.runner.debugger.breakpoint.CamelBreakpoint in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method checkSuspendedBreakpoints.
private void checkSuspendedBreakpoints() {
while (isConnected()) {
try {
Collection<String> suspendedBreakpointIDs = (Collection<String>) serverConnection.invoke(this.debuggerMBeanObjectName, "getSuspendedBreakpointNodeIds", new Object[] {}, new String[] {});
if (suspendedBreakpointIDs != null && !suspendedBreakpointIDs.isEmpty()) {
// Fire notifications here, we need to display the exchange, stack etc
for (String id : suspendedBreakpointIDs) {
String xml = backlogDebugger.dumpTracedMessagesAsXml(id);
try {
// If the Camel version is 3.15 or later, the exchange properties are included
xml = (String) serverConnection.invoke(this.debuggerMBeanObjectName, "dumpTracedMessagesAsXml", new Object[] { id, true }, new String[] { "java.lang.String", "boolean" });
} catch (Exception e) {
// TODO log this or display warning
}
final String suspendedMessage = xml;
ApplicationManager.getApplication().runReadAction(() -> {
for (MessageReceivedListener listener : messageReceivedListeners) {
try {
CamelBreakpoint breakpoint = breakpoints.get(id);
if (breakpoint == null) {
// find tag and source position based on ID
breakpoint = getCamelBreakpointById(id);
breakpoints.put(id, breakpoint);
}
List<CamelMessageInfo> stack = getStack(id, suspendedMessage);
// We only need stack for the top frame
CamelMessageInfo info = stack.get(0);
info.setStack(stack);
listener.onNewMessageReceived(info);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
} finally {
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.github.cameltooling.idea.runner.debugger.breakpoint.CamelBreakpoint in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method nextStep.
private void nextStep(XSourcePosition position, boolean isOver) {
Map<String, PsiElement> breakpointElement = createBreakpointElementFromPosition(position);
if (breakpointElement == null) {
// TODO Log warning
return;
}
String breakpointId = breakpointElement.keySet().iterator().next();
PsiElement breakpointTag = breakpointElement.get(breakpointId);
breakpoints.put(breakpointId, new CamelBreakpoint(breakpointId, breakpointTag, position));
String name = breakpointTag instanceof XmlTag ? ((XmlTag) breakpointTag).getLocalName() : breakpointTag.getText();
if (isOver && ("to".equals(name) || "toD".equals(name))) {
String newTemporaryBreakpointId = getSiblingId(breakpointId);
if (newTemporaryBreakpointId != null) {
// Add temporary breakpoint
backlogDebugger.addBreakpoint(newTemporaryBreakpointId);
// Run to that breakpoint
backlogDebugger.resumeBreakpoint(breakpointId);
if (temporaryBreakpointId != null && !explicitBreakpointIDs.contains(temporaryBreakpointId) && !newTemporaryBreakpointId.equals(temporaryBreakpointId)) {
// Remove previous temporary breakpoint
backlogDebugger.removeBreakpoint(temporaryBreakpointId);
}
temporaryBreakpointId = newTemporaryBreakpointId;
} else {
// This was the last one
resume();
}
} else {
backlogDebugger.stepBreakpoint(breakpointId);
}
}
use of com.github.cameltooling.idea.runner.debugger.breakpoint.CamelBreakpoint in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerSession method runToPosition.
public void runToPosition(XSourcePosition fromPosition, XSourcePosition toPosition) {
Map<String, PsiElement> fromBreakpointElement = createBreakpointElementFromPosition(fromPosition);
Map<String, PsiElement> toBreakpointElement = createBreakpointElementFromPosition(toPosition);
if (toBreakpointElement == null) {
// this is not a tag
return;
}
String toBreakpointId = toBreakpointElement.keySet().iterator().next();
String fromBreakpointId = fromBreakpointElement.keySet().iterator().next();
breakpoints.put(toBreakpointId, new CamelBreakpoint(toBreakpointId, toBreakpointElement.get(toBreakpointId), toPosition));
backlogDebugger.addBreakpoint(toBreakpointId);
// Run to that breakpoint
backlogDebugger.resumeBreakpoint(fromBreakpointId);
if (temporaryBreakpointId != null && !explicitBreakpointIDs.contains(temporaryBreakpointId) && !toBreakpointId.equals(temporaryBreakpointId)) {
// Remove previous temporary breakpoint
backlogDebugger.removeBreakpoint(temporaryBreakpointId);
}
temporaryBreakpointId = toBreakpointId;
}
Aggregations