diff --git a/cmd/command/main.go b/cmd/command/main.go index ecd54f9df0b044db5440e7b618180ee3462935d6..bd16c6f1eea50fc204a83ae524a88ce0f55409a3 100644 --- a/cmd/command/main.go +++ b/cmd/command/main.go @@ -82,6 +82,8 @@ func main() { flagSet.StringVar(&unitTestTool, "unitTestTool", "", "") flagSet.StringVar(&unitBuildTool, "unitBuildTool", "", "") + flagSet.StringVar(&commConsts.JacocoReport, "jacocoReport", "", "") + flagSet.StringVar(&keywords, "k", "", "") flagSet.StringVar(&keywords, "keywords", "", "") @@ -265,6 +267,9 @@ func runUnitTest(args []string) { if commConsts.AllureReportDir != "" { start = start + 2 } + if commConsts.JacocoReport != "" { + start = start + 2 + } if unitTestTool != "" { start = start + 2 } diff --git a/internal/pkg/consts/var.go b/internal/pkg/consts/var.go index f57190641dfbadda0df0accecb78a34a6dc2b403..bf0c0d94b1e51bb42353a33baab221c61835564b 100644 --- a/internal/pkg/consts/var.go +++ b/internal/pkg/consts/var.go @@ -27,6 +27,7 @@ var ( UnitBuildTool BuildTool UnitTestTool TestTool AllureReportDir string + JacocoReport string ProductId string ZenTaoVersion string diff --git a/internal/pkg/domain/testing-jacoco.go b/internal/pkg/domain/testing-jacoco.go new file mode 100644 index 0000000000000000000000000000000000000000..4def393602943a502ec918cbf1323f8b541ce2d8 --- /dev/null +++ b/internal/pkg/domain/testing-jacoco.go @@ -0,0 +1,66 @@ +package commDomain + +type JacocoReport struct { + Sessioninfo JacocoSessioninfo `xml:"sessioninfo"` + Package JacocoPackage `xml:"package"` + Counter []JacocoCounter `xml:"counter"` + Name string `xml:"name,attr"` +} + +type JacocoCounter struct { + Type Type `xml:"type,attr"` + Missed string `xml:"missed,attr"` + Covered string `xml:"covered,attr"` +} + +type JacocoPackage struct { + Class JacocoClassClass `xml:"class"` + Sourcefile JacocoSourcefile `xml:"sourcefile"` + Counter []JacocoCounter `xml:"counter"` + Name string `xml:"name,attr"` +} + +type JacocoClassClass struct { + Method []JacocoMethodElement `xml:"method"` + Counter []JacocoCounter `xml:"counter"` + Name string `xml:"name,attr"` + Sourcefilename string `xml:"sourcefilename,attr"` +} + +type JacocoMethodElement struct { + Counter []JacocoCounter `xml:"counter"` + Name string `xml:"name,attr"` + Desc string `xml:"desc,attr"` + Line string `xml:"line,attr"` +} + +type JacocoSourcefile struct { + Line []JacocoLineElement `xml:"line"` + Counter []JacocoCounter `xml:"counter"` + Name string `xml:"name,attr"` +} + +type JacocoLineElement struct { + Nr string `xml:"nr,attr"` + Mi string `xml:"mi,attr"` + Ci string `xml:"ci,attr"` + MB string `xml:"mb,attr"` + Cb string `xml:"cb,attr"` +} + +type JacocoSessioninfo struct { + ID string `xml:"id,attr"` + Start string `xml:"start,attr"` + Dump string `xml:"dump,attr"` +} + +type Type string + +const ( + Branch Type = "BRANCH" + Class Type = "CLASS" + Complexity Type = "COMPLEXITY" + Instruction Type = "INSTRUCTION" + Line Type = "LINE" + Method Type = "METHOD" +) diff --git a/internal/pkg/helper/exec/exec.go b/internal/pkg/helper/exec/exec.go index e7e8d1ac375c14b4be78e5eb883f1c8ca58b5896..45928d68d0b9c7c24beeb364fed30b94f5155d59 100644 --- a/internal/pkg/helper/exec/exec.go +++ b/internal/pkg/helper/exec/exec.go @@ -35,6 +35,7 @@ func Exec(ch chan int, req serverDomain.ExecReq, msg *websocket.Message) ( ExecUnit(ch, testSet, msg) } }() // for defer + } return diff --git a/internal/pkg/helper/exec/report-jacoco.go b/internal/pkg/helper/exec/report-jacoco.go new file mode 100644 index 0000000000000000000000000000000000000000..c9735e90b79091cea0783e0009eb99c98e988db9 --- /dev/null +++ b/internal/pkg/helper/exec/report-jacoco.go @@ -0,0 +1,47 @@ +package execHelper + +import ( + "encoding/xml" + commConsts "github.com/easysoft/zentaoatf/internal/pkg/consts" + commDomain "github.com/easysoft/zentaoatf/internal/pkg/domain" + dateUtils "github.com/easysoft/zentaoatf/pkg/lib/date" + fileUtils "github.com/easysoft/zentaoatf/pkg/lib/file" + i118Utils "github.com/easysoft/zentaoatf/pkg/lib/i118" + logUtils "github.com/easysoft/zentaoatf/pkg/lib/log" + "github.com/fatih/color" + "time" +) + +const ( + Tmpl = `Counter Missed Covered +------------------------------------------ +%11s %s %s +%11s %s %s +%11s %s %s +%11s %s %s +%11s %s %s +%11s %s %s +` +) + +func GenJacocoCovReport() (report commDomain.JacocoReport) { + content := fileUtils.ReadFileBuf(commConsts.JacocoReport) + + xml.Unmarshal(content, &report) + + var params []interface{} + for _, counter := range report.Counter { + params = append(params, string(counter.Type)) + params = append(params, counter.Missed) + params = append(params, counter.Covered) + } + + title := i118Utils.Sprintf("jacoco_report") + + msg := dateUtils.DateTimeStr(time.Now()) + " " + title + " \n" + i118Utils.Sprintf(Tmpl, params...) + + logUtils.ExecConsole(color.FgCyan, msg) + logUtils.ExecResult(msg) + + return +} diff --git a/internal/pkg/helper/exec/unit.go b/internal/pkg/helper/exec/unit.go index 42775cf9c521456d0a9b644d8162b618c0d481be..c2580e1bb2646b9d1f7626800b9cf3edd505743a 100644 --- a/internal/pkg/helper/exec/unit.go +++ b/internal/pkg/helper/exec/unit.go @@ -41,7 +41,7 @@ func ExecUnit(ch chan int, iris.Map{"key": key, "status": "start"}, wsMsg) } - //deal with -allureReportDir param + //deal with -allureReportDir param arr := strings.Split(req.Cmd, " ") if len(arr) > 1 && strings.TrimSpace(arr[0]) == "-allureReportDir" { commConsts.AllureReportDir = arr[1] @@ -74,6 +74,11 @@ func ExecUnit(ch chan int, // gen report report := GenUnitTestReport(req, startTime.Unix(), entTime.Unix(), ch, wsMsg) + // dealwith jacoco report + if commConsts.JacocoReport != "" { + GenJacocoCovReport() + } + // submit result if req.SubmitResult && (report.FuncResult != nil || report.UnitResult != nil) { configDir := req.WorkspacePath diff --git a/res/server/en/messages.json b/res/server/en/messages.json index 95a1590fa2f88ae2d12c379b46f53478117a436d..eaef53f67581faba3c4713171e6d737301694995 100644 --- a/res/server/en/messages.json +++ b/res/server/en/messages.json @@ -726,6 +726,10 @@ { "id": "pls_check_zentao_url", "translation": "%s, Zentao version '%s'.\n Please use above OpenSource 17.0, Biz 7.0, Max 3.1 version, or you may install RestAPI plugin according to UserManual section 4.4." + }, + { + "id": "jacoco_report", + "translation": "Jacoco Coverage Report" } ] } diff --git a/res/server/zh/messages.json b/res/server/zh/messages.json index e5d05219dd2db3f2e2f37a55834dc386e91992d9..c410c00c2e74f0548a8ef21da42968eb437f3ea0 100644 --- a/res/server/zh/messages.json +++ b/res/server/zh/messages.json @@ -714,6 +714,10 @@ { "id": "pls_check_zentao_url", "translation": "%s,当前禅道版本'%s'。\n请确认您使用了禅道开源17.0、企业7.0、旗舰3.1以上版本,或已按照用户手册4.4小节成功安装RestAPI插件。" + }, + { + "id": "jacoco_report", + "translation": "Jacoco覆盖率报告" } ] } diff --git a/xdoc/jacoco/jacoco.xml b/xdoc/jacoco/jacoco.xml new file mode 100644 index 0000000000000000000000000000000000000000..12779768887248dbd08d19af8ae25d91ddf1fe55 --- /dev/null +++ b/xdoc/jacoco/jacoco.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +