diff options
16 files changed, 712 insertions, 6 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java index ede140253e..0cfb51190c 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java @@ -30,4 +30,9 @@ public interface TmfXmlStrings { static final String NAME = "name"; static final String VERSION = "version"; + /* XML head element */ + static final String HEAD = "head"; + static final String TRACETYPE = "tracetype"; + static final String ID = "id"; + }
\ No newline at end of file diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/META-INF/MANIFEST.MF index 10a1d7f261..d8006475cb 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/META-INF/MANIFEST.MF +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/META-INF/MANIFEST.MF @@ -11,8 +11,10 @@ Require-Bundle: org.eclipse.ui, org.eclipse.linuxtools.tmf.analysis.xml.core, org.eclipse.core.resources, org.eclipse.linuxtools.tmf.core, + org.eclipse.linuxtools.tmf.analysis.xml.core, org.eclipse.linuxtools.tmf.analysis.xml.ui, - org.eclipse.linuxtools.tmf.ui + org.eclipse.linuxtools.tmf.ui, + org.eclipse.linuxtools.tmf.analysis.xml.core.tests Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Import-Package: org.junit.runners diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/plugin.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/plugin.properties index 445d26162a..6424a1e5d4 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/plugin.properties +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/plugin.properties @@ -12,4 +12,4 @@ #Properties file for org.eclipse.linuxtools.tmf.core Bundle-Vendor = Eclipse Linux Tools -Bundle-Name = Linux Tools TMF Xml Analysis UI Tests Plug-in +Bundle-Name = Linux Tools TMF XML Analysis UI Tests Plug-in diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/AllAnalysisXmlUiTests.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/AllAnalysisXmlUiTests.java index 2b0dd54b5f..61e085c0b3 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/AllAnalysisXmlUiTests.java +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/AllAnalysisXmlUiTests.java @@ -20,7 +20,8 @@ import org.junit.runners.Suite; */ @RunWith(Suite.class) @Suite.SuiteClasses({ - XmlAnalysisUiPluginTest.class + XmlAnalysisUiPluginTest.class, + org.eclipse.linuxtools.tmf.analysis.xml.ui.tests.module.AllTests.class }) public class AllAnalysisXmlUiTests { diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/module/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/module/AllTests.java new file mode 100644 index 0000000000..865fd02ec8 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/module/AllTests.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.ui.tests.module; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * Test suite for org.eclipse.linuxtools.tmf.analysis.xml.ui.module package + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + XmlAnalysisModuleSourceTest.class +}) +public class AllTests { + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/module/XmlAnalysisModuleSourceTest.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/module/XmlAnalysisModuleSourceTest.java new file mode 100644 index 0000000000..c35a44c853 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/module/XmlAnalysisModuleSourceTest.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.ui.tests.module; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.util.Map; + +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils; +import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles; +import org.eclipse.linuxtools.tmf.analysis.xml.ui.module.XmlAnalysisModuleSource; +import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; +import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Test suite for the {@link XmlAnalysisModuleSource} class + * + * @author Geneviève Bastien + */ +public class XmlAnalysisModuleSourceTest { + + private static final String SS_MODULE = "polymtl.kernel.sp"; + + private static void emptyXmlFolder() { + File fFolder = XmlUtils.getXmlFilesPath().toFile(); + if (!(fFolder.isDirectory() && fFolder.exists())) { + return; + } + for (File xmlFile : fFolder.listFiles()) { + xmlFile.delete(); + } + XmlAnalysisModuleSource.notifyModuleChange(); + } + + /** + * Empty the XML directory before the test, just in case + */ + @Before + public void setUp() { + emptyXmlFolder(); + } + + /** + * Empty the XML directory after the test + */ + @After + public void cleanUp() { + emptyXmlFolder(); + } + + /** + * Test the {@link XmlAnalysisModuleSource#getAnalysisModules()} method + */ + @Test + public void testPopulateModules() { + XmlAnalysisModuleSource module = new XmlAnalysisModuleSource(); + + Iterable<IAnalysisModuleHelper> modules = module.getAnalysisModules(); + assertFalse(modules.iterator().hasNext()); + + /* use the valid XML test file */ + File testXmlFile = TmfXmlTestFiles.VALID_FILE.getFile(); + if ((testXmlFile == null) || !testXmlFile.exists()) { + fail("XML test file does not exist"); + } + + XmlUtils.addXmlFile(testXmlFile); + XmlAnalysisModuleSource.notifyModuleChange(); + modules = module.getAnalysisModules(); + + assertTrue(modules.iterator().hasNext()); + assertTrue(findStateSystemModule(modules)); + } + + private static boolean findStateSystemModule(Iterable<IAnalysisModuleHelper> modules) { + for (IAnalysisModuleHelper helper : modules) { + if (SS_MODULE.equals(helper.getId())) { + return true; + } + } + return false; + } + + /** + * Test that XML modules are available through the analysis manager + */ + @Test + public void testPopulateModulesWithAnalysisManager() { + + /* + * Make sure module sources are initialized. When run as unit test, the + * XML module source is sometimes missing + */ + TmfAnalysisManager.initializeModuleSources(); + + Map<String, IAnalysisModuleHelper> modules = TmfAnalysisManager.getAnalysisModules(); + assertFalse(findStateSystemModule(modules.values())); + + /* use the valid XML test file */ + File testXmlFile = TmfXmlTestFiles.VALID_FILE.getFile(); + if ((testXmlFile == null) || !testXmlFile.exists()) { + fail("XML test file does not exist"); + } + + XmlUtils.addXmlFile(testXmlFile); + XmlAnalysisModuleSource.notifyModuleChange(); + modules = TmfAnalysisManager.getAnalysisModules(); + assertTrue(findStateSystemModule(modules.values())); + } +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/META-INF/MANIFEST.MF index 465d5196a4..50c8ed6439 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/META-INF/MANIFEST.MF +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/META-INF/MANIFEST.MF @@ -13,4 +13,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.linuxtools.tmf.core, org.eclipse.linuxtools.tmf.ui, org.eclipse.linuxtools.tmf.analysis.xml.core -Export-Package: org.eclipse.linuxtools.internal.tmf.analysis.xml.ui;x-friends:="org.eclipse.linuxtools.tmf.analysis.xml.ui.tests" +Export-Package: org.eclipse.linuxtools.internal.tmf.analysis.xml.ui;x-friends:="org.eclipse.linuxtools.tmf.analysis.xml.ui.tests", + org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.handler;x-internal:=true, + org.eclipse.linuxtools.tmf.analysis.xml.ui.module diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/build.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/build.properties index 2b112c4613..1dde0d2c61 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/build.properties +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/build.properties @@ -3,5 +3,6 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ plugin.properties,\ - about.html + about.html,\ + plugin.xml src.includes = about.html diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.properties index b6fa1189fe..6d208136e7 100644 --- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.properties +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.properties @@ -12,5 +12,8 @@ #Properties file for org.eclipse.linuxtools.tmf.core Bundle-Vendor = Eclipse Linux Tools -Bundle-Name = Linux Tools TMF Xml Analysis UI Plug-in +Bundle-Name = Linux Tools TMF XML Analysis UI Plug-in +command.xml.import = Import XML file +command.xml.import.mnemonic = I +command.xml.import.description = Import an XML file containing analysis information diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.xml b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.xml new file mode 100644 index 0000000000..54b3b8fafe --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/plugin.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + <extension + point="org.eclipse.linuxtools.tmf.core.analysis"> + <source + class="org.eclipse.linuxtools.tmf.analysis.xml.ui.module.XmlAnalysisModuleSource"> + </source> + </extension> + <extension + point="org.eclipse.ui.commands"> + <command + categoryId="org.eclipse.linuxtools.tmf.ui.commands.category" + id="org.eclipse.linuxtools.tmf.analysis.xml.ui.importxml" + name="%command.xml.import" + description="%command.xml.import.description"> + </command> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:org.eclipse.ui.popup.any?after=additions"> + <command + commandId="org.eclipse.linuxtools.tmf.analysis.xml.ui.importxml" + label="%command.xml.import" + mnemonic="%command.xml.import.mnemonic" + style="push" + tooltip="%command.xml.import.description"> + <visibleWhen + checkEnabled="false"> + <with + variable="selection"> + <count + value="1"> + </count> + <iterate + ifEmpty="false" + operator="and"> + <or> + <instanceof + value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder"> + </instanceof> + <instanceof + value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder"> + </instanceof> + <instanceof + value="org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement"> + </instanceof> + </or> + </iterate> + </with> + </visibleWhen> + </command> + </menuContribution> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + class="org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.handler.ImportXmlHandler" + commandId="org.eclipse.linuxtools.tmf.analysis.xml.ui.importxml"> + <activeWhen> + <and> + <count + value="1"> + </count> + <iterate + ifEmpty="false" + operator="and"> + <or> + <instanceof + value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder"> + </instanceof> + <instanceof + value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder"> + </instanceof> + <instanceof + value="org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement"> + </instanceof> + </or> + </iterate> + </and> + </activeWhen> + </handler> + </extension> +</plugin> diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/ui/handler/ImportXmlHandler.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/ui/handler/ImportXmlHandler.java new file mode 100644 index 0000000000..8ea66a3251 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/ui/handler/ImportXmlHandler.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.handler; + +import java.io.File; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils; +import org.eclipse.linuxtools.tmf.analysis.xml.ui.module.Messages; +import org.eclipse.linuxtools.tmf.analysis.xml.ui.module.XmlAnalysisModuleSource; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectModelElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +/** + * Imports and validates an XML file + * + * @author Geneviève Bastien + */ +public class ImportXmlHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + + FileDialog dlg = new FileDialog(new Shell(), SWT.OPEN); + dlg.setFilterNames(new String[] { Messages.ImportXmlHandler_ImportXmlFile + " (*.xml)" }); //$NON-NLS-1$ + dlg.setFilterExtensions(new String[] { "*.xml" }); //$NON-NLS-1$ + + String fn = dlg.open(); + if (fn != null) { + File file = new File(fn); + IStatus status = XmlUtils.xmlValidate(file); + if (status.isOK()) { + status = XmlUtils.addXmlFile(file); + if (status.isOK()) { + XmlAnalysisModuleSource.notifyModuleChange(); + /* + * FIXME: It refreshes the list of analysis under a trace, + * but since modules are instantiated when the trace opens, + * the changes won't apply to an opened trace, it needs to + * be closed then reopened + */ + refreshProject(); + } else { + TraceUtils.displayErrorMsg(Messages.ImportXmlHandler_ImportXmlFile, status.getMessage()); + } + } else { + TraceUtils.displayErrorMsg(Messages.ImportXmlHandler_ImportXmlFile, status.getMessage()); + } + } + + return null; + } + + /** + * Refresh the selected project with the new XML file import + */ + private static void refreshProject() { + // Check if we are closing down + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window == null) { + return; + } + + // Get the selection + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPart part = page.getActivePart(); + if (part == null) { + return; + } + ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); + if (selectionProvider == null) { + return; + } + ISelection selection = selectionProvider.getSelection(); + + if (selection instanceof TreeSelection) { + TreeSelection sel = (TreeSelection) selection; + // There should be only one item selected as per the plugin.xml + Object element = sel.getFirstElement(); + if (element instanceof TmfProjectModelElement) { + ((TmfProjectModelElement) element).getProject().refresh(); + } + } + + } + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/Messages.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/Messages.java new file mode 100644 index 0000000000..c720fa2db5 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/Messages.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.ui.module; + +import org.eclipse.osgi.util.NLS; + +/** + * Externalized messages for the XML analysis module package + * + * @author Geneviève Bastien + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.tmf.analysis.xml.ui.module.messages"; //$NON-NLS-1$ + + /** Import XML file title */ + public static String ImportXmlHandler_ImportXmlFile; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfAnalysisModuleHelperXml.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfAnalysisModuleHelperXml.java new file mode 100644 index 0000000000..f26ccd84f4 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfAnalysisModuleHelperXml.java @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.ui.module; + +import java.io.File; + +import org.eclipse.core.runtime.Path; +import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator; +import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; +import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule; +import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; +import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.ui.analysis.TmfAnalysisViewOutput; +import org.osgi.framework.Bundle; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +/** + * Analysis module helpers for modules provided by XML files + * + * @author Geneviève Bastien + */ +public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper { + + /** + * The types of analysis that can be XML-defined + */ + public enum XmlAnalysisModuleType { + /** Analysis will be of type XmlStateSystemModule */ + STATE_SYSTEM + } + + private final File fSourceFile; + private final Element fSourceElement; + private final XmlAnalysisModuleType fType; + private final XmlHeadInfoUi fHeadInfo; + + /** + * Constructor + * + * @param xmlFile + * The XML file containing the details of this analysis + * @param node + * The XML node element + * @param type + * The type of analysis + */ + public TmfAnalysisModuleHelperXml(File xmlFile, Element node, XmlAnalysisModuleType type) { + fSourceFile = xmlFile; + fSourceElement = node; + fType = type; + + NodeList head = fSourceElement.getElementsByTagName(TmfXmlStrings.HEAD); + if (head.getLength() == 1) { + fHeadInfo = new XmlHeadInfoUi(head.item(0)); + } else { + fHeadInfo = null; + } + } + + @Override + public String getId() { + return fSourceElement.getAttribute(TmfXmlStrings.ANALYSIS_ID); + } + + @Override + public String getName() { + String name = fHeadInfo.getName(); + if (name == null) { + name = getId(); + } + return name; + } + + @Override + public boolean isAutomatic() { + return false; + } + + @Override + public String getHelpText() { + return new String(); + } + + @Override + public String getIcon() { + return null; + } + + @Override + public Bundle getBundle() { + return Activator.getDefault().getBundle(); + } + + @Override + public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass) { + /* Trace types may be available in XML header */ + if (fHeadInfo == null) { + return true; + } + + return fHeadInfo.checkTraceType(traceclass); + } + + @Override + public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException { + String analysisid = getId(); + IAnalysisModule module = null; + switch (fType) { + case STATE_SYSTEM: + module = new XmlStateSystemModule(); + XmlStateSystemModule ssModule = (XmlStateSystemModule) module; + module.setId(analysisid); + ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath())); + + /* Set header information if available */ + ssModule.setHeadInfo(fHeadInfo); + + module.registerOutput(new TmfAnalysisViewOutput("org.eclipse.linuxtools.tmf.ui.views.ssvisualizer")); //$NON-NLS-1$ + break; + default: + break; + + } + if (module != null) { + module.setTrace(trace); + } + + return module; + } + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java new file mode 100644 index 0000000000..c975069187 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.ui.module; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator; +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils; +import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; +import org.eclipse.linuxtools.tmf.analysis.xml.ui.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType; +import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper; +import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleSource; +import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +/** + * Analysis module source who creates helpers for the analysis modules described + * in the imported XML files + * + * @author Geneviève Bastien + * @since 3.0 + */ +public class XmlAnalysisModuleSource implements IAnalysisModuleSource { + + private static List<IAnalysisModuleHelper> fModules = null; + + @Override + public synchronized Iterable<IAnalysisModuleHelper> getAnalysisModules() { + if (fModules == null) { + populateAnalysisModules(); + } + return fModules; + } + + private static void populateAnalysisModules() { + fModules = new ArrayList<>(); + IPath pathToFiles = XmlUtils.getXmlFilesPath(); + File fFolder = pathToFiles.toFile(); + if (!(fFolder.isDirectory() && fFolder.exists())) { + return; + } + for (File xmlFile : fFolder.listFiles()) { + if (!XmlUtils.xmlValidate(xmlFile).isOK()) { + continue; + } + + try { + /* Load the XML File */ + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(xmlFile); + doc.getDocumentElement().normalize(); + + /* get State Providers modules */ + NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER); + for (int i = 0; i < stateproviderNodes.getLength(); i++) { + Element node = (Element) stateproviderNodes.item(i); + + IAnalysisModuleHelper helper = new TmfAnalysisModuleHelperXml(xmlFile, node, XmlAnalysisModuleType.STATE_SYSTEM); + fModules.add(helper); + } + } catch (ParserConfigurationException | SAXException | IOException e) { + Activator.logError("Error opening XML file", e); //$NON-NLS-1$ + } + } + } + + /** + * Notifies the main XML analysis module that the executable modules list + * may have changed and needs to be refreshed. + */ + public static void notifyModuleChange() { + fModules = null; + TmfAnalysisManager.refreshModules(); + } + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlHeadInfoUi.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlHeadInfoUi.java new file mode 100644 index 0000000000..1184880a85 --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlHeadInfoUi.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2014 École Polytechnique de Montréal + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Geneviève Bastien - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.analysis.xml.ui.module; + +import java.util.List; + +import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlHeadInfo; +import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings; +import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType; +import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Class to store and interpret the header information of XML-defined components + * + * TODO: When trace types are moved to the o.e.l.tmf.core plug-in, there will be + * no need for this class anymore, move to o.e.l.tmf.analysis.xml.core plug-in. + * + * @author Geneviève Bastien + */ +public class XmlHeadInfoUi extends XmlHeadInfo { + + /** + * Constructor + * + * @param item + * The XML node corresponding to this header + */ + public XmlHeadInfoUi(Node item) { + super(item); + } + + @Override + public boolean checkTraceType(Class<? extends ITmfTrace> traceClass) { + /* + * TODO: This wouldn't work for custom traces since {@link + * TmfTraceType#getTraceType(String)} has no helper for those traces + */ + List<Element> elements = getElements(TmfXmlStrings.TRACETYPE); + if (elements.isEmpty()) { + return true; + } + + for (Element element : elements) { + String traceTypeId = element.getAttribute(TmfXmlStrings.ID); + TraceTypeHelper helper = TmfTraceType.getInstance().getTraceType(traceTypeId); + if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) { + return true; + } + } + return false; + } + +} diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/messages.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/messages.properties new file mode 100644 index 0000000000..0f35f238ed --- /dev/null +++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/messages.properties @@ -0,0 +1 @@ +ImportXmlHandler_ImportXmlFile=Import XML analysis file |