Skip to content

Commit

Permalink
Replace JSR-305 annotations with spotbugs annotations
Browse files Browse the repository at this point in the history
Annotations for Nonnull, CheckForNull, and several others were proposed
for Java as part of dormant Java specification request JSR-305. The
proposal never became a part of standard Java.

Jenkins plugins should switch from using JSR-305 annotations to use
Spotbugs annotations that provide the same semantics.

https://groups.google.com/g/jenkinsci-dev/c/uE1wwtVi1W0/m/gLxdEJmlBQAJ is
the mailing list discussion from James Nord that describes the affected
annotations and why they should be replaced with annotations that are
actively maintained.

https://www.jenkins.io/doc/developer/tutorial-improve/replace-jsr-305-annotations/
provides instructions to perform this change.

https://docs.openrewrite.org/recipes/jenkins/javaxannotationstospotbugs
provides an OpenRewrite recipe for the change.  The OpenRewrite recipe
is even better than the instructions.
  • Loading branch information
MarkEWaite committed May 7, 2024
1 parent 9186970 commit 0ce8013
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package ru.yandex.qatools.allure.jenkins;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
Expand Down Expand Up @@ -48,8 +49,7 @@
import ru.yandex.qatools.allure.jenkins.utils.FilePathUtils;
import ru.yandex.qatools.allure.jenkins.utils.TrueZipArchiver;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -101,7 +101,7 @@ public class AllureReportPublisher extends Recorder implements SimpleBuildStep,
private String report;

