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

Update @Nullable/@NonNull annotations #391

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -5,11 +5,12 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Nonnull;
import net.sf.json.JSONObject;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
import org.datadog.jenkins.plugins.datadog.model.BuildData;
import org.datadog.jenkins.plugins.datadog.model.PipelineStepData;
import org.datadog.jenkins.plugins.datadog.model.PipelineNodeInfoAction;
import org.datadog.jenkins.plugins.datadog.model.PipelineStepData;
import org.datadog.jenkins.plugins.datadog.util.SuppressFBWarnings;


Expand All @@ -21,6 +22,7 @@ public abstract class DatadogBasePipelineLogic {
protected static final String CI_PROVIDER = "jenkins";
protected static final String HOSTNAME_NONE = "none";

@Nonnull
public abstract JSONObject toJson(PipelineStepData current, Run<?, ?> run) throws IOException, InterruptedException;

@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.datadog.jenkins.plugins.datadog.clients.DatadogAgentClient;
import org.datadog.jenkins.plugins.datadog.model.BuildData;
Expand Down Expand Up @@ -53,7 +54,7 @@ public Payload serialize(BuildData buildData, Run<?, ?> run) {
return getCurrentStrategy().serialize(buildData, run);
}

@Nullable
@Nonnull
@Override
public Payload serialize(PipelineStepData stepData, Run<?, ?> run) throws IOException, InterruptedException {
return getCurrentStrategy().serialize(stepData, run);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hudson.model.Run;
import java.io.IOException;
import java.util.Collection;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.datadog.jenkins.plugins.datadog.model.BuildData;
import org.datadog.jenkins.plugins.datadog.model.PipelineStepData;
Expand All @@ -11,7 +12,7 @@ public interface TraceWriteStrategy {
@Nullable
Payload serialize(BuildData buildData, Run<?, ?> run);

@Nullable
@Nonnull
Payload serialize(PipelineStepData stepData, Run<?, ?> run) throws IOException, InterruptedException;

void send(Collection<Payload> spans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Collection;
import java.util.function.Consumer;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.sf.json.JSONObject;
import org.datadog.jenkins.plugins.datadog.DatadogUtilities;
Expand Down Expand Up @@ -52,11 +53,11 @@ public Payload serialize(final BuildData buildData, final Run<?, ?> run) {
return buildSpan != null ? new Payload(buildSpan, track) : null;
}

@Nullable
@Nonnull
@Override
public Payload serialize(PipelineStepData stepData, Run<?, ?> run) throws IOException, InterruptedException {
JSONObject stepSpan = pipelineLogic.toJson(stepData, run);
return stepSpan != null ? new Payload(stepSpan, track) : null;
return new Payload(stepSpan, track);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.sf.json.JSONObject;
import org.datadog.jenkins.plugins.datadog.DatadogClient;
Expand All @@ -56,6 +57,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.datadog.jenkins.plugins.datadog.traces.write.Payload;
import org.datadog.jenkins.plugins.datadog.traces.write.TraceWriteStrategy;
import org.datadog.jenkins.plugins.datadog.traces.write.Track;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;

public class DatadogClientStub implements DatadogClient {
Expand Down Expand Up @@ -304,21 +306,15 @@ public Payload serialize(BuildData buildData, Run<?, ?> run) {
}
}

@Nullable
@Nonnull
@Override
public Payload serialize(PipelineStepData stepData, Run<?, ?> run) throws IOException, InterruptedException {
public @NotNull Payload serialize(PipelineStepData stepData, Run<?, ?> run) throws IOException, InterruptedException {
if (isWebhook) {
JSONObject json = new DatadogWebhookPipelineLogic().toJson(stepData, run);
if (json == null) {
return null;
}
webhooks.add(json);
return new Payload(json, Track.WEBHOOK);
} else {
TraceSpan span = new DatadogTracePipelineLogic().toSpan(stepData, run);
if (span == null) {
return null;
}
traces.add(span);
JSONObject json = new JsonTraceSpanMapper().map(span);
return new Payload(json, Track.APM);
Expand Down
Loading