mc1arke / sonarqube-community-branch-plugin

A plugin that allows branch analysis and pull request decoration in the Community version of Sonarqube
GNU Lesser General Public License v3.0
2.22k stars 521 forks source link

PR Decoration not working on SonarQube 9.4 #569

Closed juanrodicio closed 2 years ago

juanrodicio commented 2 years ago

Describe the bug PR Decorator is not working on the latest SonarQube version. Below you can see ce.log from sonarqube server in TRACE mode.

Log 2022.04.04 17:55:59 TRACE ce[AX_1SkES6djQpz_x560U][o.s.c.p.PriorityBeanFactory] Ignoring constructor [public org.sonar.ce.task.step.ComputationStepExecutor(org.sonar.ce.task.step.ComputationSteps,org.sonar.ce.task.CeTaskInterrupter,org.sonar.ce.task.step.ComputationStepExecutor$Listener)] of bean 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-org.sonar.ce.task.step.ComputationStepExecutor': org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-org.sonar.ce.task.step.ComputationStepExecutor': Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor': Unsatisfied dependency expressed through constructor parameter 5; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-com.github.mc1arke.sonarqube.plugin.almclient.github.DefaultGithubClientFactory': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@42a57993-com.github.mc1arke.sonarqube.plugin.almclient.github.v3.RestApplicationAuthenticationProvider': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.github.mc1arke.sonarqube.plugin.almclient.github.v3.RestApplicationAuthenticationProvider]: No default constructor found; nested exception is java.security.PrivilegedActionException: java.lang.NoSuchMethodException: com.github.mc1arke.sonarqube.plugin.almclient.github.v3.RestApplicationAuthenticationProvider.<init>()

Software Versions

Thank you in advance.

mc1arke commented 2 years ago

I'm unable to replicate this on a snapshot build of the plugin containing no changes other than the underlying sonarqube version in the build.gradle. Can you confirm more about your setup please:

  1. Installation type (container, non-container)
  2. Operating system
juanrodicio commented 2 years ago

It's installed on AWS EC2 Centos 7 with no docker container (only one container for postgres db)

mc1arke commented 2 years ago

Running on Mac OS inside a Sonarqube 9.4 unzipped distribution directory, the following works for me:

$ curl https://github.com/mc1arke/sonarqube-community-branch-plugin/releases/download/1.10.0/sonarqube-community-branch-plugin-1.10.0.jar -o extensions/plugins/sonarqube-community-branch-plugin.jar -sL
$ echo "sonar.web.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin.jar=web" >> conf/sonar.properties
$ echo "sonar.ce.javaAdditionalOpts=-javaagent:./extensions/plugins/sonarqube-community-branch-plugin.jar=ce" >> conf/sonar.properties
$ ./bin/macosx-universal-64/sonar.sh start

Whilst not identical to a Centos 7 setup, I'm fairly comfortable this works out the box. Are you able to confirm your current configuration looks similar (i.e. the plugin in the extensions/plugin directory and 2 lines added to your conf/sonar.properties file?

juanrodicio commented 2 years ago

Yes, I have both properties setted. The only difference i see is the name, but i don't think that is gonna be a problem. Reviewing other issues i see that they have a tab on project settings to manage pull request decorator wich i'm not able to see it.

mc1arke commented 2 years ago

I've just replicated the error you're seeing and believe this is due to Sonarqube switching to using Spring rather than PicoContainer for dependency injection, with Spring requiring annotations on classes with multiple constructors rather than the method PicoContainer used of ignoring low-visibility constructors.

Can you confirm:

Given your latest comment, can you also confirm:

juanrodicio commented 2 years ago

Yes, Sonarqube starts ok with no problems at all. Also i can analyze branches and pull request and seeing them on Sonarqube. I configured Bitbucket as Git Repository and DevOps Platform with Jenkins. All of this is working fine and marks builds as success on Bitbucket builds but no decorator on PRs.

prokop7 commented 2 years ago

Is there any release date?

honzajscz commented 2 years ago

Could we please have any information on a potential release date?

johnou commented 2 years ago

At least unit tests are failing after merging and resolving conflicts to master, looks like the utf8 detection? has changed..

