Skip to content

Commit 0b7bf3d

Browse files
authored
Merge pull request #612 from dwnusbaum/merge-groovy-cps
Merge groovy-cps into workflow-cps
2 parents 45835c7 + f0b2f0d commit 0b7bf3d

File tree

342 files changed

+13378
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

342 files changed

+13378
-280
lines changed

Jenkinsfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
buildPlugin(useContainerAgent: true, configurations: [
2-
[ platform: "docker", jdk: "8" ],
3-
[ platform: "windows", jdk: "8" ],
2+
[ platform: "windows", jdk: "11" ],
43
[ platform: "linux", jdk: "11" ]
54
])

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This plugin was previously the "Workflow CPS plugin" or "Workflow Groovy Plugin"
5050

5151
## Technical design
5252

53-
The plugin uses the [Groovy CPS library](https://github.com/cloudbees/groovy-cps/) to implement a [continuation-passing style transformation](https://en.wikipedia.org/wiki/Continuation-passing_style) on the program as it is compiled.
53+
The plugin uses the Groovy CPS library to implement a [continuation-passing style transformation](https://en.wikipedia.org/wiki/Continuation-passing_style) on the program as it is compiled.
5454
The standard Groovy compiler is used to create the AST, but generation of bytecode is intercepted by a `CompilationCustomizer` which replaces most operations with variants that throw a special “error”, `CpsCallableInvocation`.
5555
This is then caught by the engine, which uses information from it (such as arguments about to be passed to a method call) to pass control on to the next continuation.
5656

@@ -73,3 +73,8 @@ The `parallel` step uses “green threads” (also known as coöperative multita
7373
The program may seem to perform tasks concurrently, but only because most steps run asynchronously, while the VM thread is idle, and they may overlap in time.
7474
No Java thread is consumed except during the typically brief intervals when Groovy code is actually being run on the VM thread.
7575
The executor widget only displays an entry for the “flyweight” executor on the built-in node when the VM thread is busy; normally it is hidden.
76+
77+
* [Basics of CPS](doc/cps-basics.md)
78+
* [Continuation, Next, and Env](doc/cps-model.md) and how we interpret Groovy program
79+
* [How interpreted program is represented](doc/block-tree.md)
80+
* [CPS + Sandbox](doc/sandbox.md)

dgm-builder/pom.xml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.jenkins-ci.plugins.workflow</groupId>
7+
<artifactId>workflow-cps-parent</artifactId>
8+
<version>${changelist}</version>
9+
</parent>
10+
11+
<groupId>com.cloudbees</groupId>
12+
<artifactId>groovy-cps-dgm-builder</artifactId>
13+
14+
<name>CpsDefaultGroovyMethods generator</name>
15+
16+
<licenses>
17+
<license>
18+
<name>The Apache Software License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
</license>
22+
</licenses>
23+
24+
<properties>
25+
<maven.compiler.release>11</maven.compiler.release>
26+
<maven.compiler.testRelease>11</maven.compiler.testRelease>
27+
<maven.deploy.skip>true</maven.deploy.skip>
28+
</properties>
29+
30+
<build>
31+
<plugins>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-assembly-plugin</artifactId>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>single</goal>
40+
</goals>
41+
<configuration>
42+
<archive>
43+
<manifest>
44+
<mainClass>com.cloudbees.groovy.cps.tool.Driver</mainClass>
45+
</manifest>
46+
</archive>
47+
<descriptorRefs>
48+
<descriptorRef>jar-with-dependencies</descriptorRef>
49+
</descriptorRefs>
50+
</configuration>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
<dependencies>
58+
<dependency>
59+
<!-- TODO: Once we are ok limiting workflow-cps (and groovy-cps) to compile _and_ run only on Java 9+, we should delete this dependency and switch to javax.annotation.processing.Generated. -->
60+
<groupId>javax.annotation</groupId>
61+
<artifactId>javax.annotation-api</artifactId>
62+
<version>1.3.2</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.kohsuke.codemodel</groupId>
66+
<artifactId>codemodel</artifactId>
67+
<version>2.7</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.jenkins-ci.main</groupId>
71+
<artifactId>remoting</artifactId>
72+
<version>4.13.3</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.codehaus.groovy</groupId>
76+
<artifactId>groovy</artifactId>
77+
<version>${groovy.version}</version>
78+
</dependency>
79+
<dependency>
80+
<groupId>org.codehaus.groovy</groupId>
81+
<artifactId>groovy</artifactId>
82+
<classifier>sources</classifier>
83+
<version>${groovy.version}</version>
84+
</dependency>
85+
</dependencies>
86+
87+
<profiles>
88+
<profile>
89+
<id>skip-installation</id>
90+
<activation>
91+
<property>
92+
<name>set.changelist</name>
93+
<value>true</value>
94+
</property>
95+
</activation>
96+
<properties>
97+
<maven.install.skip>true</maven.install.skip>
98+
</properties>
99+
</profile>
100+
</profiles>
101+
</project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.cloudbees.groovy.cps.tool;
2+
3+
import com.sun.codemodel.writer.FileCodeWriter;
4+
import groovy.lang.GroovyShell;
5+
import hudson.remoting.Which;
6+
7+
import javax.tools.DiagnosticListener;
8+
import javax.tools.JavaCompiler;
9+
import javax.tools.JavaFileObject;
10+
import javax.tools.StandardJavaFileManager;
11+
import javax.tools.StandardLocation;
12+
import javax.tools.ToolProvider;
13+
import java.io.File;
14+
import java.nio.charset.Charset;
15+
import java.nio.file.Files;
16+
import java.nio.file.Paths;
17+
import java.util.ArrayList;
18+
import java.util.Collections;
19+
import java.util.List;
20+
import java.util.Locale;
21+
22+
import static java.util.Arrays.*;
23+
24+
public class Driver {
25+
public static void main(String[] args) throws Exception {
26+
new Driver().run(new File(args[0]));
27+
}
28+
29+
public void run(File dir) throws Exception {
30+
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
31+
DiagnosticListener<JavaFileObject> errorListener = createErrorListener();
32+
33+
try (StandardJavaFileManager fileManager = javac.getStandardFileManager(errorListener, Locale.getDefault(), Charset.defaultCharset())) {
34+
fileManager.setLocation(StandardLocation.CLASS_PATH,
35+
Collections.singleton(Which.jarFile(GroovyShell.class)));
36+
37+
File groovySrcJar = Which.jarFile(Driver.class.getClassLoader().getResource("groovy/lang/GroovyShell.java"));
38+
39+
// classes to translate
40+
// TODO include other classes mentioned in DefaultGroovyMethods.DGM_LIKE_CLASSES if they have any applicable methods
41+
List<String> fileNames = asList("DefaultGroovyMethods",
42+
"DefaultGroovyStaticMethods",
43+
"StringGroovyMethods");
44+
45+
List<JavaFileObject> src = new ArrayList<>();
46+
for (JavaFileObject jfo : fileManager.list(StandardLocation.CLASS_PATH, "org.codehaus.groovy.runtime", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) {
47+
for (String name : fileNames) {
48+
if (jfo.toUri().toString().endsWith("/org/codehaus/groovy/runtime/" + name + ".java")) {
49+
src.add(jfo);
50+
break;
51+
}
52+
}
53+
}
54+
55+
// annotation processing appears to cause the source files to be reparsed
56+
// (even though I couldn't find exactly where it's done), which causes
57+
// Tree symbols created by the original JavacTask.parse() call to be thrown away,
58+
// which breaks later processing.
59+
// So for now, don't perform annotation processing
60+
List<String> options = asList("-proc:none");
61+
62+
Translator t = new Translator(javac.getTask(null, fileManager, errorListener, options, null, src));
63+
64+
for (String name : fileNames) {
65+
t.translate(
66+
"org.codehaus.groovy.runtime."+name,
67+
"com.cloudbees.groovy.cps.Cps"+name,
68+
groovySrcJar.getName());
69+
}
70+
71+
72+
Files.createDirectories(dir.toPath());
73+
t.generateTo(new FileCodeWriter(dir));
74+
}
75+
}
76+
77+
private DiagnosticListener<JavaFileObject> createErrorListener() {
78+
return System.out::println;
79+
}
80+
81+
}

0 commit comments

Comments
 (0)