SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
773 stars 226 forks source link

SQ Plugin: Replace usages of deprecated Build.setProfile in the integration tests #3102

Closed costin-zaharia-sonarsource closed 1 month ago

costin-zaharia-sonarsource commented 4 years ago

Build.setProfile method is used multiple times in the integration tests but it has been deprecated and currently, calling it, doesn't have the expected result.

As an example, if I delete the call from no_coverage_on_tests the test remains green.

We have to remove the calls, replace them with provisionProject() and associateProjectToQualityProfile() where needed and see if the tests are still valid since removing a method call still keeps the test successful.

sebastien-marichal commented 1 month ago

From #8389


It is now used only in Tests.analyzeProject.

It is not as simple as replacing the call, associateProjectToQualityProfile requires the project to already exist as it calls the api/qualityprofiles/add_project endpoint which assumes that the project exists.

One approach could be:

  public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException {
    Path projectFullPath = TestUtils.projectDir(temp, projectDir);

    if (profileKey != null) {
      ORCHESTRATOR.getServer().provisionProject(projectKey, projectKey); // Create the project
      ORCHESTRATOR.getServer().associateProjectToQualityProfile(projectKey, "cs", profileKey); // Bind the profile to it
    }

    ScannerForMSBuild beginStep = TestUtils.createBeginStep(projectKey, projectFullPath)
      .setProperties(keyValues);

    ORCHESTRATOR.executeBuild(beginStep);
    TestUtils.runBuild(projectFullPath);
    return ORCHESTRATOR.executeBuild(TestUtils.createEndStep(projectFullPath));
  }

The same goes for the VBNET version. Usage outside the Tests class should be checked as well.