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

(-)a/core.osgi/src/org/netbeans/core/osgi/OSGiMainLookup.java (-1 / +1 lines)
Lines 131-137 Link Here
131
    private void postInit() {
131
    private void postInit() {
132
        nonClassLoaderDelegates.add(Lookups.fixed(OSGiRepository.DEFAULT, new OSGiLifecycleManager(context), new OSGiInstalledFileLocator(context)));
132
        nonClassLoaderDelegates.add(Lookups.fixed(OSGiRepository.DEFAULT, new OSGiLifecycleManager(context), new OSGiInstalledFileLocator(context)));
133
        nonClassLoaderDelegates.add(new AbstractLookup(moduleInfoContent));
133
        nonClassLoaderDelegates.add(new AbstractLookup(moduleInfoContent));
134
        // XXX InstalledFileLocator impl for OSGI-INF/files/*
134
        // XXX should add a org.openide.modules.Modules
135
        setClassLoader();
135
        setClassLoader();
136
    }
136
    }
137
137
(-)a/core.startup/src/org/netbeans/core/startup/preferences/PreferencesProviderImpl.java (-8 / +5 lines)
Lines 45-51 Link Here
45
package org.netbeans.core.startup.preferences;
45
package org.netbeans.core.startup.preferences;
46
46
47
import java.util.prefs.Preferences;
47
import java.util.prefs.Preferences;
48
import org.netbeans.Util;
48
import org.openide.modules.ModuleInfo;
49
import org.openide.modules.Modules;
49
import org.openide.util.lookup.ServiceProvider;
50
import org.openide.util.lookup.ServiceProvider;
50
51
51
/**
52
/**
Lines 53-67 Link Here
53
 */
54
 */
