Bug 2891 - Better user experience for stepping into preview system code
authorEugene Ostroukhov <eugeneo@symbian.org>
Thu, 10 Jun 2010 11:52:23 -0700
changeset 368 749e38c3b756
parent 367 f0817aeb2d7e
child 369 0a31422d2116
Bug 2891 - Better user experience for stepping into preview system code
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WebApplicationSourceLocator.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java
org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/SymbianDebugModelPresentation.java
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java	Wed Jun 09 15:16:09 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WRTProjectWorkspaceBridge.java	Thu Jun 10 11:52:23 2010 -0700
@@ -23,6 +23,7 @@
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer;
 import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer;
 import org.symbian.tools.wrttools.debug.internal.Activator;
 import org.symbian.tools.wrttools.debug.internal.model.ResourceManager;
@@ -65,7 +66,8 @@
         ILaunch launch = debugTargetImpl.getLaunch();
         try {
             sourceLocator.initializeDefaults(launch.getLaunchConfiguration());
-            sourceLocator.setSourceContainers(new ISourceContainer[] { new ProjectSourceContainer(project, false) });
+            sourceLocator.setSourceContainers(new ISourceContainer[] { new ProjectSourceContainer(project, false),
+                    new DirectorySourceContainer(Activator.getDefault().getStateLocation(), true) });
         } catch (CoreException e) {
             throw new RuntimeException(e);
         }
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WebApplicationSourceLocator.java	Wed Jun 09 15:16:09 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WebApplicationSourceLocator.java	Thu Jun 10 11:52:23 2010 -0700
@@ -18,13 +18,22 @@
  */
 package org.symbian.tools.wrttools.debug.internal.launch;
 
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import org.chromium.debug.core.model.StackFrame;
 import org.chromium.sdk.Script;
 import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.debug.core.model.ISourceLocator;
 import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
@@ -34,13 +43,17 @@
 import org.symbian.tools.wrttools.debug.internal.Activator;
 import org.symbian.tools.wrttools.debug.internal.model.ResourceManager;
 import org.symbian.tools.wrttools.previewer.PreviewerPlugin;
+import org.symbian.tools.wrttools.previewer.http.WebappManager;
 
 public final class WebApplicationSourceLocator extends AbstractSourceLookupDirector implements ISourceLocator,
         ISourceLookupDirector {
     public static final class WebApplicationSourceLookupParticipant extends AbstractSourceLookupParticipant {
         private final ResourceManager resourceManager;
+        private final WebApplicationSourceLocator locator;
 
-        public WebApplicationSourceLookupParticipant(ResourceManager resourceManager) {
+        public WebApplicationSourceLookupParticipant(WebApplicationSourceLocator locator,
+                ResourceManager resourceManager) {
+            this.locator = locator;
             this.resourceManager = resourceManager;
         }
 
@@ -57,6 +70,8 @@
                 IFile resource = resourceManager.getResource(script);
                 if (resource != null) {
                     return resource.getProjectRelativePath().toString();
+                } else {
+                    return locator.fileUrl(script);
                 }
             }
             return null;
@@ -69,6 +84,35 @@
         this.resourceManager = resourceManager;
     }
 
+    public String fileUrl(Script script) throws CoreException {
+        String name = script.getName();
+        try {
+            URI uri = new URI(name);
+            if ("http".equals(uri.getScheme()) && WebappManager.getHost().equals(uri.getHost())
+                    && WebappManager.getPort() == uri.getPort()) {
+                final IPath stateLocation = Activator.getDefault().getStateLocation();
+                final IPath path = stateLocation.append("systemlibraries")
+                        .append(new Path(uri.getPath()).lastSegment());
+                final File file = path.toFile();
+                file.getParentFile().mkdirs();
+                final String source = script.getSource();
+                final BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+                try {
+                    writer.write(source);
+                } finally {
+                    writer.close();
+                }
+                return new Path(file.getParentFile().getName()).append(file.getName()).toString();
+            }
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e);
+        } catch (IOException e) {
+            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                    "Cannot load web runtime system libraries", e));
+        }
+        return null;
+    }
+
     public Object getSourceElement(IStackFrame stackFrame) {
 		if (stackFrame instanceof StackFrame == false) {
 			return null;
@@ -97,6 +141,7 @@
 	}
 
     public void initializeParticipants() {
-        addParticipants(new ISourceLookupParticipant[] { new WebApplicationSourceLookupParticipant(resourceManager) });
+        addParticipants(new ISourceLookupParticipant[] { new WebApplicationSourceLookupParticipant(this,
+                resourceManager) });
     }
 }
