-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d7a89ae
JENKINS-26097: Adjust label expression auto-completion and validation.
Zastai 9cbd50a
Add auto-completion and validation for the label fields on tool insta…
Zastai ab7fa7d
Merge branch 'master' into JENKINS-26097
Zastai 14d1efb
Use TODO, not FIXME for @since.
Zastai bb89a72
Use Item as validation context for the new API (instead of Job).
Zastai 3fb2b66
Make LabelExpression.LabelValidator an interface.
Zastai 5519088
Fix a JavaDoc reference.
Zastai 0428cd8
Merge branch 'master' into JENKINS-26097
Zastai 9a65888
Move LabelValidator to the top level.
Zastai 7a3d722
Move LabelExpression.AutoCompleteSeeder to top level as LabelAutoComp…
Zastai 863eae5
Moved the i18n messages.
Zastai f0621c2
Add JavaDoc.
Zastai dc286c7
Add a checkItem() to the "old" LabelValidator.
Zastai d542a76
Merge branch 'master' into JENKINS-26097
Zastai df6c373
Move new classes to jenkins.model.labels.
Zastai 0712143
Merge branch 'master' into JENKINS-26097
Zastai 1a0aea1
Tweak messages.
Zastai 6cfba40
Aggregate label validation problems.
Zastai a94cb38
Flag LabelAutoCompleteSeeder as NoExternalUse.
Zastai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
59 changes: 59 additions & 0 deletions
59
core/src/main/java/jenkins/model/labels/LabelAutoCompleteSeeder.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package jenkins.model.labels; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Utility class for taking the current input value and computing a list of potential terms to match against the | ||
| * list of defined labels. | ||
| * | ||
| * @since TODO | ||
| */ | ||
Zastai marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class LabelAutoCompleteSeeder { | ||
|
|
||
| private final String source; | ||
|
|
||
| /** | ||
| * Creates a new auto-complete seeder for labels. | ||
| * | ||
| * @param source The (partial) label expression to use as the source.. | ||
| */ | ||
| public LabelAutoCompleteSeeder(@NonNull String source) { | ||
| this.source = source; | ||
| } | ||
|
|
||
| /** | ||
| * Gets a list of seeds for label auto-completion. | ||
| * | ||
| * @return A list of seeds for label auto-completion. | ||
| */ | ||
| @NonNull | ||
| public List<String> getSeeds() { | ||
| final ArrayList<String> terms = new ArrayList<>(); | ||
| boolean trailingQuote = source.endsWith("\""); | ||
| boolean leadingQuote = source.startsWith("\""); | ||
| boolean trailingSpace = source.endsWith(" "); | ||
| if (trailingQuote || (trailingSpace && !leadingQuote)) { | ||
| terms.add(""); | ||
| } else { | ||
| if (leadingQuote) { | ||
| int quote = source.lastIndexOf('"'); | ||
| if (quote == 0) { | ||
| terms.add(source.substring(1)); | ||
| } else { | ||
| terms.add(""); | ||
| } | ||
| } else { | ||
| int space = source.lastIndexOf(' '); | ||
| if (space > -1) { | ||
| terms.add(source.substring(space+1)); | ||
| } else { | ||
| terms.add(source); | ||
| } | ||
| } | ||
| } | ||
| return terms; | ||
| } | ||
|
|
||
| } | ||
27 changes: 27 additions & 0 deletions
27
core/src/main/java/jenkins/model/labels/LabelValidator.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package jenkins.model.labels; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import hudson.ExtensionPoint; | ||
| import hudson.model.Item; | ||
| import hudson.model.Label; | ||
| import hudson.util.FormValidation; | ||
|
|
||
| /** | ||
| * Plugins may want to contribute additional restrictions on the use of specific labels for specific context items. | ||
| * This extension point allows such restrictions. | ||
| * | ||
| * @since TODO | ||
| */ | ||
| public interface LabelValidator extends ExtensionPoint { | ||
|
|
||
| /** | ||
| * Validates the use of a label within a particular context. | ||
| * | ||
| * @param item The context item to be restricted by the label. | ||
| * @param label The label that the job wants to restrict itself to. | ||
| * @return The validation result. | ||
Zastai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| @NonNull | ||
| FormValidation check(@NonNull Item item, @NonNull Label label); | ||
|
|
||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.