[jbosstools-issues] [JBoss JIRA] Commented: (JBIDE-989) Provide hyperlinking in console for property/page errors

Max Andersen (JIRA) jira-events at lists.jboss.org
Sun Oct 7 14:47:03 EDT 2007


    [ http://jira.jboss.com/jira/browse/JBIDE-989?page=comments#action_12380877 ] 
            
Max Andersen commented on JBIDE-989:
------------------------------------

Victor - I actually got an implementation for this done this afternoon.

Here is a patch; let me know if you want me to commit this or yours have other/better features (i'm missing logging of errors - but thats a trivial fix)

Index: /home/max/work/os/jbosstools/trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/console/PropertyNotFoundMatcher.java
===================================================================
--- /home/max/work/os/jbosstools/trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/console/PropertyNotFoundMatcher.java	(revision 0)
+++ /home/max/work/os/jbosstools/trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/console/PropertyNotFoundMatcher.java	(revision 0)
@@ -0,0 +1,223 @@
+package org.jboss.ide.eclipse.as.ui.console;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+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.core.ILaunch;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.ISourceLocator;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
+import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.console.FileLink;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.ui.console.IHyperlink;
+import org.eclipse.ui.console.IPatternMatchListenerDelegate;
+import org.eclipse.ui.console.PatternMatchEvent;
+import org.eclipse.ui.console.TextConsole;
+
+/**
+ * Pattern matcher to provide linking for 
+ * Caused by: Exception: /login.xhtml @23,66 value="#{identity.usernamedoesnotexists}": Property 'usernamedoesnotexists' not found on type org.jboss.seam.security.RuleBasedIdentity
+
+ * @author max
+ *
+ */
+// TODO: add logging, but AS plugins has no logging support ;(
+public class PropertyNotFoundMatcher implements IPatternMatchListenerDelegate {
+
+	private TextConsole console;
+
+	static final Pattern resourceLocationPattern = Pattern.compile("Exception: (.*) @(\\d+),(\\d+)");
+	
+	public void connect(TextConsole console) {
+		this.console = console;
+	}
+
+	public void disconnect() {
+		console = null;
+	}
+
+	
+	public void matchFound(PatternMatchEvent event) {
+
+		String line = null;
+		try {
+			line = console.getDocument().get(event.getOffset(),
+					event.getLength());
+		} catch (BadLocationException e1) {
+			return;
+		}
+
+		
+
+		Matcher matcher;
+		synchronized (resourceLocationPattern) {
+			matcher = resourceLocationPattern.matcher(line);
+		}
+
+		String resource = null, lineNum, columnNum = null;
+		int resourceStart = -1, resourceEnd = -1, columnEnd = -1;
+		if (matcher.find()) {
+			resource = matcher.group(1);
+			resourceStart = matcher.start(1);
+			resourceEnd = matcher.end(1);
+
+			lineNum = matcher.group(2);
+			columnNum = matcher.group(3);
+            columnEnd = matcher.end(3);
+			CustomFileLink customFileLink = new CustomFileLink(console,
+					resource, lineNum);
+			try {
+				console.addHyperlink(customFileLink, event.getOffset()+resourceStart, columnEnd
+						- resourceStart);
+			} catch (BadLocationException e) {
+				// Can't do anything
+				return;
+			}
+		}
+				
+	}
+
+	static class CustomFileLink implements IHyperlink {
+
+		private TextConsole console;
+		private final String resource;
+		private final String lineNum;
+
+		CustomFileLink(TextConsole console, String resourceName, String lineNum) {
+			this.console = console;
+			this.resource = resourceName;
+			this.lineNum = lineNum;
+		}
+
+		private ILaunch getLaunch() {
+			IProcess process = (IProcess) console
+					.getAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS);
+			if (process != null) {
+				return process.getLaunch();
+			}
+			return null;
+		}
+
+		public void linkActivated() {
+			ILaunch launch = getLaunch();
+			if (launch != null) {
+				FileLink launchSpecificFile = getLaunchSpecificFile(launch);
+				if (launchSpecificFile != null) {
+					launchSpecificFile.linkActivated();
+				}
+			} else { // no launch associated, search recursively all
+						// projects.
+				FileLink launchSpecificFile = findFileInWorkspace();
+				if (launchSpecificFile != null) {
+					launchSpecificFile.linkActivated();
+				}				
+			}
+
+		}
+
+		private FileLink findFileInWorkspace() {
+			final String simpleName = resource.substring(resource
+					.lastIndexOf("/") + 1);
+
+			IPath path = new Path(resource);
+			IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
+					.getProjects();
+
+			final String finalResource = resource;
+
+			final List<IFile> files = new ArrayList<IFile>();
+			for (int i = 0; i < projects.length && files.isEmpty(); i++) {
+				IProject project = projects[i];
+				try {
+					project.accept(new IResourceProxyVisitor() {
+
+						public boolean visit(IResourceProxy proxy)
+								throws CoreException {
+							if (proxy.requestResource().getType() != IResource.FILE) {
+								return true;
+							}
+							String n = proxy.getName();
+
+							if (n.equals(simpleName)) {
+								IPath requestFullPath = proxy.requestFullPath();
+								if (requestFullPath.toOSString().endsWith(
+										finalResource)) {
+									files.add((IFile) proxy.requestResource());
+								}
+							}
+							return true;
+						}
+
+					}, 0);
+				} catch (CoreException e1) {
+					//
+
+				}
+			}
+
+			if (files.size() != 0) {
+				IFile file = (IFile) files.get(0);
+				if (file != null && file.exists()) {
+					FileLink link = new FileLink(file, null, -1, -1, Integer
+							.parseInt(lineNum));
+					return link;
+				}
+			}
+
+			return null;
+		}
+
+		private FileLink getLaunchSpecificFile(ILaunch launch) {
+			try {
+				Object resolveSourceElement = resolveSourceElement(resource,
+						launch);
+				if (resolveSourceElement != null
+						&& resolveSourceElement instanceof IFile) {
+					IFile file = (IFile) resolveSourceElement;
+					FileLink link = new FileLink(file, null, -1, -1, Integer
+							.parseInt(lineNum));
+					return link;
+				}
+			} catch (CoreException e) {
+				// resolveSourceElement somehow failed
+			}
+
+			return null;
+		}
+
+		/** Try and locate a file via the launch support for sourcelookup */
+		private static Object resolveSourceElement(Object object, ILaunch launch)
+				throws CoreException {
+			ISourceLocator sourceLocator = launch.getSourceLocator();
+			if (sourceLocator instanceof ISourceLookupDirector) {
+				ISourceLookupDirector director = (ISourceLookupDirector) sourceLocator;
+				Object[] objects = director.findSourceElements(object);
+				if (objects.length > 0) {
+					return objects[0];
+				}
+			}
+			return null;
+		}
+
+		public void linkEntered() {
+			 // noop
+		}
+
+		public void linkExited() {
+			// noop
+		}
+
+	}
+}
Index: /home/max/work/os/jbosstools/trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
===================================================================
--- /home/max/work/os/jbosstools/trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml	(revision 3993)
+++ /home/max/work/os/jbosstools/trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml	(working copy)
@@ -311,6 +311,21 @@
       </action> 
    </objectContribution> 
 </extension>
+   <extension
+         point="org.eclipse.ui.console.consolePatternMatchListeners">
+      <consolePatternMatchListener
+            class="org.jboss.ide.eclipse.as.ui.console.PropertyNotFoundMatcher"
+            id="org.jboss.ide.eclipse.as.ui.console.PropertyNotFound"
+            regex="Exception.*: .* @[0-9]+,[0-9]+ ">
+         <enablement>
+         <or>
+			  <test property="org.eclipse.ui.console.consoleTypeTest" value="javaStackTraceConsole"/>
+               <test property="org.eclipse.debug.ui.processTypeTest" value="java"/>
+               <test property="org.eclipse.debug.ui.processTypeTest" value="org.eclipse.ant.ui.antProcess"/>
+            </or>
+         </enablement>
+      </consolePatternMatchListener>
+   </extension>
    
 
 </plugin>


> Provide hyperlinking in console for property/page errors
> --------------------------------------------------------
>
>                 Key: JBIDE-989
>                 URL: http://jira.jboss.com/jira/browse/JBIDE-989
>             Project: JBoss Tools
>          Issue Type: Feature Request
>          Components: JBoss Tools Core
>    Affects Versions: 2.0.0.Beta3, 2.0.0.Beta4
>            Reporter: Max Andersen
>         Assigned To: Victor Rubezhny
>             Fix For: 2.0.0.CR1
>
>
> If a property is wrong an exception like this is shown in the console of JBoss AS:
> Caused by: javax.el.PropertyNotFoundException: /anotherPing.xhtml @20,52 action="#{thirdPing.anotherPing}": Target Unreachable, identifier 'thirdPing' resolved to null
> 	at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:70)
> 	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
> The class names and stacktrace locations are highlighted.
> We should add support for linking   /anotherPing.xhtml @20,52 (there might be multiple matches since the as can contain multiple projects so if we can't decide between them we need to show a list of the possible matches)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jbosstools-issues mailing list