54
@ServiceProvider(service=org.openide.util.NbPreferences.Provider.class)
55
@ServiceProvider(service=org.openide.util.NbPreferences.Provider.class)
55
public class PreferencesProviderImpl implements org.openide.util.NbPreferences.Provider {
56
public class PreferencesProviderImpl implements org.openide.util.NbPreferences.Provider {
56
    /** Creates a new instance of PreferencesProviderImpl */
57
    public PreferencesProviderImpl() {
58
    }
59
    
60
    public Preferences preferencesForModule(Class cls) {
57
    public Preferences preferencesForModule(Class cls) {
61
        String absolutePath = null;
58
        String absolutePath = null;
62
        ClassLoader cl = cls.getClassLoader();
59
        ModuleInfo owner = Modules.getDefault().ownerOf(cls);
63
        if (cl instanceof Util.ModuleProvider) {
60
        if (owner != null) {
64
            absolutePath = ((Util.ModuleProvider) cl).getModule().getCodeNameBase();
61
            absolutePath = owner.getCodeNameBase();
65
        } else {
62
        } else {
66
            absolutePath = cls.getName().replaceFirst("(^|\\.)[^.]+$", "");//NOI18N
63
            absolutePath = cls.getName().replaceFirst("(^|\\.)[^.]+$", "");//NOI18N
67
        }
64
        }
(-)a/o.n.bootstrap/src/org/netbeans/Module.java (-5 / +11 lines)
Lines 259-266 Link Here
259
        return specVers;
259
        return specVers;
260
    }
260
    }
261
    
261
    
262
    @Override
262
    public @Override boolean owns(Class<?> clazz) {
263
    public boolean owns(Class clazz) {
264
        ClassLoader cl = clazz.getClassLoader();
263
        ClassLoader cl = clazz.getClassLoader();
265
        if (cl instanceof Util.ModuleProvider) {
264
        if (cl instanceof Util.ModuleProvider) {
266
            return ((Util.ModuleProvider) cl).getModule() == this;
265
            return ((Util.ModuleProvider) cl).getModule() == this;
Lines 268-273 Link Here
268
        if (cl != classloader) {
267
        if (cl != classloader) {
269
            return false;
268
            return false;
270
        }
269
        }
270
        String _codeName = findClasspathModuleCodeName(clazz);
271
        if (_codeName != null) {
272
            return _codeName.equals(codeName);
273
        }
274
        return true; // not sure...
275
    }
276
    
277
    static String findClasspathModuleCodeName(Class<?> clazz) {
271
        // #157798: in JNLP or otherwise classpath mode, all modules share a CL.
278
        // #157798: in JNLP or otherwise classpath mode, all modules share a CL.
272
        CodeSource src = clazz.getProtectionDomain().getCodeSource();
279
        CodeSource src = clazz.getProtectionDomain().getCodeSource();
273
        if (src != null) {
280
        if (src != null) {
Lines 280-287 Link Here
280
                URL manifest = new URL(loc, "META-INF/MANIFEST.MF");
287
                URL manifest = new URL(loc, "META-INF/MANIFEST.MF");
281
                InputStream is = manifest.openStream();
288
                InputStream is = manifest.openStream();
282
                try {
289
                try {
283
                    Manifest mf = new Manifest(is);
290
                    return new Manifest(is).getMainAttributes().getValue("OpenIDE-Module");
284
                    return codeName.equals(mf.getMainAttributes().getValue("OpenIDE-Module"));
285
                } finally {
291
                } finally {
286
                    is.close();
292
                    is.close();
287
                }
293
                }
Lines 289-295 Link Here
289
                Logger.getLogger(Module.class.getName()).log(Level.FINE, null, x);
295
                Logger.getLogger(Module.class.getName()).log(Level.FINE, null, x);
290
            }
296
            }
291
        }
297
        }
292
        return true; // not sure...
298
        return null;
293
    }
299
    }
294
    
300
    
295
    /** Get all packages exported by this module to other modules.
301
    /** Get all packages exported by this module to other modules.
(-)a/o.n.bootstrap/src/org/netbeans/ModuleManager.java (-2 / +18 lines)
Lines 70-87 Link Here
70
import org.openide.LifecycleManager;
70
import org.openide.LifecycleManager;
71
import org.openide.modules.Dependency;
71
import org.openide.modules.Dependency;
72
import org.openide.modules.ModuleInfo;
72
import org.openide.modules.ModuleInfo;
73
import org.openide.modules.Modules;
73
import org.openide.modules.SpecificationVersion;
74
import org.openide.modules.SpecificationVersion;
74
import org.openide.util.Lookup;
75
import org.openide.util.Lookup;
75
import org.openide.util.Mutex;
76
import org.openide.util.Mutex;
76
import org.openide.util.TopologicalSortException;
77
import org.openide.util.TopologicalSortException;
77
import org.openide.util.Union2;
78
import org.openide.util.Union2;
78
import org.openide.util.Utilities;
79
import org.openide.util.Utilities;
80
import org.openide.util.lookup.Lookups;
81
import org.openide.util.lookup.ProxyLookup;
79
82
80
/** Manages a collection of modules.
83
/** Manages a collection of modules.
81
 * Must use {@link #mutex} to access its important methods.
84
 * Must use {@link #mutex} to access its important methods.
82
 * @author Jesse Glick
85
 * @author Jesse Glick
83
 */
86
 */
84
public final class ModuleManager {
87
public final class ModuleManager extends Modules {
85
88
86
    public static final String PROP_MODULES = "modules"; // NOI18N
89
    public static final String PROP_MODULES = "modules"; // NOI18N
87
    public static final String PROP_ENABLED_MODULES = "enabledModules"; // NOI18N
90
    public static final String PROP_ENABLED_MODULES = "enabledModules"; // NOI18N
Lines 272-277 Link Here
272
    }
275
    }
273
276
274
    private final Util.ModuleLookup lookup = new Util.ModuleLookup();
277
    private final Util.ModuleLookup lookup = new Util.ModuleLookup();
278
    private final Lookup completeLookup = new ProxyLookup(Lookups.fixed(this), lookup);
275
    /** Retrieve set of modules in Lookup form.
279
    /** Retrieve set of modules in Lookup form.
276
     * The core top manager should install this into the set of
280
     * The core top manager should install this into the set of
277
     * available lookups. Will fire lookup events when the
281
     * available lookups. Will fire lookup events when the
Lines 281-287 Link Here
281
     * straight to this lookup when ModuleInfo/Module is requested.
285
     * straight to this lookup when ModuleInfo/Module is requested.
282
     */
286
     */
283
    public Lookup getModuleLookup() {
287
    public Lookup getModuleLookup() {
284
        return lookup;
288
        return completeLookup;
285
    }
289
    }
286
    // Access from ChangeFirer:
290
    // Access from ChangeFirer:
287
    final void fireModulesCreatedDeleted(Set created, Set deleted) {
291
    final void fireModulesCreatedDeleted(Set created, Set deleted) {
Lines 320-325 Link Here
320
        return modulesByName.get(codeNameBase);
324
        return modulesByName.get(codeNameBase);
321
    }
325
    }
322
326
327
    public @Override ModuleInfo ownerOf(Class<?> clazz) {
328
        ClassLoader cl = clazz.getClassLoader();
329
        if (cl instanceof Util.ModuleProvider) {
330
            return ((Util.ModuleProvider) cl).getModule();
331
        }
332
        String codename = Module.findClasspathModuleCodeName(clazz);
333
        if (codename != null) {
334
            return get(codename.replaceFirst("/\\d+$", "")); // NOI18N
335
        }
336
        return null;
337
    }
338
323
    /**
339
    /**
324
     * Get a set of modules depended upon or depending on this module.
340
     * Get a set of modules depended upon or depending on this module.
325
     * <p>Note that provide-require/need dependencies are listed alongside direct
341
     * <p>Note that provide-require/need dependencies are listed alongside direct
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java (+13 lines)
Lines 77-82 Link Here
77
import org.netbeans.junit.RandomlyFails;
77
import org.netbeans.junit.RandomlyFails;
78
import org.openide.modules.Dependency;
78
import org.openide.modules.Dependency;
79
import org.openide.modules.ModuleInfo;
79
import org.openide.modules.ModuleInfo;
80
import org.openide.modules.Modules;
80
import org.openide.util.Lookup;
81
import org.openide.util.Lookup;
81
import org.openide.util.LookupEvent;
82
import org.openide.util.LookupEvent;
82
import org.openide.util.LookupListener;
83
import org.openide.util.LookupListener;
Lines 2532-2537 Link Here
2532
        TestFileUtils.writeFile(new File(data, "mod2/pkg/C3.java"), "package pkg; class C3 {}");
2533
        TestFileUtils.writeFile(new File(data, "mod2/pkg/C3.java"), "package pkg; class C3 {}");
2533
        File mod2JAR = createTestJAR(data, jars, "mod2", null);
2534
        File mod2JAR = createTestJAR(data, jars, "mod2", null);
2534
        ModuleManager mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2535
        ModuleManager mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2536
        Modules modules = mgr.getModuleLookup().lookup(Modules.class);
2537
        assertNotNull(modules);
2535
        mgr.mutexPrivileged().enterWriteAccess();
2538
        mgr.mutexPrivileged().enterWriteAccess();
2536
        try {
2539
        try {
2537
            Module mod1 = mgr.create(mod1JAR, null, false, false, false);
2540
            Module mod1 = mgr.create(mod1JAR, null, false, false, false);
Lines 2547-2556 Link Here
2547
            assertFalse(mod2.owns(c1));
2550
            assertFalse(mod2.owns(c1));
2548
            assertFalse(mod2.owns(c2));
2551
            assertFalse(mod2.owns(c2));
2549
            assertTrue(mod2.owns(c3));
2552
            assertTrue(mod2.owns(c3));
2553
            assertEquals(mod1, modules.ownerOf(c1));
2554
            assertEquals(mod1, modules.ownerOf(c2));
2555
            assertEquals(mod2, modules.ownerOf(c3));
2556
            assertNull(modules.ownerOf(String.class));
2550
        } finally {
2557
        } finally {
2551
            mgr.mutexPrivileged().exitWriteAccess();
2558
            mgr.mutexPrivileged().exitWriteAccess();
2552
        }
2559
        }
2553
        mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2560
        mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2561
        modules = mgr.getModuleLookup().lookup(Modules.class);
2562
        assertNotNull(modules);
2554
        mgr.mutexPrivileged().enterWriteAccess();
2563
        mgr.mutexPrivileged().enterWriteAccess();
2555
        try {
2564
        try {
2556
            ClassLoader l = new URLClassLoader(new URL[] {mod1JAR.toURI().toURL(), mod2JAR.toURI().toURL()});
2565
            ClassLoader l = new URLClassLoader(new URL[] {mod1JAR.toURI().toURL(), mod2JAR.toURI().toURL()});
Lines 2569-2574 Link Here
2569
            assertFalse(mod2.owns(c1));
2578
            assertFalse(mod2.owns(c1));
2570
            assertFalse(mod2.owns(c2));
2579
            assertFalse(mod2.owns(c2));
2571
            assertTrue(mod2.owns(c3));
2580
            assertTrue(mod2.owns(c3));
2581
            assertEquals(mod1, modules.ownerOf(c1));
2582
            assertEquals(mod1, modules.ownerOf(c2));
2583
            assertEquals(mod2, modules.ownerOf(c3));
2584
            assertNull(modules.ownerOf(String.class));
2572
        } finally {
2585
        } finally {
2573
            mgr.mutexPrivileged().exitWriteAccess();
2586
            mgr.mutexPrivileged().exitWriteAccess();
2574
        }
2587
        }
(-)a/o.n.core/src/org/netbeans/core/NbLoaderPool.java (-11 / +3 lines)
Lines 52-58 Link Here
52
import java.io.OutputStream;
52
import java.io.OutputStream;
53
import java.util.ArrayList;
53
import java.util.ArrayList;
54
import java.util.Arrays;
54
import java.util.Arrays;
55
import java.util.Collection;
56
import java.util.Enumeration;
55
import java.util.Enumeration;
57
import java.util.HashMap;
56
import java.util.HashMap;
58
import java.util.HashSet;
57
import java.util.HashSet;
Lines 74-79 Link Here
74
import org.openide.loaders.DataLoader;
73
import org.openide.loaders.DataLoader;
75
import org.openide.loaders.DataLoaderPool;
74
import org.openide.loaders.DataLoaderPool;
76
import org.openide.modules.ModuleInfo;
75
import org.openide.modules.ModuleInfo;
76
import org.openide.modules.Modules;
77
import org.openide.modules.SpecificationVersion;
77
import org.openide.modules.SpecificationVersion;
78
import org.openide.util.Lookup;
78
import org.openide.util.Lookup;
79
import org.openide.util.LookupEvent;
79
import org.openide.util.LookupEvent;
Lines 317-325 Link Here
317
        oos.writeObject (new HashMap()/*installBefores*/);
317
        oos.writeObject (new HashMap()/*installBefores*/);
318
        oos.writeObject (new HashMap()/*installAfters*/);
318
        oos.writeObject (new HashMap()/*installAfters*/);
319
        
319
        
320
        // Note which module each loader came from.
321
        Collection modules = Lookup.getDefault().lookupAll(ModuleInfo.class); // Collection<ModuleInfo>
322
323
        Iterator it = loaders.iterator ();
320
        Iterator it = loaders.iterator ();
324
321
325
        while (it.hasNext ()) {
322
        while (it.hasNext ()) {
Lines 345-356 Link Here
345
            if (obj != null) {
342
            if (obj != null) {
346
                if (err.isLoggable(Level.FINE)) err.fine("writing modified " + l.getClass().getName());
343
                if (err.isLoggable(Level.FINE)) err.fine("writing modified " + l.getClass().getName());
347
                // Find its module, if any.
344
                // Find its module, if any.
348
                Class c = l.getClass();
349
                Iterator mit = modules.iterator();
350
                boolean found = false;
345
                boolean found = false;
351
                while (mit.hasNext()) {
346
                ModuleInfo m = Modules.getDefault().ownerOf(l.getClass());
352
                    ModuleInfo m = (ModuleInfo)mit.next();
347
                if (m != null && m.isEnabled()) {
353
                    if (m.isEnabled() && m.owns(c)) {
354
                        if (err.isLoggable(Level.FINE)) err.fine("belongs to module: " + m.getCodeNameBase());
348
                        if (err.isLoggable(Level.FINE)) err.fine("belongs to module: " + m.getCodeNameBase());
355
                        oos.writeObject(m.getCodeNameBase());
349
                        oos.writeObject(m.getCodeNameBase());
356
                        int r = m.getCodeNameRelease();
350
                        int r = m.getCodeNameRelease();
Lines 362-369 Link Here
362
                            oos.writeObject(null);
356
                            oos.writeObject(null);
363
                        }
357
                        }
364
                        found = true;
358
                        found = true;
365
                        break;
366
                    }
367
                }
359
                }
368
                if (!found) {
360
                if (!found) {
369
                    if (err.isLoggable(Level.FINE)) err.fine("does not belong to any module");
361
                    if (err.isLoggable(Level.FINE)) err.fine("does not belong to any module");
(-)a/openide.loaders/src/org/openide/loaders/DataLoaderPool.java (-11 / +5 lines)
Lines 52-57 Link Here
52
import javax.swing.event.*;
52
import javax.swing.event.*;
53
import org.openide.filesystems.*;
53
import org.openide.filesystems.*;
54
import org.openide.modules.ModuleInfo;
54
import org.openide.modules.ModuleInfo;
55
import org.openide.modules.Modules;
55
import org.openide.nodes.*;
56
import org.openide.nodes.*;
56
import org.openide.util.*;
57
import org.openide.util.*;
57
import org.openide.util.actions.SystemAction;
58
import org.openide.util.actions.SystemAction;
Lines 568-585 Link Here
568
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER, null);
569
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER, null);
569
        } else {
570
        } else {
570
            Class c = loader.getClass();
571
            Class c = loader.getClass();
571
            // [PENDING] in the future a more efficient API may be introduced
572
            fo.setAttribute (DataObject.EA_ASSIGNED_LOADER, c.getName ());
572
            Iterator modules = Lookup.getDefault().lookupAll(ModuleInfo.class).iterator();
573
            ModuleInfo module = Modules.getDefault().ownerOf(c);
573
            String modulename = null;
574
            if (module != null) {
574
            while (modules.hasNext()) {
575
                fo.setAttribute(DataObject.EA_ASSIGNED_LOADER_MODULE, module.getCodeNameBase());
575
                ModuleInfo module = (ModuleInfo)modules.next();
576
                if (module.owns(c)) {
577
                    modulename = module.getCodeNameBase();
578
                    break;
579
                }
580
            }
576
            }
581
            fo.setAttribute (DataObject.EA_ASSIGNED_LOADER, c.getName ());
582
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER_MODULE, modulename);
583
        }
577
        }
