1 19 20 package org.netbeans.core.startup; 21 22 24 import java.awt.Component ; 25 import java.awt.Dimension ; 26 import java.io.File ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Collections ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import java.util.Set ; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 import javax.swing.JOptionPane ; 36 import javax.swing.JTextArea ; 37 import org.netbeans.Events; 38 import org.netbeans.Module; 39 import org.netbeans.TopSecurityManager; 40 import org.netbeans.Util; 41 import org.openide.filesystems.FileObject; 42 import org.openide.modules.SpecificationVersion; 43 import org.openide.util.NbBundle; 44 import org.openide.util.NbCollections; 45 import org.openide.util.RequestProcessor; 46 47 51 final class NbEvents extends Events { 52 private Logger logger = Logger.getLogger(NbEvents.class.getName()); 53 54 private int moduleCount; 55 56 private int counter; 57 58 64 protected void logged(final String message, Object [] args) { 65 if (message == PERF_TICK) { 66 StartLog.logProgress( (String )args[0]); 67 } else if (message == PERF_START) { 68 StartLog.logStart( (String )args[0]); 69 } else if (message == PERF_END) { 70 StartLog.logEnd( (String )args[0]); 71 } else if (message == START_CREATE_BOOT_MODULE) { 72 org.netbeans.core.startup.Splash.getInstance().increment(1); 73 } else if (message == START_LOAD_BOOT_MODULES) { 74 setStatusText( 75 NbBundle.getMessage(NbEvents.class, "MSG_start_load_boot_modules")); 76 StartLog.logStart("ModuleSystem.loadBootModules"); } else if (message == START_LOAD) { 78 StartLog.logStart("NbInstaller.load"); } else if (message == FINISH_LOAD_BOOT_MODULES) { 80 setStatusText( 81 NbBundle.getMessage(NbEvents.class, "MSG_finish_load_boot_modules")); 82 StartLog.logEnd( "ModuleSystem.loadBootModules" ); } else if (message == FINISH_LOAD) { 84 StartLog.logEnd("NbInstaller.load"); } else if (message == START_AUTO_RESTORE) { 86 Set modules = (Set )args[0]; 87 if (! modules.isEmpty()) { 88 setStatusText( 89 NbBundle.getMessage(NbEvents.class, "MSG_start_auto_restore")); 90 } 91 } else if (message == FINISH_AUTO_RESTORE) { 92 setStatusText( 93 NbBundle.getMessage(NbEvents.class, "MSG_finish_auto_restore")); 94 } else if (message == START_ENABLE_MODULES) { 95 setStatusText( 96 NbBundle.getMessage(NbEvents.class, "MSG_start_enable_modules")); 97 } else if (message == FINISH_ENABLE_MODULES) { 98 List modules = (List )args[0]; 99 if (! modules.isEmpty()) { 100 dumpModulesList(modules); 101 } 102 setStatusText( 103 NbBundle.getMessage(NbEvents.class, "MSG_finish_enable_modules")); 104 StartLog.logEnd("ModuleManager.enable"); } else if (message == START_DISABLE_MODULES) { 106 setStatusText( 107 NbBundle.getMessage(NbEvents.class, "MSG_start_disable_modules")); 108 } else if (message == FINISH_DISABLE_MODULES) { 109 List modules = (List )args[0]; 110 if (! modules.isEmpty()) { 111 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_finish_disable_modules")); 112 dumpModulesList(modules); 113 } 114 setStatusText( 115 NbBundle.getMessage(NbEvents.class, "MSG_finish_disable_modules")); 116 } else if (message == START_DEPLOY_TEST_MODULE) { 117 setStatusText( 122 "Deploying test module in " + (File )args[0] + "..."); } else if (message == FINISH_DEPLOY_TEST_MODULE) { 124 setStatusText( 125 "Finished deploying test module."); } else if (message == FAILED_INSTALL_NEW) { 127 Set <Module> modules = NbCollections.checkedSetByCopy((Set ) args[0], Module.class, true); 128 { 129 StringBuilder buf = new StringBuilder (NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new")); 130 NbProblemDisplayer.problemMessagesForModules(buf, modules, false); 131 logger.log(Level.INFO, buf.toString()); 132 } 133 { 134 StringBuilder buf = new StringBuilder (NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new")); 135 NbProblemDisplayer.problemMessagesForModules(buf, modules, true); 136 String msg = buf.toString(); 137 notify(msg, true); 138 } 139 setStatusText(""); 140 } else if (message == FAILED_INSTALL_NEW_UNEXPECTED) { 141 Module m = (Module)args[0]; 142 { 144 StringBuffer buf = new StringBuffer (NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new_unexpected", m.getDisplayName())); 145 NbProblemDisplayer.problemMessagesForModules(buf, Collections.singleton(m), false); 146 logger.log(Level.INFO, buf.toString()); 147 } 148 149 { 150 StringBuffer buf = new StringBuffer (NbBundle.getMessage(NbEvents.class, "MSG_failed_install_new_unexpected", m.getDisplayName())); 151 NbProblemDisplayer.problemMessagesForModules(buf, Collections.singleton(m), true); 152 notify(buf.toString(), true); 153 } 154 setStatusText(""); 155 } else if (message == START_READ) { 156 setStatusText( 157 NbBundle.getMessage(NbEvents.class, "MSG_start_read")); 158 StartLog.logStart("ModuleList.readInitial"); } else if (message == MODULES_FILE_SCANNED) { 160 moduleCount = (Integer )args[0]; 161 Splash.getInstance().addToMaxSteps(Math.max(moduleCount + moduleCount/2 - 100, 0)); 162 } else if (message == MODULES_FILE_PROCESSED) { 163 Splash.getInstance().increment(1); 164 if (StartLog.willLog()) { 165 StartLog.logProgress("file " + ((FileObject)args[0]).getNameExt() + " processed"); } 167 } else if (message == FINISH_READ) { 168 if (moduleCount < 100) { 169 Splash.getInstance().increment(moduleCount - 100); 170 } 171 setStatusText( 172 NbBundle.getMessage(NbEvents.class, "MSG_finish_read")); 173 StartLog.logEnd("ModuleList.readInitial"); } else if (message == RESTORE) { 175 setStatusText( 177 NbBundle.getMessage(NbEvents.class, "MSG_restore")); 178 if (++counter < moduleCount / 2) { 179 Splash.getInstance().increment(1); 180 } 181 } else if (message == INSTALL) { 182 setStatusText( 184 NbBundle.getMessage(NbEvents.class, "MSG_install", ((Module)args[0]).getDisplayName())); 185 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_install", ((Module)args[0]).getDisplayName())); 186 } else if (message == UPDATE) { 187 setStatusText( 188 NbBundle.getMessage(NbEvents.class, "MSG_update", ((Module)args[0]).getDisplayName())); 189 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_update", ((Module)args[0]).getDisplayName())); 190 } else if (message == UNINSTALL) { 191 setStatusText( 192 NbBundle.getMessage(NbEvents.class, "MSG_uninstall", ((Module)args[0]).getDisplayName())); 193 } else if (message == LOAD_SECTION) { 194 setStatusText( 196 NbBundle.getMessage(NbEvents.class, "MSG_load_section")); 197 if (++counter < moduleCount / 4) { 198 Splash.getInstance().increment(1); 199 } 200 } else if (message == LOAD_LAYERS) { 201 setStatusText( 202 NbBundle.getMessage(NbEvents.class, "MSG_load_layers")); 203 } else if (message == WRONG_CLASS_LOADER) { 204 if (! Boolean.getBoolean("netbeans.moduleitem.dontverifyclassloader") && Util.err.isLoggable(Level.WARNING)) { Class clazz = (Class )args[1]; 206 StringBuffer b = new StringBuffer (); 208 b.append("The module " + ((Module)args[0]).getDisplayName() + " loaded the class " + clazz.getName() + "\n"); b.append("from the wrong classloader. The expected classloader was " + args[2] + "\n"); b.append("whereas it was actually loaded from " + clazz.getClassLoader() + "\n"); b.append("Usually this means that some classes were in the startup classpath.\n"); b.append("To suppress this message, run with: -J-Dnetbeans.moduleitem.dontverifyclassloader=true"); Util.err.warning(b.toString()); 214 } 215 } else if (message == EXTENSION_MULTIPLY_LOADED) { 216 logger.log(Level.WARNING, "The extension " + (File )args[0] + " may be multiply loaded by modules: " + (Set )args[1] + "; see: http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#class-path"); } else if (message == MISSING_JAR_FILE) { 219 File jar = (File )args[0]; 220 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_missing_jar_file", jar.getAbsolutePath())); 221 } else if (message == CANT_DELETE_ENABLED_AUTOLOAD) { 222 Module m = (Module)args[0]; 223 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_cant_delete_enabled_autoload", m.getDisplayName())); 224 } else if (message == MISC_PROP_MISMATCH) { 225 Module m = (Module)args[0]; 228 String prop = (String )args[1]; 229 Object onDisk = args[2]; 230 Object inMem = args[3]; 231 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_misc_prop_mismatch", new Object [] {m.getDisplayName(), prop, onDisk, inMem})); 232 } else if (message == PATCH) { 233 File f = (File )args[0]; 234 logger.log(Level.INFO, NbBundle.getMessage(NbEvents.class, "TEXT_patch", f.getAbsolutePath())); 235 } 236 } 238 239 242 private void dumpModulesList(Collection modules) { 243 Iterator it = modules.iterator(); 244 if (! it.hasNext()) throw new IllegalArgumentException (); 245 StringBuilder buf = new StringBuilder (modules.size() * 100 + 1); 246 buf.append(NbBundle.getMessage(NbEvents.class, "TEXT_finish_enable_modules")); 247 String lineSep = System.getProperty("line.separator"); 248 buf.append(lineSep); 249 while (it.hasNext()) { 250 Module m = (Module)it.next(); 251 buf.append('\t'); buf.append(m.getCodeName()); 253 buf.append(" ["); SpecificationVersion sv = m.getSpecificationVersion(); 255 if (sv != null) { 256 buf.append(sv); 257 } 258 String iv = m.getImplementationVersion(); 259 if (iv != null) { 260 buf.append(' '); buf.append(iv); 262 } 263 String bv = m.getBuildVersion(); 264 if (bv != null && !bv.equals (iv)) { 265 buf.append(' '); buf.append(bv); 267 } 268 buf.append(']'); buf.append(lineSep); 271 } 272 logger.log(Level.INFO, buf.toString()); 273 } 274 275 private void notify(String text, boolean warn) { 276 if (Boolean.getBoolean("netbeans.full.hack")) { logger.log(Level.INFO, text); 279 } else { 280 new Notifier(text, warn); 282 } 283 } 284 private static final class Notifier implements Runnable { 285 private static int questions; 286 287 private boolean warn; 288 private String text; 289 private static RequestProcessor RP = new RequestProcessor("Notify About Module System"); private Object [] options; 291 private Object value; 292 293 public Notifier(String text, boolean type) { 294 this.warn = type; 295 this.text = text; 296 298 if (questions++ == 0) { 299 this.options = new String [] { 300 NbBundle.getMessage(Notifier.class, "MSG_continue"), 301 NbBundle.getMessage(Notifier.class, "MSG_exit"), 302 }; 303 } 304 305 RequestProcessor.Task t = RP.post(this, 0, Thread.MIN_PRIORITY); 306 307 if (options != null) { 308 t.waitFinished(); 309 } 310 } 311 312 public Object getOption() { 313 return value; 314 } 315 public void run() { 316 int type = warn ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE; 317 String msg = NbBundle.getMessage(Notifier.class, warn ? "MSG_warning" : "MSG_info"); 319 Splash out = Splash.getInstance(); 320 Component c = out.getComponent() == null ? null : out.getComponent(); 321 322 JTextArea area = new JTextArea (); 323 area.setText(text); 324 area.setEditable(false); 325 area.setEnabled(true); 326 area.setOpaque(false); 327 javax.swing.JScrollPane pane = new javax.swing.JScrollPane (area); 328 pane.setPreferredSize(new Dimension (pane.getPreferredSize().width + 50, area.getFont().getSize() * 15)); 329 330 if (options == null) { 331 JOptionPane.showMessageDialog(null, pane, msg, type); 332 } else { 333 int ret = JOptionPane.showOptionDialog(c, pane, msg, 0, type, null, options, options[1]); 334 if (ret == 1 || ret == -1) { TopSecurityManager.exit(1); 336 } 337 } 338 } 339 } 340 341 private static void setStatusText (String msg) { 342 Main.setStatusText (msg); 343 } 344 } 345 | Popular Tags |