Index: src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabMergeRequestDecoratorIntegrationTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabMergeRequestDecoratorIntegrationTest.java b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabMergeRequestDecoratorIntegrationTest.java
--- a/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabMergeRequestDecoratorIntegrationTest.java   (revision fdc0f3087e5560c52409db78dc332ca31363a565)
+++ b/src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/gitlab/GitlabMergeRequestDecoratorIntegrationTest.java   (date 1649833362148)
@@ -210,11 +210,11 @@
                 .willReturn(created()));

         wireMockRule.stubFor(post(urlPathEqualTo("/api/v4/projects/" + sourceProjectId + "/merge_requests/" + mergeRequestIid + "/discussions"))
-                .withRequestBody(equalTo("body=summary+comm%C3%A9nt%0A%0A%5Blink+text%5D"))
+                .withRequestBody(equalTo("body=summary+comm%C3%83%C2%A9nt%0A%0A%5Blink+text%5D"))
                 .willReturn(created().withBody(discussionPostResponseBody(discussionId, discussionNote(noteId, user, "summary comment", true, false)))));

         wireMockRule.stubFor(post(urlPathEqualTo("/api/v4/projects/" + sourceProjectId + "/merge_requests/" + mergeRequestIid + "/discussions"))
-                .withRequestBody(equalTo("body=issu%C3%A9&" +
+                .withRequestBody(equalTo("body=issu%C3%83%C2%A9&" +
                         urlEncode("position[base_sha]") + "=d6a420d043dfe85e7c240fd136fc6e197998b10a&" +
                         urlEncode("position[start_sha]") + "=d6a420d043dfe85e7c240fd136fc6e197998b10a&" +
                         urlEncode("position[head_sha]") + "=" + commitSHA + "&" +
mc1arke commented 2 years ago

@johnou Is this what you're having to apply to make unit tests pass? Can you confirm what version of Java, what OS you're running on, and if you have any changes applies to your project please?

johnou commented 2 years ago

@mc1arke yep, without it I'm seeing these errors [1]. No modifications to my fork https://github.com/mc1arke/sonarqube-community-branch-plugin/compare/master...johnou:sulake?expand=1

OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22000 N/A Build 22000
openjdk version "11.0.14.1" 2022-02-08 LTS
OpenJDK Runtime Environment Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.14.10.1 (build 11.0.14.1+10-LTS, mixed mode)

[1]

10:14:29.521 [qtp1649140180-35] ERROR WireMock - 
                                               Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
POST                                                       | POST
[path] /api/v4/projects/1234/merge_requests/6/discussions  | /api/v4/projects/1234/merge_requests/6/discussions
                                                           |
body=issu%C3%A9&position%5Bbase_sha%5D=d6a420d043dfe85e7c  | body=issu%C3%83%C2%A9&position%5Bbase_sha%5D=d6a420d043df<<<<< Body does not match
240fd136fc6e197998b10a&position%5Bstart_sha%5D=d6a420d043  | e85e7c240fd136fc6e197998b10a&position%5Bstart_sha%5D=d6a4
dfe85e7c240fd136fc6e197998b10a&position%5Bhead_sha%5D=com  | 20d043dfe85e7c240fd136fc6e197998b10a&position%5Bhead_sha%
mitSHA&position%5Bold_path%5D=%2Fpath%2Fto%2Ffile&positio  | 5D=commitSHA&position%5Bold_path%5D=%2Fpath%2Fto%2Ffile&p
n%5Bnew_path%5D=%2Fpath%2Fto%2Ffile&position%5Bnew_line%5  | osition%5Bnew_path%5D=%2Fpath%2Fto%2Ffile&position%5Bnew_
D=5&position%5Bposition_type%5D=text                       | line%5D=5&position%5Bposition_type%5D=text
                                                           |
10:15:39.131 [qtp1300523151-37] ERROR WireMock - 
                                               Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
POST                                                       | POST
[path] /api/v4/projects/1234/merge_requests/6/discussions  | /api/v4/projects/1234/merge_requests/6/discussions
                                                           |
body=summary+comm%C3%A9nt%0A%0A%5Blink+text%5D             | body=summary+comm%C3%83%C2%A9nt%0A%0A%5Blink+text%5D<<<<< Body does not match
                                                           |
-----------------------------------------------------------------------------------------------------------------------
johnou commented 2 years ago

@mc1arke looks like a problem with charsets, I'll take a closer look.

johnou commented 2 years ago

@mc1arke this does the job https://github.com/johnou/sonarqube-community-branch-plugin/commit/9db30f63622533c5e2d342b0242487671e084402 unit tests now pass on Windows.

honzajscz commented 2 years ago

I have just tried to build the master branch (sha fbbc416) and the following tests fail. Can't that be connected with all the Azure DevOps-related problems? Thanks

image

AzureDevopsRestClientTest. checkAddCommentToThreadSubmitsCorrectContent() AzureDevopsRestClientTest. checkErrorThrownOnNonSuccessResponseStatus() AzureDevopsRestClientTest. checkSubmitPullRequestStatusSubmitsCorrectContent() GitlabRestClientTest. checkCorrectEncodingUsedOnMergeRequestDiscussion() GitlabRestClientTest. checkErrorThrownOnNonSuccessResponseStatus()

I built on Windows 11. Here is the complete test HTML log

mc1arke commented 2 years ago

What version of Java are you building on @honzajscz?

honzajscz commented 2 years ago

openjdk version "17.0.1" 2021-10-19 OpenJDK Runtime Environment (build 17.0.1+12-39) OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)

mc1arke commented 2 years ago

You need to be using Java 11. Sonarqube only support Java 11 for server-side components so the plugin is tested and built using Java 11.

mc1arke commented 2 years ago

Released in 1.11.0