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

PR Decoration not working on SonarQube 9.4 #569

Closed
juanrodicio opened this issue Apr 4, 2022 · 18 comments
Closed

PR Decoration not working on SonarQube 9.4 #569

juanrodicio opened this issue Apr 4, 2022 · 18 comments
Labels
awaiting release Merged but not currently in release version bug Something isn't working

Comments

@juanrodicio
Copy link

juanrodicio commented Apr 4, 2022

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

  • SonarQube Version: 9.4.0.54424

  • Plugin Version: 1.10.0

Thank you in advance.

@juanrodicio juanrodicio added the bug Something isn't working label Apr 4, 2022
@mc1arke
Copy link
Owner

mc1arke commented Apr 4, 2022

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
Copy link
Author

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

@mc1arke
Copy link
Owner

mc1arke commented Apr 4, 2022

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?

@mc1arke mc1arke added the question Further information is requested label Apr 4, 2022
@juanrodicio
Copy link
Author

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
Copy link
Owner

mc1arke commented Apr 4, 2022

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:

  • The issue you're reporting is that Sonarqube 9.4 starts ok with the plugin installed, but fails on the decoration stage
  • You can see the Pull Request analysis in the Sonarqube UI, but no decoration in your ALM

Given your latest comment, can you also confirm:

  • Which ALM you're using?
  • What configuration you've performed for setting up your ALM (now known as DevOps Platform Integration)?

@juanrodicio
Copy link
Author

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.

mc1arke added a commit that referenced this issue Apr 4, 2022
The latest release of Sonarqube switches from using Pico Container for
dependency injection to using Spring. The method used for detecting the
constructor to be used for injecting in a multi-constructor class varies
between the 2 frameworks, with Pico only looking for public constructors
but Spring looking for any visible constructor, and then excluding any
constructors that do not have the `@Autowired` annotation on a muti-
constructor class. This change adds the relevant annotation onto the two
classes impacted by this change in frameworks, thereby allowing for the
Compute Engine to have the appropriate components generated for
completing decoration of Pull Requests.
mc1arke added a commit that referenced this issue Apr 4, 2022
The latest release of Sonarqube switches from using Pico Container for
dependency injection to using Spring. The method used for detecting the
constructor to be used for injecting in a multi-constructor class varies
between the 2 frameworks, with Pico only looking for public constructors
but Spring looking for any visible constructor, and then excluding any
constructors that do not have the `@Autowired` annotation on a muti-
constructor class. This change adds the relevant annotation onto the two
classes impacted by this change in frameworks, thereby allowing for the
Compute Engine to have the appropriate components generated for
completing decoration of Pull Requests.
@mc1arke mc1arke added awaiting release Merged but not currently in release version and removed question Further information is requested labels Apr 4, 2022
@prokop7
Copy link

prokop7 commented Apr 7, 2022

Is there any release date?

@honzajscz
Copy link

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

@johnou
Copy link
Contributor

johnou commented Apr 13, 2022

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
Copy link
Owner

mc1arke commented Apr 13, 2022

@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
Copy link
Contributor

johnou commented Apr 13, 2022

@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
Copy link
Contributor

johnou commented Apr 13, 2022

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

@johnou
Copy link
Contributor

johnou commented Apr 13, 2022

@mc1arke this does the job johnou@9db30f6 unit tests now pass on Windows.

@honzajscz
Copy link

honzajscz commented Apr 16, 2022

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
Copy link
Owner

mc1arke commented Apr 16, 2022

What version of Java are you building on @honzajscz?

@honzajscz
Copy link

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
Copy link
Owner

mc1arke commented Apr 17, 2022

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
Copy link
Owner

mc1arke commented Apr 17, 2022

Released in 1.11.0

@mc1arke mc1arke closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release Merged but not currently in release version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants