Skip to content

Commit

Permalink
allow to specify absolute paths for reports. to support msbuild runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Costa authored and jmecosta committed Dec 13, 2015
1 parent d646ffb commit d2038d6
Show file tree
Hide file tree
Showing 31 changed files with 814 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ target
*.pyc

*.java.orig
**/.sonarqube/*
**/Debug/**
**/Release/**
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ script:

after_failure:
- cat $SONARHOME/logs/sonar.log
- find . -name _cpp-multimodule-project-2_.log | xargs cat
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ install:
}
- cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET

build_script:
- mvn clean install
cache:
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/features/multimodule_analysis.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Feature: cpp-multimodule-project
.*WARN - .* cannot find the sources for .*
.*WARN - SCM provider autodetection failed.*
.*WARN.*Cannot find a report for '.*'
.*WARN.*- File access Failed '.*'
.*ERROR.*Invalid report baseDir '.*'
.*ERROR.*Using module base failed to find Path '.*'
"""
AND the following metrics have following values:
| metric | value |
Expand Down
42 changes: 42 additions & 0 deletions integration-tests/features/multimodule_analysis_2.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Feature: cpp-multimodule-project

Test multimodule project with reports at root of the project

Scenario: cpp-multimodule-project-2
GIVEN the project "cpp-multimodule-project-2"
WHEN I run "sonar-runner -X"
THEN the analysis finishes successfully
AND the analysis log contains no error/warning messages except those matching:
"""
.*WARN.*Unable to get a valid mac address, will use a dummy address
.*WARN.*cannot find the sources for '#include <gtest/gtest\.h>'
.*WARN.*cannot find the sources for '#include <iostream>'
.*WARN - Cannot find the file '.*', skipping violations
.*WARN.*to create a dependency with .*
.*WARN - the include root '.*' doesn't exist
.*WARN - .* cannot find the sources for .*
.*WARN - SCM provider autodetection failed.*
.*WARN.*Cannot find a report for '.*'
.*WARN.*- File access Failed '.*'
.*WARN.* A multi-module project can't have source folders, so '.*'
.*ERROR.*Invalid report baseDir '.*'
.*ERROR.*Using module base failed to find Path '.*'
"""
AND the following metrics have following values:
| metric | value |
# size metrics
| ncloc | 12 |
| lines | 14 |
| statements | 4 |
| classes | 0 |
| files | 6 |
| directories | 4 |
| functions | 4 |
# complexity
| complexity | 4 |
| function_complexity | 1.0 |
| file_complexity | 0.7 |
# violations
| violations | 4 |


28 changes: 25 additions & 3 deletions integration-tests/features/steps/test_execution_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@
from behave import given, when, then, model
from common import analyselog, build_regexp, sonarlog, analyseloglines

RED = ""
YELLOW = ""
GREEN = ""
RESET = ""
RESET_ALL = ""
BRIGHT = ""
try:
import colorama
colorama.init()
RED = colorama.Fore.RED
YELLOW = colorama.Fore.YELLOW
GREEN = colorama.Fore.GREEN
RESET = colorama.Fore.RESET
BRIGHT = colorama.Style.BRIGHT
RESET_ALL = colorama.Style.RESET_ALL
except ImportError:
pass

TESTDATADIR = os.path.normpath(os.path.join(os.path.realpath(__file__),
"..", "..", "..", "testdata"))
SONAR_URL = "http://localhost:9000"
Expand Down Expand Up @@ -195,12 +213,16 @@ def step_impl(context):

def assert_measures(project, measures):
metrics_to_query = measures.keys()
url = (SONAR_URL + "/api/resources?resource=" + project + "&metrics="
+ ",".join(metrics_to_query))

print(BRIGHT + "\nGet measures with query : " + url + RESET_ALL)

try:

url = (SONAR_URL + "/api/resources?resource=" + project + "&metrics="
+ ",".join(metrics_to_query))



response = requests.get(url)
got_measures = {}
json_measures = json.loads(response.text)[0].get("msr", None)
Expand All @@ -209,7 +231,7 @@ def assert_measures(project, measures):

diff = _diffMeasures(measures, got_measures)
except requests.exceptions.ConnectionError, e:
assert False, "cannot query the metrics, details: %s" % str(e)
assert False, "cannot query the metrics, details: %s -> url %s" % str(e) % url

assert diff == "", "\n" + diff

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<results>
<error file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project-2/A/1/a/dup.cpp" line="2" id="unreadVariable" severity="style" msg="Variable &apos;x&apos; is assigned a value that is never used."/>
<error file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project-2/A/1/a/x.cpp" line="2" id="unreadVariable" severity="style" msg="Variable &apos;x&apos; is assigned a value that is never used."/>
<error file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project-2/A/1/b/dup.cpp" line="2" id="unreadVariable" severity="style" msg="Variable &apos;x&apos; is assigned a value that is never used."/>
<error file="/home/travis/build/SonarOpenCommunity/sonar-cxx/integration-tests/testdata/cpp-multimodule-project-2/A/1/b/y.cpp" line="2" id="unreadVariable" severity="style" msg="Variable &apos;x&apos; is assigned a value that is never used."/>
</results>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{9595BF11-4B0A-4927-9787-F438305342DF}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>multimodule</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile />
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="x.cpp">
</ClCompile>
<ClCompile Include="dup.cpp">
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void funciton_1() {
int x = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sonar.projectName=a
sonar.sources=.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void funciton_2() {
int x = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{AFE14FC3-12F8-481C-A038-25399C2EEA95}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>multimodule</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile />
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="y.cpp">
</ClCompile>
<ClCompile Include="dup.cpp">
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void funciton_3() {
int x = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sonar.projectName=b
sonar.sources=.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
void funciton_4() {
int x = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sonar.projectName=1
sonar.modules=a,b
sonar.sources=.
Loading

0 comments on commit d2038d6

Please sign in to comment.