Register OptionHandler
s through META-INF/services/annotations
and Annotation Indexer rather than META-INF/services
and Commons Discovery
#9980
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.
CLICommand
has two mechanisms for registeringOptionHandler
s:jenkins/core/src/main/java/hudson/cli/CLICommand.java
Lines 530 to 542 in ab2ae8b
@OptionHandlerExtension
annotation) and load the handlers.jenkins/core/src/main/java/hudson/cli/CLICommand.java
Lines 564 to 582 in 6d17999
@MetaInfServices(OptionHandler.class)
annotation) the handlers and Commons Discovery to load the handlers.There is a desire to reduce and eventually remove usages of Commons Discovery, since it is an abandoned and unmaintained library. The second of these two code paths cannot be replaced with
ServiceLoader
, sinceServiceLoader
insists on having a zero-argument public constructor for each service, andOptionHandler
violates this contract. So if getting rid of Commons Discovery is desired, then the second code path must be deprecated in favor of the first. Once all usages of the second code path in core and plugins have been converted to the first code path, and once those releases have been sufficiently deployed, then the second code path can be deleted.This PR migrates from the second pattern to the first pattern in Jenkins core. I am aware of two cases where the second pattern is used in plugins:
I am not aware of any usages in proprietary plugins.
Implementation
The second code path was being invoked at class loading time (a single time) and loading the bulk of the handlers in practice there. The first code path was being invoked when each CLI command was invoked, which was simultaneously too frequent (a handler only needs to be registered once) and too late:
HelpCommandTest
started failing because we could not show the help until the handler had been loaded, and the handler was not loaded until the command was first invoked. We solved the latter problem by unifying the invocation of these two code paths from the same place: initialization of the class. In practice, this means that the existing handlers are loaded after this PR at the same time (and frequency) as they were before this PR, minimizing regressions and increasing consistency.Testing done
mvn clean verify -Dtest=hudson.cli.AddJobToViewCommandTest,hudson.cli.BuildCommandTest,hudson.cli.CancelQuietDownCommandTest,hudson.cli.ClearQueueCommandTest,hudson.cli.ComputerStateTest,hudson.cli.ConnectNodeCommandTest,hudson.cli.ConsoleCommandTest,hudson.cli.CopyJobCommandTest,hudson.cli.CreateJobCommandTest,hudson.cli.CreateNodeCommandTest,hudson.cli.CreateViewCommandTest,hudson.cli.DeleteBuildsCommandTest,hudson.cli.DeleteJobCommandTest,hudson.cli.DeleteNodeCommandTest,hudson.cli.DeleteViewCommandTest,hudson.cli.DisablePluginCommandTest,hudson.cli.DisconnectNodeCommandTest,hudson.cli.EnableJobCommandTest,hudson.cli.EnablePluginCommandTest,hudson.cli.GetJobCommandTest,hudson.cli.GetNodeCommandTest,hudson.cli.GetViewCommandTest,hudson.cli.GroovyshCommandTest,hudson.cli.HelpCommandTest,hudson.cli.InstallPluginCommandTest,hudson.cli.ListJobsCommandTest,hudson.cli.ListPluginsCommandTest,hudson.cli.OfflineNodeCommandTest,hudson.cli.OnlineNodeCommandTest,hudson.cli.QuietDownCommandTest,hudson.cli.ReloadConfigurationCommandTest,hudson.cli.ReloadJobCommandTest,hudson.cli.RemoveJobFromViewCommandTest,hudson.cli.RunRangeCommand2Test,hudson.cli.RunRangeCommandTest,hudson.cli.SetBuildDescriptionCommandTest,hudson.cli.SetBuildDisplayNameCommandTest,hudson.cli.UpdateNodeCommandTest,hudson.cli.UpdateViewCommandTest,hudson.cli.ViewManipulationTestBase,hudson.cli.WaitNodeOfflineCommandTest,hudson.cli.WaitNodeOnlineCommandTest,hudson.model.ComputerSetTest,hudson.model.ItemsTest,hudson.model.listeners.ItemListenerTest,hudson.util.RobustReflectionConverterTest,jenkins.cli.StopBuildsCommandTest,jenkins.model.JenkinsManagePermissionTest,jenkins.model.NodeListenerTest,jenkins.model.RunIdMigratorTest,jenkins.model.ScriptListenerTest,jenkins.security.Security3314Test,jenkins.security.Security3448Test,lib.form.PasswordTest
Proposed changelog entries
N/A
Proposed upgrade guidelines
N/A
Submitter checklist
Desired reviewers
@mention
Before the changes are marked as
ready-for-merge
:Maintainer checklist