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

Offering default methods on ParameterizedJob #2864

Merged
merged 7 commits into from
May 13, 2017

Conversation

jglick
Copy link
Member

@jglick jglick commented May 1, 2017

Description

Allows subtypes to have less boilerplate. Mentioned as a design pattern in #2730.

Changelog entries

None required.

Desired reviewers

@reviewbybees

@jglick jglick requested a review from abayer May 1, 2017 19:34
@ghost
Copy link

ghost commented May 1, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

* Cancels a scheduled build.
* @see ParameterizedJobMixIn#doCancelQueue
*/
@RequirePOST
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jglick
Copy link
Member Author

jglick commented May 1, 2017

[ERROR] …/core/src/main/java/jenkins/model/ParameterizedJobMixIn.java:165: error: reference not found
[ERROR] * Standard implementations of {@link ParameterizedJob#isParametrized}.
[ERROR] ^
[ERROR] 

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda 🐛 since it advertises non-Restricted & non-RequirePOST method in all ParameterizedJob implementations. Even though it is a historic API in AbstractProject, I am not sure we want to offer it in other job types

* Schedules a new build command.
* @see ParameterizedJobMixIn#doBuild
*/
default void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, no Restricted/RequirePOST annotations here? I am not sure it is safe to offer such default impl. 🐛 , but probably I miss something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original had neither annotation. @Restricted cannot be added compatibly. @RequirePOST is unwanted since the implementation checks the request method explicitly.

* Currently only String parameters are supported.
* @see ParameterizedJobMixIn#doBuildWithParameters
*/
default void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member

@stephenc stephenc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

The public doBuild method that is being moved does not currently have any annotations, so while I think it should have a @RequirePOST annotation, this refactoring is not making the code worse than it already is and therefore the lack of an annotation is not blocking this PR IMHO

@oleg-nenashev
Copy link
Member

oleg-nenashev commented May 2, 2017

@stephenc

... this refactoring is not making the code worse than it already is and therefore the lack of an annotation is not blocking this PR IMHO

From what I see it adds new API to the ParameterizedJob interface (new default method doBuilds(), which was not defined in the interface before), so IMHO it makes the code worse.

@stephenc
Copy link
Member

stephenc commented May 2, 2017

From what I see it adds new API to the ParameterizedJob interface (new default method doBuilds(), which was not defined in the interface before), so IMHO it makes the code worse.

Well ParameterizedJob is a marker interface and this is just a refactoring of methods in classes implementing that marker interface, so I see it as non-blocking for this PR but the lack of annotation should be fixed (just in a different PR with a separate JIRA to track that change as I think the annotation change could affect users that may have been accidentally using the "feature" so to co-mingle with this PR would hide the change)

return getParameterizedJobMixIn().scheduleBuild(quietPeriod, c);
}

// omitting scheduleBuild2(int, Action...) since it is defined in SCMTriggerItem (could include less commonly used overloads if desired)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually as per this tip it could be defined here. Implementing classes would still need to define the method, but at least they could select a known super implementation, which is probably more discoverable than looking for similar methods on a mixin.


// omitting scheduleBuild2(int, Action...) since it is defined in SCMTriggerItem (could include less commonly used overloads if desired)

// cannot offer makeSearchIndex() since it is defined in Job
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case would still be tricky however, since the defining method is protected and we do not really want to force implementations to override it as public.

* Schedules a new build command.
* @see ParameterizedJobMixIn#doBuild
*/
default void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original had neither annotation. @Restricted cannot be added compatibly. @RequirePOST is unwanted since the implementation checks the request method explicitly.

@jglick jglick added the work-in-progress The PR is under active development, not ready to the final review label May 2, 2017
@jglick
Copy link
Member Author

jglick commented May 2, 2017

Test failures are bogus.

Withdrawing for the moment since I want to check if I can offer default versions of even (public) methods defined in supertypes.

@jglick
Copy link
Member Author

jglick commented May 2, 2017

Hmm,

Failed to execute goal com.infradna.tool:bridge-method-injector:1.15:process (default) on project jenkins-core: Failed to process @WithBridgeMethods: Failed to process …/core/target/classes/hudson/model/AbstractProject.class: INVOKESPECIAL/STATIC on interfaces require ASM 5

seems like exactly what jenkinsci/bridge-method-injector#14 should have been solving. Investigating.

@jglick jglick removed the work-in-progress The PR is under active development, not ready to the final review label May 2, 2017
@jglick jglick added the needs-more-reviews Complex change, which would benefit from more eyes label May 3, 2017
@jglick jglick dismissed oleg-nenashev’s stale review May 8, 2017 15:29

Explained a week ago why the design is intentional; no response since.

@jglick
Copy link
Member Author

jglick commented May 9, 2017

BTW test failures in this & related PRs are due to INFRA-1176; will make sure tests pass before merging.

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked all usages of "instanceof BuildableItem". Actually there are extra implementations in tests, but I do not see anything risky within jenkinsci org and several other repos I usually check. And yes, the ParameterizedJobMixIn seems to be always buildable according to Javadoc

Here is a list of ones which attracted my attention:

*/
public interface ParameterizedJob extends hudson.model.Queue.Task, hudson.model.Item {
public interface ParameterizedJob<JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob<JobT, RunT> & Queue.Task, RunT extends Run<JobT, RunT> & Queue.Executable> extends BuildableItem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To follow-up on my bug in #2874 (comment) . Effectively it makes any any Parameterized job explicitly buildable. After some consideration, it seems to be a valid change according to the ParameterizedJobMixIn documentation.

🐜 since I expect ParameterizedJob Javadoc to explicitly say it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the mixin Javadoc does say

be scheduled in various ways

which I guess is enough. Anyway BuildableItem is an interface which is not used all that much and not especially interesting to people grokking this code.

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐝 after the review of possible regressions due to making all ParameterizedJobs BuildableItems.

@reviewbybees done, passing to @jenkinsci/code-reviewers

@@ -143,7 +143,7 @@
* @see AbstractBuild
*/
@SuppressWarnings("rawtypes")
public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Job<P,R> implements BuildableItem, LazyBuildMixIn.LazyLoadingJob<P,R>, ParameterizedJobMixIn.ParameterizedJob {
public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Job<P,R> implements BuildableItem, LazyBuildMixIn.LazyLoadingJob<P,R>, ParameterizedJobMixIn.ParameterizedJob<P, R> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implements BuildableItem is now redundant, could be removed I guess.

I have checked all usages of "instanceof BuildableItem".

The only implementations of ParameterizedJob were already BuildableItems so retrofitting it to implement that interface should not cause any behavioral change even if someone were doing that instanceof check.

@oleg-nenashev
Copy link
Member

According to the discussion at the governance meeting on May 10, merging it towards 2.61

@oleg-nenashev oleg-nenashev merged commit 37dfa99 into jenkinsci:master May 13, 2017
Ykus pushed a commit to Ykus/jenkins that referenced this pull request May 13, 2017
* Offering default methods on ParameterizedJob.

* Javadoc typo.

* Cleaner use of default methods in ParameterizedJob.

* Need to pick up jenkinsci/bridge-method-injector#15 to be able to build.

* Using new type bounds.

* bridge-method-injector 1.17
@jglick jglick deleted the ParameterizedJobMixIn-defaults branch May 15, 2017 13:56
jglick added a commit to jglick/maven-plugin that referenced this pull request Jan 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-reviews Complex change, which would benefit from more eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants