Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLVS-1559 Embed Enterprise dotnet analyzer #5787

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ UnitTestResults.html
# Visual Studio temp directories
.vs/

# Rider temp directories
.idea/

# Visual C++ cache files
ipch/
*.aps
Expand Down Expand Up @@ -170,4 +173,5 @@ $RECYCLE.BIN/
/**/launchSettings.json
/src/Rules/Embedded
/src/Integration.Vsix/DownloadedJars
/src/Integration.Vsix/Sloop
/src/Integration.Vsix/Sloop
/src/Integration.Vsix/EmbeddedDotnetAnalyzerDLLs
15 changes: 13 additions & 2 deletions build/CopyDependencies/CopyDependencies.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
<Target Name="Build">
<CallTarget Targets="ClearDirs" />
<CallTarget Targets="CopyJars" />
<CallTarget Targets="CopyEnterpriseDotnet" />
<CallTarget Targets="CopySloop" />
</Target>

<PropertyGroup>
<VsixDir>..\..\src\Integration.Vsix</VsixDir>
<EnterpriseDotnetAnalyzersExtractDir>$(LOCALAPPDATA)\SLVS_Build_Dotnet\EnterpriseAnalyzerDlls-$(EmbeddedSonarAnalyzerVersion)</EnterpriseDotnetAnalyzersExtractDir>
<EmbeddedEnterpriseDotnetAnalyzersDir>$(VsixDir)\EmbeddedDotnetAnalyzerDLLs</EmbeddedEnterpriseDotnetAnalyzersDir>
<JarDownloadDir>$(LOCALAPPDATA)\SLVS_Build_DownloadedJars</JarDownloadDir>
<EmbeddedJarDir>$(VsixDir)\DownloadedJars</EmbeddedJarDir>
<SloopDowloadDir>$(LOCALAPPDATA)\SLVS_Build_SLOOP\sonarlint-backend-cli-$(EmbeddedSloopVersion)-windows_x64</SloopDowloadDir>
Expand All @@ -19,18 +22,26 @@
<Target Name="ClearDirs">
<RemoveDir Directories="$(EmbeddedJarDir)" />
<RemoveDir Directories="$(EmbeddedSloopDir)" />
<RemoveDir Directories="$(EmbeddedEnterpriseDotnetAnalyzersDir)" />
</Target>

<Target Name="CopyJars">
<ItemGroup>
<SourceJars Include="$(JarDownloadDir)\sonar-cfamily-plugin-$(EmbeddedSonarCFamilyAnalyzerVersion).jar" />
<SourceJars Include="$(JarDownloadDir)\sonar-csharp-plugin-$(EmbeddedSonarAnalyzerVersion).jar" />
<SourceJars Include="$(JarDownloadDir)\sonar-vbnet-plugin-$(EmbeddedSonarAnalyzerVersion).jar" />
<SourceJars Include="$(JarDownloadDir)\sonar-csharp-enterprise-plugin-$(EmbeddedSonarAnalyzerVersion).jar" />
<SourceJars Include="$(JarDownloadDir)\sonar-vbnet-enterprise-plugin-$(EmbeddedSonarAnalyzerVersion).jar" />
<SourceJars Include="$(JarDownloadDir)\sonar-javascript-plugin-$(EmbeddedSonarJSAnalyzerVersion).jar" />
<SourceJars Include="$(JarDownloadDir)\sonar-text-plugin-$(EmbeddedSonarSecretsJarVersion).jar" />
</ItemGroup>
<Copy SourceFiles ="@(SourceJars)" DestinationFolder="$(EmbeddedJarDir)" />
</Target>

<Target Name="CopyEnterpriseDotnet">
gabriela-trutan-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
<ItemGroup>
<EnterpriseDotnetSource Include="$(EnterpriseDotnetAnalyzersExtractDir)\*.dll" />
</ItemGroup>
<Copy SourceFiles="@(EnterpriseDotnetSource)" DestinationFolder="$(EmbeddedEnterpriseDotnetAnalyzersDir)"/>
</Target>

