-
Notifications
You must be signed in to change notification settings - Fork 257
Converting some Groovy sources to Java #765
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
base: master
Are you sure you want to change the base?
Conversation
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.
This file is right at the similarity limit for Git, so any further edits would risk making the diff unreviewable!
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.
…which is causing a problem since resolving SpotBugs violations puts it over the limit.
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.
🤔 maybe I could merge a change to trunk first which just pads out the *.groovy file with lots of long multiline comments that say nothing, and then leave them there, so that Git considers them unmodified.
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.
(Mercurial IMO is better in this regard since hg mv explicitly records the rename, rather than leaving subsequent diff commands to guess at whether it might have happened.)
| @Restricted(NoExternalUse.class) | ||
| static Map<String, CredentialWrapper> getLegacyEnvCredentials(@NonNull Environment environment) { | ||
| Map<String, CredentialWrapper> m = [:] | ||
| environment.each {k, v -> |
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.
No longer compilable. Introduced in #147 but (AFAICT) without test coverage, and not clear it ever worked.
| return causeClass.class.simpleName.matches("(?i)\\.*${cause}.*") | ||
| public static boolean shouldRunBeAllowed(Cause causeClass, String cause, String detail) { | ||
| if (causeClass instanceof Cause.UserIdCause && Cause.UserIdCause.class.getSimpleName().equals(cause)) { | ||
| return detail == null || ((Cause.UserIdCause) causeClass).getUserId().equals(detail); | ||
| } else { | ||
| return causeClass.getClass().getSimpleName().matches("(?i).*" + cause + ".*"); |
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.
Unclear what was meant by \.*cause.*. This would seem to mean mycauselala, .mycause, ..mycausexxx, etc.? Does not seem to make any sense. I think .* (any characters) was meant. Maybe .*\.?
(Copilot quietly converted the regexp, which is a bit alarming; I noticed the change while looking over the diff.)
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.
Called via #isRunCausedBy by TriggeredByConditionalScript. So seems to support when { triggeredBy 'SCMTrigger' } etc.
What the pattern generally seems to do is it allows shorthand, e.g. triggeredBy 'SCM' (or 'scm' thanks to case-insensitivity). I don't see how a #getSimpleName would start with . though, so all this currently does is effectively ^ (no prefix).
The "fix" appears to change behavior (from matching a prefix to matching any substring) so should be done only carefully considered.
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.
all this currently does is effectively
^(no prefix)
Agreed. Maybe better to just write it that way for now.
| toApply.addAll(newProperties) | ||
| return toApply.asList() | ||
| if (newProperties != null) { | ||
| toApply.addAll(newProperties); |
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.
Copilot quietly inserted a null check here. The parameter is declared @CheckForNull so this might have been an NPE, unless it was in fact always non-null?
| } | ||
| public static Predicate<FlowNode> isParallelBranchFlowNode(final String stageName) { | ||
| return input -> { | ||
| if (input != null) { |
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.
(ignore WS)
| // Remove all triggers defined in previous Jenkinsfile and may be deprecated | ||
| toApply.removeIf(t -> prevDefined.contains(t.getDescriptor().getId())); | ||
| // Replace all triggers defined in current Jenkinsfile | ||
| if (newTriggers != null) { |
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.
(ditto)
| @NonNull List<JobProperty> existingProperties) { | ||
| Set<String> currentPropertiesDescriptors = currentProperties.collect{ it.descriptor.id }.toSet() | ||
| return existingProperties.findAll{ !(it.descriptor.id in currentPropertiesDescriptors)} | ||
| Set<String> currentPropertiesDescriptors = currentProperties != null ? currentProperties.stream() |
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.
Was able to resolve one SpotBugs violation here (currentProperties null check), but if I do the same in a nearby method, the diff goes over 50% modified: #765 (comment)
| countMap[it.descriptor.id] > 1 || | ||
| !(Objects.equals(it, descriptorsToExistingProperties[it.descriptor.id]) || | ||
| isObjectsEqualsXStream(it, descriptorsToExistingProperties[it.descriptor.id]))} | ||
| return currentProperties.stream() |
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.
(currentProperties null check)
dwnusbaum
left a comment
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.
Seems fine. The only thing that I noticed was that [:] has been converted to HashMap everywhere rather than LinkedHashMap. Whether this makes a meaningful difference anywhere was not immediately obvious to me.
| return causeClass.class.simpleName.matches("(?i)\\.*${cause}.*") | ||
| public static boolean shouldRunBeAllowed(Cause causeClass, String cause, String detail) { | ||
| if (causeClass instanceof Cause.UserIdCause && Cause.UserIdCause.class.getSimpleName().equals(cause)) { | ||
| return detail == null || ((Cause.UserIdCause) causeClass).getUserId().equals(detail); | ||
| } else { | ||
| return causeClass.getClass().getSimpleName().matches("(?i)^" + cause + ".*"); |
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.
There are three tests which exercise triggeredBy. All are testing positive matches, two exercising this class, both testing a positive match on the full Class.simpleName (no prefix or substring, no case insensitivity). There is also no help for this field;
Lines 26 to 33 in 8bf54c8
| Cause class simpleName case insensitive. | |
| <li> | |
| <ul>cause: TimerTrigger</ul> | |
| <ul>cause: SCMTrigger</ul> | |
| <ul>cause: UpstreamCause</ul> | |
| <ul>cause: UserIdCause, detail: username</ul> | |
| </li> | |
| </p> |
Hmm, good point, probably needs to be checked. |
Experimenting with whether Copilot is able to figure out how to do this efficiently. Only considering
src/main/groovy/;src/main/resources/**/*.groovyare CPS-transformed.