1 18 19 package org.apache.tools.ant.taskdefs.condition; 20 21 import java.io.IOException ; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.ProjectComponent; 25 26 33 public class Socket extends ProjectComponent implements Condition { 34 private String server = null; 35 private int port = 0; 36 37 42 public void setServer(String server) { 43 this.server = server; 44 } 45 46 51 public void setPort(int port) { 52 this.port = port; 53 } 54 55 59 public boolean eval() throws BuildException { 60 if (server == null) { 61 throw new BuildException("No server specified in socket " 62 + "condition"); 63 } 64 if (port == 0) { 65 throw new BuildException("No port specified in socket condition"); 66 } 67 log("Checking for listener at " + server + ":" + port, 68 Project.MSG_VERBOSE); 69 java.net.Socket s = null; 70 try { 71 s = new java.net.Socket (server, port); 72 } catch (IOException e) { 73 return false; 74 } finally { 75 if (s != null) { 76 try { 77 s.close(); 78 } catch (IOException ioe) { 79 } 81 } 82 } 83 return true; 84 } 85 86 } 87 | Popular Tags |