From 4dfe7b7ba21e2f989b859bcddd173cd9a0c019b6 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 | 2 +- core/src/main/java/jenkins/model/Jenkins.java | 9 +++++---- test/src/test/java/jenkins/model/JenkinsTest.java | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 2681d52743780..f00bd5af917ba 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1942,7 +1942,7 @@ public boolean isApplicable(Descriptor descriptor) { @Restricted(DoNotUse.class) public FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { - return Jenkins.get().doCheckDisplayName(value, project); + return Jenkins.get().checkDisplayName(value, project); } @Restricted(DoNotUse.class) diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index d2c79cd3365fc..0808d2e7ce7fe 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 8739692054076..c44b12cdd037b 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); }