Merge lp:~zorba-coders/zorba/fread-pdf-utiljvm-module into lp:zorba/util-jvm-module

Proposed by Cezar Andrei
Status: Merged
Approved by: Chris Hillery
Approved revision: 15
Merged at revision: 15
Proposed branch: lp:~zorba-coders/zorba/fread-pdf-utiljvm-module
Merge into: lp:zorba/util-jvm-module
Diff against target: 208 lines (+66/-20)
2 files modified
include/JavaVMSingleton.h (+19/-7)
src/JavaVMSingleton.cpp (+47/-13)
To merge this branch: bzr merge lp:~zorba-coders/zorba/fread-pdf-utiljvm-module
Reviewer Review Type Date Requested Status
Cezar Andrei Approve
Chris Hillery Approve
Review via email: mp+125332@code.launchpad.net

Commit message

Add java.library.path property when starting the jvm

Description of the change

Add java.library.path property when starting the jvm

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Cezar Andrei (cezar-andrei) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job fread-pdf-utiljvm-module-2012-09-19T20-32-43.622Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job fread-pdf-utiljvm-module-2012-09-19T21-04-41.287Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/JavaVMSingleton.h'
2--- include/JavaVMSingleton.h 2012-05-22 09:56:29 +0000
3+++ include/JavaVMSingleton.h 2012-09-19 20:46:20 +0000
4@@ -1,12 +1,12 @@
5 /*
6 * Copyright 2006-2008 The FLWOR Foundation.
7- *
8+ *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12- *
13+ *
14 * http://www.apache.org/licenses/LICENSE-2.0
15- *
16+ *
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20@@ -44,12 +44,16 @@
21
22 namespace zorba { namespace jvm {
23
24+#define NO_OF_JVM_OPTIONS 3
25+
26+
27 class VMOpenException {};
28
29 class UTIL_JVM_DLL_PUBLIC JavaVMSingleton
30 {
31 public:
32- static JavaVMSingleton* getInstance(const char* classPath);
33+ //static JavaVMSingleton* getInstance(const char* classPath);
34+ static JavaVMSingleton* getInstance(const char* classPath, const char* javaLibPath);
35 static JavaVMSingleton* getInstance(const zorba::StaticContext* aStaticContext);
36
37 virtual ~JavaVMSingleton();
38@@ -57,19 +61,27 @@
39 JNIEnv* getEnv();
40
41 protected:
42- JavaVMSingleton(const char* classPath);
43+ JavaVMSingleton(const char* classPath, const char* javaLibPath);
44 JavaVMSingleton(JavaVM *jvm, JNIEnv *env) : m_vm(jvm), m_env(env) {}
45 static String computeClassPath(const zorba::StaticContext* aStaticContext);
46+ static String computeLibPath(const zorba::StaticContext* aStaticContext);
47
48 static JavaVMSingleton* instance;
49 JavaVM* m_vm;
50 JNIEnv* m_env;
51 JavaVMInitArgs args;
52- JavaVMOption options[2];
53+ JavaVMOption options[NO_OF_JVM_OPTIONS];
54+
55+ char* classPathOption;
56 char* awtOption;
57- char* classPathOption;
58+ char* jlpOption;
59 };
60
61+
62 }} //namespace zorba, jvm
63
64 #endif // JAVA_VM_SINGLETON
65+
66+
67+
68+
69
70=== modified file 'src/JavaVMSingleton.cpp'
71--- src/JavaVMSingleton.cpp 2012-05-25 17:50:10 +0000
72+++ src/JavaVMSingleton.cpp 2012-09-19 20:46:20 +0000
73@@ -1,12 +1,12 @@
74 /*
75 * Copyright 2006-2008 The FLWOR Foundation.
76- *
77+ *
78 * Licensed under the Apache License, Version 2.0 (the "License");
79 * you may not use this file except in compliance with the License.
80 * You may obtain a copy of the License at
81- *
82+ *
83 * http://www.apache.org/licenses/LICENSE-2.0
84- *
85+ *
86 * Unless required by applicable law or agreed to in writing, software
87 * distributed under the License is distributed on an "AS IS" BASIS,
88 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89@@ -32,13 +32,11 @@
90 namespace zorba { namespace jvm {
91 JavaVMSingleton* JavaVMSingleton::instance = NULL;
92
93-JavaVMSingleton::JavaVMSingleton(const char* classPath)
94+JavaVMSingleton::JavaVMSingleton(const char* classPath, const char* javaLibPath)
95 {
96- //std::cout << "JavaVMSingleton::JavaVMSingleton classPath: " << classPath << "\n"; std::cout.flush();
97-
98 memset(&args, 0, sizeof(args));
99 jint r;
100- jint nOptions = 2;
101+ jint nOptions = NO_OF_JVM_OPTIONS;
102
103 std::string classpathOption;
104 std::ostringstream os;
105@@ -47,15 +45,27 @@
106 classPathOption = new char[classpathOption.size() + 1];
107 memset(classPathOption, 0, sizeof(char) * (classpathOption.size() + 1));
108 memcpy(classPathOption, classpathOption.c_str(), classpathOption.size() * sizeof(char));
109+
110 std::string lAwtArgStr = "-Djava.awt.headless=true";
111 awtOption = new char[lAwtArgStr.size() + 1];
112 memset(awtOption, 0, sizeof(char) * (lAwtArgStr.size() + 1));
113 memcpy(awtOption, lAwtArgStr.c_str(), sizeof(char) * lAwtArgStr.size());
114 awtOption[lAwtArgStr.size()] = 0;
115+
116+ // javaLibPath are only base pathes, the full path will be computed at runtime in the Java class
117+ std::string jlpStr = "-Djava.library.path=" + std::string(javaLibPath);
118+ jlpOption = new char[jlpStr.size() + 1];
119+ memset(jlpOption, 0, sizeof(char) * (jlpStr.size() + 1));
120+ memcpy(jlpOption, jlpStr.c_str(), sizeof(char) * jlpStr.size());
121+ jlpOption[jlpStr.size()] = 0;
122+
123 options[0].optionString = classPathOption;
124 options[0].extraInfo = NULL;
125 options[1].optionString = awtOption;
126 options[1].extraInfo = NULL;
127+ options[2].optionString = jlpOption;
128+ options[2].extraInfo = NULL;
129+
130 memset(&args, 0, sizeof(args));
131 args.version = JNI_VERSION_1_2;
132 args.nOptions = nOptions;
133@@ -81,7 +91,12 @@
134 delete[] classPathOption;
135 }
136
137-JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath)
138+/*JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath)
139+{
140+ return getInstance(classPath, "");
141+}*/
142+
143+JavaVMSingleton* JavaVMSingleton::getInstance(const char* classPath, const char* javaLibPath)
144 {
145 //#ifdef WIN32
146 // // If pointer to instance of JavaVMSingleton exists (true) then return instance pointer else look for
147@@ -118,19 +133,22 @@
148
149 if (instance == NULL)
150 {
151- instance = new JavaVMSingleton(classPath);
152+ instance = new JavaVMSingleton(classPath, javaLibPath);
153 }
154 }
155
156 return instance;
157 }
158
159+
160+
161 JavaVMSingleton* JavaVMSingleton::getInstance(const zorba::StaticContext* aStaticContext)
162 {
163 if (instance == NULL)
164 {
165 String cp = computeClassPath(aStaticContext);
166- return getInstance(cp.c_str());
167+ String lp = computeLibPath(aStaticContext);
168+ return getInstance(cp.c_str(), lp.c_str());
169 }
170
171 return instance;
172@@ -211,8 +229,6 @@
173 if ( lineStr.size() == 0 )
174 continue;
175
176- //std::cout << "line: '" << lineStr << "'" << std::endl; std::cout.flush();
177-
178 const std::string normalizedPath =
179 filesystem_path::normalize_path( lineStr, jarsDirPath.get_path());
180
181@@ -226,8 +242,26 @@
182
183 properties->setJVMClassPath(cp.str());
184
185- //std::cout << "JavaVMSingleton::computeClassPath: '" << cp << "'" << std::endl; std::cout.flush();
186 return cp;
187 }
188
189+
190+String JavaVMSingleton::computeLibPath(const zorba::StaticContext* aStaticContext)
191+{
192+ String lp;
193+ std::vector<String> lCPV;
194+ String pathSeparator(filesystem_path::get_path_separator());
195+
196+ aStaticContext->getFullLibPath(lCPV);
197+ for (std::vector<String>::iterator lIter = lCPV.begin();
198+ lIter != lCPV.end(); ++lIter)
199+ {
200+ String p = *lIter;
201+ lp += pathSeparator + p;
202+ }
203+
204+ return lp;
205+}
206+
207+
208 }} // namespace zorba, jvm

Subscribers

People subscribed via source and target branches

to all changes: