Skip to content

Commit

Permalink
Merge pull request #245 from skarnecki/java-support
Browse files Browse the repository at this point in the history
add java support. Closes #4
  • Loading branch information
tj committed Feb 22, 2016
2 parents aa24353 + 42c8c4d commit 076da39
Show file tree
Hide file tree
Showing 14 changed files with 456 additions and 4 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
main
*.zip
.DS_Store
examples/go/main
Expand Down
3 changes: 3 additions & 0 deletions _examples/java/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}
7 changes: 7 additions & 0 deletions _examples/java/functions/bar/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"description": "Java example function",
"timeout": 1,
"memory": 256,
"runtime": "java",
"handler": "lambda.Example::handler"
}
50 changes: 50 additions & 0 deletions _examples/java/functions/bar/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Generic values -->
<groupId>plugin-result</groupId>
<artifactId>run.apex</artifactId>
<packaging>jar</packaging>
<version>apex</version>
<name>apex-plugin-result</name>

<properties>
<!-- This prop is set when apex mvn package -->
<jar.finalName>apex-plugin-result</jar.finalName>
</properties>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
</project>
49 changes: 49 additions & 0 deletions _examples/java/functions/bar/src/main/java/lambda/Example.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package lambda;

import com.amazonaws.services.lambda.runtime.Context;

public class Example {

public static class ExampleRequest {
String hello;

public String getHello() {
return hello;
}

public void setHello(String hello) {
this.hello = hello;
}

public ExampleRequest(String hello) {
this.hello = hello;
}

public ExampleRequest() {
}
}


public static class ExampleResponse {
String hello;

public String getHello() {
return hello;
}

public void setHello(String hello) {
this.hello = hello;
}

public ExampleResponse(String hello) {
this.hello = hello;
}

public ExampleResponse() {
}
}

public ExampleResponse handler(ExampleRequest event, Context context) {
return new ExampleResponse("bar");
}
}
49 changes: 49 additions & 0 deletions _examples/java/functions/baz/src/main/java/lambda/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package lambda;

import com.amazonaws.services.lambda.runtime.Context;

public class Main {

public static class ExampleRequest {
String hello;

public String getHello() {
return hello;
}

public void setHello(String hello) {
this.hello = hello;
}

public ExampleRequest(String hello) {
this.hello = hello;
}

public ExampleRequest() {
}
}


public static class ExampleResponse {
String hello;

public String getHello() {
return hello;
}

public void setHello(String hello) {
this.hello = hello;
}

public ExampleResponse(String hello) {
this.hello = hello;
}

public ExampleResponse() {
}
}

public ExampleResponse handler(ExampleRequest event, Context context) {
return new ExampleResponse("baz");
}
}
7 changes: 7 additions & 0 deletions _examples/java/functions/foo/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"description": "Java example function",
"timeout": 1,
"memory": 512,
"runtime": "java",
"handler": "lambda.Hello::handler"
}
49 changes: 49 additions & 0 deletions _examples/java/functions/foo/src/main/java/lambda/Hello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package lambda;

import com.amazonaws.services.lambda.runtime.Context;

public class Hello {

public static class ExampleRequest {
String hello;

public String getHello() {
return hello;
}

public void setHello(String hello) {
this.hello = hello;
}

public ExampleRequest(String hello) {
this.hello = hello;
}

public ExampleRequest() {
}
}


public static class ExampleResponse {
String hello;

public String getHello() {
return hello;
}

public void setHello(String hello) {
this.hello = hello;
}

public ExampleResponse(String hello) {
this.hello = hello;
}

public ExampleResponse() {
}
}

public ExampleResponse handler(ExampleRequest event, Context context) {
return new ExampleResponse("foo");
}
}
7 changes: 7 additions & 0 deletions _examples/java/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "java",
"description": "Java example project",
"memory": 128,
"timeout": 5,
"role": "arn:aws:iam::293503197324:role/lambda"
}
64 changes: 64 additions & 0 deletions docs/java.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Requirements
Apex expects pom.xml file to be in function directory. If not found, it generic pom.xml will be used.

Requirements for pom.xml to work with apex:
- mvn package produces valid jar
- jar.finalName prop have to set name jar name
- has AWS Lambda dependencies (com.amazonaws.aws-lambda-java-core)

# Generic pom.xml
When no pom.xml file in function main directory, Apex will generate one with default properties.

Generated pom.xml
```xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- Generic values -->
<groupId>plugin-result</groupId>
<artifactId>run.apex</artifactId>
<packaging>jar</packaging>
<version>apex</version>
<name>apex-plugin-result</name>

<properties>
<!-- This prop is set when apex mvn package -->
<jar.finalName>apex-plugin-result</jar.finalName>
</properties>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</build>
</project>
```
1 change: 1 addition & 0 deletions function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var defaultPlugins = []string{
"golang",
"python",
"nodejs",
"java",
"hooks",
"env",
"shim",
Expand Down
9 changes: 6 additions & 3 deletions plugins/inference/inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (

"github.com/apex/apex/function"
"github.com/apex/apex/plugins/golang"
"github.com/apex/apex/plugins/java"
"github.com/apex/apex/plugins/nodejs"
"github.com/apex/apex/plugins/python"
)

func init() {
function.RegisterPlugin("inference", &Plugin{
Files: map[string]string{
"main.py": python.Runtime,
"index.js": nodejs.Runtime,
"main.go": golang.Runtime,
"main.py": python.Runtime,
"index.js": nodejs.Runtime,
"main.go": golang.Runtime,
"pom.xml": java.Runtime,
"/src/main/java/lambda/Main.java": java.Runtime,
},
})
}
Expand Down
Loading

0 comments on commit 076da39

Please sign in to comment.