diff --git a/RoslynPluginGenerator/AnalyzerPluginGenerator.cs b/RoslynPluginGenerator/AnalyzerPluginGenerator.cs index e6e00fb..7f9d885 100644 --- a/RoslynPluginGenerator/AnalyzerPluginGenerator.cs +++ b/RoslynPluginGenerator/AnalyzerPluginGenerator.cs @@ -26,7 +26,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using NuGet; -using SonarLint.XmlDescriptor; using SonarQube.Plugins.Common; using SonarQube.Plugins.Roslyn.CommandLine; @@ -50,13 +49,6 @@ public class AnalyzerPluginGenerator /// public const string RulesTemplateFileNameFormat = "{0}.{1}.rules.template.xml"; - /// - /// Specifies the format for the name of the placeholder SQALE file - /// - public const string SqaleTemplateFileNameFormat = "{0}.{1}.sqale.template.xml"; - - private const string DefaultRemediationCost = "5min"; - private readonly INuGetPackageHandler packageHandler; private readonly SonarQube.Plugins.Common.ILogger logger; @@ -139,7 +131,7 @@ public bool Generate(ProcessedArgs args) // Initial run with the user-targeted package and arguments if (analyzersByPackage.ContainsKey(targetPackage)) { - string generatedJarPath = GeneratePluginForPackage(args.OutputDirectory, args.Language, args.SqaleFilePath, args.RuleFilePath, targetPackage, analyzersByPackage[targetPackage]); + string generatedJarPath = GeneratePluginForPackage(args.OutputDirectory, args.Language, args.RuleFilePath, targetPackage, analyzersByPackage[targetPackage]); if (generatedJarPath == null) { return false; @@ -152,12 +144,12 @@ public bool Generate(ProcessedArgs args) // Dependent package generation changes the arguments if (args.RecurseDependencies) { - logger.LogWarning(UIResources.APG_RecurseEnabled_SQALEandRuleCustomisationNotEnabled); + logger.LogWarning(UIResources.APG_RecurseEnabled_RuleCustomizationNotEnabled); foreach (IPackage currentPackage in analyzersByPackage.Keys) { - // No way to specify the SQALE or rules xml files for any but the user-targeted package at this time - string generatedJarPath = GeneratePluginForPackage(args.OutputDirectory, args.Language, null, null, currentPackage, analyzersByPackage[currentPackage]); + // No way to specify the rules xml files for any but the user-targeted package at this time + string generatedJarPath = GeneratePluginForPackage(args.OutputDirectory, args.Language, null, currentPackage, analyzersByPackage[currentPackage]); if (generatedJarPath == null) { return false; @@ -177,7 +169,7 @@ public bool Generate(ProcessedArgs args) return true; } - private string GeneratePluginForPackage(string outputDir, string language, string sqaleFilePath, string rulesFilePath, IPackage package, IEnumerable analyzers) + private string GeneratePluginForPackage(string outputDir, string language, string rulesFilePath, IPackage package, IEnumerable analyzers) { Debug.Assert(analyzers.Any(), "The method must be called with a populated list of DiagnosticAnalyzers."); @@ -191,7 +183,6 @@ private string GeneratePluginForPackage(string outputDir, string language, strin RoslynPluginDefinition definition = new RoslynPluginDefinition { Language = language, - SqaleFilePath = sqaleFilePath, RulesFilePath = rulesFilePath, PackageId = package.Id, PackageVersion = package.Version.ToString(), @@ -218,27 +209,12 @@ private string GeneratePluginForPackage(string outputDir, string language, strin generate = IsValidRulesFile(definition.RulesFilePath); } - string generatedSqaleFile = null; - - if (definition.SqaleFilePath == null) - { - generatedSqaleFile = CalculateSqaleFileName(package, outputDir); - GenerateFixedSqaleFile(analyzers, generatedSqaleFile); - Debug.Assert(File.Exists(generatedSqaleFile)); - } - else - { - this.logger.LogInfo(UIResources.APG_UsingSuppliedSqaleFile, definition.SqaleFilePath); - generate = IsValidSqaleFile(definition.SqaleFilePath); - } - if (generate) { createdJarFilePath = BuildPlugin(definition, outputDir); } LogMessageForGeneratedRules(generatedRulesTemplateFile); - LogMessageForGeneratedSqale(generatedSqaleFile); return createdJarFilePath; } @@ -252,15 +228,6 @@ private void LogMessageForGeneratedRules(string generatedFile) } } - private void LogMessageForGeneratedSqale(string generatedSqaleFile) - { - if (generatedSqaleFile != null) - { - // Log a message about the generated SQALE file for every plugin generated - logger.LogInfo(UIResources.APG_TemplateSqaleFileGenerated, generatedSqaleFile); - } - } - private void LogAcceptedPackageLicenses(IEnumerable licenseAcceptancePackages) { if (licenseAcceptancePackages.Any()) @@ -386,30 +353,6 @@ private static string CalculateRulesTemplateFileName(IPackage package, string di return filePath; } - private static string CalculateSqaleFileName(IPackage package, string directory) - { - string filePath = string.Format(System.Globalization.CultureInfo.CurrentCulture, - SqaleTemplateFileNameFormat, package.Id, package.Version); - - filePath = Path.Combine(directory, filePath); - return filePath; - } - - /// - /// Generates a SQALE file with fixed remediation costs for the specified analyzers - /// - private void GenerateFixedSqaleFile(IEnumerable analyzers, string outputFilePath) - { - logger.LogInfo(UIResources.APG_GeneratingConstantSqaleFile); - - HardcodedConstantSqaleGenerator generator = new HardcodedConstantSqaleGenerator(); - - SqaleModel sqale = generator.GenerateSqaleData(analyzers, DefaultRemediationCost); - - Serializer.SaveModel(sqale, outputFilePath); - logger.LogDebug(UIResources.APG_SqaleGeneratedToFile, outputFilePath); - } - /// /// Checks that the supplied rule file has valid content /// @@ -432,29 +375,7 @@ private bool IsValidRulesFile(string filePath) } return true; } - - /// - /// Checks that the supplied sqale file has valid content - /// - private bool IsValidSqaleFile(string sqaleFilePath) - { - Debug.Assert(!string.IsNullOrWhiteSpace(sqaleFilePath)); - // Existence is checked when parsing the arguments - Debug.Assert(File.Exists(sqaleFilePath), "Expecting the sqale file to exist: " + sqaleFilePath); - - try - { - // TODO: consider adding further checks - Serializer.LoadModel(sqaleFilePath); - } - catch(InvalidOperationException) // will be thrown for invalid xml - { - logger.LogError(UIResources.APG_InvalidSqaleFile, sqaleFilePath); - return false; - } - return true; - } - + public /* for test */ static PluginManifest CreatePluginManifest(IPackage package) { // The manifest properties supported by SonarQube are documented at @@ -562,11 +483,6 @@ private string BuildPlugin(RoslynPluginDefinition definition, string outputDirec .SetPluginManifestProperties(definition.Manifest) .SetJarFilePath(fullJarPath); - if (!string.IsNullOrWhiteSpace(definition.SqaleFilePath)) - { - builder.SetSqaleFilePath(definition.SqaleFilePath); - } - AddRoslynMetadata(builder, definition, repositoryId); string relativeStaticFilePath = "static/" + Path.GetFileName(definition.StaticResourceName); diff --git a/RoslynPluginGenerator/CommandLine/ArgumentProcessor.cs b/RoslynPluginGenerator/CommandLine/ArgumentProcessor.cs index 6718f51..b00323c 100644 --- a/RoslynPluginGenerator/CommandLine/ArgumentProcessor.cs +++ b/RoslynPluginGenerator/CommandLine/ArgumentProcessor.cs @@ -114,7 +114,7 @@ public ProcessedArgs Process(string[] commandLineArgs) parsedOk &= TryParseAnalyzerRef(arguments, out NuGetReference analyzerRef); - parsedOk &= TryParseSqaleFile(arguments, out string sqaleFilePath); + parsedOk &= TryParseSqaleArgument(arguments); parsedOk &= TryParseRuleFile(arguments, out string ruleFilePath); @@ -128,7 +128,6 @@ public ProcessedArgs Process(string[] commandLineArgs) analyzerRef.PackageId, analyzerRef.Version, SupportedLanguages.CSharp, /* TODO: support multiple languages */ - sqaleFilePath, ruleFilePath, acceptLicense, recurseDependencies, @@ -186,9 +185,8 @@ private NuGetReference TryParseNuGetReference(string argumentValue) return new NuGetReference(packageId, packageVersion); } - private bool TryParseSqaleFile(IEnumerable arguments, out string sqaleFilePath) + private bool TryParseSqaleArgument(IEnumerable arguments) { - sqaleFilePath = null; ArgumentInstance arg = arguments.SingleOrDefault(a => ArgumentDescriptor.IdComparer.Equals(KeywordIds.SqaleXmlFile, a.Descriptor.Id)); if (arg == null) @@ -196,18 +194,8 @@ private bool TryParseSqaleFile(IEnumerable arguments, out stri return true; } - bool success = true; - if (File.Exists(arg.Value)) - { - sqaleFilePath = arg.Value; - logger.LogDebug(CmdLineResources.DEBUG_UsingSqaleFile, sqaleFilePath); - } - else - { - success = false; - logger.LogError(CmdLineResources.ERROR_SqaleFileNotFound, arg.Value); - } - return success; + logger.LogError(CmdLineResources.ERROR_SqaleParameterIsNotSupported); + return false; } private bool TryParseRuleFile(IEnumerable arguments, out string ruleFilePath) diff --git a/RoslynPluginGenerator/CommandLine/CmdLineResources.Designer.cs b/RoslynPluginGenerator/CommandLine/CmdLineResources.Designer.cs index 84dc204..ea5eb9c 100644 --- a/RoslynPluginGenerator/CommandLine/CmdLineResources.Designer.cs +++ b/RoslynPluginGenerator/CommandLine/CmdLineResources.Designer.cs @@ -97,7 +97,7 @@ internal static string ArgDescription_RuleXmlFile { } /// - /// Looks up a localized string similar to /sqale:[path to sqale xml file]. + /// Looks up a localized string similar to /sqale:[path to sqale xml file] - DEPRECATED. Use the /rules parameter instead.. /// internal static string ArgDescription_SqaleXmlFile { get { @@ -123,15 +123,6 @@ internal static string DEBUG_UsingRuleFile { } } - /// - /// Looks up a localized string similar to Using SQALE file '{0}'. - /// - internal static string DEBUG_UsingSqaleFile { - get { - return ResourceManager.GetString("DEBUG_UsingSqaleFile", resourceCulture); - } - } - /// /// Looks up a localized string similar to Invalid NuGet package version: {0}. /// @@ -160,11 +151,13 @@ internal static string ERROR_RuleFileNotFound { } /// - /// Looks up a localized string similar to The specified SQALE file could not found: {0}. + /// Looks up a localized string similar to The /sqale parameter is no longer supported. + ///If you are targetting SonarQube v6.7 or higher, use the /rules parameter and add the debt remediation information to the rules.xml file instead. If you are targetting an older version of SonarQube, use v1.0 of this SDK. + ///. /// - internal static string ERROR_SqaleFileNotFound { + internal static string ERROR_SqaleParameterIsNotSupported { get { - return ResourceManager.GetString("ERROR_SqaleFileNotFound", resourceCulture); + return ResourceManager.GetString("ERROR_SqaleParameterIsNotSupported", resourceCulture); } } } diff --git a/RoslynPluginGenerator/CommandLine/CmdLineResources.resx b/RoslynPluginGenerator/CommandLine/CmdLineResources.resx index 2e6d2ae..73566ea 100644 --- a/RoslynPluginGenerator/CommandLine/CmdLineResources.resx +++ b/RoslynPluginGenerator/CommandLine/CmdLineResources.resx @@ -130,7 +130,7 @@ /rules:[path to rules xml file] - /sqale:[path to sqale xml file] + /sqale:[path to sqale xml file] - DEPRECATED. Use the /rules parameter instead. Parsed NuGet reference. Id: {0}, version: {1} @@ -138,9 +138,6 @@ Using rules xml file '{0}' - - Using SQALE file '{0}' - Invalid NuGet package version: {0} @@ -150,7 +147,9 @@ The specified rules xml file could not found: {0} - - The specified SQALE file could not found: {0} + + The /sqale parameter is no longer supported. +If you are targetting SonarQube v6.7 or higher, use the /rules parameter and add the debt remediation information to the rules.xml file instead. If you are targetting an older version of SonarQube, use v1.0 of this SDK. + \ No newline at end of file diff --git a/RoslynPluginGenerator/CommandLine/ProcessedArgs.cs b/RoslynPluginGenerator/CommandLine/ProcessedArgs.cs index 65011c8..1b197c6 100644 --- a/RoslynPluginGenerator/CommandLine/ProcessedArgs.cs +++ b/RoslynPluginGenerator/CommandLine/ProcessedArgs.cs @@ -25,7 +25,7 @@ namespace SonarQube.Plugins.Roslyn.CommandLine { public class ProcessedArgs { - public ProcessedArgs(string packageId, SemanticVersion packageVersion, string language, string sqaleFilePath, string ruleFilePath, + public ProcessedArgs(string packageId, SemanticVersion packageVersion, string language, string ruleFilePath, bool acceptLicenses, bool recurseDependencies, string outputDirectory) { if (string.IsNullOrWhiteSpace(packageId)) @@ -41,7 +41,6 @@ public ProcessedArgs(string packageId, SemanticVersion packageVersion, string la PackageId = packageId; PackageVersion = packageVersion; - SqaleFilePath = sqaleFilePath; // can be null RuleFilePath = ruleFilePath; Language = language; AcceptLicenses = acceptLicenses; @@ -53,8 +52,6 @@ public ProcessedArgs(string packageId, SemanticVersion packageVersion, string la public SemanticVersion PackageVersion { get; } - public string SqaleFilePath { get; } - public string RuleFilePath { get; } public string Language { get; } diff --git a/RoslynPluginGenerator/DataModel/RoslynSdkConfiguration.cs b/RoslynPluginGenerator/DataModel/RoslynSdkConfiguration.cs index c18f733..d741d29 100644 --- a/RoslynPluginGenerator/DataModel/RoslynSdkConfiguration.cs +++ b/RoslynPluginGenerator/DataModel/RoslynSdkConfiguration.cs @@ -40,8 +40,6 @@ public RoslynSdkConfiguration() public string RulesXmlResourcePath { get; set; } - public string SqaleXmlResourcePath { get; set; } - [XmlElement("PluginProperties")] public PluginProperties Properties { get; set; } diff --git a/RoslynPluginGenerator/HardcodedConstantSqaleGenerator.cs b/RoslynPluginGenerator/HardcodedConstantSqaleGenerator.cs deleted file mode 100644 index 8718290..0000000 --- a/RoslynPluginGenerator/HardcodedConstantSqaleGenerator.cs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube Roslyn SDK - * Copyright (C) 2015-2017 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; -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Diagnostics; -using SonarLint.XmlDescriptor; - -namespace SonarQube.Plugins.Roslyn -{ - /// - /// Generates a simple SQALE description using a constant value for each rule - /// - public class HardcodedConstantSqaleGenerator - { - private string remediationConstantValue; - - public SqaleModel GenerateSqaleData(IEnumerable analyzers, string remediationValue) - { - if (analyzers == null) - { - throw new ArgumentNullException(nameof(analyzers)); - } - - Debug.Assert(remediationValue.EndsWith("min"), "Expecting a remediation value in the form '15min'"); - remediationConstantValue = remediationValue; - - SqaleModel root = new SqaleModel(); - - foreach(DiagnosticAnalyzer analyzer in analyzers) - { - ProcessAnalyzer(analyzer, root); - } - - return root; - } - - #region Private methods - - private void ProcessAnalyzer(DiagnosticAnalyzer analyzer, SqaleModel root) - { - foreach(DiagnosticDescriptor diagnostic in analyzer.SupportedDiagnostics) - { - SqaleDescriptor sqaleDescriptor = new SqaleDescriptor - { - Remediation = new SqaleRemediation - { - RuleKey = diagnostic.Id - }, - SubCharacteristic = "MAINTAINABILITY_COMPLIANCE" - }; - - sqaleDescriptor.Remediation.Properties.AddRange(new[] - { - new SqaleRemediationProperty - { - Key = "remediationFunction", - Text = "CONSTANT_ISSUE" - }, - new SqaleRemediationProperty - { - Key = "offset", - Value = remediationConstantValue, - Text = string.Empty - } - }); - - root.Sqale.Add(sqaleDescriptor); - } - } - - #endregion Private methods - } -} \ No newline at end of file diff --git a/RoslynPluginGenerator/Resources/sonar-roslyn-sdk-template-plugin-1.1.jar b/RoslynPluginGenerator/Resources/sonar-roslyn-sdk-template-plugin-1.1.jar index 31317dd..c54e2db 100644 Binary files a/RoslynPluginGenerator/Resources/sonar-roslyn-sdk-template-plugin-1.1.jar and b/RoslynPluginGenerator/Resources/sonar-roslyn-sdk-template-plugin-1.1.jar differ diff --git a/RoslynPluginGenerator/RoslynPluginDefinition.cs b/RoslynPluginGenerator/RoslynPluginDefinition.cs index a452def..73db8f5 100644 --- a/RoslynPluginGenerator/RoslynPluginDefinition.cs +++ b/RoslynPluginGenerator/RoslynPluginDefinition.cs @@ -29,7 +29,6 @@ internal class RoslynPluginDefinition public string PackageId { get; set; } public string PackageVersion { get; set; } public PluginManifest Manifest { get; set; } - public string SqaleFilePath { get; set; } public string RulesFilePath { get; set; } /// diff --git a/RoslynPluginGenerator/RoslynPluginJarBuilder.cs b/RoslynPluginGenerator/RoslynPluginJarBuilder.cs index 8094922..384fa16 100644 --- a/RoslynPluginGenerator/RoslynPluginJarBuilder.cs +++ b/RoslynPluginGenerator/RoslynPluginJarBuilder.cs @@ -45,8 +45,7 @@ public class RoslynPluginJarBuilder private const string RelativeConfigurationResourcePath = "org\\sonar\\plugins\\roslynsdk\\configuration.xml"; private const string RelativeRulesXmlResourcePath = "org\\sonar\\plugins\\roslynsdk\\rules.xml"; - private const string RelativeSqaleXmlResourcePath = "org\\sonar\\plugins\\roslynsdk\\sqale.xml"; - + private readonly ILogger logger; private readonly IDictionary pluginProperties; @@ -54,7 +53,6 @@ public class RoslynPluginJarBuilder private readonly IDictionary fileToRelativePathMap; private string language; private string rulesFilePath; - private string sqaleFilePath; private string repositoryKey; private string repositoryName; @@ -180,16 +178,6 @@ public RoslynPluginJarBuilder SetRulesFilePath(string filePath) return this; } - public RoslynPluginJarBuilder SetSqaleFilePath(string filePath) - { - // The existence of the file will be checked before building - if (string.IsNullOrWhiteSpace(filePath)) - { - throw new ArgumentNullException(nameof(filePath)); - } - sqaleFilePath = filePath; - return this; - } public RoslynPluginJarBuilder SetRepositoryKey(string key) { @@ -261,11 +249,6 @@ public void BuildJar(string workingDirectory) updater.AddFile(kvp.Key, kvp.Value); } - if (!string.IsNullOrWhiteSpace(sqaleFilePath)) - { - updater.AddFile(sqaleFilePath, RelativeSqaleXmlResourcePath); - } - updater.UpdateArchive(); } @@ -308,11 +291,6 @@ private string BuildConfigFile(string workingDirectory) RulesXmlResourcePath = GetAbsoluteResourcePath(RelativeRulesXmlResourcePath) }; - if (!string.IsNullOrWhiteSpace(sqaleFilePath)) - { - config.SqaleXmlResourcePath = GetAbsoluteResourcePath(RelativeSqaleXmlResourcePath); - } - foreach(KeyValuePair kvp in pluginProperties) { config.Properties[kvp.Key] = kvp.Value; diff --git a/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj b/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj index 77374ff..7c41a3e 100644 --- a/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj +++ b/RoslynPluginGenerator/SonarQube.Plugins.Roslyn.PluginGenerator.csproj @@ -133,8 +133,6 @@ - - True @@ -172,6 +170,7 @@ ResXFileCodeGenerator CmdLineResources.Designer.cs + Designer PublicResXFileCodeGenerator diff --git a/RoslynPluginGenerator/SqaleModel.cs b/RoslynPluginGenerator/SqaleModel.cs deleted file mode 100644 index 3a9f7a4..0000000 --- a/RoslynPluginGenerator/SqaleModel.cs +++ /dev/null @@ -1,78 +0,0 @@ -/* - * SonarQube Roslyn SDK - * Copyright (C) 2015-2017 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.Collections.Generic; -using System.Xml.Serialization; - -namespace SonarLint.XmlDescriptor -{ - [XmlRoot("sqale", Namespace = "")] - public class SqaleModel - { - public SqaleModel() - { - Sqale = new List(); - } - - [XmlArray("chc")] - public List Sqale { get; private set; } - } - - [XmlType("chc")] - public class SqaleDescriptor - { - public SqaleDescriptor() - { - Remediation = new SqaleRemediation(); - } - - [XmlElement("key")] - public string SubCharacteristic { get; set; } - - [XmlElement("chc")] - public SqaleRemediation Remediation { get; set; } - } - - public class SqaleRemediation - { - public SqaleRemediation() - { - Properties = new List(); - } - - [XmlElement("rule-key")] - public string RuleKey { get; set; } - - [XmlElement("prop")] - public List Properties { get; set; } - } - - public class SqaleRemediationProperty - { - [XmlElement("key")] - public string Key { get; set; } - - [XmlElement("txt")] - public string Text { get; set; } - - [XmlElement("val")] - public string Value { get; set; } - } -} \ No newline at end of file diff --git a/RoslynPluginGenerator/UIResources.Designer.cs b/RoslynPluginGenerator/UIResources.Designer.cs index 7f48976..91f3fa7 100644 --- a/RoslynPluginGenerator/UIResources.Designer.cs +++ b/RoslynPluginGenerator/UIResources.Designer.cs @@ -78,15 +78,6 @@ public static string APG_CreatedTempWorkingDir { } } - /// - /// Looks up a localized string similar to Generating fixed remediation cost SQALE file.... - /// - public static string APG_GeneratingConstantSqaleFile { - get { - return ResourceManager.GetString("APG_GeneratingConstantSqaleFile", resourceCulture); - } - } - /// /// Looks up a localized string similar to Generating plugin.... /// @@ -114,15 +105,6 @@ public static string APG_InvalidRulesFile { } } - /// - /// Looks up a localized string similar to The specified SQALE file is invalid: {0}. - /// - public static string APG_InvalidSqaleFile { - get { - return ResourceManager.GetString("APG_InvalidSqaleFile", resourceCulture); - } - } - /// /// Looks up a localized string similar to Looking for analyzers in the package.... /// @@ -205,11 +187,11 @@ public static string APG_PluginGenerated { } /// - /// Looks up a localized string similar to SQALE and customised rule xml information cannot currently be embedded into plugins generated from package dependencies.. + /// Looks up a localized string similar to Customized rule xml information cannot currently be embedded into plugins generated from package dependencies.. /// - public static string APG_RecurseEnabled_SQALEandRuleCustomisationNotEnabled { + public static string APG_RecurseEnabled_RuleCustomizationNotEnabled { get { - return ResourceManager.GetString("APG_RecurseEnabled_SQALEandRuleCustomisationNotEnabled", resourceCulture); + return ResourceManager.GetString("APG_RecurseEnabled_RuleCustomizationNotEnabled", resourceCulture); } } @@ -222,15 +204,6 @@ public static string APG_RulesGeneratedToFile { } } - /// - /// Looks up a localized string similar to SQALE generated to file {0}. - /// - public static string APG_SqaleGeneratedToFile { - get { - return ResourceManager.GetString("APG_SqaleGeneratedToFile", resourceCulture); - } - } - /// /// Looks up a localized string similar to ///Rules definitions: a template rules xml file for the analyzer was saved to {0}. To customise the rules definitions for the analyzer: @@ -245,20 +218,6 @@ public static string APG_TemplateRuleFileGenerated { } } - /// - /// Looks up a localized string similar to - ///SQALE: an empty SQALE file for the analyzer was saved to {0}. To provide SQALE remediation information for the analyzer: - /// * rename the file - /// * fill in the appropriate remediation information for each diagnostic - /// * re-run this generator specifying the sqale file to use with the /sqale:[filename] argument. - ///. - /// - public static string APG_TemplateSqaleFileGenerated { - get { - return ResourceManager.GetString("APG_TemplateSqaleFileGenerated", resourceCulture); - } - } - /// /// Looks up a localized string similar to The language '{0}' is not supported. Valid options are 'cs' or 'vb'.. /// @@ -277,15 +236,6 @@ public static string APG_UsingSuppliedRulesFile { } } - /// - /// Looks up a localized string similar to Using the SQALE file: {0}. - /// - public static string APG_UsingSuppliedSqaleFile { - get { - return ResourceManager.GetString("APG_UsingSuppliedSqaleFile", resourceCulture); - } - } - /// /// Looks up a localized string similar to Roslyn Analyzer Plugin Generator for SonarQube. /// diff --git a/RoslynPluginGenerator/UIResources.resx b/RoslynPluginGenerator/UIResources.resx index 678ad7a..1cd5087 100644 --- a/RoslynPluginGenerator/UIResources.resx +++ b/RoslynPluginGenerator/UIResources.resx @@ -123,9 +123,6 @@ Temporary working folder for this run: {0} - - Generating fixed remediation cost SQALE file... - Generating plugin... @@ -135,9 +132,6 @@ The specified rules xml file is invalid: {0} - - The specified SQALE file is invalid: {0} - Looking for analyzers in the package... @@ -165,29 +159,18 @@ Plugin generated: {0} - - SQALE and customised rule xml information cannot currently be embedded into plugins generated from package dependencies. + + Customized rule xml information cannot currently be embedded into plugins generated from package dependencies. {0} rules generated to {1} - - SQALE generated to file {0} - Rules definitions: a template rules xml file for the analyzer was saved to {0}. To customise the rules definitions for the analyzer: * rename the file * edit the rules definitions in the file * re-run this generator specifying the rules xml file to use with the /rules:[filename] argument. - - - - -SQALE: an empty SQALE file for the analyzer was saved to {0}. To provide SQALE remediation information for the analyzer: - * rename the file - * fill in the appropriate remediation information for each diagnostic - * re-run this generator specifying the sqale file to use with the /sqale:[filename] argument. @@ -196,9 +179,6 @@ SQALE: an empty SQALE file for the analyzer was saved to {0}. To provide SQALE r Using the supplied rules xml file: {0} - - Using the SQALE file: {0} - Roslyn Analyzer Plugin Generator for SonarQube diff --git a/Tests/Common/ZipFileChecker.cs b/Tests/Common/ZipFileChecker.cs index 5925bb1..823159e 100644 --- a/Tests/Common/ZipFileChecker.cs +++ b/Tests/Common/ZipFileChecker.cs @@ -71,6 +71,18 @@ public void AssertZipContainsFiles(params string[] expectedRelativePaths) } } + public void AssertZipDoesNotContainFiles(params string[] unexpectedRelativePaths) + { + foreach (string relativePath in unexpectedRelativePaths) + { + testContext.WriteLine("ZipFileChecker: checking for file '{0}'", relativePath); + + string[] matchingFiles = Directory.GetFiles(UnzippedDirectoryPath, relativePath, SearchOption.TopDirectoryOnly); + + matchingFiles.Length.Should().Be(0, $"Zip file contains unexpected file: {relativePath}"); + } + } + public void AssertZipContainsOnlyExpectedFiles(params string[] expectedRelativePaths) { AssertZipContainsFiles(expectedRelativePaths); diff --git a/Tests/IntegrationTests/Roslyn/RoslynGenTests.cs b/Tests/IntegrationTests/Roslyn/RoslynGenTests.cs index 1c0760c..f8f5cfd 100644 --- a/Tests/IntegrationTests/Roslyn/RoslynGenTests.cs +++ b/Tests/IntegrationTests/Roslyn/RoslynGenTests.cs @@ -58,7 +58,7 @@ public void RoslynPlugin_GenerateForValidAnalyzer_Succeeds() // Act NuGetPackageHandler nuGetHandler = new NuGetPackageHandler(fakeRemotePkgMgr.LocalRepository, localPackageDestination, logger); AnalyzerPluginGenerator apg = new AnalyzerPluginGenerator(nuGetHandler, logger); - ProcessedArgs args = new ProcessedArgs(packageId, new SemanticVersion("1.0.2"), "cs", null, null, false, false, outputDir); + ProcessedArgs args = new ProcessedArgs(packageId, new SemanticVersion("1.0.2"), "cs", null, false, false, outputDir); bool result = apg.Generate(args); // Assert @@ -92,7 +92,7 @@ public void RoslynPlugin_GenerateForDependencyAnalyzers_Succeeds() // Act NuGetPackageHandler nuGetHandler = new NuGetPackageHandler(fakeRemotePkgMgr.LocalRepository, localPackageDestination, logger); AnalyzerPluginGenerator apg = new AnalyzerPluginGenerator(nuGetHandler, logger); - ProcessedArgs args = new ProcessedArgs(targetPkg.Id, targetPkg.Version, "cs", null, null, false, + ProcessedArgs args = new ProcessedArgs(targetPkg.Id, targetPkg.Version, "cs", null, false, true /* generate plugins for dependencies with analyzers*/, outputDir); bool result = apg.Generate(args); @@ -127,7 +127,7 @@ public void RoslynPlugin_GenerateForMultiLevelAnalyzers_Succeeds() // Act NuGetPackageHandler nuGetHandler = new NuGetPackageHandler(fakeRemotePkgMgr.LocalRepository, localPackageDestination, logger); AnalyzerPluginGenerator apg = new AnalyzerPluginGenerator(nuGetHandler, logger); - ProcessedArgs args = new ProcessedArgs(targetPkg.Id, targetPkg.Version, "cs", null, null, false, + ProcessedArgs args = new ProcessedArgs(targetPkg.Id, targetPkg.Version, "cs", null, false, true /* generate plugins for dependencies with analyzers*/, outputDir); bool result = apg.Generate(args); diff --git a/Tests/RoslynPluginGeneratorTests/AnalyzerPluginGeneratorTests.cs b/Tests/RoslynPluginGeneratorTests/AnalyzerPluginGeneratorTests.cs index 05dc418..dd3f0fd 100644 --- a/Tests/RoslynPluginGeneratorTests/AnalyzerPluginGeneratorTests.cs +++ b/Tests/RoslynPluginGeneratorTests/AnalyzerPluginGeneratorTests.cs @@ -21,7 +21,6 @@ using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using NuGet; -using SonarLint.XmlDescriptor; using SonarQube.Plugins.Roslyn.CommandLine; using SonarQube.Plugins.Test.Common; using System; @@ -54,7 +53,7 @@ public void Generate_NoAnalyzersFoundInPackage_GenerateFails() NuGetPackageHandler nuGetHandler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, GetLocalNuGetDownloadDir(), logger); AnalyzerPluginGenerator apg = new AnalyzerPluginGenerator(nuGetHandler, logger); - ProcessedArgs args = CreateArgs("no.analyzers.id", "0.9", "cs", null, false, false, outputDir); + ProcessedArgs args = CreateArgs("no.analyzers.id", "0.9", "cs", false, false, outputDir); // Act bool result = apg.Generate(args); @@ -64,7 +63,7 @@ public void Generate_NoAnalyzersFoundInPackage_GenerateFails() logger.AssertSingleWarningExists(String.Format(UIResources.APG_NoAnalyzersFound, "no.analyzers.id")); logger.AssertSingleWarningExists(UIResources.APG_NoAnalyzersInTargetSuggestRecurse); logger.AssertWarningsLogged(2); - AssertSqaleTemplateDoesNotExist(outputDir); + AssertRuleTemplateDoesNotExist(outputDir); } [TestMethod] @@ -83,7 +82,7 @@ public void Generate_LicenseAcceptanceNotRequired_Succeeds() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. Acceptance not required -> succeeds if accept = false - ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if there are no licenses to accept"); @@ -94,7 +93,7 @@ public void Generate_LicenseAcceptanceNotRequired_Succeeds() logger.AssertWarningNotLogged("grandchild.id"); // 2. Acceptance not required -> succeeds if accept = true - args = CreateArgs("parent.id", "1.0", "cs", null, true /* accept licenses */, false, outputDir); + args = CreateArgs("parent.id", "1.0", "cs", true /* accept licenses */, false, outputDir); result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if there are no licenses to accept"); @@ -121,7 +120,7 @@ public void Generate_Recursive_Succeeds() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // Act - ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", null, false, true /* /recurse = true */, outputDir); + ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", false, true /* /recurse = true */, outputDir); bool result = apg.Generate(args); // Assert @@ -148,7 +147,7 @@ public void Generate_LicenseAcceptanceRequiredByMainPackage() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. User does not accept -> fails with error - ProcessedArgs args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeFalse("Generator should fail because license has not been accepted"); @@ -159,7 +158,7 @@ public void Generate_LicenseAcceptanceRequiredByMainPackage() // 2. User accepts -> succeeds with warnings logger.Reset(); - args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", null, true /* accept licenses */ , + args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", true /* accept licenses */ , false /* generate plugins for dependencies */, outputDir); result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if licenses are accepted"); @@ -185,7 +184,7 @@ public void Generate_LicenseAcceptanceRequiredByDependency() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. User does not accept -> fails with error - ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeFalse("Generator should fail because license has not been accepted"); @@ -196,7 +195,7 @@ public void Generate_LicenseAcceptanceRequiredByDependency() // 2. User accepts -> succeeds with warnings logger.Reset(); - args = CreateArgs("parent.id", "1.0", "cs", null, true /* accept licenses */ , + args = CreateArgs("parent.id", "1.0", "cs", true /* accept licenses */ , false, outputDir); result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if licenses are accepted"); @@ -224,7 +223,7 @@ public void Generate_LicenseAcceptanceRequired_ByParentAndDependencies() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. a) Only target package. User does not accept -> fails with error - ProcessedArgs args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeFalse("Generator should fail because license has not been accepted"); @@ -237,7 +236,7 @@ public void Generate_LicenseAcceptanceRequired_ByParentAndDependencies() // 2. User accepts -> succeeds with warnings logger.Reset(); - args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", null, true /* accept licenses */ , + args = CreateArgs("parent.requiredAccept.id", "1.0", "cs", true /* accept licenses */ , false, outputDir); result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if licenses are accepted"); @@ -267,7 +266,7 @@ public void Generate_LicenseAcceptanceNotRequestedIfNoAnalysers() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. User does not accept, but no analyzers so no license prompt -> fails due absence of analyzers - ProcessedArgs args = CreateArgs("non-analyzer.requireAccept.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("non-analyzer.requireAccept.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeFalse("Expecting generator to fail"); @@ -302,7 +301,7 @@ public void Generate_LicenseAcceptanceNotRequired_NoAnalyzersInTarget() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. a) Only target package. Acceptance not required -> fails due to absence of analyzers - ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeFalse("Expecting generator to fail"); @@ -314,7 +313,7 @@ public void Generate_LicenseAcceptanceNotRequired_NoAnalyzersInTarget() // 1. b) Target package and dependencies. Acceptance not required -> succeeds if generate dependencies = true logger.Reset(); - args = CreateArgs("parent.id", "1.0", "cs", null, false /* accept licenses */ , + args = CreateArgs("parent.id", "1.0", "cs", false /* accept licenses */ , true /* generate plugins for dependencies */, outputDir); result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if there are no licenses to accept"); @@ -351,7 +350,7 @@ public void Generate_LicenseAcceptanceRequired_NoAnalysersInTarget() AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder, logger); // 1. a) Only target package. User does not accept, but no analyzers so no license prompt -> fails due to absence of analyzers - ProcessedArgs args = CreateArgs("non-analyzer.parent.requireAccept.id", "1.0", "cs", null, false /* accept licenses */ , + ProcessedArgs args = CreateArgs("non-analyzer.parent.requireAccept.id", "1.0", "cs", false /* accept licenses */ , false, outputDir); bool result = apg.Generate(args); result.Should().BeFalse("Expecting generator to fail"); @@ -364,7 +363,7 @@ public void Generate_LicenseAcceptanceRequired_NoAnalysersInTarget() // 1. b) Target package and dependencies. User does not accept. // No analyzers in the target package, but analyzers in the dependencies -> fails with error logger.Reset(); - args = CreateArgs("non-analyzer.parent.requireAccept.id", "1.0", "cs", null, false /* accept licenses */ , + args = CreateArgs("non-analyzer.parent.requireAccept.id", "1.0", "cs", false /* accept licenses */ , true /* generate plugins for dependencies */, outputDir); result = apg.Generate(args); result.Should().BeFalse("Generator should fail because license has not been accepted"); @@ -379,7 +378,7 @@ public void Generate_LicenseAcceptanceRequired_NoAnalysersInTarget() // 2. b) Target package and dependencies. User accepts. // No analyzers in the target package, but analyzers in the dependencies -> succeeds with warnings logger.Reset(); - args = CreateArgs("non-analyzer.parent.requireAccept.id", "1.0", "cs", null, true /* accept licenses */ , + args = CreateArgs("non-analyzer.parent.requireAccept.id", "1.0", "cs", true /* accept licenses */ , true /* generate plugins for dependencies */, outputDir); result = apg.Generate(args); result.Should().BeTrue("Generator should succeed if licenses are accepted"); @@ -391,98 +390,7 @@ public void Generate_LicenseAcceptanceRequired_NoAnalysersInTarget() logger.AssertWarningsLogged(5); logger.AssertErrorsLogged(0); } - - [TestMethod] - public void Generate_SqaleFileNotSpecified_TemplateFileCreated() - { - // Arrange - string outputDir = TestUtils.CreateTestDirectory(TestContext, ".out"); - - TestLogger logger = new TestLogger(); - RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(TestContext); - IPackage child1 = CreatePackageWithAnalyzer(remoteRepoBuilder, "child1.requiredAccept.id", "2.1", License.NotRequired); - IPackage child2 = CreatePackageWithAnalyzer(remoteRepoBuilder, "child2.id", "2.2", License.NotRequired); - IPackage parent = CreatePackageWithAnalyzer(remoteRepoBuilder, "parent.id", "1.0", License.NotRequired, child1, child2); - - NuGetPackageHandler nuGetHandler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, GetLocalNuGetDownloadDir(), logger); - - AnalyzerPluginGenerator apg = new AnalyzerPluginGenerator(nuGetHandler, logger); - - // 1. Generate a plugin for the target package only. Expecting a plugin and a template SQALE file. - ProcessedArgs args = CreateArgs("parent.id", "1.0", "cs", null, false, false, outputDir); - bool result = apg.Generate(args); - - result.Should().BeTrue("Expecting generation to have succeeded"); - AssertSqaleFileExistsForPackage(logger, outputDir, parent); - - // 2. Generate a plugin for target package and all dependencies. Expecting three plugins and associated SQALE files. - logger.Reset(); - args = CreateArgs("parent.id", "1.0", "cs", null, false, true /* /recurse = true */, outputDir); - result = apg.Generate(args); - - result.Should().BeTrue("Expecting generation to have succeeded"); - logger.AssertSingleWarningExists(UIResources.APG_RecurseEnabled_SQALEandRuleCustomisationNotEnabled); - AssertSqaleFileExistsForPackage(logger, outputDir, parent); - AssertSqaleFileExistsForPackage(logger, outputDir, child1); - AssertSqaleFileExistsForPackage(logger, outputDir, child2); - } - - [TestMethod] - public void Generate_ValidSqaleFileSpecified_TemplateFileNotCreated() - { - // Arrange - string outputDir = TestUtils.CreateTestDirectory(TestContext, ".out"); - - RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(TestContext); - AnalyzerPluginGenerator apg = CreateTestSubjectWithFakeRemoteRepo(remoteRepoBuilder); - - CreatePackageInFakeRemoteRepo(remoteRepoBuilder, "dummy.id", "1.1"); - - // Create a dummy sqale file - string dummySqaleFilePath = Path.Combine(outputDir, "inputSqale.xml"); - SqaleModel dummySqale = new SqaleModel(); - Serializer.SaveModel(dummySqale, dummySqaleFilePath); - - ProcessedArgs args = CreateArgs("dummy.id", "1.1", "cs", dummySqaleFilePath, false, false, outputDir); - - // Act - bool result = apg.Generate(args); - - // Assert - result.Should().BeTrue("Expecting generation to have succeeded"); - AssertSqaleTemplateDoesNotExist(outputDir); - } - - [TestMethod] - public void Generate_InvalidSqaleFileSpecified_GeneratorError() - { - // Arrange - string outputDir = TestUtils.CreateTestDirectory(TestContext, ".out"); - - TestLogger logger = new TestLogger(); - - RemoteRepoBuilder remoteRepoBuilder = new RemoteRepoBuilder(TestContext); - CreatePackageInFakeRemoteRepo(remoteRepoBuilder, "dummy.id", "1.1"); - - NuGetPackageHandler nuGetHandler = new NuGetPackageHandler(remoteRepoBuilder.FakeRemoteRepo, GetLocalNuGetDownloadDir(), logger); - - // Create an invalid sqale file - string dummySqaleFilePath = Path.Combine(outputDir, "invalidSqale.xml"); - File.WriteAllText(dummySqaleFilePath, "not valid xml"); - - AnalyzerPluginGenerator apg = new AnalyzerPluginGenerator(nuGetHandler, logger); - - ProcessedArgs args = CreateArgs("dummy.id", "1.1", "cs", dummySqaleFilePath, false, false, outputDir); - - // Act - bool result = apg.Generate(args); - - // Assert - result.Should().BeFalse("Expecting generation to have failed"); - AssertSqaleTemplateDoesNotExist(outputDir); - logger.AssertSingleErrorExists("invalidSqale.xml"); // expecting an error containing the invalid sqale file name - } - + [TestMethod] public void Generate_RulesFileNotSpecified_TemplateFileCreated() { @@ -512,11 +420,11 @@ public void Generate_RulesFileNotSpecified_TemplateFileCreated() // 2. Generate a plugin for target package and all dependencies. Expecting three plugins and associated rule files. logger.Reset(); - args = CreateArgs("parent.id", "1.0", "cs", null, false, true /* /recurse = true */, outputDir); + args = CreateArgs("parent.id", "1.0", "cs", false, true /* /recurse = true */, outputDir); result = testSubject.Generate(args); result.Should().BeTrue(); - logger.AssertSingleWarningExists(UIResources.APG_RecurseEnabled_SQALEandRuleCustomisationNotEnabled); + logger.AssertSingleWarningExists(UIResources.APG_RecurseEnabled_RuleCustomizationNotEnabled); AssertRuleTemplateFileExistsForPackage(logger, outputDir, parent); AssertRuleTemplateFileExistsForPackage(logger, outputDir, child1); AssertRuleTemplateFileExistsForPackage(logger, outputDir, child2); @@ -718,13 +626,12 @@ public void CreatePluginManifest_Owners_NotAvailable() #region Private methods - private static ProcessedArgs CreateArgs(string packageId, string packageVersion, string language, string sqaleFilePath, bool acceptLicenses, bool recurseDependencies, string outputDirectory) + private static ProcessedArgs CreateArgs(string packageId, string packageVersion, string language, bool acceptLicenses, bool recurseDependencies, string outputDirectory) { ProcessedArgs args = new ProcessedArgs( packageId, new SemanticVersion(packageVersion), language, - sqaleFilePath, null /* rule xml path */, acceptLicenses, recurseDependencies, @@ -770,26 +677,6 @@ private string GetLocalNuGetDownloadDir() return TestUtils.EnsureTestDirectoryExists(TestContext, ".localNuGetDownload"); } - private static string GetExpectedTemplateSqaleFilePath(string outputDir, IPackage package) - { - return Path.Combine(outputDir, String.Format("{0}.{1}.sqale.template.xml", package.Id, package.Version.ToString())); - } - - private void AssertSqaleFileExistsForPackage(TestLogger logger, string outputDir, IPackage package) - { - string expectedTemplateSqaleFilePath = GetExpectedTemplateSqaleFilePath(outputDir, package); - - File.Exists(expectedTemplateSqaleFilePath).Should().BeTrue("Expecting a template sqale file to have been created"); - TestContext.AddResultFile(expectedTemplateSqaleFilePath); - logger.AssertSingleInfoMessageExists(expectedTemplateSqaleFilePath); // should be a message about the generated file - } - - private static void AssertSqaleTemplateDoesNotExist(string outputDir) - { - string[] matches = Directory.GetFiles(outputDir, "*sqale*template*", SearchOption.AllDirectories); - matches.Length.Should().Be(0, "Not expecting any sqale template files to exist"); - } - private static string GetExpectedRuleTemplateFilePath(string outputDir, IPackage package) { return Path.Combine(outputDir, String.Format("{0}.{1}.rules.template.xml", package.Id, package.Version.ToString())); diff --git a/Tests/RoslynPluginGeneratorTests/ArgumentProcessorTests.cs b/Tests/RoslynPluginGeneratorTests/ArgumentProcessorTests.cs index add52f9..567a954 100644 --- a/Tests/RoslynPluginGeneratorTests/ArgumentProcessorTests.cs +++ b/Tests/RoslynPluginGeneratorTests/ArgumentProcessorTests.cs @@ -97,55 +97,35 @@ public void ArgProc_AnalyzerRef_Valid() rawArgs = new string[] { "/a:testing.id.no.version" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); - AssertArgumentsProcessed(actualArgs, logger, "testing.id.no.version", null, null, false); + AssertArgumentsProcessed(actualArgs, logger, "testing.id.no.version", null, false); // 2. Id and version logger = new TestLogger(); rawArgs = new string[] { "/analyzer:testing.id.with.version:1.0.0-rc1" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); - AssertArgumentsProcessed(actualArgs, logger, "testing.id.with.version", "1.0.0-rc1", null, false); + AssertArgumentsProcessed(actualArgs, logger, "testing.id.with.version", "1.0.0-rc1", false); // 3. Id containing a colon, with version logger = new TestLogger(); rawArgs = new string[] { "/analyzer:id.with:colon:2.1.0" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); - AssertArgumentsProcessed(actualArgs, logger, "id.with:colon", "2.1.0", null, false); + AssertArgumentsProcessed(actualArgs, logger, "id.with:colon", "2.1.0", false); } [TestMethod] - public void ArgProc_SqaleFile() + public void ArgProc_SqaleParameterIsDeprecated() { - // 0. Setup - TestLogger logger; - string[] rawArgs; - ProcessedArgs actualArgs; - - // 1. No sqale file value -> valid - logger = new TestLogger(); - rawArgs = new string[] { "/a:validId" }; - actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); - - AssertArgumentsProcessed(actualArgs, logger, "validId", null, null, false); + // Arrange + TestLogger logger = new TestLogger(); + string[] rawArgs = new string[] { "/sqale:mySqaleFile.txt", "/a:validId" }; - // 2. Missing sqale file - logger = new TestLogger(); - rawArgs = new string[] { "/sqale:missingFile.txt", "/a:validId" }; + ProcessedArgs actualArgs; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); AssertArgumentsNotProcessed(actualArgs, logger); - logger.AssertSingleErrorExists("missingFile.txt"); // should be an error containing the missing file name - - // 3. Existing sqale file - string testDir = TestUtils.CreateTestDirectory(TestContext); - string filePath = TestUtils.CreateTextFile("valid.sqale.txt", testDir, "sqale file contents"); - - logger = new TestLogger(); - rawArgs = new string[] { "/sqale:" + filePath, "/a:valid:1.0" }; - actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); - - AssertArgumentsProcessed(actualArgs, logger, "valid", "1.0", filePath, false); + logger.AssertSingleErrorExists("The /sqale parameter is no longer supported"); } [TestMethod] @@ -196,7 +176,7 @@ public void ArgProc_AcceptLicenses_Valid() rawArgs = new string[] { "/a:validId", "/acceptLicenses" }; actualArgs = ArgumentProcessor.TryProcessArguments(rawArgs, logger); - AssertArgumentsProcessed(actualArgs, logger, "validId", null, null, true); + AssertArgumentsProcessed(actualArgs, logger, "validId", null, true); } [TestMethod] @@ -239,7 +219,7 @@ private static void AssertArgumentsNotProcessed(ProcessedArgs actualArgs, TestLo logger.AssertErrorsLogged(); } - private static void AssertArgumentsProcessed(ProcessedArgs actualArgs, TestLogger logger, string expectedId, string expectedVersion, string expectedSqale, bool expectedAcceptLicenses) + private static void AssertArgumentsProcessed(ProcessedArgs actualArgs, TestLogger logger, string expectedId, string expectedVersion, bool expectedAcceptLicenses) { actualArgs.Should().NotBeNull("Expecting the arguments to have been processed successfully"); @@ -255,12 +235,6 @@ private static void AssertArgumentsProcessed(ProcessedArgs actualArgs, TestLogge actualArgs.PackageVersion.ToString().Should().Be(expectedVersion); } - actualArgs.SqaleFilePath.Should().Be(expectedSqale, "Unexpected sqale file path"); - if (expectedSqale != null) - { - File.Exists(expectedSqale).Should().BeTrue("Specified sqale file should exist: {0}", expectedSqale); - } - actualArgs.AcceptLicenses.Should().Be(expectedAcceptLicenses, "Unexpected value for AcceptLicenses"); logger.AssertErrorsLogged(0); diff --git a/Tests/RoslynPluginGeneratorTests/ProcessedArgsBuilder.cs b/Tests/RoslynPluginGeneratorTests/ProcessedArgsBuilder.cs index 9c39633..2592f64 100644 --- a/Tests/RoslynPluginGeneratorTests/ProcessedArgsBuilder.cs +++ b/Tests/RoslynPluginGeneratorTests/ProcessedArgsBuilder.cs @@ -28,7 +28,6 @@ public class ProcessedArgsBuilder private readonly string packageId; private string packageVersion; private string language; - private string sqaleFilePath; private string ruleFilePath; private bool acceptLicenses; private bool recurseDependencies; @@ -52,12 +51,6 @@ public ProcessedArgsBuilder SetLanguage(string language) return this; } - public ProcessedArgsBuilder SetSqaleFilePath(string filePath) - { - this.sqaleFilePath = filePath; - return this; - } - public ProcessedArgsBuilder SetRuleFilePath(string filePath) { this.ruleFilePath = filePath; @@ -82,7 +75,6 @@ public ProcessedArgs Build() packageId, new SemanticVersion(packageVersion), language, - sqaleFilePath, ruleFilePath, acceptLicenses, recurseDependencies, diff --git a/Tests/RoslynPluginGeneratorTests/RoslynPluginJarBuilderTests.cs b/Tests/RoslynPluginGeneratorTests/RoslynPluginJarBuilderTests.cs index 57a766e..3f27f7b 100644 --- a/Tests/RoslynPluginGeneratorTests/RoslynPluginJarBuilderTests.cs +++ b/Tests/RoslynPluginGeneratorTests/RoslynPluginJarBuilderTests.cs @@ -40,7 +40,6 @@ public void RoslynPlugin_Test() string outputJarFilePath = Path.Combine(testDir, "created.jar"); string dummyRulesFile = TestUtils.CreateTextFile("rules.txt", testDir, ""); - string dummySqaleFile = TestUtils.CreateTextFile("sqale.txt", testDir, ""); string dummyZipFile = TestUtils.CreateTextFile("payload.txt", testDir, "zip"); PluginManifest manifest= new PluginManifest() @@ -57,7 +56,6 @@ public void RoslynPlugin_Test() .SetRepositoryKey("repo.key") .SetRepositoryName("repo.name") .SetRulesFilePath(dummyRulesFile) - .SetSqaleFilePath(dummySqaleFile) .SetPluginManifestProperties(manifest) .AddResourceFile(dummyZipFile, "static\\foo.zip") .SetJarFilePath(outputJarFilePath); @@ -71,9 +69,11 @@ public void RoslynPlugin_Test() "META-INF\\MANIFEST.MF", "static\\foo.zip", "org\\sonar\\plugins\\roslynsdk\\configuration.xml", - "org\\sonar\\plugins\\roslynsdk\\sqale.xml", "org\\sonar\\plugins\\roslynsdk\\rules.xml" ); + + checker.AssertZipDoesNotContainFiles( + "org\\sonar\\plugins\\roslynsdk\\sqale.xml"); } #endregion Tests diff --git a/Tests/RoslynPluginGeneratorTests/RoslynSdkConfigurationTests.cs b/Tests/RoslynPluginGeneratorTests/RoslynSdkConfigurationTests.cs index a737cba..3143c18 100644 --- a/Tests/RoslynPluginGeneratorTests/RoslynSdkConfigurationTests.cs +++ b/Tests/RoslynPluginGeneratorTests/RoslynSdkConfigurationTests.cs @@ -47,7 +47,6 @@ public void SdkConfig_SaveAndReload_Succeeds() RepositoryName = "repo.name", RepositoryLanguage = "language", RulesXmlResourcePath = "rulesPath", - SqaleXmlResourcePath = "sqalePath" }; config.Properties["prop1.Key"] = "value1"; @@ -68,7 +67,6 @@ public void SdkConfig_SaveAndReload_Succeeds() reloaded.RepositoryName.Should().Be("repo.name"); reloaded.RepositoryLanguage.Should().Be("language"); reloaded.RulesXmlResourcePath.Should().Be("rulesPath"); - reloaded.SqaleXmlResourcePath.Should().Be("sqalePath"); reloaded.Properties.Count.Should().Be(2); AssertPropertyExists("prop1.Key", "value1", reloaded.Properties); @@ -88,7 +86,6 @@ public void SdkConfig_LoadRealExample_Succeeds() example example /org/sonar/plugins/roslynsdk/rules.xml - /org/sonar/plugins/roslynsdk/sqale.xml example.pluginKey.Value example.pluginVersion.Value @@ -119,7 +116,6 @@ public void SdkConfig_LoadRealExample_Succeeds() loaded.RepositoryLanguage.Should().Be("example"); loaded.RepositoryName.Should().Be("example"); loaded.RulesXmlResourcePath.Should().Be("/org/sonar/plugins/roslynsdk/rules.xml"); - loaded.SqaleXmlResourcePath.Should().Be("/org/sonar/plugins/roslynsdk/sqale.xml"); AssertPropertyExists("example.pluginKey", "example.pluginKey.Value", loaded.Properties); AssertPropertyExists("example.pluginVersion", "example.pluginVersion.Value", loaded.Properties);