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 / +21 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://platform.netbeans.org/articles/installation.html#logical
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
707
            if (lib.isFile()) {
714
            File lib = ifl.locate("modules/lib/" + arch + "/" + system + "/" + mapped, getCodeNameBase(), false); // NOI18N
708
                return lib.getAbsolutePath();
715
            if (lib != null) return lib.getAbsolutePath();
709
            } else {
716
710
                return null;
717
            lib = ifl.locate("modules/lib/" + arch + "/" + mapped, getCodeNameBase(), false); // NOI18N
711
            }
718
            if (lib != null) return lib.getAbsolutePath();
719
720
            lib = ifl.locate("modules/lib/" + mapped, getCodeNameBase(), false); // NOI18N
721
            if (lib != null) return lib.getAbsolutePath();
722
723
            return null;
712
        }
724
        }
713
725
714
        protected @Override boolean shouldDelegateResource(String pkg, ClassLoader parent) {
726
        protected @Override boolean shouldDelegateResource(String pkg, ClassLoader parent) {
(-)87162b13ea2c (+177 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, arch, System.mapLibraryName("common"));
104
105
        MockModuleInstaller installer = new MockModuleInstaller();
106
        MockEvents ev = new MockEvents();
107
        ModuleManager mgr = new ModuleManager(installer, ev);
108
        mgr.mutexPrivileged().enterWriteAccess();
109
        module = mgr.create(jar, null, false, false, false);
110
        mgr.enable(module);
111
        mgr.mutexPrivileged().exitWriteAccess();
112
113
    }
114
    
115
    public void testLocateLibrary() {
116
        // testing 
117
        StandardModule.OneModuleClassLoader ldr = (StandardModule.OneModuleClassLoader)module.getClassLoader();
118
        assertEquals(fullLib.getAbsolutePath(), ldr.findLibrary("full"));
119
        assertEquals(archLib.getAbsolutePath(), ldr.findLibrary("arch"));
120
        assertEquals(commonLib.getAbsolutePath(), ldr.findLibrary("common"));
121
        assertNull(ldr.findLibrary("none"));
122
    }
123
124
    private File createFakeLibrary(File jar, String... path) throws IOException {
125
        File out = new File(jar.getParentFile(), "lib");
126
        for(String component : path) out = new File(out, component);
127
128
        // prepare the path
129
        out.getParentFile().mkdirs();
130
131
        out.createNewFile();
132
        return out;
133
    }
134
135
136
    private File createModule(String cnb, File cluster, String... attr) throws IOException {
137
        String dashes = cnb.replace('.', '-');
138
        
139
        File tmp = new File(new File(cluster, "modules"), dashes + ".jar");
140
141
        Map<String,String> attribs = new HashMap<String, String>();
142
        for (int i = 0; i < attr.length; i += 2) {
143
            attribs.put(attr[i], attr[i + 1]);
144
        }
145
146
        Map<String,String> files = new HashMap<String, String>();
147
        files.put("fake/" + cnb, cnb);
148
149
        tmp.getParentFile().mkdirs();
150
        SetupHid.createJar(tmp, files, attribs);
151
152
        return tmp;
153
    }
154
155
    static File root;
156
157
    @ServiceProvider(service=InstalledFileLocator.class)
158
    public static final class TestLocator extends InstalledFileLocator {
159
160
        public TestLocator() {
161
        }
162
163
        public File locate(String relativePath, String codeNameBase, boolean localized) {
164
            StringTokenizer tk = new StringTokenizer(relativePath,"/");
165
            File f = root;
166
            while (tk.hasMoreTokens()) {
167
                String part = tk.nextToken();
168
                f = new File (f,part);
169
                if (!f.exists()) {
170
                    return null;
171
                }
172
            }
173
            return f;
174
        }
175
    }
176
177
}

Return to bug 186000