Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Grails 3.x with jacoco #309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change log

## v0.4.6

* [FIX] Customised jacoco test-reporter to support Grails 3.x applications.

## v0.4.5 [(2018-02-19)](https://github.com/codeclimate/test-reporter/releases/tag/v0.4.5)

* [FIX] Add partial automated support for Heroku CI builds [#305][]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MAN_FILES = $(wildcard man/*.md)
MAN_PAGES = $(patsubst man/%.md,man/%,$(MAN_FILES))

PROJECT = github.com/codeclimate/test-reporter
VERSION ?= 0.4.5
VERSION ?= 0.4.6
BUILD_VERSION = $(shell git log -1 --pretty=format:'%H')
BUILD_TIME = $(shell date +%FT%T%z)
LDFLAGS = -ldflags "-X $(PROJECT)/version.Version=${VERSION} -X $(PROJECT)/version.BuildVersion=${BUILD_VERSION} -X $(PROJECT)/version.BuildTime=${BUILD_TIME}"
Expand Down
35 changes: 32 additions & 3 deletions formatters/jacoco/jacoco.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package jacoco

import (
"encoding/xml"
"fmt"
"os"
"strings"

"github.com/Sirupsen/logrus"
"github.com/codeclimate/test-reporter/env"
"github.com/codeclimate/test-reporter/formatters"
"github.com/pkg/errors"
"path/filepath"
"fmt"
)

var searchPaths = []string{"jacoco.xml"}
Expand Down Expand Up @@ -52,8 +53,25 @@ func (r Formatter) Format() (formatters.Report, error) {
for _, xmlPackage := range xmlJacoco.Packages {
for _, xmlSF := range xmlPackage.SourceFile {
num := 1
filepath := fmt.Sprintf("%s/%s", xmlPackage.Name, xmlSF.Name)
sf, err := formatters.NewSourceFile(filepath, gitHead)
defaultFilepath := fmt.Sprintf("%s/%s", xmlPackage.Name, xmlSF.Name)
filePathPatternForGrailsAppDir := "./grails-app/*/" + xmlPackage.Name + "/" + xmlSF.Name
filePathPatternForSrcDir := "./src/main/*/" + xmlPackage.Name + "/" + xmlSF.Name

logrus.Debugf("Searching for source file: " + xmlSF.Name + " with search pattern: " +
filePathPatternForGrailsAppDir)
actualFilePath := getActualFilePath(filePathPatternForGrailsAppDir)

if (actualFilePath == "") {
logrus.Debugf("Searching for source file: " + xmlSF.Name + " with search pattern: " +
filePathPatternForSrcDir)
actualFilePath = getActualFilePath(filePathPatternForSrcDir)

if (actualFilePath == "") {
actualFilePath = defaultFilepath
}
}

sf, err := formatters.NewSourceFile(actualFilePath, gitHead)
if err != nil {
return rep, errors.WithStack(err)
}
Expand All @@ -75,3 +93,14 @@ func (r Formatter) Format() (formatters.Report, error) {

return rep, nil
}

func getActualFilePath(filePathPattern string) (string) {
filePaths, _ := filepath.Glob(filePathPattern)
var numberOfMatches = len(filePaths)

if (numberOfMatches != 1) {
return ""
}

return filePaths[0]
}