diff --git a/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/JavaDebugStackTraceConsoleTest.java b/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/JavaDebugStackTraceConsoleTest.java index 2fd191cc5f..806f0135bb 100644 --- a/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/JavaDebugStackTraceConsoleTest.java +++ b/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/JavaDebugStackTraceConsoleTest.java @@ -213,6 +213,31 @@ public void testMixedCases() throws Exception { new String[] { "somewhere1.somewhere2.Some1Class105", "line: 5" }, matchTexts); } + public void testStackTraceDetectionWithColors() throws Exception { + String exception = "" + + "Caused by\033[m: java.lang.NullPointerException: \033[1;31mCannot invoke \"org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus.addListener(org.eclipse.equinox.internal.provisional.p2.core.eventbus.ProvisioningListener)\" because \"this.eventBus\" is null\033[m\n" + + " \033[1mat\033[m org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager. (\033[1mAbstractRepositoryManager.java:107\033[m)\n" + + " \033[1mat\033[m org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRepositoryManager. (\033[1mArtifactRepositoryManager.java:41\033[m)\n" + // ... + + " \033[1mat\033[m java.lang.reflect.Method.invoke (\033[1mMethod.java:568\033[m)\n" + + " \033[1mat\033[m org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (\033[1mLauncher.java:282\033[m)\n" + + " \033[1mat\033[m org.codehaus.plexus.classworlds.launcher.Launcher.launch (\033[1mLauncher.java:225\033[m)\n" + + " \033[1mat\033[m org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (\033[1mLauncher.java:406\033[m)\n" + + " \033[1mat\033[m org.codehaus.plexus.classworlds.launcher.Launcher.main (\033[1mLauncher.java:347\033[m)\n"; + consoleDocumentWithText(exception); + + Position[] positions = allLinkPositions(); + int[] offsets = new int[positions.length]; + for (int i = 0; i < offsets.length; i++) { + offsets[i] = positions[i].getOffset(); + } + + String[] matchTexts = linkTextsAtPositions(offsets); + String[] expected = { "java.lang.NullPointerException", "AbstractRepositoryManager.java:107", "ArtifactRepositoryManager.java:41", + "Method.java:568", "Launcher.java:282", "Launcher.java:225", "Launcher.java:406", "Launcher.java:347" }; + assertArrayEquals("Wrong hyperlinks, listing all links: " + allLinks(), expected, matchTexts); + } + private static String getSelectedText(IEditorPart editor) { ITextEditor textEditor = (ITextEditor) editor; ISelectionProvider selectionProvider = textEditor.getSelectionProvider(); diff --git a/org.eclipse.jdt.debug.ui/plugin.xml b/org.eclipse.jdt.debug.ui/plugin.xml index 6a4cbe0fc8..718a2c9a99 100644 --- a/org.eclipse.jdt.debug.ui/plugin.xml +++ b/org.eclipse.jdt.debug.ui/plugin.xml @@ -3503,7 +3503,7 @@ M4 = Platform-specific fourth key point="org.eclipse.ui.console.consolePatternMatchListeners"> @@ -3517,7 +3517,7 @@ M4 = Platform-specific fourth key @@ -3890,4 +3890,15 @@ M4 = Platform-specific fourth key + + + + + + + diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java index 548c217b98..fbe6f559f5 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaConsoleTracker.java @@ -54,12 +54,22 @@ protected TextConsole getConsole() { * @see org.eclipse.ui.console.IPatternMatchListenerDelegate#matchFound(org.eclipse.ui.console.PatternMatchEvent) */ @Override - public void matchFound(PatternMatchEvent event) { + public void matchFound(PatternMatchEvent event) { try { - int offset = event.getOffset(); - int length = event.getLength(); + int offset = event.getOffset() + 1; // skip the leading ( + int length = event.getLength() - 2; // don't count the leading ( and trailing ) + + String text = fConsole.getDocument().get(offset, length); + // Remove the ANSI escape sequences + String textNew = text.replaceAll(JavaStackTraceHyperlink.ANSI_ESCAPE_REGEX, ""); //$NON-NLS-1$ + int delta = text.indexOf(textNew); + if (delta != -1) { + offset += delta; + length = textNew.length(); + } + IHyperlink link = new JavaStackTraceHyperlink(fConsole); - fConsole.addHyperlink(link, offset+1, length-2); + fConsole.addHyperlink(link, offset, length); } catch (BadLocationException e) { } } diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java index 760b8cc1e5..7c2e4d2a61 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/console/JavaStackTraceHyperlink.java @@ -60,7 +60,7 @@ * A hyper-link from a stack trace line of the form "*(*.java:*)" */ public class JavaStackTraceHyperlink implements IHyperlink { - + final static String ANSI_ESCAPE_REGEX = "\033\\[[\\d;]*[A-HJKSTfimnsu]"; //$NON-NLS-1$ private final TextConsole fConsole; private final AtomicReference generatedLink; private static final String REGEX_FOR_NORMAL = "([a-zA-Z0-9\\$]+)\\.([a-zA-Z0-9]+)\\(([^)]*)\\)"; //$NON-NLS-1$ @@ -103,6 +103,7 @@ public void linkActivated() { int lineNumber; try { String linkText = getLinkText(); + linkText = linkText.replaceAll(ANSI_ESCAPE_REGEX, ""); //$NON-NLS-1$ generatedLink.set(linkText); typeName = getTypeName(linkText); lineNumber = getLineNumber(linkText);