Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit bf8435a

Browse files
authored
Merge pull request #73 from MediaMarktSaturn/feature/jacocoReports
Feature/jacoco reports
2 parents 3b41638 + daf582f commit bf8435a

File tree

12 files changed

+726
-266
lines changed

12 files changed

+726
-266
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"env": {
3+
"es6": true,
34
"mocha": true,
45
"node": true
56
},

lib/coverageParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function (Joi, util, logger) {
22
'use strict';
33

4-
var validFormats = ['lcov'];
4+
var validFormats = ['lcov','jacoco'];
55
var formatValidation = Joi.string().valid(validFormats).required();
66

77
module.exports = {

lib/impl/jacoco.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
(function (jacocoParse, Promise, Joi, logger, util, path) {
2+
'use strict';
3+
4+
var jacocoStringValidation = Joi.string().required();
5+
var optionsValidation = Joi.object().keys().optional();
6+
7+
module.exports = {
8+
parse: function parseJacoco(pathPrefix, jacocoString, options) {
9+
return new Promise(function (resolve, reject) {
10+
logger.debug('Parsing Jacoco Data');
11+
var nonEmptyReport = Joi.validate(jacocoString, jacocoStringValidation);
12+
var validOptions = Joi.validate(options, optionsValidation, {
13+
stripUnknown: true
14+
});
15+
var validationError = nonEmptyReport.error || validOptions.error;
16+
17+
if (validationError) {
18+
logger.error(validationError);
19+
return reject(validationError);
20+
}
21+
22+
jacocoParse.parseContent(jacocoString, function (err, data) {
23+
if (err) {
24+
err = new Error('Failed to parse jacoco report: ' + err);
25+
26+
logger.error(err);
27+
return reject(err);
28+
}
29+
30+
var result = {
31+
total: 0,
32+
fileReports: []
33+
};
34+
var totalLines = 0;
35+
var totalHits = 0;
36+
37+
//TODO: Convert to reduce function
38+
data.forEach(function (stats) {
39+
var fileStats = {
40+
// The API expects the filenames to be relative to the project, ex. lib/reporter.js
41+
filename: stats.file ? pathPrefix + path.relative(process.cwd(), stats.file) : '',
42+
coverage: {}
43+
};
44+
45+
totalLines += stats.lines.found;
46+
totalHits += stats.lines.hit;
47+
48+
// The API uses integers only, so convert accordingly.
49+
fileStats.total = Math.floor(util.safeDivision(stats.lines.hit, stats.lines.found) * 100);
50+
51+
//TODO: Convert to reduce function
52+
stats.lines.details.forEach(function (detail) {
53+
// Codacy needs the 0s to know failed coverage data
54+
// We also can't have a negative number of hits on a line, so exclude those.
55+
if (detail.hit >= 0) {
56+
fileStats.coverage[detail.line] = detail.hit;
57+
}
58+
});
59+
60+
logger.trace('Successfully parsed ' + stats.file);
61+
result.fileReports.push(fileStats);
62+
});
63+
64+
// The API uses integers only, so convert accordingly.
65+
result.total = Math.floor(util.safeDivision(totalHits, totalLines) * 100);
66+
67+
logger.debug('Successfully Parsed Jacoco Data');
68+
69+
resolve(result);
70+
});
71+
});
72+
}
73+
};
74+
}(require('jacoco-parse'), require('bluebird'), require('joi'), require('../logger')(), require('../util'), require('path')));

lib/reporter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
jsx: 'javascript',
2424
ts: 'typescript',
2525
tsx: 'typescript',
26-
coffee: 'coffeescript'
26+
coffee: 'coffeescript',
27+
java: 'java'
2728
};
2829

2930
function sendByLanguage(endpoint, commitId, token, data, accountToken, username, projectName) {

0 commit comments

Comments
 (0)