KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > PerformanceTestPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
22  * @since 3.1
23  */

24 public class PerformanceTestPlugin extends Plugin {
25     
26     public static final String JavaDoc CONFIG= "config"; //$NON-NLS-1$
27
public static final String JavaDoc BUILD= "build"; //$NON-NLS-1$
28

29     private static final String JavaDoc DEFAULT_DB_NAME= "perfDB"; //$NON-NLS-1$
30
private static final String JavaDoc DEFAULT_DB_USER= "guest"; //$NON-NLS-1$
31
private static final String JavaDoc DEFAULT_DB_PASSWORD= "guest"; //$NON-NLS-1$
32

33     private static final String JavaDoc DB_NAME= "dbname"; //$NON-NLS-1$
34
private static final String JavaDoc DB_USER= "dbuser"; //$NON-NLS-1$
35
private static final String JavaDoc DB_PASSWD= "dbpasswd"; //$NON-NLS-1$
36

37     /*
38      * New properties
39      */

40     private static final String JavaDoc ECLIPSE_PERF_DBLOC= "eclipse.perf.dbloc"; //$NON-NLS-1$
41
private static final String JavaDoc ECLIPSE_PERF_ASSERTAGAINST= "eclipse.perf.assertAgainst"; //$NON-NLS-1$
42
private static final String JavaDoc ECLIPSE_PERF_CONFIG= "eclipse.perf.config"; //$NON-NLS-1$
43

44     /**
45      * The plug-in ID
46      */

47     public static final String JavaDoc PLUGIN_ID= "org.eclipse.test.performance"; //$NON-NLS-1$
48

49     /** Status code describing an internal error */
50     public static final int INTERNAL_ERROR= 1;
51
52     /**
53      * The shared instance.
54      */

55     private static PerformanceTestPlugin fgPlugin;
56     
57     /* temporary code */
58     private static boolean fgOldDBInitialized;
59     private static boolean fgOldDB; // true if we are talking to the old perfDB in Ottawa
60

61     /**
62      * The constructor.
63      */

64     public PerformanceTestPlugin() {
65         super();
66         fgPlugin= this;
67     }
68     
69     static boolean isOldDB() {
70         if (!fgOldDBInitialized) {
71             String JavaDoc loc= getDBLocation();
72             if (loc != null && loc.indexOf("relengbuildserv") >= 0) //$NON-NLS-1$
73
fgOldDB= true;
74             fgOldDBInitialized= true;
75         }
76         return fgOldDB;
77     }
78     
79     public void stop(BundleContext context) throws Exception JavaDoc {
80         DB.shutdown();
81         super.stop(context);
82     }
83         
84     /*
85      * Returns the shared instance.
86      */

87     public static PerformanceTestPlugin getDefault() {
88         return fgPlugin;
89     }
90         
91     /*
92      * -Declipse.perf.dbloc=net://localhost
93      */

94     public static String JavaDoc getDBLocation() {
95         String JavaDoc 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 JavaDoc getDBName() {
105         String JavaDoc 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 JavaDoc getDBUser() {
115         String JavaDoc 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 JavaDoc getDBPassword() {
125         String JavaDoc 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     /*
135      * -Declipse.perf.config=<varname1>=<varval1>;<varname2>=<varval2>;...;<varnameN>=<varvalN>
136      */

137     public static Variations getVariations() {
138         Variations keys= new Variations();
139         String JavaDoc configKey= System.getProperty(ECLIPSE_PERF_CONFIG);
140         if (configKey != null)
141             keys.parsePairs(configKey);
142         return keys;
143     }
144
145     /*
146      * -Declipse.perf.assertAgainst=<varname1>=<varval1>;<varname2>=<varval2>;...;<varnameN>=<varvalN>
147      * Returns null if assertAgainst property isn't defined.
148      */

149     public static Variations getAssertAgainst() {
150         String JavaDoc 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     // logging
162

163     public static void logError(String JavaDoc message) {
164         if (message == null)
165             message= ""; //$NON-NLS-1$
166
log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, message, null));
167     }
168
169     public static void logWarning(String JavaDoc message) {
170         if (message == null)
171             message= ""; //$NON-NLS-1$
172
log(new Status(IStatus.WARNING, PLUGIN_ID, IStatus.OK, message, null));
173     }
174
175     public static void log(Throwable JavaDoc e) {
176         log(new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, "Internal Error", e)); //$NON-NLS-1$
177
}
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()); //$NON-NLS-1$
186
break;
187             case IStatus.WARNING:
188                 System.err.println("Warning: " + status.getMessage()); //$NON-NLS-1$
189
break;
190             }
191             Throwable JavaDoc exception= status.getException();
192             if (exception != null)
193                 exception.printStackTrace(System.err);
194         }
195     }
196 }
197
Popular Tags