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

(-)/dev/null (+1 lines)
Added Link Here
1
org.netbeans.NbEvents
(-)/dev/null (+1 lines)
Added Link Here
1
org.netbeans.MainLookup
(-)o.n.bootstrap/src/org/netbeans/Bundle.properties:1.5 (+31 lines)
Lines 29-31 Link Here
29
        This module provides the initial infrastructure \
29
        This module provides the initial infrastructure \
30
        that loads all other parts of the application. \
30
        that loads all other parts of the application. \
31
        It cannot be disabled.
31
        It cannot be disabled.
32
33
34
35
MSG_restore=Starting modules...
36
# #13806: might have been installed before and uninstalled.
37
# {0} - module display name
38
MSG_install=Installing {0}
39
# {0} - module display name
40
TEXT_install=Installing new module: {0}
41
# {0} - module display name
42
MSG_update=Starting a new version of {0}
43
# {0} - module display name
44
TEXT_update=Updating module: {0}
45
# {0} - module display name
46
MSG_uninstall=Stopping {0}
47
MSG_load_section=Loading modules...
48
MSG_load_layers=Loading installed objects of modules...
49
# {0} - path to expected module JAR
50
TEXT_missing_jar_file=Warning: the module {0} could not be found, ignoring...
51
# {0} - module display name
52
TEXT_cant_delete_enabled_autoload=The module {0} could not be deleted as it was an autoload or eager module and still in use.
53
# {0} - module display name
54
# {1} - property name in XML
55
# {2} - value on disk in XML
56
# {3} - actual value
57
TEXT_misc_prop_mismatch=\
58
    An attempt was made to change the property {1} of the module {0} in the system/Modules folder.\n\
59
    The actual value is "{3}" but it was changed on disk to read "{2}".\n\
60
    This property cannot be changed while the IDE is running, so this attempt had no effect.
61
# {0} - JAR file name
62
TEXT_patch=Module patch or custom extension: {0}
(-)o.n.bootstrap/src/org/netbeans/CLIHandler.java:1.28 (-8 / +8 lines)
Lines 94-100 Link Here
94
     */
94
     */
95
    protected abstract int cli(Args args);
95
    protected abstract int cli(Args args);
96
    
96
    
97
    private static void showHelp(PrintWriter w, List handlers) {
97
    private static void showHelp(PrintWriter w, java.util.Collection handlers) {
98
//        w.println("  -? or --help          Show this help information.");
98
//        w.println("  -? or --help          Show this help information.");
99
        Iterator it = handlers.iterator();
99
        Iterator it = handlers.iterator();
100
        while (it.hasNext()) {
100
        while (it.hasNext()) {
Lines 151-157 Link Here
151
    /** Notification of available handlers.
151
    /** Notification of available handlers.
152
     * @return non-zero if one of the handlers fails
152
     * @return non-zero if one of the handlers fails
153
     */
153
     */
154
    private static int notifyHandlers(Args args, List handlers, int when, boolean failOnUnknownOptions, boolean consume) {
154
    private static int notifyHandlers(Args args, java.util.Collection handlers, int when, boolean failOnUnknownOptions, boolean consume) {
155
        try {
155
        try {
156
            //System.err.println("notifyHandlers: handlers=" + handlers + " when=" + when + " args=" + Arrays.asList(args.getArguments()));
156
            //System.err.println("notifyHandlers: handlers=" + handlers + " when=" + when + " args=" + Arrays.asList(args.getArguments()));
157
            String[] argv = args.getArguments();
157
            String[] argv = args.getArguments();
Lines 273-279 Link Here
273
        String[] args, 
273
        String[] args, 
274
        InputStream is, 
274
        InputStream is, 
275
        OutputStream os, 
275
        OutputStream os, 
276
        Main.BootClassLoader loader,
276
        ClassLoader loader,
277
        boolean failOnUnknownOptions, 
277
        boolean failOnUnknownOptions, 
278
        boolean cleanLockFile,
278
        boolean cleanLockFile,
279
        Runnable runWhenHome
279
        Runnable runWhenHome
Lines 281-287 Link Here
281
        return initialize(
281
        return initialize(
282
            new Args(args, is, os, System.getProperty ("user.dir")), 
282
            new Args(args, is, os, System.getProperty ("user.dir")), 
283
            (Integer)null, 
283
            (Integer)null, 
284
            loader.allCLIs(), 
284
            org.openide.util.lookup.Lookups.metaInfServices(loader).lookup(new org.openide.util.Lookup.Template(CLIHandler.class)).allInstances(),
285
            failOnUnknownOptions, 
285
            failOnUnknownOptions, 
286
            cleanLockFile, 
286
            cleanLockFile, 
287
            runWhenHome
287
            runWhenHome
Lines 402-408 Link Here
402
     */
402
     */
403
    static Status initialize(
403
    static Status initialize(
404
        final Args args, Integer block, 
404
        final Args args, Integer block, 
405
        final List handlers, 
405
        final java.util.Collection handlers, 
406
        final boolean failOnUnknownOptions, 
406
        final boolean failOnUnknownOptions, 
407
        boolean cleanLockFile,
407
        boolean cleanLockFile,
408
        Runnable runWhenHome
408
        Runnable runWhenHome
Lines 777-788 Link Here
777
        private byte[] key;
777
        private byte[] key;
778
        private ServerSocket socket;
778
        private ServerSocket socket;
779
        private Integer block;
779
        private Integer block;
780
        private List handlers;
780
        private java.util.Collection handlers;
781
        private Socket work;
781
        private Socket work;
782
        private static volatile int counter;
782
        private static volatile int counter;
783
        private final boolean failOnUnknownOptions;
783
        private final boolean failOnUnknownOptions;
784
        
784
        
785
        public Server(byte[] key, Integer block, List handlers, boolean failOnUnknownOptions) throws IOException {
785
        public Server(byte[] key, Integer block, java.util.Collection handlers, boolean failOnUnknownOptions) throws IOException {
786
            super("CLI Requests Server"); // NOI18N
786
            super("CLI Requests Server"); // NOI18N
787
            this.key = key;
787
            this.key = key;
788
            this.setDaemon(true);
788
            this.setDaemon(true);
Lines 794-800 Link Here
794
            start();
794
            start();
795
        }
795
        }
796
        
796
        
797
        public Server(Socket request, byte[] key, Integer block, List handlers, boolean failOnUnknownOptions) throws IOException {
797
        public Server(Socket request, byte[] key, Integer block, java.util.Collection handlers, boolean failOnUnknownOptions) throws IOException {
798
            super("CLI Handler Thread Handler: " + ++counter); // NOI18N
798
            super("CLI Handler Thread Handler: " + ++counter); // NOI18N
799
            this.key = key;
799
            this.key = key;
800
            this.setDaemon(true);
800
            this.setDaemon(true);
(-)o.n.bootstrap/src/org/netbeans/Main.java:1.30 (-25 / +48 lines)
Lines 89-95 Link Here
89
        HashSet processedDirs = new HashSet ();
89
        HashSet processedDirs = new HashSet ();
90
        String home = System.getProperty ("netbeans.home"); // NOI18N
90
        String home = System.getProperty ("netbeans.home"); // NOI18N
91
        if (home != null) {
91
        if (home != null) {
92
            build_cp (new File (home), list, processedDirs);
92
            scanForModules (new File (home), list, processedDirs);
93
        }
93
        }
94
        // #34069: need to do the same for nbdirs.
94
        // #34069: need to do the same for nbdirs.
95
        String nbdirs = System.getProperty("netbeans.dirs"); // NOI18N
95
        String nbdirs = System.getProperty("netbeans.dirs"); // NOI18N
Lines 97-103 Link Here
97
            StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator);
97
            StringTokenizer tok = new StringTokenizer(nbdirs, File.pathSeparator);
98
            while (tok.hasMoreTokens()) {
98
            while (tok.hasMoreTokens()) {
99
                // passing false as last argument as we need to initialize openfile-cli.jar
99
                // passing false as last argument as we need to initialize openfile-cli.jar
100
                build_cp(new File(tok.nextToken()), list, processedDirs);
100
                scanForModules(new File(tok.nextToken()), list, processedDirs);
101
            }
101
            }
102
        }
102
        }
103
        
103
        
Lines 119-128 Link Here
119
            if (buf.length() > 0) {
119
            if (buf.length() > 0) {
120
                buf.append(File.pathSeparatorChar);
120
                buf.append(File.pathSeparatorChar);
121
            }
121
            }
122
            buf.append(((File)it.next()).getAbsolutePath());
122
            Module m = (Module)it.next();
123
            Iterator all = m.getAllJars().iterator();
124
            while (all.hasNext()) {
125
                File jar = (File)all.next();
126
                buf.append(jar.getAbsolutePath());
127
            }
123
        }
128
        }
124
        System.setProperty("netbeans.dynamic.classpath", buf.toString());
129
        System.setProperty("netbeans.dynamic.classpath", buf.toString());
125
        
130
        
131
        /*
126
        // JarClassLoader treats a File as a dir; for a ZIP/JAR, needs JarFile
132
        // JarClassLoader treats a File as a dir; for a ZIP/JAR, needs JarFile
127
        ListIterator it2 = list.listIterator();
133
        ListIterator it2 = list.listIterator();
128
        while (it2.hasNext()) {
134
        while (it2.hasNext()) {
Lines 131-146 Link Here
131
                it2.set(new JarFile (f, false));
137
                it2.set(new JarFile (f, false));
132
            }
138
            }
133
        }
139
        }
134
        
140
         */
141
        /*
135
        BootClassLoader loader = new BootClassLoader(list, new ClassLoader[] {
142
        BootClassLoader loader = new BootClassLoader(list, new ClassLoader[] {
136
            Main.class.getClassLoader()
143
            Main.class.getClassLoader()
137
        });
144
        });
145
         */
146
        ModuleManager.getDefault().loadBootModules();
147
        ModuleManager.getDefault().enable(new HashSet(list));
148
        
149
        MainLookup.systemClassLoaderChanged(ModuleManager.getDefault().getClassLoader());
150
        Object installer = org.openide.util.Lookup.getDefault().lookup(ModuleInstaller.class);
151
        assert installer != null : "Real installer registered"; // NOI18N
152
        Object real = ModuleManager.getDefault().getInstaller(true);
153
        assert installer == real : "The installer has been updated"; // NOI18N
138
        
154
        
139
        String className = System.getProperty(
155
        String className = System.getProperty(
140
            "netbeans.mainclass", "org.netbeans.core.startup.Main" // NOI18N
156
            "netbeans.mainclass", "org.netbeans.core.startup.Main" // NOI18N
141
        );
157
        );
158
        ClassLoader loader = ModuleManager.getDefault().getClassLoader();
159
142
        
160
        
143
	Class c = loader.loadClass(className);
161
        Class c = loader.loadClass(className);
144
        Method m = c.getMethod ("main", new Class[] { String[].class }); // NOI18N
162
        Method m = c.getMethod ("main", new Class[] { String[].class }); // NOI18N
145
        
163
        
146
        // Needed for Lookup.getDefault to find NbTopManager.Lkp.
164
        // Needed for Lookup.getDefault to find NbTopManager.Lkp.
Lines 154-160 Link Here
154
        //
172
        //
155
        
173
        
156
        CLIHandler.Status result;
174
        CLIHandler.Status result;
157
        result = CLIHandler.initialize(args, reader, writer, loader, true, false, loader);
175
        result = CLIHandler.initialize(args, reader, writer, loader, true, false, null);
158
        if (result.getExitCode () == CLIHandler.Status.CANNOT_CONNECT) {
176
        if (result.getExitCode () == CLIHandler.Status.CANNOT_CONNECT) {
159
            int value = javax.swing.JOptionPane.showConfirmDialog (
177
            int value = javax.swing.JOptionPane.showConfirmDialog (
160
                null, 
178
                null, 
Lines 164-170 Link Here
164
                javax.swing.JOptionPane.WARNING_MESSAGE
182
                javax.swing.JOptionPane.WARNING_MESSAGE
165
            );
183
            );
166
            if (value == javax.swing.JOptionPane.OK_OPTION) {
184
            if (value == javax.swing.JOptionPane.OK_OPTION) {
167
                result = CLIHandler.initialize(args, reader, writer, loader, true, true, loader);
185
                result = CLIHandler.initialize(args, reader, writer, loader, true, true, null);
168
            }
186
            }
169
            
187
            
170
        }
188
        }
Lines 246-252 Link Here
246
            String user = System.getProperty ("netbeans.user"); // NOI18N
264
            String user = System.getProperty ("netbeans.user"); // NOI18N
247
            try {
265
            try {
248
                if (user != null) {
266
                if (user != null) {
249
                    build_cp (new File (user), toAdd, new HashSet ());
267
                    scanForModules (new File (user), toAdd, new HashSet ());
250
                    // JarClassLoader treats a File as a dir; for a ZIP/JAR, needs JarFile
268
                    // JarClassLoader treats a File as a dir; for a ZIP/JAR, needs JarFile
251
                    ListIterator it2 = toAdd.listIterator();
269
                    ListIterator it2 = toAdd.listIterator();
252
                    while (it2.hasNext()) {
270
                    while (it2.hasNext()) {
Lines 263-268 Link Here
263
                    allCLIs ();
281
                    allCLIs ();
264
                }
282
                }
265
                allCLIclasses = Collections.EMPTY_SET;
283
                allCLIclasses = Collections.EMPTY_SET;
284
            } catch (DuplicateException ex) {
285
                ex.printStackTrace();
266
            } catch (IOException ex) {
286
            } catch (IOException ex) {
267
                ex.printStackTrace();
287
                ex.printStackTrace();
268
            }
288
            }
Lines 376-403 Link Here
376
    }
396
    }
377
        
397
        
378
    
398
    
379
    private static void build_cp(File base, Collection toAdd, Set processedDirs) 
399
    private static void scanForModules(File base, Collection toAdd, Set processedDirs) 
380
    throws java.io.IOException {
400
    throws java.io.IOException, DuplicateException {
381
        base = base.getCanonicalFile ();
401
        base = base.getCanonicalFile ();
382
        if (!processedDirs.add (base)) {
402
        if (!processedDirs.add (base)) {
383
            // already processed
403
            // already processed
384
            return;
404
            return;
385
        }
405
        }
406
407
        File dir = new File(base, "core");
408
        if (!dir.isDirectory()) return;
386
        
409
        
387
        append_jars_to_cp(new File(base, "core/patches"), toAdd); // NOI18N
410
        File[] arr = dir.listFiles();
388
        append_jars_to_cp(new File(base, "core"), toAdd); // NOI18N
411
        for (int i = 0; i < arr.length; i++) {
389
        // XXX a minor optimization: exclude any unused locale JARs
412
            String n = arr[i].getName ();
390
        // For example, lib/locale/ might contain:
413
            /*
391
        // core_ja.jar
414
            if (n.equals("updater.jar") || // NOI18N
392
        // core_f4j.jar
415
                (dir.getName().equals("locale") && n.startsWith("updater_") && n.endsWith(".jar"))) { // NOI18N
393
        // core_f4j_ja.jar
416
                // Used by launcher, not by us.
394
        // core_f4j_ce.jar
417
                continue;
395
        // core_f4j_ce_ja.jar
418
            }
396
        // core_ru.jar
419
            */
397
        // core_fr.jar
420
            if (n.endsWith("jar") || n.endsWith ("zip")) { // NOI18N
398
        // [etc.]
421
                Module m = ModuleManager.getDefault().create(arr[i], null, false, false, false, true);
399
        // Only some of these will apply to the current session, based on the
422
                toAdd.add (m);
400
        // current values of Locale.default and NbBundle.branding.
423
            }
401
        append_jars_to_cp(new File(base, "core/locale"), toAdd); // NOI18N
424
        }
402
    }
425
    }
403
}
426
}
(-)/dev/null (+177 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans;
15
16
import org.openide.util.Lookup;
17
import org.openide.util.lookup.*;
18
import org.openide.modules.*;
19
20
21
/** The default lookup for the system.
22
 */
23
public final class MainLookup extends ProxyLookup {
24
    private static boolean started = false;
25
    /** currently effective ClassLoader */
26
    private static ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
27
    /** inner access to dynamic lookup service for this top mangager */
28
    private static InstanceContent instanceContent = new InstanceContent ();
29
    /** dynamic lookup service for this top mangager */
30
    private static Lookup instanceLookup = new AbstractLookup (instanceContent);
31
32
    /** Someone called NbTopManager.get().
33
     * That means that subsequent calls to lookup on ModuleInfo
34
     * need not try to get it again.
35
     */
36
    public static void startedNbTopManager() {
37
        started = true;
38
    }
39
40
    /** Initialize the lookup to delegate to NbTopManager.
41
    */
42
    public MainLookup () {
43
        super (new Lookup[] {
44
                   // #14722: pay attention also to META-INF/services/class.Name resources:
45
                   Lookups.metaInfServices(classLoader),
46
                   Lookups.singleton(classLoader),
47
                   Lookup.EMPTY, // will be moduleLookup
48
               });
49
    }
50
51
    /** Called when a system classloader changes.
52
     */
53
    public static final void systemClassLoaderChanged (ClassLoader nue) {
54
        if (classLoader != nue) {
55
            classLoader = nue;
56
            MainLookup l = (MainLookup)Lookup.getDefault();
57
            Lookup[] delegates = l.getLookups();
58
            Lookup[] newDelegates = (Lookup[])delegates.clone();
59
            // Replace classloader.
60
            newDelegates[0] = Lookups.metaInfServices(classLoader);
61
            newDelegates[1] = Lookups.singleton(classLoader);
62
            l.setLookups(newDelegates);
63
        } else {
64
            moduleClassLoadersUp();
65
        }
66
    }
67
68
    /** Called when modules are about to be turned on.
69
     */
70
    public static final void moduleClassLoadersUp() {
71
        MainLookup l = (MainLookup)Lookup.getDefault();
72
        Lookup[] newDelegates = null;
73
        Lookup[] delegates = l.getLookups();
74
        newDelegates = (Lookup[])delegates.clone();
75
        newDelegates[0] = Lookups.metaInfServices(classLoader);
76
        l.setLookups(newDelegates);
77
    }
78
79
    /** Called when Lookup<ModuleInfo> is ready from the ModuleManager.
80
     * @see "#28465"
81
     */
82
    public static final void moduleLookupReady(Lookup moduleLookup) {
83
        MainLookup l = (MainLookup)Lookup.getDefault();
84
        Lookup[] newDelegates = (Lookup[])l.getLookups().clone();
85
        newDelegates[2] = moduleLookup;
86
        l.setLookups(newDelegates);
87
    }
88
89
    /** When all module classes are accessible thru systemClassLoader, this
90
     * method is called to initialize the FolderLookup.
91
     */
92
93
    public static final void modulesClassPathInitialized () {
94
        //System.err.println("mCPI");
95
    //StartLog.logStart ("NbTopManager$MainLookup: initialization of FolderLookup"); // NOI18N
96
97
        // replace the lookup by new one
98
        Lookup lookup = Lookup.getDefault ();
99
        ((MainLookup)lookup).doInitializeLookup ();
100
    }
101
102
    //
103
    // 
104
    //
105
    
106
    /** Register new instance.
107
     */
108
    public static void register (Object obj) {
109
        instanceContent.add (obj);
110
    }
111
    
112
    /** Register new instance.
113
     * @param obj source
114
     * @param conv convertor which postponing an instantiation
115
     */
116
    public static void register(Object obj, InstanceContent.Convertor conv) {
117
        instanceContent.add(obj, conv);
118
    }
119
    
120
    /** Unregisters the service.
121
     */
122
    public static void unregister (Object obj) {
123
        instanceContent.remove (obj);
124
    }
125
    /** Unregisters the service registered with a convertor.
126
     */
127
    public static void unregister (Object obj, InstanceContent.Convertor conv) {
128
        instanceContent.remove (obj, conv);
129
    }
130
    
131
    
132
    
133
    
134
135
    private final void doInitializeLookup () {
136
        //System.err.println("doInitializeLookup");
137
138
        // extend the lookup
139
        Lookup[] arr = new Lookup[] {
140
            getLookups()[0], // metaInfServicesLookup
141
            getLookups()[1], // ClassLoader lookup
142
            getLookups()[2], // ModuleInfo lookup
143
            // XXX figure out how to put this ahead of MetaInfServicesLookup (for NonGuiMain):
144
            instanceLookup, 
145
        /* JST-PENDING: another removal
146
            CoreBridge.conditionallyLookupCacheLoad (),
147
         */
148
        };
149
150
        setLookups (arr);
151
152
    //StartLog.logEnd ("NbTopManager$MainLookup: initialization of FolderLookup"); // NOI18N
153
    }
154
155
    public void storeCache() throws java.io.IOException {
156
        /* JST-PENDING: another removal
157
        Lookup[] ls = getLookups();
158
        if (ls.length == 5) {
159
            // modulesClassPathInitialized has been called, so store folder lookup
160
            CoreBridge.getDefault ().lookupCacheStore (ls[4]);
161
        }
162
         */
163
    }
164
165
    protected void beforeLookup(Lookup.Template templ) {
166
        Class type = templ.getType();
167
168
        // Force module system to be initialize by looking up ModuleInfo.
169
        // Good for unit tests, etc.
170
        if (!started && (type == ModuleInfo.class || type == org.netbeans.Module.class)) {
171
            ModuleManager.getDefault();
172
        }
173
174
        super.beforeLookup(templ);
175
    }
176
}
177
    
(-)o.n.bootstrap/src/org/netbeans/Module.java:1.7 (+1 lines)
Lines 66-71 Link Here
66
    private boolean enabled;
66
    private boolean enabled;
67
    /** whether it is supposed to be automatically loaded when required */
67
    /** whether it is supposed to be automatically loaded when required */
68
    private final boolean autoload;
68
    private final boolean autoload;
69
    boolean fixed;
69
    /** */
70
    /** */
70
    protected boolean reloadable;
71
    protected boolean reloadable;
71
    /** if true, this module is eagerly turned on whenever it can be */
72
    /** if true, this module is eagerly turned on whenever it can be */
(-)o.n.bootstrap/src/org/netbeans/ModuleManager.java:1.7 (-47 / +232 lines)
Lines 17-33 Link Here
17
import java.beans.*;
17
import java.beans.*;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.io.File;
19
import java.io.File;
20
import java.io.InputStream;
20
import java.net.MalformedURLException;
21
import java.net.MalformedURLException;
21
import java.net.URL;
22
import java.net.URL;
22
import org.openide.util.*;
23
import org.openide.util.*;
23
import org.openide.modules.ModuleInfo;
24
import org.openide.modules.ModuleInfo;
24
import java.security.*;
25
import java.security.*;
26
import java.util.jar.Attributes;
25
import java.util.jar.JarFile;
27
import java.util.jar.JarFile;
26
import java.util.jar.Manifest;
28
import java.util.jar.Manifest;
27
import org.openide.modules.SpecificationVersion;
29
import org.openide.modules.SpecificationVersion;
28
import org.openide.modules.Dependency;
30
import org.openide.modules.Dependency;
29
import org.openide.ErrorManager;
31
import org.openide.ErrorManager;
30
import org.netbeans.JarClassLoader;
32
31
33
32
/** Manages a collection of modules.
34
/** Manages a collection of modules.
33
 * Must use {@link #mutex} to access its important methods.
35
 * Must use {@link #mutex} to access its important methods.
Lines 55-76 Link Here
55
    // modules providing a given requires token; set may never be empty
57
    // modules providing a given requires token; set may never be empty
56
    private final Map providersOf = new HashMap(25); // Map<String,Set<Module>>
58
    private final Map providersOf = new HashMap(25); // Map<String,Set<Module>>
57
    
59
    
58
    private final ModuleInstaller installer;
60
    private ModuleInstaller installer;
59
    private ModuleFactory moduleFactory;
61
    private ModuleFactory moduleFactory;
60
    
62
    
61
    private SystemClassLoader classLoader;
63
    private SystemClassLoader classLoader;
62
    private List classLoaderPatches; // List<File|JarFile>
64
    private List classLoaderPatches; // List<File|JarFile>
63
    private final Object classLoaderLock = new String("ModuleManager.classLoaderLock"); // NOI18N
65
    private final Object classLoaderLock = new String("ModuleManager.classLoaderLock"); // NOI18N
64
    
66
    
65
    private final Events ev;
67
    private Events ev;
68
    
69
    private static ModuleManager DEFAULT;
66
    
70
    
67
    /** Create a manager, initially with no managed modules.
71
    /** Create a manager, initially with no managed modules.
68
     * The handler for installing modules is given.
72
     * The handler for installing modules is given.
69
     * Also the sink for event messages must be given.
73
     * Also the sink for event messages must be given.
70
     */
74
     */
71
    public ModuleManager(ModuleInstaller installer, Events ev) {
75
    private ModuleManager() {
72
        this.installer = installer;
76
        this (null, null);
73
        this.ev = ev;
77
    }
78
    
79
    public ModuleManager(ModuleInstaller i, Events e) {
80
        if (i == null) {
81
            i = new EmptyInstaller();
82
        }
83
        this.installer = i;
84
        this.ev = e;
85
        
74
        String patches = System.getProperty("netbeans.systemclassloader.patches");
86
        String patches = System.getProperty("netbeans.systemclassloader.patches");
75
        if (patches != null) {
87
        if (patches != null) {
76
            // Probably temporary helper for XTest. By setting this system property
88
            // Probably temporary helper for XTest. By setting this system property
Lines 96-102 Link Here
96
            // Normal case.
108
            // Normal case.
97
            classLoaderPatches = Collections.EMPTY_LIST;
109
            classLoaderPatches = Collections.EMPTY_LIST;
98
        }
110
        }
99
        classLoader = new SystemClassLoader(classLoaderPatches, new ClassLoader[] {installer.getClass ().getClassLoader()}, Collections.EMPTY_SET);
111
        classLoader = new SystemClassLoader(classLoaderPatches, new ClassLoader[] {ModuleManager.class.getClassLoader()}, Collections.EMPTY_SET);
100
        updateContextClassLoaders(classLoader, true);
112
        updateContextClassLoaders(classLoader, true);
101
        
113
        
102
        moduleFactory = (ModuleFactory)Lookup.getDefault().lookup(ModuleFactory.class);
114
        moduleFactory = (ModuleFactory)Lookup.getDefault().lookup(ModuleFactory.class);
Lines 105-117 Link Here
105
        }
117
        }
106
    }
118
    }
107
    
119
    
108
    /** Access for ManifestSection. 
120
    /** Getter for the default implementation of module manager.
109
     * @since JST-PENDING needed by ManifestSection
121
     * @return module manager
110
     */
122
     * @since JST-PENDING more standalone rewrite 
111
    public final Events getEvents() {
123
     */
112
        return ev;
124
    public static synchronized ModuleManager getDefault() {
125
        if (DEFAULT == null) {
126
             DEFAULT = new ModuleManager();
127
        }
128
        return DEFAULT;
129
    }
130
    
131
    /** Load modules found in the classpath.
132
     * Note that they might not satisfy all their dependencies, in which
133
     * case oh well...
134
     */
135
    final void loadBootModules() {	
136
        // Keep a list of manifest URL prefixes which we know we do not need to
137
        // parse. Some of these manifests might be signed, and if so, we do not
138
        // want to touch them, as it slows down startup quite a bit.
139
        Collection ignoredPrefixes = new ArrayList(3); // List<String>
140
        try {
141
            // skip the JDK/JRE libraries
142
            String jdk = System.getProperty("java.home");
143
            if (jdk.endsWith(File.separator + "jre")) { // NOI18N
144
                jdk = jdk.substring(0, jdk.length() - 4);
145
            }
146
            File f = new File(jdk);
147
            ignoredPrefixes.add("jar:" + f.toURI().toURL()); // NOI18N
148
            // skip $nbhome/lib/ext/*.jar; all fixes modules should be in
149
            // $nbhome/lib/ (or perhaps elsewhere, with -cp:a)
150
            String nbhomeS = System.getProperty("netbeans.home");
151
            if (nbhomeS != null) {
152
                File nbhome = new File(nbhomeS);
153
                f = new File(new File(nbhome, "lib"), "ext"); // NOI18N
154
                ignoredPrefixes.add("jar:" + f.toURI().toURL()); // NOI18N
155
            }
156
        } catch (MalformedURLException e) {
157
            Util.err.notify(ErrorManager.INFORMATIONAL, e);
158
        }
159
        if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) {
160
            Util.err.log("ignoredPrefixes=" + ignoredPrefixes);
161
        }
162
        
163
        mutexPrivileged().enterWriteAccess();
164
        ev.log(Events.START_LOAD_BOOT_MODULES);
165
        try {
166
            HashSet bootModules = new HashSet(10);
167
            ClassLoader loader = getClass().getClassLoader();
168
            Enumeration e = loader.getResources("META-INF/MANIFEST.MF"); // NOI18N
169
            ev.log(Events.PERF_TICK, "got all manifests"); // NOI18N
170
            
171
            // There will be duplicates: cf. #32576.
172
            Set checkedManifests = new HashSet(); // Set<URL>
173
            MANIFESTS:
174
            while (e.hasMoreElements()) {
175
                URL manifestUrl = (URL)e.nextElement();
176
                if (!checkedManifests.add(manifestUrl)) {
177
                    // Already seen, ignore.
178
                    continue;
179
                }
180
                String manifestUrlS = manifestUrl.toExternalForm();
181
                Iterator it = ignoredPrefixes.iterator();
182
                while (it.hasNext()) {
183
                    if (manifestUrlS.startsWith((String)it.next())) {
184
                        continue MANIFESTS;
185
                    }
186
                }
187
                if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) {
188
                    Util.err.log("Checking boot manifest: " + manifestUrlS);
189
                }
190
                
191
                InputStream is;
192
                try {
193
                    is = manifestUrl.openStream();
194
                } catch (IOException ioe) {
195
                    // Debugging for e.g. #32493 - which JAR was guilty?
196
                    Util.err.annotate(ioe, ErrorManager.UNKNOWN, "URL: " + manifestUrl, null, null, null); // NOI18N
197
                    throw ioe;
198
                }
199
                try {
200
                    Manifest mani = new Manifest(is);
201
                    Attributes attr = mani.getMainAttributes();
202
                    if (attr.getValue("OpenIDE-Module") == null) { // NOI18N
203
                        // Not a module.
204
                        continue;
205
                    }
206
                    bootModules.add(createFixed(mani, manifestUrl, loader));
207
                } finally {
208
                    is.close();
209
                }
210
            }
211
            //JST-PENDING: ? if (list == null) {
212
                // Plain calling us, we have to install now.
213
                // Do it the simple way.
214
                enable(bootModules);
215
            //}
216
            ev.log(Events.PERF_TICK, "added all classpath modules"); // NOI18N
217
	    
218
        } catch (IOException ioe) {
219
            // Note: includes also InvalidException's for malformed this and that.
220
            // Probably if a bootstrap module is corrupt we are in pretty bad shape
221
            // anyway, so don't bother trying to be fancy and install just some of
222
            // them etc.
223
            Util.err.notify(ioe);
224
        } catch (DuplicateException de) {
225
            Util.err.notify(de);
226
        } finally {
227
            // Not 100% accurate in this case:
228
            ev.log(Events.FINISH_LOAD_BOOT_MODULES);
229
            mutexPrivileged().exitWriteAccess();
230
        }
113
    }
231
    }
114
    
232
    
233
    
115
    private final Mutex.Privileged MUTEX_PRIVILEGED = new Mutex.Privileged();
234
    private final Mutex.Privileged MUTEX_PRIVILEGED = new Mutex.Privileged();
116
    private final Mutex MUTEX = new Mutex(MUTEX_PRIVILEGED);
235
    private final Mutex MUTEX = new Mutex(MUTEX_PRIVILEGED);
117
    /** Get a locking mutex for this module installer.
236
    /** Get a locking mutex for this module installer.
Lines 433-439 Link Here
433
        }
552
        }
434
        
553
        
435
        protected boolean isSpecialResource(String pkg) {
554
        protected boolean isSpecialResource(String pkg) {
436
            if (installer.isSpecialResource(pkg)) {
555
            if (getInstaller(false).isSpecialResource(pkg)) {
437
                return true;
556
                return true;
438
            }
557
            }
439
            return super.isSpecialResource(pkg);
558
            return super.isSpecialResource(pkg);
Lines 469-479 Link Here
469
     * You cannot request that a module be both autoload and eager.
588
     * You cannot request that a module be both autoload and eager.
470
     */
589
     */
471
    public Module create(File jar, Object history, boolean reloadable, boolean autoload, boolean eager) throws IOException, DuplicateException {
590
    public Module create(File jar, Object history, boolean reloadable, boolean autoload, boolean eager) throws IOException, DuplicateException {
591
        return create(jar, history, reloadable, autoload, eager, false);
592
    }
593
    
594
    /** Package private accessor to create modules that are on dynamic classpath.
595
     */
596
    final Module create(File jar, Object history, boolean reloadable, boolean autoload, boolean eager, boolean fixed) throws IOException, DuplicateException {
472
        assertWritable();
597
        assertWritable();
473
        ev.log(Events.START_CREATE_REGULAR_MODULE, jar);
598
        getEvents().log(Events.START_CREATE_REGULAR_MODULE, jar);
474
        Module m = moduleFactory.create(jar.getAbsoluteFile(), 
599
        Module m = moduleFactory.create(jar.getAbsoluteFile(), 
475
                        history, reloadable, autoload, eager, this, ev);
600
                        history, reloadable, autoload, eager, this, getEvents());
476
        ev.log(Events.FINISH_CREATE_REGULAR_MODULE, jar);
601
        
602
        m.fixed = fixed;
603
        getEvents().log(Events.FINISH_CREATE_REGULAR_MODULE, jar);
477
        subCreate(m);
604
        subCreate(m);
478
        if (m.isEager()) {
605
        if (m.isEager()) {
479
            List immediate = simulateEnable(Collections.EMPTY_SET);
606
            List immediate = simulateEnable(Collections.EMPTY_SET);
Lines 504-529 Link Here
504
    public Module createFixed(Manifest mani, Object history, ClassLoader loader) throws InvalidException, DuplicateException {
631
    public Module createFixed(Manifest mani, Object history, ClassLoader loader) throws InvalidException, DuplicateException {
505
        assertWritable();
632
        assertWritable();
506
        if (mani == null || loader == null) throw new IllegalArgumentException("null manifest or loader"); // NOI18N
633
        if (mani == null || loader == null) throw new IllegalArgumentException("null manifest or loader"); // NOI18N
507
        ev.log(Events.START_CREATE_BOOT_MODULE, history);
634
        getEvents().log(Events.START_CREATE_BOOT_MODULE, history);
508
        Module m = moduleFactory.createFixed(mani, history, loader, this, ev);
635
        Module m = moduleFactory.createFixed(mani, history, loader, this, getEvents());
509
        ev.log(Events.FINISH_CREATE_BOOT_MODULE, history);
636
        getEvents().log(Events.FINISH_CREATE_BOOT_MODULE, history);
510
        subCreate(m);
637
        subCreate(m);
511
        return m;
638
        return m;
512
    }
639
    }
513
    
640
    
514
    /** Used by Module to communicate with the ModuleInstaller re. dependencies. */
641
    /** Used by Module to communicate with the ModuleInstaller re. dependencies. */
515
    void refineDependencies(Module m, Set dependencies) {
642
    void refineDependencies(Module m, Set dependencies) {
516
        installer.refineDependencies(m, dependencies);
643
        getInstaller(false).refineDependencies(m, dependencies);
517
    }
644
    }
518
    /** Allows the installer to add provides (used to provide name of platform we run on)
645
    /** Allows the installer to add provides (used to provide name of platform we run on)
519
     */
646
     */
520
    String[] refineProvides (Module m) {
647
    String[] refineProvides (Module m) {
521
        return installer.refineProvides (m);
648
        String[] refineOrig = getInstaller(false).refineProvides(m);
649
    
650
        if (m.getCodeNameBase ().equals ("org.openide.modules")) { // NOI18N
651
            // module format is now 1
652
            ArrayList refine = new ArrayList();
653
            if (refineOrig != null) {
654
                refine.addAll (Arrays.asList (refineOrig));
655
            }
656
            refine.add ("org.openide.modules.ModuleFormat1"); // NOI18N
657
            return (String[])refine.toArray(new String[0]);
658
        } else {
659
            return refineOrig;
660
        }
522
    }
661
    }
523
    /** Used by Module to communicate with the ModuleInstaller re. classloader. */
662
    /** Used by Module to communicate with the ModuleInstaller re. classloader. */
524
    public void refineClassLoader(Module m, List parents) {
663
    public void refineClassLoader(Module m, List parents) {
525
        // #27853:
664
        // #27853:
526
        installer.refineClassLoader(m, parents);
665
        getInstaller(false).refineClassLoader(m, parents);
527
    }
666
    }
528
    /** Use by OneModuleClassLoader to communicate with the ModuleInstaller re. masking. */
667
    /** Use by OneModuleClassLoader to communicate with the ModuleInstaller re. masking. */
529
    public boolean shouldDelegateResource(Module m, Module parent, String pkg) {
668
    public boolean shouldDelegateResource(Module m, Module parent, String pkg) {
Lines 578-591 Link Here
578
            return false;
717
            return false;
579
        }
718
        }
580
        // The installer can perform additional checks:
719
        // The installer can perform additional checks:
581
        return installer.shouldDelegateResource(m, parent, pkg);
720
        return getInstaller(false).shouldDelegateResource(m, parent, pkg);
582
    }
721
    }
583
    public boolean isSpecialResource(String pkg) {
722
    public boolean isSpecialResource(String pkg) {
584
        return installer.isSpecialResource(pkg);
723
        return getInstaller(false).isSpecialResource(pkg);
585
    }
724
    }
586
    // Again, access from Module to ModuleInstaller:
725
    // Again, access from Module to ModuleInstaller:
587
    Manifest loadManifest(File jar) throws IOException {
726
    Manifest loadManifest(File jar) throws IOException {
588
        return installer.loadManifest(jar);
727
        return getInstaller(false).loadManifest(jar);
589
    }
728
    }
590
729
591
    private void subCreate(Module m) throws DuplicateException {
730
    private void subCreate(Module m) throws DuplicateException {
Lines 627-633 Link Here
627
        assertWritable();
766
        assertWritable();
628
        if (m.isFixed()) throw new IllegalArgumentException("fixed module: " + m); // NOI18N
767
        if (m.isFixed()) throw new IllegalArgumentException("fixed module: " + m); // NOI18N
629
        if (m.isEnabled()) throw new IllegalArgumentException("enabled module: " + m); // NOI18N
768
        if (m.isEnabled()) throw new IllegalArgumentException("enabled module: " + m); // NOI18N
630
        ev.log(Events.DELETE_MODULE, m);
769
        getEvents().log(Events.DELETE_MODULE, m);
631
        modules.remove(m);
770
        modules.remove(m);
632
        modulesByName.remove(m.getCodeNameBase());
771
        modulesByName.remove(m.getCodeNameBase());
633
        possibleProviderRemoved(m);
772
        possibleProviderRemoved(m);
Lines 731-740 Link Here
731
            return;
870
            return;
732
        }
871
        }
733
         */
872
         */
734
        ev.log(Events.PERF_START, "ModuleManager.enable"); // NOI18N
873
        getEvents().log(Events.PERF_START, "ModuleManager.enable"); // NOI18N
735
        // Basic problems will be caught here, and we also get the autoloads:
874
        // Basic problems will be caught here, and we also get the autoloads:
736
        List toEnable = simulateEnable(modules);
875
        List toEnable = simulateEnable(modules);
737
	ev.log(Events.PERF_TICK, "checked the required ordering and autoloads"); // NOI18N
876
	getEvents().log(Events.PERF_TICK, "checked the required ordering and autoloads"); // NOI18N
738
	
877
	
739
        Util.err.log("enable: toEnable=" + toEnable); // NOI18N
878
        Util.err.log("enable: toEnable=" + toEnable); // NOI18N
740
        {
879
        {
Lines 754-762 Link Here
754
            }
893
            }
755
        }
894
        }
756
        Util.err.log("enable: verified dependencies");
895
        Util.err.log("enable: verified dependencies");
757
	ev.log(Events.PERF_TICK, "verified dependencies"); // NOI18N
896
	getEvents().log(Events.PERF_TICK, "verified dependencies"); // NOI18N
758
897
759
        ev.log(Events.START_ENABLE_MODULES, toEnable);
898
        getEvents().log(Events.START_ENABLE_MODULES, toEnable);
760
        {
899
        {
761
            // Actually turn on the listed modules.
900
            // Actually turn on the listed modules.
762
            // List of modules that need to be "rolled back".
901
            // List of modules that need to be "rolled back".
Lines 770-781 Link Here
770
            try {
909
            try {
771
                Iterator teIt = toEnable.iterator();
910
                Iterator teIt = toEnable.iterator();
772
		
911
		
773
		ev.log(Events.PERF_START, "module preparation" ); // NOI18N
912
		getEvents().log(Events.PERF_START, "module preparation" ); // NOI18N
774
                while (teIt.hasNext()) {
913
                while (teIt.hasNext()) {
775
                    Module m = (Module)teIt.next();
914
                    Module m = (Module)teIt.next();
776
                    fallback.addFirst(m);
915
                    fallback.addFirst(m);
777
                    Util.err.log("enable: bringing up: " + m);
916
                    Util.err.log("enable: bringing up: " + m);
778
                    ev.log(Events.PERF_START, "bringing up classloader on " + m.getCodeName() ); // NOI18N
917
                    getEvents().log(Events.PERF_START, "bringing up classloader on " + m.getCodeName() ); // NOI18N
779
                    try {
918
                    try {
780
                        // Calculate the parents to initialize the classloader with.
919
                        // Calculate the parents to initialize the classloader with.
781
                        Dependency[] dependencies = m.getDependenciesArray();
920
                        Dependency[] dependencies = m.getDependenciesArray();
Lines 802-810 Link Here
802
                        throw ie;
941
                        throw ie;
803
                    }
942
                    }
804
                    m.setEnabled(true);
943
                    m.setEnabled(true);
805
                    ev.log(Events.PERF_END, "bringing up classloader on " + m.getCodeName() ); // NOI18N
944
                    getEvents().log(Events.PERF_END, "bringing up classloader on " + m.getCodeName() ); // NOI18N
806
                    // Check package dependencies.
945
                    // Check package dependencies.
807
                    ev.log(Events.PERF_START, "package dependency check on " + m.getCodeName() ); // NOI18N
946
                    getEvents().log(Events.PERF_START, "package dependency check on " + m.getCodeName() ); // NOI18N
808
                    Util.err.log("enable: checking package dependencies for " + m);
947
                    Util.err.log("enable: checking package dependencies for " + m);
809
                    Dependency[] dependencies = m.getDependenciesArray();
948
                    Dependency[] dependencies = m.getDependenciesArray();
810
                    for (int i = 0; i < dependencies.length; i++) {
949
                    for (int i = 0; i < dependencies.length; i++) {
Lines 818-830 Link Here
818
                        }
957
                        }
819
                        Util.err.log("Successful check for: " + dep);
958
                        Util.err.log("Successful check for: " + dep);
820
                    }
959
                    }
821
                    ev.log(Events.PERF_END, "package dependency check on " + m.getCodeName() ); // NOI18N
960
                    getEvents().log(Events.PERF_END, "package dependency check on " + m.getCodeName() ); // NOI18N
822
                    // Prepare to load it.
961
                    // Prepare to load it.
823
                    ev.log(Events.PERF_START, "ModuleInstaller.prepare " + m.getCodeName() ); // NOI18N
962
                    getEvents().log(Events.PERF_START, "ModuleInstaller.prepare " + m.getCodeName() ); // NOI18N
824
                    installer.prepare(m);
963
                    getInstaller(false).prepare(m);
825
                    ev.log(Events.PERF_END, "ModuleInstaller.prepare " + m.getCodeName() ); // NOI18N
964
                    getEvents().log(Events.PERF_END, "ModuleInstaller.prepare " + m.getCodeName() ); // NOI18N
826
                }
965
                }
827
                ev.log(Events.PERF_END, "module preparation" ); // NOI18N
966
                getEvents().log(Events.PERF_END, "module preparation" ); // NOI18N
828
967
829
            } catch (InvalidException ie) {
968
            } catch (InvalidException ie) {
830
                // Remember that there was a problem with this guy.
969
                // Remember that there was a problem with this guy.
Lines 895-901 Link Here
895
                Util.err.log("enable: no class loader yet, not appending");
1034
                Util.err.log("enable: no class loader yet, not appending");
896
            }
1035
            }
897
            Util.err.log("enable: continuing to installation");
1036
            Util.err.log("enable: continuing to installation");
898
            installer.load(toEnable);
1037
            getInstaller(false).load(toEnable);
899
        }
1038
        }
900
        {
1039
        {
901
            // Take care of notifying various changes.
1040
            // Take care of notifying various changes.
Lines 911-917 Link Here
911
                }
1050
                }
912
            }
1051
            }
913
        }
1052
        }
914
        ev.log(Events.FINISH_ENABLE_MODULES, toEnable);
1053
        getEvents().log(Events.FINISH_ENABLE_MODULES, toEnable);
915
        firer.fire();
1054
        firer.fire();
916
    }
1055
    }
917
    
1056
    
Lines 941-954 Link Here
941
            }
1080
            }
942
        }
1081
        }
943
        Util.err.log("disable: verified dependencies");
1082
        Util.err.log("disable: verified dependencies");
944
        ev.log(Events.START_DISABLE_MODULES, toDisable);
1083
        getEvents().log(Events.START_DISABLE_MODULES, toDisable);
945
        {
1084
        {
946
            // Actually turn off all modules.
1085
            // Actually turn off all modules.
947
            installer.unload(toDisable);
1086
            getInstaller(true).unload(toDisable);
948
            Iterator it = toDisable.iterator();
1087
            Iterator it = toDisable.iterator();
949
            while (it.hasNext()) {
1088
            while (it.hasNext()) {
950
                Module m = (Module)it.next();
1089
                Module m = (Module)it.next();
951
                installer.dispose(m);
1090
                getInstaller(true).dispose(m);
952
                m.setEnabled(false);
1091
                m.setEnabled(false);
953
                m.classLoaderDown();
1092
                m.classLoaderDown();
954
            }
1093
            }
Lines 974-980 Link Here
974
                firer.change(new ChangeFirer.Change(m, Module.PROP_CLASS_LOADER, null, null));
1113
                firer.change(new ChangeFirer.Change(m, Module.PROP_CLASS_LOADER, null, null));
975
            }
1114
            }
976
        }
1115
        }
977
        ev.log(Events.FINISH_DISABLE_MODULES, toDisable);
1116
        getEvents().log(Events.FINISH_DISABLE_MODULES, toDisable);
978
        firer.fire();
1117
        firer.fire();
979
    }
1118
    }
980
    
1119
    
Lines 1549-1555 Link Here
1549
            Util.err.log(ErrorManager.WARNING, "Cyclic module dependencies, will not shut down cleanly: " + deps); // NOI18N
1688
            Util.err.log(ErrorManager.WARNING, "Cyclic module dependencies, will not shut down cleanly: " + deps); // NOI18N
1550
            return true;
1689
            return true;
1551
        }
1690
        }
1552
        if (! installer.closing(modules)) {
1691
        if (! getInstaller(true).closing(modules)) {
1553
            return false;
1692
            return false;
1554
        }
1693
        }
1555
        if (midHook != null) {
1694
        if (midHook != null) {
Lines 1561-1567 Link Here
1561
                Util.err.notify(e);
1700
                Util.err.notify(e);
1562
            }
1701
            }