<Target Name="CopySloop">
<ItemGroup>
Expand Down
33 changes: 19 additions & 14 deletions build/DownloadDependencies/CommonProperties.props
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@
<LanguageKey>c</LanguageKey>
<RepoKey>c</RepoKey>
</PluginJars>

<PluginJars Include="C#">
<JarName>sonar-csharp-plugin-$(EmbeddedSonarAnalyzerVersion).jar</JarName>
<URL>https://binaries.sonarsource.com/Distribution/sonar-csharp-plugin/%(JarName)</URL>
<LanguageKey>cs</LanguageKey>
<RepoKey>csharpsquid</RepoKey>
</PluginJars>

<PluginJars Include="VB.NET">
<JarName>sonar-vbnet-plugin-$(EmbeddedSonarAnalyzerVersion).jar</JarName>
<URL>https://binaries.sonarsource.com/Distribution/sonar-vbnet-plugin/%(JarName)</URL>
<LanguageKey>vbnet</LanguageKey>
<RepoKey>vbnet</RepoKey>
</PluginJars>
</ItemGroup>

<PropertyGroup>
Expand All @@ -66,4 +52,23 @@
<SonarTextPluginDownloadPath>$(JarDownloadDir)\$(SonarTextPluginFileName)</SonarTextPluginDownloadPath>
<SonarTextPluginRemoteUrl>https://repox.jfrog.io/artifactory/sonarsource/org/sonarsource/text/sonar-text-plugin/$(EmbeddedSonarSecretsJarVersion)/$(SonarTextPluginFileName)</SonarTextPluginRemoteUrl>
</PropertyGroup>

<PropertyGroup>
<DotnetPluginsExtractDir>$(LOCALAPPDATA)\SLVS_Build_Dotnet</DotnetPluginsExtractDir>
<EnterpriseDotnetAnalyzersExtractDir>$(LOCALAPPDATA)\SLVS_Build_Dotnet\EnterpriseAnalyzerDlls-$(EmbeddedSonarAnalyzerVersion)</EnterpriseDotnetAnalyzersExtractDir>
</PropertyGroup>

<PropertyGroup>
<EnterpriseSonarVBNetPluginFileNameWithoutExtension>sonar-vbnet-enterprise-plugin-$(EmbeddedSonarAnalyzerVersion)</EnterpriseSonarVBNetPluginFileNameWithoutExtension>
<EnterpriseSonarVBNetPluginFileName>$(EnterpriseSonarVBNetPluginFileNameWithoutExtension).jar</EnterpriseSonarVBNetPluginFileName>
<EnterpriseSonarVBNetPluginDownloadPath>$(JarDownloadDir)\$(EnterpriseSonarVBNetPluginFileName)</EnterpriseSonarVBNetPluginDownloadPath>
<EnterpriseSonarVBNetPluginRemoteUrl>https://repox.jfrog.io/artifactory/sonarsource/com/sonarsource/dotnet/sonar-vbnet-enterprise-plugin/$(EmbeddedSonarAnalyzerVersion)/$(EnterpriseSonarVBNetPluginFileName)</EnterpriseSonarVBNetPluginRemoteUrl>
</PropertyGroup>

