[Cmake-commits] CMake branch, next, updated. v3.3.1-2662-gb104667

Zack Galbreath zack.galbreath at kitware.com
Mon Aug 31 14:58:29 EDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  b104667b9132bdc13fe42bde140378d579bfb3e6 (commit)
       via  8dc7f6c425ebdf1db8280e3b5f64a52729db64da (commit)
      from  5ce9fe1efde6b17acdd0b3ae1dac0b65c0254893 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b104667b9132bdc13fe42bde140378d579bfb3e6
commit b104667b9132bdc13fe42bde140378d579bfb3e6
Merge: 5ce9fe1 8dc7f6c
Author:     Zack Galbreath <zack.galbreath at kitware.com>
AuthorDate: Mon Aug 31 14:58:27 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Aug 31 14:58:27 2015 -0400

    Merge topic 'jacoco_find_files' into next
    
    8dc7f6c4 Make Jacoco parser better at finding source files


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=8dc7f6c425ebdf1db8280e3b5f64a52729db64da
commit 8dc7f6c425ebdf1db8280e3b5f64a52729db64da
Author:     Zack Galbreath <zack.galbreath at kitware.com>
AuthorDate: Fri Aug 28 13:35:47 2015 -0400
Commit:     Zack Galbreath <zack.galbreath at kitware.com>
CommitDate: Fri Aug 28 13:38:26 2015 -0400

    Make Jacoco parser better at finding source files
    
    Instead of searching for source files in a couple hard-coded
    locations, we now search the source and binary directory for files
    matching both the name of the covered file and its package
    directory structure.

diff --git a/Source/CTest/cmParseJacocoCoverage.cxx b/Source/CTest/cmParseJacocoCoverage.cxx
index 31ad9fe..47e3b32 100644
--- a/Source/CTest/cmParseJacocoCoverage.cxx
+++ b/Source/CTest/cmParseJacocoCoverage.cxx
@@ -15,11 +15,9 @@ class cmParseJacocoCoverage::XMLParser: public cmXMLParser
     XMLParser(cmCTest* ctest, cmCTestCoverageHandlerContainer& cont)
       : CTest(ctest), Coverage(cont)
       {
+      this->FilePath = "";
+      this->PackagePath = "";
       this->PackageName = "";
-      this->ModuleName = "";
-      this->FileName = "";
-      this->CurFileName = "";
-      this->FilePaths.push_back(this->Coverage.SourceDir);
       }
 
     virtual ~XMLParser()
@@ -38,58 +36,46 @@ class cmParseJacocoCoverage::XMLParser: public cmXMLParser
       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);
-        FilePath = this->Coverage.SourceDir +
-         "/src/main/java/" + this->PackageName;
-        this->FilePaths.push_back(FilePath);
+        this->PackagePath = "";
         }
       else if(name == "sourcefile")
         {
-        this->FileName = atts[1];
-        cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
-          "Reading file: " << this->FileName << std::endl,
-          this->Coverage.Quiet);
-          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 )
+        std::string fileName = atts[1];
+
+        if (this->PackagePath == "")
           {
-            this->CurFileName = this->Coverage.BinaryDir + "/" +
-                                   this->FileName;
-            fin.open(this->CurFileName.c_str());
-            if (!fin)
+          if(!this->FindPackagePath(fileName))
             {
-              cmCTestLog(this->CTest, ERROR_MESSAGE,
-                         "Jacoco Coverage: Error opening " << this->CurFileName
-                         << std::endl);
-              this->Coverage.Error++;
+            cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot find file: "
+              << this->PackageName << "/" << fileName << std::endl);
+            this->Coverage.Error++;
+            return;
             }
           }
-          std::string line;
-          FileLinesType& curFileLines =
-            this->Coverage.TotalCoverage[this->CurFileName];
-          if(fin)
-            {
-            curFileLines.push_back(-1);
-            }
-          while(cmSystemTools::GetLineFromStream(fin, line))
+
+        cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+          "Reading file: " << fileName << std::endl,
+          this->Coverage.Quiet);
+
+        this->FilePath = this->PackagePath + "/" + fileName;
+        cmsys::ifstream fin(this->FilePath.c_str());
+        if (!fin)
           {
-            curFileLines.push_back(-1);
+          cmCTestLog(this->CTest, ERROR_MESSAGE,
+                     "Jacoco Coverage: Error opening " << this->FilePath
+                     << std::endl);
+          }
+        std::string line;
+        FileLinesType& curFileLines =
+          this->Coverage.TotalCoverage[this->FilePath];
+        if(fin)
+          {
+          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")
         {
@@ -109,7 +95,7 @@ class cmParseJacocoCoverage::XMLParser: public cmXMLParser
           if (ci > -1 && nr > 0)
             {
             FileLinesType& curFileLines=
-              this->Coverage.TotalCoverage[this->CurFileName];
+              this->Coverage.TotalCoverage[this->FilePath];
             if(!curFileLines.empty())
                {
                curFileLines[nr-1] = ci;
@@ -121,12 +107,61 @@ class cmParseJacocoCoverage::XMLParser: public cmXMLParser
         }
       }
 
+    virtual bool FindPackagePath(const std::string fileName)
+      {
+      // Search for the source file in the source directory.
+      if (this->PackagePathFound(fileName, this->Coverage.SourceDir))
+        {
+        return true;
+        }
+
+      // If not found there, check the binary directory.
+      if (this->PackagePathFound(fileName, this->Coverage.BinaryDir))
+        {
+        return true;
+        }
+      return false;
+      }
+
+    virtual bool PackagePathFound(const std::string fileName,
+                                  const std::string baseDir)
+      {
+      // Search for the file in the baseDir and its subdirectories.
+      std::string packageGlob = baseDir;
+      packageGlob += "/";
+      packageGlob += fileName;
+      cmsys::Glob gl;
+      gl.RecurseOn();
+      gl.RecurseThroughSymlinksOn();
+      gl.FindFiles(packageGlob);
+      std::vector<std::string> const& files = gl.GetFiles();
+      if (files.size() == 0)
+        {
+        return false;
+        }
+
+      // Check if any of the locations found match our package.
+      for(std::vector<std::string>::const_iterator fi = files.begin();
+          fi != files.end(); ++fi)
+        {
+        std::string dir = cmsys::SystemTools::GetParentDirectory(*fi);
+        if (cmsys::SystemTools::StringEndsWith(dir, this->PackageName.c_str()))
+          {
+          cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
+                             "Found package directory for " << fileName <<
+                             ": " << dir << std::endl,
+                             this->Coverage.Quiet);
+          this->PackagePath = dir;
+          return true;
+          }
+        }
+      return false;
+      }
+
   private:
+    std::string FilePath;
+    std::string PackagePath;
     std::string PackageName;
-    std::string FileName;
-    std::string ModuleName;
-    std::string CurFileName;
-    std::vector<std::string> FilePaths;
     typedef cmCTestCoverageHandlerContainer::SingleFileCoverageVector
      FileLinesType;
     cmCTest* CTest;

-----------------------------------------------------------------------

Summary of changes:
 Source/CTest/cmParseJacocoCoverage.cxx |  139 ++++++++++++++++++++------------
 1 file changed, 87 insertions(+), 52 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list