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

Commit

Permalink
Merge pull request #54 from jglick/closures-JENKINS-26481
Browse files Browse the repository at this point in the history
[JENKINS-26481] Working on supporting CPS-transformed closures passed to DefaultGroovyMethods
  • Loading branch information
jglick authored May 16, 2017
2 parents c94b915 + ba5769b commit 21f8b27
Show file tree
Hide file tree
Showing 10 changed files with 2,580 additions and 463 deletions.
20 changes: 18 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<parent>
<groupId>com.cloudbees</groupId>
<artifactId>cloudbees-oss-parent</artifactId>
<version>6</version>
<version>7</version>
<relativePath />
</parent>

<artifactId>groovy-cps</artifactId>
Expand All @@ -14,6 +15,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<groovy.version>2.4.7</groovy.version>
</properties>

<build>
Expand Down Expand Up @@ -54,6 +56,14 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<trimStackTrace>false</trimStackTrace> <!-- SUREFIRE-1226 workaround -->
</configuration>
</plugin>
</plugins>
<extensions>
<extension>
Expand Down Expand Up @@ -81,13 +91,19 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.8.9</version>
<version>${groovy.version}</version>
<!--
let the user of this library select the right flavor of groovy,
including groovy vs groovy-all
-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-test</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down

This file was deleted.

51 changes: 35 additions & 16 deletions src/main/java/com/cloudbees/groovy/cps/Continuable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.cloudbees.groovy.cps.impl.ConstantBlock;
import com.cloudbees.groovy.cps.impl.CpsCallableInvocation;
import com.cloudbees.groovy.cps.impl.SourceLocation;
import com.cloudbees.groovy.cps.impl.SuspendBlock;
import com.cloudbees.groovy.cps.impl.ThrowBlock;
import com.cloudbees.groovy.cps.sandbox.Invoker;
Expand All @@ -18,13 +17,24 @@
import java.util.List;

import static com.cloudbees.groovy.cps.impl.SourceLocation.UNKNOWN;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import groovy.lang.Closure;
import org.codehaus.groovy.runtime.GroovyCategorySupport;

/**
* Mutable representation of the program. This is the primary API of the groovy-cps library to the outside.
*
* @author Kohsuke Kawaguchi
*/
public class Continuable implements Serializable {

@SuppressWarnings("rawtypes")
public static final List<Class> categories = ImmutableList.<Class>of(
CpsDefaultGroovyMethods.class,
CpsDefaultGroovyStaticMethods.class,
CpsProcessGroovyMethods.class);

/**
* When the program resumes with a value (in particular an exception thrown), what environment
* do we evaluate that in?
Expand Down Expand Up @@ -142,22 +152,31 @@ public Object runByThrow(Throwable arg) throws InvocationTargetException {
* Resumes this program by either returning the value from {@link Continuable#suspend(Object)} or
* throwing an exception
*/
public Outcome run0(Outcome cn) {
Next n = cn.resumeFrom(e,k);

while(n.yield==null) {
if (interrupt!=null) {
// TODO: correctly reporting a source location requires every block to have the line number
n = new Next(new ThrowBlock(UNKNOWN, new ConstantBlock(interrupt), true),n.e,n.k);
interrupt = null;
}
n = n.step();
}

e = n.e;
k = n.k;
public Outcome run0(final Outcome cn) {
return run0(cn, categories);
}

return n.yield;
public Outcome run0(final Outcome cn, List<Class> categories) {
return GroovyCategorySupport.use(categories, new Closure<Outcome>(null) {
@Override
public Outcome call() {
Next n = cn.resumeFrom(e,k);

while(n.yield==null) {
if (interrupt!=null) {
// TODO: correctly reporting a source location requires every block to have the line number
n = new Next(new ThrowBlock(UNKNOWN, new ConstantBlock(interrupt), true),n.e,n.k);
interrupt = null;
}
n = n.step();
}

e = n.e;
k = n.k;

return n.yield;
}
});
}

/**
Expand Down
Loading

0 comments on commit 21f8b27

Please sign in to comment.