1563
        }
1702
        }
1564
        installer.close(modules);
1703
        getInstaller(true).close(modules);
1565
        return true;
1704
        return true;
1566
    }
1705
    }
1706
1707
    final ModuleInstaller getInstaller(boolean needRealInstaller) {
1708
        if (needRealInstaller && (installer instanceof EmptyInstaller)) {
1709
            installer = (ModuleInstaller)Lookup.getDefault().lookup(ModuleInstaller.class);
1710
            assert installer != null : "ModuleInstaller must be provided in lookup"; // NOI18N
1711
        }
1712
        return installer;
1713
    }
1714
    
1715
    /** Access for ManifestSection. 
1716
     * @since JST-PENDING needed by ManifestSection
1717
     */
1718
    public final Events getEvents() {
1719
        if (ev == null) {
1720
            ev = new NbEvents();
1721
            //ev = (Events)Lookup.getDefault().lookup(Events.class);
1722
            assert ev != null : "Must register Events in lookup"; // NOI18N
1723
        }
1724
        return ev;
1725
    }
1726
    private static class EmptyInstaller extends ModuleInstaller {
1727
        public void unload(List modules) {
1728
            throw new IllegalStateException();
1729
        }
1730
1731
        public void prepare(Module m) throws InvalidException {
1732
            System.err.println("default prepare: " + m);
1733
        }
1734
1735
        public void load(List modules) {
1736
            System.err.println("default load: " + modules);
1737
        }
1738
1739
        public void dispose(Module m) {
1740
            throw new IllegalStateException();
1741
        }
1742
1743
        public boolean closing(List modules) {
1744
            throw new IllegalStateException();
1745
        }
1746
1747
        public void close(List modules) {
1748
            throw new IllegalStateException();
1749
        }
1750
1751
    };
1567
}
1752
}
(-)/dev/null (+315 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans;
15
16
// May use core, GUI, ad nauseum.
17
18
import java.io.File;
19
import java.text.Collator;
20
import java.util.*;
21
import javax.swing.JOptionPane;
22
import org.openide.ErrorManager;
23
import org.openide.modules.SpecificationVersion;
24
import org.openide.util.NbBundle;
25
import org.openide.util.RequestProcessor;
26
27
28
/** Report events to the performance logger, status text/splash screen,
29
 * console, and so on.
30
 * @author Jesse Glick
31
 */
32
public final class NbEvents extends Events {
33
    
34
    /** Handle a logged event.
35
     * CAREFUL that this is called synchronously, usually within a write
36
     * mutex or other sensitive environment. So do not call anything
37
     * blocking (like TM.notify) directly. TM.setStatusText and printing
38
     * to console are fine, as well as performance logging.
39
     */
40
    protected void logged(final String message, Object[] args) {
41
        if (message == PERF_TICK) {
42
            logProgress( (String)args[0]);
43
        } else if (message == PERF_START) {
44
            logStart( (String)args[0]);
45
        } else if (message == PERF_END) {
46
            logEnd( (String)args[0]);
47
        } else if (message == START_CREATE_BOOT_MODULE) {
48
            addToSplashMaxSteps(1);
49
        } else if (message == START_LOAD_BOOT_MODULES) {
50
            setStatusText(
51
                NbBundle.getMessage(NbEvents.class, "MSG_start_load_boot_modules"));
52
            logStart("ModuleSystem.loadBootModules"); // NOI18N
53
        } else if (message == START_LOAD) {
54
            logStart("NbInstaller.load"); // NOI18N
55
        } else if (message == FINISH_LOAD_BOOT_MODULES) {
56
            /*
57
            setStatusText(
58
                NbBundle.getMessage(NbEvents.class, "MSG_finish_load_boot_modules"));
59
            logEnd( "ModuleSystem.loadBootModules" ); // NOI18N
60
             */
61
        } else if (message == FINISH_LOAD) {
62
            logEnd("NbInstaller.load"); // NOI18N
63
        } else if (message == START_AUTO_RESTORE) {
64
            Set modules = (Set)args[0];
65
            if (! modules.isEmpty()) {
66
   /*             setStatusText(
67
                    NbBundle.getMessage(NbEvents.class, "MSG_start_auto_restore"));
68
    */
69
            }
70
        } else if (message == FINISH_AUTO_RESTORE) {
71
/*            setStatusText(
72
                NbBundle.getMessage(NbEvents.class, "MSG_finish_auto_restore"));
73
 */
74
        } else if (message == START_ENABLE_MODULES) {
75
/*            setStatusText(
76
                NbBundle.getMessage(NbEvents.class, "MSG_start_enable_modules"));
77
 */
78
        } else if (message == FINISH_ENABLE_MODULES) {
79
            List modules = (List)args[0];
80
            if (! modules.isEmpty()) {
81
/*                System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_finish_enable_modules"));*/
82
                dumpModulesList(modules);
83
            }
84
            /*setStatusText(
85
                NbBundle.getMessage(NbEvents.class, "MSG_finish_enable_modules"));
86
             */
87
            logEnd("ModuleManager.enable"); // NOI18N
88
        } else if (message == START_DISABLE_MODULES) {
89
            setStatusText(
90
                NbBundle.getMessage(NbEvents.class, "MSG_start_disable_modules"));
91
        } else if (message == FINISH_DISABLE_MODULES) {
92
            List modules = (List)args[0];
93
            if (! modules.isEmpty()) {
94
                System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_finish_disable_modules"));
95
                dumpModulesList(modules);
96
            }
97
            setStatusText(
98
                NbBundle.getMessage(NbEvents.class, "MSG_finish_disable_modules"));
99
        } else if (message == START_DEPLOY_TEST_MODULE) {
100
            // No need to print anything. ModuleSystem.deployTestModule prints
101
            // its own stuff (it needs to be printed synchronously to console
102
            // in order to appear in the output window). But status text is OK.
103
            // Again no need for I18N as this is only for module developers.
104
            setStatusText(
105
                "Deploying test module in " + (File)args[0] + "..."); // NOI18N
106
        } else if (message == FINISH_DEPLOY_TEST_MODULE) {
107
            setStatusText(
108
                "Finished deploying test module."); // NOI18N
109
        } else if (message == FAILED_INSTALL_NEW) {
110
            SortedSet problemTexts = new TreeSet(Collator.getInstance()); // SortedSet<String>
111
            Iterator it = ((Set)args[0]).iterator();
112
            while (it.hasNext()) {
113
                Module m = (Module)it.next();
114
                Iterator pit = m.getProblems().iterator();
115
                if (pit.hasNext()) {
116
                    while (pit.hasNext()) {
117
                        /** JST-PENDING:
118
                        problemTexts.add(m.getDisplayName() + " - " + // NOI18N
119
                                         NbProblemDisplayer.messageForProblem(m, pit.next()));
120
                         */
121
                    }
122
                } else {
123
                    throw new IllegalStateException("Module " + m + " could not be installed but had no problems"); // NOI18N
124
                }
125
            }
126
            StringBuffer buf = new StringBuffer(NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new"));
127
            it = problemTexts.iterator();
128
            while (it.hasNext()) {
129
                buf.append("\n\t"); // NOI18N
130
                buf.append((String)it.next());
131
            }
132
            String msg = buf.toString();
133
            notify(msg, true);
134
            System.err.println(msg);
135
            setStatusText("");
136
        } else if (message == FAILED_INSTALL_NEW_UNEXPECTED) {
137
            Module m = (Module)args[0];
138
            // ignore args[1]: InvalidException
139
            StringBuffer buf = new StringBuffer(NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new_unexpected", m.getDisplayName()));
140
            Iterator it = m.getProblems().iterator();
141
            if (it.hasNext()) {
142
                SortedSet problemTexts = new TreeSet(Collator.getInstance()); // SortedSet<String>
143
                while (it.hasNext()) {
144
                    // JST-PENDING: messageForProblem
145
                    //problemTexts.add(NbProblemDisplayer.messageForProblem(m, it.next()));
146
                }
147
                it = problemTexts.iterator();
148
                while (it.hasNext()) {
149
                    buf.append(" - "); // NOI18N
150
                    buf.append((String)it.next());
151
                }
152
            } else {
153
                throw new IllegalStateException("Module " + m + " could not be installed but had no problems"); // NOI18N
154
            }
155
            notify(buf.toString(), true);
156
            System.err.println(buf.toString());
157
            setStatusText("");
158
        } else if (message == START_READ) {
159
            setStatusText(
160
                NbBundle.getMessage(NbEvents.class, "MSG_start_read"));
161
            logStart("ModuleList.readInitial"); // NOI18N
162
        } else if (message == MODULES_FILE_PROCESSED) {
163
            incrementSplashProgressBar();
164
            /* JST-PENDING: does not log at all
165
            if (willLog()) {
166
                logProgress("file " + ((FileObject)args[0]).getNameExt() + " processed"); // NOI18N
167
            }
168
             */
169
        } else if (message == FINISH_READ) {
170
            Set modules = (Set)args[0];
171
            addToSplashMaxSteps(modules.size() + modules.size());
172
            setStatusText(
173
                NbBundle.getMessage(NbEvents.class, "MSG_finish_read"));
174
            logEnd("ModuleList.readInitial"); // NOI18N
175
        } else if (message == RESTORE) {
176
            // Don't look for display name. Just takes too long.
177
            setStatusText(
178
                NbBundle.getMessage(NbEvents.class, "MSG_restore"/*, ((Module)args[0]).getDisplayName()*/));
179
            incrementSplashProgressBar();
180
        } else if (message == INSTALL) {
181
            // Nice to see the real title; not that common, after all.
182
            setStatusText(
183
                NbBundle.getMessage(NbEvents.class, "MSG_install", ((Module)args[0]).getDisplayName()));
184
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_install", ((Module)args[0]).getDisplayName()));
185
            incrementSplashProgressBar();
186
        } else if (message == UPDATE) {
187
            setStatusText(
188
                NbBundle.getMessage(NbEvents.class, "MSG_update", ((Module)args[0]).getDisplayName()));
189
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_update", ((Module)args[0]).getDisplayName()));
190
            incrementSplashProgressBar();
191
        } else if (message == UNINSTALL) {
192
            setStatusText(
193
                NbBundle.getMessage(NbEvents.class, "MSG_uninstall", ((Module)args[0]).getDisplayName()));
194
        } else if (message == LOAD_SECTION) {
195
            // Again avoid finding display name now.
196
            setStatusText(
197
                NbBundle.getMessage(NbEvents.class, "MSG_load_section"/*, ((Module)args[0]).getDisplayName()*/));
198
        } else if (message == LOAD_LAYERS) {
199
            setStatusText(
200
                NbBundle.getMessage(NbEvents.class, "MSG_load_layers"));
201
        } else if (message == WRONG_CLASS_LOADER) {
202
            if (! Boolean.getBoolean("netbeans.moduleitem.dontverifyclassloader") && Util.err.isLoggable(ErrorManager.WARNING)) { // NOI18N
203
                Class clazz = (Class)args[1];
204
                // Message for developers, no need for I18N.
205
                StringBuffer b = new StringBuffer();
206
                b.append("The module " + ((Module)args[0]).getDisplayName() + " loaded the class " + clazz.getName() + "\n"); // NOI18N
207
                b.append("from the wrong classloader. The expected classloader was " + args[2] + "\n"); // NOI18N
208
                b.append("whereas it was actually loaded from " + clazz.getClassLoader() + "\n"); // NOI18N
209
                b.append("Usually this means that some classes were in the startup classpath.\n"); // NOI18N
210
                b.append("To suppress this message, run with: -J-Dnetbeans.moduleitem.dontverifyclassloader=true"); // NOI18N
211
                Util.err.log(ErrorManager.WARNING, b.toString());
212
            }
213
        } else if (message == EXTENSION_MULTIPLY_LOADED) {
214
            // Developer-oriented message, no need for I18N.
215
            Util.err.log(ErrorManager.WARNING, "Warning: the extension " + (File)args[0] + " may be multiply loaded by modules: " + (Set/*<File>*/)args[1] + "; see: http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#class-path"); // NOI18N
216
        } else if (message == MISSING_JAR_FILE) {
217
            File jar = (File)args[0];
218
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_missing_jar_file", jar.getAbsolutePath()));
219
        } else if (message == CANT_DELETE_ENABLED_AUTOLOAD) {
220
            Module m = (Module)args[0];
221
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_cant_delete_enabled_autoload", m.getDisplayName()));
222
        } else if (message == MISC_PROP_MISMATCH) {
223
            // XXX does this really need to be logged to the user?
224
            // Or should it just be sent quietly to the log file?
225
            Module m = (Module)args[0];
226
            String prop = (String)args[1];
227
            Object onDisk = (Object)args[2];
228
            Object inMem = (Object)args[3];
229
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_misc_prop_mismatch", new Object[] {m.getDisplayName(), prop, onDisk, inMem}));
230
        } else if (message == PATCH) {
231
            File f = (File)args[0];
232
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_patch", f.getAbsolutePath()));
233
        }
234
        // XXX other messages?
235
    }
236
237
    /** Print a nonempty list of modules to console (= log file).
238
     * @param modules the modules
239
     */
240
    private void dumpModulesList(Collection modules) {
241
        Iterator it = modules.iterator();
242
        if (! it.hasNext()) throw new IllegalArgumentException();
243
        StringBuffer buf = new StringBuffer(modules.size() * 100 + 1);
244
        String lineSep = System.getProperty("line.separator");
245
        while (it.hasNext()) {
246
            Module m = (Module)it.next();
247
            buf.append('\t'); // NOI18N
248
            buf.append(m.getCodeName());
249
            buf.append(" ["); // NOI18N
250
            SpecificationVersion sv = m.getSpecificationVersion();
251
            if (sv != null) {
252
                buf.append(sv);
253
            }
254
            String iv = m.getImplementationVersion();
255
            if (iv != null) {
256
                buf.append(' '); // NOI18N
257
                buf.append(iv);
258
            }
259
            String bv = m.getBuildVersion();
260
            if (bv != null && !bv.equals (iv)) {
261
                buf.append(' '); // NOI18N
262
                buf.append(bv);
263
            }
264
            buf.append(']'); // NOI18N
265
            // #32331: use platform-specific newlines
266
            buf.append(lineSep);
267
        }
268
        System.err.print(buf.toString());
269
    }
270
    
271
    private void notify(String text, boolean warn) {
272
        if (Boolean.getBoolean("netbeans.full.hack")) { // NOI18N
273
            // #21773: interferes with automated GUI testing.
274
            System.err.println(text);
275
        } else {
276
            // Normal - display dialog.
277
            int type = warn ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE;
278
            javax.swing.JOptionPane p = new javax.swing.JOptionPane (text, type);
279
            RequestProcessor.getDefault().post(new Notifier(p));
280
        }
281
    }
282
    private static final class Notifier implements Runnable {
283
        private final javax.swing.JOptionPane desc;
284
        public Notifier(javax.swing.JOptionPane desc) {
285
            this.desc = desc;
286
        }
287
        public void run() {
288
             desc.setVisible (true);
289
        }
290
    }
291
292
    private static void incrementSplashProgressBar () {
293
        System.err.println("incrementSplashProgressBar");
294
    }
295
    
296
    private static void setStatusText (String msg) {
297
        System.err.println("setStatusText: " + msg);
298
    }
299
300
    private void logStart(String string) {
301
        setStatusText("logStart: " + string);
302
    }
303
304
    private void logEnd(String string) {
305
        setStatusText("logEnd: " + string);
306
    }
307
308
    private void logProgress(String string) {
309
        setStatusText("logProgress: " + string);
310
    }
311
312
    private void addToSplashMaxSteps(int i) {
313
        setStatusText("addToSplashMaxSteps: " + i);
314
    }
315
}
(-)o.n.bootstrap/src/org/netbeans/StandardModule.java:1.1 (-2 / +2 lines)
Lines 57-63 Link Here
57
 * the module manager's read mutex as a rule.
57
 * the module manager's read mutex as a rule.
58
 * @author Jesse Glick
58
 * @author Jesse Glick
59
 */
59
 */
60
final class StandardModule extends Module {
60
class StandardModule extends Module {
61
    
61
    
62
    /** JAR file holding the module */
62
    /** JAR file holding the module */
63
    private final File jar;
63
    private final File jar;
Lines 206-212 Link Here
206
    }
206
    }
207
    
207
    
208
    public boolean isFixed() {
208
    public boolean isFixed() {
209
        return false;
209
        return fixed;
210
    }
210
    }
211
    
211
    
212
    /** Get the JAR this module is packaged in.
212
    /** Get the JAR this module is packaged in.
(-)o.n.core/src/META-INF/services/org.netbeans.CLIHandler:1.4 (-1 lines)
Line 1 Link Here
1
org.netbeans.core.CLIOptions2
(-)o.n.core/src/org/netbeans/core/CLIOptions2.java:1.5 (-73 lines)
Lines 1-73 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core;
15
16
import org.netbeans.CLIHandler;
17
18
/**
19
 * Shows the main window, so it is fronted when second instance of
20
 * NetBeans tries to start.
21
 *
22
 * @author Jaroslav Tulach
23
 */
24
public class CLIOptions2 extends CLIHandler implements Runnable {
25
    /** number of invocations */
26
    private int cnt;
27
28
    /**
29
     * Create a default handler.
30
     */
31
    public CLIOptions2 () {
32
        super(WHEN_INIT);
33
    }
34
    
35
    protected int cli(Args arguments) {
36
        return cli(arguments.getArguments());
37
    }
38
    
39
    final int cli(String[] args) {
40
        if (cnt++ == 0) return 0;
41
        
42
        /*
43
        for (int i = 0; i < args.length; i++) {
44
            if ("--nofront".equals (args[i])) {
45
                return 0;
46
            }
47
        }
48
         */
49
        javax.swing.SwingUtilities.invokeLater (this);
50
        
51
        return 0;
52
    }
53
    
54
    public void run () {
55
        java.awt.Frame f = org.openide.windows.WindowManager.getDefault ().getMainWindow ();
56
57
        // makes sure the frame is visible
58
        f.setVisible(true);
59
        // uniconifies the frame if it is inconified
60
        if ((f.getExtendedState () & java.awt.Frame.ICONIFIED) != 0) {
61
            f.setExtendedState (~java.awt.Frame.ICONIFIED & f.getExtendedState ());
62
        }
63
        // moves it to front and requests focus
64
        f.toFront ();
65
        
66
    }
67
    
68
    
69
    protected void usage(java.io.PrintWriter w) {
70
        //w.println(NonGui.getString("TEXT_help"));
71
    }
72
    
73
}
(-)o.n.core/src/org/netbeans/core/NbTopManager.java:1.216 (-1 / +1 lines)
Lines 30-36 Link Here
30
import javax.swing.border.*;
30
import javax.swing.border.*;
31
import javax.swing.event.ChangeEvent;
31
import javax.swing.event.ChangeEvent;
32
import javax.swing.event.ChangeListener;
32
import javax.swing.event.ChangeListener;
33
import org.netbeans.core.startup.MainLookup;
33
import org.netbeans.MainLookup;
34
import org.netbeans.core.startup.layers.SessionManager;
34
import org.netbeans.core.startup.layers.SessionManager;
35
35
36
import org.openide.*;
36
import org.openide.*;
(-)o.n.core/src/org/netbeans/core/Plain.java:1.35 (-1 / +1 lines)
Lines 86-92 Link Here
86
            notifyException(ioe);
86
            notifyException(ioe);
87
            return;
87
            return;
88
        }
88
        }
89
        moduleSystem.loadBootModules();
89
//JST-PENDING:        moduleSystem.loadBootModules();
90
        if (!Repository.getDefault().getDefaultFileSystem().isReadOnly()) {
90
        if (!Repository.getDefault().getDefaultFileSystem().isReadOnly()) {
91
            moduleSystem.readList();
91
            moduleSystem.readList();
92
            moduleSystem.restore();
92
            moduleSystem.restore();
(-)/dev/null (+1 lines)
Added Link Here
1
org.netbeans.core.startup.NbInstaller
(-)core.startup/src/org/netbeans/core/startup/Bundle.properties:1.9 (-28 lines)
Lines 149-179 Link Here
149
MSG_failed_install_new_unexpected=Warning - could not install module {0}
149
MSG_failed_install_new_unexpected=Warning - could not install module {0}
150
MSG_start_read=Reading module storage...
150
MSG_start_read=Reading module storage...
151
MSG_finish_read=Reading module storage...done.
151
MSG_finish_read=Reading module storage...done.
152
MSG_restore=Starting modules...
153
# #13806: might have been installed before and uninstalled.
154
# {0} - module display name
155
MSG_install=Installing {0}
156
# {0} - module display name
157
TEXT_install=Installing new module: {0}
158
# {0} - module display name
159
MSG_update=Starting a new version of {0}
160
# {0} - module display name
161
TEXT_update=Updating module: {0}
162
# {0} - module display name
163
MSG_uninstall=Stopping {0}
164
MSG_load_section=Loading modules...
165
MSG_load_layers=Loading installed objects of modules...
166
# {0} - path to expected module JAR
167
TEXT_missing_jar_file=Warning: the module {0} could not be found, ignoring...
168
# {0} - module display name
169
TEXT_cant_delete_enabled_autoload=The module {0} could not be deleted as it was an autoload or eager module and still in use.
170
# {0} - module display name
171
# {1} - property name in XML
172
# {2} - value on disk in XML
173
# {3} - actual value
174
TEXT_misc_prop_mismatch=\
175
    An attempt was made to change the property {1} of the module {0} in the system/Modules folder.\n\
176
    The actual value is "{3}" but it was changed on disk to read "{2}".\n\
177
    This property cannot be changed while the IDE is running, so this attempt had no effect.
178
# {0} - JAR file name
179
TEXT_patch=Module patch or custom extension: {0}
(-)core.startup/src/org/netbeans/core/startup/Main.java:1.9 (-1 lines)
Lines 200-206 Link Here
200
            StartLog.logProgress ("ModuleSystem created"); // NOI18N
200
            StartLog.logProgress ("ModuleSystem created"); // NOI18N
201
        }
201
        }
202
202
203
        moduleSystem.loadBootModules();
204
        moduleSystem.readList();
203
        moduleSystem.readList();
205
        Main.addAndSetSplashMaxSteps(30); // additional steps after loading all modules
204
        Main.addAndSetSplashMaxSteps(30); // additional steps after loading all modules
206
        moduleSystem.restore();
205
        moduleSystem.restore();
(-)core.startup/src/org/netbeans/core/startup/MainLookup.java:1.2 (-178 lines)
Lines 1-178 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core.startup;
15
16
import org.openide.util.Lookup;
17
import org.openide.util.lookup.*;
18
import org.openide.modules.*;
19
20
import org.netbeans.*;
21
22
/** The default lookup for the system.
23
 */
24
public final class MainLookup extends ProxyLookup {
25
    private static boolean started = false;
26
    /** currently effective ClassLoader */
27
    private static ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
28
    /** inner access to dynamic lookup service for this top mangager */
29
    private static InstanceContent instanceContent = new InstanceContent ();
30
    /** dynamic lookup service for this top mangager */
31
    private static Lookup instanceLookup = new AbstractLookup (instanceContent);
32
33
    /** Someone called NbTopManager.get().
34
     * That means that subsequent calls to lookup on ModuleInfo
35
     * need not try to get it again.
36
     */
37
    public static void startedNbTopManager() {
38
        started = true;
39
    }
40
41
    /** Initialize the lookup to delegate to NbTopManager.
42
    */
43
    public MainLookup () {
44
        super (new Lookup[] {
45
                   // #14722: pay attention also to META-INF/services/class.Name resources:
46
                   Lookups.metaInfServices(classLoader),
47
                   Lookups.singleton(classLoader),
48
                   Lookup.EMPTY, // will be moduleLookup
49
               });
50
    }
51
52
    /** Called when a system classloader changes.
53
     */
54
    public static final void systemClassLoaderChanged (ClassLoader nue) {
55
        if (classLoader != nue) {
56
            classLoader = nue;
57
            MainLookup l = (MainLookup)Lookup.getDefault();
58
            Lookup[] delegates = l.getLookups();
59
            Lookup[] newDelegates = (Lookup[])delegates.clone();
60
            // Replace classloader.
61
            newDelegates[0] = Lookups.metaInfServices(classLoader);
62
            newDelegates[1] = Lookups.singleton(classLoader);
63
            l.setLookups(newDelegates);
64
        } else {
65
            moduleClassLoadersUp();
66
        }
67
    }
68
69
    /** Called when modules are about to be turned on.
70
     */
71
    public static final void moduleClassLoadersUp() {
72
        MainLookup l = (MainLookup)Lookup.getDefault();
73
        Lookup[] newDelegates = null;
74
        Lookup[] delegates = l.getLookups();
75
        newDelegates = (Lookup[])delegates.clone();
76
        newDelegates[0] = Lookups.metaInfServices(classLoader);
77
        l.setLookups(newDelegates);
78
    }
79
80
    /** Called when Lookup<ModuleInfo> is ready from the ModuleManager.
81
     * @see "#28465"
82
     */
83
    public static final void moduleLookupReady(Lookup moduleLookup) {
84
        MainLookup l = (MainLookup)Lookup.getDefault();
85
        Lookup[] newDelegates = (Lookup[])l.getLookups().clone();
86
        newDelegates[2] = moduleLookup;
87
        l.setLookups(newDelegates);
88
    }
89
90
    /** When all module classes are accessible thru systemClassLoader, this
91
     * method is called to initialize the FolderLookup.
92
     */
93
94
    public static final void modulesClassPathInitialized () {
95
        //System.err.println("mCPI");
96
    //StartLog.logStart ("NbTopManager$MainLookup: initialization of FolderLookup"); // NOI18N
97
98
        // replace the lookup by new one
99
        Lookup lookup = Lookup.getDefault ();
100
        StartLog.logProgress ("Got Lookup"); // NOI18N
101
102
        ((MainLookup)lookup).doInitializeLookup ();
103
    }
104
105
    //
106
    // 
107
    //
108
    
109
    /** Register new instance.
110
     */
111
    public static void register (Object obj) {
112
        instanceContent.add (obj);
113
    }
114
    
115
    /** Register new instance.
116
     * @param obj source
117
     * @param conv convertor which postponing an instantiation
118
     */
119
    public static void register(Object obj, InstanceContent.Convertor conv) {
120
        instanceContent.add(obj, conv);
121
    }
122
    
123
    /** Unregisters the service.
124
     */
125
    public static void unregister (Object obj) {
126
        instanceContent.remove (obj);
127
    }
128
    /** Unregisters the service registered with a convertor.
129
     */
130
    public static void unregister (Object obj, InstanceContent.Convertor conv) {
131
        instanceContent.remove (obj, conv);
132
    }
133
    
134
    
135
    
136
    
137
138
    private final void doInitializeLookup () {
139
        //System.err.println("doInitializeLookup");
140
141
        // extend the lookup
142
        Lookup[] arr = new Lookup[] {
143
            getLookups()[0], // metaInfServicesLookup
144
            getLookups()[1], // ClassLoader lookup
145
            getLookups()[2], // ModuleInfo lookup
146
            // XXX figure out how to put this ahead of MetaInfServicesLookup (for NonGuiMain):
147
            instanceLookup, 
148
            CoreBridge.conditionallyLookupCacheLoad (),
149
        };
150
        StartLog.logProgress ("prepared other Lookups"); // NOI18N
151
152
        setLookups (arr);
153
        StartLog.logProgress ("Lookups set"); // NOI18N
154
155
    //StartLog.logEnd ("NbTopManager$MainLookup: initialization of FolderLookup"); // NOI18N
156
    }
157
158
    public void storeCache() throws java.io.IOException {
159
        Lookup[] ls = getLookups();
160
        if (ls.length == 5) {
161
            // modulesClassPathInitialized has been called, so store folder lookup
162
            CoreBridge.getDefault ().lookupCacheStore (ls[4]);
163
        }
164
    }
165
166
    protected void beforeLookup(Lookup.Template templ) {
167
        Class type = templ.getType();
168
169
        // Force module system to be initialize by looking up ModuleInfo.
170
        // Good for unit tests, etc.
171
        if (!started && (type == ModuleInfo.class || type == org.netbeans.Module.class)) {
172
            Main.getModuleSystem ();
173
        }
174
175
        super.beforeLookup(templ);
176
    }
177
}
178
    
(-)core.startup/src/org/netbeans/core/startup/ModuleSystem.java:1.3 (-115 / +8 lines)
Lines 49-70 Link Here
49
     */
49
     */
50
    public ModuleSystem(FileSystem systemFileSystem) throws IOException {
50
    public ModuleSystem(FileSystem systemFileSystem) throws IOException {
51
        if (Boolean.getBoolean("org.netbeans.core.startup.ModuleSystem.CULPRIT")) Thread.dumpStack(); // NOI18N
51
        if (Boolean.getBoolean("org.netbeans.core.startup.ModuleSystem.CULPRIT")) Thread.dumpStack(); // NOI18N
52
        ev = Boolean.getBoolean("netbeans.modules.quiet") ? (Events)new QuietEvents() : new NbEvents();
52
        // JST-PENDING: ev = Boolean.getBoolean("netbeans.modules.quiet") ? (Events)new QuietEvents() : new NbEvents();
53
        installer = new NbInstaller(ev);
53
        ev = (Events)Lookup.getDefault().lookup(Events.class);
54
        mgr = new ModuleManager(installer, ev);
54
        installer = (NbInstaller)Lookup.getDefault().lookup(ModuleInstaller.class);
55
        mgr = ModuleManager.getDefault();
55
        PropertyChangeListener l = new PropertyChangeListener() {
56
        PropertyChangeListener l = new PropertyChangeListener() {
56
            public void propertyChange(PropertyChangeEvent ev) {
57
            public void propertyChange(PropertyChangeEvent ev) {
57
                if (ModuleManager.PROP_CLASS_LOADER.equals(ev.getPropertyName())) {
58
                if (ModuleManager.PROP_CLASS_LOADER.equals(ev.getPropertyName())) {
58
                    org.netbeans.core.startup.MainLookup.systemClassLoaderChanged(mgr.getClassLoader());
59
                    org.netbeans.MainLookup.systemClassLoaderChanged(mgr.getClassLoader());
59
                }
60
                }
60
            }
61
            }
61
        };
62
        };
62
        mgr.addPropertyChangeListener(l);
63
        mgr.addPropertyChangeListener(l);
63
        
64
        
64
        // now initialize to core/* classloader, later we reassign to all modules
65
        // now initialize to core/* classloader, later we reassign to all modules
65
        org.netbeans.core.startup.MainLookup.systemClassLoaderChanged(installer.getClass ().getClassLoader ());
66
        org.netbeans.MainLookup.systemClassLoaderChanged(installer.getClass ().getClassLoader ());
66
        // #28465: initialize module lookup early
67
        // #28465: initialize module lookup early
67
        org.netbeans.core.startup.MainLookup.moduleLookupReady(mgr.getModuleLookup());
68
        org.netbeans.MainLookup.moduleLookupReady(mgr.getModuleLookup());
68
        if (systemFileSystem.isReadOnly()) {
69
        if (systemFileSystem.isReadOnly()) {
69
            list = null;
70
            list = null;
70
        } else {
71
        } else {
Lines 75-81 Link Here
75
            }
76
            }
76
            list = new ModuleList(mgr, modulesFolder, ev);
77
            list = new ModuleList(mgr, modulesFolder, ev);
77
            ((NbInstaller)installer).registerList(list);
78
            ((NbInstaller)installer).registerList(list);
78
            ((NbInstaller)installer).registerManager(mgr);
79
        }
79
        }
80
        ev.log(Events.CREATED_MODULE_SYSTEM);
80
        ev.log(Events.CREATED_MODULE_SYSTEM);
81
    }
81
    }
Lines 114-226 Link Here
114
        }
114
        }
115
    }
115
    }
