Search in sources :

Example 1 with FileLink

use of org.eclipse.debug.ui.console.FileLink in project linuxtools by eclipse.

the class ErrorLineMatcher method matchFound.

@Override
public void matchFound(PatternMatchEvent event) {
    String line = null;
    try {
        line = console.getDocument().get(event.getOffset(), event.getLength());
        int lineNumber = Integer.parseInt(line.substring(12, line.indexOf(':', line.indexOf(LINE))).trim());
        FileLink fileLink = new FileLink(console.getSpecfile().getAdapter(IFile.class), "org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor", -1, -1, // $NON-NLS-1$
        lineNumber);
        console.addHyperlink(fileLink, 7, line.indexOf(':', line.indexOf(LINE)) - 7);
    } catch (BadLocationException e1) {
        return;
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FileLink(org.eclipse.debug.ui.console.FileLink) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with FileLink

use of org.eclipse.debug.ui.console.FileLink in project erlide_eclipse by erlang.

the class ErlPatternMatchListenerDelegate method matchFound.

@Override
public void matchFound(final PatternMatchEvent event) {
    if (fConsole == null) {
        return;
    }
    try {
        final String txt = fConsole.getDocument().get(event.getOffset(), event.getLength());
        final String[] v = txt.split(":");
        final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
        IResource res = null;
        for (final IProject prj : projects) {
            if (!prj.isOpen()) {
                continue;
            }
            try {
                res = ErlPatternMatchListenerDelegate.recursiveFindNamedResourceWithReferences(prj, v[0]);
                if (res != null) {
                    break;
                }
            } catch (final CoreException e) {
                ErlLogger.warn(e);
            }
        }
        IFile file = null;
        if (res instanceof IFile) {
            file = (IFile) res;
        }
        final IHyperlink link = new FileLink(file, null, -1, -1, Integer.parseInt(v[1]));
        fConsole.addHyperlink(link, event.getOffset(), event.getLength());
    } catch (final BadLocationException e) {
        ErlLogger.warn(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IHyperlink(org.eclipse.ui.console.IHyperlink) FileLink(org.eclipse.debug.ui.console.FileLink) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with FileLink

use of org.eclipse.debug.ui.console.FileLink in project liferay-ide by liferay.

the class ConsoleLineTracker method lineAppended.

public void lineAppended(IRegion line) {
    try {
        String text = console.getDocument().get(line.getOffset(), line.getLength());
        if (text.indexOf(CHECK) >= 0) {
            // it might relate to us
            int i1 = text.lastIndexOf(CHECK_TEMPLATE);
            if (i1 < 0) {
                int i2 = text.lastIndexOf(CHECK_LINE2);
                if (i2 >= 0) {
                    i1 = text.indexOf(CHECK_TEMPLATE2, i2);
                    i1 -= 6;
                }
            }
            if (i1 > 0) {
                // this is most likely an error message
                int linkOffset = i1 + 10;
                int linkLength = text.length() - linkOffset;
                String fileName = text.substring(linkOffset, text.length()).trim();
                // $NON-NLS-1$
                if (fileName.endsWith("."))
                    fileName = fileName.substring(0, fileName.length() - 1);
                int lineNumber = -1;
                try {
                    int i2 = text.lastIndexOf(CHECK_LINE);
                    if (i2 > 0) {
                        i2 += CHECK_LINE.length();
                        // $NON-NLS-1$
                        int i3 = text.indexOf(",", i2);
                        if (i3 > 0) {
                            lineNumber = Integer.parseInt(text.substring(i2, i3).trim());
                        }
                    } else {
                        i2 = text.lastIndexOf(CHECK_LINE2);
                        if (i2 > 0) {
                            i2 += CHECK_LINE2.length();
                            // $NON-NLS-1$
                            int i3 = text.indexOf(",", i2);
                            if (i3 > 0) {
                                lineNumber = Integer.parseInt(text.substring(i2, i3).trim());
                            }
                        }
                    }
                } catch (Exception e) {
                // we can still proceed if we don't get the line number
                }
                IPath path = new Path(fileName);
                IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                List files = new ArrayList();
                for (int i = 0; i < projects.length; i++) {
                    IProject project = projects[i];
                    IJavaProject javaProject = JavaCore.create(project);
                    fileName = fileName.replace('\\', '/');
                    try {
                        // $NON-NLS-1$
                        populateMatchingFiles(project, files, fileName.split("/"));
                    } catch (CoreException e) {
                    // TODO log this exception
                    }
                }
                if (files.size() != 0) {
                    IFile file = (IFile) files.get(0);
                    if (file != null && file.exists()) {
                        FileLink link = new FileLink(file, null, -1, -1, lineNumber);
                        console.addLink(link, linkOffset, linkLength);
                    }
                }
            }
        }
    } catch (BadLocationException e) {
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) FileLink(org.eclipse.debug.ui.console.FileLink) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) List(java.util.List) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with FileLink

use of org.eclipse.debug.ui.console.FileLink in project ow by vtst.

the class LessCompilerLaunchConfigurationDelegate method addProcessListeners.

protected void addProcessListeners(ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
    acceptor.acceptTerminationListener(new IProcessTerminationListener() {

        public void terminated(IProcess process, int exitValue) {
            IConsole console = DebugUITools.getConsole(process);
            if (console instanceof IOConsole) {
                IOConsole ioConsole = (IOConsole) console;
                IOConsoleOutputStream stream = ioConsole.newOutputStream();
                if (exitValue == 0) {
                    try {
                        stream.write(messages.getString("less_compiler_success"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                /*
            FileLink link = new FileLink(destinationFile, null, -1, -1, -1);
            console.defaultStream.hyperlink(link, messages.getString("less_link_to_output"));
            console.defaultStream.println();
            */
                } else {
                    try {
                        stream.write(messages.getString("less_compiler_error"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            try {
                fixture.outputFile.refreshLocal(0, null);
            } catch (CoreException e) {
            }
        }
    });
    acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {

        private Pattern pattern = Pattern.compile("([0-9]+)( .*)");

        private int numberOfLines = 0;

        private int errorLineNumber = 0;

        private String errorMessage = null;

        @Override
        public void connect(TextConsole console) {
            super.connect(console);
            try {
                for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
                    if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
                        marker.delete();
                    }
                }
            } catch (CoreException e) {
            }
        }

        @Override
        public void disconnect() {
            if (errorLineNumber != 0 && errorMessage != null) {
                try {
                    IMarker marker = fixture.inputFile.createMarker(MARKER_TYPE);
                    marker.setAttribute(IMarker.LINE_NUMBER, this.errorLineNumber);
                    marker.setAttribute(IMarker.MESSAGE, this.errorMessage);
                    marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                    marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }

        private void processLine(int offset, int length) throws BadLocationException {
            String line = document.get(offset, length);
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                this.numberOfLines++;
                int lineNumber = Integer.parseInt(matcher.group(1));
                if (this.numberOfLines <= 2)
                    errorLineNumber = lineNumber;
                FileLink link = new FileLink(fixture.inputFile, null, -1, -1, lineNumber);
                console.addHyperlink(link, offset, matcher.group(1).length());
            } else {
                if (this.numberOfLines == 0)
                    errorMessage = line;
            }
        }

        @Override
        public void matchFound(PatternMatchEvent matchEvent) {
            try {
                processLine(matchEvent.getOffset(), matchEvent.getLength());
            } catch (BadLocationException e) {
            // This should never arise if the code is correct
            }
        }

        @Override
        public String getPattern() {
            return ".+";
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) Matcher(java.util.regex.Matcher) IProcessTerminationListener(net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener) FileLink(org.eclipse.debug.ui.console.FileLink) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) PatternMatchEvent(org.eclipse.ui.console.PatternMatchEvent) CoreException(org.eclipse.core.runtime.CoreException) EasyPatternMatchListener(net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener) TextConsole(org.eclipse.ui.console.TextConsole) IMarker(org.eclipse.core.resources.IMarker) IProcess(org.eclipse.debug.core.model.IProcess) IOConsole(org.eclipse.ui.console.IOConsole) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

FileLink (org.eclipse.debug.ui.console.FileLink)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 IProject (org.eclipse.core.resources.IProject)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 IProcessTerminationListener (net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener)1 EasyPatternMatchListener (net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IProcess (org.eclipse.debug.core.model.IProcess)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IConsole (org.eclipse.ui.console.IConsole)1