You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/03/23 11:34:39 UTC

[GitHub] [openwhisk-runtime-java] sciabarra commented on a change in pull request #82: Add OpenJDK 11 action loop runtime

sciabarra commented on a change in pull request #82: Add OpenJDK 11 action loop runtime
URL: https://github.com/apache/openwhisk-runtime-java/pull/82#discussion_r396385900
 
 

 ##########
 File path: core/java11actionloop/bin/compile
 ##########
 @@ -0,0 +1,129 @@
+#!/usr/bin/env python
+"""Java Action Builder
+#
+# 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.
+#
+"""
+
+from __future__ import print_function
+from os.path import abspath, exists, dirname
+import os, sys, codecs, subprocess, shutil, logging
+
+def copy(src, dst):
+    with codecs.open(src, 'r', 'utf-8') as s:
+        body = s.read()
+        with codecs.open(dst, 'w', 'utf-8') as d:
+            d.write(body)
+
+def find_with_ext(basedir, ext):
+    result = []
+    for root, _, files in os.walk(basedir, topdown=False):
+        for name in files:
+            if name.endswith(ext):
+                result.append(os.path.join(root,name))
+    return result
+
+def javac(sources, classpath, target_dir):
+    cmd = [ "javac", 
+            "-encoding", "UTF-8",
+            "-cp", ":".join(classpath),
+            "-d", target_dir
+    ]+sources
+    #print(cmd)
+    logging.info(" ".join(cmd))
+    p = subprocess.Popen(cmd,
+                         stdout=subprocess.PIPE,
+                         stderr=subprocess.PIPE)
+    (o, e) = p.communicate()
+    if isinstance(o, bytes) and not isinstance(o, str):
+        o = o.decode('utf-8')
+    if isinstance(e, bytes) and not isinstance(e, str):
+        e = e.decode('utf-8')
+    ok = True
+    if o:
+        ok = False
+        sys.stdout.write(o)
+        sys.stdout.flush()
+    if e:
+        ok = False
+        sys.stderr.write(e)
+        sys.stderr.flush()
+    return ok
+
+def build(source_dir, classpath, target_dir, mainClass):
+ 
+    # copy exec to <main>.java if it is there
+    src = "%s/exec" % source_dir
+    if os.path.isfile(src):
+        main_java = "%s/%s.java" % (source_dir, mainClass.split(".")[-1])
+        copy(src,main_java)
+        logging.info("renamed exec to %s", main_java)
+
+    # look for sources and compile
+    sources = find_with_ext(source_dir, ".java")
+    if len(sources) > 0:
+        jars = find_with_ext(source_dir, ".jar")
+        logging.info("compiling  %d sources with %d jars", len(sources),len(jars))
+        return javac(sources, classpath+jars, source_dir)
+    
+    return True 
+
+def write_exec(target_dir, classpath, main):
+    launcher = "%s/exec" % target_dir
+    jars = find_with_ext(target_dir, ".jar")
+    jars.append(target_dir)
+    cmd = """#!/bin/bash
+cd "%s"
+/opt/java/openjdk/bin/java --add-opens java.base/java.util=ALL-UNNAMED --illegal-access=permit -Dfile.encoding=UTF-8 -cp "%s" Launcher "%s" "$@"
 
 Review comment:
   Indeed that is an horrible and ugly hack that unfortunately is the only way to set environment variables with jdk8. I was kinda of "forced" to add that in actionloop because I tried to make the actionloop 100% compatible but I really would like to change the API, and not use environment variables but system properties to pass environment variables.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services