null
- */
- private static IConsoleLineTrackerExtension fDelegate;
- private static IConsole fConsole;
-
- /**
- * Sets the delegate, possibly null
- */
- public static void setDelegate(IConsoleLineTrackerExtension tracker) {
- fDelegate = tracker;
- fConsole = null;
- }
-
- @Override
- public void dispose() {
- if (fDelegate != null) {
- fDelegate.dispose();
- }
- fConsole = null;
- }
-
- @Override
- public synchronized void init(IConsole console) {
- fConsole = console;
- if (fDelegate != null) {
- fDelegate.init(console);
- }
- }
-
- /**
- * Returns the document backing this console
- */
- public static IDocument getDocument() {
- return fConsole.getDocument();
- }
-
- @Override
- public void lineAppended(IRegion line) {
- if (fDelegate != null) {
- fDelegate.lineAppended(line);
- }
- }
-
- @Override
- public void consoleClosed() {
- if (fDelegate != null && fConsole != null) {
- fDelegate.consoleClosed();
- }
- }
-}
diff --git a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/launch/ConsoleLineTrackerTests.groovy b/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/launch/ConsoleLineTrackerTests.groovy
deleted file mode 100644
index f608071d68..0000000000
--- a/ide-test/org.codehaus.groovy.eclipse.tests/src/org/codehaus/groovy/eclipse/test/launch/ConsoleLineTrackerTests.groovy
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright 2009-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.codehaus.groovy.eclipse.test.launch
-
-import groovy.transform.PackageScope
-
-import org.codehaus.groovy.eclipse.launchers.GroovyConsoleLineTracker
-import org.codehaus.groovy.eclipse.launchers.GroovyConsoleLineTracker.AmbiguousFileLink
-import org.codehaus.groovy.eclipse.test.GroovyEclipseTestSuite
-import org.eclipse.core.resources.IFile
-import org.eclipse.debug.core.model.IProcess
-import org.eclipse.debug.core.model.IStreamMonitor
-import org.eclipse.debug.core.model.IStreamsProxy
-import org.eclipse.debug.ui.console.FileLink
-import org.eclipse.debug.ui.console.IConsole
-import org.eclipse.jdt.groovy.core.util.ReflectionUtils
-import org.eclipse.jface.text.Document
-import org.eclipse.jface.text.IDocument
-import org.eclipse.jface.text.IRegion
-import org.eclipse.jface.text.Region
-import org.eclipse.ui.console.IHyperlink
-import org.eclipse.ui.console.IOConsoleOutputStream
-import org.eclipse.ui.console.IPatternMatchListener
-import org.junit.Assert
-import org.junit.Before
-import org.junit.Test
-
-final class ConsoleLineTrackerTests extends GroovyEclipseTestSuite {
-
- GroovyConsoleLineTracker lineTracker
- MockConsole console
- IDocument doc
-
- @Before
- void setUp() {
- doc = new Document()
- console = new MockConsole(doc)
- lineTracker = new GroovyConsoleLineTracker()
- lineTracker.init(console)
- }
-
- @Test
- void testNoLink() {
- addGroovySource('', 'Bar', 'f')
- String contents = 'ahdhjkfsfds'
- doc.set(contents)
- lineTracker.lineAppended(new Region(0, contents.length()))
- Assert.assertNull('Should not have found any hyperlinks', console.lastLink)
- }
-
- @Test
- void testLink() {
- addGroovySource('', 'Bar', 'f')
- String contents = 'at f.Bar.run(Bar.groovy:2)'
- doc.set(contents)
- lineTracker.lineAppended(new Region(0, contents.length()))
- Assert.assertNotNull('Should have found a hyperlink', console.lastLink)
- FileLink link = (FileLink) console.lastLink
- IFile file = ReflectionUtils.getPrivateField(FileLink, 'fFile', link)
- Assert.assertTrue('File should exist', file.isAccessible())
- Assert.assertEquals('File name is wrong', 'Bar.groovy', file.name)
- }
-
- @Test
- void testAmbiguousLink() {
- addGroovySource('', 'Baz', 'f')
- addGroovySource('', 'Baz', 'f', addSourceFolder('other'))
- String contents = 'at f.Baz.run(Baz.groovy:2)'
- doc.set(contents)
- lineTracker.lineAppended(new Region(0, contents.length()))
- Assert.assertNotNull('Should have found a hyperlink', console.lastLink)
- FileLink link = (FileLink) console.lastLink
- Object file = ReflectionUtils.getPrivateField(FileLink, 'fFile', link)
- Assert.assertNull('File should be null since the selection is ambiguous', file)
-
- IFile[] files = ReflectionUtils.getPrivateField(AmbiguousFileLink, 'files', link)
-
- Assert.assertEquals('Should have found 2 files', 2, files.length)
- Assert.assertEquals('File name is wrong', 'Baz.groovy', files[0].name)
- Assert.assertEquals('File name is wrong', 'Baz.groovy', files[1].name)
- }
-}
-
-@SuppressWarnings('deprecation')
-@PackageScope class MockConsole implements IConsole {
-
- private Map
+ * NOTE: "pack.Type.meth(File.groovy:line)" is handled by {@code JavaConsoleTracker}.
+ */
+public class GroovyConsoleLineTracker extends JavaConsoleTracker {
- /**
- * Hyperlink error lines to the editor.
- */
@Override
- public void lineAppended(IRegion line) {
- if (console == null) return;
-
- int lineOffset = line.getOffset();
- int lineLength = line.getLength();
+ public void matchFound(final PatternMatchEvent event) {
+ int offset = event.getOffset();
+ int length = event.getLength() - 1;
+ TextConsole console = getConsole();
try {
- String consoleLine = console.getDocument().get(lineOffset, lineLength);
- GroovyPlugin.trace(consoleLine);
- Matcher m = LINE_PATTERN.matcher(consoleLine);
- String groovyFileName = null;
- int lineNumber = -1;
- int openParenIndexAt = -1;
- int closeParenIndexAt = -1;
- // match
- if (m.matches()) {
- consoleLine = m.group(0);
- openParenIndexAt = consoleLine.indexOf("(");
- if (openParenIndexAt >= 0) {
- int end = consoleLine.indexOf(".groovy");
- if (end == -1 || (openParenIndexAt + 1) >= end) {
- return;
- }
- String groovyClassName = consoleLine.substring(openParenIndexAt + 1, end);
- int classIndex = consoleLine.indexOf(groovyClassName);
- int start = 3;
- if (classIndex < start || classIndex >= consoleLine.length()) {
- return;
- }
- String groovyFilePath = consoleLine.substring(start, classIndex).trim().replace('.', '/');
- groovyFileName = groovyFilePath + groovyClassName + ".groovy";
- int colonIndex = consoleLine.indexOf(":");
- // get the line number in groovy class
- closeParenIndexAt = consoleLine.lastIndexOf(")");
- if (colonIndex > 0) {
- lineNumber = Integer.parseInt(consoleLine.substring(colonIndex + 1, closeParenIndexAt));
- }
- GroovyPlugin.trace("groovyFile=" + groovyFileName + " lineNumber:" + lineNumber);
- }
- // hyperlink if we found something
- if (groovyFileName != null) {
- IFile[] file = searchForFileInLaunchConfig(groovyFileName);
- if (file.length == 1) {
- IHyperlink link = new FileLink(file[0], GroovyEditor.EDITOR_ID, -1, -1, lineNumber);
- console.addLink(link, lineOffset + openParenIndexAt + 1, closeParenIndexAt - openParenIndexAt - 1);
- } else if (file.length > 1) {
- IHyperlink link = new AmbiguousFileLink(file, GroovyEditor.EDITOR_ID, -1, -1, lineNumber);
- console.addLink(link, lineOffset + openParenIndexAt + 1, closeParenIndexAt - openParenIndexAt - 1);
- }
- }
- }
- } catch (Exception e) {
- GroovyPlugin.getDefault().logError("unexpected error", e);
- }
- }
-
- private IFile[] searchForFileInLaunchConfig(String groovyFileName) throws JavaModelException {
- List