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

Fixes #12900 - JPMS and environments. #12910

Merged
merged 7 commits into from
Mar 18, 2025

Conversation

sbordet
Copy link
Contributor

@sbordet sbordet commented Mar 14, 2025

  • Environments are now built using a ModuleLayer, that contains all the jars related to that environment.
  • Introduced websocket-core-[client|server].mod to avoid that the WebSocket core jars will be present in both the server ModuleLayer and the environment ModuleLayer, causing JPMS errors.
  • Now server.mod specifies --add-modules ALL-DEFAULT,ALL-MODULE-PATH. ALL-DEFAULT is necessary to expose JDK modules to the environment ModuleLayer. ALL-MODULE-PATH was previously hardcoded in the code, now it's externalized.
  • Removed most of the [jpms] directives in *.mod files, as they are either covered by ALL-DEFAULT, or not necessary.
  • EnvironmentBuilder now uses the ModuleLayer APIs to create an environment ModuleLayer child of the server ModuleLayer (the latter created by the JVM at startup, containing all the server/core jars).

* Environments are now built using a ModuleLayer, that contains all the jars related to that environment.
* Introduced websocket-core-[client|server].mod to avoid that the WebSocket core jars will be present in both the server ModuleLayer and the environment ModuleLayer, causing JPMS errors.
* Now server.mod specifies --add-modules ALL-DEFAULT,ALL-MODULE-PATH.
  ALL-DEFAULT is necessary to expose JDK modules to the environment ModuleLayer.
  ALL-MODULE-PATH was previously hardcoded in the code, now it's externalized.
* Removed most of the [jpms] directives in *.mod files, as they are either covered by ALL-DEFAULT, or not necessary.
* EnvironmentBuilder now uses the ModuleLayer APIs to create an environment ModuleLayer child of the server ModuleLayer (the latter created by the JVM at startup, containing all the server/core jars).

Signed-off-by: Simone Bordet <[email protected]>
…leLayers hierarchy to get the module-path of each layer, as well as navigate the ClassLoader hierarchy.

Removed now unnecessary part that was splitting system property "jdk.module.path".

Signed-off-by: Simone Bordet <[email protected]>
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Just a few niggles

Comment on lines 1917 to 1919
environment = Environment.get(envName);
if (environment == null)
envBuilder = new EnvironmentBuilder(envName);
Copy link
Contributor

Choose a reason for hiding this comment

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

This code will work so that an already known environment will switch subsequent args back to acting on the main environment. I don't think we want that. Maybe throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understand?
An already known environment will be retrieved by Environment.get but it will have that given name, so it would act on that environment, not the "main" environment (not sure what you refer to here by "main": you mean the current environment, or the core (i.e. not eeN) environment?).

A command line --env ee10 --add-modules foo --env ee11 --add-modules bar --env ee10 --add-modules baz would be badly formatted, I don't think we want to support that.

Copy link
Contributor

@gregw gregw Mar 17, 2025

Choose a reason for hiding this comment

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

Exactly. We should throw. Currently the second --env ee10 will reset the environment builder to null and then continue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the second --env ee10 will reset the environment bullet to null and then continue.

Yes. And if a --add-modules (or the others explicitly mentioned in the cases) is specified, it will throw NPE.
Otherwise, if it's an XML or properties file, will be applied to the right environment.

Seems to me we already do the right thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope. There are paths through that don't throw. Just throw if an environment is already defined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gregw I have added a test case, and are now throwing if the environment already exists.

@sbordet sbordet requested a review from gregw March 16, 2025 21:32
Signed-off-by: Simone Bordet <[email protected]>
Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet requested a review from lorban March 17, 2025 17:16
gregw
gregw previously approved these changes Mar 17, 2025
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

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

Lgtm

lorban
lorban previously approved these changes Mar 17, 2025
@sbordet sbordet dismissed stale reviews from lorban and gregw via c79a951 March 17, 2025 21:51
Copy link
Contributor

@joakime joakime left a comment

Choose a reason for hiding this comment

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

The build failure is a network failure with nexus on JDK23.
I'm ok with this PR as it stands.
Merge it.

@sbordet sbordet merged commit ec3870a into jetty-12.0.x Mar 18, 2025
7 of 9 checks passed
@sbordet sbordet deleted the fix/jetty-12.0.x/12900/jpms-environments branch March 18, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants