1 19 20 package org.netbeans.modules.autoupdate; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.logging.Logger ; 28 import java.util.prefs.Preferences ; 29 import org.netbeans.updater.UpdateTracking; 30 import org.openide.LifecycleManager; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileSystem; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.filesystems.Repository; 35 import org.openide.modules.InstalledFileLocator; 36 import org.openide.modules.ModuleInfo; 37 import org.openide.util.Lookup; 38 import org.openide.util.NbPreferences; 39 import org.openide.util.RequestProcessor; 40 import org.openide.windows.WindowManager; 41 42 43 50 class Autoupdater extends Object { 51 52 53 static void restart() { 54 LifecycleManager.getDefault().exit(); 55 } 56 57 58 static void installUpdateChecker( final Runnable updateChecker ) { 59 if (Boolean.getBoolean("netbeans.full.hack") || Boolean.getBoolean("netbeans.close")) { return; 62 } 63 Settings.getShared().getIdeIdentity(); 65 WindowManager.getDefault().invokeWhenUIReady(new Runnable () { 67 public void run () { 68 doInstallUpdateChecker (updateChecker); 69 } 70 }); 71 } 72 73 private static void doInstallUpdateChecker (final Runnable updateChecker) { 74 RequestProcessor.getDefault().post(updateChecker, 5000); 76 } 77 78 private static final Logger LOG = Logger.getLogger ("org.netbeans.modules.autoupdate.Autoupdater"); 80 private static Preferences proxySettingsNode; 81 82 private static synchronized Preferences getProxyPreferences () { 83 if (proxySettingsNode == null) { 84 proxySettingsNode = NbPreferences.root ().node ("/org/netbeans/core"); 85 assert proxySettingsNode != null; 86 } 87 return proxySettingsNode; 88 } 89 90 91 static int getProxyType () { 92 return getProxyPreferences ().getInt ("proxyType", 1); 93 } 94 95 96 static String getUserProxyHost() { 97 return getProxyPreferences ().get ("proxyHttpHost", ""); 98 } 99 100 101 static String getUserProxyPort() { 102 return getProxyPreferences ().get ("proxyHttpPort", ""); 103 } 104 105 106 static void setProxyConfiguration (int proxyType, String host, String port) { 107 getProxyPreferences ().putInt ("proxyType", proxyType); 108 getProxyPreferences ().put ("proxyHttpHost", host); 109 getProxyPreferences ().put ("proxyHttpPort", port); 110 } 111 112 113 static class Support extends Object { 114 115 116 private static final String FILE_SEPARATOR = System.getProperty ("file.separator"); 117 118 119 private static final String UPDATE_DIR = "update"; 121 122 private static final String DOWNLOAD_DIR =UPDATE_DIR + FILE_SEPARATOR + "download"; 124 125 private static final String PATCH_DIR = ModuleUpdate.NBM_LIB + FILE_SEPARATOR + "patches"; 127 128 private static final String KS_FILE = ModuleUpdate.NBM_CORE + FILE_SEPARATOR + "ide.ks"; 130 131 public static final String LOG_FILE_NAME = "update.log"; 133 134 public static final String LATER_FILE_NAME = "install_later.xml"; 136 137 private static final String UPDATE_TEMP = "autoupdateTemp"; 138 139 140 private static FileObject tempDir = null; 141 142 143 private Support() {} 144 145 146 public static ModuleInfo[] getModuleDescriptions() { 147 Collection descs = Lookup.getDefault().lookup(new Lookup.Template(ModuleInfo.class)).allInstances(); 148 return (ModuleInfo[])descs.toArray(new ModuleInfo[descs.size()]); 149 } 150 151 152 public static File getDownloadDirectory (File base) { 153 if (base == null) { 154 base = new File (System.getProperty ("netbeans.user")); 155 } 156 File downloadDirectory = new File (base, DOWNLOAD_DIR); 157 if ( !downloadDirectory.isDirectory() ) { 158 downloadDirectory.mkdirs(); 159 } 160 161 return downloadDirectory; 162 } 163 164 165 public static List getPatchDirectories () { 166 List patches = new ArrayList (); 167 List clusters = UpdateTracking.clusters (true); 168 assert clusters != null : "Clusters cannot be empty."; Iterator it = clusters.iterator (); 170 while (it.hasNext ()) { 171 File dir = (File )it.next (); 172 if (dir.isDirectory ()) { 174 patches.add (new File (dir.getPath () + FILE_SEPARATOR + PATCH_DIR)); 175 } 176 } 177 return patches; 178 } 179 180 181 static File getKSFile () { 182 File ksFileLocated = InstalledFileLocator.getDefault ().locate (KS_FILE, null, true); 207 return ksFileLocated; 208 } 209 210 static File getInstall_Later (File root) { 211 File file = new File (root.getPath () + FILE_SEPARATOR + DOWNLOAD_DIR + FILE_SEPARATOR + LATER_FILE_NAME); 212 return file; 213 } 214 215 static File getTempCopyFile(FileObject original) { 216 File f = null; 217 if ( tempDir == null ) { 218 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 219 tempDir = fs.getRoot().getFileObject( UPDATE_TEMP ); 220 try { 221 if ( tempDir == null ) 222 tempDir = fs.getRoot().createFolder( UPDATE_TEMP ); 223 } catch ( java.io.IOException ioe ) { 224 } 225 } 226 if ( tempDir != null ) 227 try { 228 FileObject fo = tempDir.getFileObject( original.getName(), "nbm" ); if ( fo == null ) 230 fo = FileUtil.copyFile( original, tempDir, original.getName() ); 231 f = FileUtil.toFile( fo ); 232 } catch ( java.io.IOException ioe ) { 233 } 234 return f; 235 } 236 237 static void deleteTempDir() { 238 if ( tempDir == null ) { 239 FileSystem fs = Repository.getDefault().getDefaultFileSystem(); 240 tempDir = fs.getRoot().getFileObject( UPDATE_TEMP ); 241 } 242 if ( tempDir != null ) { 243 try { 244 tempDir.delete(); 245 } catch ( java.io.IOException ioe ) { 246 } 247 } 248 } 249 } 250 } 251 | Popular Tags |