1 19 20 package org.netbeans.core.startup; 21 22 import java.beans.PropertyVetoException ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.StringTokenizer ; 28 29 import org.openide.filesystems.*; 30 31 import org.netbeans.core.startup.layers.SessionManager; 32 import org.openide.util.NbBundle; 33 34 36 public final class NbRepository extends Repository { 37 38 static final String SYSTEM_FOLDER = "config"; 40 43 public NbRepository () { 44 super (createDefaultFileSystem()); 45 Main.initializeURLFactory (); 47 } 48 49 51 private static FileSystem createDefaultFileSystem () { 52 String systemDir = System.getProperty("system.dir"); 54 if (systemDir != null) { 55 57 try { 58 return SessionManager.getDefault().create(new File (systemDir), null, new File [0]); 59 } catch (IOException ex) { 60 ex.printStackTrace(); 61 throw new InternalError (); 62 } catch (PropertyVetoException ex) { 63 ex.printStackTrace(); 64 throw new InternalError (); 65 } 66 } 67 68 File u = null; 69 File h = null; 70 List <File > extradirs = new ArrayList <File >(); 71 String homeDir = CLIOptions.getHomeDir (); 72 if (homeDir != null) { 73 76 File homeDirFile = new File (CLIOptions.getHomeDir ()); 77 if (!homeDirFile.exists ()) { 78 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome_notexists")); 79 doExit (2); 80 } 81 if (!homeDirFile.isDirectory ()) { 82 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome1")); 83 doExit (3); 84 } 85 86 h = new File (homeDirFile, SYSTEM_FOLDER); 87 88 String nbdirs = System.getProperty("netbeans.dirs"); 90 if (nbdirs != null) { 91 StringTokenizer tok = new StringTokenizer (nbdirs, File.pathSeparator); 92 while (tok.hasMoreTokens()) { 93 File f = new File (tok.nextToken(), SYSTEM_FOLDER); 94 if (f.isDirectory()) { 95 extradirs.add(f); 96 } 97 } 98 } 99 } 100 String ud = CLIOptions.getUserDir (); 101 if (!ud.equals("memory")) { File userDirFile = new File (ud); 103 if (!userDirFile.exists ()) { 104 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome2")); 105 doExit (4); 106 } 107 if (!userDirFile.isDirectory ()) { 108 System.err.println (NbBundle.getMessage(NbRepository.class, "CTL_Netbeanshome3")); 109 doExit (5); 110 } 111 u = new File (userDirFile, SYSTEM_FOLDER); 112 } 113 114 Exception exc; 115 try { 116 return SessionManager.getDefault().create(u, h, extradirs.toArray(new File [extradirs.size()])); 117 } catch (IOException ex) { 118 exc = ex; 119 } catch (PropertyVetoException ex) { 120 exc = ex; 121 } catch (RuntimeException ex) { 122 exc = ex; 123 } 124 125 exc.printStackTrace (); 126 Object [] arg = new Object [] {systemDir}; 127 System.err.println (new java.text.MessageFormat ( 128 NbBundle.getMessage(NbRepository.class, "CTL_Cannot_mount_systemfs") 129 ).format(arg)); 130 doExit (3); 131 return null; 132 } 133 134 135 139 private static void doExit (int value) { 140 org.netbeans.TopSecurityManager.exit(value); 141 } 142 143 } 144 | Popular Tags |