Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

[JENKINS-26481] Patch DGM methods with closure parameters #52

Closed
wants to merge 24 commits into from

Conversation

abayer
Copy link
Contributor

@abayer abayer commented May 11, 2017

JENKINS-26481

Subsumes #51 (which itself subsumes #24).

Note that this is currently a work in progress, adding patched methods one by one, but I wanted to get a PR open for watching the changes as we go.

cc @reviewbybees

jglick and others added 22 commits April 6, 2016 17:31
so returning the same type makes the patching code above easier
... that we need to rewrite differently.
While running tests, I came across a strange test failure where
each(List,Closure) is delegating to each(Iterator,Closure) and results
in a cast failure. Obviously, it shuold have resolved to
each(Object,Closure) instead.

This got me thinking about how Groovy resolves overloaded methods, which
is non-trivial as a dynamic language.

So in this change I'm changing the code so that Groovy doesn't have to
resolve overloaded versions correctly.
The correct signature, which you can check in DefaultGroovyMethods, is
to return the 'self' type
…if only once, rather than merely returning the list element.
The suspected cause of the problem is that DGMPatcher is not touching
everything it needs to touch, when Groovy runtime is already warm and
cached lots of MetaMethod objects.

This test, having a name that is alphabetically before
CpsTransformerTest, runs before that and populates the cache, exposing
the defect in DGMPatcher.

Run the test like this:

  mvn clean test -Dtest=AaaMakeGroovyBusy,CpsTransformerTest
... and cast wider net to traverse a bigger graph
…4' into DGMPatcher-Groovy-2-JENKINS-34064

Conflicts:
	src/main/java/com/cloudbees/groovy/cps/impl/DGMPatcher.java
…nued

Conflicts:
	src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy
Needs more tests for sets and map collect
@@ -14,6 +14,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<groovy.version>2.4.11</groovy.version>
Copy link
Member

Choose a reason for hiding this comment

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

IIUC this will be usable only in 2.61+, right?

for (Iterator itr = ((ManagedConcurrentLinkedQueue) o).iterator(); itr.hasNext(); ) {
Object item = itr.next();
if (patch(item) != item) {
LOGGER.log(WARNING, "Can't replace members of ManagedConcurrentLinkedQueue", item);
Copy link
Member

Choose a reason for hiding this comment

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

I think you meant

LOGGER.log(WARNING, "Can''t replace members of ManagedConcurrentLinkedQueue: {0}", item);

or more nicely

LOGGER.log(WARNING, "Cannot replace members of ManagedConcurrentLinkedQueue: {0}", item);

or

LOGGER.log(WARNING, "Can’t replace members of ManagedConcurrentLinkedQueue: {0}", item);

Object item = itr.next();
if (patch(item) != item) {
LOGGER.log(WARNING, "Can't replace members of ManagedConcurrentLinkedQueue", item);
// TODO would be possible, if necessary, by calling ManagedConcurrentLinkedQueue.Element.remove on *all* elements, then using ManagedLinkedList.add to recreate the entire list
Copy link
Member

Choose a reason for hiding this comment

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

possibly copy-paste error in comment

@jglick
Copy link
Member

jglick commented May 12, 2017

The manual changes to CpsDefaultGroovyMethods.groovy are not scalable, I think. There are just too many methods taking a Closure and we can expect more to be added in every Groovy release. I would like to try #7 instead.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Trying an alternative approach.

@abayer
Copy link
Contributor Author

abayer commented May 18, 2017

Closing in favor of #56, which now includes tests from here.

@abayer abayer closed this May 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants