1 11 package org.eclipse.test.internal.performance; 12 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.core.runtime.Plugin; 15 import org.eclipse.core.runtime.Status; 16 import org.eclipse.test.internal.performance.db.DB; 17 import org.eclipse.test.internal.performance.db.Variations; 18 import org.osgi.framework.BundleContext; 19 20 21 24 public class PerformanceTestPlugin extends Plugin { 25 26 public static final String CONFIG= "config"; public static final String BUILD= "build"; 29 private static final String DEFAULT_DB_NAME= "perfDB"; private static final String DEFAULT_DB_USER= "guest"; private static final String DEFAULT_DB_PASSWORD= "guest"; 33 private static final String DB_NAME= "dbname"; private static final String DB_USER= "dbuser"; private static final String DB_PASSWD= "dbpasswd"; 37 40 private static final String ECLIPSE_PERF_DBLOC= "eclipse.perf.dbloc"; private static final String ECLIPSE_PERF_ASSERTAGAINST= "eclipse.perf.assertAgainst"; private static final String ECLIPSE_PERF_CONFIG= "eclipse.perf.config"; 44 47 public static final String PLUGIN_ID= "org.eclipse.test.performance"; 49 50 public static final int INTERNAL_ERROR= 1; 51 52 55 private static PerformanceTestPlugin fgPlugin; 56 57 58 private static boolean fgOldDBInitialized; 59 private static boolean fgOldDB; 61 64 public PerformanceTestPlugin() { 65 super(); 66 fgPlugin= this; 67 } 68 69 static boolean isOldDB() { 70 if (!fgOldDBInitialized) { 71 String loc= getDBLocation(); 72 if (loc != null && loc.indexOf("relengbuildserv") >= 0) fgOldDB= true; 74 fgOldDBInitialized= true; 75 } 76 return fgOldDB; 77 } 78 79 public void stop(BundleContext context) throws Exception { 80 DB.shutdown(); 81 super.stop(context); 82 } 83 84 87 public static PerformanceTestPlugin getDefault() { 88 return fgPlugin; 89 } 90 91 94 public static String getDBLocation() { 95 String dbloc= System.getProperty(ECLIPSE_PERF_DBLOC); 96 if (dbloc != null) { 97 Variations keys= new Variations(); 98 keys.parsePairs(ECLIPSE_PERF_DBLOC + '=' + dbloc); 99 return keys.getProperty(ECLIPSE_PERF_DBLOC); 100 } 101 return null; 102 } 103 104 public static String getDBName() { 105 String dbloc= System.getProperty(ECLIPSE_PERF_DBLOC); 106 if (dbloc != null) { 107 Variations keys= new Variations(); 108 keys.parsePairs(ECLIPSE_PERF_DBLOC + '=' + dbloc); 109 return keys.getProperty(DB_NAME, DEFAULT_DB_NAME); 110 } 111 return DEFAULT_DB_NAME; 112 } 113 114 public static String getDBUser() { 115 String dbloc= System.getProperty(ECLIPSE_PERF_DBLOC); 116 if (dbloc != null) { 117 Variations keys= new Variations(); 118 keys.parsePairs(ECLIPSE_PERF_DBLOC + '=' + dbloc); 119 return keys.getProperty(DB_USER, DEFAULT_DB_USER); 120 } 121 return DEFAULT_DB_USER; 122 } 123 124 public static String getDBPassword() { 125 String dbloc= System.getProperty(ECLIPSE_PERF_DBLOC); 126 if (dbloc != null) { 127 Variations keys= new Variations(); 128 keys.parsePairs(ECLIPSE_PERF_DBLOC + '=' + dbloc); 129 return keys.getProperty(DB_PASSWD, DEFAULT_DB_PASSWORD); 130 } 131 return DEFAULT_DB_PASSWORD; 132 } 133 134 137 public static Variations getVariations() { 138 Variations keys= new Variations(); 139 String configKey= System.getProperty(ECLIPSE_PERF_CONFIG); 140 if (configKey != null) 141 keys.parsePairs(configKey); 142 return keys; 143 } 144 145 149 public static Variations getAssertAgainst() { 150 String assertKey= System.getProperty(ECLIPSE_PERF_ASSERTAGAINST); 151 if (assertKey != null) { 152 Variations keys= getVariations(); 153 if (keys == null) 154 keys= new Variations(); 155 keys.parsePairs(assertKey); 156 return keys; 157 } 158 return null; 159 } 160 161 163 public static void logError(String message) { 164 if (message == null) 165 message= ""; log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, null)); 167 } 168 169 public static void logWarning(String message) { 170 if (message == null) 171 message= ""; log(new Status(IStatus.WARNING, PLUGIN_ID, IStatus.OK, message, null)); 173 } 174 175 public static void log(Throwable e) { 176 log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, "Internal Error", e)); } 178 179 public static void log(IStatus status) { 180 if (fgPlugin != null) { 181 fgPlugin.getLog().log(status); 182 } else { 183 switch (status.getSeverity()) { 184 case IStatus.ERROR: 185 System.err.println("Error: " + status.getMessage()); break; 187 case IStatus.WARNING: 188 System.err.println("Warning: " + status.getMessage()); break; 190 } 191 Throwable exception= status.getException(); 192 if (exception != null) 193 exception.printStackTrace(System.err); 194 } 195 } 196 } 197 | Popular Tags |