-
Notifications
You must be signed in to change notification settings - Fork 35
Add nonnull annotation #19
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
Changes from all commits
b9e9353
91f8fa1
f9243b8
cbce547
3149628
136dca1
5203045
24800f0
ec9ef54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package org.jenkinsci.plugins.displayurlapi; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import edu.umd.cs.findbugs.annotations.Nullable; | ||
| import hudson.ExtensionList; | ||
| import hudson.ExtensionPoint; | ||
|
|
@@ -9,15 +10,13 @@ | |
| import jenkins.model.Jenkins; | ||
| import org.apache.commons.lang.StringUtils; | ||
| import org.jenkinsci.plugins.displayurlapi.actions.AbstractDisplayAction; | ||
| import org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty; | ||
| import org.kohsuke.accmod.Restricted; | ||
| import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
|
||
| import static org.apache.commons.lang.StringUtils.isNotEmpty; | ||
|
|
||
| /** | ||
| * Generates URLs for well known UI locations for use in notifications (e.g. mailer, HipChat, Slack, IRC, etc) | ||
| * Extensible to allow plugins to override common URLs (e.g. Blue Ocean or another future secondary UI) | ||
| * Generates URLs for well known UI locations for use in notifications (e.g. mailer, HipChat, Slack, | ||
| * IRC, etc) Extensible to allow plugins to override common URLs (e.g. Blue Ocean or another future | ||
| * secondary UI) | ||
| */ | ||
| public abstract class DisplayURLProvider implements ExtensionPoint { | ||
|
|
||
|
|
@@ -35,23 +34,25 @@ public static DisplayURLProvider get() { | |
| * | ||
| * @return all the {@link DisplayURLProvider} implementations. | ||
| */ | ||
| public static Iterable<DisplayURLProvider> all() { | ||
| public static ExtensionList<DisplayURLProvider> all() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not breaking since ExtensionList is still Iterable, it just lends itself better to stream API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this, it causes problems in environments like the PCT: See BlueOceanDisplayURLImplTest. That is the only use of Based on the spec, I don't think this is a compatible change, since JARs compiled against the old class are looking for a method whose return type is |
||
| return ExtensionList.lookup(DisplayURLProvider.class); | ||
| } | ||
|
|
||
| public static DisplayURLProvider getDefault() { | ||
| DisplayURLProvider defaultProvider = getPreferredProvider(); | ||
| if (defaultProvider == null) { | ||
| defaultProvider = ExtensionList.lookup(DisplayURLProvider.class).get(ClassicDisplayURLProvider.class); | ||
| defaultProvider = ExtensionList.lookup(DisplayURLProvider.class) | ||
| .get(ClassicDisplayURLProvider.class); | ||
| } | ||
| return defaultProvider; | ||
| } | ||
|
|
||
| /** | ||
| * Fully qualified URL for the Root display URL | ||
| */ | ||
| @NonNull | ||
| public String getRoot() { | ||
| String root = Jenkins.getActiveInstance().getRootUrl(); | ||
| String root = Jenkins.getInstance().getRootUrl(); | ||
| if (root == null) { | ||
| root = "http://unconfigured-jenkins-location/"; | ||
| } | ||
|
|
@@ -61,28 +62,35 @@ public String getRoot() { | |
| /** | ||
| * Display name of this provider e.g. "Jenkins Classic", "Blue Ocean", etc | ||
| */ | ||
| @NonNull | ||
| public String getDisplayName() { | ||
| return this.getClass().getSimpleName(); | ||
| } | ||
|
|
||
| /** Name of provider to be used as an id. Do not use i18n */ | ||
| /** | ||
| * Name of provider to be used as an id. Do not use i18n | ||
| */ | ||
| @NonNull | ||
| public String getName() { | ||
| return this.getClass().getSimpleName(); | ||
| } | ||
|
|
||
| /** | ||
| * Fully qualified URL for a Run | ||
| */ | ||
| @NonNull | ||
| public abstract String getRunURL(Run<?, ?> run); | ||
|
|
||
| /** | ||
| * Fully qualified URL for a page that displays changes for a project. | ||
| */ | ||
| @NonNull | ||
| public abstract String getChangesURL(Run<?, ?> run); | ||
|
|
||
| /** | ||
| * Fully qualified URL for a Jobs home | ||
| */ | ||
| @NonNull | ||
| public abstract String getJobURL(Job<?, ?> job); | ||
|
|
||
| /** | ||
|
|
@@ -96,44 +104,39 @@ static class DisplayURLProviderImpl extends ClassicDisplayURLProvider { | |
| static final String DISPLAY_POSTFIX = AbstractDisplayAction.URL_NAME + "/redirect"; | ||
|
|
||
| @Override | ||
| @NonNull | ||
| public String getRunURL(Run<?, ?> run) { | ||
| DisplayURLContext ctx = DisplayURLContext.open(); | ||
| try { | ||
| try (DisplayURLContext ctx = DisplayURLContext.open()) { | ||
| if (ctx.run() == null) { | ||
| // the link might be generated from another run so we only add this to the context if unset | ||
| ctx.run(run); | ||
| } | ||
| return DisplayURLDecorator.decorate(ctx, super.getRunURL(run) + DISPLAY_POSTFIX); | ||
| } finally { | ||
| ctx.close(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| @NonNull | ||
| public String getChangesURL(Run<?, ?> run) { | ||
| DisplayURLContext ctx = DisplayURLContext.open(); | ||
| try { | ||
| try (DisplayURLContext ctx = DisplayURLContext.open()) { | ||
| if (ctx.run() == null) { | ||
| // the link might be generated from another run so we only add this to the context if unset | ||
| ctx.run(run); | ||
| } | ||
| return DisplayURLDecorator.decorate(ctx, super.getRunURL(run) + DISPLAY_POSTFIX + "?page=changes"); | ||
| } finally { | ||
| ctx.close(); | ||
| return DisplayURLDecorator | ||
| .decorate(ctx, super.getRunURL(run) + DISPLAY_POSTFIX + "?page=changes"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| @NonNull | ||
| public String getJobURL(Job<?, ?> job) { | ||
| DisplayURLContext ctx = DisplayURLContext.open(); | ||
| try { | ||
| try (DisplayURLContext ctx = DisplayURLContext.open()) { | ||
| if (ctx.job() == null) { | ||
| // the link might be generated from another job so we only add this to the context if unset | ||
| ctx.job(job); | ||
| } | ||
| return DisplayURLDecorator.decorate(ctx, super.getJobURL(job) + DISPLAY_POSTFIX); | ||
| } finally { | ||
| ctx.close(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,35 @@ | ||
| package org.jenkinsci.plugins.displayurlapi; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import hudson.EnvVars; | ||
| import hudson.Extension; | ||
| import hudson.model.EnvironmentContributor; | ||
| import hudson.model.Job; | ||
| import hudson.model.Run; | ||
| import hudson.model.TaskListener; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
| import java.io.IOException; | ||
|
|
||
| @Extension | ||
| public class EnvironmentContributorImpl extends EnvironmentContributor { | ||
|
|
||
| @Override | ||
| public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { | ||
| DisplayURLContext ctx = DisplayURLContext.open(); | ||
| try { | ||
| public void buildEnvironmentFor(@NonNull Run r, @NonNull EnvVars envs, @NonNull TaskListener listener) throws IOException, InterruptedException { | ||
| try (DisplayURLContext ctx = DisplayURLContext.open()) { | ||
| ctx.run(r); | ||
| ctx.plugin(null); // environment contributor "comes from" core | ||
| DisplayURLProvider urlProvider = DisplayURLProvider.get(); | ||
| envs.put("RUN_DISPLAY_URL", urlProvider.getRunURL(r)); | ||
| envs.put("RUN_CHANGES_DISPLAY_URL", urlProvider.getChangesURL(r)); | ||
| } finally { | ||
| ctx.close(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void buildEnvironmentFor(@Nonnull Job j, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { | ||
| DisplayURLContext ctx = DisplayURLContext.open(); | ||
| try { | ||
| public void buildEnvironmentFor(@NonNull Job j, @NonNull EnvVars envs, @NonNull TaskListener listener) throws IOException, InterruptedException { | ||
| try (DisplayURLContext ctx = DisplayURLContext.open()) { | ||
| ctx.job(j); | ||
| ctx.plugin(null); // environment contributor "comes from" core | ||
| envs.put("JOB_DISPLAY_URL", DisplayURLProvider.get().getJobURL(j)); | ||
| } finally { | ||
| ctx.close(); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
Jenkins.get()already available in the used Jenkins version? Then this should be used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly it is not 😢