This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 186000
Collapse All | Expand All

(-)a/o.n.bootstrap/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.bootstrap/1
2
OpenIDE-Module: org.netbeans.bootstrap/1
3
OpenIDE-Module-Specification-Version: 2.32
3
OpenIDE-Module-Specification-Version: 2.33
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/Bundle.properties
5
OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework
5
OpenIDE-Module-Recommends: org.netbeans.NetigsoFramework
6
6
(-)a/o.n.bootstrap/src/org/netbeans/StandardModule.java (-9 / +22 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 73-78 Link Here
73
import org.netbeans.Module.PackageExport;
73
import org.netbeans.Module.PackageExport;
74
import org.netbeans.LocaleVariants.FileWithSuffix;
74
import org.netbeans.LocaleVariants.FileWithSuffix;
75
import org.openide.modules.Dependency;
75
import org.openide.modules.Dependency;
76
import org.openide.modules.InstalledFileLocator;
76
import org.openide.util.Exceptions;
77
import org.openide.util.Exceptions;
77
import org.openide.util.NbBundle;
78
import org.openide.util.NbBundle;
78
79
Lines 674-680 Link Here
674
    /** Class loader to load a single module.
675
    /** Class loader to load a single module.
675
     * Auto-localizing, multi-parented, permission-granting, the works.
676
     * Auto-localizing, multi-parented, permission-granting, the works.
676
     */
677
     */
677
    private class OneModuleClassLoader extends JarClassLoader implements Util.ModuleProvider {
678
    class OneModuleClassLoader extends JarClassLoader implements Util.ModuleProvider {
678
        private int rc;
679
        private int rc;
679
        /** Create a new loader for a module.
680
        /** Create a new loader for a module.
680
         * @param classp the List of all module jars of code directories;
681
         * @param classp the List of all module jars of code directories;
Lines 700-714 Link Here
700
            return getAllPermission();
701
            return getAllPermission();
701
        }
702
        }
702
        
703
        
703
        /** look for JNI libraries also in modules/bin/ */
704
        /**
705
         * Look up a native library as described in modules documentation.
706
         * @see http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
707
         */
704
        protected @Override String findLibrary(String libname) {
708
        protected @Override String findLibrary(String libname) {
709
            InstalledFileLocator ifl = InstalledFileLocator.getDefault();
710
            String arch = System.getProperty("os.arch"); // NOI18N
711
            String system = System.getProperty("os.name").toLowerCase(); // NOI18N
705
            String mapped = System.mapLibraryName(libname);
712
            String mapped = System.mapLibraryName(libname);
706
            File lib = new File(new File(jar.getParentFile(), "lib"), mapped); // NOI18N
713
            File lib;
707
            if (lib.isFile()) {
714
708
                return lib.getAbsolutePath();
715
            lib = ifl.locate("modules/lib/" + mapped, getCodeNameBase(), false); // NOI18N
709
            } else {
716
            if (lib != null) return lib.getAbsolutePath();
710
                return null;
717
711
            }
718
            lib = ifl.locate("modules/lib/" + arch + "/" + mapped, getCodeNameBase(), false); // NOI18N
719
            if (lib != null) return lib.getAbsolutePath();
720
721
            lib = ifl.locate("modules/lib/" + arch + "/" + system + "/" + mapped, getCodeNameBase(), false); // NOI18N
722
            if (lib != null) return lib.getAbsolutePath();
723
724
            return null;
712
        }
725
        }
713
726
714
        protected @Override boolean shouldDelegateResource(String pkg, ClassLoader parent) {
727
        protected @Override boolean shouldDelegateResource(String pkg, ClassLoader parent) {
(-)87162b13ea2c (+182 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans;
41
42
import java.io.File;
43
import java.io.IOException;
44
import java.util.HashMap;
45
import java.util.Map;
46
import java.util.StringTokenizer;
47
import org.netbeans.junit.NbTestCase;
48
import org.netbeans.junit.MockServices;
49
import org.openide.modules.InstalledFileLocator;
50
import org.openide.util.lookup.ServiceProvider;
51
52
/**
53
 * A test covering native library lookup mechanism.
54
 * @see http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#jni
55
 *
56
 * @author Petr Nejedly <pnejedly@netbeans.org>
57
 */
58
public class NativeLibraryTest extends NbTestCase {
59
    private File userdir;
60
    private File ide;
61
    private File platform;
62
    private File install;
63
64
    private File jar;
65
    private Module module;
66
67
    File fullLib;
68
    File archLib;
69
    File commonLib;
70
    
71
    public NativeLibraryTest(String testName) {
72
        super(testName);
73
    }            
74
75
    @Override
76
    protected void setUp() throws Exception {
77
//        MockServices.setServices(TestLocator.class);
78
79
        clearWorkDir();
80
81
        String arch = System.getProperty("os.arch"); // NOI18N
82
        String system = System.getProperty("os.name").toLowerCase(); // NOI18N
83
84
        install = new File(getWorkDir(), "install");
85
        platform = new File(install, "platform");
86
        ide = new File(install, "ide");
87
        userdir = new File(getWorkDir(), "tmp");
88
        
89
        System.setProperty("netbeans.home", platform.getPath());
90
        System.setProperty("netbeans.dirs", ide.getPath());
91
        System.setProperty("netbeans.user", userdir.getPath());
92
        
93
        jar = createModule("org.openide.sample", platform,
94
            "OpenIDE-Module-Public-Packages", "-",
95
            "OpenIDE-Module", "org.openide.sample"
96
        );
97
98
        root = jar.getParentFile().getParentFile();
99
100
        // now create 3 libraries, full, arch and common
101
        fullLib = createFakeLibrary(jar, arch, system, System.mapLibraryName("full"));
102
        archLib = createFakeLibrary(jar, arch, System.mapLibraryName("arch"));
103
        commonLib = createFakeLibrary(jar, System.mapLibraryName("common"));
104
105
        // and create some honeypots for validating the search order
106
        createFakeLibrary(jar, arch, system, System.mapLibraryName("arch"));
107
        createFakeLibrary(jar, arch, system, System.mapLibraryName("common"));
108
        createFakeLibrary(jar, arch, System.mapLibraryName("common"));
109
110
        MockModuleInstaller installer = new MockModuleInstaller();
111
        MockEvents ev = new MockEvents();
112
        ModuleManager mgr = new ModuleManager(installer, ev);
113
        mgr.mutexPrivileged().enterWriteAccess();
114
        module = mgr.create(jar, null, false, false, false);
115
        mgr.enable(module);
116
        mgr.mutexPrivileged().exitWriteAccess();
117
118
    }
119
    
120
    public void testLocateLibrary() {
121
        // testing 
122
        StandardModule.OneModuleClassLoader ldr = (StandardModule.OneModuleClassLoader)module.getClassLoader();
123
        assertEquals(fullLib.getAbsolutePath(), ldr.findLibrary("full"));
124
        assertEquals(archLib.getAbsolutePath(), ldr.findLibrary("arch"));
125
        assertEquals(commonLib.getAbsolutePath(), ldr.findLibrary("common"));
126
        assertNull(ldr.findLibrary("none"));
127
    }
128
129
    private File createFakeLibrary(File jar, String... path) throws IOException {
130
        File out = new File(jar.getParentFile(), "lib");
131
        for(String component : path) out = new File(out, component);
132
133
        // prepare the path
134
        out.getParentFile().mkdirs();
135
136
        out.createNewFile();
137
        return out;
138
    }
139
140
141
    private File createModule(String cnb, File cluster, String... attr) throws IOException {
142
        String dashes = cnb.replace('.', '-');
143
        
144
        File tmp = new File(new File(cluster, "modules"), dashes + ".jar");
145
146
        Map<String,String> attribs = new HashMap<String, String>();
147
        for (int i = 0; i < attr.length; i += 2) {
148
            attribs.put(attr[i], attr[i + 1]);
149
        }
150
151
        Map<String,String> files = new HashMap<String, String>();
152
        files.put("fake/" + cnb, cnb);
153
154
        tmp.getParentFile().mkdirs();
155
        SetupHid.createJar(tmp, files, attribs);
156
157
        return tmp;
158
    }
159
160
    static File root;
161
162
    @ServiceProvider(service=InstalledFileLocator.class)
163
    public static final class TestLocator extends InstalledFileLocator {
164
165
        public TestLocator() {
166
        }
167
168
        public File locate(String relativePath, String codeNameBase, boolean localized) {
169
            StringTokenizer tk = new StringTokenizer(relativePath,"/");
170
            File f = root;
171
            while (tk.hasMoreTokens()) {
172
                String part = tk.nextToken();
173
                f = new File (f,part);
174
                if (!f.exists()) {
175
                    return null;
176
                }
177
            }
178
            return f;
179
        }
180
    }
181
182
}
(-)a/openide.modules/apichanges.xml (+19 lines)
Lines 47-52 Link Here
47
  	<apidef name="modules">Modules API</apidef>
47
  	<apidef name="modules">Modules API</apidef>
48
  </apidefs>
48
  </apidefs>
49
<changes>
49
<changes>
50
    <change id="ClassLoader.findLibrary">
51
        <api name="modules"/>
52
        <summary>Documented the new native library lookup mechanism</summary>
53
        <version major="7" minor="17"/>
54
        <date day="14" month="5" year="2010"/>
55
        <author login="pnejedly"/>
56
        <compatibility addition="yes"/>
57
        <description>
58
            <p>
59
                You can now distribute native libraries into architecture
60
                and OS specific directories under <samp>modules/lib</samp>
61
                as documented in the <a href="@TOP@/org/openide/modules/doc-files/api.html#jni">documentation</a>.
62
                The functionality is actually provided by the
63
                org.netbeans.bootstrap module as of version 2.33, which will be
64
                part of NetBeans 6.9 release.
65
            </p>
66
        </description>
67
        <issue number="186000"/>
68
    </change>
50
    <change id="ModuleInstall-no-extern">
69
    <change id="ModuleInstall-no-extern">
51
        <api name="modules"/>
70
        <api name="modules"/>
52
        <summary>Simplified <code>ModuleInstall</code> lifecycle</summary>
71
        <summary>Simplified <code>ModuleInstall</code> lifecycle</summary>
(-)a/openide.modules/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.modules
2
OpenIDE-Module: org.openide.modules
3
OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/modules/Bundle.properties
4
OpenIDE-Module-Specification-Version: 7.16
4
OpenIDE-Module-Specification-Version: 7.17
5
5
(-)a/openide.modules/src/org/openide/modules/doc-files/api.html (-14 / +23 lines)
Lines 1485-1508 Link Here
1485
1485
1486
<h3><a name="jni">JNI</a></h3>
1486
<h3><a name="jni">JNI</a></h3>
1487
1487
1488
<p>It is possible to run
1488
<p>It is possible to run modules making use of JNI native implementations inside
1489
modules making use of JNI native implementations inside
1489
NetBeans. You may place the native libraries (DLL or shared-object) beneath
1490
NetBeans. You may create a directory
1490
a <samp>modules/lib</samp> directory (i.e. a subdirectory <samp>lib/</samp>
1491
<samp>modules/lib/</samp> (i.e. a subdirectory <samp>lib/</samp> beneath the directory where the module JAR resides)
1491
beneath the directory where the module JAR resides). If your native library file
1492
and place native libraries (DLL or shared-object) there;
1492
names for different architectures or operating systems clash, you may create
1493
it will be added to the search path for calls to
1493
subdirectories under <samp>modules/lib</samp> for each supported platform and
1494
<code>System.loadLibrary</code> made from module code. This avoids the
1494
nested subdirectories for each supported operating system. The directory names
1495
need to explicitly add some directory to the binary load path. The
1495
must match <code>System.getProperty ("os.arch")</code> and
1496
module is entirely responsible for distinguishing between various
1496
<code>System.getProperty ("os.name").toLowerCase ()</code> respectively.
1497
platforms and operating systems and requesting a library name
1497
The <code>System.loadLibrary</code> call originating from the module code
1498
appropriate to the current one, however. Use of JNI is of course not
1498
will try to locate the library file in the following order of directories:<ul>
1499
    <li><samp>modules/lib/</samp></li>
1500
    <li><samp>modules/lib/&lt;arch&gt;/</samp></li>
1501
    <li><samp>modules/lib/&lt;arch&gt;/&lt;os&gt;/</samp></li>
1502
</ul>
1503
so you may place e.g. 64bit linux version of a <samp>foo</samp> library in a file
1504
<samp>modules/lib/amd64/linux/libfoo.so</samp>.
1505
The module may distinguish additional library variants itself or even override
1506
the platform selection logic by naming the library <em>file</em> appropriately
1507
and calling System.loadLibrary with such a name. Use of JNI is of course not
1499
recommended and should be restricted to cases where it is unavoidable.</p>
1508
recommended and should be restricted to cases where it is unavoidable.</p>
1500
1509
1501
<p>Example of usage: if on Linux a module located in <samp>/home/app/cluster/modules/something.jar</samp> calls
1510
<p>Example of usage: if on Linux a module located in <samp>/home/app/cluster/modules/something.jar</samp> calls
1502
<samp>System.loadLibrary("stuff-linux-i386")</samp>, the library should be in
1511
<samp>System.loadLibrary("stuff-linux-i386-gnome")</samp>, the library should be in
1503
<samp>/home/app/cluster/modules/lib/libstuff-linux-i386.so</samp>. On Windows, if
1512
<samp>/home/app/cluster/modules/lib/libstuff-linux-i386-gnome.so</samp>. On 64bit Windows, if
1504
<samp>C:\app\cluster\modules\something.jar</samp> calls <samp>System.loadLibrary("stuff")</samp>, the library
1513
<samp>C:\app\cluster\modules\something.jar</samp> calls <samp>System.loadLibrary("stuff")</samp>, the library
1505
should be in <samp>C:\app\cluster\modules\lib\stuff.dll</samp>. (Remember that Java has platform-specific
1514
should be in <samp>C:\app\cluster\modules\lib\amd64\stuff.dll</samp>. (Remember that Java has platform-specific
1506
prefixes and suffixes it adds to plain library names before trying to find it on disk.)</p>
1515
prefixes and suffixes it adds to plain library names before trying to find it on disk.)</p>
1507
1516
1508
<p>If a native library refers to <em>other</em> native libraries, they
1517
<p>If a native library refers to <em>other</em> native libraries, they

Return to bug 186000