forked from cloudfoundry/app-autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_checkstyle.go
59 lines (49 loc) · 1.01 KB
/
format_checkstyle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
)
type Result struct {
Files []File `xml:"file"`
}
type File struct {
Name string `xml:"name,attr"`
Errors []Error `xml:"error"`
}
type Error struct {
Line string `xml:"line,attr"`
Column string `xml:"column,attr"`
Severity string `xml:"severity,attr"`
Message string `xml:"message,attr"`
Source string `xml:"source,attr"`
}
func main() {
xmlFile, err := os.Open("scheduler/target/checkstyle-result.xml")
if err != nil {
panic(err)
}
fmt.Println("Successfully Opened file")
defer xmlFile.Close()
byteValue, err := ioutil.ReadAll(xmlFile)
if err != nil {
panic(err)
}
var result Result
err = xml.Unmarshal(byteValue, &result)
if err != nil {
panic(err)
}
count := 0
for _, f := range result.Files {
for _, e := range f.Errors {
count++
fmt.Printf("::%s file=%s,line=%s,col=%s::%s\n", e.Severity, f.Name, e.Line, e.Column, e.Message)
}
}
fmt.Printf("Total %d Issues\n", count)
if count > 0 {
os.Exit(1)
}
}