Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 76d4bb8
Author: Jan Faracik <[email protected]>
Date:   Sun Jan 5 11:01:47 2025 +0000

    Fix in case of null provider

commit ebb6831
Author: Jan Faracik <[email protected]>
Date:   Sat Jan 4 15:23:03 2025 +0000

    Lint

commit 11e4b8d
Author: Jan Faracik <[email protected]>
Date:   Sat Jan 4 14:48:20 2025 +0000

    Init

commit 519eb19
Merge: 908030e b3b5a69
Author: Kris Stern <[email protected]>
Date:   Sat Jan 4 16:01:19 2025 +0800

    Merge pull request jenkinsci#9980 from basil/OptionHandlerExtension

    Register `OptionHandler`s through `META-INF/services/annotations` and Annotation Indexer rather than `META-INF/services` and Commons Discovery

commit 908030e
Merge: d3e8908 fc4a567
Author: Kris Stern <[email protected]>
Date:   Sat Jan 4 16:00:31 2025 +0800

    Merge pull request jenkinsci#10026 from mtughan/allow-immutable-collections

    Allow all immutable List subclasses from Java 11

commit d3e8908
Author: Jesse Glick <[email protected]>
Date:   Fri Jan 3 05:43:27 2025 -0500

    Correcting API documentation of `builds` vs. `allBuilds` (jenkinsci#10112)

commit 89f48c5
Merge: 238c498 e1dff1a
Author: Kris Stern <[email protected]>
Date:   Fri Jan 3 18:00:18 2025 +0800

    Merge pull request jenkinsci#10106 from timja/ballColorTd-table

    [JENKINS-74868] Use new build status symbols in multi branch projects

commit 238c498
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Thu Jan 2 20:32:04 2025 -0800

    Update dependency io.jenkins.plugins:design-library to v342 (jenkinsci#10111)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

commit 75410bc
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Thu Jan 2 10:45:55 2025 -0800

    Update dependency io.jenkins.plugins:json-api to v20241224 (jenkinsci#10110)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

commit 1aa9c57
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Thu Jan 2 10:44:50 2025 -0800

    Update Yarn to v4.6.0 (jenkinsci#10109)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

commit e1dff1a
Author: Tim Jacomb <[email protected]>
Date:   Tue Dec 31 19:46:12 2024 +0000

    Adjust test

commit 5fd9f51
Author: Tim Jacomb <[email protected]>
Date:   Mon Dec 30 22:20:15 2024 +0000

    [JENKINS-74868] Use new build status symbols in multi branch projects

commit b3b5a69
Merge: 33d8280 d73c0ea
Author: Basil Crow <[email protected]>
Date:   Tue Dec 17 10:19:22 2024 -1000

    Merge branch 'master' into OptionHandlerExtension

commit fc4a567
Author: Michael Tughan <[email protected]>
Date:   Wed Dec 4 15:15:13 2024 -0500

    Allow all immutable List subclasses from Java 11

    A previous commit specifically allowed one of the two subclasses used by
    `List.of` and `List.copyOf`, but not the other, which can result in
    unexpected errors and bugs. Add the other to the default allow list of
    classes to avoid these.

commit 33d8280
Merge: a1c8c83 9965f04
Author: Tim Jacomb <[email protected]>
Date:   Sun Dec 8 08:32:24 2024 +0000

    Merge branch 'master' into OptionHandlerExtension

commit a1c8c83
Author: Basil Crow <[email protected]>
Date:   Fri Nov 15 10:58:26 2024 -0800

    Register `OptionHandler`s through `META-INF/services/annotations` and Annotation Indexer rather than `META-INF/services` and Commons Discovery
  • Loading branch information
janfaracik committed Jan 5, 2025
1 parent e04fc0d commit 01593ce
Show file tree
Hide file tree
Showing 28 changed files with 234 additions and 123 deletions.
10 changes: 10 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,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 @@ -158,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.Detail;
import jenkins.model.DetailFactory;
Expand Down Expand Up @@ -1996,6 +1998,14 @@ public static String joinPath(String... components) {
return consoleUrl != null ? Stapler.getCurrentRequest().getContextPath() + '/' + consoleUrl : null;
}

/**
* @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());
}

/**
* Escapes the character unsafe for e-mail address.
* See <a href="https://en.wikipedia.org/wiki/Email_address">the Wikipedia page</a> for the details,
Expand Down
29 changes: 12 additions & 17 deletions core/src/main/java/hudson/cli/CLICommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public int main(List<String> args, Locale locale, InputStream stdin, PrintStream
this.stdout = stdout;
this.stderr = stderr;
this.locale = locale;
registerOptionHandlers();
CmdLineParser p = getCmdLineParser();

// add options from the authenticator
Expand Down Expand Up @@ -527,20 +526,6 @@ protected CLICommand createClone() {
}
}

/**
* Auto-discovers {@link OptionHandler}s and add them to the given command line parser.
*/
protected void registerOptionHandlers() {
try {
for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.get().pluginManager.uberClassLoader, Class.class)) {
Type t = Types.getBaseClass(c, OptionHandler.class);
CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t, 0)), c);
}
} catch (IOException e) {
throw new Error(e);
}
}

