diff -r 5fb0d903fe36 openide.filesystems/src/org/openide/filesystems/ExternalUtil.java --- a/openide.filesystems/src/org/openide/filesystems/ExternalUtil.java Mon Jun 08 19:00:44 2009 +0200 +++ b/openide.filesystems/src/org/openide/filesystems/ExternalUtil.java Tue Jun 09 13:56:42 2009 +0200 @@ -149,16 +149,18 @@ /** Initializes the context and errManager */ - private static synchronized void initialize() { + private static void initialize() { + Lookup lkp = Lookup.getDefault(); + Repository r; synchronized (ExternalUtil.class) { r = repository; } - + if (r == null) { assert ADD_FS == null; ADD_FS = new AtomicReference(); - Repository registeredRepository = Lookup.getDefault().lookup(Repository.class); + Repository registeredRepository = lkp.lookup(Repository.class); Repository realRepository = assignRepository(registeredRepository); diff -r 5fb0d903fe36 openide.filesystems/test/unit/src/org/netbeans/modules/openide/filesystems/FSFoldersInLookupTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.filesystems/test/unit/src/org/netbeans/modules/openide/filesystems/FSFoldersInLookupTest.java Tue Jun 09 13:56:42 2009 +0200 @@ -0,0 +1,106 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.netbeans.modules.openide.filesystems; + +import java.io.File; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.junit.NbTestCase; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.util.Lookup; +import org.openide.util.SharedClassObject; + +/** + * @author Jaroslav Tulach + */ +public class FSFoldersInLookupTest extends NbTestCase { + static { + System.setProperty("org.openide.util.Lookup.paths", "MyServices:YourServices"); + } + + private FileObject root; + private Logger LOG; + + public FSFoldersInLookupTest(String name) { + super(name); + } + + @Override + protected Level logLevel() { + return Level.FINE; + } + + @Override + protected void setUp() throws Exception { + if (System.getProperty("netbeans.user") == null) { + System.setProperty("netbeans.user", new File(getWorkDir(), "ud").getPath()); + } + + LOG = Logger.getLogger("Test." + getName()); + + root = FileUtil.getConfigRoot(); + for (FileObject fo : root.getChildren()) { + fo.delete(); + } + + super.setUp(); + } + + public void testInterfaceFoundInMyServices() throws Exception { + assertNull("not found", Lookup.getDefault().lookup(Shared.class)); + FileObject fo = FileUtil.createData(root, "MyServices/sub/dir/2/" + Shared.class.getName().replace('.', '-') + ".instance"); + assertNotNull("found", Lookup.getDefault().lookup(Shared.class)); + fo.delete(); + assertNull("not found again", Lookup.getDefault().lookup(Shared.class)); + } + public void testInterfaceFoundInMyServices2() throws Exception { + assertNull("not found", Lookup.getDefault().lookup(Shared.class)); + FileObject fo = FileUtil.createData(root, "YourServices/kuk/" + Shared.class.getName().replace('.', '-') + ".instance"); + assertNotNull("found", Lookup.getDefault().lookup(Shared.class)); + fo.delete(); + assertNull("not found again", Lookup.getDefault().lookup(Shared.class)); + } + + public static final class Shared extends SharedClassObject {} + +} diff -r 5fb0d903fe36 openide.util/apichanges.xml --- a/openide.util/apichanges.xml Mon Jun 08 19:00:44 2009 +0200 +++ b/openide.util/apichanges.xml Tue Jun 09 13:56:42 2009 +0200 @@ -49,6 +49,20 @@ Actions API + + + Added org.openide.util.Lookup.paths property + + + + + +

+ Better way to integrate Lookup.getDefault() and system filesystem. +

+
+ +
Added loadImageIcon(String resource, boolean localized) diff -r 5fb0d903fe36 openide.util/arch.xml --- a/openide.util/arch.xml Mon Jun 08 19:00:44 2009 +0200 +++ b/openide.util/arch.xml Tue Jun 09 13:56:42 2009 +0200 @@ -514,6 +514,21 @@ is the result of Lookup.getDefault(). + +
  • + + Sometimes it may be useful for the Lookup to contains objects from + some system file system folder. This can be done with + org.openide.util.Lookup.paths=Folder1:Folder2:Folder3. + If this property is set prior to first call to + Lookup.getDefault(), + it is split into pieces (separator is ':') and individual + parts are then used to construct Lookups.forPath("Folder1"), + etc. All these lookups then become part of the + Lookup.getDefault() + one. This propert works since version 7.24 + +
  • diff -r 5fb0d903fe36 openide.util/nbproject/project.properties --- a/openide.util/nbproject/project.properties Mon Jun 08 19:00:44 2009 +0200 +++ b/openide.util/nbproject/project.properties Tue Jun 09 13:56:42 2009 +0200 @@ -42,7 +42,7 @@ module.jar.dir=lib cp.extra=${nb_all}/apisupport.harness/external/openjdk-javac-6-b12.jar -spec.version.base=7.23.0 +spec.version.base=7.24.0 # For XMLSerializer, needed for XMLUtil.write to work w/ namespaces under JDK 1.4: diff -r 5fb0d903fe36 openide.util/src/org/openide/util/Lookup.java --- a/openide.util/src/org/openide/util/Lookup.java Mon Jun 08 19:00:44 2009 +0200 +++ b/openide.util/src/org/openide/util/Lookup.java Tue Jun 09 13:56:42 2009 +0200 @@ -41,9 +41,11 @@ package org.openide.util; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.openide.util.lookup.Lookups; import org.openide.util.lookup.ProxyLookup; @@ -147,8 +149,10 @@ } DefLookup def = new DefLookup(); - def.init(l, misl); - return defaultLookup = def; + def.init(l, misl, false); + defaultLookup = def; + def.init(l, misl, true); + return defaultLookup; } private static final class DefLookup extends ProxyLookup { @@ -156,12 +160,21 @@ super(new Lookup[0]); } - public void init(ClassLoader loader, Lookup metaInfLookup) { + public void init(ClassLoader loader, Lookup metaInfLookup, boolean addPath) { // Had no such line, use simple impl. // It does however need to have ClassLoader available or many things will break. // Use the thread context classloader in effect now. Lookup clLookup = Lookups.singleton(loader); - setLookups(new Lookup[] { metaInfLookup, clLookup }); + List arr = new ArrayList(); + arr.add(metaInfLookup); + arr.add(clLookup); + String paths = System.getProperty("org.openide.util.Lookup.paths"); // NOI18N + if (addPath && paths != null) { + for (String p : paths.split(":")) { // NOI18N + arr.add(Lookups.forPath(p)); + } + } + setLookups(arr.toArray(new Lookup[0])); } } @@ -171,7 +184,7 @@ if (defaultLookup instanceof DefLookup) { DefLookup def = (DefLookup)defaultLookup; ClassLoader l = Thread.currentThread().getContextClassLoader(); - def.init(l, Lookups.metaInfServices(l)); + def.init(l, Lookups.metaInfServices(l), true); } } @@ -345,6 +358,7 @@ /* Computes hashcode for this template. The hashcode is cached. * @return hashcode */ + @Override public int hashCode() { if (hashCode != 0) { return hashCode; @@ -360,6 +374,7 @@ * @param obj another template to check * @return true if so, false otherwise */ + @Override public boolean equals(Object obj) { if (!(obj instanceof Template)) { return false; @@ -395,6 +410,7 @@ } /* for debugging */ + @Override public String toString() { return "Lookup.Template[type=" + type + ",id=" + id + ",instance=" + instance + "]"; // NOI18N } @@ -489,6 +505,7 @@ public abstract String getDisplayName(); /* show ID for debugging */ + @Override public String toString() { return getId(); } diff -r 5fb0d903fe36 openide.util/test/unit/src/org/openide/util/lookup/PathInLookupTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openide.util/test/unit/src/org/openide/util/lookup/PathInLookupTest.java Tue Jun 09 13:56:42 2009 +0200 @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 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]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * 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. + */ + +package org.openide.util.lookup; + +import java.util.logging.Level; +import org.netbeans.junit.MockServices; +import org.netbeans.junit.NbTestCase; +import org.netbeans.modules.openide.util.NamedServicesProvider; +import org.openide.util.Lookup; + +/** + * @author Jaroslav Tulach + */ +public class PathInLookupTest extends NbTestCase { + static { + System.setProperty("org.openide.util.Lookup.paths", "MyServices:YourServices"); + MockServices.setServices(P.class); + Lookup.getDefault(); + } + + public PathInLookupTest(String name) { + super(name); + } + + @Override + protected Level logLevel() { + return Level.FINE; + } + + public void testInterfaceFoundInMyServices() throws Exception { + assertNull("not found", Lookup.getDefault().lookup(Shared.class)); + Shared v = new Shared(); + P.ic1.add(v); + assertNotNull("found", Lookup.getDefault().lookup(Shared.class)); + P.ic1.remove(v); + assertNull("not found again", Lookup.getDefault().lookup(Shared.class)); + } + public void testInterfaceFoundInMyServices2() throws Exception { + assertNull("not found", Lookup.getDefault().lookup(Shared.class)); + Shared v = new Shared(); + P.ic2.add(v); + assertNotNull("found", Lookup.getDefault().lookup(Shared.class)); + P.ic2.remove(v); + assertNull("not found again", Lookup.getDefault().lookup(Shared.class)); + } + + static final class Shared extends Object {} + + public static final class P extends NamedServicesProvider { + static InstanceContent ic1 = new InstanceContent(); + static InstanceContent ic2 = new InstanceContent(); + static AbstractLookup[] arr = { + new AbstractLookup(ic1), new AbstractLookup(ic2) + }; + + + @Override + public Lookup create(String path) { + int indx = -1; + if (path.equals("MyServices/")) { + indx = 0; + } + if (path.equals("YourServices/")) { + indx = 1; + } + if (indx == -1) { + fail("Unexpected lookup query: " + path); + } + return arr[indx]; + } + } + +}