0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.plugins;
0025:
0026: import java.io.File;
0027: import java.net.URL;
0028: import java.util.HashMap;
0029: import java.util.Iterator;
0030: import java.util.Map;
0031: import java.util.Properties;
0032: import java.util.StringTokenizer;
0033: import java.util.Vector;
0034:
0035: import javax.swing.JMenu;
0036:
0037: import org.apache.commons.logging.Log;
0038: import org.apache.commons.logging.LogFactory;
0039: import org.apache.log4j.PropertyConfigurator;
0040: import org.java.plugin.Extension;
0041: import org.java.plugin.ExtensionPoint;
0042: import org.java.plugin.IntegrityCheckReport;
0043: import org.java.plugin.Library;
0044: import org.java.plugin.Plugin;
0045: import org.java.plugin.PluginDescriptor;
0046: import org.java.plugin.PluginManager;
0047: import org.java.plugin.IntegrityCheckReport.ReportItem;
0048: import org.objectweb.salome_tmf.api.Api;
0049: import org.objectweb.salome_tmf.api.Util;
0050: import org.objectweb.salome_tmf.ihm.main.SalomeTMFPanels;
0051: import org.objectweb.salome_tmf.ihm.main.plugins.PluginsTools;
0052: import org.objectweb.salome_tmf.plugins.core.Admin;
0053: import org.objectweb.salome_tmf.plugins.core.BugTracker;
0054: import org.objectweb.salome_tmf.plugins.core.Common;
0055: import org.objectweb.salome_tmf.plugins.core.ReqManager;
0056:
0057: //import org.objectweb.salome_tmf.data.TestData;
0058:
0059: //import salome.ihm.UICompCst;
0060: //import salome.ihm.SalomeTMF;
0061:
0062: /**
0063: * Class for JPF management
0064: */
0065: public class JPFManager implements PluginConstants {
0066:
0067: static java.net.URL urlBase = null;
0068:
0069: // Debug
0070: private static Log log;
0071:
0072: private PluginManager pluginManager = null;
0073:
0074: private PluginClassLoader pPluginClassLoader;
0075:
0076: //IPlugObject salomeContextTMF = null;
0077:
0078: /** Cretaes a new instance of JPFManager */
0079: public JPFManager() {
0080: pPluginClassLoader = new PluginClassLoader(this .getClass()
0081: .getClassLoader());
0082: }
0083:
0084: public PluginClassLoader getClassLoader() {
0085: return pPluginClassLoader;
0086: }
0087:
0088: /**
0089: * JPF initialisation
0090: *
0091: * @param _urlBase
0092: * Applet's URL in the server
0093: */
0094: public void startJPF(IPlugObject salomeTMF, URL urlBase,
0095: Map UIComponentsMap) {
0096: //public void startJPF(SalomeTMF VT,Map UIComponentsMap) {
0097: //salomeContextTMF = salomeTMF;
0098: try {
0099: //URL _urlBase = VT.getDocumentBase();
0100: URL _urlBase = urlBase;
0101:
0102: String url_txt = _urlBase.toString();
0103: url_txt = url_txt.substring(0, url_txt.lastIndexOf("/"));
0104: urlBase = new java.net.URL(url_txt);
0105:
0106: // JPF's configuration file
0107: java.net.URL url_server = new java.net.URL(urlBase
0108: + CONFIG_JPF_FILE_PATH);
0109: Properties props = null;
0110:
0111: try {
0112: props = Util.getPropertiesFile(url_server);
0113: } catch (Exception e) {
0114: System.out
0115: .println("WARNING JAR FILE PLUGINS PROPERTIES SELECTED "
0116: + e);
0117: props = Util.getPropertiesFile(CONFIG_JPF_FILE_PATH);
0118: }
0119:
0120: // SI DEBUG METTRE LE REPERTOIRE PHYSIQUE !!!
0121: String appliRoot = null;
0122:
0123: appliRoot = urlBase.toString() + "/";
0124:
0125: /*if (Api.IDE_DEV) {
0126: //appliRoot = new File("/org/objectweb/salome_tmf/").toURL().toString();
0127: } else {
0128: appliRoot = urlBase.toString() + "/";
0129: }*/
0130:
0131: // Logging system initialization
0132: // Logs will be stored in ${tmpDir}/logs where ${tmpDir} is the
0133: // system
0134: // temp directory
0135: if (Api.isDEBUG()) {
0136: Properties sys = System.getProperties();
0137: // Temp directory for log system
0138: String tmpDir = sys.getProperty("java.io.tmpdir");
0139:
0140: props.setProperty("tmpDir", tmpDir);
0141: try {
0142: File logFolder = new File(tmpDir + "logs");
0143: logFolder.mkdir();
0144: } catch (Exception e) {
0145: //System.out.println("Failed to create log folder \"tmpDir/logs\"");
0146: e.printStackTrace();
0147: }
0148:
0149: PropertyConfigurator.configure(props);
0150: log = LogFactory.getLog(JPFManager.class);
0151: log.info("logging system initialized");
0152: }
0153:
0154: // Pamameters for PluginManager
0155: StringTokenizer PluginsFolders = new StringTokenizer(props
0156: .getProperty(PARAM_PLUGINS_FOLDERS), ",", false);
0157: Map pluginLocations = new HashMap();
0158:
0159: for (; PluginsFolders.hasMoreTokens();) {
0160: String currentPlgFolder = appliRoot
0161: + PluginsFolders.nextToken().trim();
0162:
0163: Util.log("plug-ins folder - " + currentPlgFolder);
0164:
0165: StringTokenizer PluginsList = new StringTokenizer(props
0166: .getProperty(PARAM_PLUGINS_LIST), ",", false);
0167:
0168: for (; PluginsList.hasMoreTokens();) {
0169: String currentPlg = currentPlgFolder + "/"
0170: + PluginsList.nextToken().trim();
0171:
0172: String plgManifest = "plugin.xml";
0173: if (Api.isIDE_DEV())
0174: plgManifest = "pluginDBG.xml";
0175: try {
0176: pluginLocations.put(new URL(currentPlg + "/"
0177: + plgManifest), new URL(currentPlg));
0178: } catch (Exception e) {
0179: e.printStackTrace();
0180: }
0181: }
0182: }
0183:
0184: // New instance of PluginManager
0185: pluginManager = PluginManager
0186: .createStandardManager(pluginLocations);
0187:
0188: // Plugins integrity
0189: Util.log("[JPFManager] Check plugins integrity");
0190:
0191: IntegrityCheckReport integrityCheckReport = pluginManager
0192: .getRegistry().checkIntegrity(
0193: pluginManager.getPathResolver());
0194: if (Api.isDEBUG()) {
0195: log.info("integrity check done: errors - "
0196: + integrityCheckReport.countErrors()
0197: + ", warnings - "
0198: + integrityCheckReport.countWarnings());
0199: }
0200:
0201: if (integrityCheckReport.countErrors() != 0) {
0202: //throw new Exception("plug-ins integrity check failed");
0203: Iterator it = integrityCheckReport.getItems()
0204: .iterator();
0205: while (it.hasNext()) {
0206: ReportItem ri = (ReportItem) it.next();
0207: if (ri.getCode() != 0) {
0208: Util.log("[JPFManager Error] "
0209: + ri.getMessage());
0210: }
0211: }
0212: salomeTMF
0213: .showMessage("Problème lors du chargement des plugins.\n"
0214: + "Certains plugins ne fonctionneront pas normalement");
0215: }
0216:
0217: if (Api.isDEBUG())
0218: log
0219: .trace(integrityCheckReport2str(integrityCheckReport));
0220:
0221: // Running the "core" plugin
0222: Util.log("[JPFManager] Running the core plugin");
0223: Plugin corePlugin = pluginManager.getPlugin("core");
0224:
0225: //
0226: //pPluginClassLoader = pluginManager.getPluginClassLoader(corePlugin.getDescriptor());
0227:
0228: if (corePlugin == null) {
0229: //throw new Exception("can't get plug-in core");
0230: salomeTMF
0231: .showMessage("Problème lors du chargement du core plugin.\n"
0232: + "Les plugins ne pourront pas être chargés");
0233: }
0234:
0235: // Extension points initialization
0236: Util.log("[JPFManager] Extension points initialization");
0237: ExtensionPoint Common = (ExtensionPoint) corePlugin
0238: .getClass().getMethod("getCommonExtPoint",
0239: new Class[] {}).invoke(corePlugin,
0240: new Object[] {});
0241:
0242: ExtensionPoint testDriver = (ExtensionPoint) corePlugin
0243: .getClass().getMethod("getTestDriverExtPoint",
0244: new Class[] {}).invoke(corePlugin,
0245: new Object[] {});
0246:
0247: ExtensionPoint scriptEngine = (ExtensionPoint) corePlugin
0248: .getClass().getMethod("getScriptEngineExtPoint",
0249: new Class[] {}).invoke(corePlugin,
0250: new Object[] {});
0251:
0252: ExtensionPoint bugTracker = (ExtensionPoint) corePlugin
0253: .getClass().getMethod("getBugTrackerExtPoint",
0254: new Class[] {}).invoke(corePlugin,
0255: new Object[] {});
0256:
0257: ExtensionPoint reqManager = (ExtensionPoint) corePlugin
0258: .getClass().getMethod("getReqManagerExtPoint",
0259: new Class[] {}).invoke(corePlugin,
0260: new Object[] {});
0261:
0262: ExtensionPoint XMLPrinters = (ExtensionPoint) corePlugin
0263: .getClass().getMethod("getXMLPrinterExtPoint",
0264: new Class[] {}).invoke(corePlugin,
0265: new Object[] {});
0266:
0267: // Common plugins activation
0268: Util.log("[JPFManager] Common plugins activation");
0269: activateCommonsInStaticUIComps(salomeTMF, Common,
0270: UIComponentsMap);
0271:
0272: // Bug Tracking plugins activation
0273: Util.log("[JPFManager] Bug tracking plugins activation");
0274: activateBugTrackingPlugins(salomeTMF, bugTracker);
0275:
0276: // ReqManager plugins activation
0277: Util.log("[JPFManager] Requirement plugins activation");
0278: activateRegManagerPlugins(salomeTMF, reqManager);
0279:
0280: // The application needs some JPF parameters
0281: Util
0282: .log("[JPFManager] The application needs some JPF parameters");
0283: salomeTMF.init_Component(pluginManager, Common, testDriver,
0284: scriptEngine, bugTracker, reqManager);
0285:
0286: ExtensionPoint pExtsionTestDriver = (ExtensionPoint) corePlugin
0287: .getClass().getMethod("getTestDriverExtPoint",
0288: new Class[] {}).invoke(corePlugin,
0289: new Object[] {});
0290:
0291: ExtensionPoint pExtsionScriptEngine = (ExtensionPoint) corePlugin
0292: .getClass().getMethod("getScriptEngineExtPoint",
0293: new Class[] {}).invoke(corePlugin,
0294: new Object[] {});
0295:
0296: initExtsionTestDriver(salomeTMF, pExtsionTestDriver);
0297: initExtsionScriptEngine(salomeTMF, pExtsionScriptEngine);
0298: loadExtsionXMLPrinter(salomeTMF, XMLPrinters);
0299:
0300: } catch (Exception e) {
0301: e.printStackTrace();
0302: }
0303: }
0304:
0305: public void reActivatePlugin(IPlugObject salomeTMF,
0306: ExtensionPoint commonE, ExtensionPoint bugTracker,
0307: Map UIComponentsMap) {
0308: Util.log("[JPFManager] Common plugins activation");
0309: reActivateCommonsInStaticUIComps(salomeTMF, commonE,
0310: UIComponentsMap);
0311: reActivateBugTrackingPlugins(salomeTMF, bugTracker);
0312: }
0313:
0314: /*public void suspendPlugin(IPlugObject salomeTMF, ExtensionPoint commonE, ExtensionPoint bugTracker , Map UIComponentsMap) {
0315: Util.log("[JPFManager] Common plugins suspend");
0316: //suspendCommonsInStaticUIComps(salomeTMF, commonE, UIComponentsMap);
0317: suspendBugTrackingPlugins(salomeTMF, bugTracker);
0318: }*/
0319:
0320: /**
0321: * This method makes string presentation of given integrity check report.
0322: * sous forme de chaîne de caractères
0323: *
0324: * @param report
0325: * IntegrityCheckReport
0326: */
0327: private static String integrityCheckReport2str(
0328: IntegrityCheckReport report) {
0329: StringBuffer buf = new StringBuffer();
0330: buf.append("integrity check report:\r\n");
0331: buf.append("-------------- REPORT BEGIN -----------------\r\n");
0332: for (Iterator it = report.getItems().iterator(); it.hasNext();) {
0333: IntegrityCheckReport.ReportItem item = (IntegrityCheckReport.ReportItem) it
0334: .next();
0335: buf.append("\tseverity=").append(item.getSeverity())
0336: .append("; code=").append(item.getCode()).append(
0337: "; message=").append(item.getMessage())
0338: .append("; source=").append(item.getSource())
0339: .append("\r\n");
0340: }
0341: buf.append("-------------- REPORT END -----------------");
0342: return buf.toString();
0343: }
0344:
0345: /**
0346: * This method activates the plugins which implements the "Common" extension
0347: * point in static UI components
0348: *
0349: * @param VT
0350: * @param pluginManager
0351: * @param uiComps
0352: */
0353: private void activateCommonsInStaticUIComps(IPlugObject salomeTMF,
0354: ExtensionPoint Common, Map uiComps) {
0355: if (!Common.getConnectedExtensions().isEmpty()) {
0356:
0357: for (Iterator it = Common.getConnectedExtensions()
0358: .iterator(); it.hasNext();) {
0359: Extension commonExt = (Extension) it.next();
0360:
0361: try {
0362: Common common = null;
0363: common = (Common) activateExtension(commonExt);
0364: // Plugin initialisation
0365: common.init(salomeTMF);
0366:
0367: // Activation of the plugin in the "Tools" menu for tests
0368: if (common.isActivableInTestToolsMenu())
0369: common
0370: .activatePluginInTestToolsMenu((JMenu) uiComps
0371: .get(UICompCst.TEST_TOOLS_MENU));
0372:
0373: // Activation of the plugin in the "Tools" menu for campaigns
0374: if (common.isActivableInCampToolsMenu())
0375: common
0376: .activatePluginInCampToolsMenu((JMenu) uiComps
0377: .get(UICompCst.CAMP_TOOLS_MENU));
0378:
0379: // Activation of the plugin in the "Tools" menu for data management
0380: if (common.isActivableInDataToolsMenu())
0381: common
0382: .activatePluginInDataToolsMenu((JMenu) uiComps
0383: .get(UICompCst.DATA_TOOLS_MENU));
0384:
0385: // Ask if the plugin uses other UI components
0386: if (common.usesOtherUIComponents()) {
0387: // Getting UI components used by the plugin
0388: Vector compCsts = common.getUsedUIComponents();
0389:
0390: // We associate, for each dynamic UI component, the plugins that uses it
0391: if (compCsts != null) {
0392: for (int i = 0; i < compCsts.size(); i++) {
0393: Integer uiCompCont = (Integer) compCsts
0394: .elementAt(i);
0395: salomeTMF.addPlgToUICompList(
0396: uiCompCont, common);
0397:
0398: // If it's a static UI component we activate the plugin in it
0399: if (UICompCst.staticUIComps
0400: .contains(uiCompCont)) {
0401: common
0402: .activatePluginInStaticComponent(uiCompCont);
0403: }// else we will activate plugins when dynamic UI components are instanciated
0404: }
0405: }
0406: }
0407:
0408: } catch (Exception e) {
0409: e.printStackTrace();
0410: }
0411:
0412: }
0413: }
0414:
0415: }
0416:
0417: private void reActivateCommonsInStaticUIComps(
0418: IPlugObject salomeTMF, ExtensionPoint Common, Map uiComps) {
0419: if (!Common.getConnectedExtensions().isEmpty()) {
0420:
0421: for (Iterator it = Common.getConnectedExtensions()
0422: .iterator(); it.hasNext();) {
0423: Extension commonExt = (Extension) it.next();
0424:
0425: try {
0426: Common common = null;
0427: common = (Common) reActivateExtension(commonExt);
0428: // Plugin initialisation
0429: common.init(salomeTMF);
0430:
0431: // Activation of the plugin in the "Tools" menu for tests
0432: if (common.isActivableInTestToolsMenu())
0433: common
0434: .activatePluginInTestToolsMenu((JMenu) uiComps
0435: .get(UICompCst.TEST_TOOLS_MENU));
0436:
0437: // Activation of the plugin in the "Tools" menu for campaigns
0438: if (common.isActivableInCampToolsMenu())
0439: common
0440: .activatePluginInCampToolsMenu((JMenu) uiComps
0441: .get(UICompCst.CAMP_TOOLS_MENU));
0442:
0443: // Activation of the plugin in the "Tools" menu for data management
0444: if (common.isActivableInDataToolsMenu())
0445: common
0446: .activatePluginInDataToolsMenu((JMenu) uiComps
0447: .get(UICompCst.DATA_TOOLS_MENU));
0448:
0449: // Ask if the plugin uses other UI components
0450: if (common.usesOtherUIComponents()) {
0451: // Getting UI components used by the plugin
0452: Vector compCsts = common.getUsedUIComponents();
0453:
0454: // We associate, for each dynamic UI component, the plugins that uses it
0455: if (compCsts != null) {
0456: for (int i = 0; i < compCsts.size(); i++) {
0457: Integer uiCompCont = (Integer) compCsts
0458: .elementAt(i);
0459:
0460: //salomeTMF.addPlgToUICompList(uiCompCont, common);
0461:
0462: // If it's a static UI component we activate the plugin in it
0463: if (UICompCst.staticUIComps
0464: .contains(uiCompCont)) {
0465: common
0466: .activatePluginInStaticComponent(uiCompCont);
0467: }// else we will activate plugins when dynamic UI components are instanciated
0468: }
0469: }
0470:
0471: }
0472:
0473: } catch (Exception e) {
0474: e.printStackTrace();
0475: }
0476:
0477: }
0478: }
0479:
0480: }
0481:
0482: /*private void suspendCommonsInStaticUIComps(IPlugObject salomeTMF, ExtensionPoint Common, Map uiComps) {
0483: if (!Common.getConnectedExtensions().isEmpty()) {
0484:
0485: for (Iterator it = Common.getConnectedExtensions().iterator(); it.hasNext();) {
0486: Extension commonExt = (Extension) it.next();
0487:
0488: try {
0489: Common common = null;
0490: common = (Common) reActivateExtension(commonExt);
0491: // Plugin initialisation
0492: common.init(salomeTMF);
0493:
0494: // Activation of the plugin in the "Tools" menu for tests
0495: if (common.isActivableInTestToolsMenu())
0496: common.activatePluginInTestToolsMenu((JMenu) uiComps.get(UICompCst.TEST_TOOLS_MENU));
0497:
0498: // Activation of the plugin in the "Tools" menu for campaigns
0499: if (common.isActivableInCampToolsMenu())
0500: common.activatePluginInCampToolsMenu((JMenu) uiComps.get(UICompCst.CAMP_TOOLS_MENU));
0501:
0502: // Activation of the plugin in the "Tools" menu for data management
0503: if (common.isActivableInDataToolsMenu())
0504: common.activatePluginInDataToolsMenu((JMenu) uiComps.get(UICompCst.DATA_TOOLS_MENU));
0505:
0506: // Ask if the plugin uses other UI components
0507: if (common.usesOtherUIComponents()) {
0508: // Getting UI components used by the plugin
0509: Vector compCsts = common.getUsedUIComponents();
0510:
0511: // We associate, for each dynamic UI component, the plugins that uses it
0512: if (compCsts != null) {
0513: for (int i = 0; i < compCsts.size(); i++) {
0514: Integer uiCompCont = (Integer) compCsts.elementAt(i);
0515:
0516: //salomeTMF.addPlgToUICompList(uiCompCont, common);
0517:
0518: // If it's a static UI component we activate the plugin in it
0519: if (UICompCst.staticUIComps.contains(uiCompCont)) {
0520: common.activatePluginInStaticComponent(uiCompCont);
0521: }// else we will activate plugins when dynamic UI components are instanciated
0522: }
0523: }
0524:
0525: }
0526:
0527: } catch (Exception e) {
0528: e.printStackTrace();
0529: }
0530:
0531: }
0532: }
0533:
0534: }*/
0535:
0536: /**
0537: * This method activates the plugins which implements the "BugTracker" extension point
0538: * @param IPlugObject
0539: * @param BugTracker extension point
0540: */
0541: private void activateBugTrackingPlugins(IPlugObject salomeTMF,
0542: ExtensionPoint bugTracker) {
0543: Util.log("[JPFManager] Number of bug tracking plugins = "
0544: + bugTracker.getConnectedExtensions().size());
0545: if (!bugTracker.getConnectedExtensions().isEmpty()) {
0546:
0547: for (Iterator it = bugTracker.getConnectedExtensions()
0548: .iterator(); it.hasNext();) {
0549: Extension bugTrackerExt = (Extension) it.next();
0550:
0551: try {
0552: BugTracker bugTrack = null;
0553: bugTrack = (BugTracker) activateExtension(bugTrackerExt);
0554: //Plugins initialisation
0555: bugTrack.initBugTracker(salomeTMF);
0556: salomeTMF.addBugTrackers(bugTrack);
0557: //Activation of bug tracking plugins in tools menus
0558: if (bugTrack.isIndependantTracker()) {
0559: PluginsTools
0560: .activateBugTrackingPlgsInToolsMenu(
0561: SalomeTMFPanels
0562: .getTestToolsMenu(),
0563: bugTrack);
0564: PluginsTools
0565: .activateBugTrackingPlgsInToolsMenu(
0566: SalomeTMFPanels
0567: .getCampToolsMenu(),
0568: bugTrack);
0569: PluginsTools
0570: .activateBugTrackingPlgsInToolsMenu(
0571: SalomeTMFPanels
0572: .getDataToolsMenu(),
0573: bugTrack);
0574: }
0575: } catch (Exception e) {
0576: e.printStackTrace();
0577: }
0578:
0579: }
0580: }
0581:
0582: }
0583:
0584: private void reActivateBugTrackingPlugins(IPlugObject salomeTMF,
0585: ExtensionPoint bugTracker) {
0586: Util.log("[JPFManager] Number of bug tracking plugins = "
0587: + bugTracker.getConnectedExtensions().size());
0588: if (!bugTracker.getConnectedExtensions().isEmpty()) {
0589:
0590: for (Iterator it = bugTracker.getConnectedExtensions()
0591: .iterator(); it.hasNext();) {
0592: Extension bugTrackerExt = (Extension) it.next();
0593:
0594: try {
0595: BugTracker bugTrack = null;
0596: bugTrack = (BugTracker) reActivateExtension(bugTrackerExt);
0597: //Plugins initialisation
0598: bugTrack.initBugTracker(salomeTMF);
0599: //salomeTMF.addBugTrackers(bugTrack);
0600:
0601: //Activation of bug tracking plugins in tools menus
0602: if (bugTrack.isIndependantTracker()) {
0603: PluginsTools
0604: .activateBugTrackingPlgsInToolsMenu(
0605: SalomeTMFPanels
0606: .getTestToolsMenu(),
0607: bugTrack);
0608: PluginsTools
0609: .activateBugTrackingPlgsInToolsMenu(
0610: SalomeTMFPanels
0611: .getCampToolsMenu(),
0612: bugTrack);
0613: PluginsTools
0614: .activateBugTrackingPlgsInToolsMenu(
0615: SalomeTMFPanels
0616: .getDataToolsMenu(),
0617: bugTrack);
0618: }
0619: } catch (Exception e) {
0620: e.printStackTrace();
0621: }
0622:
0623: }
0624: }
0625:
0626: }
0627:
0628: /**
0629: * This method activates the plugins which implements the "ReqManager" extension point
0630: * @param IPlugObject
0631: * @param ReqManager extension point
0632: */
0633: private void activateRegManagerPlugins(IPlugObject salomeTMF,
0634: ExtensionPoint reqManager) {
0635: Util.log("[JPFManager] Number of reqManager plugins = "
0636: + reqManager.getConnectedExtensions().size());
0637: if (!reqManager.getConnectedExtensions().isEmpty()) {
0638:
0639: for (Iterator it = reqManager.getConnectedExtensions()
0640: .iterator(); it.hasNext();) {
0641: Extension reqManagerExt = (Extension) it.next();
0642:
0643: try {
0644: ReqManager req = null;
0645: req = (ReqManager) activateExtension(reqManagerExt);
0646: //Plugins initialisation
0647: salomeTMF.addReqManager(req);
0648: } catch (Exception e) {
0649: e.printStackTrace();
0650: }
0651:
0652: }
0653: }
0654:
0655: }
0656:
0657: /*private void suspendBugTrackingPlugins(IPlugObject salomeTMF, ExtensionPoint bugTracker) {
0658: Util.log("[JPFManager] Number of bug tracking plugins = " + bugTracker.getConnectedExtensions().size());
0659: if (!bugTracker.getConnectedExtensions().isEmpty()) {
0660:
0661: for (Iterator it = bugTracker.getConnectedExtensions().iterator(); it.hasNext();) {
0662: Extension bugTrackerExt = (Extension) it.next();
0663:
0664: try {
0665: BugTracker bugTrack = null;q
0666: bugTrack = (BugTracker)reActivateExtension(bugTrackerExt);
0667: //Plugins initialisation
0668: bugTrack.suspend();
0669:
0670: } catch (Exception e) {
0671: e.printStackTrace();
0672: }
0673:
0674: }
0675: }
0676:
0677: }*/
0678:
0679: public Object activateExtension(Extension pExtension)
0680: throws Exception {
0681: PluginDescriptor pDesc = pExtension
0682: .getDeclaringPluginDescriptor();
0683:
0684: Object pluginRef = null;
0685:
0686: // This will invoke the method "addLocalJar()" of
0687: // sun.plugin.security.PluginClassLoader
0688: // which forces the SecurityManager to verify signatures for plugin's
0689: // libraries jar files
0690: System.out.println("Try to activate Extension : " + pExtension);
0691:
0692: if (!Api.isIDE_DEV()) {
0693: for (Iterator itl = pDesc.getLibraries().iterator(); itl
0694: .hasNext();) {
0695: Library lib = (Library) itl.next();
0696: Util.log("[activateExtension] Find lib : " + lib);
0697: if (lib.isCodeLibrary()) {
0698: URL UrlLib = pluginManager.getPathResolver()
0699: .resolvePath(lib, lib.getPath());
0700: Util.log("[activateExtension] Try lo load lib : "
0701: + UrlLib);
0702: pPluginClassLoader.AddJar(UrlLib);
0703: /*
0704: try {
0705: Class pclC = (this.getClass().getClassLoader()).getClass();
0706: pclC.getMethod("addLocalJar", new Class[] { URL.class })
0707: .invoke(this.getClass().getClassLoader(),
0708: new Object[] { UrlLib });
0709: } catch (Exception e){
0710: Util.log("[activateExtension] Error when load lib : " + e);
0711: e.printStackTrace();
0712: }*/
0713: }
0714: }
0715: }
0716:
0717: try {
0718: Util.log("[activateExtension] plugin to instance is : "
0719: + pDesc);
0720: Plugin pPlugin = pluginManager.getPlugin(pDesc.getId());
0721: Util.log("[activateExtension] The plugin is : " + pPlugin);
0722: Class pluginCls = pPlugin.getClass();
0723: Util.log("[activateExtension] The plugin class is : "
0724: + pluginCls);
0725: Class extensionCls = pluginCls.getClassLoader().loadClass(
0726: pExtension.getParameter("class").valueAsString());
0727: Util
0728: .log("[activateExtension] The plugin extensionClass is : "
0729: + extensionCls);
0730: if (pluginCls.isAssignableFrom(extensionCls)) {
0731: Util.log("[activateExtension] The plugin is loaded");
0732: pluginRef = pPlugin;
0733: } else {
0734: Util
0735: .log("[activateExtension] The plugin is not loaded, try to load");
0736: pluginRef = extensionCls.newInstance();
0737: }
0738: } catch (Exception e) {
0739: e.printStackTrace();
0740:
0741: }
0742: return pluginRef;
0743: }
0744:
0745: public Object reActivateExtension(Extension pExtension)
0746: throws Exception {
0747: PluginDescriptor pDesc = pExtension
0748: .getDeclaringPluginDescriptor();
0749:
0750: Object pluginRef = null;
0751:
0752: // This will invoke the method "addLocalJar()" of
0753: // sun.plugin.security.PluginClassLoader
0754: // which forces the SecurityManager to verify signatures for plugin's
0755: // libraries jar files
0756: System.out.println("Try to activate Extension : " + pExtension);
0757:
0758: try {
0759: Util.log("[activateExtension] plugin to instance is : "
0760: + pDesc);
0761: Plugin pPlugin = pluginManager.getPlugin(pDesc.getId());
0762: Util.log("[activateExtension] The plugin is : " + pPlugin);
0763: Class pluginCls = pPlugin.getClass();
0764: Util.log("[activateExtension] The plugin class is : "
0765: + pluginCls);
0766: Class extensionCls = pluginCls.getClassLoader().loadClass(
0767: pExtension.getParameter("class").valueAsString());
0768: Util
0769: .log("[activateExtension] The plugin extensionClass is : "
0770: + extensionCls);
0771: if (pluginCls.isAssignableFrom(extensionCls)) {
0772: System.out
0773: .println("[activateExtension] The plugin is loaded");
0774: pluginRef = pPlugin;
0775: } else {
0776: System.out
0777: .println("[activateExtension] The plugin is not loaded, try to load");
0778: pluginRef = extensionCls.newInstance();
0779: }
0780: } catch (Exception e) {
0781: e.printStackTrace();
0782:
0783: }
0784: return pluginRef;
0785: }
0786:
0787: private void initExtsionTestDriver(IPlugObject salomeTMF,
0788: ExtensionPoint pExtsionTestDriver) {
0789: if (!pExtsionTestDriver.getConnectedExtensions().isEmpty()) {
0790: for (Iterator it = pExtsionTestDriver
0791: .getConnectedExtensions().iterator(); it.hasNext();) {
0792: try {
0793: Extension testDriverExt = (Extension) it.next();
0794: String extList = testDriverExt.getParameter(
0795: "extensions").valueAsString();
0796: salomeTMF.associatedTestDriver(testDriverExt,
0797: extList);
0798: salomeTMF.associatedExtension(
0799: testDriverExt.getId(), testDriverExt);
0800: Util.log("Add testDriverExt : "
0801: + testDriverExt.getId());
0802: } catch (Exception e) {
0803: // TODO
0804: e.printStackTrace();
0805: }
0806: }
0807: }
0808: }
0809:
0810: private void initExtsionScriptEngine(IPlugObject salomeTMF,
0811: ExtensionPoint pExtsionScriptEngine) {
0812: if (!pExtsionScriptEngine.getConnectedExtensions().isEmpty()) {
0813: for (Iterator it = pExtsionScriptEngine
0814: .getConnectedExtensions().iterator(); it.hasNext();) {
0815: try {
0816: Extension scriptEngineExt = (Extension) it.next();
0817: String extList = scriptEngineExt.getParameter(
0818: "extensions").valueAsString();
0819: salomeTMF.associatedScriptEngine(scriptEngineExt,
0820: extList);
0821: salomeTMF.associatedExtension(scriptEngineExt
0822: .getId(), scriptEngineExt);
0823: Util.log("Add ExtsionScriptEngine : "
0824: + scriptEngineExt.getId());
0825: } catch (Exception e) {
0826: // TODO
0827: e.printStackTrace();
0828: }
0829: }
0830: }
0831: }
0832:
0833: private void loadExtsionXMLPrinter(IPlugObject salomeTMF,
0834: ExtensionPoint pExtensionXMLPrinter) {
0835: if (!pExtensionXMLPrinter.getConnectedExtensions().isEmpty()) {
0836:
0837: for (Iterator it = pExtensionXMLPrinter
0838: .getConnectedExtensions().iterator(); it.hasNext();) {
0839: try {
0840: Extension pXMLExt = (Extension) it.next();
0841: salomeTMF.addXMLPrinterExtension(pXMLExt);
0842: } catch (Exception e) {
0843: // TODO
0844: e.printStackTrace();
0845: }
0846: }
0847: }
0848: }
0849:
0850: /**
0851: * JPF initialisation in Salomé administration
0852: *
0853: * @param _urlBase
0854: * Applet's URL in the server
0855: */
0856: public void startJPFInAdmin(URL urlBase, Map UIComponentsMap,
0857: IPlugObject administration) {
0858: //salomeContextTMF = administration;
0859: try {
0860: //URL _urlBase = VT.getDocumentBase();
0861: URL _urlBase = urlBase;
0862:
0863: String url_txt = _urlBase.toString();
0864: url_txt = url_txt.substring(0, url_txt.lastIndexOf("/"));
0865: urlBase = new java.net.URL(url_txt);
0866:
0867: // JPF's configuration file
0868: java.net.URL url_server = new java.net.URL(urlBase
0869: + CONFIG_JPF_FILE_PATH);
0870: Properties props = null;
0871:
0872: try {
0873: props = Util.getPropertiesFile(url_server);
0874: } catch (Exception e) {
0875: System.out
0876: .println("WARNING JAR FILE PLUGINS PROPERTIES SELECTED "
0877: + e);
0878: props = Util.getPropertiesFile(CONFIG_JPF_FILE_PATH);
0879: }
0880:
0881: // SI DEBUG METTRE LE REPERTOIRE PHYSIQUE !!!
0882: String appliRoot = null;
0883:
0884: appliRoot = urlBase.toString() + "/";
0885:
0886: // Logging system initialization
0887: // Logs will be stored in ${tmpDir}/logs where ${tmpDir} is the
0888: // system
0889: // temp directory
0890: if (Api.isDEBUG()) {
0891: Properties sys = System.getProperties();
0892: // Temp directory for log system
0893: String tmpDir = sys.getProperty("java.io.tmpdir");
0894:
0895: props.setProperty("tmpDir", tmpDir);
0896: try {
0897: File logFolder = new File(tmpDir + "logs");
0898: logFolder.mkdir();
0899: } catch (Exception e) {
0900: System.out
0901: .println("Failed to create log folder \"tmpDir/logs\"");
0902: e.printStackTrace();
0903: }
0904:
0905: PropertyConfigurator.configure(props);
0906: log = LogFactory.getLog(JPFManager.class);
0907: log.info("logging system initialized");
0908: }
0909:
0910: // Pamameters for PluginManager
0911: StringTokenizer PluginsFolders = new StringTokenizer(props
0912: .getProperty(PARAM_PLUGINS_FOLDERS), ",", false);
0913: Map pluginLocations = new HashMap();
0914:
0915: for (; PluginsFolders.hasMoreTokens();) {
0916: String currentPlgFolder = appliRoot
0917: + PluginsFolders.nextToken().trim();
0918:
0919: Util.log("plug-ins folder - " + currentPlgFolder);
0920:
0921: StringTokenizer PluginsList = new StringTokenizer(props
0922: .getProperty(PARAM_PLUGINS_LIST), ",", false);
0923:
0924: for (; PluginsList.hasMoreTokens();) {
0925: String currentPlg = currentPlgFolder + "/"
0926: + PluginsList.nextToken().trim();
0927:
0928: String plgManifest = "plugin.xml";
0929: if (Api.isIDE_DEV())
0930: plgManifest = "pluginDBG.xml";
0931: try {
0932: pluginLocations.put(new URL(currentPlg + "/"
0933: + plgManifest), new URL(currentPlg));
0934: } catch (Exception e) {
0935: e.printStackTrace();
0936: }
0937: }
0938: }
0939:
0940: // New instance of PluginManager
0941: pluginManager = PluginManager
0942: .createStandardManager(pluginLocations);
0943:
0944: // Plugins integrity
0945: Util.log("[JPFManager] Check plugins integrity");
0946:
0947: IntegrityCheckReport integrityCheckReport = pluginManager
0948: .getRegistry().checkIntegrity(
0949: pluginManager.getPathResolver());
0950: if (Api.isDEBUG()) {
0951: log.info("integrity check done: errors - "
0952: + integrityCheckReport.countErrors()
0953: + ", warnings - "
0954: + integrityCheckReport.countWarnings());
0955: }
0956:
0957: if (integrityCheckReport.countErrors() != 0) {
0958: administration
0959: .showMessage("Problème lors du chargement des plugins.\n"
0960: + "Certains plugins ne fonctionneront pas normalement");
0961: }
0962:
0963: if (Api.isDEBUG())
0964: log
0965: .trace(integrityCheckReport2str(integrityCheckReport));
0966:
0967: // Running the "core" plugin
0968: Util.log("[JPFManager] Running the core plugin");
0969: Plugin corePlugin = pluginManager.getPlugin("core");
0970:
0971: if (corePlugin == null) {
0972: //throw new Exception("can't get plug-in core");
0973: administration
0974: .showMessage("Problème lors du chargement du core plugin.\n"
0975: + "Les plugins ne pourront pas être chargés");
0976: }
0977:
0978: // Extension points initialization
0979: Util.log("[JPFManager] Extension points initialization");
0980: ExtensionPoint Admin = (ExtensionPoint) corePlugin
0981: .getClass().getMethod("getAdminExtPoint",
0982: new Class[] {}).invoke(corePlugin,
0983: new Object[] {});
0984:
0985: ExtensionPoint XMLPrinters = (ExtensionPoint) corePlugin
0986: .getClass().getMethod("getXMLPrinterExtPoint",
0987: new Class[] {}).invoke(corePlugin,
0988: new Object[] {});
0989:
0990: if (!Admin.getConnectedExtensions().isEmpty()) {
0991:
0992: for (Iterator it = Admin.getConnectedExtensions()
0993: .iterator(); it.hasNext();) {
0994: Extension adminExt = (Extension) it.next();
0995:
0996: Admin admin = null;
0997:
0998: admin = (Admin) activateExtension(adminExt);
0999:
1000: admin.activateInSalomeAdmin(UIComponentsMap,
1001: administration);
1002: administration.associatedExtension(
1003: adminExt.getId(), adminExt);
1004: }
1005: }
1006:
1007: ExtensionPoint pExtsionTestDriver = (ExtensionPoint) corePlugin
1008: .getClass().getMethod("getTestDriverExtPoint",
1009: new Class[] {}).invoke(corePlugin,
1010: new Object[] {});
1011:
1012: ExtensionPoint pExtsionScriptEngine = (ExtensionPoint) corePlugin
1013: .getClass().getMethod("getScriptEngineExtPoint",
1014: new Class[] {}).invoke(corePlugin,
1015: new Object[] {});
1016:
1017: administration.initExtsionTestDriver(pExtsionTestDriver);
1018: administration
1019: .initExtsionScriptEngine(pExtsionScriptEngine);
1020: loadExtsionXMLPrinter(administration, XMLPrinters);
1021:
1022: } catch (Exception e) {
1023: e.printStackTrace();
1024: }
1025: }
1026:
1027: /*private void initExtsionTestDriverForAdmin(IPlugObject administration, ExtensionPoint pExtsionTestDriver) {
1028: if (!pExtsionTestDriver.getConnectedExtensions().isEmpty()) {
1029: for (Iterator it = pExtsionTestDriver.getConnectedExtensions()
1030: .iterator(); it.hasNext();) {
1031: try {
1032: Extension testDriverExt = (Extension) it.next();
1033: String extList = testDriverExt.getParameter("extensions")
1034: .valueAsString();
1035: administration.associatedTestDriver(testDriverExt, extList);
1036: administration.associatedExtension(testDriverExt.getId(),
1037: testDriverExt);
1038: Util.log("Add testDriverExt : "
1039: + testDriverExt.getId());
1040: } catch (Exception e) {
1041: // TODO
1042: e.printStackTrace();
1043: }
1044: }
1045: }
1046: }*/
1047:
1048: /*private void initExtsionScriptEngineForAdmin(IPlugObject administration, ExtensionPoint pExtsionScriptEngine) {
1049: if (!pExtsionScriptEngine.getConnectedExtensions().isEmpty()) {
1050: for (Iterator it = pExtsionScriptEngine.getConnectedExtensions()
1051: .iterator(); it.hasNext();) {
1052: try {
1053: Extension scriptEngineExt = (Extension) it.next();
1054: String extList = scriptEngineExt.getParameter("extensions")
1055: .valueAsString();
1056: administration.associatedScriptEngine(scriptEngineExt,
1057: extList);
1058: administration.associatedExtension(scriptEngineExt.getId(),
1059: scriptEngineExt);
1060: Util.log("Add ExtsionScriptEngine : "
1061: + scriptEngineExt.getId());
1062: } catch (Exception e) {
1063: // TODO
1064: e.printStackTrace();
1065: }
1066: }
1067: }
1068: }*/
1069:
1070: }
|