KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > maven > agent > LaunchTest


1 package hudson.maven.agent;
2
3 import hudson.remoting.Channel;
4 import hudson.remoting.Launcher;
5 import hudson.remoting.Which;
6 import junit.framework.TestCase;
7 import org.codehaus.classworlds.ClassWorld;
8
9 import java.io.File JavaDoc;
10 import java.io.IOException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.io.OutputStream JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.concurrent.Executors JavaDoc;
16
17 /**
18  * @author Kohsuke Kawaguchi
19  */

20 public class LaunchTest extends TestCase {
21     public void test1() throws Throwable JavaDoc {
22 /*
23         List<String> args = new ArrayList<String>();
24         args.add("java");
25         
26         args.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8002");
27
28         System.out.println(Channel.class);
29
30         args.add("-cp");
31         args.add(Which.jarFile(Main.class)+File.pathSeparator+Which.jarFile(ClassWorld.class));
32         args.add(Main.class.getName());
33
34         // M2_HOME
35         args.add(System.getProperty("maven.home"));
36         // remoting.jar
37         args.add(Which.jarFile(Launcher.class).getPath());
38         // interceptor.jar
39         args.add(Which.jarFile(PluginManagerInterceptor.class).getPath());
40
41         System.out.println("Launching "+args);
42
43         final Process proc = Runtime.getRuntime().exec(args.toArray(new String[0]));
44
45         // start copying system err
46         new Thread() {
47             public void run() {
48                 try {
49                     copyStream(proc.getErrorStream(),System.err);
50                 } catch (IOException e) {
51                     e.printStackTrace();
52                 }
53             }
54         }.start();
55
56         Channel ch = new Channel("maven", Executors.newCachedThreadPool(),
57             proc.getInputStream(), proc.getOutputStream(), System.err);
58
59         System.out.println("exit code="+ch.call(new RunCommand("help:effective-settings")));
60
61         ch.close();
62
63         System.out.println("done");
64 */

65     }
66
67     public static void copyStream(InputStream JavaDoc in, OutputStream JavaDoc out) throws IOException JavaDoc {
68         byte[] buf = new byte[8192];
69         int len;
70         while((len=in.read(buf))>0)
71             out.write(buf,0,len);
72     }
73 }
74
Popular Tags