1 11 package org.eclipse.ui.internal.about; 12 13 import java.io.BufferedReader ; 14 import java.io.ByteArrayInputStream ; 15 import java.io.ByteArrayOutputStream ; 16 import java.io.IOException ; 17 import java.io.InputStreamReader ; 18 import java.io.PrintWriter ; 19 import java.util.Comparator ; 20 import java.util.Iterator ; 21 import java.util.LinkedList ; 22 import java.util.Properties ; 23 import java.util.SortedSet ; 24 import java.util.TreeSet ; 25 26 import org.eclipse.core.runtime.CoreException; 27 import org.eclipse.core.runtime.IBundleGroup; 28 import org.eclipse.core.runtime.IBundleGroupProvider; 29 import org.eclipse.core.runtime.Platform; 30 import org.eclipse.core.runtime.preferences.IEclipsePreferences; 31 import org.eclipse.core.runtime.preferences.IPreferencesService; 32 import org.eclipse.osgi.util.NLS; 33 import org.eclipse.ui.about.ISystemSummarySection; 34 import org.eclipse.ui.internal.WorkbenchMessages; 35 import org.eclipse.ui.internal.WorkbenchPlugin; 36 import org.eclipse.ui.internal.util.Util; 37 import org.osgi.framework.Bundle; 38 39 46 public class ConfigurationLogDefaultSection implements ISystemSummarySection { 47 48 private static final String ECLIPSE_PROPERTY_PREFIX = "eclipse."; 50 53 public void write(PrintWriter writer) { 54 appendProperties(writer); 55 appendFeatures(writer); 56 appendRegistry(writer); 57 appendUserPreferences(writer); 58 } 59 60 63 private void appendProperties(PrintWriter writer) { 64 writer.println(); 65 writer.println(WorkbenchMessages.SystemSummary_systemProperties); 66 Properties properties = System.getProperties(); 67 SortedSet set = new TreeSet (new Comparator () { 68 public int compare(Object o1, Object o2) { 69 String s1 = (String ) o1; 70 String s2 = (String ) o2; 71 return s1.compareTo(s2); 72 } 73 }); 74 set.addAll(properties.keySet()); 75 Iterator i = set.iterator(); 76 while (i.hasNext()) { 77 String key = (String )i.next(); 78 String value = properties.getProperty(key); 79 80 writer.print(key); 81 writer.print('='); 82 83 if (key.startsWith(ECLIPSE_PROPERTY_PREFIX)) { 85 printEclipseProperty(writer, value); 86 } else if (key.toUpperCase().indexOf("PASSWORD") != -1) { for (int j = 0; j < value.length(); j++) { 89 writer.print('*'); 90 } 91 writer.println(); 92 } else { 93 writer.println(value); 94 } 95 } 96 } 97 98 private static void printEclipseProperty(PrintWriter writer, String value) { 99 String [] lines = Util.getArrayFromList(value, "\n"); for (int i = 0; i < lines.length; ++i) { 101 writer.println(lines[i]); 102 } 103 } 104 105 108 private void appendFeatures(PrintWriter writer) { 109 writer.println(); 110 writer.println(WorkbenchMessages.SystemSummary_features); 111 112 IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); 113 LinkedList groups = new LinkedList (); 114 if (providers != null) { 115 for (int i = 0; i < providers.length; ++i) { 116 IBundleGroup[] bundleGroups = providers[i].getBundleGroups(); 117 for (int j = 0; j < bundleGroups.length; ++j) { 118 groups.add(new AboutBundleGroupData(bundleGroups[j])); 119 } 120 } 121 } 122 AboutBundleGroupData[] bundleGroupInfos = (AboutBundleGroupData[]) groups 123 .toArray(new AboutBundleGroupData[0]); 124 125 AboutData.sortById(false, bundleGroupInfos); 126 127 for (int i = 0; i < bundleGroupInfos.length; ++i) { 128 AboutBundleGroupData info = bundleGroupInfos[i]; 129 String [] args = new String [] { info.getId(), info.getVersion(), 130 info.getName() }; 131 writer.println(NLS.bind(WorkbenchMessages.SystemSummary_featureVersion, args)); 132 } 133 } 134 135 138 private void appendRegistry(PrintWriter writer) { 139 writer.println(); 140 writer.println(WorkbenchMessages.SystemSummary_pluginRegistry); 141 142 Bundle[] bundles = WorkbenchPlugin.getDefault().getBundles(); 143 AboutBundleData[] bundleInfos = new AboutBundleData[bundles.length]; 144 145 for (int i = 0; i < bundles.length; ++i) { 146 bundleInfos[i] = new AboutBundleData(bundles[i]); 147 } 148 149 AboutData.sortById(false, bundleInfos); 150 151 for (int i = 0; i < bundleInfos.length; ++i) { 152 AboutBundleData info = bundleInfos[i]; 153 String [] args = new String [] { info.getId(), info.getVersion(), 154 info.getName(), info.getStateName() }; 155 writer.println(NLS.bind(WorkbenchMessages.SystemSummary_descriptorIdVersionState, args)); 156 } 157 } 158 159 162 private void appendUserPreferences(PrintWriter writer) { 163 IPreferencesService service = Platform.getPreferencesService(); 165 IEclipsePreferences node = service.getRootNode(); 166 ByteArrayOutputStream stm = new ByteArrayOutputStream (); 167 try { 168 service.exportPreferences(node, stm, null); 169 } catch (CoreException e) { 170 writer.println("Error reading preferences " + e.toString()); } 172 173 writer.println(); 175 writer.println(WorkbenchMessages.SystemSummary_userPreferences); 176 177 BufferedReader reader = null; 178 try { 179 ByteArrayInputStream in = new ByteArrayInputStream (stm 180 .toByteArray()); 181 reader = new BufferedReader (new InputStreamReader (in, "8859_1")); char[] chars = new char[8192]; 183 184 while (true) { 185 int read = reader.read(chars); 186 if (read <= 0) { 187 break; 188 } 189 writer.write(chars, 0, read); 190 } 191 } catch (IOException e) { 192 writer.println("Error reading preferences " + e.toString()); } 194 195 } 197 } 198 | Popular Tags |