584
        if (!DataObjectPool.getPOOL().revalidate(Collections.singleton(fo)).isEmpty()) {
578
        if (!DataObjectPool.getPOOL().revalidate(Collections.singleton(fo)).isEmpty()) {
585
            DataObject.LOG.fine("It was not possible to invalidate data object: " + fo); // NOI18N
579
            DataObject.LOG.fine("It was not possible to invalidate data object: " + fo); // NOI18N
(-)a/openide.modules/src/org/openide/modules/ModuleInfo.java (-8 / +6 lines)
Lines 43-55 Link Here
43
 */
43
 */
44
package org.openide.modules;
44
package org.openide.modules;
45
45
46
import java.beans.*;
46
import java.beans.PropertyChangeListener;
47
47
import java.beans.PropertyChangeSupport;
48
// THIS CLASS OUGHT NOT USE NbBundle NOR org.openide CLASSES
48
import java.util.Set;
49
// OUTSIDE OF openide-util.jar! UI AND FILESYSTEM/DATASYSTEM
50
// INTERACTIONS SHOULD GO ELSEWHERE.
51
import java.util.*;
52
53
49
54
/** General information about a module.
50
/** General information about a module.
55
 * Immutable from an API perspective, serves as
51
 * Immutable from an API perspective, serves as
Lines 162-171 Link Here
162
     * was loaded as a part of this module, and thus will only be
158
     * was loaded as a part of this module, and thus will only be
163
     * loadable later if this module is enabled.
159
     * loadable later if this module is enabled.
164
     * If in doubt, return <code>false</code>.
160
     * If in doubt, return <code>false</code>.
161
     * @see Modules#ownerOf
165
     * @since 1.28
162
     * @since 1.28
166
     */
163
     */
167
    public abstract boolean owns(Class<?> clazz);
164
    public abstract boolean owns(Class<?> clazz);
168
165
    
169
    /**
166
    /**
170
     * Get a class loader associated with this module that can load
167
     * Get a class loader associated with this module that can load
171
     * classes defined in the module.
168
     * classes defined in the module.
Lines 197-200 Link Here
197
    public String[] getProvides() {
194
    public String[] getProvides() {
198
        return new String[] {  };
195
        return new String[] {  };
199
    }
196
    }
197
    
200
}
198
}
(-)a/openide.modules/src/org/openide/modules/Modules.java (+92 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.openide.modules;
44
45
import org.openide.util.Lookup;
46
47
/**
48
 * Information about the set of available {@linkplain ModuleInfo modules}.
49
 * An implementation of this service should be registered by the module system.
50
 * @since XXX
51
 */
52
public abstract class Modules {
53
    
54
    public static Modules getDefault() {
55
        Modules impl = Lookup.getDefault().lookup(Modules.class);
56
        if (impl == null) {
57
            impl = new Trivial();
58
        }
59
        return impl;
60
    }
61
62
    /**
63
     * Restricted constructor for subclasses.
64
     */
65
    protected Modules() {
66
        if (!(this instanceof Trivial) && !getClass().getName().equals("org.netbeans.ModuleManager")) {
67
            throw new IllegalAccessError();
68
        }
69
    }
70
    
71
    /**
72
     * Finds the module which loaded a class.
73
     * @param clazz a class
74
     * @return the owner of the class, or null if it is not owned by any module
75
     * @see ModuleInfo#owns
76
     */
77
    public abstract ModuleInfo ownerOf(Class<?> clazz);
78
    
79
    private static class Trivial extends Modules {
80
        
81
        public @Override ModuleInfo ownerOf(Class<?> clazz) {
82
            for (ModuleInfo module : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
83
                if (module.owns(clazz)) {
84
                    return module;
85
                }
86
            }
87
            return null;
88
        }
89
        
90
    }
91
    
92
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java (-7 / +4 lines)
Lines 72-77 Link Here
72
import org.openide.util.Lookup;
72
import org.openide.util.Lookup;
73
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
73
import org.netbeans.modules.refactoring.spi.RefactoringElementsBag;
74
import org.netbeans.modules.refactoring.spi.impl.RefactoringPanel;
74
import org.netbeans.modules.refactoring.spi.impl.RefactoringPanel;
75
import org.openide.modules.Modules;
75
import org.openide.util.Exceptions;
76
import org.openide.util.Exceptions;
76
import org.openide.util.NbBundle;
77
import org.openide.util.NbBundle;
77
import org.openide.util.Parameters;
78
import org.openide.util.Parameters;
Lines 373-385 Link Here
373
        }
374
        }
374
    }
