TMF: Remove XML header classes, they are not useful anymore
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Mon, 10 Mar 2014 21:39:31 +0000 (17:39 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 22 May 2014 21:09:25 +0000 (17:09 -0400)
With the XmlUtils utility methods, there is no added value to wrap them in
a class and they are accessible from everywhere.

Change-Id: I66d15423ef4dadc18a77caef6af2d63faa426173
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/25584
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/stateprovider/StateProviderModuleTest.java
org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/stateprovider/StateProviderTest.java
org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java [deleted file]
org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java [deleted file]
org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java
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/XmlHeadInfoUi.java [deleted file]

index 2ea92d403f4760f689a35ff1e6d6a7837fa4ba6e..25a1a36d469feffa729ec27d9d3ca683c1ff028e 100644 (file)
@@ -12,7 +12,8 @@ Require-Bundle: org.junit,
  org.eclipse.linuxtools.tmf.core,
  org.eclipse.linuxtools.tmf.core.tests,
  org.eclipse.linuxtools.tmf.ctf.core,
- org.eclipse.linuxtools.tmf.ctf.core.tests
+ org.eclipse.linuxtools.tmf.ctf.core.tests,
+ org.eclipse.linuxtools.statesystem.core
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Bundle-ActivationPolicy: lazy
 Import-Package: org.junit.runners
index 9b099223af6a4ebfd24745dc025f6879c0d6cea0..b705182c33b601a613844a4dfad5a2d093034aed 100644 (file)
@@ -27,7 +27,6 @@ import javax.xml.parsers.ParserConfigurationException;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
-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.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
@@ -94,12 +93,6 @@ public class StateProviderModuleTest {
         assertEquals(ANALYSIS_ID, fModule.getId());
 
         fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
-        NodeList head = node.getElementsByTagName(TmfXmlStrings.HEAD);
-        XmlHeadInfo headInfo = null;
-        if (head.getLength() == 1) {
-            headInfo = new XmlHeadInfo(head.item(0));
-        }
-        fModule.setHeadInfo(headInfo);
 
         assertEquals(ANALYSIS_NAME, fModule.getName());
     }
@@ -123,12 +116,6 @@ public class StateProviderModuleTest {
         fModule.setId(moduleId);
 
         fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
-        NodeList head = node.getElementsByTagName(TmfXmlStrings.HEAD);
-        XmlHeadInfo headInfo = null;
-        if (head.getLength() == 1) {
-            headInfo = new XmlHeadInfo(head.item(0));
-        }
-        fModule.setHeadInfo(headInfo);
 
         try {
             ITmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace();
index 6a4cae9c317245b8321a92da610e0d633c65c6c8..79bc3e290afecfd64ac5b1c025aa81ade60dbe54 100644 (file)
@@ -28,7 +28,6 @@ import javax.xml.parsers.ParserConfigurationException;
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
-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.analysis.xml.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
@@ -90,12 +89,7 @@ public class StateProviderTest {
         fModule.setId(moduleId);
 
         fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
-        NodeList head = node.getElementsByTagName(TmfXmlStrings.HEAD);
-        XmlHeadInfo headInfo = null;
-        if (head.getLength() == 1) {
-            headInfo = new XmlHeadInfo(head.item(0));
-        }
-        fModule.setHeadInfo(headInfo);
+
         try {
             fModule.setTrace(fTrace);
             fModule.schedule();
diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java
deleted file mode 100644 (file)
index 079910e..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * 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.core.module;
-
-/**
- * Interface that XML analysis modules may implement to interpret the extra
- * metadata they may get for example from the header element in the XML file.
- *
- * @author Geneviève Bastien
- */
-public interface IXmlModuleMetadata {
-
-    /**
-     * Set the header information node associated with this module
-     *
-     * @param headInfo
-     *            The header information
-     */
-    void setHeadInfo(XmlHeadInfo headInfo);
-
-}
diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java b/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java
deleted file mode 100644 (file)
index 58d827e..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * 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.core.module;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * Class to store and interpret the header information of XML-defined components
- *
- * @author Geneviève Bastien
- */
-public class XmlHeadInfo {
-
-    private final Node fHeadInfo;
-
-    /**
-     * Constructor
-     *
-     * @param item
-     *            The XML node corresponding to this header
-     */
-    public XmlHeadInfo(Node item) {
-        fHeadInfo = item;
-    }
-
-    /**
-     * Get a list of child elements with the requested name
-     *
-     * @param nodeName
-     *            The name of the nodes to get
-     * @return List of child elements
-     */
-    public List<Element> getElements(String nodeName) {
-        List<Element> list = new ArrayList<>();
-        NodeList nodes = fHeadInfo.getChildNodes();
-        for (int i = 0; i < nodes.getLength(); i++) {
-            Node node = nodes.item(i);
-            if (node instanceof Element) {
-                Element element = (Element) node;
-                if (element.getNodeName().equals(nodeName)) {
-                    list.add(element);
-                }
-            }
-        }
-        return list;
-    }
-
-    /**
-     * Check whether, if this header information has trace types defined, this
-     * component applies to a given trace type.
-     *
-     * @param traceClass
-     *            The trace type to check for
-     * @return True if there is no trace type information in header or if the
-     *         trace type applies
-     */
-    public boolean checkTraceType(Class<? extends ITmfTrace> traceClass) {
-        /*
-         * By default this returns true, child implementation who have access to
-         * trace types will override this
-         *
-         * TODO: actually check the trace type here when trace types are moved
-         * to o.e.l.tmf.core instead of o.e.l.tmf.ui
-         */
-        return true;
-    }
-
-    /**
-     * Get the name of this component from the header information
-     *
-     * @return The name of the component
-     */
-    public String getName() {
-        List<Element> elements = getElements(TmfXmlStrings.LABEL);
-        if (elements.isEmpty()) {
-            return null;
-        }
-
-        Element element = elements.get(0);
-        return element.getAttribute(TmfXmlStrings.VALUE);
-    }
-
-}
index 1e284e3ea738900b122db0cb7a41398fdae1f4e6..bb5932662320448716571287e4dd7a153d0351f1 100644 (file)
 
 package org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider;
 
+import java.util.List;
+
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.linuxtools.tmf.analysis.xml.core.module.IXmlModuleMetadata;
-import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlHeadInfo;
+import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider;
 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.w3c.dom.Element;
 
 /**
  * Analysis module for the data-driven state systems, defined in XML.
@@ -25,11 +27,9 @@ import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
  * @author Geneviève Bastien
  * @since 3.0
  */
-public class XmlStateSystemModule extends TmfStateSystemAnalysisModule
-        implements IXmlModuleMetadata {
+public class XmlStateSystemModule extends TmfStateSystemAnalysisModule {
 
     private IPath fXmlFile;
-    private XmlHeadInfo fHeadInfo = null;
 
     @Override
     protected StateSystemBackendType getBackendType() {
@@ -44,10 +44,17 @@ public class XmlStateSystemModule extends TmfStateSystemAnalysisModule
 
     @Override
     public String getName() {
-        String name = fHeadInfo.getName();
-        if (name == null) {
-            name = getId();
+        String name = getId();
+        Element doc = XmlUtils.getElementInFile(fXmlFile.makeAbsolute().toString(), TmfXmlStrings.STATE_PROVIDER, getId());
+        /* Label may be available in XML header */
+        List<Element> head = XmlUtils.getChildElements(doc, TmfXmlStrings.HEAD);
+        if (head.size() == 1) {
+            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
+            if (!labels.isEmpty()) {
+                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
+            }
         }
+
         return name;
     }
 
@@ -61,11 +68,6 @@ public class XmlStateSystemModule extends TmfStateSystemAnalysisModule
         fXmlFile = file;
     }
 
-    @Override
-    public void setHeadInfo(XmlHeadInfo headInfo) {
-        fHeadInfo = headInfo;
-    }
-
     /**
      * Get the path to the XML file containing this state provider definition.
      *
index 8b6b3c39b853d5f800e6cb913724b21ffb85b3cf..2288bb33cca4cc09d81017f36a80659d18b9bbcc 100644 (file)
@@ -14,9 +14,11 @@ package org.eclipse.linuxtools.tmf.analysis.xml.ui.module;
 
 import java.io.File;
 import java.util.Collections;
+import java.util.List;
 
 import org.eclipse.core.runtime.Path;
 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.core.stateprovider.XmlStateSystemModule;
 import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
@@ -24,10 +26,11 @@ import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
 import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
 import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
+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.osgi.framework.Bundle;
 import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
 
 /**
  * Analysis module helpers for modules provided by XML files
@@ -47,7 +50,6 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
     private final File fSourceFile;
     private final Element fSourceElement;
     private final XmlAnalysisModuleType fType;
-    private final XmlHeadInfoUi fHeadInfo;
 
     /**
      * Constructor
@@ -63,13 +65,6 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
         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
@@ -79,7 +74,16 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
 
     @Override
     public String getName() {
-        String name = fHeadInfo.getName();
+        String name = null;
+        /* Label may be available in XML header */
+        List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
+        if (head.size() == 1) {
+            List<Element> labels = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.LABEL);
+            if (!labels.isEmpty()) {
+                name = labels.get(0).getAttribute(TmfXmlStrings.VALUE);
+            }
+        }
+
         if (name == null) {
             name = getId();
         }
@@ -107,13 +111,28 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
     }
 
     @Override
-    public boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass) {
+    public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
         /* Trace types may be available in XML header */
-        if (fHeadInfo == null) {
+        List<Element> head = XmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
+        if (head.size() != 1) {
+            return true;
+        }
+        /*
+         * TODO: Test with custom trace types
+         */
+        List<Element> elements = XmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
+        if (elements.isEmpty()) {
             return true;
         }
 
-        return fHeadInfo.checkTraceType(traceclass);
+        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;
     }
 
     @Override
@@ -137,8 +156,6 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
             module.setId(analysisid);
             ssModule.setXmlFile(new Path(fSourceFile.getAbsolutePath()));
 
-            /* 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
diff --git a/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlHeadInfoUi.java b/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/XmlHeadInfoUi.java
deleted file mode 100644 (file)
index 1184880..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * 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;
-    }
-
-}
This page took 0.031494 seconds and 5 git commands to generate.