116
116
117
    /** We just make the modules now, restore them later
118
     * to optimize the layer merge.
119
     */
120
    private Set bootModules = null; // Set<Module>
121
    
122
    /** Load modules found in the classpath.
123
     * Note that they might not satisfy all their dependencies, in which
124
     * case oh well...
125
     */
126
    public void loadBootModules() {	
127
        // Keep a list of manifest URL prefixes which we know we do not need to
128
        // parse. Some of these manifests might be signed, and if so, we do not
129
        // want to touch them, as it slows down startup quite a bit.
130
        Collection ignoredPrefixes = new ArrayList(3); // List<String>
131
        try {
132
            // skip the JDK/JRE libraries
133
            String jdk = System.getProperty("java.home");
134
            if (jdk.endsWith(File.separator + "jre")) { // NOI18N
135
                jdk = jdk.substring(0, jdk.length() - 4);
136
            }
137
            File f = new File(jdk);
138
            ignoredPrefixes.add("jar:" + f.toURI().toURL()); // NOI18N
139
            // skip $nbhome/lib/ext/*.jar; all fixes modules should be in
140
            // $nbhome/lib/ (or perhaps elsewhere, with -cp:a)
141
            String nbhomeS = System.getProperty("netbeans.home");
142
            if (nbhomeS != null) {
143
                File nbhome = new File(nbhomeS);
144
                f = new File(new File(nbhome, "lib"), "ext"); // NOI18N
145
                ignoredPrefixes.add("jar:" + f.toURI().toURL()); // NOI18N
146
            }
147
        } catch (MalformedURLException e) {
148
            Util.err.notify(ErrorManager.INFORMATIONAL, e);
149
        }
150
        if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) {
151
            Util.err.log("ignoredPrefixes=" + ignoredPrefixes);
152
        }
153
        
154
        mgr.mutexPrivileged().enterWriteAccess();
155
        ev.log(Events.START_LOAD_BOOT_MODULES);
156
        try {
157
            bootModules = new HashSet(10);
158
            ClassLoader loader = ModuleSystem.class.getClassLoader();
159
            Enumeration e = loader.getResources("META-INF/MANIFEST.MF"); // NOI18N
160
            ev.log(Events.PERF_TICK, "got all manifests"); // NOI18N
161
            
162
            // There will be duplicates: cf. #32576.
163
            Set checkedManifests = new HashSet(); // Set<URL>
164
            MANIFESTS:
165
            while (e.hasMoreElements()) {
166
                URL manifestUrl = (URL)e.nextElement();
167
                if (!checkedManifests.add(manifestUrl)) {
168
                    // Already seen, ignore.
169
                    continue;
170
                }
171
                String manifestUrlS = manifestUrl.toExternalForm();
172
                Iterator it = ignoredPrefixes.iterator();
173
                while (it.hasNext()) {
174
                    if (manifestUrlS.startsWith((String)it.next())) {
175
                        continue MANIFESTS;
176
                    }
177
                }
178
                if (Util.err.isLoggable(ErrorManager.INFORMATIONAL)) {
179
                    Util.err.log("Checking boot manifest: " + manifestUrlS);
180
                }
181
                
182
                InputStream is;
183
                try {
184
                    is = manifestUrl.openStream();
185
                } catch (IOException ioe) {
186
                    // Debugging for e.g. #32493 - which JAR was guilty?
187
                    Util.err.annotate(ioe, ErrorManager.UNKNOWN, "URL: " + manifestUrl, null, null, null); // NOI18N
188
                    throw ioe;
189
                }
190
                try {
191
                    Manifest mani = new Manifest(is);
192
                    Attributes attr = mani.getMainAttributes();
193
                    if (attr.getValue("OpenIDE-Module") == null) { // NOI18N
194
                        // Not a module.
195
                        continue;
196
                    }
197
                    bootModules.add(mgr.createFixed(mani, manifestUrl, loader));
198
                } finally {
199
                    is.close();
200
                }
201
            }
202
            if (list == null) {
203
                // Plain calling us, we have to install now.
204
                // Do it the simple way.
205
                mgr.enable(bootModules);
206
            }
207
            ev.log(Events.PERF_TICK, "added all classpath modules"); // NOI18N
208
	    
209
        } catch (IOException ioe) {
210
            // Note: includes also InvalidException's for malformed this and that.
211
            // Probably if a bootstrap module is corrupt we are in pretty bad shape
212
            // anyway, so don't bother trying to be fancy and install just some of
213
            // them etc.
214
            Util.err.notify(ioe);
215
        } catch (DuplicateException de) {
216
            Util.err.notify(de);
217
        } finally {
218
            // Not 100% accurate in this case:
219
            ev.log(Events.FINISH_LOAD_BOOT_MODULES);
220
            mgr.mutexPrivileged().exitWriteAccess();
221
        }
222
    }
223
    
224
    /** Read disk settings and determine what the known modules are.
117
    /** Read disk settings and determine what the known modules are.
225
     */
118
     */
