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

[MNG-7160] Ability to customize core extensions classloaders #616

Merged
merged 5 commits into from Jun 15, 2022

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Nov 22, 2021

JIRA issue: https://issues.apache.org/jira/browse/MNG-7160

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace MNG-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Copy link
Member

@cstamas cstamas left a comment

Choose a reason for hiding this comment

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

To me this change looks kinda okay, but also not okay, here is why:

  • before change it was delegated, but as core extension realm has no imports applied to it (!), it really has no effect is it "base" realm (parent class-loader in java lingo, no filtering) or "parent" realm (delegates via strategy, filtering applies if set).
  • but CoreExports (and corresponding XML file) seems was never applied/used in core extension realm?

This looks something either I am missing, or is simply missing?

@gnodet
Copy link
Contributor Author

gnodet commented Nov 22, 2021

To me this change looks kinda okay, but also not okay, here is why:

  • before change it was delegated, but as core extension realm has no imports applied to it (!), it really has no effect is it "base" realm (parent classload in java lingo) or "parent" realm.

Not really, when no imports are specified for the parent realm, the realm has full visibility on its parent.

  • but CoreExports (and corresponding XML file) seems was never applied/used in core extension realm?

The xml extension is not used, that's right.

This looks something either I am missing, or is simply missing?

Yes, what this commit does is to simply change from self-first to parent-first class loading, that's all. This avoids the ClassCastException because there will be a single Xpp3Dom class loaded.

If this change is not acceptable for compatibility reason, one possibility would be to extend the extension model to be able to specify self-first or parent-first strategy as an xml attribute on the extension.

@cstamas
Copy link
Member

cstamas commented Nov 22, 2021

This makes sense to me, just to repeat: core extension (had) have "unfiltered" access to maven being extended, along with all the classes being present in maven-core realm. Essentially, this is the case even today (no CoreExports applied), but due SelfFirst strategy CCEx happend? And after this change will not.

@gnodet
Copy link
Contributor Author

gnodet commented Nov 22, 2021

This makes sense to me, just to repeat: core extension (had) have "unfiltered" access to maven being extended, along with all the classes being present in maven-core realm. Essentially, this is the case even today (no CoreExports applied), but due SelfFirst strategy CCEx happend? And after this change will not.

Yes, that's it.

@rmannibucau
Copy link
Contributor

Change looks good to me but can be great to test some more real world extensions (the ones I tested don't abuse of dependencies enough).

Copy link
Contributor

@jvanzyl jvanzyl left a comment

Choose a reason for hiding this comment

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

Where are the projects you're testing that demonstrate the Xpp3Dom loading issue? For any extensions I've made that used core dependencies I've marked as provided and I don't have any issues. But in your case you are not marking them as provided and this is when you see the CCE? That's why I just wanted to look at your setup, as it seems like it's the same thing being done in Provisio where there's no issue with 3.x.

@gnodet
Copy link
Contributor Author

gnodet commented Nov 22, 2021

Where are the projects you're testing that demonstrate the Xpp3Dom loading issue? For any extensions I've made that used core dependencies I've marked as provided and I don't have any issues. But in your case you are not marking them as provided and this is when you see the CCE? That's why I just wanted to look at your setup, as it seems like it's the same thing being done in Provisio where there's no issue with 3.x.

Ah, I think the problem comes from the way the extension's artifacts are resolved. When I put the plexus-utils in scope provided, this is not sufficient and I also have to explicitly exclude it from transitive dependencies to get it working.

@jvanzyl
Copy link
Contributor

jvanzyl commented Nov 22, 2021

Using the assembly plugin?

@gnodet
Copy link
Contributor Author

gnodet commented Nov 22, 2021

@gnodet gnodet force-pushed the mng-7160 branch 2 times, most recently from 5bb43e2 to 1c6e732 Compare November 23, 2021 14:08
@gnodet
Copy link
Contributor Author

gnodet commented Nov 23, 2021

I've rewritten the PR to allow the user to choose the class loading strategy and added an integration test (apache/maven-integration-testing#125) showing the 4 possibilities and the differences in class loading.

I'm not sure if the fact that even when a dependency with an explicit provided scope is defined, the same dependency leaks through as a transitive dependency is a problem or not. Thoughts ?

@jvanzyl
Copy link
Contributor

jvanzyl commented Nov 23, 2021

I know you've gone through the effort here to get the caching extension to work from lib/ext but is that how you envision it working? If you have a large organization with many developers I think it would be preferable to configure it from the POM no? Or does this extension do some capabilities earlier than an extension in the form of a plugin?

I realize the way extensions in lib/ext versus being defined in a plugin have always worked differently, and I can't off the the top of my head remember why we did that, but maybe they should be aligned so that artifacts are resolved in the same way.

@gnodet
Copy link
Contributor Author

gnodet commented Nov 23, 2021

I know you've gone through the effort here to get the caching extension to work from lib/ext but is that how you envision it working? If you have a large organization with many developers I think it would be preferable to configure it from the POM no? Or does this extension do some capabilities earlier than an extension in the form of a plugin?

I realize the way extensions in lib/ext versus being defined in a plugin have always worked differently, and I can't off the the top of my head remember why we did that, but maybe they should be aligned so that artifacts are resolved in the same way.

Currently, they do not work exactly the same. Some beans are discovered a bit too early in the process. For example EventSpy implementations can't be registered inside an extension discovered from the POM afaik. This is also true for a few other beans.

The new plugin class loading strategy that I propose aims at reconciling the class loaders difference. I also plan to raise a PR so that some beans are discovered later in the process inside the @SessionScoped, such as MojoExecutor and related beans. This would allow the caching extension from #607 to be registered in the POM, which is not currently possible.

@gnodet
Copy link
Contributor Author

gnodet commented Nov 24, 2021

This would allow the caching extension from #607 to be registered in the POM, which is not currently possible.

Registering the extension in the POM is also blocked by #618 and the ability to use org.eclipse.sisu.Priority.

@gnodet gnodet changed the title [MNG-7160] Fix core extension classloader [MNG-7160] Ability to customize core extensions classloaders Nov 25, 2021
@gnodet gnodet requested a review from michael-o December 3, 2021 10:14
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

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

If this is going into 3.9.0, make sure to adjust the IT too.

@gnodet gnodet merged commit 415eaf3 into apache:master Jun 15, 2022
oehme added a commit to oehme/maven-mvnd that referenced this pull request Jan 5, 2023
Since apache/maven#616, the default
CoreExportProvider no longer uses the provided CoreExports,
but instead tries (and fails) to discover them itself.

This change fixes that by providing our own custom instance
of CoreExportProvider. This allows core extension to contribute
exported artifacts and exported packages again, like it used to
do before the Maven 4.x upgrade.
gnodet pushed a commit to apache/maven-mvnd that referenced this pull request Jan 17, 2023
* Fix core export provider

Since apache/maven#616, the default
CoreExportProvider no longer uses the provided CoreExports,
but instead tries (and fails) to discover them itself.

This change fixes that by providing our own custom instance
of CoreExportProvider. This allows core extension to contribute
exported artifacts and exported packages again, like it used to
do before the Maven 4.x upgrade.

* Add integration tests for API-providing extensions
famod pushed a commit to famod/maven that referenced this pull request Feb 14, 2023
@gnodet gnodet mentioned this pull request May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants