From db638ece0951cf3492f91b39b445a16069c520b9 Mon Sep 17 00:00:00 2001 From: Markus Winter Date: Fri, 1 Dec 2023 23:12:51 +0100 Subject: [PATCH] [JENKINS-63971] prepare for casc support of node monitors (#189) * [JENKINS-63971] prepare for casc support for node monitors to support node monitors in casc, is is essential that they have DataBoundConstructors defined and a proper symbol is used. * apply formatting * remove newInstance from descriptor * Remove unused imports --------- Co-authored-by: Mark Waite --- .../versioncolumn/JVMVersionMonitor.java | 2 ++ .../plugin/versioncolumn/VersionMonitor.java | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main/java/hudson/plugin/versioncolumn/JVMVersionMonitor.java b/src/main/java/hudson/plugin/versioncolumn/JVMVersionMonitor.java index 67ce20c..4bb416d 100644 --- a/src/main/java/hudson/plugin/versioncolumn/JVMVersionMonitor.java +++ b/src/main/java/hudson/plugin/versioncolumn/JVMVersionMonitor.java @@ -36,6 +36,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import jenkins.security.MasterToSlaveCallable; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; public class JVMVersionMonitor extends NodeMonitor { @@ -110,6 +111,7 @@ public JVMVersionComparator.ComparisonMode getComparisonMode() { } @Extension + @Symbol("jvmVersion") public static class JvmVersionDescriptor extends AbstractAsyncNodeMonitorDescriptor { @Override diff --git a/src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java b/src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java index ef539d1..2aca082 100644 --- a/src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java +++ b/src/main/java/hudson/plugin/versioncolumn/VersionMonitor.java @@ -24,6 +24,7 @@ package hudson.plugin.versioncolumn; import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.Extension; import hudson.Util; import hudson.model.Computer; @@ -34,13 +35,16 @@ import java.io.IOException; import java.util.logging.Logger; import jenkins.security.MasterToSlaveCallable; -import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.DataBoundConstructor; public class VersionMonitor extends NodeMonitor { private static final String masterVersion = Launcher.VERSION; + @DataBoundConstructor + public VersionMonitor() {} + @SuppressWarnings("unused") // jelly public String toHtml(String version) { if (version == null) { @@ -52,8 +56,19 @@ public String toHtml(String version) { return version; } + @SuppressFBWarnings(value = "MS_PKGPROTECT", justification = "for backward compatibility") + public static /*almost final*/ AbstractNodeMonitorDescriptor DESCRIPTOR; + @Extension - public static final AbstractNodeMonitorDescriptor DESCRIPTOR = new AbstractNodeMonitorDescriptor<>() { + @Symbol("remotingVersion") + public static class DescriptorImpl extends AbstractNodeMonitorDescriptor { + + @SuppressFBWarnings( + value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", + justification = "for backward compatibility") + public DescriptorImpl() { + DESCRIPTOR = this; + } protected String monitor(Computer c) throws IOException, InterruptedException { String version = c.getChannel().call(new SlaveVersion()); @@ -70,12 +85,7 @@ protected String monitor(Computer c) throws IOException, InterruptedException { public String getDisplayName() { return Messages.VersionMonitor_DisplayName(); } - - @Override - public NodeMonitor newInstance(StaplerRequest req, @NonNull JSONObject formData) throws FormException { - return new VersionMonitor(); - } - }; + } private static final class SlaveVersion extends MasterToSlaveCallable {