upgle commented on a change in pull request #82: Support OpenJDK 11 runtime
URL: 
https://github.com/apache/openwhisk-runtime-java/pull/82#discussion_r384345096
 
 

 ##########
 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:
   ## Note
   From java 9 version, it outputs below warning messages when accessing 
encapsulated field by reflection.
   
   > WARNING: An illegal reflective access operation has occurred 
   WARNING: Please consider reporting this to the maintainers of Main
   WARNING: Use --illegal-access=warn to enable warnings of further illegal 
reflective access operations
   WARNING: All illegal access operations will be denied in a future release
   
   #### Source code using reflection
   - core/java11actionloop/lib/src/Launcher.java
   ```java
   if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
       Field field = cl.getDeclaredField("m");
       field.setAccessible(true); // <- here
   ```
   
   
   So, I added `--add-opens` and `--illegal-access`  VM options to access 
`java.util.Collections$UnmodifiableMap`.
   ```
   --add-opens java.base/java.util=ALL-UNNAMED 
   --illegal-access=permit
   ```
   
   https://stackoverflow.com/a/46230678
   

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to