Merge lp:~zorba-coders/zorba/util-jvm_core_module into lp:zorba

Proposed by Chris Hillery
Status: Rejected
Rejected by: Chris Hillery
Proposed branch: lp:~zorba-coders/zorba/util-jvm_core_module
Merge into: lp:zorba
Diff against target: 841 lines (+788/-0)
9 files modified
modules/CMakeLists.txt (+1/-0)
modules/util-jvm/CMakeLists.txt (+88/-0)
modules/util-jvm/JavaVMSingleton.cpp (+267/-0)
modules/util-jvm/config/CMakeLists.txt (+44/-0)
modules/util-jvm/config/ExternalModuleConfig.cmake.in (+40/-0)
modules/util-jvm/config/UtilJavaUse.cmake (+129/-0)
modules/util-jvm/include/JavaVMSingleton.h (+87/-0)
modules/util-jvm/util-jvm.cpp (+92/-0)
modules/util-jvm/util-jvm.xq (+40/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/util-jvm_core_module
Reviewer Review Type Date Requested Status
Cezar Andrei Needs Fixing
Chris Hillery Pending
Review via email: mp+161854@code.launchpad.net

Description of the change

Moves the util-jvm module into the core.

To post a comment you must log in.
Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

modules/ExternalModules.conf file needs to be updated. If the line with util-jvm is left there is build error.

Also, the modules that depend on it have to be fixed too, right now they don't find util-jvm:

-- --- Module: nosqldb ---
-- Zorba's util-jvm module not found; skipping nosqldb module.
-- --- End module: nosqldb ---
-- --- Module: read-pdf ---
-- Zorba's util-jvm module not found; skipping read-pdf module.
-- --- End module: read-pdf ---
-- ******** BEGIN Configuring module Data-Formatting ********
-- Zorba's util-jvm module not found; skipping data-formatting module.
-- ******** END Configuring module Data-Formatting ********

-- Zorba's util-jvm module not found; skipping schema-tools module.

review: Needs Fixing
Revision history for this message
Chris Hillery (ceejatec) wrote :

Fixing ExternalModules.conf should be trivial.

As to the other modules, we'll have to update them after merging this proposal. If we remove the FIND_PACKAGE() from them first, they'll have build errors. If we leave them as-is and merge this one first, then they will quietly get skipped by the remote queue, which is better. We'll just need to immediately commit changes to each of them after the main merge.

Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

Agreed, but we need to have them working before e check anything in.
 On May 1, 2013 5:31 PM, "Chris Hillery" <email address hidden>
wrote:

> Fixing ExternalModules.conf should be trivial.
>
> As to the other modules, we'll have to update them after merging this
> proposal. If we remove the FIND_PACKAGE() from them first, they'll have
> build errors. If we leave them as-is and merge this one first, then they
> will quietly get skipped by the remote queue, which is better. We'll just
> need to immediately commit changes to each of them after the main merge.
> --
>
> https://code.launchpad.net/~zorba-coders/zorba/util-jvm_core_module/+merge/161854
> You are reviewing the proposed merge of
> lp:~zorba-coders/zorba/util-jvm_core_module into lp:zorba.
>

Revision history for this message
Chris Hillery (ceejatec) wrote :

Did you have any other comments, Cezar?

I want to think a bit about the ExternalModuleConfig.cmake that's included here; it looks like it might be redundant with the one in the Zorba trunk, plus I'm not sure it's the right solution to the problem anyway.

11390. By Chris Hillery

Merge from trunk.

Revision history for this message
Chris Hillery (ceejatec) wrote :

I think we can simplify this quite a bit. All Java modules really need are:

1. The macros in UtilJavaUse.cmake (or the location of that file to INCLUDE() it).
2. The location of JavaVMSingleton.h.
3. The location of libutil-java.so (or whatever the dynamic library is called).

We can add those variables directly to the main ZorbaConfig.cmake which is exported from the Zorba project, with appropriate NOTFOUND values if Java support wasn't built into Zorba. Then modules will only need to FIND_PACKAGE(zorba) and check for those variables having valid settings. We can eliminate the entire util-jvm/config directory except for UtilJavaUse.cmake. I believe we can actually eliminate util-jvm.xq too; there's no purpose to the XQuery module that I can see.

Revision history for this message
Chris Hillery (ceejatec) wrote :

This has grown stale and I think it probably needs to be done differently. We will update the branch and re-propose in future.

Unmerged revisions

11390. By Chris Hillery

Merge from trunk.

11389. By Juan Zacarias

Added util-jvm as core module

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'modules/CMakeLists.txt'
--- modules/CMakeLists.txt 2013-02-07 17:24:36 +0000
+++ modules/CMakeLists.txt 2013-05-03 09:36:26 +0000
@@ -16,6 +16,7 @@
16ADD_SUBDIRECTORY(org)16ADD_SUBDIRECTORY(org)
17ADD_SUBDIRECTORY(functx)17ADD_SUBDIRECTORY(functx)
18ADD_SUBDIRECTORY(xqxq)18ADD_SUBDIRECTORY(xqxq)
19ADD_SUBDIRECTORY(util-jvm)
19ADD_SUBDIRECTORY(w3c)20ADD_SUBDIRECTORY(w3c)
2021
21# Add external module projects - any subdirectories of a directory22# Add external module projects - any subdirectories of a directory
2223
=== added directory 'modules/util-jvm'
=== added file 'modules/util-jvm/CMakeLists.txt'
--- modules/util-jvm/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/CMakeLists.txt 2013-05-03 09:36:26 +0000
@@ -0,0 +1,88 @@
1# Copyright 2006-2010 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# missing
16# share use file for other modules
17
18#
19# JAVA
20#
21IF (ZORBA_SUPPRESS_JAVA)
22 MESSAGE (STATUS "ZORBA_SUPPRESS_JAVA is true - not searching for Java")
23ELSE (ZORBA_SUPPRESS_JAVA)
24 #include util-jvm macros
25 INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/config/UtilJavaUse.cmake)
26 MESSAGE(STATUS "-- util-jvm module --")
27 #find packages
28 MESSAGE (STATUS "Looking for JNI")
29 ZORBA_FIND_JNI()
30 MESSAGE (STATUS "Looking for Java")
31 FIND_PACKAGE(Java)
32
33 IF (JNI_FOUND)
34 SET (UTIL_JVM_VERSION 1.0)
35
36 # Export this include directory by setting ZORBA_PROJECT_INCLUDE_DIRS
37 SET (ZORBA_PROJECT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
38 INCLUDE_DIRECTORIES ("${ZORBA_PROJECT_INCLUDE_DIRS}")
39 INSTALL (FILES include/JavaVMSingleton.h DESTINATION include)
40
41 INCLUDE (CMakeJavaInformation )
42 MESSAGE(STATUS "Using Java API")
43 EXECUTE_PROCESS (
44 COMMAND ${JAVA_RUNTIME} -version
45 RESULT_VARIABLE JAVA_VERSION
46 OUTPUT_QUIET
47 ERROR_QUIET)
48
49 MESSAGE (STATUS "JNI found at :${JAVA_INCLUDE_PATH}")
50 MESSAGE (STATUS "Java Library at :${JAVA_JVM_LIBRARY}")
51
52 INCLUDE_DIRECTORIES (${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
53 INCLUDE_DIRECTORIES (${JAVA_INCLUDE_PATH})
54
55 # For now, we still have a module, but it actually does nothing at all.
56 DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/util-jvm"
57 VERSION 1.0 FILE "util-jvm.xq")
58
59 # The important stuff is the library, which we install in Zorba's
60 # default lib directory.
61 ADD_LIBRARY(util-jvm SHARED util-jvm.cpp JavaVMSingleton.cpp)
62 TARGET_LINK_LIBRARIES(util-jvm "${JAVA_JVM_LIBRARY}" zorba_${ZORBA_STORE_NAME})
63 INSTALL(TARGETS util-jvm
64 RUNTIME DESTINATION bin
65 LIBRARY DESTINATION lib${LIB_SUFFIX}
66 ARCHIVE DESTINATION lib)
67
68 ADD_SUBDIRECTORY(config)
69 # MAC OS X only property
70 # this is required to make sure that the library has the correct install name after
71 # installation such that dependent modules always find it
72 #SET_TARGET_PROPERTIES(util-jvm PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
73
74 # Set this in the parent scope so it will be put into our Config.cmake file.
75 # As with many other things, this doesn't work when the module is installed.
76 #SET(ZORBA_PROJECT_LIBRARIES util-jvm PARENT_SCOPE)
77
78 ELSE (JNI_FOUND)
79 MESSAGE(STATUS "Building Zorba without util-jvm module.")
80 ENDIF (JNI_FOUND)
81 MESSAGE(STATUS "---")
82 MESSAGE(STATUS "")
83ENDIF(ZORBA_SUPPRESS_JAVA)
84
85# Cache these variables for ease of packages depending on us
86SET (JAVA_FOUND "${JAVA_FOUND}" CACHE BOOL "Whether Java was found" FORCE)
87SET (JNI_FOUND "${JNI_FOUND}" CACHE BOOL "Whether JNI was found" FORCE)
88
089
=== added file 'modules/util-jvm/JavaVMSingleton.cpp'
--- modules/util-jvm/JavaVMSingleton.cpp 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/JavaVMSingleton.cpp 2013-05-03 09:36:26 +0000
@@ -0,0 +1,267 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
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#include "JavaVMSingleton.h"
18
19#include <fstream>
20#include <iostream>
21#include <istream>
22#include <string>
23#include <cstdlib>
24#include <cstring>
25#include <sstream>
26
27#include <zorba/util/path.h>
28#include <zorba/util/file.h>
29#include <zorba/zorba.h>
30
31
32namespace zorba { namespace jvm {
33JavaVMSingleton* JavaVMSingleton::instance = NULL;
34
35JavaVMSingleton::JavaVMSingleton(const char* classPath, const char* javaLibPath)
36{
37 memset(&args, 0, sizeof(args));
38 jint r;
39 jint nOptions = NO_OF_JVM_OPTIONS;
40
41 std::string classpathOption;
42 std::ostringstream os;
43 os << "-Djava.class.path=" << classPath;
44 classpathOption = os.str();
45 classPathOption = new char[classpathOption.size() + 1];
46 memset(classPathOption, 0, sizeof(char) * (classpathOption.size() + 1));
47 memcpy(classPathOption, classpathOption.c_str(), classpathOption.size() * sizeof(char));
48
49 std::string lAwtArgStr = "-Djava.awt.headless=true";
50 awtOption = new char[lAwtArgStr.size() + 1];
51 memset(awtOption, 0, sizeof(char) * (lAwtArgStr.size() + 1));
52 memcpy(awtOption, lAwtArgStr.c_str(), sizeof(char) * lAwtArgStr.size());
53 awtOption[lAwtArgStr.size()] = 0;
54
55 // javaLibPath are only base pathes, the full path will be computed at runtime in the Java class
56 std::string jlpStr = "-Djava.library.path=" + std::string(javaLibPath);
57 jlpOption = new char[jlpStr.size() + 1];
58 memset(jlpOption, 0, sizeof(char) * (jlpStr.size() + 1));
59 memcpy(jlpOption, jlpStr.c_str(), sizeof(char) * jlpStr.size());
60 jlpOption[jlpStr.size()] = 0;
61
62 options[0].optionString = classPathOption;
63 options[0].extraInfo = NULL;
64 options[1].optionString = awtOption;
65 options[1].extraInfo = NULL;
66 options[2].optionString = jlpOption;
67 options[2].extraInfo = NULL;
68
69 memset(&args, 0, sizeof(args));
70 args.version = JNI_VERSION_1_2;
71 args.nOptions = nOptions;
72 args.options = options;
73 args.ignoreUnrecognized = JNI_FALSE;
74
75 r = JNI_CreateJavaVM(&m_vm, (void **)&m_env, &args);
76 if (r != JNI_OK) {
77 throw VMOpenException();
78 }
79}
80
81JavaVMSingleton::~JavaVMSingleton()
82{
83 if (instance) {
84 delete instance;
85 instance = NULL;
86 }
87 m_vm->DestroyJavaVM();
88 if (awtOption)
89 delete[] awtOption;
90 if (classPathOption)
91 delete[] classPathOption;
92}
93
94/*JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath)
95{
96 return getInstance(classPath, "");
97}*/
98
99JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath, const char* javaLibPath)
100{
101//#ifdef WIN32
102// // If pointer to instance of JavaVMSingleton exists (true) then return instance pointer else look for
103// // instance pointer in memory mapped pointer. If the instance pointer does not exist in
104// // memory mapped pointer, return a newly created pointer to an instance of Abc.
105
106// return instance ?
107// instance : (instance = (JavaVMSingleton*) MemoryMappedPointers::getPointer("JavaVMSingleton")) ?
108// instance : (instance = (JavaVMSingleton*) MemoryMappedPointers::createEntry("JavaVMSingleton",(void*)new JavaVMSingleton(classPath)));
109//#else
110
111
112 // If pointer to instance of JavaVMSingleton exists (true) then return instance pointer
113 // else return a newly created pointer to an instance of JavaVMSingleton.
114 if (instance == NULL)
115 {
116 JavaVM *jvms;
117 jsize nVMs;
118 if ( JNI_GetCreatedJavaVMs(&jvms, 1, &nVMs)==0 )
119 {
120 //std::cout << "Got JVMs " << nVMs << "\n"; std::cout.flush();
121 if (nVMs == 1)
122 {
123 JavaVM *jvm = jvms;
124 JNIEnv *env;
125 if( jvm->AttachCurrentThread((void **)&env, NULL) ==0 )
126 {
127 // if there is a jvm opened already by a diffrent dynamic lib
128 // make a singleton for this lib with that jvm
129 instance = new JavaVMSingleton(jvm, env);
130 }
131 }
132 }
133
134 if (instance == NULL)
135 {
136 instance = new JavaVMSingleton(classPath, javaLibPath);
137 }
138 }
139
140 return instance;
141}
142
143
144
145JavaVMSingleton* JavaVMSingleton::getInstance(const zorba::StaticContext* aStaticContext)
146{
147 if (instance == NULL)
148 {
149 String cp = computeClassPath(aStaticContext);
150 String lp = computeLibPath(aStaticContext);
151 return getInstance(cp.c_str(), lp.c_str());
152 }
153
154 return instance;
155}
156
157JavaVM* JavaVMSingleton::getVM()
158{
159 return m_vm;
160}
161
162JNIEnv* JavaVMSingleton::getEnv()
163{
164 return m_env;
165}
166
167
168String JavaVMSingleton::computeClassPath(const zorba::StaticContext* aStaticContext)
169{
170 String cp;
171
172 // get classpath from global Properties
173 PropertiesGlobal * properties = Zorba::getInstance(NULL)->getPropertiesGlobal();
174 std::string globalClassPath;
175 properties->getJVMClassPath(globalClassPath);
176 cp += globalClassPath;
177
178 std::vector<String> lCPV;
179 aStaticContext->getFullLibPath(lCPV);
180
181 String pathSeparator(filesystem_path::get_path_separator());
182 String dirSeparator(filesystem_path::get_directory_separator());
183
184 for (std::vector<String>::iterator lIter = lCPV.begin();
185 lIter != lCPV.end(); ++lIter)
186 {
187 // verify it contains a jars dir
188 const filesystem_path baseFsPath((*lIter).str());
189 const filesystem_path jarsFsPath(std::string("jars"));
190 filesystem_path jarsDirPath(baseFsPath, jarsFsPath);
191
192 file jarsDir(jarsDirPath);
193
194 if ( jarsDir.exists() && jarsDir.is_directory())
195 {
196 std::vector<std::string> list;
197 jarsDir.lsdir(list);
198
199 for (std::vector<std::string>::iterator itemIter = list.begin();
200 itemIter != list.end(); ++itemIter)
201 {
202 filesystem_path itemLocalFS(*itemIter);
203 filesystem_path itemFS(jarsDirPath, itemLocalFS);
204 file itemFile(itemFS);
205 if ( itemFile.exists() && itemFile.is_file() )
206 {
207 std::string itemName = itemFile.get_path();
208 std::string suffix = "-classpath.txt";
209 size_t found;
210 found = itemName.rfind(suffix);
211 if (found!=std::string::npos &&
212 found + suffix.length() == itemName.length() )
213 {
214 std::auto_ptr<std::istream> pathFile;
215 pathFile.reset(new std::ifstream (itemName.c_str ()));
216 if (!pathFile->good() || pathFile->eof() )
217 {
218 std::cerr << "file {" << itemName << "} not found or not readable." << std::endl;
219 throw itemName;
220 }
221
222 // read file
223 char line[1024];
224 while( !pathFile->eof() && !pathFile->bad() && !pathFile->fail())
225 {
226 pathFile->getline(line, sizeof(line));
227 std::string lineStr(line);
228
229 if ( lineStr.size() == 0 )
230 continue;
231
232 const std::string normalizedPath =
233 filesystem_path::normalize_path( lineStr, jarsDirPath.get_path());
234
235 cp += pathSeparator + normalizedPath;
236 }
237 }
238 }
239 }
240 }
241 }
242
243 properties->setJVMClassPath(cp.str());
244
245 return cp;
246}
247
248
249String JavaVMSingleton::computeLibPath(const zorba::StaticContext* aStaticContext)
250{
251 String lp;
252 std::vector<String> lCPV;
253 String pathSeparator(filesystem_path::get_path_separator());
254
255 aStaticContext->getFullLibPath(lCPV);
256 for (std::vector<String>::iterator lIter = lCPV.begin();
257 lIter != lCPV.end(); ++lIter)
258 {
259 String p = *lIter;
260 lp += pathSeparator + p;
261 }
262
263 return lp;
264}
265
266
267}} // namespace zorba, jvm
0268
=== added directory 'modules/util-jvm/config'
=== added file 'modules/util-jvm/config/CMakeLists.txt'
--- modules/util-jvm/config/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/config/CMakeLists.txt 2013-05-03 09:36:26 +0000
@@ -0,0 +1,44 @@
1# Copyright 2006-2012 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# We need to be able to install util-jvm and then build module projects
16# against that. The "auto-config" approach Zorba provides does not
17# support this, so we roll our own here. This should probably be
18# re-thought in the future.
19
20IF (WIN32)
21 SET (UTILJVM_CMAKE_DIR "cmake" CACHE STRING
22 "Relative path to CMake files in util-jvm installation")
23ELSE (WIN32)
24 SET(UTILJVM_CMAKE_DIR "share/cmake/zorba_util-jvm_module" CACHE STRING
25 "Relative path to CMake files in util-jvm installation")
26ENDIF (WIN32)
27
28
29# First, install the Use file. Doesn't need to be configured since it
30# just contains a macro.
31INSTALL (FILES UtilJavaUse.cmake DESTINATION "${UTILJVM_CMAKE_DIR}")
32
33# Anyway, we set all the same variables to what they should be in the
34# install image, and re-config Zorba's ExternalModuleConfig.cmake.in.
35SET (ZORBA_PROJECT_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
36SET (ZORBA_PROJECT_USE_FILE "${CMAKE_INSTALL_PREFIX}/${UTILJVM_CMAKE_DIR}/UtilJavaUse.cmake")
37GET_TARGET_PROPERTY(_libpath util-jvm LOCATION)
38GET_FILENAME_COMPONENT(_libname "${_libpath}" NAME)
39SET (ZORBA_PROJECT_LIBRARIES "${CMAKE_INSTALL_PREFIX}/lib/${_libname}")
40
41CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/ExternalModuleConfig.cmake.in"
42 "${PROJECT_BINARY_DIR}/install/zorba_util-jvm_moduleConfig.cmake" @ONLY)
43INSTALL(FILES "${PROJECT_BINARY_DIR}/install/zorba_util-jvm_moduleConfig.cmake"
44 DESTINATION "${UTILJVM_CMAKE_DIR}")
045
=== added file 'modules/util-jvm/config/ExternalModuleConfig.cmake.in'
--- modules/util-jvm/config/ExternalModuleConfig.cmake.in 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/config/ExternalModuleConfig.cmake.in 2013-05-03 09:36:26 +0000
@@ -0,0 +1,40 @@
1# Copyright 2006-2010 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15IF (WIN32)
16 SET (PATH_SEP ",")
17ELSE (WIN32)
18 SET (PATH_SEP ":")
19ENDIF (WIN32)
20
21# Probably should have separate URI and LIB paths here someday; will
22# require testdriver to accept --uri-path and --lib-path args
23# Note that this path is meaningless if the module is installed; see
24# bug 966999.
25SET (DEPENDENCY_MODULE_PATH
26 "${DEPENDENCY_MODULE_PATH}${PATH_SEP}@PROJECT_BINARY_DIR@/URI_PATH/${PATH_SEP}${DEPENDENCY_LIB_PATH}${PATH_SEP}@PROJECT_BINARY_DIR@/LIB_PATH/")
27
28# Dynamic libraries created by this project to link against
29SET (zorba_util-jvm_module_LIBRARIES @ZORBA_PROJECT_LIBRARIES@ @ZORBA_MODULE_LIBRARIES@)
30
31# Include directories exported by this project
32SET (zorba_util-jvm_module_INCLUDE_DIRS @ZORBA_PROJECT_INCLUDE_DIRS@)
33
34# Offer a "use file" to the user of this module. For most module
35# packages, this is unnecessary. However it can be utilized by
36# advanced packages which wish to, for example, export a C++ header
37# file to dependent packages. As above, note that this currently is
38# non-functional if this module package is installed; this will only
39# work from a project build directory.
40SET (zorba_util-jvm_module_USE_FILE "@ZORBA_PROJECT_USE_FILE@")
041
=== added file 'modules/util-jvm/config/UtilJavaUse.cmake'
--- modules/util-jvm/config/UtilJavaUse.cmake 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/config/UtilJavaUse.cmake 2013-05-03 09:36:26 +0000
@@ -0,0 +1,129 @@
1# Copyright 2006-2010 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Macro to find a Jar file whose filename possibly includes a version
16# number. Some Apache distributions, such as FOP, include dependent jars
17# with version numbers, and CMake's FIND_FILE() doesn't support glob
18# patterns for the filename. This macro will find .jar files with optional
19# patterns like "-1.0" in the basename.
20#
21# This macro operates the similarly to FIND_FILE(), except it only supports
22# NAMES, PATHS, PATH_SUFFIXES, DOC, and NO_CMAKE_PATH. Other differences:
23# 1. NAMES is required, and it should be passed the basename of the
24# jarfiles without the version number or ".jar" extension.
25# 2. The only search directories will be those on CMAKE_PREFIX_PATH and
26# those specified by PATHS.
27#
28# For example:
29# ZORBA_FIND_JAR (FOP_JAR NAMES fop PATHS ${XSL_FOP_HOME} PATH_SUFFIXES build)
30#
31# will find fop.jar, fop-1.0.jar, or fop-23453.1234.jar, in any directory
32# on CMAKE_PREFIX_PATH or in XSL_FOP_HOME, or in any subdirectory named
33# "build" of any of those directories.
34#
35# For the moment this macro does not check the version number or enforce
36# a particular/minimum version.
37MACRO (ZORBA_FIND_JAR JARVARNAME)
38 IF (NOT COMMAND PARSE_ARGUMENTS)
39 MESSAGE (FATAL_ERROR
40 "Please INCLUDE(\${Zorba_USE_FILE}) file "
41 "prior to calling ZORBA_FIND_JAR().")
42 ENDIF (NOT COMMAND PARSE_ARGUMENTS)
43
44 PARSE_ARGUMENTS (ZFINDJAR "PATHS;NAMES;PATH_SUFFIXES" "DOC"
45 "NO_CMAKE_PATH" ${ARGN})
46
47 IF (NOT ZFINDJAR_NAMES)
48 MESSAGE (FATAL_ERROR "'NAMES' argument is required for ZORBA_FIND_JAR")
49 ENDIF (NOT ZFINDJAR_NAMES)
50
51 # If the value is already cached, don't do anything
52 IF (NOT ${JARVARNAME})
53
54 # Form up the set of directories to search in.
55 SET (_paths)
56 IF (NOT ZFINDJAR_NO_CMAKE_PATH)
57 SET (_paths ${CMAKE_PREFIX_PATH})
58 ENDIF (NOT ZFINDJAR_NO_CMAKE_PATH)
59 IF (ZFINDJAR_PATHS)
60 LIST (APPEND _paths ${ZFINDJAR_PATHS})
61 ENDIF (ZFINDJAR_PATHS)
62 IF (NOT _paths)
63 MESSAGE (WARNING "No place to search for ${ZFINDJAR_NAMES} jars! "
64 "Set either CMAKE_PREFIX_PATH or pass PATHS")
65 ENDIF (NOT _paths)
66
67 # Iterate through each directory looking for each filename
68 SET (_jarpath "${JARVARNAME}-NOTFOUND")
69 FOREACH (_path ${_paths})
70 IF (_jarpath)
71 BREAK ()
72 ENDIF (_jarpath)
73
74 # Iterate through each potential jarname
75 FOREACH (_name ${ZFINDJAR_NAMES})
76 IF (_jarpath)
77 BREAK ()
78 ENDIF (_jarpath)
79
80 # Iterate through current directory and each suffix
81 FOREACH (_dir "" ${ZFINDJAR_PATH_SUFFIXES})
82 # Form up the final full path
83 IF (_dir)
84 SET (_path2 "${_path}/${_dir}")
85 ELSE (_dir)
86 SET (_path2 "${_path}")
87 ENDIF (_dir)
88
89 # First see if the exact filename exists
90 IF (EXISTS "${_path2}/${_name}.jar")
91 SET (_jarpath "${_path2}/${_name}.jar")
92 BREAK ()
93 ENDIF (EXISTS "${_path2}/${_name}.jar")
94
95 # Finally, glob for version variants
96 FILE (GLOB _jarfiles "${_path2}/${_name}-*.jar")
97 IF (_jarfiles)
98 LIST (GET _jarfiles 0 _jarpath)
99 BREAK ()
100 ENDIF (_jarfiles)
101
102 ENDFOREACH (_dir)
103 ENDFOREACH (_name)
104 ENDFOREACH (_path)
105
106 # Cache the results
107 SET (${JARVARNAME} "${_jarpath}" CACHE PATH "${ZFINDJAR_DOC}" FORCE)
108
109 ENDIF (NOT ${JARVARNAME})
110
111ENDMACRO (ZORBA_FIND_JAR)
112
113MACRO (ZORBA_FIND_JNI)
114 IF (UNIX AND NOT APPLE)
115 # setting JAVA_HOME to bypass issues in FindJNI.cmake
116 FIND_FILE(_JAVA_BIN_LOC NAMES java PATHS ENV PATH)
117 IF (_JAVA_BIN_LOC)
118 GET_FILENAME_COMPONENT(_JAVA_BIN_LOC "${_JAVA_BIN_LOC}" REALPATH)
119 GET_FILENAME_COMPONENT(_JAVA_BIN_DIR ${_JAVA_BIN_LOC} PATH)
120 GET_FILENAME_COMPONENT(_JAVA_HOME "${_JAVA_BIN_DIR}/../.." ABSOLUTE)
121 MESSAGE(
122 STATUS "Generated JAVA_HOME to support FindJNI.cmake: "
123 ${_JAVA_HOME})
124 SET(ENV{JAVA_HOME} ${_JAVA_HOME})
125 ENDIF()
126 ENDIF()
127
128 FIND_PACKAGE(JNI)
129ENDMACRO (ZORBA_FIND_JNI)
0130
=== added directory 'modules/util-jvm/include'
=== added file 'modules/util-jvm/include/JavaVMSingleton.h'
--- modules/util-jvm/include/JavaVMSingleton.h 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/include/JavaVMSingleton.h 2013-05-03 09:36:26 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
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#ifndef JAVA_VM_SINGLETON
18#define JAVA_VM_SINGLETON
19
20#include <jni.h>
21#include <zorba/static_context.h>
22
23# if defined WIN32 || defined CYGWIN
24# ifdef util_jvm_EXPORTS
25# ifdef __GNUC__
26# define UTIL_JVM_DLL_PUBLIC __attribute__((dllexport))
27# else
28# define UTIL_JVM_DLL_PUBLIC __declspec(dllexport)
29# endif /* __GNUC__ */
30# else /* util_jvm_EXPORTS */
31# ifdef __GNUC__
32# define UTIL_JVM_DLL_PUBLIC __attribute__((dllimport))
33# else
34# define UTIL_JVM_DLL_PUBLIC __declspec(dllimport)
35# endif /* __GNUC__ */
36# endif /* util_jvm_EXPORTS */
37# else
38# if __GNUC__ >= 4
39# define UTIL_JVM_DLL_PUBLIC __attribute__ ((visibility("default")))
40# else
41# define UTIL_JVM_DLL_PUBLIC
42# endif
43# endif
44
45namespace zorba { namespace jvm {
46
47#define NO_OF_JVM_OPTIONS 3
48
49
50class VMOpenException {};
51
52class UTIL_JVM_DLL_PUBLIC JavaVMSingleton
53{
54public:
55 //static JavaVMSingleton* getInstance(const char* classPath);
56 static JavaVMSingleton* getInstance(const char* classPath, const char* javaLibPath);
57 static JavaVMSingleton* getInstance(const zorba::StaticContext* aStaticContext);
58
59 virtual ~JavaVMSingleton();
60 JavaVM* getVM();
61 JNIEnv* getEnv();
62
63protected:
64 JavaVMSingleton(const char* classPath, const char* javaLibPath);
65 JavaVMSingleton(JavaVM *jvm, JNIEnv *env) : m_vm(jvm), m_env(env) {}
66 static String computeClassPath(const zorba::StaticContext* aStaticContext);
67 static String computeLibPath(const zorba::StaticContext* aStaticContext);
68
69 static JavaVMSingleton* instance;
70 JavaVM* m_vm;
71 JNIEnv* m_env;
72 JavaVMInitArgs args;
73 JavaVMOption options[NO_OF_JVM_OPTIONS];
74
75 char* classPathOption;
76 char* awtOption;
77 char* jlpOption;
78};
79
80
81}} //namespace zorba, jvm
82
83#endif // JAVA_VM_SINGLETON
84
85
86
87
088
=== added file 'modules/util-jvm/util-jvm.cpp'
--- modules/util-jvm/util-jvm.cpp 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/util-jvm.cpp 2013-05-03 09:36:26 +0000
@@ -0,0 +1,92 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
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#include <sstream>
17#include <iostream>
18#include <cstdlib>
19#include <list>
20
21#include <zorba/base64.h>
22#include <zorba/empty_sequence.h>
23#include <zorba/diagnostic_list.h>
24#include <zorba/function.h>
25#include <zorba/external_module.h>
26#include <zorba/user_exception.h>
27#include <zorba/file.h>
28#include <zorba/item_factory.h>
29#include <zorba/serializer.h>
30#include <zorba/singleton_item_sequence.h>
31#include <zorba/vector_item_sequence.h>
32#include <zorba/zorba.h>
33
34#include "JavaVMSingleton.h"
35
36#define UTILJVM_MODULE_NAMESPACE "http://www.zorba-xquery.com/modules/util-jvm"
37#define UTILJVM_OPTIONS_NAMESPACE "http://www.zorba-xquery.com/modules/util-jvm/util-jvm-options"
38
39class JavaException {
40};
41
42#define CHECK_EXCEPTION(env) if ((lException = env->ExceptionOccurred())) throw JavaException()
43
44namespace zorba
45{
46 namespace utiljvm
47 {
48
49 class UtilJvmModule;
50
51 class UtilJvmModule : public ExternalModule {
52 private:
53
54 public:
55 UtilJvmModule() {}
56
57 virtual ~UtilJvmModule()
58 {}
59
60 virtual String getURI() const
61 {
62 return UTILJVM_MODULE_NAMESPACE;
63 }
64
65 virtual ExternalFunction*
66 getExternalFunction(const String& localName);
67
68 virtual void destroy()
69 {
70 delete this;
71 }
72 };
73
74
75 ExternalFunction*
76 UtilJvmModule::getExternalFunction(const String& localName)
77 {
78 return 0;
79 }
80
81 }}; // namespace zorba, utiljvm
82
83#ifdef WIN32
84# define DLL_EXPORT __declspec(dllexport)
85#else
86# define DLL_EXPORT __attribute__ ((visibility("default")))
87#endif
88
89extern "C" DLL_EXPORT zorba::ExternalModule* createModule()
90{
91 return new zorba::utiljvm::UtilJvmModule();
92}
093
=== added file 'modules/util-jvm/util-jvm.xq'
--- modules/util-jvm/util-jvm.xq 1970-01-01 00:00:00 +0000
+++ modules/util-jvm/util-jvm.xq 2013-05-03 09:36:26 +0000
@@ -0,0 +1,40 @@
1xquery version "1.0";
2
3(:
4 : Copyright 2006-2009 The FLWOR Foundation.
5 :
6 : Licensed under the Apache License, Version 2.0 (the "License");
7 : you may not use this file except in compliance with the License.
8 : You may obtain a copy of the License at
9 :
10 : http://www.apache.org/licenses/LICENSE-2.0
11 :
12 : Unless required by applicable law or agreed to in writing, software
13 : distributed under the License is distributed on an "AS IS" BASIS,
14 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : See the License for the specific language governing permissions and
16 : limitations under the License.
17 :)
18
19(:~
20 : This module provides common functionality for modules that use java
21 : implementations.
22 : <br/>
23 : <br/>
24 : Modules using java implementations must import this module
25 : to specify the dependency.
26 : <br />
27 : <br />
28 : <b>Note:</b> Since this module has a Java library dependency a JVM is required
29 : to be installed on the system. For Windows: jvm.dll is required on the system
30 : path (usually located in "C:\Program Files\Java\jre\bin\client").
31 :
32 : @author Cezar Andrei
33 : @library <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">JDK - Java Development Kit</a>
34 : @project utils/util jvm
35 :)
36module namespace util-jvm = "http://www.zorba-xquery.com/modules/util-jvm";
37
38declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
39declare option ver:module-version "1.0";
40

Subscribers

People subscribed via source and target branches