-
Notifications
You must be signed in to change notification settings - Fork 402
[FIXED JENKINS-39553] Make GitHub plugin BuildableItem aware #153
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
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import hudson.Util; | ||
| import hudson.model.AbstractProject; | ||
| import hudson.model.EnvironmentContributor; | ||
| import hudson.model.Item; | ||
| import hudson.model.Job; | ||
| import hudson.model.TaskListener; | ||
| import hudson.plugins.git.GitSCM; | ||
|
|
@@ -36,41 +37,57 @@ public abstract class GitHubRepositoryNameContributor implements ExtensionPoint | |
| * Looks at the definition of {@link AbstractProject} and list up the related github repositories, | ||
| * then puts them into the collection. | ||
| * | ||
| * @deprecated Use {@link #parseAssociatedNames(Job, Collection)} | ||
| * @deprecated Use {@link #parseAssociatedNames(Item, Collection)} | ||
| */ | ||
| @Deprecated | ||
| public void parseAssociatedNames(AbstractProject<?, ?> job, Collection<GitHubRepositoryName> result) { | ||
| parseAssociatedNames((Job) job, result); | ||
| parseAssociatedNames((Item) job, result); | ||
| } | ||
|
|
||
| /** | ||
| * Looks at the definition of {@link Job} and list up the related github repositories, | ||
| * then puts them into the collection. | ||
| * @deprecated Use {@link #parseAssociatedNames(Item, Collection)} | ||
| */ | ||
| @Deprecated | ||
| public /*abstract*/ void parseAssociatedNames(Job<?, ?> job, Collection<GitHubRepositoryName> result) { | ||
| if (overriddenMethodHasDeprecatedSignature(job)) { | ||
| parseAssociatedNames((AbstractProject) job, result); | ||
| } else { | ||
| throw new AbstractMethodError("you must override the new overload of parseAssociatedNames"); | ||
| } | ||
| parseAssociatedNames((Item) job, result); | ||
| } | ||
|
|
||
| /** | ||
| * To select backward compatible method with old extensions | ||
| * with overridden {@link #parseAssociatedNames(AbstractProject, Collection)} | ||
| * | ||
| * @param job - parameter to check for old class | ||
| * | ||
| * @return true if overridden deprecated method | ||
| * Looks at the definition of {@link Item} and list up the related github repositories, | ||
| * then puts them into the collection. | ||
| * @param item the item. | ||
| * @param result the collection to add repository names to | ||
| * @since FIXME | ||
| */ | ||
| private boolean overriddenMethodHasDeprecatedSignature(Job<?, ?> job) { | ||
| return Util.isOverridden( | ||
| @SuppressWarnings("deprecation") | ||
| public /*abstract*/ void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) { | ||
| if (Util.isOverridden( | ||
| GitHubRepositoryNameContributor.class, | ||
| getClass(), | ||
| "parseAssociatedNames", | ||
| Job.class, | ||
| Collection.class | ||
| )) { | ||
| // if this impl is legacy, it cannot contribute to non-jobs, so not an error | ||
| if (item instanceof Job) { | ||
| parseAssociatedNames((Job<?, ?>) item, result); | ||
|
Member
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. Maybe put a warning on the FINE level? Just in case somebody needs to debug the compat issue |
||
| } | ||
| } else if (Util.isOverridden( | ||
| GitHubRepositoryNameContributor.class, | ||
| getClass(), | ||
| "parseAssociatedNames", | ||
| AbstractProject.class, | ||
| Collection.class | ||
| ) && job instanceof AbstractProject; | ||
| )) { | ||
| // if this impl is legacy, it cannot contribute to non-projects, so not an error | ||
| if (item instanceof AbstractProject) { | ||
| parseAssociatedNames((AbstractProject<?, ?>) item, result); | ||
| } | ||
| } else { | ||
| throw new AbstractMethodError("you must override the new overload of parseAssociatedNames"); | ||
|
Member
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. 🐛 So it will expose the error when somebody uses Predicates like IMHO there should be one of the following fixes:
Member
Author
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. Actually this is more a design error in the original API. These methods taking the collection should actually have been If you have an old implementation, then you will have overridden If you have a new implementation, then you are supposed to override If we had these SPI methods as
Member
Author
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. Also please check the previous implementation of The exception will only be thrown if you have an implementation that does not override any To clarify for @KostyaSha this is not a bug just migration of existing pattern
Member
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. @stephenc only since |
||
| } | ||
| } | ||
|
|
||
| public static ExtensionList<GitHubRepositoryNameContributor> all() { | ||
|
|
@@ -82,13 +99,21 @@ public static ExtensionList<GitHubRepositoryNameContributor> all() { | |
| */ | ||
| @Deprecated | ||
| public static Collection<GitHubRepositoryName> parseAssociatedNames(AbstractProject<?, ?> job) { | ||
| return parseAssociatedNames((Job) job); | ||
| return parseAssociatedNames((Item) job); | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated Use {@link #parseAssociatedNames(Item)} | ||
| */ | ||
| @Deprecated | ||
| public static Collection<GitHubRepositoryName> parseAssociatedNames(Job<?, ?> job) { | ||
| return parseAssociatedNames((Item) job); | ||
| } | ||
|
|
||
| public static Collection<GitHubRepositoryName> parseAssociatedNames(Item item) { | ||
| Set<GitHubRepositoryName> names = new HashSet<GitHubRepositoryName>(); | ||
| for (GitHubRepositoryNameContributor c : all()) { | ||
| c.parseAssociatedNames(job, names); | ||
| c.parseAssociatedNames(item, names); | ||
| } | ||
| return names; | ||
| } | ||
|
|
@@ -99,11 +124,11 @@ public static Collection<GitHubRepositoryName> parseAssociatedNames(Job<?, ?> jo | |
| @Extension | ||
| public static class FromSCM extends GitHubRepositoryNameContributor { | ||
| @Override | ||
| public void parseAssociatedNames(Job<?, ?> job, Collection<GitHubRepositoryName> result) { | ||
| SCMTriggerItem item = SCMTriggerItems.asSCMTriggerItem(job); | ||
| EnvVars envVars = buildEnv(job); | ||
| if (item != null) { | ||
| for (SCM scm : item.getSCMs()) { | ||
| public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) { | ||
| SCMTriggerItem triggerItem = SCMTriggerItems.asSCMTriggerItem(item); | ||
| EnvVars envVars = item instanceof Job ? buildEnv((Job) item) : new EnvVars(); | ||
| if (triggerItem != null) { | ||
| for (SCM scm : triggerItem.getSCMs()) { | ||
| addRepositories(scm, envVars, result); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.google.common.base.Function; | ||
| import hudson.Extension; | ||
| import hudson.ExtensionPoint; | ||
| import hudson.model.Item; | ||
| import hudson.model.Job; | ||
| import hudson.model.RootAction; | ||
| import hudson.model.UnprotectedRootAction; | ||
|
|
@@ -70,21 +71,36 @@ public String getUrlName() { | |
| * {@code GitHubWebHook.get().registerHookFor(job);} | ||
| * | ||
| * @param job not null project to register hook for | ||
| * @deprecated use {@link #registerHookFor(Item)} | ||
| */ | ||
| @Deprecated | ||
| public void registerHookFor(Job job) { | ||
| reRegisterHookForJob().apply(job); | ||
| } | ||
|
|
||
| /** | ||
| * If any wants to auto-register hook, then should call this method | ||
| * Example code: | ||
| * {@code GitHubWebHook.get().registerHookFor(item);} | ||
| * | ||
| * @param item not null item to register hook for | ||
| * @since FIXME | ||
| */ | ||
| public void registerHookFor(Item item) { | ||
|
Member
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.
|
||
| reRegisterHookForJob().apply(item); | ||
| } | ||
|
|
||
| /** | ||
| * Calls {@link #registerHookFor(Job)} for every project which have subscriber | ||
| * | ||
| * @return list of jobs which jenkins tried to register hook | ||
| */ | ||
| public List<Job> reRegisterAllHooks() { | ||
| return from(getJenkinsInstance().getAllItems(Job.class)) | ||
| public List<Item> reRegisterAllHooks() { | ||
| return from(getJenkinsInstance().getAllItems(Item.class)) | ||
| .filter(isBuildable()) | ||
| .filter(isAlive()) | ||
| .transform(reRegisterHookForJob()).toList(); | ||
| .transform(reRegisterHookForJob()) | ||
| .toList(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -101,11 +117,11 @@ public void doIndex(@Nonnull @GHEventHeader GHEvent event, @Nonnull @GHEventPayl | |
| .transform(processEvent(event, payload)).toList(); | ||
| } | ||
|
|
||
| private Function<Job, Job> reRegisterHookForJob() { | ||
| return new Function<Job, Job>() { | ||
| private <T extends Item> Function<T, T> reRegisterHookForJob() { | ||
| return new Function<T, T>() { | ||
| @Override | ||
| public Job apply(Job job) { | ||
| LOGGER.debug("Calling registerHooks() for {}", notNull(job, "Job can't be null").getFullName()); | ||
| public T apply(T job) { | ||
| LOGGER.debug("Calling registerHooks() for {}", notNull(job, "Item can't be null").getFullName()); | ||
|
|
||
| // We should handle wrong url of self defined hook url here in any case with try-catch :( | ||
| URL hookUrl; | ||
|
|
||
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.
@since