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 could add a ModuleInfo.OwnershipProvider
135
        setClassLoader();
135
        setClassLoader();
136
    }
136
    }
137
137
(-)a/core.startup/src/org/netbeans/core/startup/preferences/PreferencesProviderImpl.java (-8 / +4 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.util.lookup.ServiceProvider;
49
import org.openide.util.lookup.ServiceProvider;
50
50
51
/**
51
/**
Lines 53-67 Link Here
53
 */
53
 */
54
@ServiceProvider(service=org.openide.util.NbPreferences.Provider.class)
54
@ServiceProvider(service=org.openide.util.NbPreferences.Provider.class)
55
public class PreferencesProviderImpl implements org.openide.util.NbPreferences.Provider {
55
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) {
56
    public Preferences preferencesForModule(Class cls) {
61
        String absolutePath = null;
57
        String absolutePath = null;
62
        ClassLoader cl = cls.getClassLoader();
58
        ModuleInfo owner = ModuleInfo.forClass(cls);
63
        if (cl instanceof Util.ModuleProvider) {
59
        if (owner != null) {
64
            absolutePath = ((Util.ModuleProvider) cl).getModule().getCodeNameBase();
60
            absolutePath = owner.getCodeNameBase();
65
        } else {
61
        } else {
66
            absolutePath = cls.getName().replaceFirst("(^|\\.)[^.]+$", "");//NOI18N
62
            absolutePath = cls.getName().replaceFirst("(^|\\.)[^.]+$", "");//NOI18N
67
        }
63
        }
(-)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 (-1 / +16 lines)
Lines 76-81 Link Here
76
import org.openide.util.TopologicalSortException;
76
import org.openide.util.TopologicalSortException;
77
import org.openide.util.Union2;
77
import org.openide.util.Union2;
78
import org.openide.util.Utilities;
78
import org.openide.util.Utilities;
79
import org.openide.util.lookup.Lookups;
80
import org.openide.util.lookup.ProxyLookup;
79
81
80
/** Manages a collection of modules.
82
/** Manages a collection of modules.
81
 * Must use {@link #mutex} to access its important methods.
83
 * Must use {@link #mutex} to access its important methods.
Lines 272-277 Link Here
272
    }
274
    }
273
275
274
    private final Util.ModuleLookup lookup = new Util.ModuleLookup();
276
    private final Util.ModuleLookup lookup = new Util.ModuleLookup();
277
    private final Lookup completeLookup = new ProxyLookup(Lookups.fixed(new ModuleInfo.OwnershipProvider() {
278
        public @Override ModuleInfo forClass(Class<?> clazz) {
279
            ClassLoader cl = clazz.getClassLoader();
280
            if (cl instanceof Util.ModuleProvider) {
281
                return ((Util.ModuleProvider) cl).getModule();
282
            }
283
            String codename = Module.findClasspathModuleCodeName(clazz);
284
            if (codename != null) {
285
                return get(codename.replaceFirst("/\\d+$", "")); // NOI18N
286
            }
287
            return null;
288
        }
289
    }), lookup);
275
    /** Retrieve set of modules in Lookup form.
290
    /** Retrieve set of modules in Lookup form.
276
     * The core top manager should install this into the set of
291
     * The core top manager should install this into the set of
277
     * available lookups. Will fire lookup events when the
292
     * available lookups. Will fire lookup events when the
Lines 281-287 Link Here
281
     * straight to this lookup when ModuleInfo/Module is requested.
296
     * straight to this lookup when ModuleInfo/Module is requested.
282
     */
297
     */
283
    public Lookup getModuleLookup() {
298
    public Lookup getModuleLookup() {
284
        return lookup;
299
        return completeLookup;
285
    }
300
    }
286
    // Access from ChangeFirer:
301
    // Access from ChangeFirer:
287
    final void fireModulesCreatedDeleted(Set created, Set deleted) {
302
    final void fireModulesCreatedDeleted(Set created, Set deleted) {
(-)a/o.n.bootstrap/test/unit/src/org/netbeans/ModuleManagerTest.java (+12 lines)
Lines 2532-2537 Link Here
2532
        TestFileUtils.writeFile(new File(data, "mod2/pkg/C3.java"), "package pkg; class C3 {}");
2532
        TestFileUtils.writeFile(new File(data, "mod2/pkg/C3.java"), "package pkg; class C3 {}");
2533
        File mod2JAR = createTestJAR(data, jars, "mod2", null);
2533
        File mod2JAR = createTestJAR(data, jars, "mod2", null);
2534
        ModuleManager mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2534
        ModuleManager mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2535
        ModuleInfo.OwnershipProvider ownership = mgr.getModuleLookup().lookup(ModuleInfo.OwnershipProvider.class);
2536
        assertNotNull(ownership);
2535
        mgr.mutexPrivileged().enterWriteAccess();
2537
        mgr.mutexPrivileged().enterWriteAccess();
2536
        try {
2538
        try {
2537
            Module mod1 = mgr.create(mod1JAR, null, false, false, false);
2539
            Module mod1 = mgr.create(mod1JAR, null, false, false, false);
Lines 2547-2556 Link Here
2547
            assertFalse(mod2.owns(c1));
2549
            assertFalse(mod2.owns(c1));
2548
            assertFalse(mod2.owns(c2));
2550
            assertFalse(mod2.owns(c2));
2549
            assertTrue(mod2.owns(c3));
2551
            assertTrue(mod2.owns(c3));
2552
            assertEquals(mod1, ownership.forClass(c1));
2553
            assertEquals(mod1, ownership.forClass(c2));
2554
            assertEquals(mod2, ownership.forClass(c3));
2555
            assertNull(ownership.forClass(String.class));
2550
        } finally {
2556
        } finally {
2551
            mgr.mutexPrivileged().exitWriteAccess();
2557
            mgr.mutexPrivileged().exitWriteAccess();
2552
        }
2558
        }
2553
        mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2559
        mgr = new ModuleManager(new MockModuleInstaller(), new MockEvents());
2560
        ownership = mgr.getModuleLookup().lookup(ModuleInfo.OwnershipProvider.class);
2561
        assertNotNull(ownership);
2554
        mgr.mutexPrivileged().enterWriteAccess();
2562
        mgr.mutexPrivileged().enterWriteAccess();
2555
        try {
2563
        try {
2556
            ClassLoader l = new URLClassLoader(new URL[] {mod1JAR.toURI().toURL(), mod2JAR.toURI().toURL()});
2564
            ClassLoader l = new URLClassLoader(new URL[] {mod1JAR.toURI().toURL(), mod2JAR.toURI().toURL()});
Lines 2569-2574 Link Here
2569
            assertFalse(mod2.owns(c1));
2577
            assertFalse(mod2.owns(c1));
2570
            assertFalse(mod2.owns(c2));
2578
            assertFalse(mod2.owns(c2));
2571
            assertTrue(mod2.owns(c3));
2579
            assertTrue(mod2.owns(c3));
2580
            assertEquals(mod1, ownership.forClass(c1));
2581
            assertEquals(mod1, ownership.forClass(c2));
2582
            assertEquals(mod2, ownership.forClass(c3));
2583
            assertNull(ownership.forClass(String.class));
2572
        } finally {
2584
        } finally {
2573
            mgr.mutexPrivileged().exitWriteAccess();
2585
            mgr.mutexPrivileged().exitWriteAccess();
2574
        }
2586
        }
(-)a/o.n.core/src/org/netbeans/core/NbLoaderPool.java (-11 / +2 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 317-325 Link Here
317
        oos.writeObject (new HashMap()/*installBefores*/);
316
        oos.writeObject (new HashMap()/*installBefores*/);
318
        oos.writeObject (new HashMap()/*installAfters*/);
317
        oos.writeObject (new HashMap()/*installAfters*/);
319
        
318
        
320
        // Note which module each loader came from.
321
        Collection modules = Lookup.getDefault().lookupAll(ModuleInfo.class); // Collection<ModuleInfo>
322
323
        Iterator it = loaders.iterator ();
319
        Iterator it = loaders.iterator ();
324
320
325
        while (it.hasNext ()) {
321
        while (it.hasNext ()) {
Lines 345-356 Link Here
345
            if (obj != null) {
341
            if (obj != null) {
346
                if (err.isLoggable(Level.FINE)) err.fine("writing modified " + l.getClass().getName());
342
                if (err.isLoggable(Level.FINE)) err.fine("writing modified " + l.getClass().getName());
347
                // Find its module, if any.
343
                // Find its module, if any.
348
                Class c = l.getClass();
349
                Iterator mit = modules.iterator();
350
                boolean found = false;
344
                boolean found = false;
351
                while (mit.hasNext()) {
345
                ModuleInfo m = ModuleInfo.forClass(l.getClass());
352
                    ModuleInfo m = (ModuleInfo)mit.next();
346
                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());
347
                        if (err.isLoggable(Level.FINE)) err.fine("belongs to module: " + m.getCodeNameBase());
355
                        oos.writeObject(m.getCodeNameBase());
348
                        oos.writeObject(m.getCodeNameBase());
356
                        int r = m.getCodeNameRelease();
349
                        int r = m.getCodeNameRelease();
Lines 362-369 Link Here
362
                            oos.writeObject(null);
355
                            oos.writeObject(null);
363
                        }
356
                        }
364
                        found = true;
357
                        found = true;
365
                        break;
366
                    }
367
                }
358
                }
368
                if (!found) {
359
                if (!found) {
369
                    if (err.isLoggable(Level.FINE)) err.fine("does not belong to any module");
360
                    if (err.isLoggable(Level.FINE)) err.fine("does not belong to any module");
(-)a/openide.loaders/src/org/openide/loaders/DataLoaderPool.java (-11 / +4 lines)
Lines 568-585 Link Here
568
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER, null);
568
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER, null);
569
        } else {
569
        } else {
570
            Class c = loader.getClass();
570
            Class c = loader.getClass();
571
            // [PENDING] in the future a more efficient API may be introduced
571
            fo.setAttribute (DataObject.EA_ASSIGNED_LOADER, c.getName ());
572
            Iterator modules = Lookup.getDefault().lookupAll(ModuleInfo.class).iterator();
572
            ModuleInfo module = ModuleInfo.forClass(c);
573
            String modulename = null;
573
            if (module != null) {
574
            while (modules.hasNext()) {
574
                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
            }
575
            }
581
            fo.setAttribute (DataObject.EA_ASSIGNED_LOADER, c.getName ());
582
            fo.setAttribute(DataObject.EA_ASSIGNED_LOADER_MODULE, modulename);
583
        }
576
        }
584
        if (!DataObjectPool.getPOOL().revalidate(Collections.singleton(fo)).isEmpty()) {
577
        if (!DataObjectPool.getPOOL().revalidate(Collections.singleton(fo)).isEmpty()) {
585
            DataObject.LOG.fine("It was not possible to invalidate data object: " + fo); // NOI18N
578
            DataObject.LOG.fine("It was not possible to invalidate data object: " + fo); // NOI18N
(-)a/openide.modules/src/org/openide/modules/ModuleInfo.java (-7 / +43 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
49
import org.openide.util.Lookup;
50
// INTERACTIONS SHOULD GO ELSEWHERE.
51
import java.util.*;
52
53
50
54
/** General information about a module.
51
/** General information about a module.
55
 * Immutable from an API perspective, serves as
52
 * Immutable from an API perspective, serves as
Lines 162-170 Link Here
162
     * was loaded as a part of this module, and thus will only be
159
     * was loaded as a part of this module, and thus will only be
163
     * loadable later if this module is enabled.
160
     * loadable later if this module is enabled.
164
     * If in doubt, return <code>false</code>.
161
     * If in doubt, return <code>false</code>.
162
     * @see #forClass
165
     * @since 1.28
163
     * @since 1.28
166
     */
164
     */
167
    public abstract boolean owns(Class<?> clazz);
165
    public abstract boolean owns(Class<?> clazz);
166
    
167
    /**
168
     * Finds the module which loaded a class.
169
     * @param clazz a class
170
     * @return the owner of the class, or null if it is not owned by any module
171
     * @see #owns
172
     * @since XXX
173
     */
174
    public static ModuleInfo forClass(Class<?> clazz) {
175
        OwnershipProvider prov = Lookup.getDefault().lookup(OwnershipProvider.class);
176
        if (prov != null) {
177
            return prov.forClass(clazz);
178
        } else {
179
            for (ModuleInfo module : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
180
                if (module.owns(clazz)) {
181
                    return module;
182
                }
183
            }
184
            return null;
185
        }
186
    }
168
187
169
    /**
188
    /**
170
     * Get a class loader associated with this module that can load
189
     * Get a class loader associated with this module that can load
Lines 197-200 Link Here
197
    public String[] getProvides() {
216
    public String[] getProvides() {
198
        return new String[] {  };
217
        return new String[] {  };
199
    }
218
    }
219
    
220
    /**
221
     * Service implemented by module system to quickly look up the owner of a class.
222
     * @see ModuleInfo#forClass
223
     * @since XXX
224
     */
225
    public interface OwnershipProvider {
226
    
227
        /**
228
         * Finds the module which loaded a class.
229
         * @param clazz a class
230
         * @return the owner of the class, or null if it is not owned by any module
231
         */
232
        ModuleInfo forClass(Class<?> clazz);
233
        
234
    }
235
    
200
}
236
}
(-)a/refactoring.api/src/org/netbeans/modules/refactoring/api/AbstractRefactoring.java (-7 / +3 lines)
Lines 373-385 Link Here
373
        }
373
        }
374
    }
374
    }
