Skip to content

Commit

Permalink
Updated to use Microsoft.CodeAnalysis v2.8.2 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanp-sonar authored and Amaury Levé committed Aug 7, 2018
1 parent da15e89 commit 642c400
Show file tree
Hide file tree
Showing 12 changed files with 638 additions and 155 deletions.
48 changes: 28 additions & 20 deletions DevNotes.txt
Original file line number Diff line number Diff line change
@@ -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.



Expand All @@ -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
80 changes: 60 additions & 20 deletions RoslynPluginGenerator/App.config
Original file line number Diff line number Diff line change
@@ -1,45 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.37.0" newVersion="1.1.37.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.0.21.0" newVersion="1.0.21.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Features" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.Features" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.Remote.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.CSharp.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic.Features" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces.Desktop" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
<assemblyIdentity name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces.Desktop" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.CodeAnalysis.Workspaces" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.0.0" newVersion="2.8.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.Compression" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Security.Cryptography.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO.FileSystem.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.XPath.XDocument" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Thread" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
5 changes: 4 additions & 1 deletion RoslynPluginGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Loading

0 comments on commit 642c400

Please sign in to comment.