-
Notifications
You must be signed in to change notification settings - Fork 165
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
Automation equals methods #43
Conversation
Thank you for a pull request! Please check this document for how the Jenkins project handles pull requests |
Code review, please. |
4821861
to
dae8d8c
Compare
@cloudbeesci peer review, please. |
👎 You cannot use |
@daniel-beck is there a recommended way of comparing objects? For me, something like this would be powerful for idempotent changes in configuration management. I suppose I could offload this equals functionality into the configuration management itself to stay idempotent. Though, I'm curious to hear more about your thoughts. I'm still relatively new to developing in Java. Is this by convention? Not comparing objects in this way I mean. Because technically |
@daniel-beck after further research I disagree with the following statement.
You can use It matters what properties of an object are being used for comparison. In this case, I'm comparing properties that matter between two objects. For example, I'm using the following properties to determine equality between Without implementing an |
cc @jhoblitt code review, please. |
dae8d8c
to
419043c
Compare
To clarify, you want two different instances of
Output:
|
I want to objects to be considered equal if its properties are equal. This is akin to the following example. The |
@daniel-beck the following both output println "foo".equals(new String("foo")) ? "true" : "false"
println "foo" == new String("foo") ? "true" : "false" |
Yes, because Groovy isn't Java. This code is written in Java though. |
But as you can see, I'm using Functions like |
This is exactly what I'm saying. Hence my first comment (strings are objects in Java), and the demo program I provided that shows you why you should not use |
I tried doing I've looked it up and turns out I can't do |
419043c
to
e306286
Compare
@daniel-beck I have pushed an updated commit with your feedback. Thanks for your patience. |
@daniel-beck can I get a 👍 ? |
public boolean equals(Object object){ | ||
if(object instanceof GithubAuthorizationStrategy) { | ||
GithubAuthorizationStrategy obj = (GithubAuthorizationStrategy) object; | ||
return ( |
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.
Superfluous surrounding parentheses.
I'm not familiar with this plugin, so I have no idea regarding the larger ideas behind this PR. That prevents me from providing 👍, however, I can say that there are only minor nitpicks left from my POV. |
* Add equals method to GithubAuthorizationStrategy * Add equals method to GithubSecurityRealm * GithubAuthorizationStrategy equals unit tests * GithubSecurityRealm equals unit tests
e306286
to
7d3c78d
Compare
Updated the pull request with the latest feedback. As soon as it verifies good I'll merge it. |
Add equals methods to
GithubAuthorizationStrategy
andGithubSecurityRealm
. This way they can be easily compared in configuration management scripts.The following is a
GithubSecurityRealm
example using new equals method configuring via Jenkins Script Console. It is idempotent and only modifies the Jenkins configuration if it has changed.