MCPcopy Create free account
hub / github.com/google/gapid / BuildRunAndConnect

Function BuildRunAndConnect

core/java/jdwp/test/test.go:97–133  ·  view source on GitHub ↗

BuildRunAndConnect builds all the source files with javac, executes them with java, attaches to it via JDWP, then calls onConnect with the connection.

(ctx context.Context, source JavaSource, onConnect func(ctx context.Context, conn *jdwp.Connection) int)

Source from the content-addressed store, hash-verified

95// BuildRunAndConnect builds all the source files with javac, executes them with
96// java, attaches to it via JDWP, then calls onConnect with the connection.
97func BuildRunAndConnect(ctx context.Context, source JavaSource, onConnect func(ctx context.Context, conn *jdwp.Connection) int) int {
98 ctx, stop := task.WithTimeout(ctx, time.Second*30)
99
100 port, err := findFreePort()
101 if err != nil {
102 log.E(ctx, "Failed to find a free port. Error: %v", err)
103 return -1
104 }
105
106 done := runJavaServer(ctx, source, port)
107 defer func() {
108 stop()
109 <-done
110 }()
111
112 var socket io.ReadWriteCloser
113 for i := 0; i < 5; i++ {
114 var err error
115 if socket, err = net.Dial("tcp", fmt.Sprintf("localhost:%v", port)); err == nil {
116 break
117 }
118 time.Sleep(time.Second)
119 }
120
121 if socket == nil {
122 log.E(ctx, "Failed to connect to the socket. Error: %v", err)
123 return -1
124 }
125
126 conn, err := jdwp.Open(ctx, socket)
127 if err != nil {
128 log.E(ctx, "Failed to open the JDWP connection. Error: %v", err)
129 return -1
130 }
131
132 return onConnect(ctx, conn)
133}

Callers

nothing calls this directly

Calls 4

findFreePortFunction · 0.85
runJavaServerFunction · 0.85
OpenMethod · 0.65
EMethod · 0.45

Tested by

no test coverage detected