<PropertyGroup>
<EnterpriseSonarCSharpPluginFileNameWithoutExtension>sonar-csharp-enterprise-plugin-$(EmbeddedSonarAnalyzerVersion)</EnterpriseSonarCSharpPluginFileNameWithoutExtension>
<EnterpriseSonarCSharpPluginFileName>$(EnterpriseSonarCSharpPluginFileNameWithoutExtension).jar</EnterpriseSonarCSharpPluginFileName>
<EnterpriseSonarCSharpPluginDownloadPath>$(JarDownloadDir)\$(EnterpriseSonarCSharpPluginFileName)</EnterpriseSonarCSharpPluginDownloadPath>
<EnterpriseSonarCSharpPluginRemoteUrl>https://repox.jfrog.io/artifactory/sonarsource/com/sonarsource/dotnet/sonar-csharp-enterprise-plugin/$(EmbeddedSonarAnalyzerVersion)/$(EnterpriseSonarCSharpPluginFileName)</EnterpriseSonarCSharpPluginRemoteUrl>
</PropertyGroup>
</Project>
14 changes: 14 additions & 0 deletions build/DownloadDependencies/JarProcessing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<CallTarget Targets="PrepareDirectories" />
<CallTarget Targets="DownloadIndividualJars" />
<CallTarget Targets="DownloadRepoxJars" />
<CallTarget Targets="UnzipEnterpriseSonarCSharp" />
<CallTarget Targets="UnzipEnterpriseSonarVBNet" />
<CallTarget Targets="DownloadSloop" />
<CallTarget Targets="UnzipSloop" />
<CallTarget Targets="WriteOutputFile" />
Expand All @@ -48,6 +50,8 @@
<Target Name="DownloadRepoxJars">
<Exec Command="curl -u$(ARTIFACTORY_USER):$(ARTIFACTORY_PASSWORD) --ssl-no-revoke -C - --create-dirs --output $(JavaScriptPluginDownloadPath) --url $(JavascriptPluginRemoteUrl)" />
<Exec Command="curl -u$(ARTIFACTORY_USER):$(ARTIFACTORY_PASSWORD) --ssl-no-revoke -C - --create-dirs --output $(SonarTextPluginDownloadPath) --url $(SonarTextPluginRemoteUrl)" />
<Exec Command="curl -u$(ARTIFACTORY_USER):$(ARTIFACTORY_PASSWORD) --ssl-no-revoke -C - --create-dirs --output $(EnterpriseSonarCSharpPluginDownloadPath) --url $(EnterpriseSonarCSharpPluginRemoteUrl)" />
<Exec Command="curl -u$(ARTIFACTORY_USER):$(ARTIFACTORY_PASSWORD) --ssl-no-revoke -C - --create-dirs --output $(EnterpriseSonarVBNetPluginDownloadPath) --url $(EnterpriseSonarVBNetPluginRemoteUrl)" />
</Target>

<Target Name ="DownloadSloop">
Expand All @@ -58,6 +62,16 @@
<Unzip SourceFiles="$(SloopBinaryDownloadPath)" DestinationFolder="$(SloopExtractDir)" OverwriteReadOnlyFiles="true" />
</Target>

<Target Name="UnzipEnterpriseSonarCSharp">
<Unzip SourceFiles="$(EnterpriseSonarCSharpPluginDownloadPath)" DestinationFolder="$(DotnetPluginsExtractDir)\$(EnterpriseSonarCSharpPluginFileNameWithoutExtension)" OverwriteReadOnlyFiles="true" />
<Unzip SourceFiles="$(DotnetPluginsExtractDir)\$(EnterpriseSonarCSharpPluginFileNameWithoutExtension)\static\SonarAnalyzer-$(EmbeddedSonarAnalyzerVersion).zip" DestinationFolder="$(EnterpriseDotnetAnalyzersExtractDir)" OverwriteReadOnlyFiles="true" />
</Target>

<Target Name="UnzipEnterpriseSonarVBNet">
<Unzip SourceFiles="$(EnterpriseSonarVBNetPluginDownloadPath)" DestinationFolder="$(DotnetPluginsExtractDir)\$(EnterpriseSonarVBNetPluginFileNameWithoutExtension)" OverwriteReadOnlyFiles="true" />
<Unzip SourceFiles="$(DotnetPluginsExtractDir)\$(EnterpriseSonarVBNetPluginFileNameWithoutExtension)\static\SonarAnalyzer-$(EmbeddedSonarAnalyzerVersion).zip" DestinationFolder="$(EnterpriseDotnetAnalyzersExtractDir)" OverwriteReadOnlyFiles="true" />
</Target>