226
    public void readList() {
119
    public void readList() {
Lines 240-246 Link Here
240
	ev.log(Events.PERF_START, "ModuleSystem.restore"); // NOI18N
133
	ev.log(Events.PERF_START, "ModuleSystem.restore"); // NOI18N
241
        mgr.mutexPrivileged().enterWriteAccess();
134
        mgr.mutexPrivileged().enterWriteAccess();
242
        try {
135
        try {
243
            Set toTrigger = new HashSet(bootModules/*Collections.EMPTY_SET*/);
136
            Set toTrigger = new HashSet(Collections.EMPTY_SET);
244
            list.trigger(toTrigger);
137
            list.trigger(toTrigger);
245
        } finally {
138
        } finally {
246
            mgr.mutexPrivileged().exitWriteAccess();
139
            mgr.mutexPrivileged().exitWriteAccess();
(-)core.startup/src/org/netbeans/core/startup/NbEvents.java:1.4 (-294 lines)
Lines 1-294 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.core.startup;
15
16
// May use core, GUI, ad nauseum.
17
18
import java.io.File;
19
import java.text.Collator;
20
import java.util.*;
21
import javax.swing.JOptionPane;
22
import org.openide.ErrorManager;
23
import org.openide.filesystems.FileObject;
24
import org.openide.modules.SpecificationVersion;
25
import org.openide.util.NbBundle;
26
import org.openide.util.RequestProcessor;
27
import org.netbeans.*;
28
29
/** Report events to the performance logger, status text/splash screen,
30
 * console, and so on.
31
 * @author Jesse Glick
32
 */
33
final class NbEvents extends Events {
34
    
35
    /** Handle a logged event.
36
     * CAREFUL that this is called synchronously, usually within a write
37
     * mutex or other sensitive environment. So do not call anything
38
     * blocking (like TM.notify) directly. TM.setStatusText and printing
39
     * to console are fine, as well as performance logging.
40
     */
41
    protected void logged(final String message, Object[] args) {
42
        if (message == PERF_TICK) {
43
            StartLog.logProgress( (String)args[0]);
44
        } else if (message == PERF_START) {
45
            StartLog.logStart( (String)args[0]);
46
        } else if (message == PERF_END) {
47
            StartLog.logEnd( (String)args[0]);
48
        } else if (message == START_CREATE_BOOT_MODULE) {
49
            org.netbeans.core.startup.Main.addToSplashMaxSteps(1);
50
        } else if (message == START_LOAD_BOOT_MODULES) {
51
            setStatusText(
52
                NbBundle.getMessage(NbEvents.class, "MSG_start_load_boot_modules"));
53
            StartLog.logStart("ModuleSystem.loadBootModules"); // NOI18N
54
        } else if (message == START_LOAD) {
55
            StartLog.logStart("NbInstaller.load"); // NOI18N
56
        } else if (message == FINISH_LOAD_BOOT_MODULES) {
57
            setStatusText(
58
                NbBundle.getMessage(NbEvents.class, "MSG_finish_load_boot_modules"));
59
            StartLog.logEnd( "ModuleSystem.loadBootModules" ); // NOI18N
60
        } else if (message == FINISH_LOAD) {
61
            StartLog.logEnd("NbInstaller.load"); // NOI18N
62
        } else if (message == START_AUTO_RESTORE) {
63
            Set modules = (Set)args[0];
64
            if (! modules.isEmpty()) {
65
                setStatusText(
66
                    NbBundle.getMessage(NbEvents.class, "MSG_start_auto_restore"));
67
            }
68
        } else if (message == FINISH_AUTO_RESTORE) {
69
            setStatusText(
70
                NbBundle.getMessage(NbEvents.class, "MSG_finish_auto_restore"));
71
        } else if (message == START_ENABLE_MODULES) {
72
            setStatusText(
73
                NbBundle.getMessage(NbEvents.class, "MSG_start_enable_modules"));
74
        } else if (message == FINISH_ENABLE_MODULES) {
75
            List modules = (List)args[0];
76
            if (! modules.isEmpty()) {
77
                System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_finish_enable_modules"));
78
                dumpModulesList(modules);
79
            }
80
            setStatusText(
81
                NbBundle.getMessage(NbEvents.class, "MSG_finish_enable_modules"));
82
            StartLog.logEnd("ModuleManager.enable"); // NOI18N
83
        } else if (message == START_DISABLE_MODULES) {
84
            setStatusText(
85
                NbBundle.getMessage(NbEvents.class, "MSG_start_disable_modules"));
86
        } else if (message == FINISH_DISABLE_MODULES) {
87
            List modules = (List)args[0];
88
            if (! modules.isEmpty()) {
89
                System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_finish_disable_modules"));
90
                dumpModulesList(modules);
91
            }
92
            setStatusText(
93
                NbBundle.getMessage(NbEvents.class, "MSG_finish_disable_modules"));
94
        } else if (message == START_DEPLOY_TEST_MODULE) {
95
            // No need to print anything. ModuleSystem.deployTestModule prints
96
            // its own stuff (it needs to be printed synchronously to console
97
            // in order to appear in the output window). But status text is OK.
98
            // Again no need for I18N as this is only for module developers.
99
            setStatusText(
100
                "Deploying test module in " + (File)args[0] + "..."); // NOI18N
101
        } else if (message == FINISH_DEPLOY_TEST_MODULE) {
102
            setStatusText(
103
                "Finished deploying test module."); // NOI18N
104
        } else if (message == FAILED_INSTALL_NEW) {
105
            SortedSet problemTexts = new TreeSet(Collator.getInstance()); // SortedSet<String>
106
            Iterator it = ((Set)args[0]).iterator();
107
            while (it.hasNext()) {
108
                Module m = (Module)it.next();
109
                Iterator pit = m.getProblems().iterator();
110
                if (pit.hasNext()) {
111
                    while (pit.hasNext()) {
112
                        problemTexts.add(m.getDisplayName() + " - " + // NOI18N
113
                                         NbProblemDisplayer.messageForProblem(m, pit.next()));
114
                    }
115
                } else {
116
                    throw new IllegalStateException("Module " + m + " could not be installed but had no problems"); // NOI18N
117
                }
118
            }
119
            StringBuffer buf = new StringBuffer(NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new"));
120
            it = problemTexts.iterator();
121
            while (it.hasNext()) {
122
                buf.append("\n\t"); // NOI18N
123
                buf.append((String)it.next());
124
            }
125
            String msg = buf.toString();
126
            notify(msg, true);
127
            System.err.println(msg);
128
            setStatusText("");
129
        } else if (message == FAILED_INSTALL_NEW_UNEXPECTED) {
130
            Module m = (Module)args[0];
131
            // ignore args[1]: InvalidException
132
            StringBuffer buf = new StringBuffer(NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new_unexpected", m.getDisplayName()));
133
            Iterator it = m.getProblems().iterator();
134
            if (it.hasNext()) {
135
                SortedSet problemTexts = new TreeSet(Collator.getInstance()); // SortedSet<String>
136
                while (it.hasNext()) {
137
                    problemTexts.add(NbProblemDisplayer.messageForProblem(m, it.next()));
138
                }
139
                it = problemTexts.iterator();
140
                while (it.hasNext()) {
141
                    buf.append(" - "); // NOI18N
142
                    buf.append((String)it.next());
143
                }
144
            } else {
145
                throw new IllegalStateException("Module " + m + " could not be installed but had no problems"); // NOI18N
146
            }
147
            notify(buf.toString(), true);
148
            System.err.println(buf.toString());
149
            setStatusText("");
150
        } else if (message == START_READ) {
151
            setStatusText(
152
                NbBundle.getMessage(NbEvents.class, "MSG_start_read"));
153
            StartLog.logStart("ModuleList.readInitial"); // NOI18N
154
        } else if (message == MODULES_FILE_PROCESSED) {
155
            incrementSplashProgressBar();
156
            if (StartLog.willLog()) {
157
                StartLog.logProgress("file " + ((FileObject)args[0]).getNameExt() + " processed"); // NOI18N
158
            }
159
        } else if (message == FINISH_READ) {
160
            Set modules = (Set)args[0];
161
            org.netbeans.core.startup.Main.addToSplashMaxSteps(modules.size() + modules.size());
162
            setStatusText(
163
                NbBundle.getMessage(NbEvents.class, "MSG_finish_read"));
164
            StartLog.logEnd("ModuleList.readInitial"); // NOI18N
165
        } else if (message == RESTORE) {
166
            // Don't look for display name. Just takes too long.
167
            setStatusText(
168
                NbBundle.getMessage(NbEvents.class, "MSG_restore"/*, ((Module)args[0]).getDisplayName()*/));
169
            incrementSplashProgressBar();
170
        } else if (message == INSTALL) {
171
            // Nice to see the real title; not that common, after all.
172
            setStatusText(
173
                NbBundle.getMessage(NbEvents.class, "MSG_install", ((Module)args[0]).getDisplayName()));
174
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_install", ((Module)args[0]).getDisplayName()));
175
            incrementSplashProgressBar();
176
        } else if (message == UPDATE) {
177
            setStatusText(
178
                NbBundle.getMessage(NbEvents.class, "MSG_update", ((Module)args[0]).getDisplayName()));
179
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_update", ((Module)args[0]).getDisplayName()));
180
            incrementSplashProgressBar();
181
        } else if (message == UNINSTALL) {
182
            setStatusText(
183
                NbBundle.getMessage(NbEvents.class, "MSG_uninstall", ((Module)args[0]).getDisplayName()));
184
        } else if (message == LOAD_SECTION) {
185
            // Again avoid finding display name now.
186
            setStatusText(
187
                NbBundle.getMessage(NbEvents.class, "MSG_load_section"/*, ((Module)args[0]).getDisplayName()*/));
188
        } else if (message == LOAD_LAYERS) {
189
            setStatusText(
190
                NbBundle.getMessage(NbEvents.class, "MSG_load_layers"));
191
        } else if (message == WRONG_CLASS_LOADER) {
192
            if (! Boolean.getBoolean("netbeans.moduleitem.dontverifyclassloader") && Util.err.isLoggable(ErrorManager.WARNING)) { // NOI18N
193
                Class clazz = (Class)args[1];
194
                // Message for developers, no need for I18N.
195
                StringBuffer b = new StringBuffer();
196
                b.append("The module " + ((Module)args[0]).getDisplayName() + " loaded the class " + clazz.getName() + "\n"); // NOI18N
197
                b.append("from the wrong classloader. The expected classloader was " + args[2] + "\n"); // NOI18N
198
                b.append("whereas it was actually loaded from " + clazz.getClassLoader() + "\n"); // NOI18N
199
                b.append("Usually this means that some classes were in the startup classpath.\n"); // NOI18N
200
                b.append("To suppress this message, run with: -J-Dnetbeans.moduleitem.dontverifyclassloader=true"); // NOI18N
201
                Util.err.log(ErrorManager.WARNING, b.toString());
202
            }
203
        } else if (message == EXTENSION_MULTIPLY_LOADED) {
204
            // Developer-oriented message, no need for I18N.
205
            Util.err.log(ErrorManager.WARNING, "Warning: the extension " + (File)args[0] + " may be multiply loaded by modules: " + (Set/*<File>*/)args[1] + "; see: http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#class-path"); // NOI18N
206
        } else if (message == MISSING_JAR_FILE) {
207
            File jar = (File)args[0];
208
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_missing_jar_file", jar.getAbsolutePath()));
209
        } else if (message == CANT_DELETE_ENABLED_AUTOLOAD) {
210
            Module m = (Module)args[0];
211
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_cant_delete_enabled_autoload", m.getDisplayName()));
212
        } else if (message == MISC_PROP_MISMATCH) {
213
            // XXX does this really need to be logged to the user?
214
            // Or should it just be sent quietly to the log file?
215
            Module m = (Module)args[0];
216
            String prop = (String)args[1];
217
            Object onDisk = (Object)args[2];
218
            Object inMem = (Object)args[3];
219
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_misc_prop_mismatch", new Object[] {m.getDisplayName(), prop, onDisk, inMem}));
220
        } else if (message == PATCH) {
221
            File f = (File)args[0];
222
            System.err.println(NbBundle.getMessage(NbEvents.class, "TEXT_patch", f.getAbsolutePath()));
223
        }
224
        // XXX other messages?
225
    }
226
227
    /** Print a nonempty list of modules to console (= log file).
228
     * @param modules the modules
229
     */
230
    private void dumpModulesList(Collection modules) {
231
        Iterator it = modules.iterator();
232
        if (! it.hasNext()) throw new IllegalArgumentException();
233
        StringBuffer buf = new StringBuffer(modules.size() * 100 + 1);
234
        String lineSep = System.getProperty("line.separator");
235
        while (it.hasNext()) {
236
            Module m = (Module)it.next();
237
            buf.append('\t'); // NOI18N
238
            buf.append(m.getCodeName());
239
            buf.append(" ["); // NOI18N
240
            SpecificationVersion sv = m.getSpecificationVersion();
241
            if (sv != null) {
242
                buf.append(sv);
243
            }
244
            String iv = m.getImplementationVersion();
245
            if (iv != null) {
246
                buf.append(' '); // NOI18N
247
                buf.append(iv);
248
            }
249
            String bv = m.getBuildVersion();
250
            if (bv != null && !bv.equals (iv)) {
251
                buf.append(' '); // NOI18N
252
                buf.append(bv);
253
            }
254
            buf.append(']'); // NOI18N
255
            // #32331: use platform-specific newlines
256
            buf.append(lineSep);
257
        }
258
        System.err.print(buf.toString());
259
    }
260
    
261
    private void notify(String text, boolean warn) {
262
        if (Boolean.getBoolean("netbeans.full.hack")) { // NOI18N
263
            // #21773: interferes with automated GUI testing.
264
            System.err.println(text);
265
        } else {
266
            // Normal - display dialog.
267
            new Notifier(text, warn);
268
        }
269
    }
270
    private static final class Notifier implements Runnable {
271
        private boolean warn;
272
        private String text;
273
        private static RequestProcessor RP = new RequestProcessor("Notify About Module System"); // NOI18N
274
        
275
        public Notifier(String text, boolean type) {
276
            this.warn = type;
277
            this.text = text;
278
            RP.post(this, 0, Thread.MIN_PRIORITY);
279
        }
280
        public void run() {
281
            int type = warn ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE;
282
            String msg = NbBundle.getMessage(Notifier.class, warn ? "MSG_warning" : "MSG_info"); // NOI18N
283
            JOptionPane.showMessageDialog(null, text, msg, type);
284
        }
285
    }
286
287
    private static void incrementSplashProgressBar () {
288
        org.netbeans.core.startup.Main.incrementSplashProgressBar ();
289
    }
290
    
291
    private static void setStatusText (String msg) {
292
        org.netbeans.core.startup.Main.setStatusText (msg);
293
    }
294
}
(-)core.startup/src/org/netbeans/core/startup/NbInstaller.java:1.20 (-40 / +42 lines)
Lines 42-47 Link Here
42
import java.util.jar.Manifest;
42
import java.util.jar.Manifest;
43
import org.netbeans.Events;
43
import org.netbeans.Events;
44
import org.netbeans.InvalidException;
44
import org.netbeans.InvalidException;
45
import org.netbeans.MainLookup;
45
import org.netbeans.Module;
46
import org.netbeans.Module;
46
import org.netbeans.ModuleInstaller;
47
import org.netbeans.ModuleInstaller;
47
import org.netbeans.ModuleManager;
48
import org.netbeans.ModuleManager;
Lines 67-73 Link Here
67
 * messages and the like.
68
 * messages and the like.
68
 * @author Jesse Glick, Jan Pokorsky, Jaroslav Tulach, et al.
69
 * @author Jesse Glick, Jan Pokorsky, Jaroslav Tulach, et al.
69
 */
70
 */
70
final class NbInstaller extends ModuleInstaller {
71
public final class NbInstaller extends ModuleInstaller {
71
    
72
    
72
    /** set of manifest sections for each module */
73
    /** set of manifest sections for each module */
73
    private final Map sections = new HashMap(100); // Map<Module,Set<ManifestSection>>
74
    private final Map sections = new HashMap(100); // Map<Module,Set<ManifestSection>>
Lines 77-88 Link Here
77
    private final Map layers = new HashMap(100); // Map<Module,String>
78
    private final Map layers = new HashMap(100); // Map<Module,String>
78
    /** exact use of this is hard to explain */
79
    /** exact use of this is hard to explain */
79
    private boolean initializedFolderLookup = false;
80
    private boolean initializedFolderLookup = false;
80
    /** where to report events to */
81
    private final Events ev;
82
    /** associated controller of module list; needed for handling ModuleInstall ser */
81
    /** associated controller of module list; needed for handling ModuleInstall ser */
83
    private ModuleList moduleList;
82
    private ModuleList moduleList;
84
    /** associated manager */
85
    private ModuleManager mgr;
86
    /** set of permitted core or package dependencies from a module */
83
    /** set of permitted core or package dependencies from a module */
87
    private final Map kosherPackages = new HashMap(100); // Map<Module,Set<String>>
84
    private final Map kosherPackages = new HashMap(100); // Map<Module,Set<String>>
88
    /** Package prefixes passed as special system property. */
85
    /** Package prefixes passed as special system property. */
Lines 93-114 Link Here
93
     * {@link #registerList} to make the installer fully usable.
90
     * {@link #registerList} to make the installer fully usable.
94
     * @param ev events to log
91
     * @param ev events to log
95
     */
92
     */
96
    public NbInstaller(Events ev) {
93
    public NbInstaller() {
97
        this.ev = ev;
98
    }
94
    }
95
96
    private Events getEvents() {
97
        return getManager().getEvents();
98
    }
99
100
    private ModuleManager getManager() {
101
        return ModuleManager.getDefault();
102
    }
103
99
    
104
    
100
    /** Access from ModuleSystem. */
105
    /** Access from ModuleSystem. */
101
    void registerList(ModuleList list) {
106
    void registerList(ModuleList list) {
102
        if (moduleList != null) throw new IllegalStateException();
107
        if (moduleList != null) throw new IllegalStateException();
103
        moduleList = list;
108
        moduleList = list;
104
    }
109
    }
105
    void registerManager(ModuleManager manager) {
106
        if (mgr != null) throw new IllegalStateException();
107
        mgr = manager;
108
    }
109
    
110
    
110
    public void prepare(Module m) throws InvalidException {
111
    public void prepare(Module m) throws InvalidException {
111
        ev.log(Events.PREPARE, m);
112
        getEvents().log(Events.PREPARE, m);
112
        Set mysections = null;
113
        Set mysections = null;
113
        Class clazz = null;
114
        Class clazz = null;
114
        {
115
        {
Lines 147-153 Link Here
147
                // is on the module author to avoid anything dangerous there.
148
                // is on the module author to avoid anything dangerous there.
148
                clazz = Class.forName(installClassName, false, m.getClassLoader());
149
                clazz = Class.forName(installClassName, false, m.getClassLoader());
149
                if (clazz.getClassLoader() != m.getClassLoader()) {
150
                if (clazz.getClassLoader() != m.getClassLoader()) {
150
                    ev.log(Events.WRONG_CLASS_LOADER, m, clazz, m.getClassLoader());
151
                    getEvents().log(Events.WRONG_CLASS_LOADER, m, clazz, m.getClassLoader());
151
                }
152
                }
152
                // Search for a validate() method; if there is none, do not resolve the class now!
153
                // Search for a validate() method; if there is none, do not resolve the class now!
153
                Class c;
154
                Class c;
Lines 218-231 Link Here
218
    }
219
    }
219
    
220
    
220
    public void load(List modules) {
221
    public void load(List modules) {
221
        ev.log(Events.START_LOAD, modules);
222
        getEvents().log(Events.START_LOAD, modules);
222
        
223
        
223
        // we need to update the classloader as otherwise we might not find
224
        // we need to update the classloader as otherwise we might not find
224
        // all the needed classes
225
        // all the needed classes
225
        if (mgr != null) { // could be null during tests
226
        ModuleManager mgr = ModuleManager.getDefault();
227
        if (mgr != null) {
226
            MainLookup.systemClassLoaderChanged(/* #61107: do not use Thread.cCL here! */mgr.getClassLoader());
228
            MainLookup.systemClassLoaderChanged(/* #61107: do not use Thread.cCL here! */mgr.getClassLoader());
227
        }
229
        }
228
        ev.log(Events.PERF_TICK, "META-INF/services/ additions registered"); // NOI18N
230
        getEvents().log(Events.PERF_TICK, "META-INF/services/ additions registered"); // NOI18N
229
        
231
        
230
        Iterator it = modules.iterator();
232
        Iterator it = modules.iterator();
231
        while (it.hasNext()) {
233
        while (it.hasNext()) {
Lines 235-245 Link Here
235
        }
237
        }
236
        
238
        
237
        loadLayers(modules, true);
239
        loadLayers(modules, true);
238
        ev.log(Events.PERF_TICK, "layers loaded"); // NOI18N
240
        getEvents().log(Events.PERF_TICK, "layers loaded"); // NOI18N
239
	
241
	
240
        it = modules.iterator();
242
        it = modules.iterator();
241
        ev.log(Events.PERF_START, "NbInstaller.load - sections"); // NOI18N
243
    	getEvents().log(Events.PERF_START, "NbInstaller.load - sections"); // NOI18N
242
        ev.log(Events.LOAD_SECTION);
244
        getEvents().log(Events.LOAD_SECTION);
243
        CoreBridge.conditionallyLoaderPoolTransaction(true);
245
        CoreBridge.conditionallyLoaderPoolTransaction(true);
244
        try {
246
        try {
245
            while (it.hasNext()) {
247
            while (it.hasNext()) {
Lines 251-262 Link Here
251
                } catch (LinkageError le) {
253
                } catch (LinkageError le) {
252
                    Util.err.notify(le);
254
                    Util.err.notify(le);
253
                }
255
                }
254
                ev.log(Events.PERF_TICK, "sections for " + m.getCodeName() + " loaded"); // NOI18N
256
                getEvents().log(Events.PERF_TICK, "sections for " + m.getCodeName() + " loaded"); // NOI18N
255
            }
257
            }
256
        } finally {
258
        } finally {
257
            CoreBridge.conditionallyLoaderPoolTransaction(false);
259
            CoreBridge.conditionallyLoaderPoolTransaction(false);
258
        }
260
        }
259
        ev.log(Events.PERF_END, "NbInstaller.load - sections"); // NOI18N
261
    	getEvents().log(Events.PERF_END, "NbInstaller.load - sections"); // NOI18N
260
262
261
        // Yarda says to put this here.
263
        // Yarda says to put this here.
262
        if (! initializedFolderLookup) {
264
        if (! initializedFolderLookup) {
Lines 269-275 Link Here
269
        Main.initUICustomizations();
271
        Main.initUICustomizations();
270
272
271
        it = modules.iterator();
273
        it = modules.iterator();
272
        ev.log(Events.PERF_START, "NbInstaller.load - ModuleInstalls"); // NOI18N
274
    	getEvents().log(Events.PERF_START, "NbInstaller.load - ModuleInstalls"); // NOI18N
273
        while (it.hasNext()) {
275
        while (it.hasNext()) {
274
            Module m = (Module)it.next();
276
            Module m = (Module)it.next();
275
            try {
277
            try {
Lines 281-291 Link Here
281
            } catch (AssertionError e) {
283
            } catch (AssertionError e) {
282
                Util.err.notify(e);
284
                Util.err.notify(e);
283
            }
285
            }
284
	    ev.log(Events.PERF_TICK, "ModuleInstall for " + m.getCodeName() + " called"); // NOI18N
286
	    getEvents().log(Events.PERF_TICK, "ModuleInstall for " + m.getCodeName() + " called"); // NOI18N
285
        }
287
        }
286
        ev.log(Events.PERF_END, "NbInstaller.load - ModuleInstalls"); // NOI18N
288
    	getEvents().log(Events.PERF_END, "NbInstaller.load - ModuleInstalls"); // NOI18N
287
289
288
        ev.log(Events.FINISH_LOAD, modules);
290
        getEvents().log(Events.FINISH_LOAD, modules);
289
        
291
        
290
        maybeSaveManifestCache();
292
        maybeSaveManifestCache();
291
        
293
        
Lines 295-301 Link Here
295
    }
297
    }
296
    
298
    
297
    public void unload(List modules) {
299
    public void unload(List modules) {
298
        ev.log(Events.START_UNLOAD, modules);
300
        getEvents().log(Events.START_UNLOAD, modules);
299
        Iterator it = modules.iterator();
301
        Iterator it = modules.iterator();
300
        while (it.hasNext()) {
302
        while (it.hasNext()) {
301
            Module m = (Module)it.next();
303
            Module m = (Module)it.next();
Lines 328-334 Link Here
328
            }
330
            }
329
        }
331
        }
330
        loadLayers(modules, false);
332
        loadLayers(modules, false);
331
        ev.log(Events.FINISH_UNLOAD, modules);
333
        getEvents().log(Events.FINISH_UNLOAD, modules);
332
    }
334
    }
333
    
335
    
334
    /** Load/unload installer code for a module. */
336
    /** Load/unload installer code for a module. */
Lines 352-379 Link Here
352
                                (oldSpec == null ^ nueSpec == null) ||
354
                                (oldSpec == null ^ nueSpec == null) ||
353
                                (oldSpec != null && nueSpec != null && oldSpec.compareTo(nueSpec) != 0)) {
355
                                (oldSpec != null && nueSpec != null && oldSpec.compareTo(nueSpec) != 0)) {
354
                            // Yes, different version; upgrade from the old one.
356
                            // Yes, different version; upgrade from the old one.
355
                            ev.log(Events.UPDATE, m);
357
                            getEvents().log(Events.UPDATE, m);
356
                            inst.updated(h.getOldMajorVersion(), oldSpec == null ? null : oldSpec.toString());
358
                            inst.updated(h.getOldMajorVersion(), oldSpec == null ? null : oldSpec.toString());
357
                        } else {
359
                        } else {
358
                            // Same version as before.
360
                            // Same version as before.
359
                            ev.log(Events.RESTORE, m);
361
                            getEvents().log(Events.RESTORE, m);
360
                            inst.restored();
362
                            inst.restored();
361
                        }
363
                        }
362
                    } else {
364
                    } else {
363
                        // First time.
365
                        // First time.
364
                        ev.log(Events.INSTALL, m);
366
                        getEvents().log(Events.INSTALL, m);
365
                        inst.installed();
367
                        inst.installed();
366
                    }
368
                    }
367
                } else {
369
                } else {
368
                    // Probably fixed module. Just restore.
370
                    // Probably fixed module. Just restore.
369
                    ev.log(Events.RESTORE, m);
371
                    getEvents().log(Events.RESTORE, m);
370
                    inst.restored();
372
                    inst.restored();
371
                }
373
                }
372
                if (moduleList != null) {
374
                if (moduleList != null) {
373
                    moduleList.installPostpare(m, inst);
375
                    moduleList.installPostpare(m, inst);
374
                }
376
                }
375
            } else {
377
            } else {
376
                ev.log(Events.UNINSTALL, m);
378
                getEvents().log(Events.UNINSTALL, m);
377
                inst.uninstalled();
379
                inst.uninstalled();
378
                if (m.getHistory() instanceof ModuleHistory) {
380
                if (m.getHistory() instanceof ModuleHistory) {
379
                    ((ModuleHistory)m.getHistory()).resetHistory();
381
                    ((ModuleHistory)m.getHistory()).resetHistory();
Lines 481-487 Link Here
481
     * If a module has no declared layer, does nothing.
483
     * If a module has no declared layer, does nothing.
482
     */
484
     */
483
    private void loadLayers(List modules, boolean load) {
485
    private void loadLayers(List modules, boolean load) {
484
        ev.log(load ? Events.LOAD_LAYERS : Events.UNLOAD_LAYERS, modules);
486
        getEvents().log(load ? Events.LOAD_LAYERS : Events.UNLOAD_LAYERS, modules);
485
        // #23609: dependent modules should be able to override:
487
        // #23609: dependent modules should be able to override:
486
        modules = new ArrayList(modules);
488
        modules = new ArrayList(modules);
487
        Collections.reverse(modules);
489
        Collections.reverse(modules);
Lines 568-574 Link Here
568
            for (int i = 0; i < deps.length; i++) {
570
            for (int i = 0; i < deps.length; i++) {
569
                if (deps[i].getType() == Dependency.TYPE_MODULE) {
571
                if (deps[i].getType() == Dependency.TYPE_MODULE) {
570
                    String cnb = (String)Util.parseCodeName(deps[i].getName())[0];
572
                    String cnb = (String)Util.parseCodeName(deps[i].getName())[0];
571
                    Module o = mgr.get(cnb);
573
                    Module o = getManager().get(cnb);
572
                    if (o == null) throw new IllegalStateException("No such module: " + cnb); // NOI18N
574
                    if (o == null) throw new IllegalStateException("No such module: " + cnb); // NOI18N
573
                    if (Boolean.valueOf((String)o.getAttribute("OpenIDE-Module-Deprecated")).booleanValue()) { // NOI18N
575
                    if (Boolean.valueOf((String)o.getAttribute("OpenIDE-Module-Deprecated")).booleanValue()) { // NOI18N
574
                        String message = (String)o.getLocalizedAttribute("OpenIDE-Module-Deprecation-Message"); // NOI18N
576
                        String message = (String)o.getLocalizedAttribute("OpenIDE-Module-Deprecation-Message"); // NOI18N
Lines 612-618 Link Here
612
    
614
    
613
    public void close(List modules) {
615
    public void close(List modules) {
614
        Util.err.log("close: " + modules);
616
        Util.err.log("close: " + modules);
615
        ev.log(Events.CLOSE);
617
        getEvents().log(Events.CLOSE);
616
        // [PENDING] this may need to write out changed ModuleInstall externalized
618
        // [PENDING] this may need to write out changed ModuleInstall externalized
617
        // forms...is that really necessary to do here, or isn't it enough to
619
        // forms...is that really necessary to do here, or isn't it enough to
618
        // do right after loading etc.? Currently these are only written when
620
        // do right after loading etc.? Currently these are only written when
Lines 736-742 Link Here
736
                continue;
738
                continue;
737
            }
739
            }
738
            String cnb = (String)Util.parseCodeName(deps[i].getName())[0];
740
            String cnb = (String)Util.parseCodeName(deps[i].getName())[0];
739
            Module parent = mgr.get(cnb);
741
            Module parent = getManager().get(cnb);
740
            if (parent == null) throw new IllegalStateException("No such parent module of " + master + ": " + cnb); // NOI18N
742
            if (parent == null) throw new IllegalStateException("No such parent module of " + master + ": " + cnb); // NOI18N
741
            if (parentModules.add(parent)) {
743
            if (parentModules.add(parent)) {
742
                if (!parents.contains(parent.getClassLoader())) {
744
                if (!parents.contains(parent.getClassLoader())) {
Lines 815-821 Link Here
815
                    if (idx != -1) {
817
                    if (idx != -1) {
816
                        name = name.substring(0, idx);
818
                        name = name.substring(0, idx);
817
                    }
819
                    }
818
                    Module other = mgr.get(name);
820
                    Module other = getManager().get(name);
819
                    if (other == null) throw new IllegalStateException("Should have found dep " + deps[i] + " from " + m); // NOI18N
821
                    if (other == null) throw new IllegalStateException("Should have found dep " + deps[i] + " from " + m); // NOI18N
820
                    s.addAll(findKosher(other));
822
                    s.addAll(findKosher(other));
821
                } else if (deps[i].getType() == Dependency.TYPE_PACKAGE) {
823
                } else if (deps[i].getType() == Dependency.TYPE_PACKAGE) {
Lines 1144-1150 Link Here
1144
        for (int i = 0; i < deps.length; i++) {
1146
        for (int i = 0; i < deps.length; i++) {
1145
            if (deps[i].getType() == Dependency.TYPE_MODULE) {
1147
            if (deps[i].getType() == Dependency.TYPE_MODULE) {
1146
                String cnb = (String)Util.parseCodeName(deps[i].getName())[0];
1148
                String cnb = (String)Util.parseCodeName(deps[i].getName())[0];
1147
                Module next = mgr.get(cnb);
1149
                Module next = getManager().get(cnb);
1148
                if (next == null) throw new IllegalStateException("No such module: " + cnb); // NOI18N
1150
                if (next == null) throw new IllegalStateException("No such module: " + cnb); // NOI18N
1149
                if (depth > 0) {
1151
                if (depth > 0) {
1150
                    addModuleClasspathEntries(next, orig, considered, implDeps, cp, depth - 1);
1152
                    addModuleClasspathEntries(next, orig, considered, implDeps, cp, depth - 1);
Lines 1331-1337 Link Here
1331
            Util.err.log("No manifest cache found at " + manifestCacheFile);
1333
            Util.err.log("No manifest cache found at " + manifestCacheFile);
1332
            return new HashMap(200);
1334
            return new HashMap(200);
1333
        }
1335
        }
1334
        ev.log(Events.PERF_START, "NbInstaller - loadManifestCache"); // NOI18N
1336
        getEvents().log(Events.PERF_START, "NbInstaller - loadManifestCache"); // NOI18N
1335
        try {
1337
        try {
1336
            InputStream is = new FileInputStream(manifestCacheFile);
1338
            InputStream is = new FileInputStream(manifestCacheFile);
1337
            try {
1339
            try {
Lines 1344-1350 Link Here
1344
                return m;
1346
                return m;
1345
            } finally {
1347
            } finally {
1346
                is.close();
1348
                is.close();
1347
                ev.log(Events.PERF_END, "NbInstaller - loadManifestCache"); // NOI18N
1349
                getEvents().log(Events.PERF_END, "NbInstaller - loadManifestCache"); // NOI18N
1348
            }
1350
            }
1349
        } catch (IOException ioe) {
1351
        } catch (IOException ioe) {
1350
            Util.err.annotate(ioe, ErrorManager.UNKNOWN, "While reading: " + manifestCacheFile, null, null, null); // NOI18N
1352
            Util.err.annotate(ioe, ErrorManager.UNKNOWN, "While reading: " + manifestCacheFile, null, null, null); // NOI18N
(-)core.startup/test/unit/src/org/netbeans/core/startup/ModuleFormatSatisfiedTest.java:1.3 (-5 / +1 lines)
Lines 62-72 Link Here
62
        
62
        
63
        
63
        
64
        
64
        
65
        
65
        ModuleManager mgr = new ModuleManager(new NbInstaller(), new FakeEvents());
66
        final FakeEvents ev = new FakeEvents();
67
        org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
68
        ModuleManager mgr = new ModuleManager(installer, ev);
69
        installer.registerManager(mgr);
70
        mgr.mutexPrivileged().enterWriteAccess();
66
        mgr.mutexPrivileged().enterWriteAccess();
71
        try {
67
        try {
72
            addOpenideModules(mgr);
68
            addOpenideModules(mgr);
(-)core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest2.java:1.2 (-4 / +1 lines)
Lines 39-48 Link Here
39
    /** Test #21173/#23595: overriding layers by localization. */
39
    /** Test #21173/#23595: overriding layers by localization. */
40
    public void testLocLayerOverrides() throws Exception {
40
    public void testLocLayerOverrides() throws Exception {
41
        Main.getModuleSystem (); // init module system
41
        Main.getModuleSystem (); // init module system
42
        final FakeEvents ev = new FakeEvents();
42
        org.netbeans.ModuleManager mgr = org.netbeans.ModuleManager.getDefault();
43
        org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
44
        org.netbeans.ModuleManager mgr = new org.netbeans.ModuleManager(installer, ev);
45
        installer.registerManager(mgr);
46
        mgr.mutexPrivileged().enterWriteAccess();
43
        mgr.mutexPrivileged().enterWriteAccess();
47
        try {
44
        try {
48
            Locale orig = Locale.getDefault();
45
            Locale orig = Locale.getDefault();
(-)core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest3.java:1.2 (-4 / +1 lines)
Lines 34-43 Link Here
34
    /** Test #21173/#23595: overriding layers by branding. */
34
    /** Test #21173/#23595: overriding layers by branding. */
35
    public void testBrandingLayerOverrides() throws Exception {
35
    public void testBrandingLayerOverrides() throws Exception {
36
        Main.getModuleSystem ();
36
        Main.getModuleSystem ();
37
        final FakeEvents ev = new FakeEvents();
37
        ModuleManager mgr = ModuleManager.getDefault();
38
        org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
39
        ModuleManager mgr = new ModuleManager(installer, ev);
40
        installer.registerManager(mgr);
41
        mgr.mutexPrivileged().enterWriteAccess();
38
        mgr.mutexPrivileged().enterWriteAccess();
42
        try {
39
        try {
43
            String orig = NbBundle.getBranding();
40
            String orig = NbBundle.getBranding();
(-)core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest4.java:1.1 (-4 / +1 lines)
Lines 45-54 Link Here
45
     */
45
     */
46
    public void testDependencyLayerOverrides1() throws Exception {
46
    public void testDependencyLayerOverrides1() throws Exception {
47
        Main.getModuleSystem (); // init module system
47
        Main.getModuleSystem (); // init module system
48
        final FakeEvents ev = new FakeEvents();
48
        ModuleManager mgr = ModuleManager.getDefault();
49
        org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
50
        ModuleManager mgr = new ModuleManager(installer, ev);
51
        installer.registerManager(mgr);
52
        mgr.mutexPrivileged().enterWriteAccess();
49
        mgr.mutexPrivileged().enterWriteAccess();
53
        try {
50
        try {
54
            Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false);
51
            Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false);
(-)core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest5.java:1.1 (-4 / +1 lines)
Lines 44-53 Link Here
44
        Main.getModuleSystem (); // init module system
44
        Main.getModuleSystem (); // init module system
45
        System.err.println("Module Info->"+org.openide.util.Lookup.getDefault()
45
        System.err.println("Module Info->"+org.openide.util.Lookup.getDefault()
46
                .lookup(org.openide.modules.ModuleInfo.class)); // TEMP
46
                .lookup(org.openide.modules.ModuleInfo.class)); // TEMP
47
        final FakeEvents ev = new FakeEvents();
47
        ModuleManager mgr = ModuleManager.getDefault();
48
        org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
49
        ModuleManager mgr = new ModuleManager(installer, ev);
50
        installer.registerManager(mgr);
51
        mgr.mutexPrivileged().enterWriteAccess();
48
        mgr.mutexPrivileged().enterWriteAccess();
52
        try {
49
        try {
53
            Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false);
50
            Module m1 = mgr.create(new File(jars, "base-layer-mod.jar"), null, false, false, false);
(-)core.startup/test/unit/src/org/netbeans/core/startup/NbInstallerTest9.java:1.3 (-2 / +2 lines)
Lines 62-68 Link Here
62
    public void testManifestCaching() throws Exception {
62
    public void testManifestCaching() throws Exception {
63
        File workdir = getWorkDir();
63
        File workdir = getWorkDir();
64
        System.setProperty("netbeans.user", workdir.getAbsolutePath());
64
        System.setProperty("netbeans.user", workdir.getAbsolutePath());
65
        ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller(new FakeEvents());
65
        ModuleInstaller inst = new org.netbeans.core.startup.NbInstaller();
66
        File littleJar = new File(workdir, "little-manifest.jar");
66
        File littleJar = new File(workdir, "little-manifest.jar");
67
        //inst.loadManifest(littleJar).write(System.out);
67
        //inst.loadManifest(littleJar).write(System.out);
68
        assertEquals(getManifest(littleJar), inst.loadManifest(littleJar));
68
        assertEquals(getManifest(littleJar), inst.loadManifest(littleJar));
Lines 75-81 Link Here
75
        File allManifestsDat = new File(new File(new File(workdir, "var"), "cache"), "all-manifests.dat");
75
        File allManifestsDat = new File(new File(new File(workdir, "var"), "cache"), "all-manifests.dat");
76
        assertTrue("File " + allManifestsDat + " exists", allManifestsDat.isFile());
76
        assertTrue("File " + allManifestsDat + " exists", allManifestsDat.isFile());
77
        // Create a new NbInstaller, since otherwise it turns off caching...
77
        // Create a new NbInstaller, since otherwise it turns off caching...
78
        inst = new org.netbeans.core.startup.NbInstaller(new FakeEvents());
78
        inst = new org.netbeans.core.startup.NbInstaller();
79
        assertEquals(getManifest(littleJar), inst.loadManifest(littleJar));
79
        assertEquals(getManifest(littleJar), inst.loadManifest(littleJar));
80
        assertEquals(getManifest(mediumJar), inst.loadManifest(mediumJar));
80
        assertEquals(getManifest(mediumJar), inst.loadManifest(mediumJar));
81
        assertEquals(getManifest(bigJar), inst.loadManifest(bigJar));
81
        assertEquals(getManifest(bigJar), inst.loadManifest(bigJar));
(-)core.startup/test/unit/src/org/netbeans/core/startup/PlatformDependencySatisfiedTest.java:1.5 (-4 / +1 lines)
Lines 135-145 Link Here
135
        os.close ();
135
        os.close ();
136
        
136
        
137
        
137
        
138
        final FakeEvents ev = new FakeEvents();
138
        ModuleManager mgr = new ModuleManager(new NbInstaller(), new FakeEvents());
139
        org.netbeans.core.startup.NbInstaller installer = new org.netbeans.core.startup.NbInstaller(ev);
140
        ModuleManager mgr = new ModuleManager(installer, ev);
141
        ModuleFormatSatisfiedTest.addOpenideModules(mgr);
139
        ModuleFormatSatisfiedTest.addOpenideModules(mgr);
142
        installer.registerManager(mgr);
143
        mgr.mutexPrivileged().enterWriteAccess();
140
        mgr.mutexPrivileged().enterWriteAccess();
144
        try {
141
        try {
145
            Module m1 = mgr.create(moduleJarFile, null, false, false, false);
142
            Module m1 = mgr.create(moduleJarFile, null, false, false, false);
(-)o.n.core/test/unit/src/org/netbeans/core/lookup/InstanceDataObjectModuleTestHid.java:1.15 (-1 / +1 lines)
Lines 66-72 Link Here
66
    
66
    
67
    protected void setUp() throws Exception {
67
    protected void setUp() throws Exception {
68
        mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
68
        mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
69
        org.netbeans.core.startup.MainLookup.register (new ErrManager ());
69
        org.netbeans.MainLookup.register (new ErrManager ());
70
        mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
70
        mgr = org.netbeans.core.startup.Main.getModuleSystem().getManager();
71
        final File jar1 = toFile (InstanceDataObjectModuleTestHid.class.getResource("data/test1.jar"));
71
        final File jar1 = toFile (InstanceDataObjectModuleTestHid.class.getResource("data/test1.jar"));
72
        final File jar2 = toFile (InstanceDataObjectModuleTestHid.class.getResource("data/test2.jar"));
72
        final File jar2 = toFile (InstanceDataObjectModuleTestHid.class.getResource("data/test2.jar"));

Return to bug 64046