From 11e4b8d23713bcb95afe5878d87603da9771a96b Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Sat, 4 Jan 2025 14:48:20 +0000 Subject: [PATCH 1/6] Init --- core/src/main/java/hudson/Functions.java | 12 +++++ .../jenkins/console/ConsoleUrlProvider.java | 20 +++++--- .../ConsoleWidgetUserExperimentalFlag.java | 49 +++++++++++++++++++ .../hudson/model/Run/console-log.jelly | 38 ++++++++++++++ .../hudson/model/Run/console-log.properties | 1 + .../resources/hudson/model/Run/console.jelly | 33 +------------ .../resources/hudson/model/Run/index.jelly | 5 ++ .../DefaultConsoleUrlProvider/console.jelly | 14 ++++++ .../resources/lib/hudson/progressive-text.js | 2 +- src/main/scss/pages/_build.scss | 16 ++++++ .../main/webapp/scripts/hudson-behavior.js | 10 ++-- 11 files changed, 158 insertions(+), 42 deletions(-) create mode 100644 core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java create mode 100644 core/src/main/resources/hudson/model/Run/console-log.jelly create mode 100644 core/src/main/resources/hudson/model/Run/console-log.properties create mode 100644 core/src/main/resources/jenkins/console/DefaultConsoleUrlProvider/console.jelly diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 67801475233d..153ff4c56b2c 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -54,6 +54,7 @@ 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; @@ -1993,6 +1994,17 @@ 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()); + } + } + /** * Escapes the character unsafe for e-mail address. * See the Wikipedia page for the details, diff --git a/core/src/main/java/jenkins/console/ConsoleUrlProvider.java b/core/src/main/java/jenkins/console/ConsoleUrlProvider.java index 637cf10145c6..9c6080ac02fa 100644 --- a/core/src/main/java/jenkins/console/ConsoleUrlProvider.java +++ b/core/src/main/java/jenkins/console/ConsoleUrlProvider.java @@ -83,11 +83,7 @@ default Descriptor getDescriptor() { return Stapler.getCurrentRequest().getContextPath() + '/' + run.getConsoleUrl(); } - /** - * Looks up the {@link #getConsoleUrl} value from the first provider to offer one. - * @since 2.476 - */ - static @NonNull String consoleUrlOf(Run run) { + static List all() { final List providers = new ArrayList<>(); User currentUser = User.current(); if (currentUser != null) { @@ -105,8 +101,20 @@ default Descriptor getDescriptor() { if (globalProviders != null) { providers.addAll(globalProviders); } + return providers; + } + + static ConsoleUrlProvider getProvider(Run run) { + return all().stream().filter(provider -> provider.getConsoleUrl(run) != null).findFirst().orElse(null); + } + + /** + * Looks up the {@link #getConsoleUrl} value from the first provider to offer one. + * @since 2.476 + */ + static @NonNull String consoleUrlOf(Run run) { String url = null; - for (ConsoleUrlProvider provider : providers) { + for (ConsoleUrlProvider provider : all()) { try { String tempUrl = provider.getConsoleUrl(run); if (tempUrl != null) { diff --git a/core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java b/core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java new file mode 100644 index 000000000000..15e8671b0d33 --- /dev/null +++ b/core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java @@ -0,0 +1,49 @@ +/* + * The MIT License + * + * Copyright (c) 2025, Jan Faracik + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package jenkins.model.experimentalflags; + +import edu.umd.cs.findbugs.annotations.Nullable; +import hudson.Extension; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; + +@Extension +@Restricted(NoExternalUse.class) +public class ConsoleWidgetUserExperimentalFlag extends BooleanUserExperimentalFlag { + public ConsoleWidgetUserExperimentalFlag() { + super("console-widget.flag"); + } + + @Override + public String getDisplayName() { + return "Show Console Output on build pages"; + } + + @Nullable + @Override + public String getShortDescription() { + return "Shows the Console Output as a widget on build pages."; + } +} diff --git a/core/src/main/resources/hudson/model/Run/console-log.jelly b/core/src/main/resources/hudson/model/Run/console-log.jelly new file mode 100644 index 000000000000..bb2aad579a92 --- /dev/null +++ b/core/src/main/resources/hudson/model/Run/console-log.jelly @@ -0,0 +1,38 @@ + + + + + + + + + + ${%skipSome(offset / 1024)} + + + + + + + + + + + + +
+      
+ +
+ + + + +
+        
+        ${it.writeLogTo(offset,output)}
+      
+
+ + diff --git a/core/src/main/resources/hudson/model/Run/console-log.properties b/core/src/main/resources/hudson/model/Run/console-log.properties new file mode 100644 index 000000000000..12f13f7125d6 --- /dev/null +++ b/core/src/main/resources/hudson/model/Run/console-log.properties @@ -0,0 +1 @@ +skipSome=This log is too long to show here, {0,number,integer} KB has been skipped — click to see the complete log diff --git a/core/src/main/resources/hudson/model/Run/console.jelly b/core/src/main/resources/hudson/model/Run/console.jelly index ad38828dad5a..333fc741d9c0 100644 --- a/core/src/main/resources/hudson/model/Run/console.jelly +++ b/core/src/main/resources/hudson/model/Run/console.jelly @@ -50,38 +50,7 @@ THE SOFTWARE. ${%Console Output} - - - - - - ${%skipSome(offset/1024,"consoleFull")} - - - - - - - - - - - -
-            
- -
- - - - -
-            
-            ${it.writeLogTo(offset,output)}
-          
-
- + diff --git a/core/src/main/resources/hudson/model/Run/index.jelly b/core/src/main/resources/hudson/model/Run/index.jelly index b164817a164f..c37b7108a428 100644 --- a/core/src/main/resources/hudson/model/Run/index.jelly +++ b/core/src/main/resources/hudson/model/Run/index.jelly @@ -43,6 +43,11 @@ THE SOFTWARE. + + + + +
${%startedAgo(it.timestampString)} diff --git a/core/src/main/resources/jenkins/console/DefaultConsoleUrlProvider/console.jelly b/core/src/main/resources/jenkins/console/DefaultConsoleUrlProvider/console.jelly new file mode 100644 index 000000000000..ad11b66b7699 --- /dev/null +++ b/core/src/main/resources/jenkins/console/DefaultConsoleUrlProvider/console.jelly @@ -0,0 +1,14 @@ + + + + + + + + + +
+ +
+
+
diff --git a/core/src/main/resources/lib/hudson/progressive-text.js b/core/src/main/resources/lib/hudson/progressive-text.js index 71f84b2b2238..ede4d46eba6f 100644 --- a/core/src/main/resources/lib/hudson/progressive-text.js +++ b/core/src/main/resources/lib/hudson/progressive-text.js @@ -10,7 +10,7 @@ Behaviour.specify( let onFinishEvent = holder.getAttribute("data-on-finish-event"); let errorMessage = holder.getAttribute("data-error-message"); - var scroller = new AutoScroller(document.body); + var scroller = new AutoScroller(holder.closest(".progressive-text-container") || document.body); /* fetches the latest update from the server @param e diff --git a/src/main/scss/pages/_build.scss b/src/main/scss/pages/_build.scss index 6bcf404773fa..cb5e3298faf1 100644 --- a/src/main/scss/pages/_build.scss +++ b/src/main/scss/pages/_build.scss @@ -5,3 +5,19 @@ flex-wrap: nowrap; gap: 10px; } + +.app-console-output-widget { + min-height: 340px; + max-height: 340px; + overflow-y: auto; + margin: 0 -1rem -1rem; + padding: 0 1rem 1rem; + + pre { + background: transparent; + margin: 0; + padding: 0; + line-height: 1.75; + font-size: var(--font-size-sm); + } +} diff --git a/war/src/main/webapp/scripts/hudson-behavior.js b/war/src/main/webapp/scripts/hudson-behavior.js index 715984f6ca33..93918dac11c5 100644 --- a/war/src/main/webapp/scripts/hudson-behavior.js +++ b/war/src/main/webapp/scripts/hudson-behavior.js @@ -2030,10 +2030,14 @@ function AutoScroller(scrollContainer) { scrollToBottom: function () { var scrollDiv = this.scrollContainer; var currentHeight = this.getCurrentHeight(); - if (document.documentElement) { - document.documentElement.scrollTop = currentHeight; + + if (scrollDiv === document.body) { + window.scrollTo({ + top: currentHeight, + }); + } else { + scrollDiv.scrollTop = currentHeight; } - scrollDiv.scrollTop = currentHeight; }, }; } From ebb68318ca27be87816b84ada793ea8be109d60f Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:23:03 +0000 Subject: [PATCH 2/6] Lint --- core/src/main/resources/lib/hudson/progressive-text.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/lib/hudson/progressive-text.js b/core/src/main/resources/lib/hudson/progressive-text.js index ede4d46eba6f..696a4d144c76 100644 --- a/core/src/main/resources/lib/hudson/progressive-text.js +++ b/core/src/main/resources/lib/hudson/progressive-text.js @@ -10,7 +10,9 @@ Behaviour.specify( let onFinishEvent = holder.getAttribute("data-on-finish-event"); let errorMessage = holder.getAttribute("data-error-message"); - var scroller = new AutoScroller(holder.closest(".progressive-text-container") || document.body); + var scroller = new AutoScroller( + holder.closest(".progressive-text-container") || document.body, + ); /* fetches the latest update from the server @param e From 76d4bb8ea93af11aa7080bf2df23169eb6545d88 Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:01:47 +0000 Subject: [PATCH 3/6] Fix in case of null provider --- core/src/main/java/hudson/Functions.java | 18 ++++++++---------- .../resources/hudson/model/Run/index.jelly | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 153ff4c56b2c..ea677293cb60 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -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; @@ -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; @@ -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; @@ -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()); } /** diff --git a/core/src/main/resources/hudson/model/Run/index.jelly b/core/src/main/resources/hudson/model/Run/index.jelly index c37b7108a428..ba7353955daa 100644 --- a/core/src/main/resources/hudson/model/Run/index.jelly +++ b/core/src/main/resources/hudson/model/Run/index.jelly @@ -45,7 +45,7 @@ THE SOFTWARE. - +
From 21bfc3819c2524da9d21e3d854c7e03ababe7c4e Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:25:03 +0000 Subject: [PATCH 4/6] New build page flag --- ...Flag.java => NewBuildPageUserExperimentalFlag.java} | 10 +++++----- core/src/main/resources/hudson/model/Run/index.jelly | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) rename core/src/main/java/jenkins/model/experimentalflags/{ConsoleWidgetUserExperimentalFlag.java => NewBuildPageUserExperimentalFlag.java} (83%) diff --git a/core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java b/core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java similarity index 83% rename from core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java rename to core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java index 15e8671b0d33..22f26213b8be 100644 --- a/core/src/main/java/jenkins/model/experimentalflags/ConsoleWidgetUserExperimentalFlag.java +++ b/core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java @@ -31,19 +31,19 @@ @Extension @Restricted(NoExternalUse.class) -public class ConsoleWidgetUserExperimentalFlag extends BooleanUserExperimentalFlag { - public ConsoleWidgetUserExperimentalFlag() { - super("console-widget.flag"); +public class NewBuildPageUserExperimentalFlag extends BooleanUserExperimentalFlag { + public NewBuildPageUserExperimentalFlag() { + super("new-build-page.flag"); } @Override public String getDisplayName() { - return "Show Console Output on build pages"; + return "New build page"; } @Nullable @Override public String getShortDescription() { - return "Shows the Console Output as a widget on build pages."; + return "Enables a revamped build page. This is a work in progress."; } } diff --git a/core/src/main/resources/hudson/model/Run/index.jelly b/core/src/main/resources/hudson/model/Run/index.jelly index ba7353955daa..29d8427d4f0b 100644 --- a/core/src/main/resources/hudson/model/Run/index.jelly +++ b/core/src/main/resources/hudson/model/Run/index.jelly @@ -43,8 +43,8 @@ THE SOFTWARE.
- - + + From ce0d0bc73f8aa4eec4d07dca80bea49771ae83a0 Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Tue, 7 Jan 2025 13:29:38 +0000 Subject: [PATCH 5/6] Use flag for the entire page --- .../NewBuildPageUserExperimentalFlag.java | 2 +- .../resources/hudson/model/Run/index.jelly | 92 ++++++++++--------- .../hudson/model/Run/new-build-page.jelly | 78 ++++++++++++++++ 3 files changed, 127 insertions(+), 45 deletions(-) create mode 100644 core/src/main/resources/hudson/model/Run/new-build-page.jelly diff --git a/core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java b/core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java index 22f26213b8be..cbe6e908cdc1 100644 --- a/core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java +++ b/core/src/main/java/jenkins/model/experimentalflags/NewBuildPageUserExperimentalFlag.java @@ -44,6 +44,6 @@ public String getDisplayName() { @Nullable @Override public String getShortDescription() { - return "Enables a revamped build page. This is a work in progress."; + return "Enables a revamped build page. This feature is still a work in progress, so some things might not work perfectly yet."; } } diff --git a/core/src/main/resources/hudson/model/Run/index.jelly b/core/src/main/resources/hudson/model/Run/index.jelly index 29d8427d4f0b..c358324918f2 100644 --- a/core/src/main/resources/hudson/model/Run/index.jelly +++ b/core/src/main/resources/hudson/model/Run/index.jelly @@ -25,58 +25,62 @@ THE SOFTWARE. - - + - - - - - - - - + + + + + + + - ${it.displayName} () + + + + + + + + -
- -
+ ${it.displayName} () - - - - +
+ +
-
-
- ${%startedAgo(it.timestampString)} -
-
- - ${%beingExecuted(it.executor.timestampString)} - - - ${%Took} ${it.durationString} - - -
-
+
+
+ ${%startedAgo(it.timestampString)} +
+
+ + ${%beingExecuted(it.executor.timestampString)} + + + ${%Took} ${it.durationString} + + +
+
- - +
+ - - - - + + + + - -
+ + - -
-
+ +
+
+ +
diff --git a/core/src/main/resources/hudson/model/Run/new-build-page.jelly b/core/src/main/resources/hudson/model/Run/new-build-page.jelly new file mode 100644 index 000000000000..cf1c270163e5 --- /dev/null +++ b/core/src/main/resources/hudson/model/Run/new-build-page.jelly @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + ${it.displayName} () + +
+ +
+ + + +
+
+ ${%startedAgo(it.timestampString)} +
+
+ + ${%beingExecuted(it.executor.timestampString)} + + + ${%Took} ${it.durationString} + + +
+
+ + + + + + + + + + +
+ + +
+
+
From 131c3879d91d427cef24e436e0ef73d223a859f7 Mon Sep 17 00:00:00 2001 From: Jan Faracik <43062514+janfaracik@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:17:22 +0000 Subject: [PATCH 6/6] Fix missing translations --- .../main/resources/hudson/model/Run/new-build-page.properties | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 core/src/main/resources/hudson/model/Run/new-build-page.properties diff --git a/core/src/main/resources/hudson/model/Run/new-build-page.properties b/core/src/main/resources/hudson/model/Run/new-build-page.properties new file mode 100644 index 000000000000..c52678dca5a0 --- /dev/null +++ b/core/src/main/resources/hudson/model/Run/new-build-page.properties @@ -0,0 +1,2 @@ +startedAgo=Started {0} ago +beingExecuted=Build has been executing for {0}