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

Function runJavaServer

core/java/jdwp/test/test.go:51–93  ·  view source on GitHub ↗
(ctx context.Context, sources JavaSource, port int)

Source from the content-addressed store, hash-verified

49type JavaSource map[string]string
50
51func runJavaServer(ctx context.Context, sources JavaSource, port int) task.Signal {
52 signal, done := task.NewSignal()
53 go func() {
54 defer done(ctx)
55 tmp, err := ioutil.TempDir("", "jdwp")
56 if err != nil {
57 log.E(ctx, "Couldn't get temporary directory. Error: %v", err)
58 return
59 }
60 defer os.RemoveAll(tmp)
61 sourceNames := make([]string, 0, len(sources))
62 for name, source := range sources {
63 if err := ioutil.WriteFile(filepath.Join(tmp, name), []byte(source), 0777); err != nil {
64 log.E(ctx, "Couldn't write to temporary source file. Error: %v", err)
65 return
66 }
67 sourceNames = append(sourceNames, name)
68 }
69 l := log.From(ctx)
70 if err := shell.
71 Command("javac", sourceNames...).
72 In(tmp).
73 Capture(nil, l.Writer(log.Error)).
74 Run(ctx); err != nil {
75
76 log.E(ctx, "Couldn't compile java source. Error: %v", err)
77 return
78 }
79 agentlib := fmt.Sprintf("-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=%v", port)
80 if err := shell.
81 Command("java", agentlib, "main").
82 In(tmp).
83 Capture(l.Writer(log.Info), l.Writer(log.Error)).
84 Run(ctx); err != nil {
85
86 if !task.Stopped(ctx) {
87 log.E(ctx, "Couldn't start java server. Error: %v", err)
88 }
89 return
90 }
91 }()
92 return signal
93}
94
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.

Callers 1

BuildRunAndConnectFunction · 0.85

Calls 8

InMethod · 0.80
WriterMethod · 0.80
WriteFileMethod · 0.65
RunMethod · 0.65
CaptureMethod · 0.65
CommandMethod · 0.65
EMethod · 0.45
JoinMethod · 0.45

Tested by

no test coverage detected