Skip to content

Conversation

@dcendents
Copy link
Contributor

@dcendents dcendents commented Feb 10, 2022

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

Updated the plugin to use the jersey2-api and jackson2-api plugins instead of packaging its own version of jersey.

This PR requires a modification of gitlab4j-api and also jersey2-api
gitlab4j/gitlab4j-api#795
jenkinsci/jersey2-api-plugin#9

fixes #8

Once this PR is merged and released, we also need to release gitlab-branch-source-plugin with the following PR

jenkinsci/gitlab-branch-source-plugin#188

This will fix the following error I had if I installed the jersey2-api plugin in jenkins:

org.glassfish.jersey.internal.inject.InjectionManagerFactory
java.lang.ClassCastException: Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory
	at java.base/java.lang.Class.cast(Class.java:3605)
	at org.glassfish.jersey.internal.ServiceFinder$LazyObjectIterator.hasNext(ServiceFinder.java:690)
	at org.glassfish.jersey.internal.inject.Injections.lookupService(Injections.java:88)
	at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:73)
	at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:44)
	at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:412)
	at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317)
	at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:807)
	at org.glassfish.jersey.client.ClientRequest.getClientRuntime(ClientRequest.java:219)
	at org.glassfish.jersey.client.ClientRequest.getInjectionManager(ClientRequest.java:610)
	at org.glassfish.jersey.client.JerseyWebTarget.onBuilder(JerseyWebTarget.java:364)
	at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:192)
	at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:36)
	at org.gitlab4j.api.GitLabApiClient.invocation(GitLabApiClient.java:783)
	at org.gitlab4j.api.GitLabApiClient.invocation(GitLabApiClient.java:748)
	at org.gitlab4j.api.GitLabApiClient.get(GitLabApiClient.java:399)
	at org.gitlab4j.api.GitLabApiClient.get(GitLabApiClient.java:387)
	at org.gitlab4j.api.AbstractApi.get(AbstractApi.java:213)
Caused: org.gitlab4j.api.GitLabApiException: Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory
	at org.gitlab4j.api.AbstractApi.handle(AbstractApi.java:655)
	at org.gitlab4j.api.AbstractApi.get(AbstractApi.java:215)
	at org.gitlab4j.api.RepositoryApi.getBranch(RepositoryApi.java:104)
	at io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource.retrieve(GitLabSCMSource.java:258)
	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:582)
	at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier$JobScheduledListener.lambda$onEnterWaiting$0(GitLabPipelineStatusNotifier.java:392)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

@jetersen
Copy link
Member

@dcendents you should be able to deploy snapshots to Jenkins's artifactory "repo.jenkins-ci.org"

@dcendents
Copy link
Contributor Author

dcendents commented Feb 11, 2022

@jetersen
Copy link
Member

Should be able to use them so Jenkins would pick them up

@mymarche
Copy link

I installed this versions on my Jenkins, and this works as expected.
@dcendents, Thank you!

@alexjfisher
Copy link

@dcendents Amazing! Thanks for looking at this. This should fix jenkinsci/gitlab-branch-source-plugin#151

Meanwhile... a version including gitlab4j/gitlab4j-api#806 is possibly needed much more urgently. all my gitlab builds have started failing in the last 24 hours. I'm going to be working on setting up my build environment today, to see if I can build my own snapshot plugins. But should you beat me to it, I sure there are loads of people out there who would be extremely grateful! :)

@dcendents
Copy link
Contributor Author

@alexjfisher here you go: https://repo.jenkins-ci.org/snapshots/io/jenkins/plugins/gitlab-api/1.0.7-SNAPSHOT/gitlab-api-1.0.7-20220302.133039-2.hpi

This includes gitlab4j-api with both PRs

Obviously I haven't had time to test it, but gitlab-branch-source-plugin does not seem to be affected by this change (no compilation error).

@alexjfisher
Copy link

@alexjfisher here you go: https://repo.jenkins-ci.org/snapshots/io/jenkins/plugins/gitlab-api/1.0.7-SNAPSHOT/gitlab-api-1.0.7-20220302.133039-2.hpi

This includes gitlab4j-api with both PRs

Obviously I haven't had time to test it, but gitlab-branch-source-plugin does not seem to be affected by this change (no compilation error).

Great! I'll test this shortly and let you know. Many thanks.

@dcendents
Copy link
Contributor Author

dcendents commented Mar 2, 2022

@jetersen
Copy link
Member

jetersen commented Mar 2, 2022

@dcendents Thanks for putting it together, looks like a good cleanup :)

@alexjfisher
Copy link

This just got a bit more complicated, so here are the plugins that need to be installed if you cannot wait for the official release:

