1 17 18 package org.apache.geronimo.deployment.mavenplugin; 19 20 import java.io.*; 21 import java.util.ArrayList ; 22 import java.util.StringTokenizer ; 23 24 25 28 public class StartRemoteServer { 29 30 private String geronimoTarget; 31 private String vmArgs = ""; 32 private String configs; 33 private String debugPort; 34 private String output; 35 private String error; 36 private PrintStream out = System.out; 37 private PrintStream err = System.err; 38 39 40 41 public String getGeronimoTarget() { 42 return geronimoTarget; 43 } 44 45 public void setGeronimoTarget(String geronimoTarget) { 46 this.geronimoTarget = geronimoTarget; 47 } 48 49 public String getVmArgs() { 50 return vmArgs; 51 } 52 53 public void setVmArgs(String vmArgs) { 54 this.vmArgs = vmArgs; 55 } 56 57 public String getConfigs() { 58 return configs; 59 } 60 61 public void setConfigs(String configs) { 62 this.configs = configs; 63 } 64 65 public String getDebugPort() { 66 return debugPort; 67 } 68 69 public void setDebugPort(String debugPort) { 70 this.debugPort = debugPort; 71 } 72 73 public String getOutput() { 74 return output; 75 } 76 77 public void setOutput(String output) { 78 this.output = output; 79 } 80 81 public String getError() { 82 return error; 83 } 84 85 public void setError(String error) { 86 this.error = error; 87 } 88 89 private PrintStream getOut() { 90 try { 91 if (getOutput() != null) { 92 out = new PrintStream(new FileOutputStream(getOutput())); 93 } 94 } catch (FileNotFoundException e) { 95 System.err.println(e.getMessage()); 96 } 97 98 return out; 99 } 100 101 private PrintStream getErr() { 102 try { 103 if (getError() != null) { 104 err = new PrintStream(new FileOutputStream(getError())); 105 } else if (getOutput() != null) { 106 err = getOut(); 107 } 108 } catch (FileNotFoundException e) { 109 System.err.println(e.getMessage()); 110 } 111 return err; 112 } 113 114 public void execute() throws Exception { 115 ArrayList cmd = new ArrayList (); 116 File root = new File(getGeronimoTarget()); 117 File systemFile = new File(root, "bin/server.jar"); 118 String s = java.io.File.separator; 119 String java = System.getProperty("java.home") + s + "bin" + s + "java"; 120 121 cmd.add(java); 122 123 if (debugPort != null) { 124 cmd.add("-Xdebug"); 125 cmd.add("-Xnoagent"); 126 cmd.add("-Djava.compiler=NONE"); 127 cmd.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=" + debugPort); 128 } 129 130 for (StringTokenizer st = new StringTokenizer (getVmArgs()); st.hasMoreTokens();) { 131 cmd.add(st.nextToken()); 132 } 133 134 cmd.add("-ea"); 135 cmd.add("-jar"); 136 cmd.add(systemFile.getCanonicalPath()); 137 138 if (getConfigs() != null) { 139 for (StringTokenizer st = new StringTokenizer (getConfigs()); st.hasMoreTokens();) { 140 cmd.add(st.nextToken()); 141 } 142 } 143 String [] command = (String []) cmd.toArray(new String [0]); 144 145 Runtime runtime = Runtime.getRuntime(); 146 Process server = runtime.exec(command); 147 148 149 InputStream out = server.getInputStream(); 151 Thread serverOut = new Thread (new Pipe(out, getOut())); 152 serverOut.setDaemon(true); 153 serverOut.start(); 154 155 InputStream err = server.getErrorStream(); 157 Thread serverErr = new Thread (new Pipe(err, getErr())); 158 serverErr.setDaemon(true); 159 serverErr.start(); 160 161 } 162 163 private final class Pipe implements Runnable { 164 165 private final InputStream in; 166 private final OutputStream out; 167 168 public Pipe(InputStream in, OutputStream out) { 169 this.in = in; 170 this.out = out; 171 } 172 173 public void run() { 174 int i; 175 try { 176 do { 177 i = in.read(); 178 out.write(i); 179 } while (i != -1); 180 } catch (IOException e) { 181 e.printStackTrace(); 182 } 183 } 184 185 } 186 } 187 | Popular Tags |