Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 08ea7c1caf127e3352035ccd35afb0ce105d15b4 (plain) (blame)
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
60
61
62
63
64
65
66
67
#!/usr/bin/env groovy

import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.*

def buildXmlFile = new File("build-kernel/build.xml")
def buildXml = loadXmlFile(buildXmlFile);
def relativeLocations = readProjectLocations(buildXml);

def cloverResultFiles = []

relativeLocations.each {
	cloverResultFiles.add(new File(buildXmlFile.parent, it + "/target/clover/clover.xml"))
}

println ""

cloverResultFiles.each {
	
	def coverage = determineCoverage(it);
	
	outputCoverage (it.parentFile.parentFile.parentFile.name, coverage);
}

def overallCoverage = determineCoverage(new File(buildXmlFile.parent, "/target/clover/clover.xml"))

println ""
outputCoverage("Overall", overallCoverage);
println ""

def loadXmlFile(File xmlFile) {
	builder = DocumentBuilderFactory.newInstance().newDocumentBuilder()
	inputStream = new FileInputStream(xmlFile)
	return builder.parse(inputStream).documentElement
}

def readProjectLocations(def buildXml) {
	def xpath = XPathFactory.newInstance().newXPath()
	def nodes = xpath.evaluate( '//path[@id="unit.test.bundles"]/pathelement', buildXml, XPathConstants.NODESET)

	def locations = []

	nodes.each {
	  locations.add(xpath.evaluate( '@location', it ))
	}
	
	return locations
}

double determineCoverage(def cloverXmlFile) {
	if (!cloverXmlFile.exists()) {
		return 0;
	}
	
	def cloverXml = loadXmlFile(cloverXmlFile);
	def xpath = XPathFactory.newInstance().newXPath()
	def metrics = xpath.evaluate( '/coverage/project/metrics', cloverXml, XPathConstants.NODESET).item(0)

	coveredElements = xpath.evaluate('@coveredelements', metrics).toDouble()
	elements = xpath.evaluate('@elements', metrics).toDouble()

	return (coveredElements / elements) * 100
}

def outputCoverage(def name, def coverage) {
	println String.format("%-48s: %5.2f%%", name, coverage)
}

Back to the top