Silence trailing "1 warning" message from javac when warning is silenced

soong_javac_wrapper is silencing a useless warning:
warning: [options] bootstrap class path not set in conjunction with -source 1.9
but recent versions of javac have started also printing:
1 warning

Read the warning count, subtract the number of silenced warnings, and
reprint it if the non-silenced warning count is nonzero.

Fixes: 144118634
Test: javac_wrapper_test.go
Change-Id: Ie1d0a978188ab7b1c41027f718a1274608628123
This commit is contained in:
Colin Cross
2019-11-11 13:07:38 -08:00
parent 2d5ce8538b
commit e94272d0b3
2 changed files with 53 additions and 6 deletions

View File

@@ -75,13 +75,29 @@ javadoc: option --boot-class-path not allowed with target 1.9
`,
out: "\n",
},
{
in: `
warning: [options] bootstrap class path not set in conjunction with -source 1.9\n
1 warning
`,
out: "\n",
},
{
in: `
warning: foo
warning: [options] bootstrap class path not set in conjunction with -source 1.9\n
2 warnings
`,
out: "\n\x1b[1m\x1b[35mwarning:\x1b[0m\x1b[1m foo\x1b[0m\n1 warning\n",
},
}
func TestJavacColorize(t *testing.T) {
for i, test := range testCases {
t.Run(strconv.Itoa(i), func(t *testing.T) {
buf := new(bytes.Buffer)
err := process(bytes.NewReader([]byte(test.in)), buf)
proc := processor{}
err := proc.process(bytes.NewReader([]byte(test.in)), buf)
if err != nil {
t.Errorf("error: %q", err)
}