Skip to content

Conversation

@jglick
Copy link
Member

@jglick jglick commented Feb 25, 2025

Experimenting with whether Copilot is able to figure out how to do this efficiently. Only considering src/main/groovy/; src/main/resources/**/*.groovy are CPS-transformed.

@jglick jglick added the chore label Feb 25, 2025
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 file is right at the similarity limit for Git, so any further edits would risk making the diff unreviewable!

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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 ->
Copy link
Member Author

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.

Comment on lines 290 to 271
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 + ".*");
Copy link
Member Author

@jglick jglick Feb 25, 2025

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.)

Copy link
Member

@daniel-beck daniel-beck Feb 26, 2025

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.

Copy link
Member Author

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.

Comment on lines -889 to +895
toApply.addAll(newProperties)
return toApply.asList()
if (newProperties != null) {
toApply.addAll(newProperties);
Copy link
Member Author

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) {
Copy link
Member Author

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) {
Copy link
Member Author

Choose a reason for hiding this comment

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

(ditto)

@jglick jglick marked this pull request as ready for review February 26, 2025 00:18
@jglick jglick requested a review from a team February 26, 2025 00:18
@jglick jglick changed the title Converting Groovy sources to Java Converting some Groovy sources to Java Feb 26, 2025
@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()
Copy link
Member Author

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()
Copy link
Member Author

Choose a reason for hiding this comment

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

(currentProperties null check)

Copy link
Member

@dwnusbaum dwnusbaum left a 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.

Comment on lines -290 to +271
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 + ".*");
Copy link
Member Author

Choose a reason for hiding this comment

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

#765 (comment)

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;

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>
seems to describe the tested cases (with incorrect syntax) but is in the wrong filename so it does not appear in the GUI, while https://www.jenkins.io/doc/book/pipeline/syntax/#built-in-conditions covers the same limited text. Mistakes seem to all date to #306.

@jglick
Copy link
Member Author

jglick commented May 5, 2025

[:] has been converted to HashMap everywhere rather than LinkedHashMap

Hmm, good point, probably needs to be checked.

@jglick jglick marked this pull request as draft May 5, 2025 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants