01: package org.tigris.subversion.javahl;
02:
03: /**
04: * @copyright
05: * ====================================================================
06: * Copyright (c) 2005 CollabNet. All rights reserved.
07: *
08: * This software is licensed as described in the file COPYING, which
09: * you should have received as part of this distribution. The terms
10: * are also available at http://subversion.tigris.org/license-1.html.
11: * If newer versions of this license are posted there, you may use a
12: * newer version instead, at your option.
13: *
14: * This software consists of voluntary contributions made by many
15: * individuals. For exact contribution history, see the revision
16: * history and logs, available at http://subversion.tigris.org/.
17: * ====================================================================
18: * @endcopyright
19: */
20:
21: /**
22: * Handles activities related to management of native resouces
23: * (e.g. loading of native libraries).
24: */
25: class NativeResources {
26: /**
27: * Version information about the underlying native libraries.
28: */
29: static Version version;
30:
31: /**
32: * Load the required native library whose path is specified by the
33: * system property <code>subversion.native.library</code> (which
34: * can be passed to the JVM on start-up using an argument like
35: * <code>-Dsubversion.native.library=/usr/local/lib/libsvnjavahl-1.so</code>).
36: * If the system property is not specified or cannot be loaded,
37: * attempt to load the library using its expected name, and the
38: * platform-dependent loading mechanism.
39: *
40: * @throws UnsatisfiedLinkError If the native library cannot be
41: * loaded.
42: * @since 1.3.0
43: */
44: public static synchronized void loadNativeLibrary() {
45: // If the user specified the fully qualified path to the
46: // native library, try loading that first.
47: try {
48: String specifiedLibraryName = System
49: .getProperty("subversion.native.library");
50: if (specifiedLibraryName != null) {
51: System.load(specifiedLibraryName);
52: init();
53: return;
54: }
55: } catch (UnsatisfiedLinkError ex) {
56: // ignore that error to try again
57: }
58:
59: // Try to load the library by its name. Failing that, try to
60: // load it by its old name.
61: try {
62: System.loadLibrary("svnjavahl-1");
63: init();
64: return;
65: } catch (UnsatisfiedLinkError ex) {
66: try {
67: System.loadLibrary("libsvnjavahl-1");
68: init();
69: return;
70: } catch (UnsatisfiedLinkError e) {
71: System.loadLibrary("svnjavahl");
72: init();
73: return;
74: }
75: }
76: }
77:
78: /**
79: * Initializer for native resources to be invoked <em>after</em>
80: * the native library has been loaded. Sets library version
81: * information, and initializes the re-entrance hack for native
82: * code.
83: */
84: private static final void init() {
85: version = new Version();
86: SVNClient.initNative();
87: }
88: }
|