### Eclipse Workspace Patch 1.0 #P org.eclipse.debug.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.debug.ui/plugin.xml,v retrieving revision 1.438 diff -u -r1.438 plugin.xml --- plugin.xml 24 Apr 2009 20:20:00 -0000 1.438 +++ plugin.xml 19 Jun 2009 09:28:12 -0000 @@ -2853,5 +2853,17 @@ - + + + + + + + + Index: ui/org/eclipse/debug/ui/console/FilenameToHyperlinkMaker.java =================================================================== RCS file: ui/org/eclipse/debug/ui/console/FilenameToHyperlinkMaker.java diff -N ui/org/eclipse/debug/ui/console/FilenameToHyperlinkMaker.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ui/org/eclipse/debug/ui/console/FilenameToHyperlinkMaker.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * STMicroelectronics - initial API and implementation + *******************************************************************************/ + +package org.eclipse.debug.ui.console; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.internal.ui.views.console.ProcessConsole; +import org.eclipse.debug.ui.console.FileLink; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.ui.console.IPatternMatchListenerDelegate; +import org.eclipse.ui.console.PatternMatchEvent; +import org.eclipse.ui.console.TextConsole; + +public class FilenameToHyperlinkMaker implements IPatternMatchListenerDelegate { + + private TextConsole currentListeningConsole; + + public void connect(TextConsole console) { + currentListeningConsole = console; + } + + public void disconnect() { + currentListeningConsole = null; + } + + public void matchFound(PatternMatchEvent event) { + + String matchLine; + String fileName = null; + int lineNumber = -1; + String projectName = null; + IPath workspaceLocation; + IPath projectLocation = null; + IFile filePath = null; + + try { + projectName = ((ProcessConsole)event.getSource()).getProcess().getLaunch().getLaunchConfiguration(). + getAttribute("org.eclipse.jdt.launching.PROJECT_ATTR", ".null."); + } catch (CoreException e2) { + e2.printStackTrace(); + } + + workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation(); + if (projectName != null && !projectName.equals(".null.")) projectLocation = workspaceLocation.append(projectName); + + if (currentListeningConsole != null) { + try { + matchLine = currentListeningConsole.getDocument().get(event.getOffset(), event.getLength()); + int semiBeforeNumber = matchLine.substring(0, matchLine.length()-1).lastIndexOf(':'); + //ok fileName = matchLine.substring(0, matchLine.indexOf(':')); + fileName = matchLine.substring(0, semiBeforeNumber); + try { + lineNumber = Integer.parseInt(matchLine.substring(semiBeforeNumber+1, matchLine.lastIndexOf(':'))); + } + catch (NumberFormatException nfe) { + lineNumber = -1; + nfe.printStackTrace(); + } + + } catch (BadLocationException e1) { + e1.printStackTrace(); + } + try { + if (projectLocation != null && fileName != null) { + filePath = findFileResourceByLocation(projectLocation.append(fileName).toOSString()); + if (filePath == null || !filePath.exists()) + filePath = findFileResourceByLocation(new Path(fileName).toOSString()); + } + if (filePath != null && filePath.exists()) { + if (lineNumber < 0) lineNumber = 0; + currentListeningConsole.addHyperlink(new FileLink( filePath, null, -1, -1, lineNumber), event.getOffset(), event.getLength()); + } + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + } + + + public static IFile findFileResourceByLocation (String FileLocation) { + IPath ResourcePath = new Path(FileLocation); + if (!ResourcePath.isAbsolute()) { + //this methods does not support relative paths + return null; + } + else { + IFile[] Files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(ResourcePath); + return (Files.length > 0) ? Files[0] : null; + } + } + +}