001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: * faycal.sougrati@francetelecom.com
023: */
024:
025: package salomeTMF_plug.bugzilla;
026:
027: import java.awt.Color;
028: import java.net.URL;
029: import java.util.Observable;
030: import java.util.Observer;
031: import java.util.Properties;
032: import java.util.Vector;
033:
034: import javax.swing.JOptionPane;
035: import javax.swing.JPanel;
036:
037: import org.java.plugin.Plugin;
038: import org.java.plugin.PluginDescriptor;
039: import org.java.plugin.PluginManager;
040: import org.objectweb.salome_tmf.api.Api;
041: import org.objectweb.salome_tmf.api.Util;
042: import org.objectweb.salome_tmf.api.sql.IDataBase;
043: import org.objectweb.salome_tmf.api.sql.ISQLObjectFactory;
044: import org.objectweb.salome_tmf.data.Attachment;
045: import org.objectweb.salome_tmf.data.Environment;
046: import org.objectweb.salome_tmf.data.Execution;
047: import org.objectweb.salome_tmf.data.ExecutionResult;
048: import org.objectweb.salome_tmf.data.Project;
049: import org.objectweb.salome_tmf.data.Test;
050: import org.objectweb.salome_tmf.data.User;
051: import org.objectweb.salome_tmf.ihm.main.IBugJDialog;
052: import org.objectweb.salome_tmf.ihm.main.SalomeTMFContext;
053: import org.objectweb.salome_tmf.ihm.main.plugins.PluginsTools;
054: import org.objectweb.salome_tmf.plugins.core.BugTracker;
055:
056: import salomeTMF_plug.bugzilla.languages.Language;
057:
058: public class BugzillaPlugin extends Plugin implements BugTracker,
059: Observer {
060:
061: //MOVE
062: //JApplet applet = null;
063: Properties cfg_prop = null;
064:
065: final String BUGZILLA_CFG_FILE = "/plugins/bugzilla/cfg/CfgBugzilla.properties";
066: static boolean suspended = true;
067: IDataBase iDB = null;
068: //NEW
069: BugZillaTracker pBugZillaTracker;
070:
071: public BugzillaPlugin(PluginManager arg0, PluginDescriptor arg1) {
072: super (arg0, arg1);
073: }
074:
075: protected void doStart() throws Exception {
076: // TODO Auto-generated method stub
077:
078: }
079:
080: protected void doStop() throws Exception {
081: // TODO Auto-generated method stub
082:
083: }
084:
085: /**
086: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
087: */
088: public void initBugTracker(Object iPlugObject) throws Exception {
089: // Variables initialization
090:
091: User currentUser = null;
092: Project currentProject = null;
093: String bugzilla_host = "";
094: //IDataBase iDB = null;
095:
096: //applet = (JApplet)iPlugObject;
097: currentUser = PluginsTools.getCurrentUser();
098: currentProject = PluginsTools.getCurrentProject();
099:
100: currentProject.registerObserver(this );
101:
102: // Opens bugzilla connexion
103: try {
104: URL _urlBase = SalomeTMFContext.getInstance().getUrlBase();
105: String url_txt = _urlBase.toString();
106: url_txt = url_txt.substring(0, url_txt.lastIndexOf("/"));
107: URL urlBase = new URL(url_txt);
108:
109: // Bugzilla configuration file for DB connexion
110: java.net.URL url_cfg = new java.net.URL(urlBase
111: + BUGZILLA_CFG_FILE);
112: try {
113: cfg_prop = Util.getPropertiesFile(url_cfg);
114: } catch (Exception e) {
115: cfg_prop = Util.getPropertiesFile(BUGZILLA_CFG_FILE);
116: }
117:
118: String driver = cfg_prop.getProperty("DriverJDBC");
119: String url = cfg_prop.getProperty("URLDB_BugZilla");
120: String user = cfg_prop.getProperty("User_BugZilla");
121: String password = cfg_prop.getProperty("Password_BugZilla");
122: String bugzilla_version = cfg_prop
123: .getProperty("BugZilla_Version");
124: if (!Api.isIDE_DEV()) {
125: try {
126: password = org.objectweb.salome_tmf.api.MD5paswd
127: .decryptString(password);
128: } catch (Exception e) {
129: Util
130: .log("[BugzillaPlugin] Clear pwd used for Bugzilla");
131: }
132: }
133:
134: bugzilla_host = cfg_prop.getProperty("URLHTTP_BugZilla");
135: Util.log("[BugzillaPlugin] BUGZILLA open database : "
136: + ", " + driver + ", " + url + ", " + user + ", "
137: + password);
138:
139: ISQLObjectFactory iSQL_OF = Api.getISQLObjectFactory();
140: if (iDB == null) {
141: iDB = iSQL_OF.getInstanceOfDataBase(driver);
142: iDB.open(url, user, password);
143: }
144: SQLUtils.initSQLUtils(iDB);
145:
146: // Bugzilla properties file for SQL statements
147: if (bugzilla_version.trim().equals("2.16")) {
148: pBugZillaTracker = new BugZillaTracker_2_16(iDB,
149: bugzilla_host);
150: } else {
151: pBugZillaTracker = new BugZillaTracker_2_20(iDB,
152: bugzilla_host);
153: }
154: pBugZillaTracker.init(currentUser, currentProject);
155: suspended = false;
156:
157: } catch (Exception E) {
158: E.printStackTrace();
159: SalomeTMFContext.getInstance()
160: .showMessage(
161: Language.getInstance().getText(
162: "Probleme_config"),
163: Language.getInstance().getText(
164: "Plugin_non_charge"),
165: JOptionPane.WARNING_MESSAGE);
166: throw E;
167: }
168:
169: }
170:
171: /**
172: * @return true if projet, and user are stored in other DB (not in salome DB)
173: */
174: public boolean isIndependantTracker() {
175: return true;
176: }
177:
178: /**
179: * @return true if the tracker support ICAL/QSCORE
180: */
181: public boolean isSuportIndicators() {
182: return false;
183: }
184:
185: /**
186: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
187: */
188: public boolean isUserExistsInBugDB() {
189: return pBugZillaTracker.isUserExistsInBugDB();
190: }
191:
192: public void addUser(User user) throws Exception {
193: if (pBugZillaTracker == null) {
194: return;
195: }
196: pBugZillaTracker.addUser(user);
197: }
198:
199: /**
200: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
201: */
202: public void addProject(Project project) throws Exception {
203: if (pBugZillaTracker == null) {
204: return;
205: }
206: pBugZillaTracker.addProject(project);
207: }
208:
209: /**
210: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
211: */
212: public void addEnvironment(Environment environment)
213: throws Exception {
214: if (pBugZillaTracker == null) {
215: return;
216: }
217: pBugZillaTracker.addEnvironment(environment);
218: }
219:
220: /**
221: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
222: */
223: public void updateEnvironment(String old_component,
224: String new_component, String description) throws Exception {
225: if (pBugZillaTracker == null) {
226: return;
227: }
228: pBugZillaTracker.updateEnvironment(old_component,
229: new_component, description);
230: }
231:
232: /**
233: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
234: */
235: public void deleteEnvironment(String environment) throws Exception {
236: if (pBugZillaTracker == null) {
237: return;
238: }
239: pBugZillaTracker.deleteEnvironment(environment);
240: }
241:
242: /**
243: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
244: */
245: public Attachment addBug(String long_desc, String assigned_to,
246: String url_attach, String bug_severity, String short_desc,
247: String bug_OS, String bug_priority, String bug_platform,
248: String bug_reproductibility, Execution pExec,
249: ExecutionResult pExecRes, Test ptest) throws Exception {
250: if (pBugZillaTracker == null) {
251: throw new Exception("Bugtracker is null!");
252: }
253: return pBugZillaTracker.addBug(long_desc, assigned_to,
254: url_attach, bug_severity, short_desc, bug_OS,
255: bug_priority, bug_platform, pExec, pExecRes, ptest);
256: }
257:
258: /**
259: * Modify existing bug représented by pAttach with new values
260: * @param pAttach
261: * @param long_desc
262: * @param assigned_to
263: * @param url_attach
264: * @param bug_severity
265: * @param bug_satus
266: * @param short_desc
267: * @param bug_OS
268: * @param bug_priority
269: * @param bug_platform
270: * @param bug_env
271: * @throws Exception
272: */
273: public void modifyBug(Attachment pAttach, String long_desc,
274: String assigned_to, String url_attach, String bug_severity,
275: String bug_satus, String short_desc, String bug_OS,
276: String bug_priority, String bug_platform, String bug_env,
277: String bug_reproducibility, String bug_resolution)
278: throws Exception {
279: /*TODO*/
280: }
281:
282: public String getBugID(Attachment pAttachment) {
283: if (pBugZillaTracker == null) {
284: return null;
285: }
286: return pBugZillaTracker.getBugID(pAttachment);
287: }
288:
289: /**
290: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
291: */
292: public void showBug(Attachment attach) {
293: // TODO Auto-generated method stub
294: if (pBugZillaTracker == null) {
295: return;
296: }
297: pBugZillaTracker.showBug(attach);
298: }
299:
300: public void showBugInBugTracker(Attachment attach) {
301: if (pBugZillaTracker == null) {
302: return;
303: }
304: pBugZillaTracker.showBug(attach);
305: }
306:
307: /*boolean isExistEnv(String projectName, String envName) throws Exception{
308: boolean ret = true;
309: try {
310: PreparedStatement prep = iDB.prepareStatement(sql_prop.getProperty("SelectComponent"));
311: prep.setString(1, projectName);
312: prep.setString(2, envName.trim());
313: ResultSet stmtRes = prep.executeQuery();
314: if (!stmtRes.next()) {
315: ret = false;
316: }
317: } catch (Exception e) {
318: e.printStackTrace();
319: throw e;
320: }
321: return ret;
322: }*/
323:
324: public JPanel getBugViewPanel(IBugJDialog pIBugJDialog,
325: String actionName, String actionDesc,
326: String actionAwatedRes, String actionEffectiveRes) {
327: return null;
328: }
329:
330: /*public JPanel getStateColorPanel(){
331: return null;
332: }*/
333:
334: public Color getStateDefect(Attachment pAttachment) {
335: return Color.WHITE;
336: }
337:
338: public JPanel getDefectPanelForTests(Vector testSelected) {
339: /* No yet implemùented */
340: return null;
341: }
342:
343: /**
344: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
345: */
346: public void showEnvironmentBugs(Environment env) {
347: if (pBugZillaTracker == null) {
348: return;
349: }
350: pBugZillaTracker.showEnvironmentBugs(env);
351: }
352:
353: /**
354: * @throws Exception
355: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
356: */
357:
358: public int getEnvNbBugs(Environment env, boolean onlyCorretedBugs) {
359: int res = 0;
360: res = getEnvironmentNbBugs(env, CRITICAL, onlyCorretedBugs)
361: + getEnvironmentNbBugs(env, MAJOR, onlyCorretedBugs);
362: return res;
363: }
364:
365: //MOVED
366: public int getEnvironmentNbBugs(Environment env, int severity,
367: boolean onlyCorretedBugs) {
368: if (pBugZillaTracker == null) {
369: return 0;
370: }
371: return pBugZillaTracker.getEnvironmentNbBugs(env, severity,
372: onlyCorretedBugs);
373: }
374:
375: /**
376: * @throws Exception
377: * @see org.objectweb.salome_tmf.plugins.core.BugTracker
378: */
379: //MOVED
380: public String getBugTrackerName() {
381: if (pBugZillaTracker == null) {
382: return "";
383: }
384: return pBugZillaTracker.getBugTrackerName();
385: }
386:
387: public String getBugTrackerAttachDesc() {
388: if (pBugZillaTracker == null) {
389: return "";
390: }
391: return pBugZillaTracker.getBugTrackerAttachDesc();
392: }
393:
394: public void update(Observable o, Object arg) {
395: if (pBugZillaTracker == null) {
396: return;
397: }
398: pBugZillaTracker.update(o, arg);
399: }
400:
401: //MOVED
402: public Vector getBugOSList() {
403: if (pBugZillaTracker == null) {
404: return new Vector();
405: }
406: return pBugZillaTracker.getBugOSList();
407: }
408:
409: // MOVED
410: public Vector getBugPriorityList() {
411: if (pBugZillaTracker == null) {
412: return new Vector();
413: }
414: return pBugZillaTracker.getBugPriorityList();
415: }
416:
417: //MOVED
418: public Vector getBugPlateformList() {
419: if (pBugZillaTracker == null) {
420: return new Vector();
421: }
422: return pBugZillaTracker.getBugPlateformList();
423: }
424:
425: //MOVED
426: public Vector getBugSeverityList() {
427: if (pBugZillaTracker == null) {
428: return new Vector();
429: }
430: return pBugZillaTracker.getBugSeverityList();
431: }
432:
433: //MOVED
434: public Vector getBugTrackerAllUsers() {
435: if (pBugZillaTracker == null) {
436: return new Vector();
437: }
438: return pBugZillaTracker.getBugTrackerAllUsers();
439: }
440:
441: public Vector getBugTrackerStatusList() {
442: Vector list = new Vector();
443: return list;
444: }
445:
446: public boolean isEditableOS() {
447: if (pBugZillaTracker == null) {
448: return false;
449: }
450: return pBugZillaTracker.isEditableOS();
451: }
452:
453: public boolean isEditablePlateForme() {
454: if (pBugZillaTracker == null) {
455: return false;
456: }
457: return pBugZillaTracker.isEditablePlateForme();
458: }
459:
460: public Vector getBugTrackerReproductibilityList() {
461: Vector list = new Vector();
462: return list;
463: }
464:
465: public Vector getBugTrackerResolutionList() {
466: Vector list = new Vector();
467: return list;
468: }
469:
470: public boolean isUsesBugReproducibily() {
471: // TODO Auto-generated method stub
472: return false;
473: }
474:
475: public boolean isUsesBugResolution() {
476: // TODO Auto-generated method stub
477: return false;
478: }
479:
480: public String getAdditionalBugDesc() {
481: // TODO Auto-generated method stub
482: return null;
483: }
484:
485: public void suspend() {
486: if (pBugZillaTracker == null) {
487: return;
488: }
489: try {
490: pBugZillaTracker.closeDB();
491: iDB = null;
492: suspended = true;
493: } catch (Exception e) {
494:
495: }
496: }
497:
498: public void resume() {
499: /*ISQLObjectFactory iSQL_OF = Api.getISQLObjectFactory();
500: iDB = iSQL_OF.getInstanceOfDataBase(driver);
501: iDB.open(url_db,user,pwd);
502: SQLUtils.initSQLUtils(iDB);*/
503: }
504:
505: public int getQsScoreDefectForTest(Test test, Environment env) {
506: return -1;
507: }
508: }
|