Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 84c3d9a

Browse files
committed
fix for bad display of some binary actions
add support for creating java/jar actions Fixes #961 Fixes #963
1 parent 2c17e8c commit 84c3d9a

File tree

7 files changed

+81
-4
lines changed

7 files changed

+81
-4
lines changed

app/content/js/ui.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ const ui = (function() {
14571457
// show the action's code
14581458
//
14591459

1460-
if (!entity.exec.binary || !(entity.annotations && entity.annotations.find(({key}) => key === 'binary'))) {
1460+
if (!entity.exec.binary && !(entity.annotations && entity.annotations.find(({key}) => key === 'binary'))) {
14611461
//
14621462
// render the textual source code
14631463
//
@@ -1471,6 +1471,7 @@ const ui = (function() {
14711471
setTimeout(() => { code.innerText = beautify(entity.exec.kind, entity.exec.code); hljs.highlightBlock(code) }, 100) // HACK HACK to work around highlightjs bug v0.9.12
14721472
} else {
14731473
// TODO what do we do with binary actions?
1474+
code.innerText = 'This is a binary action'
14741475
}
14751476
}
14761477
}

app/plugins/ui/commands/openwhisk-core.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ const addPrettyType = (entityType, verb, entityName) => entity => {
466466
}
467467

468468
const extensionToKind = {
469+
'jar': 'java:default',
469470
'js': 'nodejs:default',
470471
'py': 'python:default',
471472
'swift': 'swift:default'
@@ -531,7 +532,6 @@ specials.actions = {
531532
}
532533
}
533534

534-
535535
if (options.sequence) {
536536
options.action.exec = {
537537
kind: 'sequence',
@@ -575,7 +575,9 @@ specials.actions = {
575575
} else {
576576
// otherwise, find the file named by argv[0]
577577
const filepath = ui.findFile(expandHomeDir(argv[0])),
578-
isBinary = argv[0].endsWith('.zip'),
578+
isZip = argv[0].endsWith('.zip'),
579+
isJar = argv[0].endsWith('.jar'),
580+
isBinary = isZip || isJar,
579581
encoding = isBinary ? 'base64' : 'utf8'
580582

581583
options.action.exec.code = fs.readFileSync(filepath).toString(encoding)
@@ -588,7 +590,7 @@ specials.actions = {
588590
options.action.annotations.push({ key: 'wskng.combinators', value: [{
589591
type: 'action.kind',
590592
role: 'replacement',
591-
badge: 'zip'
593+
badge: isZip ? 'zip' : 'jar'
592594
}]})
593595

594596
options.action.annotations.push({ key: 'binary', value: true })
@@ -618,6 +620,11 @@ specials.actions = {
618620
// then we must remove options.exec; the backend fails if an empty struct is passed
619621
delete options.action.exec
620622
}
623+
624+
if (options.main && options.action.exec) {
625+
// main method of java actions
626+
options.action.exec.main = options.main
627+
}
621628
}),
622629
list: (options, argv) => {
623630
// support for `wsk action list <packageName>` see shell issue #449

app/plugins/ui/commands/openwhisk-usage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const actionMix = params.concat(annotations).concat(limits).concat([
8787
{ name: '--docker', boolean: true, docs: 'use a dockerhub image for the action' },
8888
{ name: '--native', boolean: true, docs: 'use a shell script or Linux binary for the action' },
8989
{ name: '--web', boolean: true, docs: 'web export the action' },
90+
{ name: '--main', docs: 'specify the main method for Java actions' },
9091
{ name: '--content-type', hidden: true }
9192
])
9293

tests/data/jar/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
The jar file is included in the repo to facilitate the tests, so that
2+
we don't depend on gradle or some such in the test rig. If you need to
3+
rebuild the jar, do the following:
4+
5+
6+
```sh
7+
curl -O https://repo1.maven.org/maven2/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar
8+
javac -target 8 -source 8 echo.java -cp gson-2.6.2.jar
9+
jar cf echo.jar echo.class
10+
```
11+
12+
Note that, as of this writing (20180521), the source and target
13+
versions are important; the currently OpenWhisk does not support any
14+
more recent bytecode target than 8.

tests/data/jar/echo.jar

686 Bytes
Binary file not shown.

tests/data/jar/echo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import com.google.gson.JsonObject;
2+
3+
public class echo {
4+
static public JsonObject main(JsonObject args) throws Exception {
5+
return args;
6+
}
7+
}

tests/tests/passes/04/jar.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2018 IBM Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const common = require('../../../lib/common'),
18+
openwhisk = require('../../../lib/openwhisk'),
19+
ui = require('../../../lib/ui'),
20+
assert = require('assert'),
21+
keys = ui.keys,
22+
cli = ui.cli,
23+
sidecar = ui.sidecar,
24+
actionName1 = 'foo1'
25+
26+
describe('Create jar actions', function() {
27+
before(common.before(this))
28+
after(common.after(this))
29+
30+
it('should have an active repl', () => cli.waitForRepl(this.app))
31+
32+
it('should create a jar action', () => cli.do(`action create ${actionName1} ./data/jar/echo.jar --main echo`, this.app)
33+
.then(cli.expectOK)
34+
.then(sidecar.expectOpen)
35+
.then(sidecar.expectShowing(actionName1))
36+
.then(sidecar.expectBadge('jar'))
37+
.then(app => app.client.getText(`${ui.selectors.SIDECAR_CONTENT} .hook-for-third-party-content`))
38+
.then(code => assert.equal(code, 'This is machine-generated code, wrapping around your original code.'))
39+
.catch(common.oops(this)))
40+
41+
it('should invoke the jar action', () => cli.do(`invoke -p x 3`, this.app)
42+
.then(cli.expectOK)
43+
.then(sidecar.expectOpen)
44+
.then(sidecar.expectShowing(actionName1))
45+
.then(sidecar.expectResult({x: 3}))
46+
.catch(common.oops(this)))
47+
})

0 commit comments

Comments
 (0)