Skip to content

Commit

Permalink
Improved logging in targets files (#785)
Browse files Browse the repository at this point in the history
Fixes #770
  • Loading branch information
duncanp-sonar authored and mickael-caro-sonarsource committed Aug 29, 2019
1 parent e047a8e commit b04ea88
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
</PropertyGroup>

<!-- Diagnostic messages for troubleshooting -->
<Message Importance="low" Text="SonarQube.Integration.ImportBefore.targets was loaded" />
<Message Importance="low" Text="SonarQube analysis targets file found: $(AnalysisTargetsFileFound)" />
<Message Importance="low" Text="SonarQube analysis targets imported: $(SonarQubeTargetsImported)" />
<Message Importance="normal" Text="Sonar: ($(MSBuildProjectName)) SonarQube.Integration.ImportBefore.targets was loaded" />
<Message Importance="low" Text="Sonar: ($(MSBuildProjectFile)) SonarQube analysis targets file found: $(AnalysisTargetsFileFound)" />
<Message Importance="low" Text="Sonar: ($(MSBuildProjectFile)) SonarQube analysis targets imported: $(SonarQubeTargetsImported)" />

<!-- Conditionally raise an error that will fail the build -->
<Message Condition=" $(ReportAnalysisTargetsError) == 'true'"
Importance="high"
Text="Calculated location for the analysis targets file: $(SonarQubeTargetFilePath)" />
Text="Sonar: ($(MSBuildProjectFile)) Calculated location for the analysis targets file: $(SonarQubeTargetFilePath)" />

<!-- We include name of the project being built in the error message as
it helps provide some context in TeamBuild scenarios when the error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@

<Target Name="SkippingSonarQubeAnalysis" BeforeTargets="Build"
Condition=" $(SonarQubeTempPath) == '' ">
<Message Importance="high" Text="Skipping dumping compile outputs because SonarQubeTempPath has not been specified" />
<Message Importance="high" Text="Sonar: ($(MSBuildProjectFile)) Skipping dumping compile outputs because SonarQubeTempPath has not been specified" />
</Target>

<Target Name="FailIfLowerThanMSBuild14"
Condition=" $(SonarQubeTempPath) != '' AND $(MSBuildToolsVersion) != '14.0' AND $(MSBuildToolsVersion) != '15.0' AND $(MSBuildToolsVersion) != 'Current'"
BeforeTargets="Build">
<Message Importance="high" Text="Current MSBuildToolsVersion: $(MSBuildToolsVersion)" />
<Message Importance="high" Text="Current MSBuildAssemblyVersion: $(MSBuildAssemblyVersion)" />
<Message Importance="high" Text="Sonar: ($(MSBuildProjectFile)) Current MSBuildToolsVersion: $(MSBuildToolsVersion)" />
<Message Importance="high" Text="Sonar: ($(MSBuildProjectFile)) Current MSBuildAssemblyVersion: $(MSBuildAssemblyVersion)" />
<Error Text="SonarQube analysis is only supported with MSBuild 14 or later." />
</Target>

Expand All @@ -166,6 +166,9 @@
<Target Name="SonarQubeCategoriseProject"
Condition=" $(SonarQubeTempPath) != '' ">

<Message Text="Sonar: ($(MSBuildProjectFile)) Categorizing project as test or product code..." />
<Message Condition="$(SonarQubeTestProject) != ''" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) SonarQubeTestProject has been set explicitly to $(SonarQubeTestProject)" />

<!-- Fakes detection -->
<PropertyGroup>
<IsFakesProject Condition="$(AssemblyName.EndsWith('.fakes', System.StringComparison.OrdinalIgnoreCase))">true</IsFakesProject>
Expand All @@ -174,6 +177,7 @@
<SonarQubeTestProject>true</SonarQubeTestProject>
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
<Message Condition="$(IsFakesProject) == 'true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) project is a temporary project generated by Microsoft Fakes and will be ignored" />

<!-- Temporary project detection -->
<!-- Some kinds of project have logic to trigger additional special builds based on
Expand All @@ -192,28 +196,46 @@
<PropertyGroup Condition="$(IsTempProject) == 'true' AND $(SonarQubeExclude)==''" >
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>
<Message Condition="$(IsTempProject) == 'true' AND $(SonarQubeExclude)==''" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) project is a temporary project and will be excluded" />

<PropertyGroup Condition=" $(SonarQubeTestProject) == '' ">
<!-- The MS Test project type guid-->
<SonarQubeMsTestProjectTypeGuid>3AC096D0-A1C2-E12C-1390-A8335801FDAB</SonarQubeMsTestProjectTypeGuid>
<SonarQubeTestProject Condition=" $(ProjectTypeGuids.ToUpperInvariant().Contains('$(SonarQubeMsTestProjectTypeGuid)')) ">true</SonarQubeTestProject>

<tmpSonarHasMSTestProjectTypeGuid Condition=" $(ProjectTypeGuids.ToUpperInvariant().Contains('$(SonarQubeMsTestProjectTypeGuid)')) ">true</tmpSonarHasMSTestProjectTypeGuid>
<SonarQubeTestProject Condition=" $(tmpSonarHasMSTestProjectTypeGuid)=='true' ">true</SonarQubeTestProject>
</PropertyGroup>
<Message Condition="$(tmpSonarHasMSTestProjectTypeGuid)=='true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) project has the MSTest project type guid -> test project" />