<Target Name="WriteOutputFile">
<!-- The timestamp on the output file is used by MSBuild to decide whether to build this project or not.
If the timestamp on the EmbeddedSonarAnalyzer.props file is later than that of the output file then
Expand Down
2 changes: 1 addition & 1 deletion src/EmbeddedSonarAnalyzer.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
NB we assume that the SonarC# and SonarVB NuGet packages have the same version number. -->
<PropertyGroup>
<!-- Note: Guide on how to update the analyzers is on the xtranet! -->
<EmbeddedSonarAnalyzerVersion>9.32.0.97167</EmbeddedSonarAnalyzerVersion>
<EmbeddedSonarAnalyzerVersion>10.0.0.102314</EmbeddedSonarAnalyzerVersion>
<EmbeddedSonarCFamilyAnalyzerVersion>6.59.0.75237</EmbeddedSonarCFamilyAnalyzerVersion>
<EmbeddedSonarJSAnalyzerVersion>10.16.0.27621</EmbeddedSonarJSAnalyzerVersion>
<EmbeddedSonarSecretsJarVersion>2.16.0.4008</EmbeddedSonarSecretsJarVersion>
Expand Down
11 changes: 4 additions & 7 deletions src/Infrastructure.VS.UnitTests/ErrorListHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ namespace SonarLint.VisualStudio.Infrastructure.VS.UnitTests
[TestClass]
public class ErrorListHelperTests
{
internal enum TestVsSuppressionState
{
Active,
Suppressed,
NotApplicable,
}

[TestMethod]
public void MefCtor_CheckIsExported()
{
Expand Down Expand Up @@ -232,8 +225,10 @@ public void TryGetRoslynIssueFromSelectedRow_NoStartColumn_NothingReturned()

[TestMethod]
[DataRow("S666", "csharpsquid", "S666", "SonarAnalyzer.CSharp", null)]
[DataRow("S667", "csharpsquid", "S667", "SonarAnalyzer.Enterprise.CSharp", null)]
[DataRow("S666", "vbnet", "S666", "SonarAnalyzer.VisualBasic", null)]
[DataRow("S234", "vbnet", "S234", "SonarAnalyzer.VisualBasic", null)]
[DataRow("S234", "vbnet", "S234", "SonarAnalyzer.Enterprise.VisualBasic", null)]
[DataRow("c:S111", "c", "S111", "SonarLint", null)]
[DataRow("cpp:S222", "cpp", "S222", "SonarLint", null)]
[DataRow("javascript:S333", "javascript", "S333", "SonarLint", null)]
Expand Down Expand Up @@ -268,8 +263,10 @@ public void TryGetRuleIdFromSelectedRow_SingleSonarIssue_ErrorCodeReturned(strin

[TestMethod]
[DataRow("S666", "csharpsquid", "S666", "SonarAnalyzer.CSharp", null)]
[DataRow("S667", "csharpsquid", "S667", "SonarAnalyzer.Enterprise.CSharp", null)]
[DataRow("S666", "vbnet", "S666", "SonarAnalyzer.VisualBasic", null)]
[DataRow("S234", "vbnet", "S234", "SonarAnalyzer.VisualBasic", null)]
[DataRow("S234", "vbnet", "S234", "SonarAnalyzer.Enterprise.VisualBasic", null)]
[DataRow("c:S111", "c", "S111", "SonarLint", null)]
[DataRow("cpp:S222", "cpp", "S222", "SonarLint", null)]
[DataRow("javascript:S333", "javascript", "S333", "SonarLint", null)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public void Get_GetsAnalyzersFromExpectedLocation()
{
testSubject.Get();

locator.Received(1).GetAnalyzerFullPaths();
locator.Received(1).GetBasicAnalyzerFullPaths();
}

[TestMethod]
public void Get_AnalyzerFilesExist_ReturnsAnalyzerFileReference()
{
locator.GetAnalyzerFullPaths().Returns([GetAnalyzerFullPath("analyzer1.dll"), GetAnalyzerFullPath("analyzer2.dll")]);
locator.GetBasicAnalyzerFullPaths().Returns([GetAnalyzerFullPath("analyzer1.dll"), GetAnalyzerFullPath("analyzer2.dll")]);

var analyzerFileReferences = testSubject.Get();

Expand All @@ -87,7 +87,7 @@ public void Get_AnalyzerFilesExist_ReturnsAnalyzerFileReference()
[TestMethod]
public void Get_AnalyzerFilesDoNotExist_ReturnsLogsAndThrows()
{
locator.GetAnalyzerFullPaths().Returns([]);
locator.GetBasicAnalyzerFullPaths().Returns([]);

Action act = () => testSubject.Get();

Expand All @@ -103,7 +103,7 @@ public void Get_CachesAnalyzerFileReferences()
testSubject.Get();

analyzerAssemblyLoaderFactory.Received(1).Create();
locator.Received(1).GetAnalyzerFullPaths();
locator.Received(1).GetBasicAnalyzerFullPaths();
}

private static string GetAnalyzerFullPath(string analyzerFile)
Expand All @@ -120,7 +120,7 @@ private static void ContainsExpectedAnalyzerFileReference(

private void MockServices()
{
locator.GetAnalyzerFullPaths().Returns([GetAnalyzerFullPath("analyzer1.dll")]);
locator.GetBasicAnalyzerFullPaths().Returns([GetAnalyzerFullPath("analyzer1.dll")]);
analyzerAssemblyLoaderFactory.Create().Returns(analyzerAssemblyLoader);
}
}
2 changes: 2 additions & 0 deletions src/Infrastructure.VS/ErrorListHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ private static string FindErrorCodeForEntry(ITableEntriesSnapshot snapshot, int
return buildTool switch
{
"SonarAnalyzer.CSharp" => $"{SonarRuleRepoKeys.CSharpRules}:{errorCode}",
"SonarAnalyzer.Enterprise.CSharp" => $"{SonarRuleRepoKeys.CSharpRules}:{errorCode}",
"SonarAnalyzer.VisualBasic" => $"{SonarRuleRepoKeys.VBNetRules}:{errorCode}",
"SonarAnalyzer.Enterprise.VisualBasic" => $"{SonarRuleRepoKeys.VBNetRules}:{errorCode}",
"SonarLint" => errorCode,
_ => null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ImmutableArray<AnalyzerFileReference> Get()

private ImmutableArray<AnalyzerFileReference> CreateAnalyzerFileReferences()
{
var analyzerPaths = locator.GetAnalyzerFullPaths();
var analyzerPaths = locator.GetBasicAnalyzerFullPaths();
if(analyzerPaths.Count == 0)
{
logger.LogVerbose(Resources.EmbeddedRoslynAnalyzersNotFound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ namespace SonarLint.VisualStudio.Infrastructure.VS.Roslyn;

public interface IEmbeddedRoslynAnalyzersLocator
{
List<string> GetAnalyzerFullPaths();
List<string> GetBasicAnalyzerFullPaths();

List<string> GetEnterpriseAnalyzerFullPaths();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.IO;

namespace SonarLint.VisualStudio.Integration.UnitTests.EmbeddedAnalyzers;

[TestClass]
public class EmbeddedDotnetAnalyzerDLLsSmokeTest
{
[TestMethod]
public void EmbeddedDotnetAnalyzerDLLs_MatchExpectedSetOfAssemblies()
{
var directoryInfo = new DirectoryInfo(GetType().Assembly.Location);
var pathToEmbeddedDotnetAnalyzerFolder = Path.Combine(GetPathToSrc(directoryInfo), @"Integration.Vsix\EmbeddedDotnetAnalyzerDLLs");
var files = Directory.GetFiles(pathToEmbeddedDotnetAnalyzerFolder, "*", SearchOption.AllDirectories).Select(Path.GetFileName);
files.Should().BeEquivalentTo(
[
"SonarAnalyzer.Enterprise.VisualBasic.dll",
"SonarAnalyzer.VisualBasic.dll",
"SonarAnalyzer.Enterprise.CSharp.dll",
"SonarAnalyzer.CSharp.dll",
], options => options.WithoutStrictOrdering());
}

private static string GetPathToSrc(DirectoryInfo directoryInfo)
{
while (!directoryInfo!.FullName.EndsWith("src"))
{
directoryInfo = directoryInfo.Parent;
}

return directoryInfo.FullName;
}
}
Loading