/**
* Returns all the registered {@link CLICommand}s.
*/
Expand Down Expand Up @@ -577,11 +562,21 @@ public static CLICommand getCurrent() {

static {
// register option handlers that are defined
ClassLoaders cls = new ClassLoaders();
Jenkins j = Jenkins.getInstanceOrNull();
if (j != null) { // only when running on the controller
cls.put(j.getPluginManager().uberClassLoader);
// Register OptionHandlers through META-INF/services/annotations and Annotation Indexer
try {
for (Class c : Index.list(OptionHandlerExtension.class, Jenkins.get().pluginManager.uberClassLoader, Class.class)) {
Type t = Types.getBaseClass(c, OptionHandler.class);
CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t, 0)), c);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}

// Register OptionHandlers through META-INF/services and Commons Discovery
ClassLoaders cls = new ClassLoaders();
cls.put(j.getPluginManager().uberClassLoader);
ResourceNameIterator servicesIter =
new DiscoverServiceNames(cls).findResourceNames(OptionHandler.class.getName());
final ResourceClassIterator itr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ protected CmdLineParser getCmdLineParser() {

private CmdLineParser bindMethod(List<MethodBinder> binders) {

registerOptionHandlers();
ParserProperties properties = ParserProperties.defaults().withAtSyntax(ALLOW_AT_SYNTAX);
CmdLineParser parser = new CmdLineParser(null, properties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

/**
* {@link OptionHandler}s that should be auto-discovered.
* TODO is this actually necessary? {@code @MetaInfServices(OptionHandler.class)} seems to work as well.
* @author Kohsuke Kawaguchi
*/
@Indexed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@

package hudson.cli.handlers;

import hudson.cli.declarative.OptionHandlerExtension;
import hudson.model.AbstractItem;
import org.kohsuke.MetaInfServices;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Setter;

/**
* Refers to an {@link AbstractItem} by name.
* @since 1.538
*/
@MetaInfServices(OptionHandler.class) public class AbstractItemOptionHandler extends GenericItemOptionHandler<AbstractItem> {
@OptionHandlerExtension
public class AbstractItemOptionHandler extends GenericItemOptionHandler<AbstractItem> {

public AbstractItemOptionHandler(CmdLineParser parser, OptionDef option, Setter<AbstractItem> setter) {
super(parser, option, setter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@

package hudson.cli.handlers;

import hudson.cli.declarative.OptionHandlerExtension;
import hudson.model.AbstractProject;
import org.kohsuke.MetaInfServices;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Setter;

/**
* Refer to {@link AbstractProject} by its name.
*
* @author Kohsuke Kawaguchi
*/
@MetaInfServices(OptionHandler.class)
@OptionHandlerExtension
@SuppressWarnings("rawtypes")
public class AbstractProjectOptionHandler extends GenericItemOptionHandler<AbstractProject> {
public AbstractProjectOptionHandler(CmdLineParser parser, OptionDef option, Setter<AbstractProject> setter) {
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/hudson/cli/handlers/JobOptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@

package hudson.cli.handlers;

import hudson.cli.declarative.OptionHandlerExtension;
import hudson.model.Job;
import org.kohsuke.MetaInfServices;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Setter;

/**
* Refer to {@link Job} by its name.
*
* @author Kohsuke Kawaguchi
*/
@MetaInfServices(OptionHandler.class)
@OptionHandlerExtension
@SuppressWarnings("rawtypes")
public class JobOptionHandler extends GenericItemOptionHandler<Job> {
public JobOptionHandler(CmdLineParser parser, OptionDef option, Setter<Job> setter) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/cli/handlers/NodeOptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

package hudson.cli.handlers;

import hudson.cli.declarative.OptionHandlerExtension;
import hudson.model.Node;
import jenkins.model.Jenkins;
import org.kohsuke.MetaInfServices;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
Expand All @@ -40,7 +40,7 @@
* @author ogondza
* @since 1.526
*/
@MetaInfServices
@OptionHandlerExtension
public class NodeOptionHandler extends OptionHandler<Node> {

public NodeOptionHandler(CmdLineParser parser, OptionDef option, Setter<Node> setter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@

package hudson.cli.handlers;

import hudson.cli.declarative.OptionHandlerExtension;
import jenkins.model.ParameterizedJobMixIn;
import org.kohsuke.MetaInfServices;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Setter;

/**
* Refer to {@link jenkins.model.ParameterizedJobMixIn.ParameterizedJob} by its name.
*/
@Restricted(DoNotUse.class)
@MetaInfServices(OptionHandler.class)
@OptionHandlerExtension
@SuppressWarnings("rawtypes")
public class ParameterizedJobOptionHandler extends GenericItemOptionHandler<ParameterizedJobMixIn.ParameterizedJob> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package hudson.cli.handlers;

import hudson.cli.declarative.OptionHandlerExtension;
import hudson.model.TopLevelItem;
import org.kohsuke.MetaInfServices;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.OptionHandler;
import org.kohsuke.args4j.spi.Setter;

/**
* Refers to {@link TopLevelItem} by its name.
*
* @author Kohsuke Kawaguchi
*/
@MetaInfServices(OptionHandler.class)
@OptionHandlerExtension
public class TopLevelItemOptionHandler extends GenericItemOptionHandler<TopLevelItem> {
public TopLevelItemOptionHandler(CmdLineParser parser, OptionDef option, Setter<TopLevelItem> setter) {
super(parser, option, setter);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/cli/handlers/ViewOptionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
package hudson.cli.handlers;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.cli.declarative.OptionHandlerExtension;
import hudson.model.View;
import hudson.model.ViewGroup;
import java.util.StringTokenizer;
import jenkins.model.Jenkins;
import org.kohsuke.MetaInfServices;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
Expand Down Expand Up @@ -58,7 +58,7 @@
* @author ogondza
* @since 1.538
*/
@MetaInfServices
@OptionHandlerExtension
public class ViewOptionHandler extends OptionHandler<View> {

public ViewOptionHandler(CmdLineParser parser, OptionDef option, Setter<View> setter) {
Expand Down
20 changes: 14 additions & 6 deletions core/src/main/java/jenkins/console/ConsoleUrlProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ default Descriptor<ConsoleUrlProvider> 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<ConsoleUrlProvider> all() {
final List<ConsoleUrlProvider> providers = new ArrayList<>();
User currentUser = User.current();
if (currentUser != null) {
Expand All @@ -105,8 +101,20 @@ default Descriptor<ConsoleUrlProvider> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.";
}
}
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/Job/_api.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ THE SOFTWARE.
<h2>Retrieving all builds</h2>
<p>
To prevent Jenkins from having to load all builds from disk when someone accesses the job API, the <code>builds</code>
tree only contains the 50 newest builds. If you really need to get all builds, access the <code>allBuilds</code> tree,
tree only contains the 100 newest builds. If you really need to get all builds, access the <code>allBuilds</code> tree,
e.g. by fetching <code>…/api/xml?tree=allBuilds[…]</code>. Note that this may result in significant performance degradation
if you have a lot of builds in this job.
</p>
Expand Down
38 changes: 38 additions & 0 deletions core/src/main/resources/hudson/model/Run/console-log.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson">
<j:set var="threshold" value="${h.getSystemProperty('hudson.consoleTailKB')?:'150'}" />
<!-- Show at most last 150KB (can override with system property) unless consoleFull is set -->
<j:set var="offset" value="${empty(consoleFull) ? it.logText.length()-threshold*1024 : 0}" />
<j:choose>
<j:when test="${offset > 0}">
<a class="jenkins-button jenkins-!-accent-color jenkins-!-padding-2 jenkins-!-margin-bottom-2" style="width: 100%; justify-content: start" href="consoleFull">
<l:icon src="symbol-help-circle" />
${%skipSome(offset / 1024)}
</a>
</j:when>
<j:otherwise>
<j:set var="offset" value="${0}" />
</j:otherwise>
</j:choose>

<j:out value="${h.generateConsoleAnnotationScriptAndStylesheet()}"/>

<j:choose>
<!-- Do progressive console output -->
<j:when test="${it.isLogUpdated()}">
<pre id="out" class="console-output" />
<div id="spinner">
<l:progressAnimation/>
</div>
<t:progressiveText href="logText/progressiveHtml" idref="out" spinner="spinner"
startOffset="${offset}" onFinishEvent="jenkins:consoleFinished"/>
</j:when>
<!-- output is completed now. -->
<j:otherwise>
<pre class="console-output">
<st:getOutput var="output" />
<j:whitespace>${it.writeLogTo(offset,output)}</j:whitespace>
</pre>
</j:otherwise>
</j:choose>
</j:jelly>
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 01593ce

Please sign in to comment.