diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..994a0ab --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "OpenCppCoverage"] + path = OpenCppCoverage + url = https://github.com/OpenCppCoverage/OpenCppCoverage.git diff --git a/OCCSonarQube/OCCSonarQube.sln b/OCCSonarQube/OCCSonarQube.sln new file mode 100644 index 0000000..0969ecf --- /dev/null +++ b/OCCSonarQube/OCCSonarQube.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.329 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SonarQube", "SonarQube\SonarQube.vcxproj", "{19007FBB-9040-43AA-BCF2-F3D84F07B302}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin", "..\..\OpenCppCoverage\Plugin\Plugin.vcxproj", "{2F439508-07E0-4084-9614-1A42BDE8ED9A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Debug|x64.ActiveCfg = Debug|x64 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Debug|x64.Build.0 = Debug|x64 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Debug|x86.ActiveCfg = Debug|Win32 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Debug|x86.Build.0 = Debug|Win32 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Release|x64.ActiveCfg = Release|x64 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Release|x64.Build.0 = Release|x64 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Release|x86.ActiveCfg = Release|Win32 + {19007FBB-9040-43AA-BCF2-F3D84F07B302}.Release|x86.Build.0 = Release|Win32 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Debug|x64.ActiveCfg = Debug|x64 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Debug|x64.Build.0 = Debug|x64 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Debug|x86.ActiveCfg = Debug|Win32 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Debug|x86.Build.0 = Debug|Win32 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Release|x64.ActiveCfg = Release|x64 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Release|x64.Build.0 = Release|x64 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Release|x86.ActiveCfg = Release|Win32 + {2F439508-07E0-4084-9614-1A42BDE8ED9A}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {76ACB947-B189-462E-BA68-2D11D0787AA4} + EndGlobalSection +EndGlobal diff --git a/OCCSonarQube/SonarQube/SonarQube.cpp b/OCCSonarQube/SonarQube/SonarQube.cpp new file mode 100644 index 0000000..9b56a79 --- /dev/null +++ b/OCCSonarQube/SonarQube/SonarQube.cpp @@ -0,0 +1,107 @@ +#include "stdafx.h" + +#include "Plugin/Exporter/IExportPlugin.hpp" +#include "Plugin/Exporter/CoverageData.hpp" +#include "Plugin/Exporter/ModuleCoverage.hpp" +#include "Plugin/Exporter/FileCoverage.hpp" +#include "Plugin/Exporter/LineCoverage.hpp" +#include "Plugin/OptionsParserException.hpp" + +#include +#include +#include +#include +#include +#include + + +class SonarQubeExport : public Plugin::IExportPlugin +{ +public: + //------------------------------------------------------------------------- + std::optional Export( + const Plugin::CoverageData& coverageData, + const std::optional& argument ) override + { + std::wstring currentfile; + std::filesystem::path output = argument ? *argument : L"SonarQube.xml"; + std::wofstream ofs{ output }; + + if ( !ofs ) + throw std::runtime_error( "Cannot create the output file for SonarQube exporting" ); + + // Convert to our internal maps. We do this because we want to collate the same file if it is seen multiple times + for ( const auto& mod : coverageData.GetModules() ) + { + // Skip the module if it has no files + if ( mod->GetFiles().empty() ) + continue; + + for ( const auto& file : mod->GetFiles() ) + { + // Skip the file if it has no lines + if ( file->GetLines().empty() ) + continue; + + currentfile = file->GetPath().wstring(); + auto &file_entry = coverage[currentfile]; + + for ( const auto &line : file->GetLines() ) + { + // In case we have seen thils file/line before, we want to 'or' in the iteration's HasBeenExecuted + auto &line_entry = file_entry[line.GetLineNumber()]; + line_entry |= line.HasBeenExecuted(); + } + } + } + + ofs << L"" << std::endl; + + std::wstring covered; + for ( const auto &file_iter : coverage ) + { + ofs << L" " << std::endl; + for ( const auto &line_iter : file_iter.second ) + { + covered = line_iter.second ? L"true" : L"false"; + ofs << L" " << std::endl; + } + ofs << L" " << std::endl; + } + ofs << L"" << std::endl; + + return output; + } + + //------------------------------------------------------------------------- + void CheckArgument( const std::optional& argument ) override + { + // Try to check if the argument is a file. + if ( argument && !std::filesystem::path{ *argument }.has_filename() ) + throw Plugin::OptionsParserException( "Invalid argument for SonarQube export." ); + } + + //------------------------------------------------------------------------- + std::wstring GetArgumentHelpDescription() override + { + return L"output file (optional)"; + } + + //------------------------------------------------------------------------- + int GetExportPluginVersion() const override + { + return Plugin::CurrentExportPluginVersion; + } + +protected: + std::unordered_map< std::wstring, std::map > coverage; +}; + +extern "C" +{ + //------------------------------------------------------------------------- + __declspec(dllexport) Plugin::IExportPlugin* CreatePlugin() + { + return new SonarQubeExport(); + } +} diff --git a/OCCSonarQube/SonarQube/SonarQube.vcxproj b/OCCSonarQube/SonarQube/SonarQube.vcxproj new file mode 100644 index 0000000..a1f6820 --- /dev/null +++ b/OCCSonarQube/SonarQube/SonarQube.vcxproj @@ -0,0 +1,183 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {19007FBB-9040-43AA-BCF2-F3D84F07B302} + Win32Proj + SonarQube + 10.0.17763.0 + + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;SONARQUBE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + stdcpp17 + ..\..\OpenCppCoverage + MultiThreadedDebug + + + Windows + true + + + + + Use + Level3 + Disabled + true + _DEBUG;SONARQUBE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + stdcpp17 + ..\..\OpenCppCoverage + MultiThreadedDebug + + + Windows + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;SONARQUBE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + stdcpp17 + ..\..\OpenCppCoverage + MultiThreaded + + + Windows + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;SONARQUBE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + stdcpp17 + ..\..\OpenCppCoverage + MultiThreaded + + + Windows + true + true + true + + + + + + + + + + + Create + Create + Create + Create + + + + + {2f439508-07e0-4084-9614-1a42bde8ed9a} + + + + + + \ No newline at end of file diff --git a/OCCSonarQube/SonarQube/SonarQube.vcxproj.filters b/OCCSonarQube/SonarQube/SonarQube.vcxproj.filters new file mode 100644 index 0000000..c918ced --- /dev/null +++ b/OCCSonarQube/SonarQube/SonarQube.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/OCCSonarQube/SonarQube/dllmain.cpp b/OCCSonarQube/SonarQube/dllmain.cpp new file mode 100644 index 0000000..465ae72 --- /dev/null +++ b/OCCSonarQube/SonarQube/dllmain.cpp @@ -0,0 +1,19 @@ +// dllmain.cpp : Defines the entry point for the DLL application. +#include "stdafx.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/OCCSonarQube/SonarQube/stdafx.cpp b/OCCSonarQube/SonarQube/stdafx.cpp new file mode 100644 index 0000000..fd4f341 --- /dev/null +++ b/OCCSonarQube/SonarQube/stdafx.cpp @@ -0,0 +1 @@ +#include "stdafx.h" diff --git a/OCCSonarQube/SonarQube/stdafx.h b/OCCSonarQube/SonarQube/stdafx.h new file mode 100644 index 0000000..f380517 --- /dev/null +++ b/OCCSonarQube/SonarQube/stdafx.h @@ -0,0 +1,16 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include + + + +// reference additional headers your program requires here diff --git a/OCCSonarQube/SonarQube/targetver.h b/OCCSonarQube/SonarQube/targetver.h new file mode 100644 index 0000000..87c0086 --- /dev/null +++ b/OCCSonarQube/SonarQube/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/OpenCppCoverage b/OpenCppCoverage new file mode 160000 index 0000000..9399456 --- /dev/null +++ b/OpenCppCoverage @@ -0,0 +1 @@ +Subproject commit 9399456a086c02fd5219c4e3b0f015e8da1cb820