\ No newline at end of file
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java	Wed Jun 09 15:16:09 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/launch/WrtLabelProvider.java	Thu Jun 10 11:52:23 2010 -0700
@@ -9,6 +9,7 @@
 import org.chromium.sdk.DebugContext;
 import org.chromium.sdk.ExceptionData;
 import org.chromium.sdk.Script;
+import org.eclipse.core.filesystem.IFileStore;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.osgi.util.NLS;
@@ -31,6 +32,8 @@
                         .getName();
                 name = NLS.bind("{0} [{1}:{2}]", new Object[] { name, resourcePath, line });
             }
+        } else if (element instanceof IFileStore) {
+            return "(WRT System Library)";
         }
         return name;
     }
--- a/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/SymbianDebugModelPresentation.java	Wed Jun 09 15:16:09 2010 -0700
+++ b/org.symbian.tools.wrttools.debug.core/src/org/symbian/tools/wrttools/debug/internal/model/SymbianDebugModelPresentation.java	Thu Jun 10 11:52:23 2010 -0700
@@ -4,7 +4,7 @@
 import org.eclipse.core.filesystem.IFileStore;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.resources.IStorage;
 import org.eclipse.debug.core.model.IBreakpoint;
 import org.eclipse.debug.core.model.ILineBreakpoint;
 import org.eclipse.debug.core.model.IValue;
@@ -18,6 +18,8 @@
 import org.eclipse.ui.ide.FileStoreEditorInput;
 import org.eclipse.ui.ide.IDE;
 import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.jsdt.core.JavaScriptCore;
+import org.eclipse.wst.jsdt.internal.ui.javaeditor.JarEntryEditorInput;
 import org.eclipse.wst.jsdt.ui.JavaScriptUI;
 
 public class SymbianDebugModelPresentation extends LabelProvider implements
@@ -54,13 +56,17 @@
 		return toEditorInput(element);
 	}
 
-	public static IEditorInput toEditorInput(Object element) {
+    @SuppressWarnings("restriction")
+    public static IEditorInput toEditorInput(Object element) {
 		if (element instanceof IFile) {
 			return new FileEditorInput((IFile) element);
 		}
 		if (element instanceof IFileStore) {
 			return new FileStoreEditorInput((IFileStore) element);
 		}
+        if (element instanceof IStorage) {
+            return new JarEntryEditorInput((IStorage) element);
+        }
 
 		if (element instanceof ILineBreakpoint) {
 			return new FileEditorInput((IFile) ((ILineBreakpoint) element)
@@ -98,11 +104,10 @@
 				return null;
 			}
 		} else {
-			if (element instanceof IFileStore) {
-				IFileStore store = (IFileStore) element;
-				String ext = new Path(store.getName()).getFileExtension();
-				if (ext.equals("js")) {
-					return JavaScriptUI.ID_CU_EDITOR;
+            if (element instanceof IStorage) {
+                IStorage store = (IStorage) element;
+                if (JavaScriptCore.isJavaScriptLikeFileName(store.getName())) {
+                    return JavaScriptUI.ID_CU_EDITOR;
 				} else {
 					return "org.eclipse.wst.html.core.htmlsource.source";
 				}