From 3086fe44e56584d022500663f803a350bb4db386 Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Tue, 9 Apr 2024 23:25:26 +0800 Subject: [PATCH 1/9] [JENKINS-69916]: adding doCheckDisplayNameOrNull to Jenkins core --- .../java/jenkins/plugins/DetachedPluginsUtil.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java index 847180257c13..8e3644ee84a6 100644 --- a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java +++ b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java @@ -4,6 +4,8 @@ import edu.umd.cs.findbugs.annotations.NonNull; import hudson.ClassicPluginStrategy; import hudson.PluginWrapper; +import hudson.model.AbstractProject; +import hudson.util.FormValidation; import hudson.util.VersionNumber; import java.io.IOException; import java.io.InputStream; @@ -15,9 +17,13 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; + +import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.AncestorInPath; +import org.kohsuke.stapler.QueryParameter; /** * Dedicated class to handle the logic related to so-called detached plugins. @@ -206,4 +212,9 @@ public String toString() { return shortName + " " + splitWhen.toString().replace(".*", "") + " " + requiredVersion; } } + + @Restricted(NoExternalUse.class) + public static FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { + return Jenkins.get().doCheckDisplayName(value, project.getName()); + } } From 18c0224a5e2c63438b01c146316a058dc85c4bfc Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Tue, 9 Apr 2024 23:29:05 +0800 Subject: [PATCH 2/9] fix: spotless patch --- core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java index 8e3644ee84a6..4001c8fffe69 100644 --- a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java +++ b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java @@ -17,7 +17,6 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; - import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.kohsuke.accmod.Restricted; From 64fa70d43133382899385fecbbbe7cbefcfac53e Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 01:10:50 +0800 Subject: [PATCH 3/9] fix: move code to its proper place in Job.java --- core/src/main/java/hudson/model/Job.java | 25 ++++++------------- .../jenkins/plugins/DetachedPluginsUtil.java | 9 ------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 8c4e3183100a..430a734eb183 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -53,19 +53,7 @@ import hudson.search.SearchItems; import hudson.security.ACL; import hudson.tasks.LogRotator; -import hudson.util.AlternativeUiTextProvider; -import hudson.util.ChartUtil; -import hudson.util.ColorPalette; -import hudson.util.CopyOnWriteList; -import hudson.util.DataSetBuilder; -import hudson.util.DescribableList; -import hudson.util.FormApply; -import hudson.util.Graph; -import hudson.util.ProcessTree; -import hudson.util.RunList; -import hudson.util.ShiftedCategoryAxis; -import hudson.util.StackedAreaRenderer2; -import hudson.util.TextFile; +import hudson.util.*; import hudson.widgets.HistoryWidget; import hudson.widgets.HistoryWidget.Adapter; import hudson.widgets.Widget; @@ -120,15 +108,13 @@ import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.stapler.StaplerOverridable; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.*; import org.kohsuke.stapler.export.Exported; import org.kohsuke.stapler.interceptor.RequirePOST; import org.kohsuke.stapler.verb.POST; /** - * A job is an runnable entity under the monitoring of Hudson. + * A job is a runnable entity under the monitoring of Hudson. * *

* Every time it "runs", it will be recorded as a {@link Run} object. @@ -1618,4 +1604,9 @@ public BuildTimelineWidget getTimeline() { } private static final HexStringConfidentialKey SERVER_COOKIE = new HexStringConfidentialKey(Job.class, "serverCookie", 16); + + @Restricted(NoExternalUse.class) + public static FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { + return Jenkins.get().doCheckDisplayName(value, project.getName()); + } } diff --git a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java index 4001c8fffe69..68ee4480a611 100644 --- a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java +++ b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java @@ -4,8 +4,6 @@ import edu.umd.cs.findbugs.annotations.NonNull; import hudson.ClassicPluginStrategy; import hudson.PluginWrapper; -import hudson.model.AbstractProject; -import hudson.util.FormValidation; import hudson.util.VersionNumber; import java.io.IOException; import java.io.InputStream; @@ -21,8 +19,6 @@ import org.apache.commons.io.IOUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; -import org.kohsuke.stapler.AncestorInPath; -import org.kohsuke.stapler.QueryParameter; /** * Dedicated class to handle the logic related to so-called detached plugins. @@ -211,9 +207,4 @@ public String toString() { return shortName + " " + splitWhen.toString().replace(".*", "") + " " + requiredVersion; } } - - @Restricted(NoExternalUse.class) - public static FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { - return Jenkins.get().doCheckDisplayName(value, project.getName()); - } } From 8bd0dddf2cdb1c3154b109835dce676f897bb893 Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 01:17:25 +0800 Subject: [PATCH 4/9] fix: move doCheckDisplayNameOrNull code to TopLevelItemDescriptor.java --- core/src/main/java/hudson/model/Job.java | 5 ----- .../java/hudson/model/TopLevelItemDescriptor.java | 12 ++++++++---- .../java/jenkins/plugins/DetachedPluginsUtil.java | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 430a734eb183..1a10bc900364 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -1604,9 +1604,4 @@ public BuildTimelineWidget getTimeline() { } private static final HexStringConfidentialKey SERVER_COOKIE = new HexStringConfidentialKey(Job.class, "serverCookie", 16); - - @Restricted(NoExternalUse.class) - public static FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { - return Jenkins.get().doCheckDisplayName(value, project.getName()); - } } diff --git a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java index 16aa01807ff8..8afd739f68c9 100644 --- a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java +++ b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java @@ -27,6 +27,7 @@ import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.ExtensionList; +import hudson.util.FormValidation; import java.io.StringWriter; import java.util.logging.Level; import java.util.logging.Logger; @@ -37,10 +38,9 @@ import org.jenkins.ui.icon.Icon; import org.jenkins.ui.icon.IconSet; import org.jenkins.ui.icon.IconSpec; -import org.kohsuke.stapler.MetaClass; -import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; -import org.kohsuke.stapler.WebApp; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.*; import org.kohsuke.stapler.jelly.DefaultScriptInvoker; import org.kohsuke.stapler.jelly.JellyClassTearOff; import org.springframework.security.access.AccessDeniedException; @@ -286,4 +286,8 @@ public static ExtensionList all() { return Items.all(); } + @Restricted(NoExternalUse.class) + public static FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { + return Jenkins.get().doCheckDisplayName(value, project.getName()); + } } diff --git a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java index 68ee4480a611..847180257c13 100644 --- a/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java +++ b/core/src/main/java/jenkins/plugins/DetachedPluginsUtil.java @@ -15,7 +15,6 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; -import jenkins.model.Jenkins; import org.apache.commons.io.IOUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; From 9988fe6d6d2eeb4b040ec6a057bba0820e4198e7 Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 01:25:43 +0800 Subject: [PATCH 5/9] apply suggestions from code review --- core/src/main/java/hudson/model/Job.java | 18 ++++++++++++++++-- .../hudson/model/TopLevelItemDescriptor.java | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 1a10bc900364..548aced2f0f8 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -53,7 +53,19 @@ import hudson.search.SearchItems; import hudson.security.ACL; import hudson.tasks.LogRotator; -import hudson.util.*; +import hudson.util.AlternativeUiTextProvider; +import hudson.util.ChartUtil; +import hudson.util.ColorPalette; +import hudson.util.CopyOnWriteList; +import hudson.util.DataSetBuilder; +import hudson.util.DescribableList; +import hudson.util.FormApply; +import hudson.util.Graph; +import hudson.util.ProcessTree; +import hudson.util.RunList; +import hudson.util.ShiftedCategoryAxis; +import hudson.util.StackedAreaRenderer2; +import hudson.util.TextFile; import hudson.widgets.HistoryWidget; import hudson.widgets.HistoryWidget.Adapter; import hudson.widgets.Widget; @@ -108,7 +120,9 @@ import org.kohsuke.accmod.restrictions.NoExternalUse; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.stapler.*; +import org.kohsuke.stapler.StaplerOverridable; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.export.Exported; import org.kohsuke.stapler.interceptor.RequirePOST; import org.kohsuke.stapler.verb.POST; diff --git a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java index 8afd739f68c9..88c4289dffb5 100644 --- a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java +++ b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java @@ -287,7 +287,7 @@ public static ExtensionList all() { } @Restricted(NoExternalUse.class) - public static FormValidation doCheckDisplayNameOrNull(@AncestorInPath AbstractProject project, @QueryParameter String value) { - return Jenkins.get().doCheckDisplayName(value, project.getName()); + public FormValidation doCheckDisplayNameOrNull(@AncestorInPath TopLevelItem item, @QueryParameter String value) { + return Jenkins.get().doCheckDisplayName(value, item.getName()); } } From 0d4fb2c0edcfac349ca755cff118674227f0040a Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 01:31:14 +0800 Subject: [PATCH 6/9] revert star imports --- core/src/main/java/hudson/model/TopLevelItemDescriptor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java index 88c4289dffb5..5bb2d9aea47c 100644 --- a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java +++ b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java @@ -40,7 +40,11 @@ import org.jenkins.ui.icon.IconSpec; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; -import org.kohsuke.stapler.*; +import org.kohsuke.stapler.MetaClass; +import org.kohsuke.stapler.Stapler; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.WebApp; +import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.jelly.DefaultScriptInvoker; import org.kohsuke.stapler.jelly.JellyClassTearOff; import org.springframework.security.access.AccessDeniedException; From 25755654332ba2fae304eca70e52218311ec62fa Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 01:34:34 +0800 Subject: [PATCH 7/9] add missing imports --- core/src/main/java/hudson/model/TopLevelItemDescriptor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java index 5bb2d9aea47c..0ba59421b0d9 100644 --- a/core/src/main/java/hudson/model/TopLevelItemDescriptor.java +++ b/core/src/main/java/hudson/model/TopLevelItemDescriptor.java @@ -40,11 +40,12 @@ import org.jenkins.ui.icon.IconSpec; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.MetaClass; +import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.Stapler; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.WebApp; -import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.jelly.DefaultScriptInvoker; import org.kohsuke.stapler.jelly.JellyClassTearOff; import org.springframework.security.access.AccessDeniedException; From c4db068e0ef7e2a56e975de96137f8465c9770cf Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 19:31:29 +0800 Subject: [PATCH 8/9] fix: revert an out-of-scope change --- core/src/main/java/hudson/model/Job.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Job.java b/core/src/main/java/hudson/model/Job.java index 548aced2f0f8..8c4e3183100a 100644 --- a/core/src/main/java/hudson/model/Job.java +++ b/core/src/main/java/hudson/model/Job.java @@ -128,7 +128,7 @@ import org.kohsuke.stapler.verb.POST; /** - * A job is a runnable entity under the monitoring of Hudson. + * A job is an runnable entity under the monitoring of Hudson. * *

* Every time it "runs", it will be recorded as a {@link Run} object. From e5c9e751fc172e69ff1276d773bf0e126c9a3026 Mon Sep 17 00:00:00 2001 From: Kris Stern Date: Wed, 10 Apr 2024 19:32:46 +0800 Subject: [PATCH 9/9] fix: remove an obsoleted previous implementation --- core/src/main/java/hudson/model/AbstractProject.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index c554ef813440..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.getName()); - } - @Restricted(DoNotUse.class) public FormValidation doCheckAssignedLabelString(@AncestorInPath AbstractProject project, @QueryParameter String value) {