1 19 20 package org.netbeans.modules.debugger.jpda.ant; 21 22 import java.util.HashMap ; 23 import java.util.Map ; 24 import java.util.logging.Level ; 25 import java.util.logging.Logger ; 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.Task; 28 import org.apache.tools.ant.types.Path; 29 30 import org.openide.util.RequestProcessor; 31 32 import org.netbeans.api.debugger.jpda.JPDADebugger; 33 import org.netbeans.api.java.classpath.ClassPath; 34 35 36 41 public class JPDAConnect extends Task { 42 43 private static final Logger logger = Logger.getLogger("org.netbeans.modules.debugger.jpda.ant"); 45 private String host = "localhost"; 47 private String address; 48 49 50 private Path sourcepath = null; 51 52 53 private Path classpath = null; 54 55 56 private Path bootclasspath = null; 57 58 61 private String name; 62 63 64 private String transport = "dt_socket"; 66 67 71 public void setHost (String h) { 72 host = h; 73 } 74 75 public void setAddress (String address) { 76 this.address = address; 77 } 78 79 private String getAddress () { 80 return address; 81 } 82 83 public void addClasspath (Path path) { 84 if (classpath != null) 85 throw new BuildException ("Only one classpath subelement is supported"); 86 classpath = path; 87 } 88 89 public void addBootclasspath (Path path) { 90 if (bootclasspath != null) 91 throw new BuildException ("Only one bootclasspath subelement is supported"); 92 bootclasspath = path; 93 } 94 95 public void addSourcepath (Path path) { 96 if (sourcepath != null) 97 throw new BuildException ("Only one sourcepath subelement is supported"); 98 sourcepath = path; 99 } 100 101 public void setTransport (String transport) { 102 this.transport = transport; 103 } 104 105 private String getTransport () { 106 return transport; 107 } 108 109 public void setName (String name) { 110 this.name = name; 111 } 112 113 private String getName () { 114 return name; 115 } 116 117 public void execute () throws BuildException { 118 logger.fine("JPDAConnect.execute ()"); 120 JPDAStart.verifyPaths(getProject(), classpath); 121 JPDAStart.verifyPaths(getProject(), sourcepath); 123 124 if (name == null) 125 throw new BuildException ( 126 "name attribute must specify name of this debugging session", 127 getLocation () 128 ); 129 if (address == null) 130 throw new BuildException ( 131 "address attribute must specify port number or memory " + 132 "allocation unit name of connection", 133 getLocation () 134 ); 135 if (transport == null) 136 transport = "dt_socket"; 138 final Object [] lock = new Object [1]; 139 140 ClassPath sourcePath = JPDAStart.createSourcePath ( 141 getProject (), 142 classpath, 143 sourcepath 144 ); 145 ClassPath jdkSourcePath = JPDAStart.createJDKSourcePath ( 146 getProject (), 147 bootclasspath 148 ); 149 if (logger.isLoggable(Level.FINE)) { 150 logger.fine("Create sourcepath:"); logger.fine(" classpath : " + classpath); logger.fine(" sourcepath : " + sourcepath); logger.fine(" bootclasspath : " + bootclasspath); logger.fine(" >> sourcePath : " + sourcePath); logger.fine(" >> jdkSourcePath : " + jdkSourcePath); } 157 final Map properties = new HashMap (); 158 properties.put ("sourcepath", sourcePath); properties.put ("name", getName ()); properties.put ("jdksources", jdkSourcePath); 162 163 synchronized(lock) { 164 RequestProcessor.getDefault ().post (new Runnable () { 165 public void run() { 166 synchronized(lock) { 167 try { 168 if (logger.isLoggable(Level.FINE)) { 169 logger.fine( 170 "JPDAConnect.execute ().synchronized: " + "host = " + host + " port = " + address + " transport = " + transport ); 174 } 175 if (transport.equals ("dt_socket")) try { 179 JPDADebugger.attach ( 180 host, 181 Integer.parseInt (address), 182 new Object [] {properties} 183 ); 184 } catch (NumberFormatException e) { 185 throw new BuildException ( 186 "address attribute must specify port " + 187 "number for dt_socket connection", 188 getLocation () 189 ); 190 } 191 else 192 JPDADebugger.attach ( 193 address, 194 new Object [] {properties} 195 ); 196 logger.fine( 197 "JPDAConnect.execute ().synchronized " + "end: success" ); 200 } catch (Throwable e) { 201 logger.fine( 202 "JPDAConnect.execute().synchronized " + "end: exception " + e ); 205 lock[0] = e; 206 } finally { 207 lock.notify(); 208 } 209 } 210 } 211 }); 212 try { 213 lock.wait(); 214 } catch (InterruptedException e) { 215 logger.fine("JPDAConnect.execute() " + "end: exception " + e); throw new BuildException(e); 217 } 218 if (lock[0] != null) { 219 logger.fine("JPDAConnect.execute() " + "end: exception " + lock[0]); throw new BuildException((Throwable ) lock[0]); 221 } 222 223 } 224 if (host == null) 225 log ("Attached JPDA debugger to " + address); 226 else 227 log ("Attached JPDA debugger to " + host + ":" + address); 228 logger.fine("JPDAConnect.execute () " + "end: success"); } 230 } 231 | Popular Tags |