Also if you have the gitlab-plugin installed, the updates on jersey2-apiandjackson2-api` will break it, so the following snapshot must be installed as well

Thanks for all of these. I'm currently updating jenkins itself. Was on 2.263.4 but soon found out I needed at least 2.289

@albertvveld
Copy link

I installed all of the plugins and got the following error (Jenkins 2.336)

java.lang.ClassCastException: class org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable cannot be cast to class org.glassfish.jersey.internal.spi.AutoDiscoverable (org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable is in unnamed module of loader jenkins.util.AntClassLoader @43bfbea3; org.glassfish.jersey.internal.spi.AutoDiscoverable is in unnamed module of loader jenkins.util.AntClassLoader @3db0f72b) at java.base/java.util.TreeMap.compare(TreeMap.java:1292) at java.base/java.util.TreeMap.put(TreeMap.java:536) at java.base/java.util.TreeSet.add(TreeSet.java:255) at java.base/java.util.AbstractCollection.addAll(AbstractCollection.java:352) at java.base/java.util.TreeSet.addAll(TreeSet.java:312) at org.glassfish.jersey.model.internal.CommonConfig.configureAutoDiscoverableProviders(CommonConfig.java:609) at org.glassfish.jersey.client.ClientConfig$State.configureForcedAutoDiscoverableProviders(ClientConfig.java:388) at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:441) at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:317) at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:820) at org.glassfish.jersey.client.ClientRequest.getClientRuntime(ClientRequest.java:176) at org.glassfish.jersey.client.ClientRequest.getInjectionManager(ClientRequest.java:567) at org.glassfish.jersey.client.JerseyWebTarget.onBuilder(JerseyWebTarget.java:371) at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:199) at org.glassfish.jersey.client.JerseyWebTarget.request(JerseyWebTarget.java:38) at org.gitlab4j.api.GitLabApiClient.invocation(GitLabApiClient.java:799) at org.gitlab4j.api.GitLabApiClient.invocation(GitLabApiClient.java:763) at org.gitlab4j.api.GitLabApiClient.get(GitLabApiClient.java:414) at org.gitlab4j.api.GitLabApiClient.get(GitLabApiClient.java:402) at org.gitlab4j.api.AbstractApi.get(AbstractApi.java:213) Caused: org.gitlab4j.api.GitLabApiException: class org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable cannot be cast to class org.glassfish.jersey.internal.spi.AutoDiscoverable

@dcendents
Copy link
Contributor Author

I installed all of the plugins and got the following error (Jenkins 2.336)

`java.lang.ClassCastException: class org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable cannot be cast to class org.glassfish.jersey.internal.spi.AutoDiscoverable (org.glassfish.jersey.jaxb.internal.JaxbAutoDiscoverable ...

Yes I got the same error because the jira plugin also has its own version of jersey. I deactivated it, we don't really need it. But the fix will be for jira to also use the jersey2-api plugin instead of packaging its own lib. So you need to hunt down which other plugins have jersey libs and deactivate them.

I submitted this PR because if I updated the gitlab-plugin from version 1.5.25 onwards it would install the jersey2-api plugin and I started having java.lang.ClassCastException: Cannot cast org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory to org.glassfish.jersey.internal.inject.InjectionManagerFactory

It seems all those plugins were ok when they all had their own private jersey libs, but since the introduction of jersey2-api no plugin can safely package jersey anymore.

I suspect this is because jersey seems to rely a lot on ClassLoader loader = Thread.currentThread().getContextClassLoader(); and jenkins does not like this:

https://github.com/eclipse-ee4j/jersey/search?p=1&q=getContextClassLoader

https://github.com/eclipse-ee4j/jersey/blob/7b6d2f84391f24310baae7d8e55e644703642826/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/MultiPartProperties.java#L151

https://www.jenkins.io/doc/developer/plugin-development/dependencies-and-class-loading/

@albertvveld
Copy link

Removed Jira plugin, it is working again thanks!

@callum-p
Copy link

callum-p commented Mar 9, 2022

Sorry to spam up this pull request but I just needed to thank @dcendents. That's resolved my issues that were causing some very inconvenient workarounds this past week.

@dcendents
Copy link
Contributor Author

quick update, my pull requests on jersey2-api and jackson2-api plugins have been merged and released. However the new version of gitlab4j-api modified all the java id fields from int to long.

So I also need to submit a PR to gitlab-branch-source-plugin to work with the updated lib.

I suspect everyone waiting for this PR also use the gitlab-branch-source-plugin (AFAIK it is the only plugin using the gitlab-api plugin).

@dcendents
Copy link
Contributor Author

@jetersen This is now ready with the following PR as well:

jenkinsci/gitlab-branch-source-plugin#188

@jetersen jetersen changed the title Draft: use jersey2 and jackson2 plugins use jersey2 and jackson2 plugins Apr 15, 2022
@jetersen
Copy link
Member

The bom has yet update the jersey-api plugin: jenkinsci/bom#1011

So the PR is not there yet

@jetersen
Copy link
Member

@dcendents if you want you could pin the version till the bom get sorted out.

@jetersen
Copy link
Member

Please go ahead and rebase with master thanks to @basil updating the POM

@basil
Copy link
Member

basil commented Apr 16, 2022

And after rebasing you should get an incremental build, which you can then reference in the other PR instead of a manually deployed snapshot.

@jetersen
Copy link
Member

went ahead and rebased 😅

pom.xml Outdated
Comment on lines 106 to 108
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

@dcendents any reason this was added?

Copy link
Member

Choose a reason for hiding this comment

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

I figured this out; it's because it's needed by jersey-apache-connector but jersey2-api declares it as optional.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Took a look at the dependency tree of org.gitlab4j:gitlab4j-api:5.0.1:

[INFO] +- org.gitlab4j:gitlab4j-api:jar:5.0.1:compile
[INFO] |  +- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] |  +- org.glassfish.jersey.inject:jersey-hk2:jar:2.35:compile
[INFO] |  |  +- org.glassfish.hk2:hk2-locator:jar:2.6.1:compile
[INFO] |  |  |  +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.6.1:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-api:jar:2.6.1:compile
[INFO] |  |  |  \- org.glassfish.hk2:hk2-utils:jar:2.6.1:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.25.0-GA:compile
[INFO] |  +- org.glassfish.jersey.connectors:jersey-apache-connector:jar:2.35:compile
[INFO] |  |  \- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] |  +- org.glassfish.jersey.media:jersey-media-multipart:jar:2.35:compile
[INFO] |  |  \- org.jvnet.mimepull:mimepull:jar:1.9.13:compile
[INFO] |  +- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.35:compile
[INFO] |  |  +- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.35:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.2:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.2:compile
[INFO] |  |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.12.2:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.12.2:compile
[INFO] |  |     \- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.2:compile
[INFO] |  +- jakarta.servlet:jakarta.servlet-api:jar:4.0.4:compile
[INFO] |  \- uk.org.webcompere:system-stubs-jupiter:jar:1.2.0:compile
[INFO] |     \- uk.org.webcompere:system-stubs-core:jar:1.2.0:compile

