Skip to content

Commit

Permalink
Streamline packaging/binaries folder (#9487)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann committed Jul 9, 2024
1 parent 71bd653 commit c8e0cdd
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 30 deletions.
7 changes: 4 additions & 3 deletions analyzers/its/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<SonarProjectType Condition="$(SonarUnknownProjectType) == 'true'">Unknown</SonarProjectType>
</PropertyGroup>

<Error Text="Could not find '$(BinariesFolder)\SonarAnalyzer.dll'" Condition="!Exists('$(BinariesFolder)\SonarAnalyzer.dll')" />
<Error Text="Could not find '$(BinariesFolder)\SonarAnalyzer.CSharp\SonarAnalyzer.CSharp.dll'" Condition="!Exists('$(BinariesFolder)\SonarAnalyzer.CSharp\SonarAnalyzer.CSharp.dll')" />
<Error Text="Could not find '$(BinariesFolder)\SonarAnalyzer.VisualBasic\SonarAnalyzer.VisualBasic.dll'" Condition="!Exists('$(BinariesFolder)\SonarAnalyzer.VisualBasic\SonarAnalyzer.VisualBasic.dll')" />

<!-- This section builds content of SonarProjectConfig.xml additional file. We need to simulate S4MSB behavior to configure the analyzer. -->
<ItemGroup>
Expand Down Expand Up @@ -52,8 +53,8 @@
<!-- Remove all previously added analyzers, except built-in SourceGenerators -->
<Analyzer Remove="@(Analyzer)" Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('%(Filename)', '(Generator|Generators|SourceGeneration|SourceGenerators)$'))"/>
<!-- Add the SonarAnalyzer analyzer DLLs -->
<Analyzer Include="$(BinariesFolder)\SonarAnalyzer*.dll" />
<Analyzer Include="$(BinariesFolder)\Google.Protobuf.dll" />
<Analyzer Include="$(BinariesFolder)\SonarAnalyzer.CSharp\*.dll" />
<Analyzer Include="$(BinariesFolder)\SonarAnalyzer.VisualBasic\*.dll" />
<AdditionalFiles Include="$(MSBuildStartupDirectory)\output\$(PROJECT)\SonarLint.xml" />
<AdditionalFiles Include="$(SonarProjectConfigFilePath)" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions analyzers/its/regression-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ function Invoke-JsonParser()
try {
. (Join-Path $PSScriptRoot "..\..\scripts\build\build-utils.ps1")
Push-Location $PSScriptRoot
Test-FileExists "..\packaging\binaries\SonarAnalyzer.dll"
Test-FileExists "..\packaging\binaries\SonarAnalyzer.CFG.dll"
Test-FileExists "..\packaging\binaries\SonarAnalyzer.CSharp\SonarAnalyzer.CSharp.dll"
Test-FileExists "..\packaging\binaries\SonarAnalyzer.VisualBasic\SonarAnalyzer.VisualBasic.dll"
Test-FileExists "..\packaging\binaries\ITs.JsonParser\ITs.JsonParser.exe"

Write-Header "Initializing the environment"
Expand Down
2 changes: 1 addition & 1 deletion analyzers/packaging/SonarAnalyzer.CSharp.Styling.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</frameworkAssemblies>
</metadata>
<files>
<file src="binaries\internal\Internal.SonarAnalyzer.CSharp.Styling.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CSharp.Styling\Internal.SonarAnalyzer.CSharp.Styling.dll" target="analyzers" />
<file src="logos\sonarsource_64.png" target="images\" />
<file src="..\..\THIRD-PARTY-NOTICES.txt" target="license\" />
</files>
Expand Down
8 changes: 4 additions & 4 deletions analyzers/packaging/SonarAnalyzer.CSharp.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
</frameworkAssemblies>
</metadata>
<files>
<file src="binaries\Google.Protobuf.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CFG.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CSharp.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CSharp\Google.Protobuf.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CSharp\SonarAnalyzer.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CSharp\SonarAnalyzer.CFG.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CSharp\SonarAnalyzer.CSharp.dll" target="analyzers" />
<file src="tools-cs\*.ps1" target="tools\" />
<file src="logos\sonarsource_64.png" target="images\" />
<file src="..\..\THIRD-PARTY-NOTICES.txt" target="license\" />
Expand Down
8 changes: 4 additions & 4 deletions analyzers/packaging/SonarAnalyzer.VisualBasic.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
</frameworkAssemblies>
</metadata>
<files>
<file src="binaries\Google.Protobuf.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.CFG.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.VisualBasic.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.VisualBasic\Google.Protobuf.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.VisualBasic\SonarAnalyzer.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.VisualBasic\SonarAnalyzer.CFG.dll" target="analyzers" />
<file src="binaries\SonarAnalyzer.VisualBasic\SonarAnalyzer.VisualBasic.dll" target="analyzers" />
<file src="tools-vbnet\*.ps1" target="tools\" />
<file src="logos\sonarsource_64.png" target="images\" />
<file src="..\..\THIRD-PARTY-NOTICES.txt" target="license\" />
Expand Down
10 changes: 3 additions & 7 deletions analyzers/src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
<Import Project="$(MSBuildThisFileDirectory)\..\Analyzers.targets" />

<PropertyGroup>
<!-- `BinariesFolder` - binary files folder used by ITs and java packaging -->
<BinariesFolder>$(MSBuildThisFileDirectory)..\packaging\binaries\</BinariesFolder>
<!-- Avoid SonarAnalyzer.CSharp.Styling to be picked up by Java ITs -->
<BinariesFolderInternal>$(BinariesFolder)internal\</BinariesFolderInternal>
<!-- `BinariesFolder` - binary files folder used by ITs, NuGet and java packaging -->
<BinariesFolder>$(MSBuildThisFileDirectory)..\packaging\binaries\$(ProjectName)</BinariesFolder>
</PropertyGroup>

<!-- The condition causes the target to only be executed once during the outer build step.
Without it, it will be executed multiple times, which can introduce race conditions. -->
<Target Name="CleanBinaries" AfterTargets="Clean" Condition="'$(IsCrossTargetingBuild)' == 'true' And Exists('$(BinariesFolder)')">
<Target Name="CleanBinaries" AfterTargets="Clean" Condition="Exists('$(BinariesFolder)')">
<RemoveDir Directories="$(BinariesFolder)" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion analyzers/src/ITs.JsonParser/ITs.JsonParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<BinariesToCopy Include="$(OutputPath)\*.dll" />
<BinariesToCopy Include="$(OutputPath)\*.json" />
</ItemGroup>
<Copy SourceFiles="@(BinariesToCopy)" DestinationFolder="$(BinariesFolder)\ITs.JsonParser" />
<Copy SourceFiles="@(BinariesToCopy)" DestinationFolder="$(BinariesFolder)" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<BinariesToCopy Include="$(OutputPath)\*.dll" />
<BinariesToCopy Include="$(OutputPath)\*.json" />
</ItemGroup>
<Copy SourceFiles="@(BinariesToCopy)" DestinationFolder="$(BinariesFolder)\RuleDescriptorGenerator" />
<Copy SourceFiles="@(BinariesToCopy)" DestinationFolder="$(BinariesFolder)" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
</Target>

<Target Name="CopyBinaries" AfterTargets="Build" DependsOnTargets="SignDlls">
<Copy SourceFiles="$(OutputPath)$(TargetFileName)" DestinationFolder="$(BinariesFolderInternal)" />
<Copy SourceFiles="$(OutputPath)$(TargetFileName)" DestinationFolder="$(BinariesFolder)" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion docs/contributing-analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ You can visualize the differences using:
If you want to debug the analysis of a project, you can add a [`Debugger.Launch()`](https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debugger.launch) breakpoint in the class you want to debug. Rebuild `SonarAnalyzer.sln` and link the analyzer debug binaries to the project you want to debug the analysis for.

- If you are analyzing the project with the Scanner for .NET, after the begin step you can replace the binaries in the local cache (`%TEMP%\.sonarqube\resources\` - the `0` folder for the C# Analyzer, the `1` folder for the VB .NET analyzer), and then run the build.
- If you don't want to use the Scanner for .NET, you can manually reference the binaries in `analyzers/packaging/binaries/` in the {cs,vb}proj file with `<Analyzer Include=... />` items (see [Directory.Build.targets](../analyzers/its/Directory.Build.targets#L46) as an example)
- If you don't want to use the Scanner for .NET, you can manually reference the binaries in `analyzers/packaging/binaries/` in the {cs,vb}proj file with `<Analyzer Include=... />` items (see [Directory.Build.targets](../analyzers/its/Directory.Build.targets#L55) as an example)

Please note that if the rule is not in SonarWay, you will also need to enable it in a RuleSet file and link it in the {cs,vb}proj file with the `<CodeAnalysisRuleSet>` property (see [example](../analyzers/src/Directory.Build.targets#L8)).

Expand Down
2 changes: 1 addition & 1 deletion its/src/test/java/com/sonar/it/shared/StylingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class StylingTest {
@Test
public void hasIssues() throws IOException {
Path projectFullPath = TestUtils.projectDir(temp, PROJECT);
FileUtils.copyFile(new File("..\\analyzers\\packaging\\binaries\\internal\\" + STYLING_DLL),
FileUtils.copyFile(new File("..\\analyzers\\packaging\\binaries\\SonarAnalyzer.CSharp.Styling\\" + STYLING_DLL),
projectFullPath.resolve(STYLING_DLL).toFile());
Tests.ORCHESTRATOR.executeBuild(TestUtils.createBeginStep(PROJECT, projectFullPath));
TestUtils.runBuild(projectFullPath);
Expand Down
4 changes: 2 additions & 2 deletions sonar-csharp-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
<target>
<!-- ITs requires the SonarAnalyzer-VERSION.zip to be present so don't remove these lines -->
<copy todir="${sonarAnalyzer.workDirectory}/SonarAnalyzer.CSharp">
<fileset dir="${analyzers.directory}/packaging/binaries/">
<fileset dir="${analyzers.directory}/packaging/binaries/SonarAnalyzer.CSharp/">
<include name="Google.Protobuf.dll"/>
<include name="SonarAnalyzer.dll"/>
<include name="SonarAnalyzer.CFG.dll"/>
Expand All @@ -247,7 +247,7 @@
failonerror="true"
dir="${analyzers.directory}/packaging/binaries/RuleDescriptorGenerator">
<arg value="RuleDescriptorGenerator.dll"/>
<arg value="${analyzers.directory}/packaging/binaries/SonarAnalyzer.CSharp.dll"/>
<arg value="${analyzers.directory}/packaging/binaries/SonarAnalyzer.CSharp/SonarAnalyzer.CSharp.dll"/>
<arg value="${sonarAnalyzer.workDirectory}/org/sonar/plugins/csharp/Rules.json"/>
</exec>
<copy todir="${sonarAnalyzer.workDirectory}/static">
Expand Down
4 changes: 2 additions & 2 deletions sonar-vbnet-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
<target>
<!-- ITs requires the SonarAnalyzer-VERSION.zip to be present so don't remove these lines -->
<copy todir="${sonarAnalyzer.workDirectory}/SonarAnalyzer.VisualBasic">
<fileset dir="${analyzers.directory}/packaging/binaries/">
<fileset dir="${analyzers.directory}/packaging/binaries/SonarAnalyzer.VisualBasic/">
<include name="Google.Protobuf.dll"/>
<include name="SonarAnalyzer.dll"/>
<include name="SonarAnalyzer.CFG.dll"/>
Expand All @@ -247,7 +247,7 @@
failonerror="true"
dir="${analyzers.directory}/packaging/binaries/RuleDescriptorGenerator">
<arg value="RuleDescriptorGenerator.dll"/>
<arg value="${analyzers.directory}/packaging/binaries/SonarAnalyzer.VisualBasic.dll"/>
<arg value="${analyzers.directory}/packaging/binaries/SonarAnalyzer.VisualBasic/SonarAnalyzer.VisualBasic.dll"/>
<arg value="${sonarAnalyzer.workDirectory}/org/sonar/plugins/vbnet/Rules.json"/>
</exec>
<copy todir="${sonarAnalyzer.workDirectory}/static">
Expand Down

0 comments on commit c8e0cdd

Please sign in to comment.