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

Improve Java ITs: Replace deprecated `setProfile` by `associateProjectToQualityProfile` #8389

Closed sebastien-marichal closed 1 month ago

sebastien-marichal commented 9 months ago

In Tests.analyzeProject, we use setProfile which is deprecated and probably not even compatible with S4NET (I am not sure we use the sonar.profile option).

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.

pavel-mikula-sonarsource commented 1 month ago

@sebastien-marichal Isn't this duplicate of #3102 ?

sebastien-marichal commented 1 month ago

Probably, although this ticket seems to be more up-to-date. setProfile does not seem to be as used in test classes as it was back in 2020.

pavel-mikula-sonarsource commented 1 month ago

Please move relevant parts there and close this one

sebastien-marichal commented 1 month ago

Close as duplicate of #3102