### Eclipse Workspace Patch 1.0
#P org.eclipse.wst.jsdt.debug.core
Index: plugin.xml
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.core/plugin.xml,v
retrieving revision 1.11
diff -u -r1.11 plugin.xml
--- plugin.xml 8 Mar 2011 02:21:37 -0000 1.11
+++ plugin.xml 17 Nov 2011 20:39:44 -0000
@@ -13,6 +13,7 @@
+
+
+
+
+
Index: schema/scriptResolvers.exsd
===================================================================
RCS file: schema/scriptResolvers.exsd
diff -N schema/scriptResolvers.exsd
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ schema/scriptResolvers.exsd 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,128 @@
+
+
+
+
+
+
+
+
+ This extension point is used to contribute a script solver that is consulted any place in JSDT where a <code>ScriptReference</code> must be resolved to a workspace-local <code>IFile</code>.
+<br><br>
+An example of typical usage is resolving if a breakpoint's workspace path matches that of a given <code>ScriptReference</code>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ A resolver that can help determine equality between workspace-local IFiles and JavaScript ScriptReferences
+
+
+
+
+
+
+ The fully qualified name of the Java class that implements org.eclipse.wst.jsdt.debug.core.model.IScriptResolver
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 3.4
+
+
+
+
+
+
+
+
+ The following is an example of the default script resolver:
+<pre>
+ <extension point="org.eclipse.wst.jsdt.debug.core.scriptResolvers">
+ <scriptResolver
+ class="org.eclipse.wst.jsdt.debug.internal.core.model.DefaultScriptResolver">
+ </scriptResolver>
+ </extension>
+</pre>
+
+
+
+
+
+
+
+
+ The class field must specify the fully qualified name of the the class the implements <code>org.eclipse.wst.jsdt.debug.core.model.IScriptResolver.java</code>.
+
+
+
+
+
+
+
+
+ [Enter information about supplied implementation of this extension point.]
+
+
+
+
+
+
+
+
+ Copyright (c) 2011 IBM Corporation and others.<br>
+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
+<a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>
+
+
+
+
Index: src/org/eclipse/wst/jsdt/debug/core/model/IScriptResolver.java
===================================================================
RCS file: src/org/eclipse/wst/jsdt/debug/core/model/IScriptResolver.java
diff -N src/org/eclipse/wst/jsdt/debug/core/model/IScriptResolver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/jsdt/debug/core/model/IScriptResolver.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.core.model;
+
+import java.net.URI;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
+
+/**
+ * This resolver allows contributors to plug-in to the process of resolving a {@link ScriptReference}'s
+ * {@link URI} to a workspace-local {@link IFile}.
+
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 3.4
+ */
+public interface IScriptResolver {
+
+ /**
+ * This method determines if the given {@link IPath} matches the {@link URI} from {@link ScriptReference#sourceURI()}.
+
+ * @param script the {@link ScriptReference} to compare the source {@link URI} from - never null
+ * @param path the path to match against the source {@link URI} - never null
+ *
+ * @return true
if the source {@link URI} of the given {@link ScriptReference} is considered to match the given {@link IPath}, false
otherwise.
+ */
+ public boolean matches(ScriptReference script, IPath path);
+
+ /**
+ * This method is used to find the workspace {@link IFile} that corresponds to the source {@link URI} from the given {@link ScriptReference}.
+ *
+ * If no file can be determined the method must return null
. The result will be checked for existence.
+ *
+ * @param script the {@link ScriptReference} to find the {@link IFile} for
+ * @return the {@link IFile} for the {@link ScriptReference} or null
+ */
+ public IFile getFile(ScriptReference script);
+}
Index: src/org/eclipse/wst/jsdt/debug/internal/core/Constants.java
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/Constants.java,v
retrieving revision 1.8
diff -u -r1.8 Constants.java
--- src/org/eclipse/wst/jsdt/debug/internal/core/Constants.java 27 Oct 2010 19:12:39 -0000 1.8
+++ src/org/eclipse/wst/jsdt/debug/internal/core/Constants.java 17 Nov 2011 20:39:45 -0000
@@ -73,6 +73,11 @@
* The name of the launching connectors extension point
*/
static final String LAUNCHING_CONNECTORS = "launchingConnectors"; //$NON-NLS-1$
+ /**
+ * The name of the script resolvers extension point
+ * @since 3.4
+ */
+ static final String SCRIPT_RESOLVERS = "scriptResolvers"; //$NON-NLS-1$
//######### PREFERENCES ############
/**
Index: src/org/eclipse/wst/jsdt/debug/internal/core/JavaScriptDebugPlugin.java
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/JavaScriptDebugPlugin.java,v
retrieving revision 1.13
diff -u -r1.13 JavaScriptDebugPlugin.java
--- src/org/eclipse/wst/jsdt/debug/internal/core/JavaScriptDebugPlugin.java 7 Jul 2011 17:22:21 -0000 1.13
+++ src/org/eclipse/wst/jsdt/debug/internal/core/JavaScriptDebugPlugin.java 17 Nov 2011 20:39:45 -0000
@@ -27,6 +27,7 @@
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.wst.jsdt.debug.internal.core.launching.ConnectorsManager;
import org.eclipse.wst.jsdt.debug.internal.core.model.BreakpointParticipantManager;
+import org.eclipse.wst.jsdt.debug.internal.core.model.ScriptResolutionManager;
import org.osgi.framework.BundleContext;
/**
@@ -64,6 +65,10 @@
*/
private static JavaScriptPreferencesManager prefmanager = null;
/**
+ * Singleton {@link ScriptResolutionManager}
+ */
+ private static ScriptResolutionManager resolutionmanager = null;
+ /**
* Handle to the 'External JavaScript Source' project
*/
private static IProject extSrcProject = null;
@@ -94,6 +99,18 @@
}
/**
+ * Returns the singleton {@link ScriptResolutionManager}
+ * @return the {@link ScriptResolutionManager}
+ * @since 3.4
+ */
+ public static synchronized ScriptResolutionManager getResolutionManager() {
+ if(resolutionmanager == null) {
+ resolutionmanager = new ScriptResolutionManager();
+ }
+ return resolutionmanager;
+ }
+
+ /**
* Returns the current handle to the 'External JavaScript Source' project or null
. If the project
* is not accessible it can be created by passing true
in for the create parameter.
*
Index: src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptBreakpoint.java
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptBreakpoint.java,v
retrieving revision 1.18
diff -u -r1.18 JavaScriptBreakpoint.java
--- src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptBreakpoint.java 21 Mar 2011 14:08:20 -0000 1.18
+++ src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptBreakpoint.java 17 Nov 2011 20:39:45 -0000
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.core.breakpoints;
-import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -20,7 +19,6 @@
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -43,7 +41,6 @@
import org.eclipse.wst.jsdt.debug.core.model.JavaScriptDebugModel;
import org.eclipse.wst.jsdt.debug.internal.core.Constants;
import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
-import org.eclipse.wst.jsdt.debug.internal.core.Messages;
import org.eclipse.wst.jsdt.debug.internal.core.launching.SourceLookup;
import org.eclipse.wst.jsdt.debug.internal.core.model.IJavaScriptEventListener;
import org.eclipse.wst.jsdt.debug.internal.core.model.JavaScriptDebugTarget;
@@ -61,7 +58,7 @@
* The total count of all of the targets this breakpoint is installed in
*/
public static final String INSTALL_COUNT = JavaScriptDebugPlugin.PLUGIN_ID + ".install_count"; //$NON-NLS-1$
-
+
private HashSet targets = null;
private HashMap requestspertarget = new HashMap(4);
@@ -165,8 +162,9 @@
boolean success = true;
for (Iterator iter = scripts.iterator(); iter.hasNext();) {
ScriptReference script = (ScriptReference) iter.next();
- if (scriptPathMatches(script))
+ if (JavaScriptDebugPlugin.getResolutionManager().matches(script, new Path(getScriptPath()))) {
success &= createRequest(target, script);
+ }
}
if (success) {
if (this.targets == null) {
@@ -437,8 +435,9 @@
ScriptReference script = sevent.script();
try {
- if (scriptPathMatches(script))
+ if (JavaScriptDebugPlugin.getResolutionManager().matches(script, new Path(getScriptPath()))) {
createRequest(target, script);
+ }
} catch (CoreException ce) {
JavaScriptDebugPlugin.log(ce);
}
@@ -446,26 +445,6 @@
return true;
}
- protected boolean scriptPathMatches(ScriptReference script) throws CoreException {
- URI sourceURI = script.sourceURI();
- if ("file".equals(sourceURI.getScheme())) {//$NON-NLS-1$
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
- URI workspaceURI = workspaceRoot.getRawLocationURI();
- sourceURI = workspaceURI.relativize(sourceURI);
- }
- String path = getScriptPath();
- IPath spath = new Path(path);
- if(spath.segment(0).equals(Messages.external_javascript_source)) {
- spath = spath.removeFirstSegments(1).makeAbsolute();
- }
- //XXX use the same algorithm we use to save the source to 'encode' the source URI for comparison
- IPath uripath = SourceLookup.getSourcePath(sourceURI);
- if(uripath != null) {
- uripath = uripath.makeAbsolute();
- }
- return spath.equals(uripath);
- }
-
/**
* Returns if the type names for the breakpoint are equal or not. Two null
type names are considered to be equal.
*
Index: src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptLoadBreakpoint.java
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptLoadBreakpoint.java,v
retrieving revision 1.15
diff -u -r1.15 JavaScriptLoadBreakpoint.java
--- src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptLoadBreakpoint.java 15 Nov 2011 21:51:08 -0000 1.15
+++ src/org/eclipse/wst/jsdt/debug/internal/core/breakpoints/JavaScriptLoadBreakpoint.java 17 Nov 2011 20:39:45 -0000
@@ -20,6 +20,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.wst.jsdt.debug.core.breakpoints.IJavaScriptBreakpointParticipant;
@@ -102,7 +103,10 @@
ScriptReference script = sevent.script();
JavaScriptThread thread = target.findThread((sevent).thread());
if (thread != null) {
- if(isGlobalLoadSuspend(target.getVM())) {
+ if(isGlobalLoadSuspend()) {
+ if(!supportsGlobalSuspend(target.getVM())) {
+ return true;
+ }
JavaScriptPreferencesManager.setGlobalSuspendOn(script.sourceURI().toString());
thread.addBreakpoint(this);
return false;
@@ -126,7 +130,7 @@
*/
private boolean isMatchedScriptLoadSuspend(ScriptReference script, JavaScriptThread thread, boolean suspendVote) {
try {
- if (scriptPathMatches(script)) {
+ if (JavaScriptDebugPlugin.getResolutionManager().matches(script, new Path(getScriptPath()))) {
int vote = thread.suspendForScriptLoad(this, script, suspendVote);
return (vote & IJavaScriptBreakpointParticipant.SUSPEND) > 0 || vote == IJavaScriptBreakpointParticipant.DONT_CARE;
}
@@ -138,11 +142,12 @@
}
/**
- * Returns if this breakpoint supports global suspend
+ * Use reflection hack to opt-out of global suspend
*
- * @return true
if we should suspend on all script loads false
otherwise
+ * @param vm
+ * @return true
if the backing {@link VirtualMachine} supports global suspend
*/
- private boolean isGlobalLoadSuspend(VirtualMachine vm) {
+ boolean supportsGlobalSuspend(VirtualMachine vm) {
boolean supports = true;
try {
//TODO consider supportsSuspendOnScriptLoads for future VirtualMachine extensions
@@ -153,8 +158,17 @@
//assume the method is not there / problematic
supports = true;
}
+ return supports;
+ }
+
+ /**
+ * Returns if this breakpoint supports global suspend
+ *
+ * @return true
if we should suspend on all script loads false
otherwise
+ */
+ private boolean isGlobalLoadSuspend() {
try {
- return supports && ensureMarker().getAttribute(GLOBAL_SUSPEND, false);
+ return ensureMarker().getAttribute(GLOBAL_SUSPEND, false);
}
catch(CoreException ce) {
JavaScriptDebugPlugin.log(ce);
Index: src/org/eclipse/wst/jsdt/debug/internal/core/launching/SourceLookup.java
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.core/src/org/eclipse/wst/jsdt/debug/internal/core/launching/SourceLookup.java,v
retrieving revision 1.11
diff -u -r1.11 SourceLookup.java
--- src/org/eclipse/wst/jsdt/debug/internal/core/launching/SourceLookup.java 7 Oct 2011 18:56:04 -0000 1.11
+++ src/org/eclipse/wst/jsdt/debug/internal/core/launching/SourceLookup.java 17 Nov 2011 20:39:45 -0000
@@ -40,7 +40,7 @@
public final class SourceLookup {
public static final QualifiedName SCRIPT_URL = new QualifiedName(JavaScriptCore.PLUGIN_ID, "scriptURL"); //$NON-NLS-1$
-
+ public static final IPath TOP_LEVEL_PATH = new Path("/"); //$NON-NLS-1$
/**
* Returns the name of the source object to lookup or null
* if the object is not a {@link IJavaScriptStackFrame} or an {@link IScript}
@@ -50,12 +50,15 @@
* @since 1.1
*/
public static String getSourceName(Object object) {
+ String name = null;
if (object instanceof IJavaScriptStackFrame) {
- return ((IJavaScriptStackFrame) object).getSourceName();
+ name = ((IJavaScriptStackFrame) object).getSourceName();
}
if(object instanceof IScript) {
- String name = URIUtil.lastSegment(((IScript)object).sourceURI());
- if(!JavaScriptCore.isJavaScriptLikeFileName(name)) {
+ name = URIUtil.lastSegment(((IScript)object).sourceURI());
+ }
+ if(name != null) {
+ if(new Path(name).getFileExtension() == null) {
//append .js, there is no case where we would look up a file with no extension from a script node
StringBuffer buf = new StringBuffer(name.length()+3);
buf.append(name).append('.').append(Constants.JS_EXTENSION);
@@ -165,7 +168,7 @@
return null;
}
if(uripath.trim().equals("/")) { //$NON-NLS-1$
- uripath = "page.js"; //$NON-NLS-1$
+ uripath = "index.htm"; //$NON-NLS-1$
}
String host = sourceuri.getHost();
IPath path = null;
@@ -244,7 +247,7 @@
newpath = newpath.append((String) segments.get(i));
}
String ext = newpath.getFileExtension();
- if(ext == null || !Constants.JS_EXTENSION.equals(ext)) {
+ if(ext == null && !Constants.JS_EXTENSION.equals(ext)) {
newpath = newpath.addFileExtension(Constants.JS_EXTENSION);
}
return newpath;
Index: src/org/eclipse/wst/jsdt/debug/internal/core/model/DefaultScriptResolver.java
===================================================================
RCS file: src/org/eclipse/wst/jsdt/debug/internal/core/model/DefaultScriptResolver.java
diff -N src/org/eclipse/wst/jsdt/debug/internal/core/model/DefaultScriptResolver.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/jsdt/debug/internal/core/model/DefaultScriptResolver.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.core.model;
+
+import java.net.URI;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
+import org.eclipse.wst.jsdt.debug.core.model.IScriptResolver;
+import org.eclipse.wst.jsdt.debug.internal.core.Messages;
+import org.eclipse.wst.jsdt.debug.internal.core.launching.SourceLookup;
+
+/**
+ * Default implementation of an {@link IScriptResolver}
+ * @since 3.4
+ */
+public class DefaultScriptResolver implements IScriptResolver {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.model.IScriptResolver#matches(org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference, org.eclipse.core.runtime.IPath)
+ */
+ public boolean matches(ScriptReference script, IPath path) {
+ if(guessScriptMatches(script, path)) {
+ return true;
+ }
+ //no luck, try an exact match
+ URI sourceURI = script.sourceURI();
+ if (URIUtil.isFileURI(sourceURI)) {
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ URI workspaceURI = workspaceRoot.getRawLocationURI();
+ sourceURI = workspaceURI.relativize(sourceURI);
+ }
+ IPath spath = path;
+ if(spath.segmentCount() > 0 && spath.segment(0).equals(Messages.external_javascript_source)) {
+ spath = spath.removeFirstSegments(1).makeAbsolute();
+ }
+ IPath uripath = SourceLookup.getSourcePath(sourceURI);
+ if(uripath != null) {
+ uripath = uripath.makeAbsolute();
+ }
+ return spath.equals(uripath);
+ }
+
+ /**
+ * Guesses if the paths are considered equal by walking backward from the last segment of the paths and counting the matching segments.
+ * The paths are guessed to be equal iff any two or more segments match in order.
+ *
+ * @param script the {@link ScriptReference}
+ * @param path the path to compare
+ * @return true
if the paths 'match', false
otherwise
+ */
+ boolean guessScriptMatches(ScriptReference script, IPath path) {
+ IPath newpath = path.makeAbsolute();
+ IPath uri = new Path(script.sourceURI().getPath());
+ if(SourceLookup.TOP_LEVEL_PATH.equals(newpath) && SourceLookup.TOP_LEVEL_PATH.equals(uri)) {
+ return true;
+ }
+ uri = uri.makeAbsolute();
+ int matched_segments = 0;
+ int last = uri.segmentCount()-1;
+ for(int i = newpath.segmentCount()-1; i > -1; i--) {
+ if(last < 0) {
+ break;
+ }
+ if(newpath.segment(i).equals(uri.segment(last))) {
+ matched_segments++;
+ last--;
+ }
+ }
+ return matched_segments > 1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.model.IScriptResolver#getFile(org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference)
+ */
+ public IFile getFile(ScriptReference script) {
+ IPath p = SourceLookup.getSourcePath(script.sourceURI());
+ IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(p);
+ if(res.getType() == IResource.FILE) {
+ return (IFile) res;
+ }
+ return null;
+ }
+}
\ No newline at end of file
Index: src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolutionManager.java
===================================================================
RCS file: src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolutionManager.java
diff -N src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolutionManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolutionManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.core.model;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
+import org.eclipse.wst.jsdt.debug.core.model.IScriptResolver;
+import org.eclipse.wst.jsdt.debug.internal.core.Constants;
+import org.eclipse.wst.jsdt.debug.internal.core.JavaScriptDebugPlugin;
+
+/**
+ * Handles the collection of {@link ScriptResolverExtension}s and provide useful utilities for path / script handling
+ * @since 3.4
+ */
+public final class ScriptResolutionManager {
+
+ static IScriptResolver[] NO_RESOLVERS = new IScriptResolver[0];
+ ListenerList resolvers = null;
+
+ /**
+ * This is a convenience method that consults all of the registered {@link IScriptResolver}s.
+ *
+ * This method will return true
iff any one (or all) of the {@link IScriptResolver}s returns true
+ * @param script the script to check
+ * @param path the path to compare against
+ * @return true
if any one (or all) of the {@link IScriptResolver}s return true
, false
otherwise
+ */
+ public boolean matches(ScriptReference script, IPath path) {
+ IScriptResolver[] res = getResolvers();
+ for (int i = 0; i < res.length; i++) {
+ if(res[i].matches(script, path)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the complete listing of {@link IScriptResolver}s or an empty array, never null
+ *
+ * @return the complete listing of {@link IScriptResolver}s
+ */
+ public IScriptResolver[] getResolvers() {
+ loadResolvers();
+ if(resolvers.size() < 1) {
+ return NO_RESOLVERS;
+ }
+ List res = Arrays.asList(resolvers.getListeners());
+ return (IScriptResolver[]) res.toArray(new IScriptResolver[res.size()]);
+ }
+
+ /**
+ * load up all the extension points to the delegate listeners
+ */
+ void loadResolvers() {
+ if(resolvers == null) {
+ resolvers = new ListenerList();
+ IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(JavaScriptDebugPlugin.PLUGIN_ID, Constants.SCRIPT_RESOLVERS);
+ IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
+ for (int i = 0; i < elements.length; i++) {
+ resolvers.add(new ScriptResolverExtension(elements[i]));
+ }
+ }
+ }
+
+ /**
+ * Clean up
+ */
+ public void dispose() {
+ if(resolvers != null) {
+ resolvers.clear();
+ resolvers = null;
+ }
+ }
+}
Index: src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolverExtension.java
===================================================================
RCS file: src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolverExtension.java
diff -N src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolverExtension.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/wst/jsdt/debug/internal/core/model/ScriptResolverExtension.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.jsdt.debug.internal.core.model;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference;
+import org.eclipse.wst.jsdt.debug.core.model.IScriptResolver;
+import org.eclipse.wst.jsdt.debug.internal.core.Constants;
+
+/**
+ * Default implementation of the delegate class for all {@link IScriptResolver}s
+ *
+ * @since 3.4
+ */
+public class ScriptResolverExtension implements IScriptResolver {
+
+ private IConfigurationElement element = null;
+ private IScriptResolver delegate = null;
+
+ /**
+ * Constructor
+ * @param element the backing {@link IConfigurationElement} to lazily load and delegate to
+ */
+ public ScriptResolverExtension(IConfigurationElement element) {
+ this.element = element;
+ }
+
+ /**
+ * Returns the delegate {@link IScriptResolver} from the backing {@link IConfigurationElement}
+ *
+ * @return the delegate {@link IScriptResolver}
+ * @throws CoreException thrown if the delegate class fails to be created
+ */
+ synchronized IScriptResolver getDelegate() throws CoreException {
+ if(delegate == null) {
+ delegate = (IScriptResolver) element.createExecutableExtension(Constants.CLASS);
+ }
+ return delegate;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.model.IScriptPathResolver#matches(org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference, org.eclipse.core.runtime.IPath)
+ */
+ public boolean matches(ScriptReference script, IPath path) {
+ try {
+ return getDelegate().matches(script, path);
+ }
+ catch(CoreException ce) {
+ return false;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.wst.jsdt.debug.core.model.IScriptPathResolver#getFile(org.eclipse.wst.jsdt.debug.core.jsdi.ScriptReference)
+ */
+ public IFile getFile(ScriptReference script) {
+ try {
+ return getDelegate().getFile(script);
+ }
+ catch(CoreException ce) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
#P org.eclipse.wst.jsdt.debug.ui
Index: plugin.xml
===================================================================
RCS file: /cvsroot/webtools/org.eclipse.jsdt/plugins/org.eclipse.wst.jsdt.debug.ui/plugin.xml,v
retrieving revision 1.31
diff -u -r1.31 plugin.xml
--- plugin.xml 21 Jun 2011 14:08:52 -0000 1.31
+++ plugin.xml 17 Nov 2011 20:39:46 -0000
@@ -89,6 +89,13 @@
type="org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider">
+
+
+
+