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
1=== modified file 'modules/CMakeLists.txt'
2--- modules/CMakeLists.txt 2013-02-07 17:24:36 +0000
3+++ modules/CMakeLists.txt 2013-05-03 09:36:26 +0000
4@@ -16,6 +16,7 @@
5 ADD_SUBDIRECTORY(org)
6 ADD_SUBDIRECTORY(functx)
7 ADD_SUBDIRECTORY(xqxq)
8+ADD_SUBDIRECTORY(util-jvm)
9 ADD_SUBDIRECTORY(w3c)
10
11 # Add external module projects - any subdirectories of a directory
12
13=== added directory 'modules/util-jvm'
14=== added file 'modules/util-jvm/CMakeLists.txt'
15--- modules/util-jvm/CMakeLists.txt 1970-01-01 00:00:00 +0000
16+++ modules/util-jvm/CMakeLists.txt 2013-05-03 09:36:26 +0000
17@@ -0,0 +1,88 @@
18+# Copyright 2006-2010 The FLWOR Foundation.
19+#
20+# Licensed under the Apache License, Version 2.0 (the "License");
21+# you may not use this file except in compliance with the License.
22+# You may obtain a copy of the License at
23+#
24+# http://www.apache.org/licenses/LICENSE-2.0
25+#
26+# Unless required by applicable law or agreed to in writing, software
27+# distributed under the License is distributed on an "AS IS" BASIS,
28+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+# See the License for the specific language governing permissions and
30+# limitations under the License.
31+
32+# missing
33+# share use file for other modules
34+
35+#
36+# JAVA
37+#
38+IF (ZORBA_SUPPRESS_JAVA)
39+ MESSAGE (STATUS "ZORBA_SUPPRESS_JAVA is true - not searching for Java")
40+ELSE (ZORBA_SUPPRESS_JAVA)
41+ #include util-jvm macros
42+ INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/config/UtilJavaUse.cmake)
43+ MESSAGE(STATUS "-- util-jvm module --")
44+ #find packages
45+ MESSAGE (STATUS "Looking for JNI")
46+ ZORBA_FIND_JNI()
47+ MESSAGE (STATUS "Looking for Java")
48+ FIND_PACKAGE(Java)
49+
50+ IF (JNI_FOUND)
51+ SET (UTIL_JVM_VERSION 1.0)
52+
53+ # Export this include directory by setting ZORBA_PROJECT_INCLUDE_DIRS
54+ SET (ZORBA_PROJECT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include")
55+ INCLUDE_DIRECTORIES ("${ZORBA_PROJECT_INCLUDE_DIRS}")
56+ INSTALL (FILES include/JavaVMSingleton.h DESTINATION include)
57+
58+ INCLUDE (CMakeJavaInformation )
59+ MESSAGE(STATUS "Using Java API")
60+ EXECUTE_PROCESS (
61+ COMMAND ${JAVA_RUNTIME} -version
62+ RESULT_VARIABLE JAVA_VERSION
63+ OUTPUT_QUIET
64+ ERROR_QUIET)
65+
66+ MESSAGE (STATUS "JNI found at :${JAVA_INCLUDE_PATH}")
67+ MESSAGE (STATUS "Java Library at :${JAVA_JVM_LIBRARY}")
68+
69+ INCLUDE_DIRECTORIES (${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
70+ INCLUDE_DIRECTORIES (${JAVA_INCLUDE_PATH})
71+
72+ # For now, we still have a module, but it actually does nothing at all.
73+ DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/util-jvm"
74+ VERSION 1.0 FILE "util-jvm.xq")
75+
76+ # The important stuff is the library, which we install in Zorba's
77+ # default lib directory.
78+ ADD_LIBRARY(util-jvm SHARED util-jvm.cpp JavaVMSingleton.cpp)
79+ TARGET_LINK_LIBRARIES(util-jvm "${JAVA_JVM_LIBRARY}" zorba_${ZORBA_STORE_NAME})
80+ INSTALL(TARGETS util-jvm
81+ RUNTIME DESTINATION bin
82+ LIBRARY DESTINATION lib${LIB_SUFFIX}
83+ ARCHIVE DESTINATION lib)
84+
85+ ADD_SUBDIRECTORY(config)
86+ # MAC OS X only property
87+ # this is required to make sure that the library has the correct install name after
88+ # installation such that dependent modules always find it
89+ #SET_TARGET_PROPERTIES(util-jvm PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
90+
91+ # Set this in the parent scope so it will be put into our Config.cmake file.
92+ # As with many other things, this doesn't work when the module is installed.
93+ #SET(ZORBA_PROJECT_LIBRARIES util-jvm PARENT_SCOPE)
94+
95+ ELSE (JNI_FOUND)
96+ MESSAGE(STATUS "Building Zorba without util-jvm module.")
97+ ENDIF (JNI_FOUND)
98+ MESSAGE(STATUS "---")
99+ MESSAGE(STATUS "")
100+ENDIF(ZORBA_SUPPRESS_JAVA)
101+
102+# Cache these variables for ease of packages depending on us
103+SET (JAVA_FOUND "${JAVA_FOUND}" CACHE BOOL "Whether Java was found" FORCE)
104+SET (JNI_FOUND "${JNI_FOUND}" CACHE BOOL "Whether JNI was found" FORCE)
105+
106
107=== added file 'modules/util-jvm/JavaVMSingleton.cpp'
108--- modules/util-jvm/JavaVMSingleton.cpp 1970-01-01 00:00:00 +0000
109+++ modules/util-jvm/JavaVMSingleton.cpp 2013-05-03 09:36:26 +0000
110@@ -0,0 +1,267 @@
111+/*
112+ * Copyright 2006-2008 The FLWOR Foundation.
113+ *
114+ * Licensed under the Apache License, Version 2.0 (the "License");
115+ * you may not use this file except in compliance with the License.
116+ * You may obtain a copy of the License at
117+ *
118+ * http://www.apache.org/licenses/LICENSE-2.0
119+ *
120+ * Unless required by applicable law or agreed to in writing, software
121+ * distributed under the License is distributed on an "AS IS" BASIS,
122+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123+ * See the License for the specific language governing permissions and
124+ * limitations under the License.
125+ */
126+
127+#include "JavaVMSingleton.h"
128+
129+#include <fstream>
130+#include <iostream>
131+#include <istream>
132+#include <string>
133+#include <cstdlib>
134+#include <cstring>
135+#include <sstream>
136+
137+#include <zorba/util/path.h>
138+#include <zorba/util/file.h>
139+#include <zorba/zorba.h>
140+
141+
142+namespace zorba { namespace jvm {
143+JavaVMSingleton* JavaVMSingleton::instance = NULL;
144+
145+JavaVMSingleton::JavaVMSingleton(const char* classPath, const char* javaLibPath)
146+{
147+ memset(&args, 0, sizeof(args));
148+ jint r;
149+ jint nOptions = NO_OF_JVM_OPTIONS;
150+
151+ std::string classpathOption;
152+ std::ostringstream os;
153+ os << "-Djava.class.path=" << classPath;
154+ classpathOption = os.str();
155+ classPathOption = new char[classpathOption.size() + 1];
156+ memset(classPathOption, 0, sizeof(char) * (classpathOption.size() + 1));
157+ memcpy(classPathOption, classpathOption.c_str(), classpathOption.size() * sizeof(char));
158+
159+ std::string lAwtArgStr = "-Djava.awt.headless=true";
160+ awtOption = new char[lAwtArgStr.size() + 1];
161+ memset(awtOption, 0, sizeof(char) * (lAwtArgStr.size() + 1));
162+ memcpy(awtOption, lAwtArgStr.c_str(), sizeof(char) * lAwtArgStr.size());
163+ awtOption[lAwtArgStr.size()] = 0;
164+
165+ // javaLibPath are only base pathes, the full path will be computed at runtime in the Java class
166+ std::string jlpStr = "-Djava.library.path=" + std::string(javaLibPath);
167+ jlpOption = new char[jlpStr.size() + 1];
168+ memset(jlpOption, 0, sizeof(char) * (jlpStr.size() + 1));
169+ memcpy(jlpOption, jlpStr.c_str(), sizeof(char) * jlpStr.size());
170+ jlpOption[jlpStr.size()] = 0;
171+
172+ options[0].optionString = classPathOption;
173+ options[0].extraInfo = NULL;
174+ options[1].optionString = awtOption;
175+ options[1].extraInfo = NULL;
176+ options[2].optionString = jlpOption;
177+ options[2].extraInfo = NULL;
178+
179+ memset(&args, 0, sizeof(args));
180+ args.version = JNI_VERSION_1_2;
181+ args.nOptions = nOptions;
182+ args.options = options;
183+ args.ignoreUnrecognized = JNI_FALSE;
184+
185+ r = JNI_CreateJavaVM(&m_vm, (void **)&m_env, &args);
186+ if (r != JNI_OK) {
187+ throw VMOpenException();
188+ }
189+}
190+
191+JavaVMSingleton::~JavaVMSingleton()
192+{
193+ if (instance) {
194+ delete instance;
195+ instance = NULL;
196+ }
197+ m_vm->DestroyJavaVM();
198+ if (awtOption)
199+ delete[] awtOption;
200+ if (classPathOption)
201+ delete[] classPathOption;
202+}
203+
204+/*JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath)
205+{
206+ return getInstance(classPath, "");
207+}*/
208+
209+JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath, const char* javaLibPath)
210+{
211+//#ifdef WIN32
212+// // If pointer to instance of JavaVMSingleton exists (true) then return instance pointer else look for
213+// // instance pointer in memory mapped pointer. If the instance pointer does not exist in
214+// // memory mapped pointer, return a newly created pointer to an instance of Abc.
215+
216+// return instance ?
217+// instance : (instance = (JavaVMSingleton*) MemoryMappedPointers::getPointer("JavaVMSingleton")) ?
218+// instance : (instance = (JavaVMSingleton*) MemoryMappedPointers::createEntry("JavaVMSingleton",(void*)new JavaVMSingleton(classPath)));
219+//#else
220+
221+
222+ // If pointer to instance of JavaVMSingleton exists (true) then return instance pointer
223+ // else return a newly created pointer to an instance of JavaVMSingleton.
224+ if (instance == NULL)
225+ {
226+ JavaVM *jvms;
227+ jsize nVMs;
228+ if ( JNI_GetCreatedJavaVMs(&jvms, 1, &nVMs)==0 )
229+ {
230+ //std::cout << "Got JVMs " << nVMs << "\n"; std::cout.flush();
231+ if (nVMs == 1)
232+ {
233+ JavaVM *jvm = jvms;
234+ JNIEnv *env;
235+ if( jvm->AttachCurrentThread((void **)&env, NULL) ==0 )
236+ {
237+ // if there is a jvm opened already by a diffrent dynamic lib
238+ // make a singleton for this lib with that jvm
239+ instance = new JavaVMSingleton(jvm, env);
240+ }
241+ }
242+ }
243+
244+ if (instance == NULL)
245+ {
246+ instance = new JavaVMSingleton(classPath, javaLibPath);
247+ }
248+ }
249+
250+ return instance;
251+}
252+
253+
254+
255+JavaVMSingleton* JavaVMSingleton::getInstance(const zorba::StaticContext* aStaticContext)
256+{
257+ if (instance == NULL)
258+ {
259+ String cp = computeClassPath(aStaticContext);
260+ String lp = computeLibPath(aStaticContext);
261+ return getInstance(cp.c_str(), lp.c_str());
262+ }
263+
264+ return instance;
265+}
266+
267+JavaVM* JavaVMSingleton::getVM()
268+{
269+ return m_vm;
270+}
271+
272+JNIEnv* JavaVMSingleton::getEnv()
273+{
274+ return m_env;
275+}
276+
277+
278+String JavaVMSingleton::computeClassPath(const zorba::StaticContext* aStaticContext)
279+{
280+ String cp;
281+
282+ // get classpath from global Properties
283+ PropertiesGlobal * properties = Zorba::getInstance(NULL)->getPropertiesGlobal();
284+ std::string globalClassPath;
285+ properties->getJVMClassPath(globalClassPath);
286+ cp += globalClassPath;
287+
288+ std::vector<String> lCPV;
289+ aStaticContext->getFullLibPath(lCPV);
290+
291+ String pathSeparator(filesystem_path::get_path_separator());
292+ String dirSeparator(filesystem_path::get_directory_separator());
293+
294+ for (std::vector<String>::iterator lIter = lCPV.begin();
295+ lIter != lCPV.end(); ++lIter)
296+ {
297+ // verify it contains a jars dir
298+ const filesystem_path baseFsPath((*lIter).str());
299+ const filesystem_path jarsFsPath(std::string("jars"));
300+ filesystem_path jarsDirPath(baseFsPath, jarsFsPath);
301+
302+ file jarsDir(jarsDirPath);
303+
304+ if ( jarsDir.exists() && jarsDir.is_directory())
305+ {
306+ std::vector<std::string> list;
307+ jarsDir.lsdir(list);
308+
309+ for (std::vector<std::string>::iterator itemIter = list.begin();
310+ itemIter != list.end(); ++itemIter)
311+ {
312+ filesystem_path itemLocalFS(*itemIter);
313+ filesystem_path itemFS(jarsDirPath, itemLocalFS);
314+ file itemFile(itemFS);
315+ if ( itemFile.exists() && itemFile.is_file() )
316+ {
317+ std::string itemName = itemFile.get_path();
318+ std::string suffix = "-classpath.txt";
319+ size_t found;
320+ found = itemName.rfind(suffix);
321+ if (found!=std::string::npos &&
322+ found + suffix.length() == itemName.length() )
323+ {
324+ std::auto_ptr<std::istream> pathFile;
325+ pathFile.reset(new std::ifstream (itemName.c_str ()));
326+ if (!pathFile->good() || pathFile->eof() )
327+ {
328+ std::cerr << "file {" << itemName << "} not found or not readable." << std::endl;
329+ throw itemName;
330+ }
331+
332+ // read file
333+ char line[1024];
334+ while( !pathFile->eof() && !pathFile->bad() && !pathFile->fail())
335+ {
336+ pathFile->getline(line, sizeof(line));
337+ std::string lineStr(line);
338+
339+ if ( lineStr.size() == 0 )
340+ continue;
341+
342+ const std::string normalizedPath =
343+ filesystem_path::normalize_path( lineStr, jarsDirPath.get_path());
344+
345+ cp += pathSeparator + normalizedPath;
346+ }
347+ }
348+ }
349+ }
350+ }
351+ }
352+
353+ properties->setJVMClassPath(cp.str());
354+
355+ return cp;
356+}
357+
358+
359+String JavaVMSingleton::computeLibPath(const zorba::StaticContext* aStaticContext)
360+{
361+ String lp;
362+ std::vector<String> lCPV;
363+ String pathSeparator(filesystem_path::get_path_separator());
364+
365+ aStaticContext->getFullLibPath(lCPV);
366+ for (std::vector<String>::iterator lIter = lCPV.begin();
367+ lIter != lCPV.end(); ++lIter)
368+ {
369+ String p = *lIter;
370+ lp += pathSeparator + p;
371+ }
372+
373+ return lp;
374+}
375+
376+
377+}} // namespace zorba, jvm
378
379=== added directory 'modules/util-jvm/config'
380=== added file 'modules/util-jvm/config/CMakeLists.txt'
381--- modules/util-jvm/config/CMakeLists.txt 1970-01-01 00:00:00 +0000
382+++ modules/util-jvm/config/CMakeLists.txt 2013-05-03 09:36:26 +0000
383@@ -0,0 +1,44 @@
384+# Copyright 2006-2012 The FLWOR Foundation.
385+#
386+# Licensed under the Apache License, Version 2.0 (the "License");
387+# you may not use this file except in compliance with the License.
388+# You may obtain a copy of the License at
389+#
390+# http://www.apache.org/licenses/LICENSE-2.0
391+#
392+# Unless required by applicable law or agreed to in writing, software
393+# distributed under the License is distributed on an "AS IS" BASIS,
394+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
395+# See the License for the specific language governing permissions and
396+# limitations under the License.
397+
398+# We need to be able to install util-jvm and then build module projects
399+# against that. The "auto-config" approach Zorba provides does not
400+# support this, so we roll our own here. This should probably be
401+# re-thought in the future.
402+
403+IF (WIN32)
404+ SET (UTILJVM_CMAKE_DIR "cmake" CACHE STRING
405+ "Relative path to CMake files in util-jvm installation")
406+ELSE (WIN32)
407+ SET(UTILJVM_CMAKE_DIR "share/cmake/zorba_util-jvm_module" CACHE STRING
408+ "Relative path to CMake files in util-jvm installation")
409+ENDIF (WIN32)
410+
411+
412+# First, install the Use file. Doesn't need to be configured since it
413+# just contains a macro.
414+INSTALL (FILES UtilJavaUse.cmake DESTINATION "${UTILJVM_CMAKE_DIR}")
415+
416+# Anyway, we set all the same variables to what they should be in the
417+# install image, and re-config Zorba's ExternalModuleConfig.cmake.in.
418+SET (ZORBA_PROJECT_INCLUDE_DIRS "${CMAKE_INSTALL_PREFIX}/include")
419+SET (ZORBA_PROJECT_USE_FILE "${CMAKE_INSTALL_PREFIX}/${UTILJVM_CMAKE_DIR}/UtilJavaUse.cmake")
420+GET_TARGET_PROPERTY(_libpath util-jvm LOCATION)
421+GET_FILENAME_COMPONENT(_libname "${_libpath}" NAME)
422+SET (ZORBA_PROJECT_LIBRARIES "${CMAKE_INSTALL_PREFIX}/lib/${_libname}")
423+
424+CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/ExternalModuleConfig.cmake.in"
425+ "${PROJECT_BINARY_DIR}/install/zorba_util-jvm_moduleConfig.cmake" @ONLY)
426+INSTALL(FILES "${PROJECT_BINARY_DIR}/install/zorba_util-jvm_moduleConfig.cmake"
427+ DESTINATION "${UTILJVM_CMAKE_DIR}")
428
429=== added file 'modules/util-jvm/config/ExternalModuleConfig.cmake.in'
430--- modules/util-jvm/config/ExternalModuleConfig.cmake.in 1970-01-01 00:00:00 +0000
431+++ modules/util-jvm/config/ExternalModuleConfig.cmake.in 2013-05-03 09:36:26 +0000
432@@ -0,0 +1,40 @@
433+# Copyright 2006-2010 The FLWOR Foundation.
434+#
435+# Licensed under the Apache License, Version 2.0 (the "License");
436+# you may not use this file except in compliance with the License.
437+# You may obtain a copy of the License at
438+#
439+# http://www.apache.org/licenses/LICENSE-2.0
440+#
441+# Unless required by applicable law or agreed to in writing, software
442+# distributed under the License is distributed on an "AS IS" BASIS,
443+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
444+# See the License for the specific language governing permissions and
445+# limitations under the License.
446+
447+IF (WIN32)
448+ SET (PATH_SEP ",")
449+ELSE (WIN32)
450+ SET (PATH_SEP ":")
451+ENDIF (WIN32)
452+
453+# Probably should have separate URI and LIB paths here someday; will
454+# require testdriver to accept --uri-path and --lib-path args
455+# Note that this path is meaningless if the module is installed; see
456+# bug 966999.
457+SET (DEPENDENCY_MODULE_PATH
458+ "${DEPENDENCY_MODULE_PATH}${PATH_SEP}@PROJECT_BINARY_DIR@/URI_PATH/${PATH_SEP}${DEPENDENCY_LIB_PATH}${PATH_SEP}@PROJECT_BINARY_DIR@/LIB_PATH/")
459+
460+# Dynamic libraries created by this project to link against
461+SET (zorba_util-jvm_module_LIBRARIES @ZORBA_PROJECT_LIBRARIES@ @ZORBA_MODULE_LIBRARIES@)
462+
463+# Include directories exported by this project
464+SET (zorba_util-jvm_module_INCLUDE_DIRS @ZORBA_PROJECT_INCLUDE_DIRS@)
465+
466+# Offer a "use file" to the user of this module. For most module
467+# packages, this is unnecessary. However it can be utilized by
468+# advanced packages which wish to, for example, export a C++ header
469+# file to dependent packages. As above, note that this currently is
470+# non-functional if this module package is installed; this will only
471+# work from a project build directory.
472+SET (zorba_util-jvm_module_USE_FILE "@ZORBA_PROJECT_USE_FILE@")
473
474=== added file 'modules/util-jvm/config/UtilJavaUse.cmake'
475--- modules/util-jvm/config/UtilJavaUse.cmake 1970-01-01 00:00:00 +0000
476+++ modules/util-jvm/config/UtilJavaUse.cmake 2013-05-03 09:36:26 +0000
477@@ -0,0 +1,129 @@
478+# Copyright 2006-2010 The FLWOR Foundation.
479+#
480+# Licensed under the Apache License, Version 2.0 (the "License");
481+# you may not use this file except in compliance with the License.
482+# You may obtain a copy of the License at
483+#
484+# http://www.apache.org/licenses/LICENSE-2.0
485+#
486+# Unless required by applicable law or agreed to in writing, software
487+# distributed under the License is distributed on an "AS IS" BASIS,
488+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
489+# See the License for the specific language governing permissions and
490+# limitations under the License.
491+
492+# Macro to find a Jar file whose filename possibly includes a version
493+# number. Some Apache distributions, such as FOP, include dependent jars
494+# with version numbers, and CMake's FIND_FILE() doesn't support glob
495+# patterns for the filename. This macro will find .jar files with optional
496+# patterns like "-1.0" in the basename.
497+#
498+# This macro operates the similarly to FIND_FILE(), except it only supports
499+# NAMES, PATHS, PATH_SUFFIXES, DOC, and NO_CMAKE_PATH. Other differences:
500+# 1. NAMES is required, and it should be passed the basename of the
501+# jarfiles without the version number or ".jar" extension.
502+# 2. The only search directories will be those on CMAKE_PREFIX_PATH and
503+# those specified by PATHS.
504+#
505+# For example:
506+# ZORBA_FIND_JAR (FOP_JAR NAMES fop PATHS ${XSL_FOP_HOME} PATH_SUFFIXES build)
507+#
508+# will find fop.jar, fop-1.0.jar, or fop-23453.1234.jar, in any directory
509+# on CMAKE_PREFIX_PATH or in XSL_FOP_HOME, or in any subdirectory named
510+# "build" of any of those directories.
511+#
512+# For the moment this macro does not check the version number or enforce
513+# a particular/minimum version.
514+MACRO (ZORBA_FIND_JAR JARVARNAME)
515+ IF (NOT COMMAND PARSE_ARGUMENTS)
516+ MESSAGE (FATAL_ERROR
517+ "Please INCLUDE(\${Zorba_USE_FILE}) file "
518+ "prior to calling ZORBA_FIND_JAR().")
519+ ENDIF (NOT COMMAND PARSE_ARGUMENTS)
520+
521+ PARSE_ARGUMENTS (ZFINDJAR "PATHS;NAMES;PATH_SUFFIXES" "DOC"
522+ "NO_CMAKE_PATH" ${ARGN})
523+
524+ IF (NOT ZFINDJAR_NAMES)
525+ MESSAGE (FATAL_ERROR "'NAMES' argument is required for ZORBA_FIND_JAR")
526+ ENDIF (NOT ZFINDJAR_NAMES)
527+
528+ # If the value is already cached, don't do anything
529+ IF (NOT ${JARVARNAME})
530+
531+ # Form up the set of directories to search in.
532+ SET (_paths)
533+ IF (NOT ZFINDJAR_NO_CMAKE_PATH)
534+ SET (_paths ${CMAKE_PREFIX_PATH})
535+ ENDIF (NOT ZFINDJAR_NO_CMAKE_PATH)
536+ IF (ZFINDJAR_PATHS)
537+ LIST (APPEND _paths ${ZFINDJAR_PATHS})
538+ ENDIF (ZFINDJAR_PATHS)
539+ IF (NOT _paths)
540+ MESSAGE (WARNING "No place to search for ${ZFINDJAR_NAMES} jars! "
541+ "Set either CMAKE_PREFIX_PATH or pass PATHS")
542+ ENDIF (NOT _paths)
543+
544+ # Iterate through each directory looking for each filename
545+ SET (_jarpath "${JARVARNAME}-NOTFOUND")
546+ FOREACH (_path ${_paths})
547+ IF (_jarpath)
548+ BREAK ()
549+ ENDIF (_jarpath)
550+
551+ # Iterate through each potential jarname
552+ FOREACH (_name ${ZFINDJAR_NAMES})
553+ IF (_jarpath)
554+ BREAK ()
555+ ENDIF (_jarpath)
556+
557+ # Iterate through current directory and each suffix
558+ FOREACH (_dir "" ${ZFINDJAR_PATH_SUFFIXES})
559+ # Form up the final full path
560+ IF (_dir)
561+ SET (_path2 "${_path}/${_dir}")
562+ ELSE (_dir)
563+ SET (_path2 "${_path}")
564+ ENDIF (_dir)
565+
566+ # First see if the exact filename exists
567+ IF (EXISTS "${_path2}/${_name}.jar")
568+ SET (_jarpath "${_path2}/${_name}.jar")
569+ BREAK ()
570+ ENDIF (EXISTS "${_path2}/${_name}.jar")
571+
572+ # Finally, glob for version variants
573+ FILE (GLOB _jarfiles "${_path2}/${_name}-*.jar")
574+ IF (_jarfiles)
575+ LIST (GET _jarfiles 0 _jarpath)
576+ BREAK ()
577+ ENDIF (_jarfiles)
578+
579+ ENDFOREACH (_dir)
580+ ENDFOREACH (_name)
581+ ENDFOREACH (_path)
582+
583+ # Cache the results
584+ SET (${JARVARNAME} "${_jarpath}" CACHE PATH "${ZFINDJAR_DOC}" FORCE)
585+
586+ ENDIF (NOT ${JARVARNAME})
587+
588+ENDMACRO (ZORBA_FIND_JAR)
589+
590+MACRO (ZORBA_FIND_JNI)
591+ IF (UNIX AND NOT APPLE)
592+ # setting JAVA_HOME to bypass issues in FindJNI.cmake
593+ FIND_FILE(_JAVA_BIN_LOC NAMES java PATHS ENV PATH)
594+ IF (_JAVA_BIN_LOC)
595+ GET_FILENAME_COMPONENT(_JAVA_BIN_LOC "${_JAVA_BIN_LOC}" REALPATH)
596+ GET_FILENAME_COMPONENT(_JAVA_BIN_DIR ${_JAVA_BIN_LOC} PATH)
597+ GET_FILENAME_COMPONENT(_JAVA_HOME "${_JAVA_BIN_DIR}/../.." ABSOLUTE)
598+ MESSAGE(
599+ STATUS "Generated JAVA_HOME to support FindJNI.cmake: "
600+ ${_JAVA_HOME})
601+ SET(ENV{JAVA_HOME} ${_JAVA_HOME})
602+ ENDIF()
603+ ENDIF()
604+
605+ FIND_PACKAGE(JNI)
606+ENDMACRO (ZORBA_FIND_JNI)
607
608=== added directory 'modules/util-jvm/include'
609=== added file 'modules/util-jvm/include/JavaVMSingleton.h'
610--- modules/util-jvm/include/JavaVMSingleton.h 1970-01-01 00:00:00 +0000
611+++ modules/util-jvm/include/JavaVMSingleton.h 2013-05-03 09:36:26 +0000
612@@ -0,0 +1,87 @@
613+/*
614+ * Copyright 2006-2008 The FLWOR Foundation.
615+ *
616+ * Licensed under the Apache License, Version 2.0 (the "License");
617+ * you may not use this file except in compliance with the License.
618+ * You may obtain a copy of the License at
619+ *
620+ * http://www.apache.org/licenses/LICENSE-2.0
621+ *
622+ * Unless required by applicable law or agreed to in writing, software
623+ * distributed under the License is distributed on an "AS IS" BASIS,
624+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
625+ * See the License for the specific language governing permissions and
626+ * limitations under the License.
627+ */
628+
629+#ifndef JAVA_VM_SINGLETON
630+#define JAVA_VM_SINGLETON
631+
632+#include <jni.h>
633+#include <zorba/static_context.h>
634+
635+# if defined WIN32 || defined CYGWIN
636+# ifdef util_jvm_EXPORTS
637+# ifdef __GNUC__
638+# define UTIL_JVM_DLL_PUBLIC __attribute__((dllexport))
639+# else
640+# define UTIL_JVM_DLL_PUBLIC __declspec(dllexport)
641+# endif /* __GNUC__ */
642+# else /* util_jvm_EXPORTS */
643+# ifdef __GNUC__
644+# define UTIL_JVM_DLL_PUBLIC __attribute__((dllimport))
645+# else
646+# define UTIL_JVM_DLL_PUBLIC __declspec(dllimport)
647+# endif /* __GNUC__ */
648+# endif /* util_jvm_EXPORTS */
649+# else
650+# if __GNUC__ >= 4
651+# define UTIL_JVM_DLL_PUBLIC __attribute__ ((visibility("default")))
652+# else
653+# define UTIL_JVM_DLL_PUBLIC
654+# endif
655+# endif
656+
657+namespace zorba { namespace jvm {
658+
659+#define NO_OF_JVM_OPTIONS 3
660+
661+
662+class VMOpenException {};
663+
664+class UTIL_JVM_DLL_PUBLIC JavaVMSingleton
665+{
666+public:
667+ //static JavaVMSingleton* getInstance(const char* classPath);
668+ static JavaVMSingleton* getInstance(const char* classPath, const char* javaLibPath);
669+ static JavaVMSingleton* getInstance(const zorba::StaticContext* aStaticContext);
670+
671+ virtual ~JavaVMSingleton();
672+ JavaVM* getVM();
673+ JNIEnv* getEnv();
674+
675+protected:
676+ JavaVMSingleton(const char* classPath, const char* javaLibPath);
677+ JavaVMSingleton(JavaVM *jvm, JNIEnv *env) : m_vm(jvm), m_env(env) {}
678+ static String computeClassPath(const zorba::StaticContext* aStaticContext);
679+ static String computeLibPath(const zorba::StaticContext* aStaticContext);
680+
681+ static JavaVMSingleton* instance;
682+ JavaVM* m_vm;
683+ JNIEnv* m_env;
684+ JavaVMInitArgs args;
685+ JavaVMOption options[NO_OF_JVM_OPTIONS];
686+
687+ char* classPathOption;
688+ char* awtOption;
689+ char* jlpOption;
690+};
691+
692+
693+}} //namespace zorba, jvm
694+
695+#endif // JAVA_VM_SINGLETON
696+
697+
698+
699+
700
701=== added file 'modules/util-jvm/util-jvm.cpp'
702--- modules/util-jvm/util-jvm.cpp 1970-01-01 00:00:00 +0000
703+++ modules/util-jvm/util-jvm.cpp 2013-05-03 09:36:26 +0000
704@@ -0,0 +1,92 @@
705+/*
706+ * Copyright 2006-2008 The FLWOR Foundation.
707+ *
708+ * Licensed under the Apache License, Version 2.0 (the "License");
709+ * you may not use this file except in compliance with the License.
710+ * You may obtain a copy of the License at
711+ *
712+ * http://www.apache.org/licenses/LICENSE-2.0
713+ *
714+ * Unless required by applicable law or agreed to in writing, software
715+ * distributed under the License is distributed on an "AS IS" BASIS,
716+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
717+ * See the License for the specific language governing permissions and
718+ * limitations under the License.
719+ */
720+#include <sstream>
721+#include <iostream>
722+#include <cstdlib>
723+#include <list>
724+
725+#include <zorba/base64.h>
726+#include <zorba/empty_sequence.h>
727+#include <zorba/diagnostic_list.h>
728+#include <zorba/function.h>
729+#include <zorba/external_module.h>
730+#include <zorba/user_exception.h>
731+#include <zorba/file.h>
732+#include <zorba/item_factory.h>
733+#include <zorba/serializer.h>
734+#include <zorba/singleton_item_sequence.h>
735+#include <zorba/vector_item_sequence.h>
736+#include <zorba/zorba.h>
737+
738+#include "JavaVMSingleton.h"
739+
740+#define UTILJVM_MODULE_NAMESPACE "http://www.zorba-xquery.com/modules/util-jvm"
741+#define UTILJVM_OPTIONS_NAMESPACE "http://www.zorba-xquery.com/modules/util-jvm/util-jvm-options"
742+
743+class JavaException {
744+};
745+
746+#define CHECK_EXCEPTION(env) if ((lException = env->ExceptionOccurred())) throw JavaException()
747+
748+namespace zorba
749+{
750+ namespace utiljvm
751+ {
752+
753+ class UtilJvmModule;
754+
755+ class UtilJvmModule : public ExternalModule {
756+ private:
757+
758+ public:
759+ UtilJvmModule() {}
760+
761+ virtual ~UtilJvmModule()
762+ {}
763+
764+ virtual String getURI() const
765+ {
766+ return UTILJVM_MODULE_NAMESPACE;
767+ }
768+
769+ virtual ExternalFunction*
770+ getExternalFunction(const String& localName);
771+
772+ virtual void destroy()
773+ {
774+ delete this;
775+ }
776+ };
777+
778+
779+ ExternalFunction*
780+ UtilJvmModule::getExternalFunction(const String& localName)
781+ {
782+ return 0;
783+ }
784+
785+ }}; // namespace zorba, utiljvm
786+
787+#ifdef WIN32
788+# define DLL_EXPORT __declspec(dllexport)
789+#else
790+# define DLL_EXPORT __attribute__ ((visibility("default")))
791+#endif
792+
793+extern "C" DLL_EXPORT zorba::ExternalModule* createModule()
794+{
795+ return new zorba::utiljvm::UtilJvmModule();
796+}
797
798=== added file 'modules/util-jvm/util-jvm.xq'
799--- modules/util-jvm/util-jvm.xq 1970-01-01 00:00:00 +0000
800+++ modules/util-jvm/util-jvm.xq 2013-05-03 09:36:26 +0000
801@@ -0,0 +1,40 @@
802+xquery version "1.0";
803+
804+(:
805+ : Copyright 2006-2009 The FLWOR Foundation.
806+ :
807+ : Licensed under the Apache License, Version 2.0 (the "License");
808+ : you may not use this file except in compliance with the License.
809+ : You may obtain a copy of the License at
810+ :
811+ : http://www.apache.org/licenses/LICENSE-2.0
812+ :
813+ : Unless required by applicable law or agreed to in writing, software
814+ : distributed under the License is distributed on an "AS IS" BASIS,
815+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
816+ : See the License for the specific language governing permissions and
817+ : limitations under the License.
818+ :)
819+
820+(:~
821+ : This module provides common functionality for modules that use java
822+ : implementations.
823+ : <br/>
824+ : <br/>
825+ : Modules using java implementations must import this module
826+ : to specify the dependency.
827+ : <br />
828+ : <br />
829+ : <b>Note:</b> Since this module has a Java library dependency a JVM is required
830+ : to be installed on the system. For Windows: jvm.dll is required on the system
831+ : path (usually located in "C:\Program Files\Java\jre\bin\client").
832+ :
833+ : @author Cezar Andrei
834+ : @library <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">JDK - Java Development Kit</a>
835+ : @project utils/util jvm
836+ :)
837+module namespace util-jvm = "http://www.zorba-xquery.com/modules/util-jvm";
838+
839+declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
840+declare option ver:module-version "1.0";
841+

Subscribers

People subscribed via source and target branches