You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by dr...@apache.org on 2018/02/26 20:10:37 UTC

[incubator-openwhisk-devtools] branch master updated: Added maven archetype for Java Action (#97)

This is an automated email from the ASF dual-hosted git repository.

dragos pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-devtools.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c2b754  Added maven archetype for Java Action (#97)
7c2b754 is described below

commit 7c2b75492884d00c5387712b09442fdca7c043a3
Author: Kamesh Sampath <ka...@hotmail.com>
AuthorDate: Tue Feb 27 01:40:35 2018 +0530

    Added maven archetype for Java Action (#97)
    
    * Adding Maven Archetype to generate template projects for JavaActions
    * Adding archetype tests
    * enabled travis
    * Adding maven wrapper
    * Fixed final name of generated project to match artifactId
    * README update for deploying app
---
 .gitignore                                         |  1 +
 .travis.yml                                        |  1 +
 java-action-archetype/.editorconfig                | 25 ++++++++++++
 java-action-archetype/.gitignore                   |  1 +
 java-action-archetype/.travis/build.sh             | 10 +++++
 java-action-archetype/.travis/setup.sh             | 10 +++++
 java-action-archetype/README.md                    | 39 ++++++++++++++++++
 java-action-archetype/pom.xml                      | 28 +++++++++++++
 .../main/resources/META-INF/maven/archetype.xml    |  9 +++++
 .../src/main/resources/archetype-resources/pom.xml | 47 ++++++++++++++++++++++
 .../src/main/java/FunctionApp.java                 | 31 ++++++++++++++
 .../src/test/java/FunctionAppTest.java             | 39 ++++++++++++++++++
 .../resources/projects/basic/archetype.properties  |  4 ++
 .../src/test/resources/projects/basic/goal.txt     |  1 +
 14 files changed, 246 insertions(+)

diff --git a/.gitignore b/.gitignore
index 9e9a503..24ad037 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ openwhisk-master*
 *.iml
 .idea
 .vscode
+**/.sts4-cache
diff --git a/.travis.yml b/.travis.yml
index 1d678b6..c3eaff3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ env:
     - DOCKER_COMPOSE_VERSION: 1.13.0
   matrix:
     - TOOL: docker-compose
+    - TOOL: java-action-archetype
 
 services:
   - docker
diff --git a/java-action-archetype/.editorconfig b/java-action-archetype/.editorconfig
new file mode 100644
index 0000000..3e5b662
--- /dev/null
+++ b/java-action-archetype/.editorconfig
@@ -0,0 +1,25 @@
+# EditorConfig is awesome: http://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+# Unix-style newlines with a newline ending every file
+[*]
+end_of_line = lf
+insert_final_newline = false
+
+# Matches multiple files with brace expansion notation
+# Set default charset
+[*.{java}]
+charset = utf-8
+
+# 4 space indentation
+[*.java]
+indent_style = space
+indent_size = 2
+insert_final_newline = true
+
+# Indentation style for yaml, yml
+[*.{js,xml,html,json,yaml,yml}]
+indent_style = space
+indent_size = 2
\ No newline at end of file
diff --git a/java-action-archetype/.gitignore b/java-action-archetype/.gitignore
new file mode 100644
index 0000000..1de5659
--- /dev/null
+++ b/java-action-archetype/.gitignore
@@ -0,0 +1 @@
+target
\ No newline at end of file
diff --git a/java-action-archetype/.travis/build.sh b/java-action-archetype/.travis/build.sh
new file mode 100755
index 0000000..d29d3fc
--- /dev/null
+++ b/java-action-archetype/.travis/build.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+SCRIPTDIR=$(cd $(dirname "$0") && pwd)
+TOOLDIR="$SCRIPTDIR/../"
+
+cd $TOOLDIR
+
+mvn -V test
+
+#TODO steps that can push this artifact to nexus
diff --git a/java-action-archetype/.travis/setup.sh b/java-action-archetype/.travis/setup.sh
new file mode 100755
index 0000000..f2c7951
--- /dev/null
+++ b/java-action-archetype/.travis/setup.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+set -x -e
+uname -sm
+
+SCRIPTDIR=$(cd $(dirname "$0") && pwd)
+TOOLDIR="$SCRIPTDIR/../"
+
+cd $TOOLDIR
+
+mvn -DskipTests=true -Dmaven.javadoc.skip=true -B -V clean install
diff --git a/java-action-archetype/README.md b/java-action-archetype/README.md
new file mode 100644
index 0000000..67bf3da
--- /dev/null
+++ b/java-action-archetype/README.md
@@ -0,0 +1,39 @@
+# Maven Archetype for Java Action
+
+This archetype helps to generate the Java Action template project.
+
+## Pre-requisite
+
+The following softwares are required to build and deploy a Java Action to OpenWhisk:
+
+* (Maven v3.3.x)[https://maven.apache.org] or above
+* Java 8 or above
+
+[WSK CLI](https://github.com/apache/incubator-openwhisk/blob/master/docs/cli.md) is configured 
+
+## Generate project 
+
+```sh
+mvn archetype:generate \
+  -DarchetypeGroupId=org.apache.openwhisk.java \
+  -DarchetypeArtifactId=java-action-archetype \
+  -DarchetypeVersion=1.0-SNAPSHOT \
+  -DgroupId=com.example \
+  -DartifactId=demo-function
+```
+
+## Deploying function to OpenWhisk
+
+The following step shows how to deploy the function to OpenWhisk
+
+```sh
+cd demo-function
+mvn clean install
+wsk action create demo target/demo-function.jar --main com.example.FunctionApp
+```
+
+After successful deployment of the function, we can invoke the same via `wsk action invoke demo --result` to see the response as:
+
+```json
+{"greetings":  "Hello! Welcome to OpenWhisk" }
+```
\ No newline at end of file
diff --git a/java-action-archetype/pom.xml b/java-action-archetype/pom.xml
new file mode 100644
index 0000000..badbf92
--- /dev/null
+++ b/java-action-archetype/pom.xml
@@ -0,0 +1,28 @@
+<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>
+  <groupId>org.apache.openwhisk.java</groupId>
+  <artifactId>java-action-archetype</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>maven-archetype</packaging>
+  <name>OpenWhisk:: Maven Archetype - Java Action</name>
+  <url>http://openwhisk.apache.org</url>
+  <build>
+    <extensions>
+      <extension>
+        <groupId>org.apache.maven.archetype</groupId>
+        <artifactId>archetype-packaging</artifactId>
+        <version>3.0.1</version>
+      </extension>
+    </extensions>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-archetype-plugin</artifactId>
+          <version>3.0.1</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
\ No newline at end of file
diff --git a/java-action-archetype/src/main/resources/META-INF/maven/archetype.xml b/java-action-archetype/src/main/resources/META-INF/maven/archetype.xml
new file mode 100644
index 0000000..065922a
--- /dev/null
+++ b/java-action-archetype/src/main/resources/META-INF/maven/archetype.xml
@@ -0,0 +1,9 @@
+<archetype>
+  <id>java-action-archetype</id>
+  <sources>
+    <source>src/main/java/FunctionApp.java</source>
+  </sources>
+  <testSources>
+    <source>src/test/java/FunctionAppTest.java</source>
+  </testSources>
+</archetype>
\ No newline at end of file
diff --git a/java-action-archetype/src/main/resources/archetype-resources/pom.xml b/java-action-archetype/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..c17dbd3
--- /dev/null
+++ b/java-action-archetype/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,47 @@
+<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>
+  <groupId>$groupId</groupId>
+  <artifactId>$artifactId</artifactId>
+  <version>$version</version>
+  <url>https://openwhisk.apache.org/</url>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>1.8</maven.compiler.target>
+    <gson.version>2.8.2</gson.version>
+  </properties>
+  <dependencies>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
+      <version>${gson.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <finalName>$artifactId</finalName>
+    <plugins>
+      <!-- This helps in packaging the function depeendencies as uber jar-->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>3.1.0</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
\ No newline at end of file
diff --git a/java-action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java b/java-action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java
new file mode 100644
index 0000000..4b88ea0
--- /dev/null
+++ b/java-action-archetype/src/main/resources/archetype-resources/src/main/java/FunctionApp.java
@@ -0,0 +1,31 @@
+package $groupId;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import com.google.gson.JsonObject;
+
+/**
+ * Hello FunctionApp
+ */
+public class FunctionApp {
+  public static JsonObject main(JsonObject args) {
+    JsonObject response = new JsonObject();
+    response.addProperty("greetings", "Hello! Welcome to OpenWhisk");
+    return response;
+  }
+}
diff --git a/java-action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java b/java-action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java
new file mode 100644
index 0000000..621ee47
--- /dev/null
+++ b/java-action-archetype/src/main/resources/archetype-resources/src/test/java/FunctionAppTest.java
@@ -0,0 +1,39 @@
+package $groupId;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import static org.junit.Assert.*;
+
+import com.google.gson.JsonObject;
+
+import org.junit.Test;
+
+/**
+ * Unit test for simple function.
+ */
+public class FunctionAppTest {
+  @Test
+  public void testFunction() {
+    JsonObject args = new JsonObject();
+    JsonObject response = FunctionApp.main(args);
+    assertNotNull(response);
+    String greetings = response.getAsJsonPrimitive("greetings").getAsString();
+    assertNotNull(greetings);
+    assertEquals("Hello! Welcome to OpenWhisk", greetings);
+  }
+}
diff --git a/java-action-archetype/src/test/resources/projects/basic/archetype.properties b/java-action-archetype/src/test/resources/projects/basic/archetype.properties
new file mode 100644
index 0000000..4ae957e
--- /dev/null
+++ b/java-action-archetype/src/test/resources/projects/basic/archetype.properties
@@ -0,0 +1,4 @@
+groupId=com.example
+artifactId=java-demo-fn
+version=0.1-SNAPSHOT
+artifactId=basic
\ No newline at end of file
diff --git a/java-action-archetype/src/test/resources/projects/basic/goal.txt b/java-action-archetype/src/test/resources/projects/basic/goal.txt
new file mode 100644
index 0000000..0d5cfb8
--- /dev/null
+++ b/java-action-archetype/src/test/resources/projects/basic/goal.txt
@@ -0,0 +1 @@
+clean test
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
dragos@apache.org.