375
    }
375
    
376
    
376
    private String getModuleName(Class c) {
377
    private String getModuleName(Class<?> c) {
377
        for (ModuleInfo info:Lookup.getDefault().lookupAll(ModuleInfo.class)) {
378
        ModuleInfo info = Modules.getDefault().ownerOf(c);
378
            if (info.owns(c)) {
379
        return info != null ? info.getDisplayName() : "Unknown"; //NOI18N
379
                return info.getDisplayName();
380
            }
381
        }
382
        return "Unknown";//NOI18N
383
    }
380
    }
384
    
381
    
385
    private String createMessage(Class c, Throwable t) {
382
    private String createMessage(Class c, Throwable t) {
(-)a/settings/src/org/netbeans/modules/settings/convertors/ModuleInfoManager.java (-13 lines)
Lines 164-182 Link Here
164
        
164
        
165
        return reloaded;
165
        return reloaded;
166
    }
166
    }
167
168
    /** look up ModuleInfo according to clazz
169
     * @param clazz class used in the look up query
170
     * @return module info of the module which clazz was loaded from
171
     */
172
    public ModuleInfo getModuleInfo(Class clazz) {
173
        Iterator it = getModulesResult().allInstances().iterator();
174
        while (it.hasNext()) {
175
            ModuleInfo mi = (ModuleInfo) it.next();
176
            if (mi.owns(clazz)) return mi;
177
        }
178
        return null;
179
    }