<PropertyGroup Condition=" $(SonarQubeTestProject) == '' ">
<!-- The legacy Service tag added by the Test Explorer window -->
<tmpSQServiceList>@(Service)</tmpSQServiceList>
<SonarQubeTestProject Condition="$(tmpSQServiceList.ToUpperInvariant().Contains('{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}')) ">true</SonarQubeTestProject>
<tmpSonarHasServiceTag Condition="$(tmpSQServiceList.ToUpperInvariant().Contains('{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}')) ">true</tmpSonarHasServiceTag>
<SonarQubeTestProject Condition="$(tmpSonarHasServiceTag)=='true'">true</SonarQubeTestProject>
</PropertyGroup>
<Message Condition="$(tmpSonarHasServiceTag)=='true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) project has the legacy Test Explorer Service tag {82A7F48D-3B50-4B1E-B82E-3ADA8210C358} -> test project" />

<PropertyGroup Condition=" $(SonarQubeTestProject) == '' ">
<!-- The ProjectCapability for test projects -->
<tmpSQProjectCapabilities>@(ProjectCapability)</tmpSQProjectCapabilities>
<SonarQubeTestProject Condition="$(tmpSQProjectCapabilities.ToUpperInvariant().Contains('TESTCONTAINER')) ">true</SonarQubeTestProject>
<tmpSonarHasTestContainerCapability Condition="$(tmpSQProjectCapabilities.ToUpperInvariant().Contains('TESTCONTAINER')) ">true</tmpSonarHasTestContainerCapability>
<SonarQubeTestProject Condition="$(tmpSonarHasTestContainerCapability)=='true'">true</SonarQubeTestProject>
</PropertyGroup>
<Message Condition="$(tmpSonarHasTestContainerCapability)=='true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) project has the ProjectCapability 'TestContainer' -> test project" />

<!-- If we haven't already determined whether the project is a test project then check
its path/name against the regular expression in the config file -->
<IsTestFileByName Condition=" $(SonarQubeTestProject) == '' "
AnalysisConfigDir="$(SonarQubeConfigPath)"
FullFilePath="$(MSBuildProjectFullPath)">
<Output TaskParameter="IsTest" PropertyName="SonarQubeTestProject" />
<Output TaskParameter="IsTest" PropertyName="tmpSonarIsTestFileByNameResult" />
</IsTestFileByName>

<PropertyGroup Condition=" $(SonarQubeTestProject) == '' ">
<SonarQubeTestProject>$(tmpSonarIsTestFileByNameResult)</SonarQubeTestProject>
</PropertyGroup>
<Message Condition="$(tmpSonarIsTestFileByNameResult)=='true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) project is evaluated as a test project based on the project name" />

<Message Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) Project categorized. SonarQubeTestProject=$(SonarQubeTestProject)" />
</Target>

<!-- **************************************************************************** -->
Expand Down Expand Up @@ -286,6 +308,9 @@
<AnalysisFileList>$(ProjectSpecificOutDir)\FilesToAnalyze.txt</AnalysisFileList>
</PropertyGroup>

<Message Condition="$(AnalysisFilesExist)!='true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) No files were found to analyse" />
<Message Condition="$(AnalysisFilesExist)=='true'" Importance="normal" Text="Sonar: ($(MSBuildProjectFile)) Number of files to analyse: @(SonarQubeAnalysisFiles->Count()). The list of files to be analyzed is in $(AnalysisFileList)." />

<!-- Write out a list of files to analyze that will be passed to the sonar-scanner -->
<WriteLinesToFile Condition=" $(AnalysisFilesExist) == 'true' "
File="$(AnalysisFileList)"
Expand All @@ -300,8 +325,6 @@
</AnalysisResults>
</ItemGroup>

<Message Importance="low" Condition=" $(SonarQubeTestProject) == 'true' "
Text="SonarQube: project will be treated as a test project : $(MSBuildProjectName)" />
<CallTarget Targets="FixUpTestProjectOutputs" />

<WriteProjectInfoFile ProjectName="$(MSBuildProjectName)"
Expand All @@ -318,10 +341,12 @@
Configuration="$(Configuration)"
Platform="$(Platform)"
TargetFramework="$(TargetFramework)" />

<Message Importance="high" Text="Sonar: ($(MSBuildProjectFile)) Project processed successfully" />
</Target>

<Target Name="FixUpTestProjectOutputs" Condition="$(SonarQubeTestProject)=='true'" >
<Message Importance="low" Text="Fixing up test project outputs..." />
<Message Importance="low" Text="Sonar: ($(MSBuildProjectFile)) Fixing up test project outputs..." />

<ItemGroup>
<!-- Select specific metrics files that should not be uploaded for test files.
Expand All @@ -330,7 +355,7 @@
<SQTestMetricFiles Include="$(ProjectSpecificOutDir)\*\token-cpd.pb" />
</ItemGroup>

<Message Importance="low" Text="Selected test metric file: @(SQTestMetricFiles)" />
<Message Importance="low" Text="Sonar: ($(MSBuildProjectFile)) Selected test metric file: @(SQTestMetricFiles)" />
<WriteZeroLengthFiles FullFilePaths="@(SQTestMetricFiles)" />
</Target>

Expand Down

0 comments on commit b04ea88

Please sign in to comment.