Skip to content

Commit

Permalink
Use invokeStatic instead of Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
imonteroperez committed Nov 10, 2021
1 parent f905a3f commit 63367c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
14 changes: 0 additions & 14 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2285,18 +2285,4 @@ public static boolean isContextMenuVisible(Action a) {
return true;
}
}

@Restricted(NoExternalUse.class)
@CheckForNull
public static Header header() {
List<Header> 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();
}
}
25 changes: 25 additions & 0 deletions core/src/main/java/jenkins/views/JenkinsHeader.java
Original file line number Diff line number Diff line change
@@ -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<Header> 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();
}

}
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/layout/pageHeader.jelly
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:i="jelly:fmt" xmlns:x="jelly:xml">
<j:set var="header" value="${h.header()}" />
<j:invokeStatic var="header" className="jenkins.views.JenkinsHeader" method="get"/>
<st:include it="${header}" page="headerDocumentation.jelly"/>
<st:include it="${header}" page="preHeader.jelly"/>
<st:include it="${header}" page="headerContent.jelly"/>
Expand Down

0 comments on commit 63367c7

Please sign in to comment.