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

SCAN4NET-171 Read new properties for downloading plugins #2294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alex-meseldzija-sonarsource
Copy link
Contributor

@alex-meseldzija-sonarsource alex-meseldzija-sonarsource commented Jan 24, 2025

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title SCAN4NET-171 Read new properties for downloading plugins SCAN4NET-171 Read new properties for downloading plugins Jan 24, 2025
@alex-meseldzija-sonarsource alex-meseldzija-sonarsource force-pushed the alex/SCAN4NET-171 branch 2 times, most recently from 0e8ecff to fdc4cef Compare January 24, 2025 12:54
Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small conceptual nuke to start with

@alex-meseldzija-sonarsource alex-meseldzija-sonarsource force-pushed the alex/SCAN4NET-171 branch 2 times, most recently from 51fadff to ad8f09f Compare January 31, 2025 10:40
@alex-meseldzija-sonarsource alex-meseldzija-sonarsource changed the base branch from master to alex/refactor-fetch-analyzer-plugin January 31, 2025 10:51
@alex-meseldzija-sonarsource alex-meseldzija-sonarsource force-pushed the alex/refactor-fetch-analyzer-plugin branch 2 times, most recently from 5fb0eda to 1e11364 Compare January 31, 2025 13:26
@alex-meseldzija-sonarsource alex-meseldzija-sonarsource force-pushed the alex/refactor-fetch-analyzer-plugin branch from 1e11364 to f4efaca Compare January 31, 2025 14:45
@alex-meseldzija-sonarsource alex-meseldzija-sonarsource force-pushed the alex/SCAN4NET-171 branch 2 times, most recently from 98affdf to f089335 Compare January 31, 2025 14:57
Base automatically changed from alex/refactor-fetch-analyzer-plugin to master January 31, 2025 15:20
Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some polishing

{
SuppliedPlugins.Should().NotBeEmpty("No plugins have been requested");
var found = SuppliedPlugins.Any(x => string.Equals(key, x.Key, System.StringComparison.Ordinal));
found.Should().BeTrue("Expected plugin was not requested. Id: {0}", key);
var suppliedPlugin = SuppliedPlugins.FirstOrDefault(x => string.Equals(plugin.Key, x.Key, System.StringComparison.Ordinal));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To throw in case the expectation of having single with that key is broken

Suggested change
var suppliedPlugin = SuppliedPlugins.FirstOrDefault(x => string.Equals(plugin.Key, x.Key, System.StringComparison.Ordinal));
var suppliedPlugin = SuppliedPlugins.SingleOrDefault(x => string.Equals(plugin.Key, x.Key, System.StringComparison.Ordinal));

{
SuppliedPlugins.Should().NotBeEmpty("No plugins have been requested");
var found = SuppliedPlugins.Any(x => string.Equals(key, x.Key, System.StringComparison.Ordinal));
found.Should().BeTrue("Expected plugin was not requested. Id: {0}", key);
var suppliedPlugin = SuppliedPlugins.FirstOrDefault(x => string.Equals(plugin.Key, x.Key, System.StringComparison.Ordinal));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the Java?

Suggested change
var suppliedPlugin = SuppliedPlugins.FirstOrDefault(x => string.Equals(plugin.Key, x.Key, System.StringComparison.Ordinal));
var suppliedPlugin = SuppliedPlugins.FirstOrDefault(x => plugin.Key = x.Key);

@@ -18,11 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see why it's worth taking care of the project structure in general? :)

private const string RoslynRepoPrefix = "roslyn.";
private const string ServerPropertyFormat = "sonar.{0}.analyzer";
private const string RoslynRepoPrefix = "roslyn."; // Used for plugins generated by SonarQube Roslyn SDK, and legacy Sonar Security C# Frontend
private const string LegacySecurityFrontEndPropertyPrefix = "sonaranalyzer.security.cs"; // Should not be used and exists for backward compatibility with version <= 9.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment doesn't sound right on the Security front end. It's only used for deduplication, and it's not really needed for backward compatibility.

As this constant was not here before, I'd hardcode the value below where it's used.

private const string ServerPropertyFormat = "sonar.{0}.analyzer";
private const string RoslynRepoPrefix = "roslyn."; // Used for plugins generated by SonarQube Roslyn SDK, and legacy Sonar Security C# Frontend
private const string LegacySecurityFrontEndPropertyPrefix = "sonaranalyzer.security.cs"; // Should not be used and exists for backward compatibility with version <= 9.2
private const string LegacyServerPropertyPrefix = "sonaranalyzer-"; // Should not be used and exists for backward compatibility with version <= 9.2.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is version 9.2? Plugin? SonarQube? Scanner?
Plugin was < 10.4
SQ was < 10.8
Scanner is irrelevant

Suggested change
private const string LegacyServerPropertyPrefix = "sonaranalyzer-"; // Should not be used and exists for backward compatibility with version <= 9.2.
private const string LegacyServerPropertyPrefix = "sonaranalyzer-"; // Backward compatibility with ??? version <= 9.2.

}

[TestMethod]
public void RoslynConfig_ValidProfile_Security_Frontend()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not write 3 dedicated UT for security. Add the scaffolding to the existing UTs above

}

[TestMethod]
public void RoslynConfig_IncompletePluginDoesNotPopulate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void RoslynConfig_IncompletePluginDoesNotPopulate()
public void RoslynConfig_IncompletePluginIgnored()

{"sonar.cs.analyzer.dotnet.staticResourceName", "SonarAnalyzer.zip"},
});
var context = new Context(TestContext, sonarProperties, [[@"c:\assembly1.dll"], [@"d:\foo\assembly2.dll"]]);
var expectedSonarLintXml = """
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of asserting this file in this UT? It seems immutable to the scaffolding

{"sonar.cs.analyzer.security.pluginVersion", "1.13.0"},
{"sonar.cs.analyzer.security.staticResourceName", "SecurityAnalyzer.zip"},
{"sonaranalyzer.security.cs.analyzerId", "SonarAnalyzer.Security"},
{"sonaranalyzer.security.cs.ruleNamespace", "SonarAnalyzer.Security"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruleNamespace should not exist as part of the new properties

Comment on lines +464 to +467
{"wintellect.pluginKey", "wintellect"},
{"sonar.cs.analyzer.dotnet.analyzerId", "SonarAnalyzer.CSharp"},
{"sonar.cs.analyzer.dotnet.ruleNamespace", "SonarAnalyzer.CSharp"},
{"sonar.cs.analyzer.dotnet.staticResourceName", "SonarAnalyzer.zip"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this trying to say? That any missing property will be no-op? It's bit hard to see. We should make that more explicit. Something like this:

            {"sonar.cs.analyzer.security.missing-pluginKey", "securitycsharpfrontend"},
            {"sonar.cs.analyzer.security.pluginVersion", "1.13.0"},
            {"sonar.cs.analyzer.security.staticResourceName", "SecurityAnalyzer.zip"},

The question is how to make it visible for all 3 of them. Parametrized test with analyzerIdName, versionName, staticResourceName?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants