summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-06-13 19:45:03 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2014-06-13 19:45:03 (GMT)
commit8be1a711b27e950b67d9c4a460a2fe1fe123a8ae (patch)
tree8a124ef3a1b051d0f08853adb4a2f7e3aa9d8049 /Source
parentf69501dfe2b6dc268ba9409a53e1413223187434 (diff)
parent558c2190e89c4a62d9e279cfee2af1f77f628b9b (diff)
downloadCMake-8be1a711b27e950b67d9c4a460a2fe1fe123a8ae.zip
CMake-8be1a711b27e950b67d9c4a460a2fe1fe123a8ae.tar.gz
CMake-8be1a711b27e950b67d9c4a460a2fe1fe123a8ae.tar.bz2
Merge topic 'add_jacoco_coverage_parsing'
558c2190 CTest: Add Jacoco Coverage functionality
Diffstat (limited to 'Source')
-rw-r--r--Source/CMakeLists.txt1
-rw-r--r--Source/CTest/cmCTestCoverageHandler.cxx40
-rw-r--r--Source/CTest/cmCTestCoverageHandler.h5
-rw-r--r--Source/CTest/cmParseJacocoCoverage.cxx167
-rw-r--r--Source/CTest/cmParseJacocoCoverage.h59
5 files changed, 271 insertions, 1 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt
index fe6cc1b..c3c24fe 100644
--- a/Source/CMakeLists.txt
+++ b/Source/CMakeLists.txt
@@ -518,6 +518,7 @@ set(CTEST_SRCS cmCTest.cxx
CTest/cmParseMumpsCoverage.cxx
CTest/cmParseCacheCoverage.cxx
CTest/cmParseGTMCoverage.cxx
+ CTest/cmParseJacocoCoverage.cxx
CTest/cmParsePHPCoverage.cxx
CTest/cmParseCoberturaCoverage.cxx
CTest/cmCTestEmptyBinaryDirectoryCommand.cxx
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx
index da27c8c..76f6584 100644
--- a/Source/CTest/cmCTestCoverageHandler.cxx
+++ b/Source/CTest/cmCTestCoverageHandler.cxx
@@ -14,6 +14,7 @@
#include "cmParseCoberturaCoverage.h"
#include "cmParseGTMCoverage.h"
#include "cmParseCacheCoverage.h"
+#include "cmParseJacocoCoverage.h"
#include "cmCTest.h"
#include "cmake.h"
#include "cmMakefile.h"
@@ -415,6 +416,13 @@ int cmCTestCoverageHandler::ProcessHandler()
return error;
}
+ file_count += this->HandleJacocoCoverage(&cont);
+ error = cont.Error;
+ if ( file_count < 0 )
+ {
+ return error;
+ }
+
std::set<std::string> uncovered = this->FindUncoveredFiles(&cont);
if ( file_count == 0 )
@@ -872,6 +880,38 @@ struct cmCTestCoverageHandlerLocale
};
//----------------------------------------------------------------------
+int cmCTestCoverageHandler::HandleJacocoCoverage(
+ cmCTestCoverageHandlerContainer* cont)
+{
+ cmParseJacocoCoverage cov =
+ cmParseJacocoCoverage(*cont, this->CTest);
+ cmsys::Glob g;
+ std::vector<std::string> files;
+ g.SetRecurse(true);
+
+ std::string SourceDir
+ = this->CTest->GetCTestConfiguration("SourceDirectory");
+ std::string coverageFile = SourceDir+ "/*jacoco.xml";
+
+ g.FindFiles(coverageFile);
+ files=g.GetFiles();
+ if (files.size() > 0)
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ "Found Jacoco Files, Performing Coverage" << std::endl);
+ cov.LoadCoverageData(files);
+ }
+ else
+ {
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+ " Cannot find Jacoco coverage files: " << coverageFile
+ << std::endl);
+ }
+ return static_cast<int>(cont->TotalCoverage.size());
+}
+
+
+//----------------------------------------------------------------------
int cmCTestCoverageHandler::HandleGCovCoverage(
cmCTestCoverageHandlerContainer* cont)
{
diff --git a/Source/CTest/cmCTestCoverageHandler.h b/Source/CTest/cmCTestCoverageHandler.h
index 38a3353..d0f274c 100644
--- a/Source/CTest/cmCTestCoverageHandler.h
+++ b/Source/CTest/cmCTestCoverageHandler.h
@@ -81,7 +81,10 @@ private:
//! Handle coverage for mumps
int HandleMumpsCoverage(cmCTestCoverageHandlerContainer* cont);
- //! Handle coverage using Bullseye
+ //! Handle coverage for Jacoco
+ int HandleJacocoCoverage(cmCTestCoverageHandlerContainer* cont);
+
+//! Handle coverage using Bullseye
int HandleBullseyeCoverage(cmCTestCoverageHandlerContainer* cont);
int RunBullseyeSourceSummary(cmCTestCoverageHandlerContainer* cont);
int RunBullseyeCoverageBranch(cmCTestCoverageHandlerContainer* cont,
diff --git a/Source/CTest/cmParseJacocoCoverage.cxx b/Source/CTest/cmParseJacocoCoverage.cxx
new file mode 100644
index 0000000..4723dd3
--- /dev/null
+++ b/Source/CTest/cmParseJacocoCoverage.cxx
@@ -0,0 +1,167 @@
+#include "cmStandardIncludes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "cmSystemTools.h"
+#include "cmXMLParser.h"
+#include "cmParseJacocoCoverage.h"
+#include <cmsys/Directory.hxx>
+#include <cmsys/Glob.hxx>
+#include <cmsys/FStream.hxx>
+
+
+class cmParseJacocoCoverage::XMLParser: public cmXMLParser
+{
+ public:
+ XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont)
+ : CTest(ctest), Coverage(cont)
+ {
+ this->PackageName = "";
+ this->ModuleName = "";
+ this->FileName = "";
+ this->CurFileName = "";
+ this->FilePaths.push_back(this->Coverage.SourceDir);
+ }
+
+ virtual ~XMLParser()
+ {
+ }
+
+ protected:
+
+ virtual void EndElement(const std::string&)
+ {
+ }
+
+ virtual void StartElement(const std::string& name,
+ const char** atts)
+ {
+ if(name == "package")
+ {
+ this->PackageName = atts[1];
+ std::string FilePath = this->Coverage.SourceDir +
+ "/" + this->ModuleName + "/src/main/java/" +
+ this->PackageName;
+ this->FilePaths.push_back(FilePath);
+ }
+ else if(name == "sourcefile")
+ {
+ this->FileName = atts[1];
+ cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Reading file: "
+ << this->FileName << std::endl);
+ for(size_t i=0;i < FilePaths.size();i++)
+ {
+ std::string finalpath = FilePaths[i] + "/" + this->FileName;
+ if(cmSystemTools::FileExists(finalpath.c_str()))
+ {
+ this->CurFileName = finalpath;
+ break;
+ }
+ }
+ cmsys::ifstream fin(this->CurFileName.c_str());
+ if(this->CurFileName == "" || !fin )
+ {
+ this->CurFileName = this->Coverage.BinaryDir + "/" +
+ this->FileName;
+ fin.open(this->CurFileName.c_str());
+ if (!fin)
+ {
+ cmCTestLog(this->CTest, ERROR_MESSAGE,
+ "Jacoco Coverage: Error opening " << this->CurFileName
+ << std::endl);
+ this->Coverage.Error++;
+ }
+ }
+ std::string line;
+ FileLinesType& curFileLines =
+ this->Coverage.TotalCoverage[this->CurFileName];
+ curFileLines.push_back(-1);
+ while(cmSystemTools::GetLineFromStream(fin, line))
+ {
+ curFileLines.push_back(-1);
+ }
+ }
+ else if(name == "report")
+ {
+ this->ModuleName=atts[1];
+ }
+ else if(name == "line")
+ {
+ int tagCount = 0;
+ int nr = -1;
+ int ci = -1;
+ while(true)
+ {
+ if(strcmp(atts[tagCount],"ci") == 0)
+ {
+ ci = atoi(atts[tagCount+1]);
+ }
+ else if (strcmp(atts[tagCount],"nr") == 0)
+ {
+ nr = atoi(atts[tagCount+1]);
+ }
+ if (ci > -1 && nr > 0)
+ {
+ FileLinesType& curFileLines=
+ this->Coverage.TotalCoverage[this->CurFileName];
+ if(curFileLines.size() > 0)
+ {
+ curFileLines[nr-1] = ci;
+ }
+ break;
+ }
+ ++tagCount;
+ }
+ }
+ }
+
+ private:
+ std::string PackageName;
+ std::string FileName;
+ std::string ModuleName;
+ std::string CurFileName;
+ std::vector<std::string> FilePaths;
+ typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
+ FileLinesType;
+ cmCTest* CTest;
+ cmCTestCoverageHandlerContainer& Coverage;
+};
+
+cmParseJacocoCoverage::cmParseJacocoCoverage(
+ cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest)
+ :Coverage(cont), CTest(ctest)
+ {
+ }
+
+bool cmParseJacocoCoverage::LoadCoverageData(
+ const std::vector<std::string> files)
+{
+ // load all the jacoco.xml files in the source directory
+ cmsys::Directory dir;
+ size_t i;
+ std::string path;
+ size_t numf = files.size();
+ for (i = 0; i < numf; i++)
+ {
+ path = files[i];
+
+ cmCTestLog(this->CTest,HANDLER_VERBOSE_OUTPUT,
+ "Reading XML File " << path << std::endl);
+ if(cmSystemTools::GetFilenameLastExtension(path) == ".xml")
+ {
+ if(!this->ReadJacocoXML(path.c_str()))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+bool cmParseJacocoCoverage::ReadJacocoXML(const char* file)
+{
+ cmParseJacocoCoverage::XMLParser
+ parser(this->CTest, this->Coverage);
+ parser.ParseFile(file);
+ return true;
+}
diff --git a/Source/CTest/cmParseJacocoCoverage.h b/Source/CTest/cmParseJacocoCoverage.h
new file mode 100644
index 0000000..dad05a3
--- /dev/null
+++ b/Source/CTest/cmParseJacocoCoverage.h
@@ -0,0 +1,59 @@
+/*============================================================================
+ CMake - Cross Platform Makefile Generator
+ Copyright 2000-2009 Kitware, Inc.
+
+ Distributed under the OSI-approved BSD License (the "License");
+ see accompanying file Copyright.txt for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even the
+ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the License for more information.
+============================================================================*/
+
+#ifndef cmParseJacocoCoverage_h
+#define cmParseJacocoCoverage_h
+
+#include "cmStandardIncludes.h"
+#include "cmCTestCoverageHandler.h"
+
+
+/** \class cmParseJacocoCoverage
+ * \brief Parse JaCoCO coverage information
+ *
+ * This class is used to parse coverage information for
+ * java using the JaCoCo tool:
+ *
+ * http://www.eclemma.org/jacoco/trunk/index.html
+ */
+class cmParseJacocoCoverage
+{
+public:
+ cmParseJacocoCoverage(cmCTestCoverageHandlerContainer& cont,
+ cmCTest* ctest);
+ bool LoadCoverageData(const std::vector<std::string> files);
+
+ std::string PackageName;
+ std::string FileName;
+ std::string ModuleName;
+ std::string CurFileName;
+private:
+ // implement virtual from parent
+ // remove files with no coverage
+ void RemoveUnCoveredFiles();
+ // Read a single mcov file
+ bool ReadJacocoXML(const char* f);
+ // split a string based on ,
+ bool SplitString(std::vector<std::string>& args,
+ std::string const& line);
+ bool FindJavaFile(std::string const& routine,
+ std::string& filepath);
+ void InitializeJavaFile(std::string& file);
+ bool LoadSource(std::string d);
+
+ class XMLParser;
+ std::map<std::string, std::string> RoutineToDirectory;
+ cmCTestCoverageHandlerContainer& Coverage;
+ cmCTest* CTest;
+};
+
+#endif