TMF: Add support for XML-defined analysis outputs
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Mon, 10 Mar 2014 19:31:13 +0000 (15:31 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 2 Apr 2014 20:01:37 +0000 (16:01 -0400)
Change-Id: Ifb1436b79a342e3ce169616f65ad293bf5eae1a6
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/23158
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.analysis.xml.ui/build.properties
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/ui/TmfXmlUiStrings.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfAnalysisModuleHelperXml.java
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java

index 567d1ef2d675242f2fc0597d88380a7ae83fd9ea..b282712d8e90ea629da2905c33987876cfbbbe58 100644 (file)
@@ -17,3 +17,5 @@ bin.includes = META-INF/,\
                about.html,\
                plugin.xml
 src.includes = about.html
+additional.bundles = org.eclipse.jdt.annotation
+jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
\ No newline at end of file
diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/ui/TmfXmlUiStrings.java b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/ui/TmfXmlUiStrings.java
new file mode 100644 (file)
index 0000000..fdab483
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.internal.tmf.analysis.xml.ui;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * This file defines all names in the XML Structure for UI elements
+ *
+ * @author Geneviève Bastien
+ */
+@SuppressWarnings({ "javadoc", "nls" })
+@NonNullByDefault
+public interface TmfXmlUiStrings {
+
+    /* XML generic Element attribute names */
+    static final String STATE_PROVIDER_VIEW = "stateSystemView";
+
+    /* View elements and attributes */
+    static final String SSV_LINE = "line";
+    static final String ENTRY_ELEMENT = "entry";
+
+    /* Elements and attributes of view entries */
+    static final String PATH = "path";
+    static final String DISPLAY_ELEMENT = "display";
+    static final String PARENT_ELEMENT = "parent";
+    static final String NAME_ELEMENT = "name";
+    static final String ID_ELEMENT = "id";
+
+    /* Generic strings for the XML module */
+    static final String XML_OUTPUT_DATA = "xmlOutputData";
+
+}
\ No newline at end of file
index 2821108af03b4f25d186a6d1206cc6cffd4cc04a..157e4d20e7a7963028e9cbc5844d447ba58ca146 100644 (file)
@@ -20,9 +20,9 @@ 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.analysis.TmfAnalysisManager;
 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;
@@ -127,8 +127,12 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
 
             /* Set header information if available */
             ssModule.setHeadInfo(fHeadInfo);
+            /*
+             * FIXME: There is no way to know if a module is automatic, so we
+             * default to true
+             */
+            ssModule.setAutomatic(true);
 
-            module.registerOutput(new TmfAnalysisViewOutput("org.eclipse.linuxtools.tmf.ui.views.ssvisualizer")); //$NON-NLS-1$
             break;
         default:
             break;
@@ -136,6 +140,7 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
         }
         if (module != null) {
             module.setTrace(trace);
+            TmfAnalysisManager.analysisModuleCreated(module);
         }
 
         return module;
diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlAnalysisOutputSource.java
new file mode 100644 (file)
index 0000000..50bf81a
--- /dev/null
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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 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.core.analysis.IAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.analysis.ITmfNewAnalysisModuleListener;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+/**
+ * This class searches all XML files to find outputs applicable to the newly
+ * created analysis
+ *
+ * @author Geneviève Bastien
+ */
+public class TmfXmlAnalysisOutputSource implements ITmfNewAnalysisModuleListener {
+
+    /** String separating data elements for the output properties */
+    public static final String DATA_SEPARATOR = ";;;"; //$NON-NLS-1$
+
+    @Override
+    public void moduleCreated(IAnalysisModule module) {
+        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 provider views if the analysis has state systems */
+                /* TODO: Code here will come in later patch */
+
+            } catch (ParserConfigurationException | SAXException | IOException e) {
+                Activator.logError("Error opening XML file", e); //$NON-NLS-1$
+            }
+        }
+    }
+
+}
diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfXmlViewOutput.java
new file mode 100644 (file)
index 0000000..4ee6c64
--- /dev/null
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * 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.jdt.annotation.NonNull;
+import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.TmfXmlUiStrings;
+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.ui.analysis.TmfAnalysisViewOutput;
+import org.w3c.dom.Element;
+
+/**
+ * Class overriding the default analysis view output for XML views. These views
+ * may have labels defined in the XML element and those label will be used as
+ * the name of the view
+ *
+ * @author Geneviève Bastien
+ *
+ *         TODO: We shouldn't have to do a new class here, we should be able to
+ *         set the name in the parent instead
+ */
+public class TmfXmlViewOutput extends TmfAnalysisViewOutput {
+
+    private String fLabel = null;
+
+    /**
+     * Constructor
+     *
+     * @param viewid
+     *            id of the view to display as output
+     */
+    public TmfXmlViewOutput(String viewid) {
+        super(viewid);
+    }
+
+    @Override
+    public String getName() {
+        if (fLabel == null) {
+            return super.getName();
+        }
+        return fLabel;
+    }
+
+    @Override
+    public void setOutputProperty(@NonNull String key, String value, boolean immediate) {
+        super.setOutputProperty(key, value, immediate);
+        /* Find the label of the view */
+        if (key.equals(TmfXmlUiStrings.XML_OUTPUT_DATA)) {
+            String[] idFile = value.split(TmfXmlAnalysisOutputSource.DATA_SEPARATOR);
+            String viewId = (idFile.length > 0) ? idFile[0] : null;
+            String filePath = (idFile.length > 1) ? idFile[1] : null;
+            if ((viewId == null) || (filePath == null)) {
+                return;
+            }
+            Element viewElement = XmlUtils.getElementInFile(filePath, TmfXmlUiStrings.STATE_PROVIDER_VIEW, viewId);
+            if (viewElement == null) {
+                return;
+            }
+            List<Element> heads = XmlUtils.getChildElements(viewElement, TmfXmlStrings.HEAD);
+            if (heads.size() != 1) {
+                return;
+            }
+            Element headElement = heads.get(0);
+            List<Element> label = XmlUtils.getChildElements(headElement, TmfXmlStrings.LABEL);
+            if (label.isEmpty()) {
+                return;
+            }
+            Element labelElement = label.get(0);
+            fLabel = labelElement.getAttribute(TmfXmlStrings.VALUE);
+        }
+    }
+}
index a4335ff5667e81ce04c3687b3db0dce86cd3ab51..05e5f6a974bcc241979946dfec5698dae6dbaa7d 100644 (file)
@@ -56,6 +56,13 @@ public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
 
     private static List<IAnalysisModuleHelper> fModules = null;
 
+    /**
+     * Constructor. It adds the new module listener to the analysis manager.
+     */
+    public XmlAnalysisModuleSource() {
+        TmfAnalysisManager.addNewModuleListener(new TmfXmlAnalysisOutputSource());
+    }
+
     @Override
     public synchronized Iterable<IAnalysisModuleHelper> getAnalysisModules() {
         if (fModules == null) {
This page took 0.043358 seconds and 5 git commands to generate.