-
Notifications
You must be signed in to change notification settings - Fork 34
Conversation
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
…at elements overriding Object.equals.
... 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
Reverting cloudbees#38 in this branch.
…nued Conflicts: src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy
FTR I never proposed using |
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.
Looks promising. I need to look at this in detail. Agreed that we would like to get this in ASAP.
I.e., part of jenkinsci/workflow-cps-plugin#15. Probably we would actually want to maintain a list of methods which were successfully patched, at least until we get automatic
Does not prove that much since you were presumably not running |
@jglick Nope, I was running I'm 100% sure there's problems with this still in cases we don't have test coverage for due to real-world things, and am still entirely open to revisiting it and actually trying to use the APIs
|
Got it. Yeah that looks right. Will be more reproducible if we In the meantime I am taking another look at DefaultMetaClassInfo.setCategoryUsed(true);
VMPluginFactory.getPlugin().invalidateCallSites(); I now see that this is likely not going to work, as these are basically markers, while tons of other Groovy core code calls back into OTOH my original reasons for rejecting
class XTest {
@Test
public void x() {
Base x = new Base()
use(Cat) {
println "x.m1()=${x.m1()} x.m2()=${x.m2()} x.asBoolean()=${x.asBoolean()}"
}
}
public static class Base {
public String m1() {"base-m1"}
}
public static class Cat {
public static String m1(Base o) {"cat-m1"}
public static String m2(Base o) {"cat-m2"}
public static String asBoolean(Base o) {"cat-asBoolean"}
}
} prints what we would want:
Note that the category is replacing |
Oh yeah, categories can replace methods for sure. So you're thinking that we can do |
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.
Superseded by #56, we hope.
Yup, closing. |
JENKINS-34064
Subsumes #24
I did a local build of core with Groovy 2.4.11, modified
workflow-cps
to roll back jenkinsci/workflow-cps-plugin@efeee2b, and ran theworkflow-cps
tests against that tweaked core and this snapshot...and everything passed.I know
DGMPatcher
is not the ideal way to do this, but given thatCategorySupport
isn't viable due to it affecting the whole thread, I'd say this is worth doing as is. I'd really like to get this in so that I can work on adding more patched methods for things like.collect
,.collectEntries
,.find
, etc...cc @reviewbybees