-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
[JENKINS-26097] Adjust label expression auto-completion and validation #4774
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
Conversation
This moves label expression auto-completion and validation from AbstractProject to LabelExpression. Auto-Completion: - AbstractProject.AutoCompleteSeerder was moved to LabelExpression - test class correspondingly moved to the relevant package - added static LabelExpression.autoComplete() method - does what the non-static AbstractProject.doAutoCompleteLabel() used to do; that now calls the new static method Validation: - added LabelExpression.LabelValidator, which is like AbstractProject.LabelValidator except it takes a Job instead of an AbstractProject - AbstractProject.LabelValidator is now deprecated - added static LabelExpression.validate(String, Job) method, which replaces AbstractProject.validateLabelExpression(String, AbstractProject) - the latter is marked as deprecated and forwards to the former - LabelExpressionTest.formValidation() uses the new static method
jglick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable from a quick glance. (Blocks of code moved around makes it hard to read the diff.) Would make sense to consume this from workflow-durable-task-step-plugin so that snippet generator on the node step can offer the same conveniences that you get in a freestyle project’s config screen.
In addition, the new LabelValidators are now applied to AbstractProjects too.
jglick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would still recommend demonstrating usage in workflow-durable-task-step-plugin.
|
I merged current master so the build produces an incremental; will look at creating a PR on |
|
Looking at If there was a snippet generator for the |
|
I had missed |
|
Yes on |
|
I have changes in progress for that and the one other use of the old validation method (other than my own plugin), in |
|
Dropped my attempts to change |
|
|
OK, three plugins now have reference implementations of the changed API; main PR comment updated. Main open item from my end is whether or not I should move the i18n messages (to |
oleg-nenashev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good in principle, hence I am approving it.
At the same time it could be possible to enhance how API is provided and to simplify adoption of the API in the code
…leteSeeder. This also adds missing nullability annotations.
These are now under LabelExpression.xxx instead of AbstractProject.xxx. For the translations, properties were either renamed in-place or moved, depending on whether the file seemed to be sorted alphabetically by property name.
|
Suggestions applied; messages moved (no message changes, except that a stray trailing |
By default, this calls the regular check() if the item is an AbstractProject; otherwise, it returns OK. This allows a plugin to implement an override for that method in order to have its validator applied to Jobs too, without needing to bump their Jenkins dependency in order to get the new LabelValidator. As a result, LabelExpression.validate() now always uses the "old" LabelValidators, calling this new method.
core/src/main/java/hudson/model/labels/LabelAutoCompleteSeeder.java
Outdated
Show resolved
Hide resolved
Moved the test class over as well. This also makes the constructor and getSeeds() method of LabelAutoCompleteSeeder public.
oleg-nenashev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me after the patches, thanks a lot @Zastai !
jglick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting API surface reduction. Otherwise looks good.
core/src/main/java/jenkins/model/labels/LabelAutoCompleteSeeder.java
Outdated
Show resolved
Hide resolved
This avoids referring to a job (because the label validation can be
applied completely outside of any job context, like in tool installers)
or an assignment.
Also aligned terms ("is serviced by" -> "matches").
This still discards all OKs, but instead of stopping at and returning the first warning/error reported, all warnings/errors are returned as an aggregated result. The JavaDoc for the relevant messages was extended to describe this behaviour.
| if (!FormValidation.Kind.OK.equals(result.kind)) { | ||
| return result; | ||
| if (FormValidation.Kind.OK.equals(result.kind)) { | ||
| continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I think if
jenkins/core/src/main/java/hudson/util/FormValidation.java
Lines 227 to 238 in 339f9b9
| final StringBuilder sb = new StringBuilder("<ul style='list-style-type: none; padding-left: 0; margin: 0'>"); | |
| FormValidation.Kind worst = Kind.OK; | |
| for (FormValidation validation: validations) { | |
| sb.append("<li>").append(validation.renderHtml()).append("</li>"); | |
| if (validation.kind.ordinal() > worst.ordinal()) { | |
| worst = validation.kind; | |
| } | |
| } | |
| sb.append("</ul>"); | |
| return respond(worst, sb.toString()); |
FormValidation.OK in its input, then the API and this impl could be simplified a bit while actually handling ok(String) from validators. Not necessary in this PR, just something I noticed while looking at aggregate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I looked there too. But I'm not sure it would help to get bulleted list entries for "Label is valid" (assuming a validator might put that in the OK text) among the errors/warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right—aggregate would need to be made smarter, perhaps:
- if no arguments, or all
FormValidation.OK, returnFormValidation.OK - else consider all non-
FormValidation.OKarguments with the worst status among the bunch, and- if only one, return that as is
- else return a bulleted list of those messages
oleg-nenashev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks for the adjustments in the pull request!
We may merge it in 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process
See JENKINS-26097.
This moves label expression auto-completion and validation from
AbstractProjecttoLabelExpression.Auto-Completion:
AbstractProject.AutoCompleteSeederwas moved toLabelExpressionLabelExpression.autoComplete()methodAbstractProject.doAutoCompleteLabel()used to do; that now calls the new static methodValidation:
LabelExpression.LabelValidator, which is likeAbstractProject.LabelValidatorexcept it takes aJobinstead of anAbstractProjectAbstractProject.LabelValidatoris now deprecatedLabelExpression.validate(String, Job)method, which replacesAbstractProject.validateLabelExpression(String, AbstractProject)LabelExpressionTest.formValidation()uses the new static methodhudson.model.Messages.AbstractProject_xxx()tohudson.model.Messages.LabelExpression_xxx()).Proposed changelog entries
hudson.model.AbstractProject.LabelValidatoris now deprecated in favour ofjenkins.model.labels.LabelValidatorcheckItem()method to allow them to apply validation to non-Project items toohudson.model.AbstractProject.DescriptorImpl.validateLabelExpression()is now deprecated in favour ofLabelExpression.validate()(which takes any kind ofItemobject instead of onlyAbstractProjects)LabelValidators (old and new)LabelExpression.autoComplete()Proposed upgrade guidelines
N/A
Submitter checklist
Proposed changelog entriessection only if there are breaking changes or other changes which may require extra steps from users during the upgradeReference implementations:
Desired reviewers
@jglick
Maintainer checklist
Before the changes are marked as
ready-for-merge:Proposed changelog entriesare correctupgrade-guide-neededlabel is set and there is aProposed upgrade guidelinessection in the PR title. (example)lts-candidateto be considered (see query).