1 11 package org.eclipse.update.internal.core; 12 13 import java.io.*; 14 import java.util.HashMap ; 15 import java.util.Properties ; 16 17 import org.eclipse.update.configurator.*; 18 import org.eclipse.update.core.*; 19 20 29 public class InstallRegistry extends Properties { 30 31 private static final long serialVersionUID = 1L; 32 private File file = null; 33 private final static String REGISTRY = "registry"; private static InstallRegistry instance; 35 36 private HashMap justInstalledPlugins = new HashMap (); 38 39 42 private InstallRegistry() { 43 super(); 44 String configFile = 45 ConfiguratorUtils 46 .getCurrentPlatformConfiguration() 47 .getConfigurationLocation() 48 .getFile(); 49 file = new File(configFile); 50 file = file.getParentFile(); 51 file = new File(file, REGISTRY); 52 restore(); 53 } 54 55 58 public static InstallRegistry getInstance() { 59 if (instance == null) 60 instance = new InstallRegistry(); 61 return instance; 62 } 63 64 68 public boolean restore() { 69 InputStream in = null; 70 boolean loaded = false; 71 clear(); 72 if (!file.exists()) 76 return loaded; 77 try { 78 in = new FileInputStream(file); 79 super.load(in); 80 loaded = true; 81 } catch (IOException e) { 82 UpdateCore.log(e); 83 } finally { 84 if (in != null) 85 try { 86 in.close(); 87 } catch (IOException e) { 88 } 89 } 90 return loaded; 91 } 92 96 public synchronized boolean save() { 97 OutputStream out = null; 98 boolean ret = false; 99 try { 100 out = new FileOutputStream(file); 101 super.store(out, "This is a generated file; do not edit."); ret = true; 103 } catch (IOException e) { 104 UpdateCore.log(e); 105 } finally { 106 try { 107 if (out != null) { 108 out.close(); 109 } 110 } catch (IOException e) { 111 } 112 } 113 return ret; 114 } 115 116 120 public static synchronized void registerFeature(IFeature feature) { 121 String name = "feature_"+feature.getVersionedIdentifier(); if (InstallRegistry.getInstance().get(name) == null) { 123 InstallRegistry.getInstance().put(name, name); 124 InstallRegistry.getInstance().save(); 126 } 127 } 128 129 133 public static synchronized void registerPlugin(IPluginEntry pluginEntry) { 134 String name = "plugin_"+pluginEntry.getVersionedIdentifier(); if (InstallRegistry.getInstance().get(name) == null) { 136 InstallRegistry.getInstance().put(name, name); 137 InstallRegistry.getInstance().save(); 139 } 140 141 InstallRegistry.getInstance().justInstalledPlugins.put(name,name); 143 } 144 145 149 public static synchronized void unregisterFeature(IFeature feature) { 150 String name = "feature_"+feature.getVersionedIdentifier(); InstallRegistry.getInstance().remove(name); 152 } 153 154 158 public static synchronized void unregisterPlugin(IPluginEntry pluginEntry) { 159 String name = "plugin_"+pluginEntry.getVersionedIdentifier(); InstallRegistry.getInstance().remove(name); 161 162 InstallRegistry.getInstance().justInstalledPlugins.remove(name); 164 } 165 166 171 public boolean isPluginJustInstalled(IPluginEntry pluginEntry) { 172 String name = "plugin_"+pluginEntry.getVersionedIdentifier(); return InstallRegistry.getInstance().justInstalledPlugins.get(name) != null; 174 } 175 176 180 public static void cleanup() { 181 InstallRegistry.getInstance().justInstalledPlugins.clear(); 182 } 183 } 184 | Popular Tags |