1 19 20 package org.netbeans.api.debugger.jpda.test; 21 22 import java.net.URISyntaxException ; 23 import org.netbeans.spi.debugger.jpda.SourcePathProvider; 24 import org.netbeans.spi.debugger.ContextProvider; 25 import org.netbeans.api.debugger.Session; 26 27 import java.beans.PropertyChangeListener ; 28 import java.beans.PropertyChangeSupport ; 29 import java.util.*; 30 import java.net.URL ; 31 import java.net.MalformedURLException ; 32 import java.io.File ; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileStateInvalidException; 35 import org.openide.filesystems.FileUtil; 36 import org.openide.filesystems.JarFileSystem; 37 38 39 44 public class TestEngineContextProvider extends SourcePathProvider { 45 46 private String sourceRoot = System.getProperty ("test.dir.src"); 47 private String home = System.getProperty("user.home"); 48 private String [] originalSourceRoots = new String [] { 49 sourceRoot, home 50 }; 51 private PropertyChangeSupport pcs = new PropertyChangeSupport (this); 52 53 54 public TestEngineContextProvider (ContextProvider ctxProvider) { 55 for (int i = 0; i < originalSourceRoots.length; i++) { 57 while (originalSourceRoots[i].endsWith(File.separator)) { 58 originalSourceRoots[i] = originalSourceRoots[i].substring(0, originalSourceRoots[i].length() - 1); 59 } 60 } 61 } 62 63 69 public String getURL (String relativePath, boolean global) { 70 String url = sourceRoot + relativePath; 71 if (new File (url).exists ()) return url; 72 else System.out.println("WARNIG: No URL for '"+relativePath+"', sourceRoot = '"+sourceRoot+"'."); 73 return null; 74 } 75 76 77 87 public String getRelativePath ( 88 String url, 89 char directorySeparator, 90 boolean includeExtension 91 ) { 92 if (!url.startsWith (sourceRoot)) return null; 93 url = url.substring (sourceRoot.length ()); 94 if (!includeExtension) { 95 int i = url.lastIndexOf ('.'); 96 if (i > 0) 97 url = url.substring (0, i); 98 } 99 url = url.replace ('/', directorySeparator); 100 return url; 101 } 102 103 108 public String [] getOriginalSourceRoots () { 109 return originalSourceRoots; 110 } 111 112 117 public String [] getSourceRoots () { 118 return originalSourceRoots; 119 } 120 121 126 public void setSourceRoots (String [] sourceRoots) { 127 } 128 129 public String getSourceRoot(String url) { 130 try { 131 url = new URL (url).toString(); 132 } catch (MalformedURLException ex) { 133 ex.printStackTrace(); 134 } 135 for (int i = 0; i < originalSourceRoots.length; i++) { 136 String sourceRoot = originalSourceRoots[i]; 137 File sourceRootFile = new File (sourceRoot); 138 sourceRootFile = FileUtil.normalizeFile(sourceRootFile); 139 FileObject fileObject = FileUtil.toFileObject(sourceRootFile); 140 String rootURL; 141 try { 142 if (fileObject == null) { 143 try { 144 rootURL = sourceRootFile.toURI().toURL().toString(); 145 } catch (MalformedURLException ex) { 146 ex.printStackTrace(); 147 continue; 148 } 149 } else { 150 rootURL = fileObject.getURL().toString(); 151 } 152 if (url.startsWith(rootURL)) { 153 File f = null; 154 if (fileObject != null) { 155 if (fileObject.getFileSystem () instanceof JarFileSystem) 156 f = ((JarFileSystem) fileObject.getFileSystem ()).getJarFile (); 157 else 158 f = FileUtil.toFile (fileObject); 159 } else { 160 f = sourceRootFile; 161 } 162 if (f != null) { 163 return f.getAbsolutePath (); 164 } 165 } 166 } catch (FileStateInvalidException ex) { 167 } 169 } 170 return null; } 172 173 178 public void addPropertyChangeListener (PropertyChangeListener l) { 179 } 180 181 186 public void removePropertyChangeListener ( 187 PropertyChangeListener l 188 ) { 189 } 190 } 191 | Popular Tags |