Author: mladen.turk(a)jboss.com
Date: 2008-03-26 10:12:48 -0400 (Wed, 26 Mar 2008)
New Revision: 551
Added:
trunk/java/org/apache/tomcat/jni/Library.properties
trunk/java/org/apache/tomcat/jni/LibraryLoader.java
Modified:
trunk/java/org/apache/tomcat/jni/Library.java
Log:
Add alternate native loader.
The libraries are loaded according to the Library.properties file.
They are chosen according to the JVM arch used and
they are supposed to be inside catalina.home/bin/platform/cpu.
The old logic is stil favored if setup correctly.
Modified: trunk/java/org/apache/tomcat/jni/Library.java
===================================================================
--- trunk/java/org/apache/tomcat/jni/Library.java 2008-03-26 14:07:07 UTC (rev 550)
+++ trunk/java/org/apache/tomcat/jni/Library.java 2008-03-26 14:12:48 UTC (rev 551)
@@ -50,6 +50,15 @@
break;
}
if (!loaded) {
+ try {
+ LibraryLoader.load(System.getProperty("catalina.home"));
+ loaded = true;
+ }
+ catch (Throwable e) {
+ err += e.getMessage();
+ }
+ }
+ if (!loaded) {
err += "(";
err += System.getProperty("java.library.path");
err += ")";
Added: trunk/java/org/apache/tomcat/jni/Library.properties
===================================================================
--- trunk/java/org/apache/tomcat/jni/Library.properties (rev 0)
+++ trunk/java/org/apache/tomcat/jni/Library.properties 2008-03-26 14:12:48 UTC (rev 551)
@@ -0,0 +1,57 @@
+# Copyright(c) 2007 Red Hat Middleware, LLC,
+# and individual contributors as indicated by the @authors tag.
+# See the copyright.txt in the distribution for a
+# full listing of individual contributors.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library in the file COPYING.LIB;
+# if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+#
+# @author Mladen Turk
+#
+# Library.properties
+#
+windows.count=5
+windows.0=libapr-1.dll
+windows.1=libaprutil-1.dll
+windows.2=?libeay32.dll
+windows.3=?ssleay32.dll
+windows.4=libtcnative-1.dll
+
+linux2.count=7
+linux2.0=libapr-1.so
+linux2.1=libexpat.so
+linux2.2=libaprutil-1.so
+linux2.3=?libz.so
+linux2.4=?libcrypto.so
+linux2.5=?libssl.so
+linux2.6=libtcnative-1.so
+
+solaris.count=7
+solaris.0=libapr-1.so
+solaris.1=libexpat.so
+solaris.2=libaprutil-1.so
+solaris.3=?libz.so
+solaris.4=?libcrypto.so
+solaris.5=?libssl.so
+solaris.6=libtcnative-1.so
+
+hpux.count=7
+hpux.0=libapr-1.sl
+hpux.1=libexpat.sl
+hpux.2=libaprutil-1.sl
+hpux.3=?libz.sl
+hpux.4=?libcrypto.sl
+hpux.5=?libssl.sl
+hpux.6=libtcnative-1.sl
Property changes on: trunk/java/org/apache/tomcat/jni/Library.properties
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/java/org/apache/tomcat/jni/LibraryLoader.java
===================================================================
--- trunk/java/org/apache/tomcat/jni/LibraryLoader.java (rev 0)
+++ trunk/java/org/apache/tomcat/jni/LibraryLoader.java 2008-03-26 14:12:48 UTC (rev 551)
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.jni;
+
+/** LibraryLoader
+ *
+ * @author Mladen Turk
+ * @version $Revision: $, $Date: $
+ */
+
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+public final class LibraryLoader {
+
+
+ public static String getDefaultPlatformName()
+ {
+ String name = System.getProperty("os.name");
+ String platform = "unknown";
+
+ if (name.startsWith("Windows"))
+ platform = "windows";
+ else if (name.startsWith("Mac OS"))
+ platform = "macosx";
+ else if (name.endsWith("BSD"))
+ platform = "bsd";
+ else if (name.equals("Linux"))
+ platform = "linux2";
+ else if (name.equals("Solaris"))
+ platform = "solaris";
+ else if (name.equals("SunOS"))
+ platform = "solaris";
+ else if (name.equals("HP-UX"))
+ platform = "hpux";
+ else if (name.equals("AIX"))
+ platform = "aix";
+
+ return platform;
+ }
+
+ public static String getDefaultPlatformCpu()
+ {
+ String cpu;
+ String arch = System.getProperty("os.arch");
+
+ if (arch.endsWith("86"))
+ cpu = "x86";
+ else if (arch.startsWith("PA_RISC"))
+ cpu = "parisc2";
+ else if (arch.startsWith("IA64"))
+ cpu = "i64";
+ else if (arch.startsWith("sparc"))
+ cpu = "sparcv9";
+ else if (arch.equals("x86_64"))
+ cpu = "x64";
+ else if (arch.equals("amd64"))
+ cpu = "x64";
+ else
+ cpu = arch;
+ return cpu;
+ }
+
+ public static String getDefaultLibraryPath()
+ {
+ String name = getDefaultPlatformName();
+ String arch = getDefaultPlatformCpu();
+
+ return name + File.separator + arch;
+ }
+
+ public static String getDefaultMetaPath()
+ {
+ return "META-INF" + File.separator + "lib" + File.separator;
+ }
+
+ private LibraryLoader()
+ {
+ // Disallow creation
+ }
+
+ protected static void load(String rootPath)
+ throws SecurityException, IOException, UnsatisfiedLinkError
+ {
+ int count = 0;
+ String name = getDefaultPlatformName();
+ String path = getDefaultLibraryPath();
+ Properties props = new Properties();
+
+ File root = new File(rootPath);
+ String basePath = root.getCanonicalPath().toString();
+ if (!basePath.endsWith(File.separator)) {
+ basePath += File.separator;
+ }
+ String metaPath = basePath + getDefaultMetaPath();
+ File meta = new File(metaPath);
+ if (!meta.exists()) {
+ /* Try adding bin prefix to rootPath.
+ * Used if we pass catalina.base property
+ */
+ metaPath = basePath + "bin" + File.separator +
+ getDefaultMetaPath();
+ }
+ try {
+ InputStream is = LibraryLoader.class.getResourceAsStream
+ ("/org/apache/tomcat/jni/Library.properties");
+ props.load(is);
+ is.close();
+ count = Integer.parseInt(props.getProperty(name + ".count"));
+ }
+ catch (Throwable t) {
+ throw new UnsatisfiedLinkError("Can't use
Library.properties");
+ }
+ for (int i = 0; i < count; i++) {
+ boolean optional = false;
+ String dlibName = props.getProperty(name + "." + i);
+ if (dlibName.startsWith("?")) {
+ dlibName = dlibName.substring(1);
+ optional = true;
+ }
+ String fullPath = metaPath + path +
+ File.separator + dlibName;
+ try {
+ Runtime.getRuntime().load(fullPath);
+ }
+ catch (Throwable d) {
+ if (!optional) {
+ throw new UnsatisfiedLinkError(dlibName);
+ }
+ }
+ }
+ }
+
+}
Property changes on: trunk/java/org/apache/tomcat/jni/LibraryLoader.java
___________________________________________________________________
Name: svn:eol-style
+ native