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

[FIXED JENKINS-44898] Add findResource to PluginFirstClassLoader #2916

Merged
merged 3 commits into from
Jun 17, 2017

Conversation

abayer
Copy link
Member

@abayer abayer commented Jun 14, 2017

Description

See JENKINS-44898.

Details: This fixes GroovyClassLoader.loadClass for a .groovy file in a plugin with a PluginFirstClassLoader, specifically by fixing fast-loading via the UberClassLoader.

Still need to figure out the right way to do a test for this - I have verified that the issue described in jenkinsci/kubernetes-plugin#127 doesn't occur with this PR but the PluginFirstClassLoader expected behavior is still good.

Changelog entries

Proposed changelog entries:

  • Entry 1: JENKINS-44898, Add findResource for PluginFirstClassLoader.

Submitter checklist

  • JIRA issue is well described
  • Link to JIRA ticket in description, if appropriate
  • Appropriate autotests or explanation to why this change has no tests
  • For new API and extension points: Link to the reference implementation in open-source (or example in Javadoc)

Desired reviewers

@reviewbybees

This fixes GroovyClassLoader.loadClass for a .groovy file in a plugin
with a PluginFirstClassLoader, specifically by fixing fast-loading via
the UberClassLoader.
@abayer abayer requested a review from jglick June 14, 2017 17:14
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Needs test coverage.


try {
Field $pathComponents = AntClassLoader.class.getDeclaredField("pathComponents");
$pathComponents.setAccessible(true);
Copy link
Member

Choose a reason for hiding this comment

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

Seems like you need to introduce a common ancestor with AntClassLoader2 to avoid code duplication.

Copy link
Member

Choose a reason for hiding this comment

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

(Or we should just stop using AntClassLoader at all. I am not sure why we ever did.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm generally mystified but wanted to go with the least-disruptive-change-possible in case there was some legitimate reason somewhere for it. I'll add a common ancestor.

@abayer
Copy link
Member Author

abayer commented Jun 14, 2017

@jglick Any suggestions/thoughts/ideas on how to get said test coverage? I definitely agree, I just can't figure out what the right way to do that would be.

@ghost
Copy link

ghost commented Jun 14, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@jglick
Copy link
Member

jglick commented Jun 14, 2017

I just can't figure out what the right way to do that would be.

There are some tests which install plugins from test/src/test/resources/plugins/. PluginManagerTest at least. So you should be able to make a tiny plugin just containing a resource but using plugin-first class loading, install it, get its ClassLoader, and call getResource.

* As of 1.8.0, {@link org.apache.tools.ant.AntClassLoader} doesn't implement {@link #findResource(String)}
* in any meaningful way, which breaks fast lookup. Implement it properly.
*/
public class AntWithFindResourceClassLoader extends AntClassLoader implements Closeable {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer @Restricted(NoExternalUse.class). Or just move into hudson package and leave it as default access.

private final class AntClassLoader2 extends AntClassLoader implements Closeable {
private final Vector pathComponents;

private final class AntClassLoader2 extends AntWithFindResourceClassLoader implements Closeable {
Copy link
Member

Choose a reason for hiding this comment

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

implements Closeable redundant

@@ -42,10 +42,14 @@
* @since 1.371
*/
public class PluginFirstClassLoader
extends AntClassLoader
extends AntWithFindResourceClassLoader
implements Closeable
Copy link
Member

Choose a reason for hiding this comment

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

implements Closeable redundant

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

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

🐝 and @reviewbybees done

@oleg-nenashev
Copy link
Member

@abayer @daniel-beck I propose the following changelog entry:

@daniel-beck Maybe you've already moved this page to jenkins.io

@oleg-nenashev oleg-nenashev added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Jun 17, 2017
@jglick
Copy link
Member

jglick commented Jun 17, 2017

Well the bug is generic and could have broader effects but OK.

@oleg-nenashev oleg-nenashev merged commit 303a9f7 into jenkinsci:master Jun 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants