Skip to content

Commit

Permalink
Fix in case of null provider
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Jan 5, 2025
1 parent ebb6831 commit 76d4bb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import hudson.model.ParameterDefinition;
import hudson.model.ParameterDefinition.ParameterDescriptor;
import hudson.model.PasswordParameterDefinition;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.Slave;
import hudson.model.TimeZoneProperty;
Expand Down Expand Up @@ -144,6 +143,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.TimeZone;
Expand All @@ -159,6 +159,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import jenkins.console.ConsoleUrlProvider;
import jenkins.console.DefaultConsoleUrlProvider;
import jenkins.console.WithConsoleUrl;
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
Expand Down Expand Up @@ -1994,15 +1995,12 @@ public static String joinPath(String... components) {
return consoleUrl != null ? Stapler.getCurrentRequest().getContextPath() + '/' + consoleUrl : null;
}

public static @CheckForNull ConsoleUrlProvider getConsoleProvider(Queue.Executable executable) {
if (executable == null) {
return null;
} else if (executable instanceof Run) {
return ConsoleUrlProvider.getProvider((Run<?, ?>) executable);
} else {
// Handles cases such as PlaceholderExecutable for Pipeline node steps.
return getConsoleProvider(executable.getParentExecutable());
}
/**
* @param run the run
* @return the Console Provider for the given run, if null, the default Console Provider
*/
public static ConsoleUrlProvider getConsoleProviderFor(Run<?, ?> run) {
return Optional.ofNullable(ConsoleUrlProvider.getProvider(run)).orElse(new DefaultConsoleUrlProvider());

Check warning on line 2003 in core/src/main/java/hudson/Functions.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 2003 is not covered by tests
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/Run/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ THE SOFTWARE.

<l:userExperimentalFlag var="showConsoleWidget" flagClassName="jenkins.model.experimentalflags.ConsoleWidgetUserExperimentalFlag" />
<j:if test="${showConsoleWidget}">
<st:include page="console.jelly" from="${h.getConsoleProvider(it)}" optional="true" />
<st:include page="console.jelly" from="${h.getConsoleProviderFor(it)}" optional="true" />
</j:if>

<div style="float:right; z-index: 1; position:relative; margin-left: 1em">
Expand Down

0 comments on commit 76d4bb8

Please sign in to comment.