Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced jsr-305 annotations with spotbugs annotations #1055

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.TaskListener;
import io.fabric8.kubernetes.api.model.ContainerStatus;
import io.fabric8.kubernetes.api.model.Pod;
Expand All @@ -19,9 +21,6 @@
import io.fabric8.kubernetes.client.WatcherException;
import io.fabric8.kubernetes.client.utils.Serialization;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
* A pod watcher reporting when all containers are running
*/
Expand All @@ -35,7 +34,7 @@ public class AllContainersRunningPodWatcher implements Watcher<Pod> {

private KubernetesClient client;

@Nonnull
@NonNull
private final TaskListener runListener;

public AllContainersRunningPodWatcher(KubernetesClient client, Pod pod, @CheckForNull TaskListener runListener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.csanchez.jenkins.plugins.kubernetes;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.csanchez.jenkins.plugins.kubernetes.model.KeyValueEnvVar;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -42,7 +41,7 @@ public String getDisplayName() {
@Extension
public static class DescriptorVisibilityFilterImpl extends DescriptorVisibilityFilter {
@Override
public boolean filter(@CheckForNull Object context, @Nonnull Descriptor descriptor) {
public boolean filter(@CheckForNull Object context, @NonNull Descriptor descriptor) {
return !(descriptor instanceof ContainerEnvVar.DescriptorImpl);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javax.annotation.CheckForNull;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

import java.util.Set;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Label;
Expand All @@ -21,7 +20,7 @@ public abstract class InProvisioning implements ExtensionPoint {
* @param label the {@link Label} being checked.
* @return the agents names in provisioning according to all implementations of this extension point for the given label.
*/
@Nonnull
@NonNull
public static Set<String> getAllInProvisioning(@CheckForNull Label label) {
return all().stream()
.flatMap(c -> c.getInProvisioning(label).stream())
Expand All @@ -38,6 +37,6 @@ public static ExtensionList<InProvisioning> all() {
* @param label The label being checked
* @return The agents names in provisioning for the current label.
*/
@Nonnull
@NonNull
public abstract Set<String> getInProvisioning(Label label);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.Extension;
Expand All @@ -29,7 +30,6 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import javax.annotation.Nonnull;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Writer;
Expand All @@ -50,8 +50,8 @@ public class KubectlBuildWrapper extends SimpleBuildWrapper {
private String caCertificate;

@DataBoundConstructor
public KubectlBuildWrapper(@Nonnull String serverUrl, @Nonnull String credentialsId,
@Nonnull String caCertificate) {
public KubectlBuildWrapper(@NonNull String serverUrl, @NonNull String credentialsId,
@NonNull String caCertificate) {
this.serverUrl = serverUrl;
this.credentialsId = Util.fixEmpty(credentialsId);
this.caCertificate = Util.fixEmptyAndTrim(caCertificate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.servlet.ServletException;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Main;
import hudson.model.ItemGroup;
import hudson.model.Node;
import hudson.util.XStream2;
import jenkins.metrics.api.Metrics;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -61,8 +59,6 @@
import hudson.slaves.NodeProvisioner;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.PodList;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.VersionInfo;
Expand Down Expand Up @@ -101,7 +97,7 @@ public class KubernetesCloud extends Cloud {

private String defaultsProviderTemplate;

@Nonnull
@NonNull
private List<PodTemplate> templates = new ArrayList<>();
private String serverUrl;
private boolean useJenkinsProxy;
Expand Down Expand Up @@ -211,7 +207,7 @@ public void setDefaultsProviderTemplate(String defaultsProviderTemplate) {
this.defaultsProviderTemplate = defaultsProviderTemplate;
}

@Nonnull
@NonNull
public List<PodTemplate> getTemplates() {
return templates;
}
Expand All @@ -220,13 +216,13 @@ public List<PodTemplate> getTemplates() {
* Returns all pod templates for this cloud including the dynamic ones.
* @return all pod templates for this cloud including the dynamic ones.
*/
@Nonnull
@NonNull
public List<PodTemplate> getAllTemplates() {
return PodTemplateSource.getAll(this);
}

@DataBoundSetter
public void setTemplates(@Nonnull List<PodTemplate> templates) {
public void setTemplates(@NonNull List<PodTemplate> templates) {
this.templates = new ArrayList<>(templates);
}

Expand All @@ -235,7 +231,7 @@ public String getServerUrl() {
}

@DataBoundSetter
public void setServerUrl(@Nonnull String serverUrl) {
public void setServerUrl(@NonNull String serverUrl) {
this.serverUrl = serverUrl;
}

Expand Down Expand Up @@ -295,7 +291,7 @@ public boolean isCapOnlyOnAlivePods() {
* @return same as {@link #getJenkinsUrlOrNull}, if set
* @throws IllegalStateException if no Jenkins URL could be computed.
*/
@Nonnull
@NonNull
public String getJenkinsUrlOrDie() {
String url = getJenkinsUrlOrNull();
if (url == null) {
Expand Down Expand Up @@ -580,7 +576,7 @@ public PodTemplate getTemplate(@CheckForNull Label label) {
}

@CheckForNull
public PodTemplate getTemplateById(@Nonnull String id) {
public PodTemplate getTemplateById(@NonNull String id) {
return getAllTemplates().stream().filter(t -> id.equals(t.getId())).findFirst().orElse(null);
}

Expand Down Expand Up @@ -933,9 +929,9 @@ private Object readResolve() {

@Extension
public static class PodTemplateSourceImpl extends PodTemplateSource {
@Nonnull
@NonNull
@Override
public List<PodTemplate> getList(@Nonnull KubernetesCloud cloud) {
public List<PodTemplate> getList(@NonNull KubernetesCloud cloud) {
return cloud.getTemplates();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import java.util.Collections;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.ProxyConfiguration;
import hudson.security.ACL;
import hudson.util.Secret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
Expand Down Expand Up @@ -242,7 +241,7 @@ private static boolean isUsageRestrictedKubernetesCloud(Cloud cloud) {
@Extension
public static class DescriptorImpl extends AbstractFolderPropertyDescriptor {

@Nonnull
@NonNull
@Override
public String getDisplayName() {
return Messages.KubernetesFolderProperty_displayName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import javax.annotation.CheckForNull;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.fabric8.kubernetes.client.KubernetesClientException;
import jenkins.metrics.api.Metrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Nonnull;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

Expand Down Expand Up @@ -68,7 +67,7 @@ public static KubernetesProvisioningLimits get() {
* @param podTemplate the pod template used to schedule the agent
* @param numExecutors the number of executors (pretty much always 1)
*/
public synchronized boolean register(@Nonnull KubernetesCloud cloud, @Nonnull PodTemplate podTemplate, int numExecutors) {
public synchronized boolean register(@NonNull KubernetesCloud cloud, @NonNull PodTemplate podTemplate, int numExecutors) {
int newGlobalCount = getGlobalCount(cloud.name) + numExecutors;
if (newGlobalCount <= cloud.getContainerCap()) {
int newPodTemplateCount = getPodTemplateCount(podTemplate.getId()) + numExecutors;
Expand Down Expand Up @@ -96,7 +95,7 @@ public synchronized boolean register(@Nonnull KubernetesCloud cloud, @Nonnull Po
* @param podTemplate the pod template used to schedule the agent
* @param numExecutors the number of executors (pretty much always 1)
*/
public synchronized void unregister(@Nonnull KubernetesCloud cloud, @Nonnull PodTemplate podTemplate, int numExecutors) {
public synchronized void unregister(@NonNull KubernetesCloud cloud, @NonNull PodTemplate podTemplate, int numExecutors) {
int newGlobalCount = getGlobalCount(cloud.name) - numExecutors;
if (newGlobalCount < 0) {
LOGGER.log(Level.WARNING, "Global count for " + cloud.name + " went below zero. There is likely a bug in kubernetes-plugin");
Expand All @@ -112,13 +111,13 @@ public synchronized void unregister(@Nonnull KubernetesCloud cloud, @Nonnull Pod
LOGGER.log(Level.FINEST, () -> podTemplate.getName() + " template limit: " + Math.max(0, newPodTemplateCount) + "/" + podTemplate.getInstanceCap());
}

@Nonnull
@NonNull
@Restricted(NoExternalUse.class)
int getGlobalCount(String cloudName) {
return cloudCounts.getOrDefault(cloudName, 0);
}

@Nonnull
@NonNull
@Restricted(NoExternalUse.class)
int getPodTemplateCount(String podTemplate) {
return podTemplateCounts.getOrDefault(podTemplate, 0);
Expand All @@ -127,7 +126,7 @@ int getPodTemplateCount(String podTemplate) {
@Extension
public static class NodeListenerImpl extends NodeListener {
@Override
protected void onDeleted(@Nonnull Node node) {
protected void onDeleted(@NonNull Node node) {
if (node instanceof KubernetesSlave) {
KubernetesSlave kubernetesNode = (KubernetesSlave) node;
PodTemplate template = kubernetesNode.getTemplateOrNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.FilePath;
import hudson.Util;
import hudson.slaves.SlaveComputer;
Expand Down Expand Up @@ -46,7 +45,6 @@
import hudson.slaves.Cloud;
import hudson.slaves.CloudRetentionStrategy;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.OfflineCause;
import hudson.slaves.RetentionStrategy;
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.KubernetesClient;
Expand Down Expand Up @@ -76,15 +74,15 @@ public class KubernetesSlave extends AbstractCloudSlave {

private final String cloudName;
private String namespace;
@Nonnull
@NonNull
private String podTemplateId;
private transient PodTemplate template;
private transient Set<Queue.Executable> executables = new HashSet<>();

@CheckForNull
private transient Pod pod;

@Nonnull
@NonNull
public PodTemplate getTemplate() {
// Look up updated pod template after a restart
PodTemplate template = getTemplateOrNull();
Expand All @@ -94,7 +92,7 @@ public PodTemplate getTemplate() {
return template;
}

@Nonnull
@NonNull
public String getTemplateId() {
return podTemplateId;
}
Expand Down Expand Up @@ -147,7 +145,7 @@ public KubernetesSlave(PodTemplate template, String nodeDescription, String clou
this(getSlaveName(template), template, nodeDescription, cloudName, labelStr, new KubernetesLauncher(), rs);
}

protected KubernetesSlave(String name, @Nonnull PodTemplate template, String nodeDescription, String cloudName, String labelStr,
protected KubernetesSlave(String name, @NonNull PodTemplate template, String nodeDescription, String cloudName, String labelStr,
ComputerLauncher computerLauncher, RetentionStrategy rs)
throws Descriptor.FormException, IOException {
super(name, null, computerLauncher);
Expand All @@ -166,11 +164,11 @@ public String getCloudName() {
return cloudName;
}

public void setNamespace(@Nonnull String namespace) {
public void setNamespace(@NonNull String namespace) {
this.namespace = namespace;
}

@Nonnull
@NonNull
public String getNamespace() {
return namespace;
}
Expand Down Expand Up @@ -225,7 +223,7 @@ public Optional<Pod> getPod() {
* @return the cloud instance which created this agent.
* @throws IllegalStateException if the cloud doesn't exist anymore, or is not a {@link KubernetesCloud}.
*/
@Nonnull
@NonNull
public KubernetesCloud getKubernetesCloud() {
return getKubernetesCloud(getCloudName());
}
Expand Down
Loading