From 642c4003bdc5abc221344c4dfac98805bd8a7baf Mon Sep 17 00:00:00 2001 From: duncanp-sonar Date: Tue, 7 Aug 2018 10:46:03 +0100 Subject: [PATCH] Updated to use Microsoft.CodeAnalysis v2.8.2 (#95) --- DevNotes.txt | 48 ++++--- RoslynPluginGenerator/App.config | 80 ++++++++--- RoslynPluginGenerator/Program.cs | 5 +- ...Qube.Plugins.Roslyn.PluginGenerator.csproj | 113 +++++++++++++-- RoslynPluginGenerator/UIResources.Designer.cs | 36 +++-- RoslynPluginGenerator/UIResources.resx | 12 +- RoslynPluginGenerator/packages.config | 58 +++++++- .../IntegrationTests/IntegrationTests.csproj | 131 ++++++++++++------ .../IntegrationTests/Roslyn/RoslynGenTests.cs | 72 ++++++++++ Tests/IntegrationTests/packages.config | 63 +++++++-- ...s.Roslyn.RoslynPluginGeneratorTests.csproj | 103 ++++++++++++-- .../packages.config | 72 +++++++--- 12 files changed, 638 insertions(+), 155 deletions(-) diff --git a/DevNotes.txt b/DevNotes.txt index 9c9e3f5..1547b3a 100644 --- a/DevNotes.txt +++ b/DevNotes.txt @@ -1,22 +1,31 @@ -Creating a plug-in jar file: ----------------------------- +Supported Roslyn version +------------------------ +Currently the SDK is built against Microsoft.CodeAnalysis v2.8.2. It ships with a binding redirect file that forwards all of +the earlier versions to v2.8.2, so it should work against analyzers written with any earlier Roslyn version. -* generate the MD file containing the plugin info - - License, OrganizationUrl, BuildDate, Version, Class, Sonar-Version, Organization, Name, Description, Key +The SDK only needs the packages "Microsoft.CodeAnalysis.Analyzers" and "Microsoft.CodeAnalysis.Common". However, we reference +the full "Microsoft.CodeAnalysis" package as it will pull in other packages that might be needed by the third-party analyzers +e.g. the workspaces packages. -Plugin-BuildDate: 2015-09-27T13:50:19+0100 -Sonar-Version: 4.5.2 +If the SDK fails to generate a plugin for a Roslyn analyzer: +1) check that the analyzer is built against v2.8.2 or earlier (e.g. by using ildasm to see which version is referenced), and +2) check that any other dependencies required by the analyzer are available. -* create folder structure: folder per namespace - - RulesDefinition.java, Plugin.java, rules.xml +The SDK will fetch any NuGet dependencies that are declared in the NuGet analyzer package. However, analyzer packages do +not normally reference the Roslyn packages they required, so they will not be fetched. -* Compile the classes - javac myorg\*.* -classpath sonar-plugin-api-4.5.2.jar - Note: the code references the sonar-plugin-api jar, which must be locatable +Updating the version of Roslyn used by the SDK +---------------------------------------------- +1) Use the VS Package Manager to update the version of Microsoft.CodeAnalysis referenced by the following projects: + * RoslynPluginGenerator\SonarQube.Plugins.Roslyn.PluginGenerator.csproj + * Tests\IntegrationTests\IntegrationTests.csproj + * Tests\RoslynPluginGeneratorTests\SonarQube.Plugins.Roslyn.RoslynPluginGeneratorTests.csproj -* Create the jar file - jar cvfm test.jar MANIFEST.MF myorg\*.class* resources\*.* +2) update the app.config file to forward all calls to the new version + File: RoslynPluginGenerator\app.config. + Note: this is the app.config that is shipped with the SDK, and it is shared (linked) to the test + projects so it is the only app.config that needs to be updated. @@ -25,14 +34,13 @@ Sonar-Version: 4.5.2 [root folder] - MANIFEST.MF : manifest file containing plugin property values used by SonarQube + META-INF/MANIFEST.MF : manifest file containing general plugin property values used by SonarQube + : e.g. plugin name, version, unique key etc - [myorg] - [plugin] etc i.e. folder structure corresponding to the namespaces of the class components - Plugin.class - RuleDefinitions.class + org/sonar/plugins/roslynsdk/configuration.xml : metadata about the analyzer used by the Scanner for MSBuild + : e.g repository key and language - [resources] - rules.xml : XML file containing the new rules (loaded by RulesDefinition.class) + org/sonar/plugins/roslynsdk/rules.xml : XML file containing the new rules (loaded by RulesDefinition.class) + static/[analyzer id].[analyzer version].zip : the zip containing the third party analyzer will be added here diff --git a/RoslynPluginGenerator/App.config b/RoslynPluginGenerator/App.config index 04d9ce4..393aefa 100644 --- a/RoslynPluginGenerator/App.config +++ b/RoslynPluginGenerator/App.config @@ -1,45 +1,85 @@ - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RoslynPluginGenerator/Program.cs b/RoslynPluginGenerator/Program.cs index 9f3dea9..1aa89a8 100644 --- a/RoslynPluginGenerator/Program.cs +++ b/RoslynPluginGenerator/Program.cs @@ -20,6 +20,7 @@ using System.IO; using System.Reflection; +using Microsoft.CodeAnalysis.Diagnostics; using NuGet; using SonarQube.Plugins.Common; using SonarQube.Plugins.Roslyn.CommandLine; @@ -37,7 +38,9 @@ public static class Program private static int Main(string[] args) { ConsoleLogger logger = new ConsoleLogger(); - Utilities.LogAssemblyVersion(typeof(Program).Assembly, UIResources.AssemblyDescription, logger); + Utilities.LogAssemblyVersion(typeof(Program).Assembly, UIResources.Program_AssemblyDescription, logger); + Utilities.LogAssemblyVersion(typeof(DiagnosticAnalyzer).Assembly, UIResources.Program_SupportedRoslynVersion, logger); + logger.LogInfo(UIResources.Program_SupportedSonarQubeVersions); ProcessedArgs processedArgs = ArgumentProcessor.TryProcessArguments(args, logger); diff --git a/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj b/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj index 4a54a45..25d4f5e 100644 --- a/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj +++ b/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj @@ -36,24 +36,97 @@ - - ..\packages\Microsoft.CodeAnalysis.Common.1.1.0\lib\net45\Microsoft.CodeAnalysis.dll - True + + ..\packages\Microsoft.CodeAnalysis.Common.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.dll + + + ..\packages\Microsoft.CodeAnalysis.CSharp.Workspaces.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.CSharp.Workspaces.dll + + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.VisualBasic.dll + + + ..\packages\Microsoft.CodeAnalysis.VisualBasic.Workspaces.2.8.2\lib\netstandard1.3\Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll + + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.8.2\lib\net46\Microsoft.CodeAnalysis.Workspaces.dll + + + ..\packages\Microsoft.CodeAnalysis.Workspaces.Common.2.8.2\lib\net46\Microsoft.CodeAnalysis.Workspaces.Desktop.dll ..\packages\NuGet.CommandLine.4.7.0\tools\NuGet.exe - - ..\packages\System.Collections.Immutable.1.1.37\lib\dotnet\System.Collections.Immutable.dll - True + + ..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll + + + ..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + + + + ..\packages\System.Composition.AttributedModel.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.AttributedModel.dll + + + ..\packages\System.Composition.Convention.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.Convention.dll + + + ..\packages\System.Composition.Hosting.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.Hosting.dll + + + ..\packages\System.Composition.Runtime.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.Runtime.dll + + + ..\packages\System.Composition.TypedParts.1.0.31\lib\portable-net45+win8+wp8+wpa81\System.Composition.TypedParts.dll + + + ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll - + + ..\packages\System.Diagnostics.FileVersionInfo.4.3.0\lib\net46\System.Diagnostics.FileVersionInfo.dll + + + ..\packages\System.Diagnostics.StackTrace.4.3.0\lib\net46\System.Diagnostics.StackTrace.dll + + + ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll + - - ..\packages\System.Reflection.Metadata.1.1.0\lib\dotnet5.2\System.Reflection.Metadata.dll - True + + ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll + + + ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll + + + + ..\packages\System.Reflection.Metadata.1.4.2\lib\portable-net45+win8\System.Reflection.Metadata.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net46\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net46\System.Security.Cryptography.X509Certificates.dll + + + ..\packages\System.Text.Encoding.CodePages.4.3.0\lib\net46\System.Text.Encoding.CodePages.dll + + + ..\packages\System.Threading.Thread.4.3.0\lib\net46\System.Threading.Thread.dll + + + ..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll @@ -61,6 +134,18 @@ + + ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll + + + ..\packages\System.Xml.XmlDocument.4.3.0\lib\net46\System.Xml.XmlDocument.dll + + + ..\packages\System.Xml.XPath.4.3.0\lib\net46\System.Xml.XPath.dll + + + ..\packages\System.Xml.XPath.XDocument.4.3.0\lib\net46\System.Xml.XPath.XDocument.dll + @@ -118,10 +203,6 @@ SonarQube.Plugins.PluginGenerator - - - - ResXFileCodeGenerator @@ -156,6 +237,10 @@ Properties\SonarLint.xml + + + +