From 0e06d65651c386f0bab4455f1aad22e7e649e4c8 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Tue, 9 Apr 2024 21:22:03 +0200 Subject: [PATCH] adjust method name to avoid conflict with old implementations --- core/src/main/java/hudson/model/AbstractProject.java | 5 ----- core/src/main/java/jenkins/model/Jenkins.java | 9 +++++---- test/src/test/java/jenkins/model/JenkinsTest.java | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 2681d5274378..cceff9c42b19 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1940,11 +1940,6 @@ public boolean isApplicable(Descriptor descriptor) { return true; } - @Restricted(DoNotUse.class) - public FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { - return Jenkins.get().doCheckDisplayName(value, project); - } - @Restricted(DoNotUse.class) public FormValidation doCheckAssignedLabelString(@AncestorInPath AbstractProject project, @QueryParameter String value) { diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index d2c79cd3365f..0808d2e7ce7f 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -5276,7 +5276,7 @@ public View getStaplerFallback() { */ boolean isDisplayNameUnique(ItemGroup itemGroup, String displayName, String currentJobName) { - Collection itemCollection = itemGroup.getAllItems(TopLevelItem.class); + Collection itemCollection = (Collection) itemGroup.getItems(t -> t instanceof TopLevelItem); // if there are a lot of projects, we'll have to store their // display names in a HashSet or something for a quick check @@ -5324,7 +5324,7 @@ else if (item.getName().equals(currentJobName)) { * @param displayName The display name to test * @param jobName The name of the job the user is configuring * - * @deprecated use {@link Jenkins#doCheckDisplayName(String, Item)} + * @deprecated use {@link TopLevelItemDescriptor#doCheckDisplayNameOrNull(TopLevelItem, String)} */ @Deprecated public FormValidation doCheckDisplayName(@QueryParameter String displayName, @@ -5350,8 +5350,9 @@ else if (!isDisplayNameUnique(this, displayName, jobName)) { * @param displayName The display name to test * @param item The item to check for duplicates */ - public FormValidation doCheckDisplayName(String displayName, - Item item) { + @Restricted(NoExternalUse.class) + public FormValidation checkDisplayName(String displayName, + TopLevelItem item) { displayName = displayName.trim(); String jobName = item.getName(); diff --git a/test/src/test/java/jenkins/model/JenkinsTest.java b/test/src/test/java/jenkins/model/JenkinsTest.java index 873969205407..c44b12cdd037 100644 --- a/test/src/test/java/jenkins/model/JenkinsTest.java +++ b/test/src/test/java/jenkins/model/JenkinsTest.java @@ -281,7 +281,7 @@ public void testDoCheckDisplayNameUnique() throws Exception { p.setDisplayName("displayName"); Jenkins jenkins = Jenkins.get(); - FormValidation v = jenkins.doCheckDisplayName("1displayName", curProject); + FormValidation v = jenkins.checkDisplayName("1displayName", curProject); assertEquals(FormValidation.ok(), v); } @@ -297,7 +297,7 @@ public void testDoCheckDisplayNameSameAsDisplayName() throws Exception { p.setDisplayName(displayName); Jenkins jenkins = Jenkins.get(); - FormValidation v = jenkins.doCheckDisplayName(displayName, curProject); + FormValidation v = jenkins.checkDisplayName(displayName, curProject); assertEquals(FormValidation.Kind.WARNING, v.kind); } @@ -313,7 +313,7 @@ public void testDoCheckDisplayNameSameAsJobName() throws Exception { p.setDisplayName(displayName); Jenkins jenkins = Jenkins.get(); - FormValidation v = jenkins.doCheckDisplayName(jobName, curProject); + FormValidation v = jenkins.checkDisplayName(jobName, curProject); assertEquals(FormValidation.Kind.WARNING, v.kind); }