@DataBoundConstructor
public AllureReportPublisher(final @Nonnull List<ResultsConfig> results) {
public AllureReportPublisher(final @NonNull List<ResultsConfig> results) {
this.results = results;
}

Expand Down Expand Up @@ -156,9 +156,9 @@ public String getCommandline() {
}

private AllureCommandlineInstallation getCommandline(
final @Nonnull Launcher launcher,
final @Nonnull TaskListener listener,
final @Nonnull EnvVars env)
final @NonNull Launcher launcher,
final @NonNull TaskListener listener,
final @NonNull EnvVars env)
throws IOException, InterruptedException {

// discover commandline
Expand Down Expand Up @@ -226,29 +226,29 @@ public String getConfigPath() {
return StringUtils.isNotBlank(configPath) ? configPath : null;
}

@Nonnull
@NonNull
public AllureReportConfig getConfig() {
return config;
}

@Override
@Nonnull
@NonNull
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

@Override
@Nonnull
@NonNull
public AllureReportPublisherDescriptor getDescriptor() {
return (AllureReportPublisherDescriptor) super.getDescriptor();
}

@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
@Override
public void perform(final @Nonnull Run<?, ?> run,
final @Nonnull FilePath workspace,
final @Nonnull Launcher launcher,
final @Nonnull TaskListener listener) throws InterruptedException, IOException {
public void perform(final @NonNull Run<?, ?> run,
final @NonNull FilePath workspace,
final @NonNull Launcher launcher,
final @NonNull TaskListener listener) throws InterruptedException, IOException {
if (isDisabled()) {
listener.getLogger().println("Allure report is disabled.");
return;
Expand Down Expand Up @@ -282,9 +282,9 @@ public void perform(final @Nonnull Run<?, ?> run,
* between perform and createAggregator, because for concurrent builds (Jenkins provides such feature)
* state objects will be corrupted.
*/
private void copyResultsToParentIfNeeded(final @Nonnull List<FilePath> results,
final @Nonnull Run<?, ?> run,
final @Nonnull TaskListener listener
private void copyResultsToParentIfNeeded(final @NonNull List<FilePath> results,
final @NonNull Run<?, ?> run,
final @NonNull TaskListener listener
) throws IOException, InterruptedException {
if (run instanceof MatrixRun) {
final MatrixBuild parentBuild = ((MatrixRun) run).getParentBuild();
Expand Down Expand Up @@ -328,11 +328,11 @@ public boolean endBuild() throws InterruptedException, IOException {
}

@SuppressWarnings("TrailingComment")
private void generateReport(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull Run<?, ?> run,
final @Nonnull FilePath workspace,
final @Nonnull Launcher launcher,
final @Nonnull TaskListener listener
private void generateReport(final @NonNull List<FilePath> resultsPaths,
final @NonNull Run<?, ?> run,
final @NonNull FilePath workspace,
final @NonNull Launcher launcher,
final @NonNull TaskListener listener
) throws IOException, InterruptedException { //NOSONAR

final ReportBuildPolicy reportBuildPolicy = getReportBuildPolicy();
Expand Down Expand Up @@ -406,27 +406,27 @@ private void setAllureProperties(final EnvVars envVars) {
envVars.put("ALLURE_OPTS", options.toString());
}

@Nonnull
@NonNull
@Override
public Collection<? extends Action> getProjectActions(final AbstractProject<?, ?> project) {
return Collections.singleton(new AllureReportProjectAction(
project
));
}

private void prepareResults(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull Run<?, ?> run,
final @Nonnull FilePath workspace,
final @Nonnull TaskListener listener)
private void prepareResults(final @NonNull List<FilePath> resultsPaths,
final @NonNull Run<?, ?> run,
final @NonNull FilePath workspace,
final @NonNull TaskListener listener)
throws IOException, InterruptedException {
addHistory(resultsPaths, run, workspace, listener);
addTestRunInfo(resultsPaths, run);
addExecutorInfo(resultsPaths, run);
}

@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private void addTestRunInfo(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull Run<?, ?> run)
private void addTestRunInfo(final @NonNull List<FilePath> resultsPaths,
final @NonNull Run<?, ?> run)
throws IOException, InterruptedException {
final long start = run.getStartTimeInMillis();
final long stop = run.getTimeInMillis();
Expand All @@ -435,8 +435,8 @@ private void addTestRunInfo(final @Nonnull List<FilePath> resultsPaths,
}
}

private void addExecutorInfo(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull Run<?, ?> run)
private void addExecutorInfo(final @NonNull List<FilePath> resultsPaths,
final @NonNull Run<?, ?> run)
throws IOException, InterruptedException {

final String rootUrl = Jenkins.get().getRootUrl();
Expand All @@ -450,10 +450,10 @@ private void addExecutorInfo(final @Nonnull List<FilePath> resultsPaths,
}
}

private void addHistory(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull Run<?, ?> run,
final @Nonnull FilePath workspace,
final @Nonnull TaskListener listener) {
private void addHistory(final @NonNull List<FilePath> resultsPaths,
final @NonNull Run<?, ?> run,
final @NonNull FilePath workspace,
final @NonNull TaskListener listener) {
try {
final String reportPath = workspace.child(getReport()).getName();
final FilePath previousReport = FilePathUtils.getPreviousReportWithHistory(run, reportPath);
Expand All @@ -467,9 +467,9 @@ private void addHistory(final @Nonnull List<FilePath> resultsPaths,
}
}

private void copyHistoryToResultsPaths(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull FilePath previousReport,
final @Nonnull FilePath workspace)
private void copyHistoryToResultsPaths(final @NonNull List<FilePath> resultsPaths,
final @NonNull FilePath previousReport,
final @NonNull FilePath workspace)
throws IOException, InterruptedException {
try (ZipFile archive = new ZipFile(previousReport.getRemote())) {
for (FilePath resultsPath : resultsPaths) {
Expand All @@ -479,8 +479,8 @@ private void copyHistoryToResultsPaths(final @Nonnull List<FilePath> resultsPath
}

private void copyHistoryToResultsPath(final ZipFile archive,
final @Nonnull FilePath resultsPath,
final @Nonnull FilePath workspace)
final @NonNull FilePath resultsPath,
final @NonNull FilePath workspace)
throws IOException, InterruptedException {
final FilePath reportPath = workspace.child(getReport());
for (final ZipEntry historyEntry : listEntries(archive, reportPath.getName() + "/history")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.AutoCompletionCandidates;
Expand All @@ -33,7 +34,6 @@
import ru.yandex.qatools.allure.jenkins.config.ReportBuildPolicy;
import ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void setProperties(final List<PropertyConfig> properties) {
}

@Override
@Nonnull
@NonNull
public String getDisplayName() {
return Messages.AllureReportPublisher_DisplayName();
}
Expand All @@ -85,7 +85,7 @@ public ReportBuildPolicy[] getReportBuildPolicies() {
}

@SuppressWarnings("unused")
@Nonnull
@NonNull
public AutoCompletionCandidates doAutoCompletePropertyKey() {
final AutoCompletionCandidates candidates = new AutoCompletionCandidates();
candidates.add("allure.issues.tracker.pattern");
Expand Down Expand Up @@ -113,7 +113,7 @@ public boolean configure(final StaplerRequest req,
return true;
}

@Nonnull
@NonNull
public List<AllureCommandlineInstallation> getCommandlineInstallations() {
return Optional.of(Jenkins.get())
.map(j -> j.getDescriptorByType(AllureCommandlineInstallation.DescriptorImpl.class))
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/ru/yandex/qatools/allure/jenkins/ReportBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package ru.yandex.qatools.allure.jenkins;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.TaskListener;
import hudson.util.ArgumentListBuilder;
import ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.List;

Expand All @@ -49,11 +49,11 @@ public class ReportBuilder {

private FilePath configFilePath;

public ReportBuilder(final @Nonnull Launcher launcher,
final @Nonnull TaskListener listener,
final @Nonnull FilePath workspace,
final @Nonnull EnvVars envVars,
final @Nonnull AllureCommandlineInstallation commandline) {
public ReportBuilder(final @NonNull Launcher launcher,
final @NonNull TaskListener listener,
final @NonNull FilePath workspace,
final @NonNull EnvVars envVars,
final @NonNull AllureCommandlineInstallation commandline) {
this.workspace = workspace;
this.launcher = launcher;
this.listener = listener;
Expand All @@ -65,8 +65,8 @@ public void setConfigFilePath(final FilePath configFilePath) {
this.configFilePath = configFilePath;
}

public int build(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull FilePath reportPath) //NOSONAR
public int build(final @NonNull List<FilePath> resultsPaths,
final @NonNull FilePath reportPath) //NOSONAR
throws IOException, InterruptedException {
final String version = commandline.getMajorVersion(launcher);
final ArgumentListBuilder arguments = getArguments(version, resultsPaths, reportPath);
Expand All @@ -76,15 +76,15 @@ public int build(final @Nonnull List<FilePath> resultsPaths,
}

private ArgumentListBuilder getArguments(final String version,
final @Nonnull List<FilePath> resultsPaths,
final @Nonnull FilePath reportPath)
final @NonNull List<FilePath> resultsPaths,
final @NonNull FilePath reportPath)
throws IOException, InterruptedException {
return version.startsWith("2") ? getAllure2Arguments(resultsPaths, reportPath)
: getAllure1Arguments(resultsPaths, reportPath);
}

private ArgumentListBuilder getAllure2Arguments(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull FilePath reportPath) //NOSONAR
private ArgumentListBuilder getAllure2Arguments(final @NonNull List<FilePath> resultsPaths,
final @NonNull FilePath reportPath) //NOSONAR
throws IOException, InterruptedException {
final ArgumentListBuilder arguments = new ArgumentListBuilder();
arguments.add(commandline.getExecutable(launcher));
Expand All @@ -102,8 +102,8 @@ private ArgumentListBuilder getAllure2Arguments(final @Nonnull List<FilePath> re
return arguments;
}

private ArgumentListBuilder getAllure1Arguments(final @Nonnull List<FilePath> resultsPaths,
final @Nonnull FilePath reportPath) //NOSONAR
private ArgumentListBuilder getAllure1Arguments(final @NonNull List<FilePath> resultsPaths,
final @NonNull FilePath reportPath) //NOSONAR
throws IOException, InterruptedException {
final ArgumentListBuilder arguments = new ArgumentListBuilder();
arguments.add(commandline.getExecutable(launcher));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package ru.yandex.qatools.allure.jenkins.config;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import javax.annotation.Nonnull;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -78,7 +78,7 @@ public String getCommandline() {
return commandline;
}

@Nonnull
@NonNull
@SuppressWarnings("deprecation")
public List<ResultsConfig> getResults() {
if (StringUtils.isNotBlank(this.resultsPattern)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package ru.yandex.qatools.allure.jenkins.tools;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Functions;
Expand All @@ -33,7 +34,6 @@
import org.kohsuke.stapler.DataBoundConstructor;
import ru.yandex.qatools.allure.jenkins.Messages;

import javax.annotation.Nonnull;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -59,11 +59,11 @@ public AllureCommandlineInstallation(final String name,
}

@SuppressWarnings("TrailingComment")
public String getExecutable(final @Nonnull Launcher launcher) throws InterruptedException, IOException { //NOSONAR
public String getExecutable(final @NonNull Launcher launcher) throws InterruptedException, IOException { //NOSONAR
return launcher.getChannel().call(new GetExecutable(getHome()));
}

public String getMajorVersion(final @Nonnull Launcher launcher) throws InterruptedException, IOException {
public String getMajorVersion(final @NonNull Launcher launcher) throws InterruptedException, IOException {
return launcher.getChannel().call(new GetMajorVersion(getHome()));
}

Expand Down Expand Up @@ -100,12 +100,12 @@ private static Path getExecutablePath(final String rawHome) {
}

@Override
public AllureCommandlineInstallation forEnvironment(final @Nonnull EnvVars environment) {
public AllureCommandlineInstallation forEnvironment(final @NonNull EnvVars environment) {
return new AllureCommandlineInstallation(getName(), environment.expand(getHome()), getProperties().toList());
}

@Override
public AllureCommandlineInstallation forNode(final @Nonnull Node node,
public AllureCommandlineInstallation forNode(final @NonNull Node node,
final TaskListener log)
throws IOException, InterruptedException {
return new AllureCommandlineInstallation(getName(), translateFor(node, log), getProperties().toList());
Expand Down Expand Up @@ -161,7 +161,7 @@ public DescriptorImpl() {
}

@Override
@Nonnull
@NonNull
public String getDisplayName() {
return Messages.AllureCommandlineInstallation_DisplayName();
}
Expand Down
Loading

0 comments on commit 0ce8013

Please sign in to comment.