1 19 20 package org.netbeans.core.startup; 21 22 import java.beans.Introspector ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.lang.reflect.Method ; 26 import java.net.URL ; 27 import java.util.Iterator ; 28 import javax.swing.SwingUtilities ; 29 import javax.swing.UIManager ; 30 import org.netbeans.Util; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileStateInvalidException; 33 import org.openide.filesystems.Repository; 34 import org.openide.modules.Dependency; 35 import org.openide.modules.InstalledFileLocator; 36 import org.openide.modules.SpecificationVersion; 37 import org.openide.util.Exceptions; 38 import org.openide.util.Lookup; 39 import org.openide.util.NbBundle; 40 import org.openide.util.Utilities; 41 42 45 public final class Main extends Object { 46 47 private static ModuleSystem moduleSystem; 48 49 private static boolean moduleSystemInitialized; 50 51 53 public static void setStatusText (String msg) { 54 Splash.getInstance().print (msg); 55 if (moduleSystemInitialized) { 56 org.netbeans.core.startup.CoreBridge.conditionallyPrintStatus (msg); 57 } 58 } 59 60 63 public static void main (String [] argv) throws Exception { 64 TopThreadGroup tg = new TopThreadGroup ("IDE Main", argv); StartLog.logStart ("Forwarding to topThreadGroup"); tg.start (); 67 StartLog.logProgress ("Main.main finished"); } 69 70 71 private static boolean nbFactoryInitialized; 72 73 public static void initializeURLFactory () { 74 if (!nbFactoryInitialized) { 75 NbURLStreamHandlerFactory fact = new NbURLStreamHandlerFactory(); 76 try { 77 java.net.URL.setURLStreamHandlerFactory(fact); 78 } catch (Error e) { 79 fact.registerUsingReflection(e); 80 } 81 nbFactoryInitialized = true; 82 } 83 } 84 85 89 static void initUICustomizations() { 90 if (!CLIOptions.isGui ()) { 91 return; 92 } 93 94 URL themeURL = null; 95 boolean wantTheme = Boolean.getBoolean ("netbeans.useTheme") || 96 CLIOptions.uiClass != null && CLIOptions.uiClass.getName().indexOf("MetalLookAndFeel") >= 0; 97 98 try { 99 if (wantTheme) { 100 FileObject fo = 102 Repository.getDefault().getDefaultFileSystem().findResource("themes.xml"); if (fo == null) { 104 try { 107 themeURL = new URL ("nbresloc:/org/netbeans/core/startup/resources/themes.xml"); themeURL.openStream().close(); 110 } catch (IOException ex) { 111 themeURL = null; 112 } 113 } else { 114 try { 115 themeURL = fo.getURL(); 116 } catch (FileStateInvalidException fsie) { 117 } 119 } 120 } 121 } finally { 122 CoreBridge.getDefault ().initializePlaf(CLIOptions.uiClass, CLIOptions.getFontSize(), themeURL); 123 } 124 if (CLIOptions.getFontSize() > 0 && "GTK".equals(UIManager.getLookAndFeel().getID())) { Util.err.warning(NbBundle.getMessage(Main.class, 126 "GTK_FONTSIZE_UNSUPPORTED")); } 128 StartLog.logProgress("Fonts updated"); } 130 131 public static ModuleSystem getModuleSystem() { 132 synchronized (Main.class) { 133 if (moduleSystem != null) { 134 return moduleSystem; 135 } 136 137 StartLog.logStart ("Modules initialization"); try { 139 moduleSystem = new ModuleSystem(Repository.getDefault().getDefaultFileSystem()); 140 } catch (IOException ioe) { 141 throw (IllegalStateException ) new IllegalStateException ("Module system cannot be created").initCause(ioe); } 144 StartLog.logProgress ("ModuleSystem created"); } 146 147 moduleSystem.loadBootModules(); 148 moduleSystem.readList(); 149 moduleSystem.restore(); 150 StartLog.logEnd ("Modules initialization"); 152 moduleSystemInitialized = true; 153 154 return moduleSystem; 155 } 156 157 162 public static boolean isInitialized() { 163 return moduleSystemInitialized; 164 } 165 166 167 170 static void start (String [] args) throws SecurityException { 171 StartLog.logEnd ("Forwarding to topThreadGroup"); StartLog.logStart ("Preparation"); 174 System.setProperty ("org.openide.specification.version", "6.2"); System.setProperty ("org.openide.version", "deprecated"); System.setProperty ("org.openide.major.version", "IDE/1"); 181 if (Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.5")) < 0) { System.err.println("The IDE requires JDK 5 or higher to run."); org.netbeans.TopSecurityManager.exit(1); 185 } 186 187 198 String jdkHome = System.getProperty("jdk.home"); 200 if (jdkHome == null) { 201 jdkHome = System.getProperty("java.home"); 203 if (Utilities.isMac()) { 204 jdkHome += File.separator + ".."; } 206 207 System.setProperty("jdk.home", jdkHome); } 209 210 initializeURLFactory(); 212 213 if (System.getProperties ().get ("org.openide.TopManager") == null) { System.setProperty ("org.openide.TopManager.GUI", "true"); System.getProperties().put ( 218 "org.openide.TopManager", "org.netbeans.core.NonGui" ); 222 } 223 224 CLIOptions.initialize(); 225 StartLog.logProgress ("Command line parsed"); 227 228 StartLog.logStart ("XML Factories"); 231 org.netbeans.core.startup.SAXFactoryImpl.install(); 232 org.netbeans.core.startup.DOMFactoryImpl.install(); 233 238 if (CLIOptions.isGui ()) { 239 try { 240 java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(); 241 } catch (java.lang.InternalError exc) { 242 String s = NbBundle.getMessage(Main.class, "EXC_GraphicsStartFails1", exc.getMessage()); 243 System.out.println(s); 244 s = NbBundle.getMessage(Main.class, "EXC_GraphicsStartFails2", CLIOptions.getUserDir() + "/var/log/messages.log"); 245 System.out.println(s); 246 throw exc; 247 } 248 } 249 StartLog.logEnd ("XML Factories"); 251 252 253 org.netbeans.core.startup.InstalledFileLocatorImpl.prepareCache(); 254 255 String [] sysbisp = Introspector.getBeanInfoSearchPath(); 258 String [] nbbisp = new String [] { 259 "org.netbeans.beaninfo", }; 261 String [] allbisp = new String [sysbisp.length + nbbisp.length]; 262 System.arraycopy(nbbisp, 0, allbisp, 0, nbbisp.length); 263 System.arraycopy(sysbisp, 0, allbisp, nbbisp.length, sysbisp.length); 264 Introspector.setBeanInfoSearchPath(allbisp); 265 266 267 try { 268 if ((System.getProperty ("netbeans.full.hack") == null) && (System.getProperty ("netbeans.close") == null)) { 269 if (!handleLicenseCheck()) { 272 org.netbeans.TopSecurityManager.exit(0); 273 } 274 if (!handleImportOfUserDir ()) { 277 org.netbeans.TopSecurityManager.exit(0); 278 } 279 } 280 } catch (Exception e) { 281 Exceptions.printStackTrace(e); 282 } 283 StartLog.logProgress ("License check performed and upgrade wizard consulted"); 285 289 Splash.getInstance().setRunning(true); 290 291 293 Splash.getInstance().print(NbBundle.getMessage(Main.class, "MSG_IDEInit")); 294 295 296 299 assert Repository.getDefault() instanceof NbRepository : "Has to be NbRepository: " + Repository.getDefault(); getModuleSystem (); 301 302 CoreBridge.getDefault().registerPropertyEditors(); 304 StartLog.logProgress ("PropertyEditors registered"); 306 CoreBridge.getDefault().loadSettings(); 307 StartLog.logProgress ("IDE settings loaded"); 309 { 310 Iterator it = Lookup.getDefault().lookupAll(RunLevel.class).iterator(); 311 312 while (it.hasNext ()) { 313 RunLevel level = (RunLevel)it.next (); 314 level.run (); 315 } 316 } 317 318 org.netbeans.Main.finishInitialization(); 319 StartLog.logProgress("Ran any delayed command-line options"); 321 Splash.getInstance().setRunning(false); 322 Splash.getInstance().dispose(); 323 StartLog.logProgress ("Splash hidden"); StartLog.logEnd ("Preparation"); } 326 327 328 private static final Class getKlass(String cls) { 329 try { 330 ClassLoader loader; 331 ModuleSystem ms = moduleSystem; 332 if (ms != null) { 333 loader = ms.getManager ().getClassLoader (); 334 } else { 335 loader = Main.class.getClassLoader (); 336 } 337 338 return Class.forName(cls, false, loader); 339 } catch (ClassNotFoundException e) { 340 throw new NoClassDefFoundError (e.getLocalizedMessage()); 341 } 342 } 343 344 349 static boolean handleImportOfUserDir () { 350 class ImportHandler implements Runnable { 351 private File installed = new File (new File (CLIOptions.getUserDir (), "var"), "imported"); private String classname; 353 private boolean executedOk; 354 355 public boolean shouldDoAnImport () { 356 classname = System.getProperty ("netbeans.importclass"); 358 return classname != null && !installed.exists (); 359 } 360 361 362 public void run() { 363 try { 366 Class <?> clazz = getKlass (classname); 367 368 Method showMethod = clazz.getMethod( "main", String [].class ); showMethod.invoke (null, new Object [] { 371 new String [0] 372 }); 373 executedOk = true; 374 } catch (java.lang.reflect.InvocationTargetException ex) { 375 if (ex.getTargetException () instanceof org.openide.util.UserCancelException) { 377 executedOk = true; 378 } else { 379 ex.printStackTrace(); 380 } 381 } catch (Exception e) { 382 e.printStackTrace(); 384 } catch (LinkageError e) { 385 e.printStackTrace(); 387 } 388 } 389 390 391 public boolean canContinue () { 392 if (shouldDoAnImport ()) { 393 try { 394 SwingUtilities.invokeAndWait (this); 395 if (executedOk) { 396 installed.getParentFile ().mkdirs (); 399 installed.createNewFile (); 400 return true; 401 } else { 402 return false; 403 } 404 } catch (IOException ex) { 405 ex.printStackTrace(); 407 return true; 408 } catch (java.lang.reflect.InvocationTargetException ex) { 409 return false; 410 } catch (InterruptedException ex) { 411 ex.printStackTrace(); 412 return false; 413 } 414 } else { 415 return true; 417 } 418 } 419 } 420 421 422 ImportHandler handler = new ImportHandler (); 423 424 return handler.canContinue (); 425 } 426 427 432 static boolean handleLicenseCheck () { 433 class LicenseHandler implements Runnable { 434 private String classname; 435 private boolean executedOk; 436 437 438 public boolean shouldDisplayLicense () { 439 File f = InstalledFileLocator.getDefault().locate("var/license_accepted",null,false); if (f != null) { 441 return false; 442 } 443 classname = System.getProperty("netbeans.accept_license_class"); return (classname != null); 445 } 446 447 public void run() { 448 try { 451 Class <?> clazz = getKlass (classname); 452 453 Method showMethod = clazz.getMethod("showLicensePanel"); showMethod.invoke (null, new Object [] {}); 455 executedOk = true; 456 File f = new File (new File (CLIOptions.getUserDir(), "var"), "license_accepted"); if (!f.exists()) { 459 f.getParentFile().mkdirs(); 460 try { 461 f.createNewFile(); 462 } catch (IOException exc) { 463 exc.printStackTrace(); 464 } 465 } 466 } catch (java.lang.reflect.InvocationTargetException ex) { 467 if (ex.getTargetException() instanceof org.openide.util.UserCancelException) { 469 executedOk = false; 470 } else { 471 ex.printStackTrace(); 472 } 473 } catch (Exception ex) { 474 ex.printStackTrace(); 476 } catch (LinkageError ex) { 477 ex.printStackTrace(); 479 } 480 } 481 482 public boolean canContinue () { 483 if (shouldDisplayLicense()) { 484 try { 485 SwingUtilities.invokeAndWait(this); 486 if (executedOk) { 487 return true; 488 } else { 489 return false; 490 } 491 } catch (java.lang.reflect.InvocationTargetException ex) { 492 return false; 493 } catch (InterruptedException ex) { 494 ex.printStackTrace(); 495 return false; 496 } 497 } else { 498 return true; 500 } 501 } 502 } 503 504 LicenseHandler handler = new LicenseHandler (); 505 506 return handler.canContinue (); 507 } 508 } 509 | Popular Tags |