diff --git a/openide.util.lookup/manifest.mf b/openide.util.lookup/manifest.mf --- a/openide.util.lookup/manifest.mf +++ b/openide.util.lookup/manifest.mf @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openide.util.lookup OpenIDE-Module-Localizing-Bundle: org/openide/util/lookup/Bundle.properties -OpenIDE-Module-Specification-Version: 8.30 +OpenIDE-Module-Specification-Version: 8.31 diff --git a/openide.util.lookup/src/org/netbeans/modules/openide/util/GlobalLookup.java b/openide.util.lookup/src/org/netbeans/modules/openide/util/GlobalLookup.java --- a/openide.util.lookup/src/org/netbeans/modules/openide/util/GlobalLookup.java +++ b/openide.util.lookup/src/org/netbeans/modules/openide/util/GlobalLookup.java @@ -46,10 +46,19 @@ public class GlobalLookup { private static final ThreadLocal CURRENT = new ThreadLocal(); + /** + * The true system Lookup, the main, holy and only. + */ + private static volatile Lookup systemLookup; + private GlobalLookup() { } + @SuppressWarnings("AssignmentToMethodParameter") public static boolean execute(Lookup defaultLookup, Runnable r) { + if (defaultLookup == null) { + defaultLookup = systemLookup; + } Lookup prev = CURRENT.get(); if (prev == defaultLookup) { return false; @@ -66,4 +75,8 @@ public static Lookup current() { return CURRENT.get(); } + + public static void setSystemLookup(Lookup lkp) { + systemLookup = lkp; + } } diff --git a/openide.util.lookup/src/org/openide/util/Lookup.java b/openide.util.lookup/src/org/openide/util/Lookup.java --- a/openide.util.lookup/src/org/openide/util/Lookup.java +++ b/openide.util.lookup/src/org/openide/util/Lookup.java @@ -127,8 +127,9 @@ if (lkp != null) { return lkp; } + } else { + return defaultLookup; } - return defaultLookup; } LOG.log(Level.FINER, "About to initialize Lookup@{0}.getDefault() by {1}", new Object[] { Lookup.class.getClassLoader(), Thread.currentThread() } @@ -149,6 +150,8 @@ if (className != null) { Object o = Class.forName(className, true, l).newInstance(); defaultLookup = (Lookup)o; + // set the global global Lookuo + GlobalLookup.setSystemLookup(defaultLookup); LOG.log(Level.FINE, "Default lookup initialized {0}", defaultLookup); // for testing purposes, tests may setup a class implementing both interfaces if (o instanceof Lookup.Provider) { diff --git a/openide.util.lookup/src/org/openide/util/lookup/Lookups.java b/openide.util.lookup/src/org/openide/util/lookup/Lookups.java --- a/openide.util.lookup/src/org/openide/util/lookup/Lookups.java +++ b/openide.util.lookup/src/org/openide/util/lookup/Lookups.java @@ -285,10 +285,19 @@ * of {@link Lookup#getDefault()} to here-in provided lookup. Useful in a * multi user environment where different users and their requests should * be associated with different content of default lookup. + *

+ * As a special case, {@code executeWith} will execute the Runnable with + * the system global lookup (the one effective during system bootstrap), when + * the passed {@code defaultLookup} parameter is {@code null}. This feature may + * be useful to switch from a specialized Lookup back to a default one for + * some limited processing, or when the caller needs to bypass potential + * execution-local content temporary effective in the default Lookup and + * work with system-wide services only. * * @param defaultLookup the lookup to be come default while code is running * @param code the code to execute (synchronously) before the method returns * @since 8.30 + * @since 8.31 can delegate to the system Lookup */ public static void executeWith(Lookup defaultLookup, Runnable code) { if (!GlobalLookup.execute(defaultLookup, code)) { diff --git a/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java b/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java --- a/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java +++ b/openide.util.lookup/src/org/openide/util/lookup/MetaInfServicesLookup.java @@ -512,6 +512,10 @@ if (o == null) { o = SharedClassObjectBridge.newInstance(c); + Object other = CACHE.findInstance(c); + if (other != null) { + return object = other; + } CACHE.storeInstance(o); }