jakarta.activation:jakarta.activation-api should not be bundled in this plugin; rather, exclude it and depend on

    <dependency>
      <groupId>io.jenkins.plugins</groupId>
      <artifactId>javax-activation-api</artifactId>
      <version>1.2.0-2</version>
    </dependency>

uk.org.webcompere:system-stubs-jupiter and uk.org.webcompere:system-stubs-core look like mocking/test libraries. Probably an upstream issue that these are not in <scope>test</scope>, but in the meantime we should work around that by not bundling them in this Jenkins plugin.

jakarta.servlet:jakarta.servlet-api is provided by core and should be excluded.

Please also add comments for each exclusion explaining where the classes come from (core, a plugin, etc).

@jetersen
Copy link
Member

@basil thanks for digging into it, already created: gitlab4j/gitlab4j-api#840

Comment on lines +120 to +124
<!-- Needed by jersey-apache-connector, but jersey2-api plugin declares it as optional -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>apache-httpcomponents-client-4-api</artifactId>
</dependency>
Copy link
Member

@jetersen jetersen Apr 16, 2022

Choose a reason for hiding this comment

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

Should this be fixed in jersey2-api and make it non optional? again apache-httpcomponents-client-4-api is pretty much in all Jenkins installs anyhow.
@basil ?

Copy link
Member

Choose a reason for hiding this comment

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

We could. The downside is that someone who wants to use some other parts of Jersey 2 but doesn't need the Jersey Apache connector would be forced to install it. That might not be so bad, after all. I could go either way, don't feel strongly.

Copy link
Member

Choose a reason for hiding this comment

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

Me neither, I was simply wondering so 🤷‍♂️

@basil
Copy link
Member

basil commented Apr 16, 2022

Check this out, I ported gitlab-oauth-plugin to use this new library in jenkinsci/gitlab-oauth-plugin#66

If feasible (I have no way to test) that would be a huge boon for the maintainability of gitlab-oauth-plugin.

@jetersen
Copy link
Member

@basil
Copy link
Member

basil commented Apr 16, 2022

Yes, and I know I'm hijacking this thread but if I could have any volunteers to test the incremental from jenkinsci/gitlab-oauth-plugin#66 that would be super cool =)

https://repo.jenkins-ci.org/incrementals/org/jenkins-ci/plugins/gitlab-oauth/1.16-rc464.6b_256e1a_ef5c/

@jetersen jetersen changed the title use jersey2 and jackson2 plugins update gitlab4j and use jersey2 and jackson2 plugins Apr 16, 2022
@jetersen jetersen merged commit a3711d5 into jenkinsci:master Apr 18, 2022
@jetersen
Copy link
Member

@jetersen jetersen added the enhancement New feature or request label Apr 18, 2022
@dcendents
Copy link
Contributor Author

@basil @jetersen Sorry guys I was not available this weekend but I can see you did all the work.
Thanks a lot

@jetersen
Copy link
Member

@dcendents your welcome 😅

FYI I have created jenkinsci/jira-plugin#435

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants