Mercurial > hg > blitz_condensed
comparison src/org/dancres/blitz/config/ConfigAssistant.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz.config; | |
2 | |
3 /** | |
4 <p> As Blitz can be run on many operating systems (Win32, Mac OS X and most | |
5 UNIX varieties) and on top of several different versions of Db (4.1 and | |
6 4.2), initial configuration has the potential to be time-consuming. To make | |
7 the task simpler, the Blitz distribution includes a tool (ConfigAssistant) | |
8 which will assist you in determining what your configuration is and what | |
9 changes are required. Run ConfigAssistant as follows:</p> | |
10 | |
11 <pre> | |
12 cd /home/dan/src/jini/space/ | |
13 | |
14 java -Djava.security.policy=config/policy.all -cp lib/blitz.jar | |
15 org.dancres.blitz.config.ConfigAssistant | |
16 | |
17 </pre> | |
18 | |
19 <p> | |
20 ConfigAssistant performs the following steps: | |
21 </p> | |
22 | |
23 <ol> | |
24 <li> Identify the operating system you are running on.</li> | |
25 <li> Identify which version of Db you have installed.</li> | |
26 <li> Display recommended .config file changes and any platform specific instructions for running Blitz.</li> | |
27 </ol> | |
28 | |
29 <p> | |
30 ConfigAssistant may fail to determine the version of Db you have installed.# | |
31 When this happens, it will suggest the likely cause of the problem and exit | |
32 Once the problem is identified and fixed, you can re-run | |
33 ConfigAssistant.</p> | |
34 | |
35 <p> | |
36 <b>Note:</b> Mac OS X users should read the platform notes which details | |
37 additional requirements for running ConfigAssistant, ServiceStarter etc. | |
38 </p> | |
39 */ | |
40 public class ConfigAssistant { | |
41 private static final String[][] DB_VERSIONS = {{"4", "1"}, {"4", "2"}}; | |
42 | |
43 private static final int[] DB_VERSION_CODE = {0, 1}; | |
44 | |
45 private static final String[] DB_NAMES = {"db4.1", "db4.2"}; | |
46 | |
47 private static final int OS_X = 1; | |
48 private static final int WIN32 = 2; | |
49 private static final int UNIX = 3; | |
50 | |
51 private static final String DB_PROP = "sleepycat.db.libfile"; | |
52 | |
53 private static final String[] CONFIG_GENERAL = { | |
54 "", | |
55 "**********", | |
56 "** Note **", | |
57 "**********", | |
58 "", | |
59 "Remember to set the persistDir and logDir variables in your", | |
60 "blitz.config to suitable directories which should be writable", | |
61 "by the user you plan to run Blitz under.", | |
62 "", | |
63 "" | |
64 }; | |
65 | |
66 private static final String[] CONFIG_UNIX_DB41 = { | |
67 "UNIX with Db4.1", | |
68 "===============", | |
69 "", | |
70 "Edit the start-*.config files as follows:", | |
71 "", | |
72 "Set dbVersion=\"\"", | |
73 "Edit jiniRoot, dbLib, codebasePort and blitzRoot to appropriate values" | |
74 }; | |
75 | |
76 private static final String[] CONFIG_UNIX_DB42 = { | |
77 "UNIX with Db4.2", | |
78 "===============", | |
79 "", | |
80 "Edit the start-*.config files as follows:", | |
81 "", | |
82 "Set dbVersion=\"db42/\"", | |
83 "Edit jiniRoot, dbLib, codebasePort and blitzRoot to appropriate values" | |
84 }; | |
85 | |
86 private static final String[][] CONFIG_UNIX = {CONFIG_UNIX_DB41, | |
87 CONFIG_UNIX_DB42}; | |
88 | |
89 private static final String[] CONFIG_OS_X_DB41 = { | |
90 "OSX with Db4.1", | |
91 "===============", | |
92 "", | |
93 "Edit the start-*.config files as follows:", | |
94 "", | |
95 "Set dbVersion=\"\"", | |
96 "Edit jiniRoot, dbLib, codebasePort and blitzRoot to appropriate values", | |
97 "", | |
98 "*** IMPORTANT NOTES ON USING SERVICESTARTER ***", | |
99 "", | |
100 "When using start-transient-blitz.config or other transient configurations", | |
101 "Make sure you run the java command with -D" + DB_PROP + "=" + | |
102 System.getProperty(DB_PROP), | |
103 "", | |
104 "When using start-activatable-blitz.config or other activatable configurations", | |
105 "Make sure you set sharedVM_options (in the .config file) to", | |
106 "\"-D" + DB_PROP + "=" + System.getProperty(DB_PROP) + "\"" | |
107 }; | |
108 | |
109 private static final String[] CONFIG_OS_X_DB42 = { | |
110 "OSX with Db4.2", | |
111 "===============", | |
112 "", | |
113 "Edit the start-*.config files as follows:", | |
114 "", | |
115 "Set dbVersion=\"db42/\"", | |
116 "Edit jiniRoot, dbLib, codebasePort and blitzRoot to appropriate values", | |
117 "", | |
118 "*** IMPORTANT NOTES ON USING SERVICESTARTER ***", | |
119 "", | |
120 "When using start-transient-blitz.config or other transient configurations", | |
121 "Make sure you run the java command with -D" + DB_PROP + "=" + | |
122 System.getProperty(DB_PROP), | |
123 "", | |
124 "When using start-activatable-blitz.config or other activatable configurations", | |
125 "Make sure you set sharedVM_options (in the .config file) to", | |
126 "\"-D" + DB_PROP + "=" + System.getProperty(DB_PROP) + "\"" | |
127 }; | |
128 | |
129 private static final String[][] CONFIG_OS_X = {CONFIG_OS_X_DB41, | |
130 CONFIG_OS_X_DB42}; | |
131 | |
132 private static final String[] CONFIG_WIN32_DB41 = { | |
133 "Win32 with Db4.1", | |
134 "===============", | |
135 "", | |
136 "Edit the start-*.config files as follows:", | |
137 "", | |
138 "Set dbVersion=\"\"", | |
139 "Edit jiniRoot, dbLib, codebasePort and blitzRoot to appropriate values" | |
140 }; | |
141 | |
142 private static final String[] CONFIG_WIN32_DB42 = { | |
143 "Win32 with Db4.2", | |
144 "===============", | |
145 "", | |
146 "Edit the start-*.config files as follows:", | |
147 "", | |
148 "Set dbVersion=\"db42/\"", | |
149 "Edit jiniRoot, dbLib, codebasePort and blitzRoot to appropriate values" | |
150 }; | |
151 | |
152 private static final String[][] CONFIG_WIN32 = {CONFIG_WIN32_DB41, | |
153 CONFIG_WIN32_DB42}; | |
154 | |
155 public static void main(String args[]) { | |
156 | |
157 if (Boolean.getBoolean("debug")) { | |
158 System.err.println("OS name: " + System.getProperty("os.name")); | |
159 | |
160 System.err.println("MacOSX: " + System.getProperty(DB_PROP)); | |
161 | |
162 for (int i = 0; i < DB_VERSIONS.length; i++) { | |
163 String myLibName; | |
164 | |
165 myLibName = getLibName(DB_VERSIONS[i][0], DB_VERSIONS[i][1], | |
166 WIN32); | |
167 | |
168 System.err.println("Win32: " + myLibName + ", " + | |
169 libraryPresent(myLibName, WIN32)); | |
170 | |
171 myLibName = getLibName(DB_VERSIONS[i][0], DB_VERSIONS[i][1], | |
172 UNIX); | |
173 | |
174 System.err.println("Unix: " + myLibName + ", " + | |
175 libraryPresent(myLibName, UNIX)); | |
176 } | |
177 | |
178 dumpInstructions(CONFIG_UNIX); | |
179 dumpInstructions(CONFIG_OS_X); | |
180 dumpInstructions(CONFIG_WIN32); | |
181 | |
182 System.exit(0); | |
183 } | |
184 | |
185 if (System.getProperty("os.name").startsWith("Windows")) { | |
186 configWindows(); | |
187 return; | |
188 } | |
189 | |
190 if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { | |
191 if (System.getProperty(DB_PROP) == null) { | |
192 System.err.println(); | |
193 System.err.println("Please read docs/mac_osx.html and rerun ConfigAssistant with an appropriate -D" + DB_PROP); | |
194 System.exit(0); | |
195 } else { | |
196 configMacOSX(); | |
197 return; | |
198 } | |
199 } | |
200 | |
201 configUnix(); | |
202 } | |
203 | |
204 private static void dumpInstructions(String[][] anInsts) { | |
205 for (int i = 0; i < anInsts.length; i++) { | |
206 System.err.println(); | |
207 dumpSpecificInstructions(anInsts[i]); | |
208 System.err.println(); | |
209 } | |
210 } | |
211 | |
212 private static void dumpSpecificInstructions(String[] anInst) { | |
213 for (int i = 0; i < anInst.length; i++) { | |
214 System.err.println(anInst[i]); | |
215 } | |
216 } | |
217 | |
218 private static void configMacOSX() { | |
219 System.err.println("I think you're on Mac OSX"); | |
220 | |
221 int myVersion = probeLib(OS_X); | |
222 | |
223 if (myVersion == -1) { | |
224 System.err.println("Couldn't locate Db :("); | |
225 System.err.println("Are the Db .so's on LD_LIBRARY_PATH?"); | |
226 System.exit(0); | |
227 } else { | |
228 System.err.println("I think you have: " + DB_NAMES[myVersion]); | |
229 } | |
230 | |
231 System.err.println(); | |
232 dumpSpecificInstructions(CONFIG_OS_X[myVersion]); | |
233 dumpSpecificInstructions(CONFIG_GENERAL); | |
234 } | |
235 | |
236 private static void configUnix() { | |
237 System.err.println("I think you're on UNIX"); | |
238 | |
239 int myVersion = probeLib(UNIX); | |
240 | |
241 if (myVersion == -1) { | |
242 System.err.println("Couldn't locate Db :("); | |
243 System.err.println("Are the Db .so's on LD_LIBRARY_PATH?"); | |
244 System.exit(0); | |
245 } else { | |
246 System.err.println("I think you have: " + DB_NAMES[myVersion]); | |
247 } | |
248 | |
249 System.err.println(); | |
250 dumpSpecificInstructions(CONFIG_UNIX[myVersion]); | |
251 dumpSpecificInstructions(CONFIG_GENERAL); | |
252 } | |
253 | |
254 private static void configWindows() { | |
255 System.err.println("I think you're on Win32"); | |
256 | |
257 int myVersion = probeLib(WIN32); | |
258 | |
259 if (myVersion == -1) { | |
260 System.err.println("Couldn't locate Db :("); | |
261 System.err.println("Are the Db .dll's on PATH?"); | |
262 System.exit(0); | |
263 } else { | |
264 System.err.println("I think you have: " + DB_NAMES[myVersion]); | |
265 } | |
266 | |
267 System.err.println(); | |
268 dumpSpecificInstructions(CONFIG_WIN32[myVersion]); | |
269 dumpSpecificInstructions(CONFIG_GENERAL); | |
270 } | |
271 | |
272 private static String getLibName(String aMajor, String aMinor, | |
273 int aPlatform) { | |
274 | |
275 switch(aPlatform) { | |
276 case OS_X : { | |
277 return System.getProperty(DB_PROP); | |
278 } | |
279 | |
280 case WIN32 : { | |
281 return "libdb_java" + aMajor + aMinor; | |
282 } | |
283 | |
284 case UNIX : { | |
285 return "db_java-" + aMajor + "." + aMinor; | |
286 } | |
287 | |
288 default : { | |
289 throw new RuntimeException("Not a platform"); | |
290 } | |
291 } | |
292 } | |
293 | |
294 private static int probeLib(int aPlatform) { | |
295 if (aPlatform == OS_X) { | |
296 String myLib = System.getProperty(DB_PROP); | |
297 | |
298 if (libraryPresent(myLib, OS_X)) { | |
299 if (myLib.indexOf("db_java-4.1") != -1) | |
300 return DB_VERSION_CODE[0]; | |
301 else | |
302 return DB_VERSION_CODE[1]; | |
303 } | |
304 } else { | |
305 for (int i = 0; i < DB_VERSIONS.length; i++) { | |
306 String myLibName; | |
307 | |
308 myLibName = getLibName(DB_VERSIONS[i][0], DB_VERSIONS[i][1], | |
309 aPlatform); | |
310 | |
311 if (libraryPresent(myLibName, aPlatform)) | |
312 return DB_VERSION_CODE[i]; | |
313 } | |
314 } | |
315 | |
316 return -1; | |
317 } | |
318 | |
319 private static boolean libraryPresent(String aLibName, int aPlatform) { | |
320 try { | |
321 if (aPlatform == OS_X) { | |
322 System.load(aLibName); | |
323 } else { | |
324 System.loadLibrary(aLibName); | |
325 } | |
326 } catch (UnsatisfiedLinkError aULE) { | |
327 return false; | |
328 } | |
329 | |
330 return true; | |
331 } | |
332 } |