375
    
375
    
376
    private String getModuleName(Class c) {
376
    private String getModuleName(Class<?> c) {
377
        for (ModuleInfo info:Lookup.getDefault().lookupAll(ModuleInfo.class)) {
377
        ModuleInfo info = ModuleInfo.forClass(c);
378
            if (info.owns(c)) {
378
        return info != null ? info.getDisplayName() : "Unknown"; //NOI18N
379
                return info.getDisplayName();
380
            }
381
        }
382
        return "Unknown";//NOI18N
383
    }
379
    }
384
    
380
    
385
    private String createMessage(Class c, Throwable t) {
381
    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 / +1 lines)
Lines 135-141 Link Here
135
     * @exception IOException if the object cannot be written
135
     * @exception IOException if the object cannot be written
136
     */
136
     */
137
    public void write(Writer w, Object inst) throws IOException {
137
    public void write(Writer w, Object inst) throws IOException {
138
        XMLSettingsSupport.storeToXML10(inst, w, ModuleInfoManager.getDefault().getModuleInfo(inst.getClass()));
138
        XMLSettingsSupport.storeToXML10(inst, w, ModuleInfo.forClass(inst.getClass()));
139
    }
139
    }
140
    
140
    
141
    /** delegate to SaveSupport to handle an unfired setting object change
141
    /** delegate to SaveSupport to handle an unfired setting object change
(-)a/settings/src/org/netbeans/modules/settings/convertors/XMLSettingsSupport.java (-1 / +1 lines)
Lines 1167-1173 Link Here
1167
        }
1167
        }
1168
        
1168
        
1169
        public void write(java.io.Writer w, Object inst) throws java.io.IOException {
1169
        public void write(java.io.Writer w, Object inst) throws java.io.IOException {
1170
            XMLSettingsSupport.storeToXML10(inst, w, ModuleInfoManager.getDefault().getModuleInfo(inst.getClass()));
1170
            XMLSettingsSupport.storeToXML10(inst, w, ModuleInfo.forClass(inst.getClass()));
1171
        }
1171
        }
1172
        
1172
        
1173
    }
1173
    }

Return to bug 157828