From 63367c7b65447a89ab55136d43fca18e65769a0a Mon Sep 17 00:00:00 2001 From: imonteroperez Date: Wed, 10 Nov 2021 13:27:19 +0100 Subject: [PATCH] Use invokeStatic instead of Functions --- core/src/main/java/hudson/Functions.java | 14 ----------- .../java/jenkins/views/JenkinsHeader.java | 25 +++++++++++++++++++ .../resources/lib/layout/pageHeader.jelly | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 21a2a382b4f5..a0e385abbc0f 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -2285,18 +2285,4 @@ public static boolean isContextMenuVisible(Action a) { return true; } } - - @Restricted(NoExternalUse.class) - @CheckForNull - public static Header header() { - List
headers = ExtensionList.lookup(Header.class).stream().filter(header -> header.isHeaderEnabled()).collect(Collectors.toList()); - if (headers.size() > 0) { - if (headers.size() > 1) { - LOGGER.warning("More than one configured header. This should not happen. Serving the Jenkins default header and please review"); - } else { - return headers.get(0); - } - } - return new JenkinsHeader(); - } } diff --git a/core/src/main/java/jenkins/views/JenkinsHeader.java b/core/src/main/java/jenkins/views/JenkinsHeader.java index 6e4886df691b..defba5872424 100644 --- a/core/src/main/java/jenkins/views/JenkinsHeader.java +++ b/core/src/main/java/jenkins/views/JenkinsHeader.java @@ -1,13 +1,38 @@ package jenkins.views; +import java.util.List; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; + +import edu.umd.cs.findbugs.annotations.CheckForNull; import hudson.Extension; +import hudson.ExtensionList; @Extension(ordinal = Integer.MIN_VALUE) public class JenkinsHeader implements Header { + + private static Logger LOGGER = Logger.getLogger(JenkinsHeader.class.getName()); @Override public boolean isHeaderEnabled() { return true; } + + @Restricted(NoExternalUse.class) + @CheckForNull + public static Header get() { + List
headers = ExtensionList.lookup(Header.class).stream().filter(header -> header.isHeaderEnabled()).collect(Collectors.toList()); + if (headers.size() > 0) { + if (headers.size() > 1) { + LOGGER.warning("More than one configured header. This should not happen. Serving the Jenkins default header and please review"); + } else { + return headers.get(0); + } + } + return new JenkinsHeader(); + } } diff --git a/core/src/main/resources/lib/layout/pageHeader.jelly b/core/src/main/resources/lib/layout/pageHeader.jelly index b793259536e7..881fde275d8e 100644 --- a/core/src/main/resources/lib/layout/pageHeader.jelly +++ b/core/src/main/resources/lib/layout/pageHeader.jelly @@ -1,6 +1,6 @@ - +