~hudson-ubuntu/+junk/windows-remote-command

« back to all changes in this revision

Viewing changes to src/test/java/org/jvnet/hudson/remcom/App.java

  • Committer: James Page
  • Date: 2010-12-06 10:47:32 UTC
  • Revision ID: james.page@canonical.com-20101206104732-nctfskg5ky3vinf4
Initial release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.jvnet.hudson.remcom;
 
2
 
 
3
import org.apache.commons.io.FileUtils;
 
4
import org.apache.commons.io.IOUtils;
 
5
import org.jinterop.dcom.common.IJIAuthInfo;
 
6
import org.jinterop.dcom.common.JIDefaultAuthInfoImpl;
 
7
import org.jinterop.dcom.common.JIException;
 
8
 
 
9
import java.io.File;
 
10
import java.io.IOException;
 
11
import java.io.OutputStream;
 
12
import java.util.logging.ConsoleHandler;
 
13
import java.util.logging.Level;
 
14
import java.util.logging.Logger;
 
15
 
 
16
/**
 
17
 * Debug code.
 
18
 */
 
19
public class App {
 
20
    private static IJIAuthInfo createAuth() throws IOException {
 
21
        String pwd = FileUtils.readFileToString(new File("/home/kohsuke/.cubit")).trim();
 
22
        return new JIDefaultAuthInfoImpl("cloud", "kohsuke", pwd);
 
23
//        return new JIDefaultAuthInfoImpl("", "kohsuke", "kohsuke");
 
24
    }
 
25
 
 
26
    public static void main(String[] args) throws Exception {
 
27
        Logger.getLogger("org.jinterop").setLevel(Level.WARNING);
 
28
        Logger l = Logger.getLogger("org.jvnet.hudson");
 
29
        l.setLevel(Level.ALL);
 
30
        ConsoleHandler ch = new ConsoleHandler();
 
31
        ch.setLevel(Level.ALL);
 
32
        l.addHandler(ch);
 
33
 
 
34
//        String host = "10.1.6.71";
 
35
        String host = "10.1.68.89";
 
36
 
 
37
        installJdk(host);
 
38
//        blockingTest(host);
 
39
 
 
40
//        permissionTest(host);
 
41
    }
 
42
 
 
43
    private static void installJdk(String host) throws IOException, JIException, InterruptedException {
 
44
        WindowsRemoteProcessLauncher wrp = new WindowsRemoteProcessLauncher(host, createAuth());
 
45
        Process proc = wrp.launch("c:\\hudson\\jdk.exe /s \"/v/qn REBOOT=Suppress INSTALLDIR=c:\\hudson\\jdk /L c:\\hudson/jdk.exe.install.log\"", "c:\\");
 
46
        proc.getOutputStream().close();
 
47
        IOUtils.copy(proc.getInputStream(),System.out);
 
48
 
 
49
        System.out.println();
 
50
        System.out.println("Exit code="+proc.waitFor());
 
51
    }
 
52
 
 
53
    private static void blockingTest(String host) throws IOException, JIException, InterruptedException {
 
54
        WindowsRemoteProcessLauncher wrp = new WindowsRemoteProcessLauncher(host, createAuth());
 
55
        Process proc = wrp.launch("c:\\cygwin\\bin\\cat", "c:\\");
 
56
        IOUtils.copy(proc.getInputStream(),System.out);
 
57
 
 
58
        System.out.println();
 
59
        System.out.println("Exit code="+proc.waitFor());
 
60
    }
 
61
 
 
62
    private static void permissionTest(String host) throws IOException, JIException, InterruptedException {
 
63
        WindowsRemoteProcessLauncher wrp = new WindowsRemoteProcessLauncher(host, createAuth());
 
64
        Process proc = wrp.launch("c:\\cygwin\\bin\\cat > iAmHere", "c:\\");
 
65
        OutputStream o = proc.getOutputStream();
 
66
        o.write("Hello world".getBytes());
 
67
        o.close();
 
68
        IOUtils.copy(proc.getInputStream(),System.out);
 
69
        IOUtils.copy(proc.getErrorStream(),System.out);
 
70
 
 
71
        System.out.println();
 
72
        System.out.println("Exit code="+proc.waitFor());
 
73
 
 
74
 
 
75
        proc = wrp.launch("dir", "c:\\");
 
76
 
 
77
        o = proc.getOutputStream();
 
78
        o.write("Hello world".getBytes());
 
79
        o.close();
 
80
        IOUtils.copy(proc.getInputStream(),System.out);
 
81
        IOUtils.copy(proc.getErrorStream(),System.out);
 
82
 
 
83
        System.out.println();
 
84
        System.out.println("Exit code="+proc.waitFor());
 
85
    }
 
86
}