180
    
167
    
181
    /** register listener to be notified about changes of mi
168
    /** register listener to be notified about changes of mi
182
     * @param sdc convertor
169
     * @param sdc convertor
(-)a/settings/src/org/netbeans/modules/settings/convertors/SerialDataConvertor.java (-1 / +2 lines)
Lines 77-82 Link Here
77
import org.openide.loaders.Environment;
77
import org.openide.loaders.Environment;
78
import org.openide.loaders.InstanceDataObject;
78
import org.openide.loaders.InstanceDataObject;
79
import org.openide.modules.ModuleInfo;
79
import org.openide.modules.ModuleInfo;
80
import org.openide.modules.Modules;
80
import org.openide.nodes.Node;
81
import org.openide.nodes.Node;
81
import org.openide.util.Lookup;
82
import org.openide.util.Lookup;
82
import org.openide.util.SharedClassObject;
83
import org.openide.util.SharedClassObject;
Lines 135-141 Link Here
135
     * @exception IOException if the object cannot be written
136
     * @exception IOException if the object cannot be written
136
     */
137
     */
137
    public void write(Writer w, Object inst) throws IOException {
138
    public void write(Writer w, Object inst) throws IOException {
138
        XMLSettingsSupport.storeToXML10(inst, w, ModuleInfoManager.getDefault().getModuleInfo(inst.getClass()));
139
        XMLSettingsSupport.storeToXML10(inst, w, Modules.getDefault().ownerOf(inst.getClass()));
139
    }
140
    }
