|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.autoupdate; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.IOException; import java.lang.reflect.Method; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import javax.swing.SwingUtilities; import org.netbeans.updater.UpdateTracking; import org.openide.ErrorManager; import org.openide.LifecycleManager; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; import org.openide.filesystems.Repository; import org.openide.modules.InstalledFileLocator; import org.openide.modules.ModuleInfo; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; import org.openide.util.SharedClassObject; import org.openide.windows.WindowManager; /** This singleton class is a skeleton for running autoupdate, it also * contains all communication with core of IDE implementation. This * communication is handled by org.netbeans.core.UpdateSupport * on the side of IDE Core implementation. * * @author Petr Hrebejk */ class Autoupdater extends Object { /** Is the autoupdate running ? */ private static boolean isRunning = false; /** Getter for static property isRunning */ static boolean isRunning() { return isRunning; } /** Setter for static property isRunning */ static void setRunning( boolean isRunning ) { Autoupdater.isRunning = isRunning; } /** Restarts IDE in order to run Updater */ static void restart() { LifecycleManager.getDefault().exit(); } /** Installs autoupdate checker */ static void installUpdateChecker( final Runnable updateChecker ) { // XXX probably not ideal but should work for now... if (! Boolean.getBoolean("netbeans.full.hack") && ! Boolean.getBoolean("netbeans.close")) { // NOI18N // Just wait for GUI to pop up, whatever... l = new WindowListener () { public void windowOpened(WindowEvent e) { doInstallUpdateChecker (updateChecker); } public void windowClosing(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} }; // WindowsAPI is required to be called from AWT thread only SwingUtilities.invokeLater (new Runnable () { public void run () { WindowManager.getDefault ().getMainWindow ().addWindowListener (l); } }); } } private static WindowListener l; private static void doInstallUpdateChecker (final Runnable updateChecker) { // bugfix #43655, postpone the connect to AU till the main window is opened RequestProcessor.getDefault().post(updateChecker, 5000); WindowManager.getDefault ().getMainWindow ().removeWindowListener (l); } // Try to avoid referring directly to IDESettings. // If we can in fact find IDESettings and all appropriate methods, then we // use them. This means proxy config etc. will be properly persisted in // the system option. If something goes wrong, log it quietly and revert // to just setting the system properties (valid just for the session duration). private static Object settingsInstance; private static Method mGetUseProxy, mSetUseProxy, mGetProxyHost, mSetProxyHost, mGetProxyPort, mSetProxyPort; private static boolean useReflection() { initProxyMethodsMaybe(); return mSetProxyPort != null; } private static boolean reflectionAlreadyTried = false; private static synchronized void initProxyMethodsMaybe() { if (reflectionAlreadyTried) return; reflectionAlreadyTried = true; try { ClassLoader l = (ClassLoader)Lookup.getDefault().lookup(ClassLoader.class); Class clazz = l.loadClass("org.netbeans.core.IDESettings"); // NOI18N settingsInstance = SharedClassObject.findObject(clazz, true); mGetUseProxy = clazz.getMethod("getUseProxy", null); // NOI18N mSetUseProxy = clazz.getMethod("setUseProxy", new Class[] {Boolean.TYPE}); // NOI18N mGetProxyHost = clazz.getMethod("getProxyHost", null); // NOI18N mSetProxyHost = clazz.getMethod("setProxyHost", new Class[] {String.class}); // NOI18N mGetProxyPort = clazz.getMethod("getProxyPort", null); // NOI18N mSetProxyPort = clazz.getMethod("setProxyPort", new Class[] {String.class}); // NOI18N } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); // OK, use system properties rather than reflection. } } private static final String PROXY_HOST = "http.proxyHost"; // NOI18N private static final String PROXY_PORT = "http.proxyPort"; // NOI18N /** Gets proxy usage */ static boolean isUseProxy() { if (useReflection()) { try { return ((Boolean)mGetUseProxy.invoke(settingsInstance, new Object[0])).booleanValue(); } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); return false; } } else { return System.getProperty(PROXY_HOST) != null; } } /** Gets Proxy Host */ static String getProxyHost() { if (useReflection()) { try { return (String)mGetProxyHost.invoke(settingsInstance, new Object[0]); } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); return null; } } else { return System.getProperty(PROXY_HOST); } } /** Gets Proxy Port */ static String getProxyPort() { if (useReflection()) { try { return (String)mGetProxyPort.invoke(settingsInstance, new Object[0]); } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); return null; } } else { return System.getProperty(PROXY_PORT); } } /** Sets the whole proxy configuration */ static void setProxyConfiguration( boolean use, String host, String port ) { if (useReflection()) { try { mSetUseProxy.invoke(settingsInstance, new Object[] {use ? Boolean.TRUE : Boolean.FALSE}); mSetProxyHost.invoke(settingsInstance, new Object[] {host}); mSetProxyPort.invoke(settingsInstance, new Object[] {port}); } catch (Exception e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } } else { if (use) { System.setProperty(PROXY_HOST, host); System.setProperty(PROXY_PORT, port); } else { System.setProperty(PROXY_HOST, ""); // NOI18N System.setProperty(PROXY_PORT, ""); // NOI18N } } } /** Singleton support class for getting directories */ static class Support extends Object { /** Platform dependent file name separator */ private static final String FILE_SEPARATOR = System.getProperty ("file.separator"); /** Relative name of update directory */ private static final String UPDATE_DIR = "update"; // NOI18N /** Relative name of directory where the .NBM files are downloaded */ private static final String DOWNLOAD_DIR =UPDATE_DIR + FILE_SEPARATOR + "download"; // NOI18N /** Relative name of directory where the patch files are stored */ private static final String PATCH_DIR = "lib" + FILE_SEPARATOR + "patches"; // NOI18N /** Relative name of key store file */ private static final String KS_FILE = "core" + FILE_SEPARATOR + "ide.ks"; // NOI18N /** The name of the log file */ public static final String LOG_FILE_NAME = "update.log"; // NOI18N /** The name of the install_later file */ public static final String LATER_FILE_NAME = "install_later.xml"; // NOI18N /** Relative name of temp directory */ private static final String UPDATE_TEMP = "autoupdateTemp"; /** File representing the download directory */ private static File downloadDirectory = null; /** File representing the update directory */ private static File updateDirectory = null; private static File nbDirectory = null; /** File representing the central patch directory */ private static File centralPatchDirectory = null; /** File representing the users patch directory */ private static File userPatchDirectory = null; /** The file with cenral KeySotre */ private static File centralKSFile = null; /** The file with users KeySotre */ private static File userKSFile = null; /** File object representing the temp directory */ private static FileObject tempDir = null; /** Disable instantiation */ private Support() {} /** Retruns array of module descriptions of installed modules */ public static ModuleInfo[] getModuleDescriptions() { Collection descs = Lookup.getDefault().lookup(new Lookup.Template(ModuleInfo.class)).allInstances(); return (ModuleInfo[])descs.toArray(new ModuleInfo[descs.size()]); } /** The directory where to download the distribution files of modules */ public static File getDownloadDirectory (File base) { if (base == null) { base = new File (System.getProperty ("netbeans.user")); } File downloadDirectory = new File (base, DOWNLOAD_DIR); if ( !downloadDirectory.isDirectory() ) { downloadDirectory.mkdirs(); } return downloadDirectory; } /** Gets the central directory of patches */ public static List/* |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.