Improvements for annotation framework use#9025
Open
headius wants to merge 3 commits intojruby:masterfrom
Open
Conversation
Member
Author
|
See headius/boing#2 for related work on the other side (the new "boing" library). |
This allows doing annotations like:
```
add_class_annotations(Entity => {name: "Employee"})
```
and similar for methods and parameters.
This change primarily moves the loading of command-line requires further into the "main" execution path, rather then running them on instantiation of Ruby before other state has been set up. When the command-line requires depend on other state set up by the main path, it may behave differently to require at the command line versus requiring in the first executed file. One example is that no thread context classloader will be set when these files run. Such a case was found working on a Spring Boot application. When the Spring classes were loaded and registered before the main script started, they would have a misconfigured SLF4J logger and fail to boot. Moving that logic into the main script fixed the issue, presumably because the early stages of Spring Boot's boot process depends on the context classloader. This moves the automatic load of command-line required files to the main path in the method `runFromMain`. A new `boot` method is added to include these pre-execution startup items. A new constructor method `newMain` is added for the main path to create a new runtime without immediately booting it, allowing for that to happen during main execution. The other forms of `newInstance` are modified to pre-boot the runtime, assuming it will immediately be used to execute code.
94090c9 to
0ea455e
Compare
The default behavior to create a new runtime would check if a global runtime had been intialized, and if not it called the newInstance method expecting that the result would be registered as the global runtime. With the changes in this PR we no longer do this automatic registration, so the code here is changed to use getGlobalRuntime methods that explicitly create and register the runtime. This exposes a risk in changing the global registration lifecycle for the newInstance methods: any code that expects the simple act of calling newInstance to register a global runtime will need to be updated to avoid that expectation, either capturing the runtime returned or calling getGlobalRuntime or useAsGlobalRuntime to ensure that the new runtime instance is registered. I don't expect there to be a lot of code calling these APIs directly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Working on some demo applications for a JRuby Spring Boot meta-framework, I've had to deal with some challenges and inconsistencies in how annotations are applied. This PR aims to address those so simplify annotation-heavy use of JRuby's class reification subsystem.
See https://github.com/headius/boing for some of these examples.
This allows doing annotations like:
and similar for methods and parameters.