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

CPS does not support categories #16

Closed
Fiouz opened this issue Sep 26, 2015 · 4 comments
Closed

CPS does not support categories #16

Fiouz opened this issue Sep 26, 2015 · 4 comments

Comments

@Fiouz
Copy link
Contributor

Fiouz commented Sep 26, 2015

The following does not work under CPS as the up() method cannot be resolved:

diff --git a/src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy b/src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy
index 9f45611..5bf85d0 100644
--- a/src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy
+++ b/src/test/groovy/com/cloudbees/groovy/cps/CpsTransformerTest.groovy
@@ -535,4 +535,18 @@ class CpsTransformerTest extends AbstractGroovyCpsTest {
         assert evalCPS("('2009' ==~ /\\d+/) as boolean")
         assert !evalCPS("('holla' ==~ /\\d+/) as boolean")
     }
+
+    @Test
+    void category() {
+        assert evalCPS('''
+            class BarCategory {
+                static String up(String text) {
+                    text.toUpperCase()
+                }
+            }
+            return use(BarCategory) {
+                'foo'.up()
+            };
+''') == 'FOO';
+    }
 }

category(com.cloudbees.groovy.cps.CpsTransformerTest)  Time elapsed: 0.027 sec  <<< ERROR!
groovy.lang.MissingMethodException: No signature of method: java.lang.String.up() is applicable for argument types: () values: []
Possible solutions: dump(), use([Ljava.lang.Object;), is(java.lang.Object), use(java.lang.Class, groovy.lang.Closure), tr(java.lang.String, java.lang.String), tr(java.lang.CharSequence, java.lang.CharSequence)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
    at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
    at Script1.run(Script1.groovy:8)
    at Script1.run(Script1.groovy:7)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:69)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:74)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:58)
    at com.cloudbees.groovy.cps.Next.run(Next.java:49)
    at com.cloudbees.groovy.cps.Next$run.call(Unknown Source)
    at com.cloudbees.groovy.cps.AbstractGroovyCpsTest.evalCPSonly(AbstractGroovyCpsTest.groovy:55)
    at com.cloudbees.groovy.cps.AbstractGroovyCpsTest.evalCPS(AbstractGroovyCpsTest.groovy:49)
    at com.cloudbees.groovy.cps.AbstractGroovyCpsTest$evalCPS.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at com.cloudbees.groovy.cps.CpsTransformerTest.category(CpsTransformerTest.groovy:541)
@jglick
Copy link
Member

jglick commented Nov 10, 2016

I doubt there is any straightforward way to make this work. The category support relies on ThreadLocals, which do not work in the CPS VM thread.

@jglick
Copy link
Member

jglick commented May 12, 2017

In principal DefaultGroovyMethods.use could be replaced with a version which records the category being requested, and then we would actually call GroovyCategorySupport on each CPS VM operation. Would be tricky.

@jglick
Copy link
Member

jglick commented May 30, 2017

Since as of #56 we are calling GroovyCategorySupport, this is looking more practical. We would need a new (meta-?)category which overrides DefaultGroovyMethods.use.

@dwnusbaum
Copy link
Member

I am closing this issue. If it is still a problem for anyone, feel free to file an issue on https://issues.jenkins.io/ with the component set to workflow-cps, but note that unless you work on it yourself it is relatively unlikely that this will ever be fixed.

@dwnusbaum dwnusbaum closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants