diff -r 87162b13ea2c o.n.bootstrap/manifest.mf
--- a/o.n.bootstrap/manifest.mf Tue May 11 18:05:28 2010 +0200
+++ b/o.n.bootstrap/manifest.mf Fri May 14 14:35:21 2010 +0200
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.bootstrap/1
-OpenIDE-Module-Specification-Version: 2.32
+OpenIDE-Module-Specification-Version: 2.33
OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties
OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework
diff -r 87162b13ea2c o.n.bootstrap/src/org/netbeans/StandardModule.java
--- a/o.n.bootstrap/src/org/netbeans/StandardModule.java Tue May 11 18:05:28 2010 +0200
+++ b/o.n.bootstrap/src/org/netbeans/StandardModule.java Fri May 14 14:35:21 2010 +0200
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
@@ -73,6 +73,7 @@
import org.netbeans.Module.PackageExport;
import org.netbeans.LocaleVariants.FileWithSuffix;
import org.openide.modules.Dependency;
+import org.openide.modules.InstalledFileLocator;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
@@ -674,7 +675,7 @@
/** Class loader to load a single module.
* Auto-localizing, multi-parented, permission-granting, the works.
*/
- private class OneModuleClassLoader extends JarClassLoader implements Util.ModuleProvider {
+ class OneModuleClassLoader extends JarClassLoader implements Util.ModuleProvider {
private int rc;
/** Create a new loader for a module.
* @param classp the List of all module jars of code directories;
@@ -700,15 +701,27 @@
return getAllPermission();
}
- /** look for JNI libraries also in modules/bin/ */
+ /**
+ * Look up a native library as described in modules documentation.
+ * @see http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
+ */
protected @Override String findLibrary(String libname) {
+ InstalledFileLocator ifl = InstalledFileLocator.getDefault();
+ String arch = System.getProperty("os.arch"); // NOI18N
+ String system = System.getProperty("os.name").toLowerCase(); // NOI18N
String mapped = System.mapLibraryName(libname);
- File lib = new File(new File(jar.getParentFile(), "lib"), mapped); // NOI18N
- if (lib.isFile()) {
- return lib.getAbsolutePath();
- } else {
- return null;
- }
+ File lib;
+
+ lib = ifl.locate("modules/lib/" + mapped, getCodeNameBase(), false); // NOI18N
+ if (lib != null) return lib.getAbsolutePath();
+
+ lib = ifl.locate("modules/lib/" + arch + "/" + mapped, getCodeNameBase(), false); // NOI18N
+ if (lib != null) return lib.getAbsolutePath();
+
+ lib = ifl.locate("modules/lib/" + arch + "/" + system + "/" + mapped, getCodeNameBase(), false); // NOI18N
+ if (lib != null) return lib.getAbsolutePath();
+
+ return null;
}
protected @Override boolean shouldDelegateResource(String pkg, ClassLoader parent) {
diff -r 87162b13ea2c o.n.bootstrap/test/unit/src/org/netbeans/NativeLibraryTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/o.n.bootstrap/test/unit/src/org/netbeans/NativeLibraryTest.java Fri May 14 14:35:21 2010 +0200
@@ -0,0 +1,182 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2010 Sun Microsystems, Inc.
+ */
+
+package org.netbeans;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.StringTokenizer;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.junit.MockServices;
+import org.openide.modules.InstalledFileLocator;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * A test covering native library lookup mechanism.
+ * @see http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
+ *
+ * @author Petr Nejedly
+ You can now distribute native libraries into architecture
+ and OS specific directories under modules/lib
+ as documented in the documentation.
+ The functionality is actually provided by the
+ org.netbeans.bootstrap module as of version 2.33, which will be
+ part of NetBeans 6.9 release.
+ It is possible to run
-modules making use of JNI native implementations inside
-NetBeans. You may create a directory
-modules/lib/ (i.e. a subdirectory lib/ beneath the directory where the module JAR resides)
-and place native libraries (DLL or shared-object) there;
-it will be added to the search path for calls to
- It is possible to run modules making use of JNI native implementations inside
+NetBeans. You may place the native libraries (DLL or shared-object) beneath
+a modules/lib directory (i.e. a subdirectory lib/
+beneath the directory where the module JAR resides). If your native library file
+names for different architectures or operating systems clash, you may create
+subdirectories under modules/lib for each supported platform and
+nested subdirectories for each supported operating system. The directory names
+must match ModuleInstall
lifecycleJNI
-System.loadLibrary
made from module code. This avoids the
-need to explicitly add some directory to the binary load path. The
-module is entirely responsible for distinguishing between various
-platforms and operating systems and requesting a library name
-appropriate to the current one, however. Use of JNI is of course not
+System.getProperty ("os.arch")
and
+System.getProperty ("os.name").toLowerCase ()
respectively.
+The System.loadLibrary
call originating from the module code
+will try to locate the library file in the following order of directories:
+
+so you may place e.g. 64bit linux version of a foo library in a file
+modules/lib/amd64/linux/libfoo.so.
+The module may distinguish additional library variants itself or even override
+the platform selection logic by naming the library file appropriately
+and calling System.loadLibrary with such a name. Use of JNI is of course not
recommended and should be restricted to cases where it is unavoidable.
Example of usage: if on Linux a module located in /home/app/cluster/modules/something.jar calls -System.loadLibrary("stuff-linux-i386"), the library should be in -/home/app/cluster/modules/lib/libstuff-linux-i386.so. On Windows, if +System.loadLibrary("stuff-linux-i386-gnome"), the library should be in +/home/app/cluster/modules/lib/libstuff-linux-i386-gnome.so. On 64bit Windows, if C:\app\cluster\modules\something.jar calls System.loadLibrary("stuff"), the library -should be in C:\app\cluster\modules\lib\stuff.dll. (Remember that Java has platform-specific +should be in C:\app\cluster\modules\lib\amd64\stuff.dll. (Remember that Java has platform-specific prefixes and suffixes it adds to plain library names before trying to find it on disk.)
If a native library refers to other native libraries, they