Repository: jenkinsci/jenkins
File: core/src/main/java/jenkins/views/Header.java (Java)

Code before:
     * @return if header is available
     */
    public boolean isAvailable() {
        return isCompatible() && isEnabled();
    }

    /**
     * Checks API compatibility of the header
     * @return if header is compatible
     */
    public abstract boolean isCompatible();

    /**
     * Checks if header is enabled.
     * @return if header is enabled
     */
    public abstract boolean isEnabled();

    @Restricted(NoExternalUse.class)
    public static Header get() {
        Optional<Header> header = ExtensionList.lookup(Header.class).stream().filter(Header::isAvailable).findFirst();
        return header.orElseGet(JenkinsHeader::new);
    }

    /**
     * @return a list of {@link Action} to show in the header, defaults to {@link Jenkins#getActions()} with the {@link SearchAction}, {@link ManageJenkinsAction} and {@link UserAction} removed
     */
    @Restricted(NoExternalUse.class)
    public List<Action> getActions() {
        // There's an issue where new actions (e.g. a new plugin installation) don't appear in the order
        // of their ordinal annotation - to work around that we manually sort the list
        Map<String, Double> rootActionsOrdinal = ExtensionList.lookup(RootAction.class)
                .getComponents()
                .stream()
                .collect(Collectors.toMap(
                        c -> c.getInstance().getClass().getName(),
                        ExtensionComponent::ordinal
                ));

        return Jenkins.get()
                .getActions()
                .stream()
                .filter(e -> e.getIconFileName() != null || (e instanceof IconSpec is && is.getIconClassName() != null))
                .sorted(Comparator.comparingDouble(
                        a -> rootActionsOrdinal.getOrDefault(a.getClass().getName(), Double.MAX_VALUE)
                ).reversed())
                .toList();
    }
}


Review comment (bug):
this is now incorrect, I was going to filter here but that would make it specific to the `JenkinsHeader` implementation

Code after:
        return isCompatible() && isEnabled();
    }

    /**
     * Checks API compatibility of the header
     * @return if header is compatible
     */
    public abstract boolean isCompatible();

    /**
     * Checks if header is enabled.
     * @return if header is enabled
     */
    public abstract boolean isEnabled();

    @Restricted(NoExternalUse.class)
    public static Header get() {
        Optional<Header> header = ExtensionList.lookup(Header.class).stream().filter(Header::isAvailable).findFirst();
        return header.orElseGet(JenkinsHeader::new);
    }

    /**
     * @return a list of {@link Action} to show in the header.
     * The default implementation returns an {@link Jenkins#getActions()} that should be displayed (ie have an icon).
     */
    @Restricted(NoExternalUse.class)
    public List<Action> getActions() {
        // There's an issue where new actions (e.g. a new plugin installation) don't appear in the order
        // of their ordinal annotation - to work around that we manually sort the list
        Map<String, Double> rootActionsOrdinal = ExtensionList.lookup(RootAction.class)
                .getComponents()
                .stream()
                .collect(Collectors.toMap(
                        c -> c.getInstance().getClass().getName(),
                        ExtensionComponent::ordinal
                ));

        return Jenkins.get()
                .getActions()
                .stream()
                .filter(e -> e.getIconFileName() != null || (e instanceof IconSpec is && is.getIconClassName() != null))
                .sorted(Comparator.comparingDouble(
                        a -> rootActionsOrdinal.getOrDefault(a.getClass().getName(), Double.MAX_VALUE)
                ).reversed())
                .toList();
    }
}