140
    
141
    
141
    /** delegate to SaveSupport to handle an unfired setting object change
142
    /** delegate to SaveSupport to handle an unfired setting object change
(-)a/settings/src/org/netbeans/modules/settings/convertors/XMLSettingsSupport.java (-1 / +2 lines)
Lines 52-57 Link Here
52
52
53
import org.openide.filesystems.*;
53
import org.openide.filesystems.*;
54
import org.openide.modules.ModuleInfo;
54
import org.openide.modules.ModuleInfo;
55
import org.openide.modules.Modules;
55
import org.openide.modules.SpecificationVersion;
56
import org.openide.modules.SpecificationVersion;
56
import org.openide.util.Exceptions;
57
import org.openide.util.Exceptions;
57
import org.openide.util.Lookup;
58
import org.openide.util.Lookup;
Lines 1167-1173 Link Here
1167
        }
1168
        }
1168
        
1169
        
1169
        public void write(java.io.Writer w, Object inst) throws java.io.IOException {
1170
        public void write(java.io.Writer w, Object inst) throws java.io.IOException {
1170
            XMLSettingsSupport.storeToXML10(inst, w, ModuleInfoManager.getDefault().getModuleInfo(inst.getClass()));
1171
            XMLSettingsSupport.storeToXML10(inst, w, Modules.getDefault().ownerOf(inst.getClass()));
1171
        }
1172
        }
1172
        
1173
        
1173
    }
1174
    }

Return to bug 157828