Skip to content

Commit 7b0083b

Browse files
authored
Merge pull request #116 from salesforce/feature/canteen
Feature/canteen
2 parents 4f24f19 + 54b9398 commit 7b0083b

File tree

8 files changed

+54
-22
lines changed

8 files changed

+54
-22
lines changed

canteen/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@ The `canteen-maven-plugin` uses the same technique to prepend a simple platform
9393
cross-compiled with Go to the front of a jar.
9494

9595
When you execute a Canteen packaged jar, the bootstrap program captures all the command line arguments and the name
96-
of the current file. It then spawns a child process as `java -jar $args`, proxying `stdin`, `stdout`, and `stderr`
97-
between the shell and the child process.
96+
of the current file. On Windows, the bootstrap spawns a child process as `java -jar $args`, proxying `stdin`, `stdout`,
97+
and `stderr` between the shell and the child process. On Linux and MacOS, the bootstrap transfers process control to
98+
Java by invoking `syscall.Exec()`;

canteen/canteen-bootstrap/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Canteen Bootstrap
22

33
This module contains the golang bootstrap shim used to invoke `java -jar`. The shim tries to be transparent. It passes
4-
all command line arguments to the child process, so you can use it as if it were the Java process itself.
4+
all command line arguments to the java process, so you can use it as if you invoked Java itself.
55

6-
Once the bootstrap is running, stdin, stdout, and stderr are proxied to the child process. When the child process
7-
exits, the bootstrap assumes the child's exit code. At the moment, the bootstrap does not proxy signals between the
8-
shell and the child process.
6+
On Linux and MacOS, the bootstrap invokes `syscall.Exec()`, transparently transferring control of the process to Java.
7+
8+
On Windows, once the bootstrap is running, stdin, stdout, and stderr are proxied to the child process. When the child
9+
process exits, the bootstrap assumes the child's exit code. At the moment, the bootstrap does not proxy signals between
10+
the shell and the child process.
911

1012
The bootstrap is cross-compiled for 64-bit Linux, MacOS, and Windows as part of the Maven build and attached as
1113
additional artifacts with classifiers compatible with the [os-maven-plugin](https://github.com/trustin/os-maven-plugin).
1214

1315
## Improvements
1416

15-
* Propagate signals to and from child process
1617
* More platforms
1718
* More architectures

canteen/canteen-bootstrap/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<artifactId>canteen-parent</artifactId>
1414
<groupId>com.salesforce.servicelibs</groupId>
15-
<version>0.1.0-SNAPSHOT</version>
15+
<version>1.0.0-SNAPSHOT</version>
1616
</parent>
1717
<modelVersion>4.0.0</modelVersion>
1818

canteen/canteen-bootstrap/src/main/go/main.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"log"
1212
"os"
1313
"os/exec"
14+
"runtime"
1415
"strings"
1516
"syscall"
1617
)
@@ -27,19 +28,26 @@ func main() {
2728
args := []string{"-jar", strings.TrimPrefix(jarName, "./")}
2829
args = append(args, jarArgs...)
2930

30-
cmd := exec.Command(binary, args...)
31-
cmd.Stdout = os.Stdout
32-
cmd.Stderr = os.Stderr
33-
cmd.Stdin = os.Stdin
31+
if runtime.GOOS == "windows" {
32+
cmd := exec.Command(binary, args...)
33+
cmd.Stdout = os.Stdout
34+
cmd.Stderr = os.Stderr
35+
cmd.Stdin = os.Stdin
3436

35-
if err := cmd.Run(); err != nil {
36-
if err, ok := err.(*exec.ExitError); ok {
37-
if status, ok := err.Sys().(syscall.WaitStatus); ok {
38-
// Exit with the same code as the Java program
39-
os.Exit(status.ExitStatus())
37+
if err := cmd.Run(); err != nil {
38+
if err, ok := err.(*exec.ExitError); ok {
39+
if status, ok := err.Sys().(syscall.WaitStatus); ok {
40+
// Exit with the same code as the Java program
41+
os.Exit(status.ExitStatus())
42+
}
43+
} else {
44+
log.Fatalf("Bootstrap execution error: %v", err)
4045
}
41-
} else {
42-
log.Fatalf("Bootstrap execution error: %v", err)
46+
}
47+
} else {
48+
err = syscall.Exec(binary, append([]string{"java"}, args...), nil)
49+
if err != nil {
50+
log.Fatalf("Bootstrap execution error: %v", os.Environ())
4351
}
4452
}
4553
}

canteen/canteen-it/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<artifactId>canteen-parent</artifactId>
1414
<groupId>com.salesforce.servicelibs</groupId>
15-
<version>0.1.0-SNAPSHOT</version>
15+
<version>1.0.0-SNAPSHOT</version>
1616
</parent>
1717
<modelVersion>4.0.0</modelVersion>
1818

canteen/canteen-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<artifactId>canteen-parent</artifactId>
1414
<groupId>com.salesforce.servicelibs</groupId>
15-
<version>0.1.0-SNAPSHOT</version>
15+
<version>1.0.0-SNAPSHOT</version>
1616
</parent>
1717
<modelVersion>4.0.0</modelVersion>
1818

canteen/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<groupId>com.salesforce.servicelibs</groupId>
1515
<artifactId>canteen-parent</artifactId>
1616
<packaging>pom</packaging>
17-
<version>0.1.0-SNAPSHOT</version>
17+
<version>1.0.0-SNAPSHOT</version>
1818

1919
<name>Canteen</name>
2020
<description>A Maven plugin for generating self-executing jars</description>

jprotoc/jprotoc/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ POM file. For more documentation, see the Maven protoc plugin's
8888
</configuration>
8989
```
9090

91+
## Packaging your plugin for native execution
92+
93+
jProtoc plugins can be packaged as native executables using the [`canteen-maven-plugin`](https://github.com/salesforce/grpc-java-contrib/tree/master/canteen).
94+
Canteen repackages jar files so they can be executed from the command line directly without requiring a `java -jar`
95+
invocation.
96+
97+
```xml
98+
<!-- Make the jar self-executing with Canteen -->
99+
<plugin>
100+
<groupId>com.salesforce.servicelibs</groupId>
101+
<artifactId>canteen-maven-plugin</artifactId>
102+
<version>${canteen.version}</version>
103+
<executions>
104+
<execution>
105+
<goals>
106+
<goal>bootstrap</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
```
112+
91113
Using the Jdk8 Protoc generator
92114
===============================
93115
1. Add the following to your POM:

0 commit comments

Comments
 (0)