null
when no source root was found.
+ */
+ public String getSourceRoot(String url) {
+ return getContext().getSourceRoot(url);
+ }
/**
* Translates a relative path ("java/lang/Thread.java") to url
@@ -359,7 +370,15 @@
includeExtension
);
}
-
+
+ public String getSourceRoot(String url) {
+ String sourceRoot = cp1.getSourceRoot(url);
+ if (sourceRoot == null) {
+ sourceRoot = cp2.getSourceRoot(url);
+ }
+ return sourceRoot;
+ }
+
public String[] getSourceRoots () {
String[] fs1 = cp1.getSourceRoots ();
String[] fs2 = cp2.getSourceRoots ();
Index: api/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java
===================================================================
RCS file: /cvs/debuggerjpda/api/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java,v
retrieving revision 1.2
diff -u -r1.2 SourcePathProvider.java
--- api/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java 18 Oct 2004 14:57:49 -0000 1.2
+++ api/src/org/netbeans/spi/debugger/jpda/SourcePathProvider.java 3 May 2006 16:27:02 -0000
@@ -7,7 +7,7 @@
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
- * Code is Sun Micro//S ystems, Inc. Portions Copyright 1997-2001 Sun
+ * Code is Sun Micro//S ystems, Inc. Portions Copyright 1997-2006 Sun
* Micro//S ystems, Inc. All Rights Reserved.
*/
package org.netbeans.spi.debugger.jpda;
@@ -60,6 +60,18 @@
*/
public abstract String getURL (String relativePath, boolean global);
+ /**
+ * Returns the source root (if any) for given url.
+ *
+ * @param url a url of resource file
+ *
+ * @return the source root or null
when no source root was found.
+ * @since 2.6
+ */
+ public String getSourceRoot(String url) {
+ return null;
+ }
+
/**
* Returns array of source roots.
*/
Index: ant/src/org/netbeans/modules/debugger/projects/SourcePathProviderImpl.java
===================================================================
RCS file: /cvs/debuggerjpda/ant/src/org/netbeans/modules/debugger/projects/SourcePathProviderImpl.java,v
retrieving revision 1.12
diff -u -r1.12 SourcePathProviderImpl.java
--- ant/src/org/netbeans/modules/debugger/projects/SourcePathProviderImpl.java 2 Mar 2005 15:46:19 -0000 1.12
+++ ant/src/org/netbeans/modules/debugger/projects/SourcePathProviderImpl.java 3 May 2006 16:27:03 -0000
@@ -7,7 +7,7 @@
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
- * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
* Microsystems, Inc. All Rights Reserved.
*/
@@ -184,6 +184,37 @@
directorySeparator,
includeExtension
);
+ }
+
+ /**
+ * Returns the source root (if any) for given url.
+ *
+ * @param url a url of resource file
+ *
+ * @return the source root or null
when no source root was found.
+ */
+ public String getSourceRoot(String url) {
+ Iterator it = GlobalPathRegistry.getDefault().getSourceRoots().iterator();
+ while (it.hasNext()) {
+ FileObject fileObject = (FileObject) it.next ();
+ try {
+ String rootURL = fileObject.getURL().toString();
+ if (url.startsWith(rootURL)) {
+ File f = null;
+ if (fileObject.getFileSystem () instanceof JarFileSystem)
+ f = ((JarFileSystem) fileObject.getFileSystem ()).
+ getJarFile ();
+ else
+ f = FileUtil.toFile (fileObject);
+ if (f != null) {
+ return f.getAbsolutePath ();
+ }
+ }
+ } catch (FileStateInvalidException ex) {
+ // Invalid source root - skip
+ }
+ }
+ return null; // not found
}
/**
Index: test/unit/src/org/netbeans/api/debugger/jpda/test/TestEngineContextProvider.java
===================================================================
RCS file: /cvs/debuggerjpda/test/unit/src/org/netbeans/api/debugger/jpda/test/TestEngineContextProvider.java,v
retrieving revision 1.8
diff -u -r1.8 TestEngineContextProvider.java
--- test/unit/src/org/netbeans/api/debugger/jpda/test/TestEngineContextProvider.java 4 Jun 2005 05:16:04 -0000 1.8
+++ test/unit/src/org/netbeans/api/debugger/jpda/test/TestEngineContextProvider.java 3 May 2006 16:27:03 -0000
@@ -7,7 +7,7 @@
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
- * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
* Microsystems, Inc. All Rights Reserved.
*/
@@ -23,6 +23,10 @@
import java.net.URL;
import java.net.MalformedURLException;
import java.io.File;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileStateInvalidException;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.JarFileSystem;
/**
@@ -33,14 +37,20 @@
public class TestEngineContextProvider extends SourcePathProvider {
private String sourceRoot = System.getProperty ("test.dir.src");
+ private String home = System.getProperty("user.home");
private String[] originalSourceRoots = new String[] {
- sourceRoot
+ sourceRoot, home
};
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public TestEngineContextProvider (ContextProvider ctxProvider) {
// this.session = (Session) ctxProvider.lookupFirst (null, Session.class);
+ for (int i = 0; i < originalSourceRoots.length; i++) {
+ while (originalSourceRoots[i].endsWith(File.separator)) {
+ originalSourceRoots[i] = originalSourceRoots[i].substring(0, originalSourceRoots[i].length() - 1);
+ }
+ }
}
/**
@@ -108,6 +118,38 @@
public void setSourceRoots (String[] sourceRoots) {
}
+ public String getSourceRoot(String url) {
+ for (int i = 0; i < originalSourceRoots.length; i++) {
+ String sourceRoot = originalSourceRoots[i];
+ FileObject fileObject = FileUtil.toFileObject(new File(sourceRoot));
+ String rootURL;
+ try {
+ if (fileObject == null) {
+ rootURL = sourceRoot;
+ } else {
+ rootURL = fileObject.getURL().toString();
+ }
+ if (url.startsWith(rootURL)) {
+ File f = null;
+ if (fileObject != null) {
+ if (fileObject.getFileSystem () instanceof JarFileSystem)
+ f = ((JarFileSystem) fileObject.getFileSystem ()).getJarFile ();
+ else
+ f = FileUtil.toFile (fileObject);
+ } else {
+ f = new File(sourceRoot);
+ }
+ if (f != null) {
+ return f.getAbsolutePath ();
+ }
+ }
+ } catch (FileStateInvalidException ex) {
+ // Invalid source root - skip
+ }
+ }
+ return null; // not found
+ }
+
/**
* Adds property change listener.
*
Index: api/apichanges.xml
===================================================================
RCS file: /cvs/debuggerjpda/api/apichanges.xml,v
retrieving revision 1.12
diff -u -r1.12 apichanges.xml
--- api/apichanges.xml 3 Nov 2005 11:34:45 -0000 1.12
+++ api/apichanges.xml 3 May 2006 16:27:03 -0000
@@ -365,6 +365,23 @@
+ Retrieves a source root for a given URL. This is necessary to
+ match breakpoint locations with the sources selected fopr debugging.
+ It returns null
by default.
+