Skip to content

Just get a classloader for the Mojo, no need for an actual instance - #140

Merged
vorburger merged 2 commits into
m2e-code-quality:developfrom
GEBIT:prevent-mojo-instantiation
Sep 22, 2018
Merged

vorburger merged 2 commits into
m2e-code-quality:developfrom
GEBIT:prevent-mojo-instantiation

Conversation

@erwint

@erwint erwint commented Sep 19, 2018

Copy link
Copy Markdown
Member

In big workspaces we noticed strange classloading errors in Eclipse, which result from Mojo instantiated for the ResourceResolver. As the Mojo instance is not needed at all (just it's classpath), we changed it to not actually create instances of the Mojo. Unfortunately, some internal m2e API is needed for this.

@vorburger

Copy link
Copy Markdown
Member

Unfortunately, some internal m2e API is needed for this.

@fbricon @mickaelistria perhaps you have any input into how (and whether) this can be avoided?

@mickaelistria

Copy link
Copy Markdown

Would mojo.getClass().getClassloader() return a classloader that could be used to get the classpath without requiring any m2e internal API?

@erwint

erwint commented Sep 19, 2018

Copy link
Copy Markdown
Member Author

no, there is no instance of the Mojo (that's the whole point)

@erwint
erwint force-pushed the prevent-mojo-instantiation branch from 29171cd to f5c68b1 Compare September 19, 2018 14:00
@erwint

erwint commented Sep 19, 2018

Copy link
Copy Markdown
Member Author

The "only" internal API needed is MavenImpl, to access the public method lookupComponent()

@mickaelistria

Copy link
Copy Markdown

I think you should first refine "in big workspaces we noticed strange classloading errors in Eclipse" with something reproducible to narrow down the root cause. What you're suggesting seems more like a workaround IMO, and the real bug is that mojo instantation to screw up resource loading.
I'd strongly discourage relying on non-API, the risk of being broken often is very high. It could be even better to just duplicate code, and it would be best to join m2e project and try to make this a regular sustainable API first.

@erwint

erwint commented Sep 19, 2018

Copy link
Copy Markdown
Member Author

In an ideal world you might be right. But:

As I wrote, the problem is not reproducible, but a huge PITA. We get it mostly during startup in large workspaces. It might be a bug in m2e or in the way the Mojo was instantiated here, but in the end the instance is not even needed here at all.

Honestly, turning to and waiting on m2e is no option: first of all, that would only work with they most recent version then. Also, our experience with getting someting into m2e is, eh, let's say "not ideal" (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=486737, which will soon have it's 3rd anniversary).

Other m2e plugins are using MavenImpl too (e.g. m2e-wtp), so IMHO the risk is not that high. Especially as there are bounds on the m2e version to use.

Also, I see no option to "duplicate code" here, as there is no other way to access the PlexusContainer that I can see.

@vorburger

Copy link
Copy Markdown
Member

I don't want to get in the middle of something where there may be some prior history 😸 but perhaps @erwint if you could at least open a new issue on M2E, and perhaps even raise a Gerrit there, with a proposal how to expose what API you would need to do this here "properly" to further discuss with @mickaelistria, more for the medium term, then perhaps for the short term this could already be merged here anyway?

@erwint

erwint commented Sep 19, 2018

Copy link
Copy Markdown
Member Author

I added https://bugs.eclipse.org/bugs/show_bug.cgi?id=539248 for m2e to provide an API

@erwint

erwint commented Sep 20, 2018

Copy link
Copy Markdown
Member Author

A gerrit change for m2e is now also provided: https://git.eclipse.org/r/#/c/129717/

@erwint

erwint commented Sep 21, 2018

Copy link
Copy Markdown
Member Author

Change in m2e has been merged, but will be available with 1.10 only. I suggest merging this PR and as soon as we require 1.10 (might be some while) to update it to the API in IMaven

@vorburger

vorburger commented Sep 22, 2018 via email

Copy link
Copy Markdown
Member

@vorburger
vorburger merged commit cef7514 into m2e-code-quality:develop Sep 22, 2018
@vorburger vorburger mentioned this pull request Sep 22, 2018
@erwint
erwint deleted the prevent-mojo-instantiation branch September 22, 2018 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants