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 166782
Collapse All | Expand All

(-)a/openide.filesystems/src/org/openide/filesystems/ExternalUtil.java (-3 / +5 lines)
Lines 149-164 Link Here
149
    
149
    
150
    /** Initializes the context and errManager
150
    /** Initializes the context and errManager
151
     */
151
     */
152
    private static synchronized void initialize() {
152
    private static void initialize() {
153
        Lookup lkp = Lookup.getDefault();
154
        
153
        Repository r;
155
        Repository r;
154
        synchronized (ExternalUtil.class) {
156
        synchronized (ExternalUtil.class) {
155
            r = repository;
157
            r = repository;
156
        }
158
        }
157
        
159
158
        if (r == null) {
160
        if (r == null) {
159
            assert ADD_FS == null;
161
            assert ADD_FS == null;
160
            ADD_FS = new AtomicReference<FileSystem>();
162
            ADD_FS = new AtomicReference<FileSystem>();
161
            Repository registeredRepository = Lookup.getDefault().lookup(Repository.class);
163
            Repository registeredRepository = lkp.lookup(Repository.class);
162
            Repository realRepository = assignRepository(registeredRepository);
164
            Repository realRepository = assignRepository(registeredRepository);
163
            
165
            
164
            
166
            
(-)5fb0d903fe36 (+106 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.netbeans.modules.openide.filesystems;
43
44
import java.io.File;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
47
import org.netbeans.junit.NbTestCase;
48
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileUtil;
50
import org.openide.util.Lookup;
51
import org.openide.util.SharedClassObject;
52
53
/** 
54
 * @author Jaroslav Tulach
55
 */
56
public class FSFoldersInLookupTest extends NbTestCase {
57
    static {
58
        System.setProperty("org.openide.util.Lookup.paths", "MyServices:YourServices");
59
    }
60
61
    private FileObject root;
62
    private Logger LOG;
63
64
    public FSFoldersInLookupTest(String name) {
65
        super(name);
66
    }
67
68
    @Override
69
    protected Level logLevel() {
70
        return Level.FINE;
71
    }
72
    
73
    @Override
74
    protected void setUp() throws Exception {
75
        if (System.getProperty("netbeans.user") == null) {
76
            System.setProperty("netbeans.user", new File(getWorkDir(), "ud").getPath());
77
        }
78
        
79
        LOG = Logger.getLogger("Test." + getName());
80
        
81
        root = FileUtil.getConfigRoot();
82
        for (FileObject fo : root.getChildren()) {
83
            fo.delete();
84
        }
85
        
86
        super.setUp();
87
    }
88
    
89
    public void testInterfaceFoundInMyServices() throws Exception {
90
        assertNull("not found", Lookup.getDefault().lookup(Shared.class));
91
        FileObject fo = FileUtil.createData(root, "MyServices/sub/dir/2/" + Shared.class.getName().replace('.', '-') + ".instance");
92
        assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
93
        fo.delete();
94
        assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
95
    }
96
    public void testInterfaceFoundInMyServices2() throws Exception {
97
        assertNull("not found", Lookup.getDefault().lookup(Shared.class));
98
        FileObject fo = FileUtil.createData(root, "YourServices/kuk/" + Shared.class.getName().replace('.', '-') + ".instance");
99
        assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
100
        fo.delete();
101
        assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
102
    }
103
104
    public static final class Shared extends SharedClassObject {}
105
106
}
(-)a/openide.util/apichanges.xml (+14 lines)
Lines 49-54 Link Here
49
    <apidef name="actions">Actions API</apidef>
49
    <apidef name="actions">Actions API</apidef>
50
</apidefs>
50
</apidefs>
51
<changes>
51
<changes>
52
    <change id="org.openide.util.Lookup.paths">
53
        <api name="lookup"/>
54
        <summary>Added <code>org.openide.util.Lookup.paths</code> property</summary>
55
        <version major="7" minor="24"/>
56
        <date day="16" month="6" year="2009"/>
57
        <author login="jtulach"/>
58
        <compatibility addition="yes"/>
59
        <description>
60
            <p>
61
                Better way to integrate Lookup.getDefault() and system filesystem.
62
            </p>
63
        </description>
64
        <class package="org.openide.util" name="Lookup"/>
65
    </change>
52
    <change id="ImageUtilities.loadImageIcon">
66
    <change id="ImageUtilities.loadImageIcon">
53
        <api name="util"/>
67
        <api name="util"/>
54
        <summary>Added <code>loadImageIcon(String resource, boolean localized)</code></summary>
68
        <summary>Added <code>loadImageIcon(String resource, boolean localized)</code></summary>
(-)a/openide.util/arch.xml (+15 lines)
Lines 514-519 Link Here
514
        is the result of <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>.
514
        is the result of <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>.
515
    </api>
515
    </api>
516
    </li>
516
    </li>
517
518
    <li>
519
    <api type="export" group="property" name="org.openide.util.Lookup.paths" category="devel">
520
        Sometimes it may be useful for the Lookup to contains objects from
521
        some system file system folder. This can be done with
522
        <code>org.openide.util.Lookup.paths=Folder1:Folder2:Folder3</code>.
523
        If this property is set prior to first call to
524
        <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>,
525
        it is split into pieces (separator is <code>':'</code>) and individual
526
        parts are then used to construct <code>Lookups.forPath("Folder1")</code>,
527
        etc. All these lookups then become part of the
528
        <a href="@TOP@/org/openide/util/Lookup.html#getDefault()">Lookup.getDefault()</a>
529
        one. This propert works since version 7.24
530
    </api>
531
    </li>
517
    
532
    
518
  </ul>
533
  </ul>
519
 </answer>
534
 </answer>
(-)a/openide.util/nbproject/project.properties (-1 / +1 lines)
Lines 42-48 Link Here
42
module.jar.dir=lib
42
module.jar.dir=lib
43
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
43
cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar
44
44
45
spec.version.base=7.23.0
45
spec.version.base=7.24.0
46
46
47
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
47
# For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4:
48
48
(-)a/openide.util/src/org/openide/util/Lookup.java (-5 / +22 lines)
Lines 41-49 Link Here
41
41
42
package org.openide.util;
42
package org.openide.util;
43
43
44
import java.util.ArrayList;
44
import java.util.Collection;
45
import java.util.Collection;
45
import java.util.Collections;
46
import java.util.Collections;
46
import java.util.Iterator;
47
import java.util.Iterator;
48
import java.util.List;
47
import java.util.Set;
49
import java.util.Set;
48
import org.openide.util.lookup.Lookups;
50
import org.openide.util.lookup.Lookups;
49
import org.openide.util.lookup.ProxyLookup;
51
import org.openide.util.lookup.ProxyLookup;
Lines 147-154 Link Here
147
        }
149
        }
148
150
149
        DefLookup def = new DefLookup();
151
        DefLookup def = new DefLookup();
150
        def.init(l, misl);
152
        def.init(l, misl, false);
151
        return defaultLookup = def;
153
        defaultLookup = def;
154
        def.init(l, misl, true);
155
        return defaultLookup;
152
    }
156
    }
153
    
157
    
154
    private static final class DefLookup extends ProxyLookup {
158
    private static final class DefLookup extends ProxyLookup {
Lines 156-167 Link Here
156
            super(new Lookup[0]);
160
            super(new Lookup[0]);
157
        }
161
        }
158
        
162
        
159
        public void init(ClassLoader loader, Lookup metaInfLookup) {
163
        public void init(ClassLoader loader, Lookup metaInfLookup, boolean addPath) {
160
            // Had no such line, use simple impl.
164
            // Had no such line, use simple impl.
161
            // It does however need to have ClassLoader available or many things will break.
165
            // It does however need to have ClassLoader available or many things will break.
162
            // Use the thread context classloader in effect now.
166
            // Use the thread context classloader in effect now.
163
            Lookup clLookup = Lookups.singleton(loader);
167
            Lookup clLookup = Lookups.singleton(loader);
164
            setLookups(new Lookup[] { metaInfLookup, clLookup });
168
            List<Lookup> arr = new ArrayList<Lookup>();
169
            arr.add(metaInfLookup);
170
            arr.add(clLookup);
171
            String paths = System.getProperty("org.openide.util.Lookup.paths"); // NOI18N
172
            if (addPath && paths != null) {
173
                for (String p : paths.split(":")) { // NOI18N
174
                    arr.add(Lookups.forPath(p));
175
                }
176
            }
177
            setLookups(arr.toArray(new Lookup[0]));
165
        }
178
        }
166
    }
179
    }
167
    
180
    
Lines 171-177 Link Here
171
        if (defaultLookup instanceof DefLookup) {
184
        if (defaultLookup instanceof DefLookup) {
172
            DefLookup def = (DefLookup)defaultLookup;
185
            DefLookup def = (DefLookup)defaultLookup;
173
            ClassLoader l = Thread.currentThread().getContextClassLoader();
186
            ClassLoader l = Thread.currentThread().getContextClassLoader();
174
            def.init(l, Lookups.metaInfServices(l));
187
            def.init(l, Lookups.metaInfServices(l), true);
175
        }
188
        }
176
    }
189
    }
177
190
Lines 345-350 Link Here
345
        /* Computes hashcode for this template. The hashcode is cached.
358
        /* Computes hashcode for this template. The hashcode is cached.
346
         * @return hashcode
359
         * @return hashcode
347
         */
360
         */
361
        @Override
348
        public int hashCode() {
362
        public int hashCode() {
349
            if (hashCode != 0) {
363
            if (hashCode != 0) {
350
                return hashCode;
364
                return hashCode;
Lines 360-365 Link Here
360
         * @param obj another template to check
374
         * @param obj another template to check
361
         * @return true if so, false otherwise
375
         * @return true if so, false otherwise
362
         */
376
         */
377
        @Override
363
        public boolean equals(Object obj) {
378
        public boolean equals(Object obj) {
364
            if (!(obj instanceof Template)) {
379
            if (!(obj instanceof Template)) {
365
                return false;
380
                return false;
Lines 395-400 Link Here
395
        }
410
        }
396
411
397
        /* for debugging */
412
        /* for debugging */
413
        @Override
398
        public String toString() {
414
        public String toString() {
399
            return "Lookup.Template[type=" + type + ",id=" + id + ",instance=" + instance + "]"; // NOI18N
415
            return "Lookup.Template[type=" + type + ",id=" + id + ",instance=" + instance + "]"; // NOI18N
400
        }
416
        }
Lines 489-494 Link Here
489
        public abstract String getDisplayName();
505
        public abstract String getDisplayName();
490
506
491
        /* show ID for debugging */
507
        /* show ID for debugging */
508
        @Override
492
        public String toString() {
509
        public String toString() {
493
            return getId();
510
            return getId();
494
        }
511
        }
(-)5fb0d903fe36 (+112 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 1997-2007 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
 * Contributor(s):
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
31
 * or only the GPL Version 2, indicate your decision by adding
32
 * "[Contributor] elects to include this software in this distribution
33
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
34
 * single choice of license, a recipient has the option to distribute
35
 * your version of this file under either the CDDL, the GPL Version 2 or
36
 * to extend the choice of license to its licensees as provided above.
37
 * However, if you add GPL Version 2 code and therefore, elected the GPL
38
 * Version 2 license, then the option applies only if the new code is
39
 * made subject to such option by the copyright holder.
40
 */
41
42
package org.openide.util.lookup;
43
44
import java.util.logging.Level;
45
import org.netbeans.junit.MockServices;
46
import org.netbeans.junit.NbTestCase;
47
import org.netbeans.modules.openide.util.NamedServicesProvider;
48
import org.openide.util.Lookup;
49
50
/** 
51
 * @author Jaroslav Tulach
52
 */
53
public class PathInLookupTest extends NbTestCase {
54
    static {
55
        System.setProperty("org.openide.util.Lookup.paths", "MyServices:YourServices");
56
        MockServices.setServices(P.class);
57
        Lookup.getDefault();
58
    }
59
60
    public PathInLookupTest(String name) {
61
        super(name);
62
    }
63
64
    @Override
65
    protected Level logLevel() {
66
        return Level.FINE;
67
    }
68
    
69
    public void testInterfaceFoundInMyServices() throws Exception {
70
        assertNull("not found", Lookup.getDefault().lookup(Shared.class));
71
        Shared v = new Shared();
72
        P.ic1.add(v);
73
        assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
74
        P.ic1.remove(v);
75
        assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
76
    }
77
    public void testInterfaceFoundInMyServices2() throws Exception {
78
        assertNull("not found", Lookup.getDefault().lookup(Shared.class));
79
        Shared v = new Shared();
80
        P.ic2.add(v);
81
        assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
82
        P.ic2.remove(v);
83
        assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
84
    }
85
86
    static final class Shared extends Object {}
87
88
    public static final class P extends NamedServicesProvider {
89
        static InstanceContent ic1 = new InstanceContent();
90
        static InstanceContent ic2 = new InstanceContent();
91
        static AbstractLookup[] arr = {
92
            new AbstractLookup(ic1), new AbstractLookup(ic2)
93
        };
94
95
96
        @Override
97
        public Lookup create(String path) {
98
            int indx = -1;
99
            if (path.equals("MyServices/")) {
100
                indx = 0;
101
            }
102
            if (path.equals("YourServices/")) {
103
                indx = 1;
104
            }
105
            if (indx == -1) {
106
                fail("Unexpected lookup query: " + path);
107
            }
108
            return arr[indx];
109
        }
110
    }
111
112
}

Return to bug 166782