From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Nadav Har'El <n...@scylladb.com>
Branch: master

Support building and running Java apps in non-isolated mode

Added new java-non-isolated module and refactored
 scripts/module.py to provide isolated_jvm and non_isolated_jvm as a way to
 build and run java apps in isolated (old default) and non-isolated mode.

The non-isolated mode gets enabled by module.py that detects if selected
java module (provides = ['java']) has following attribute set to true like so:

non_isolated_jvm = True

Example to build an image with isolated JVM (default):
./scripts/build image=java,java-example

Example to build an image with non-isolated JVM:
./scripts/build image=java-non-isolated,java-example

Fixes #800

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
Message-Id: <1476475985-1980-1-git-send-email-jwkozac...@gmail.com>

---
diff --git a/modules/java-non-isolated/Makefile b/modules/java-non-isolated/Makefile
--- a/modules/java-non-isolated/Makefile
+++ b/modules/java-non-isolated/Makefile
@@ -0,0 +1,10 @@
+# TODO: need to move compilation of $(java-targets) from the main makefile
+# to here. Unfortunately, compiling with OSv header files is a big mess,
+# and much easier to do it in the main OSv makefile :-(
+SRC = $(shell readlink -f ../..)
+module:
+       cd $(SRC)/java && mvn package -DskipTests=true
+
+clean:
+       cd $(SRC)/java && mvn clean
+       -rm -f dependency-reduced-pom.xml
diff --git a/modules/java-non-isolated/module.py b/modules/java-non-isolated/module.py
--- a/modules/java-non-isolated/module.py
+++ b/modules/java-non-isolated/module.py
@@ -0,0 +1,28 @@
+from osv.modules.filemap import FileMap
+from osv.modules import api
+import os, os.path
+
+usr_files = FileMap()
+
+provides = ['java']
+
+non_isolated_jvm = True
+
+api.require('fonts')
+api.require('ca-certificates')
+api.require('libz')
+api.require('josvsym')
+api.require('httpserver-jolokia-plugin')
+api.require('httpserver-jvm-plugin')
+
+jdkdir = os.path.basename(os.path.expandvars('${jdkbase}'))
+
+usr_files.add('${jdkbase}').to('/usr/lib/jvm/java') \
+    .include('lib/**') \
+    .include('jre/**') \
+    .exclude('jre/lib/security/cacerts') \
+    .exclude('jre/lib/audio/**')
+
+usr_files.link('/usr/lib/jvm/' + jdkdir).to('java')
+usr_files.link('/usr/lib/jvm/jre').to('java/jre')
+usr_files.link('/usr/lib/jvm/java/jre/lib/security/cacerts').to('/etc/pki/java/cacerts')
diff --git a/modules/java-non-isolated/usr.manifest b/modules/java-non-isolated/usr.manifest
--- a/modules/java-non-isolated/usr.manifest
+++ b/modules/java-non-isolated/usr.manifest
@@ -0,0 +1,21 @@
+#
+# Copyright (C) 2013-2014 Cloudius Systems, Ltd.
+#
+# This work is open source software, licensed under the terms of the
+# BSD license as described in the LICENSE file in the top-level directory.
+#
+
+[manifest]
+/usr/lib/&/libexpat.so.1: %(miscbase)s/usr/lib64/&
+/usr/lib/&/libjpeg.so.62: %(miscbase)s/usr/lib64/&
+/usr/lib/jni/balloon.so: java/jni/balloon.so
+/usr/lib/jni/monitor.so: java/jni/monitor.so
+/usr/lib/&/jni/elf-loader.so: java/&
+/usr/lib/&/jni/networking.so: java/&
+/usr/lib/&/jni/stty.so: java/&
+/usr/lib/&/jni/tracepoint.so: java/&
+/usr/lib/&/jni/power.so: java/&
+/java.so: java/jvm/java_non_isolated.so
+/usr/lib/libosv.so: libosv.so
+/usr/lib/jvm/java/jre/lib/ext/runjava.jar: ${OSV_BASE}/java/runjava/target/runjava.jar
+/java/cloudius.jar: ${OSV_BASE}/java/cloudius/target/cloudius.jar
diff --git a/scripts/module.py b/scripts/module.py
--- a/scripts/module.py
+++ b/scripts/module.py
@@ -8,7 +8,7 @@
 from functools import reduce
 from osv.modules import api, resolve, filemap

-class jvm(api.basic_app):
+class isolated_jvm(api.basic_app):
     multimain_manifest = '/etc/javamains'
     apps = []

@@ -33,6 +33,21 @@ def get_launcher_args(self):
     def add(self, app):
         self.apps.append(app)

+    def has_any_app(self):
+        return self.apps
+
+class non_isolated_jvm(api.basic_app):
+    app = None
+
+    def get_launcher_args(self):
+ return ['java.so'] + self.app.get_jvm_args() + self.app.get_multimain_lines()
+
+    def add(self, app):
+        self.app = app
+
+    def has_any_app(self):
+        return self.app
+
 def expand(text, variables):
     def resolve(m):
         name = m.group('name')
@@ -117,7 +132,11 @@ def flatten_list(elememnts):

 def get_basic_apps(apps):
     basic_apps = []
-    _jvm = jvm()
+    java = resolve.require('java')
+    if hasattr(java,'non_isolated_jvm') and java.non_isolated_jvm:
+        _jvm = non_isolated_jvm()
+    else:
+        _jvm = isolated_jvm()

     for app in flatten_list(apps):
         if isinstance(app, api.basic_app):
@@ -127,7 +146,7 @@ def get_basic_apps(apps):
         else:
             raise Exception("Unknown app type: " + str(app))

-    if _jvm.apps:
+    if _jvm.has_any_app():
         basic_apps.append(_jvm)

     return basic_apps

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to