aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Wininger2014-01-13 21:36:50 (EST)
committerGenevieve Bastien2014-01-23 10:22:48 (EST)
commit984a0ca92bce05358887cb238dcbcf5b762708cc (patch)
tree7091b8936a65b4c9863d5f6f42ee03f68fde1f10
parenta1bfcef3204c443cd48a7727638578d4bca48e3c (diff)
downloadorg.eclipse.linuxtools-984a0ca92bce05358887cb238dcbcf5b762708cc.zip
org.eclipse.linuxtools-984a0ca92bce05358887cb238dcbcf5b762708cc.tar.gz
org.eclipse.linuxtools-984a0ca92bce05358887cb238dcbcf5b762708cc.tar.bz2
TMF: Add XML state provider analysis module and XML utilitiesrefs/changes/14/19914/10
This patch adds an analysis module for an XML-defined state system. It does not actually build the state system, the details will come in another patch. It also contains the [stripped-down] XML schema definition and the methods to read an XML file and validate it. Change-Id: I2a3d322f96742d995912700d223e2ecb9e07d8f5 Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Signed-off-by: Florian Wininger <florian.wininger@polymtl.ca> Reviewed-on: https://git.eclipse.org/r/19914 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/.classpath1
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF9
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/build.properties3
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/plugin.properties4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/Activator.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/AllAnalysisXmlCoreTests.java7
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/XmlAnalysisCorePluginTest.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/AllTests.java27
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java107
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/stubs/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java52
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_invalid.xml7
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_valid.xml22
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF8
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/plugin.properties2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/core/Activator.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java31
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/Messages.java41
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java100
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlUtils.java143
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/messages.properties4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/xmldefinition.xsd48
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java33
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java164
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java78
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/Activator.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/AllAnalysisXmlUiTests.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/XmlAnalysisUiPluginTest.java4
27 files changed, 889 insertions, 26 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/.classpath b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/.classpath
index 098194c..f1d3296 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/.classpath
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/.classpath
@@ -3,5 +3,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="stubs"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF
index cdcc097..b7463bd 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/META-INF/MANIFEST.MF
@@ -5,12 +5,13 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tmf.analysis.xml.core.tests
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.linuxtools.tmf.analysis.xml.core.tests.Activator
Bundle-Vendor: %Bundle-Vendor
-Require-Bundle: org.eclipse.ui,
+Require-Bundle: org.junit,
org.eclipse.core.runtime,
- org.junit,
- 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.core,
+ org.eclipse.linuxtools.tmf.core.tests
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Import-Package: org.junit.runners
+Export-Package: org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common;x-friends:="org.eclipse.linuxtools.tmf.analysis.xml.ui.tests"
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/build.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/build.properties
index 9cbab3c..73ce20d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/build.properties
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/build.properties
@@ -1,4 +1,5 @@
-source.. = src/
+source.. = src/,\
+ stubs/
output.. = bin/
bin.includes = META-INF/,\
.,\
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/plugin.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/plugin.properties
index b061a75..9b58acf 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/plugin.properties
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/plugin.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2013 École Polytechnique de Montréal
+# Copyright (c) 2013, 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
@@ -12,4 +12,4 @@
#Properties file for org.eclipse.linuxtools.tmf.core
Bundle-Vendor = Eclipse Linux Tools
-Bundle-Name = Linux Tools TMF Xml Analysis Tests Plug-in
+Bundle-Name = Linux Tools TMF XML Analysis Tests Plug-in
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/Activator.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/Activator.java
index 08231ec..4f5cda4 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/Activator.java
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/Activator.java
@@ -12,13 +12,13 @@
package org.eclipse.linuxtools.tmf.analysis.xml.core.tests;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
-public class Activator extends AbstractUIPlugin {
+public class Activator extends Plugin {
/**
* The plug-in ID
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/AllAnalysisXmlCoreTests.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/AllAnalysisXmlCoreTests.java
index ce4f1d8..7d2b6ec 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/AllAnalysisXmlCoreTests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/AllAnalysisXmlCoreTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013, 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
@@ -16,11 +16,12 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
- * Master test suite for TMF Xml Core Analysis plug-in.
+ * Master test suite for TMF XML Core Analysis plug-in.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- XmlAnalysisCorePluginTest.class
+ XmlAnalysisCorePluginTest.class,
+ org.eclipse.linuxtools.tmf.analysis.xml.core.tests.module.AllTests.class
})
public class AllAnalysisXmlCoreTests {
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/XmlAnalysisCorePluginTest.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/XmlAnalysisCorePluginTest.java
index 3509a67..993b118 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/XmlAnalysisCorePluginTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/XmlAnalysisCorePluginTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013, 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
@@ -18,7 +18,7 @@ import org.eclipse.linuxtools.internal.tmf.analysis.xml.core.Activator;
import org.junit.Test;
/**
- * Test the Xml Analysis Core plug-in activator
+ * Test the XML Analysis Core plug-in activator
*/
public class XmlAnalysisCorePluginTest {
// ------------------------------------------------------------------------
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/AllTests.java
new file mode 100644
index 0000000..ca0aa28
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/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.core.tests.module;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for org.eclipse.linuxtools.tmf.analysis.xml.core.module package
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ XmlUtilsTest.class
+})
+public class AllTests {
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java
new file mode 100644
index 0000000..1dd8200
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/module/XmlUtilsTest.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.tests.module;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
+import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
+import org.junit.After;
+import org.junit.Test;
+
+/**
+ * Tests for the {@link XmlUtils} class
+ *
+ * @author Geneviève Bastien
+ */
+public class XmlUtilsTest {
+
+ /**
+ * Empty the XML directory after the test
+ */
+ @After
+ public void emptyXmlFolder() {
+ File fFolder = XmlUtils.getXmlFilesPath().toFile();
+ if (!(fFolder.isDirectory() && fFolder.exists())) {
+ return;
+ }
+ for (File xmlFile : fFolder.listFiles()) {
+ xmlFile.delete();
+ }
+ }
+
+ /**
+ * Test the {@link XmlUtils#getXmlFilesPath()} method
+ */
+ @Test
+ public void testXmlPath() {
+ IPath xmlPath = XmlUtils.getXmlFilesPath();
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IPath workspacePath = workspace.getRoot().getRawLocation();
+ workspacePath = workspacePath.addTrailingSeparator()
+ .append(".metadata").addTrailingSeparator().append(".plugins")
+ .addTrailingSeparator()
+ .append("org.eclipse.linuxtools.tmf.analysis.xml.core")
+ .addTrailingSeparator().append("xml_files");
+
+ assertEquals(xmlPath, workspacePath);
+ }
+
+ /**
+ * test the {@link XmlUtils#xmlValidate(File)} method
+ */
+ @Test
+ public void testXmlValidate() {
+ File testXmlFile = TmfXmlTestFiles.VALID_FILE.getFile();
+ if ((testXmlFile == null) || !testXmlFile.exists()) {
+ fail("XML test file does not exist");
+ }
+ assertTrue(XmlUtils.xmlValidate(testXmlFile).isOK());
+
+ testXmlFile = TmfXmlTestFiles.INVALID_FILE.getFile();
+ if ((testXmlFile == null) || !testXmlFile.exists()) {
+ fail("XML test file does not exist");
+ }
+ assertFalse(XmlUtils.xmlValidate(testXmlFile).isOK());
+ }
+
+ /**
+ * test the {@link XmlUtils#addXmlFile(File)} method
+ */
+ @Test
+ public void testXmlAddFile() {
+ /* Check the file does not exist */
+ IPath xmlPath = XmlUtils.getXmlFilesPath().addTrailingSeparator().append("test_valid.xml");
+ File destFile = xmlPath.toFile();
+ assertFalse(destFile.exists());
+
+ /* Add test_valid.xml file */
+ File testXmlFile = TmfXmlTestFiles.VALID_FILE.getFile();
+ if ((testXmlFile == null) || !testXmlFile.exists()) {
+ fail("XML test file does not exist");
+ }
+
+ XmlUtils.addXmlFile(testXmlFile);
+ assertTrue(destFile.exists());
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/stubs/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/stubs/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java
new file mode 100644
index 0000000..2274bd8
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/stubs/org/eclipse/linuxtools/tmf/analysis/xml/core/tests/common/TmfXmlTestFiles.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.tests.common;
+
+import java.io.File;
+
+/**
+ * Provides some test XML files to use
+ *
+ * @author Geneviève Bastien
+ */
+public enum TmfXmlTestFiles {
+ /** A valid XML test file */
+ VALID_FILE("../org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_valid.xml"),
+ /** An invalid test file */
+ INVALID_FILE("../org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_invalid.xml");
+
+ private final String fPath;
+
+ private TmfXmlTestFiles(String file) {
+ fPath = file;
+ }
+
+ /**
+ * Get the file name part of the file
+ *
+ * @return The path of this test file
+ */
+ public String getPath() {
+ return fPath;
+ }
+
+ /**
+ * Returns the file object corresponding to the test XML file
+ *
+ * @return The file object for this test file
+ */
+ public File getFile() {
+ return new File(fPath);
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_invalid.xml b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_invalid.xml
new file mode 100644
index 0000000..dcd5512
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_invalid.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tmfxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="stateprovider.xsd">
+
+ <!-- This element does not belong to the schema -->
+ <element id="fail"></element>
+</tmfxml> \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_valid.xml b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_valid.xml
new file mode 100644
index 0000000..e8895dd
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core.tests/test_xml_files/test_valid.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- ***************************************************************************
+ * Copyright (c) 2013 É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:
+ * Florian Wininger - Initial API and implementation
+ *************************************************************************** -->
+<tmfxml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="stateprovider.xsd">
+
+ <stateProvider analysisId="polymtl.kernel.sp" version="1">
+ <head>
+ <traceType id="org.eclipse.linuxtools.lttng2.kernel.tracetype" />
+ <label value="Xml kernel State System" />
+ </head>
+ </stateProvider>
+</tmfxml> \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF
index 40cc526..46034f2 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/META-INF/MANIFEST.MF
@@ -8,7 +8,9 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tmf.analysis.xml.core;singleton:=tru
Bundle-Activator: org.eclipse.linuxtools.internal.tmf.analysis.xml.core.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
+Require-Bundle: org.eclipse.core.runtime,
org.eclipse.linuxtools.tmf.core
-Export-Package: org.eclipse.linuxtools.internal.tmf.analysis.xml.core;x-friends:="org.eclipse.linuxtools.tmf.analysis.xml.core.tests"
+Export-Package: org.eclipse.linuxtools.internal.tmf.analysis.xml.core;x-friends:="org.eclipse.linuxtools.tmf.analysis.xml.core.tests",
+ org.eclipse.linuxtools.tmf.analysis.xml.core.module,
+ org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider
+
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/plugin.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/plugin.properties
index 8703303..eeb5439 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/plugin.properties
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/plugin.properties
@@ -12,5 +12,5 @@
#Properties file for org.eclipse.linuxtools.tmf.core
Bundle-Vendor = Eclipse Linux Tools
-Bundle-Name = Linux Tools TMF Xml Analysis Core Plug-in
+Bundle-Name = Linux Tools TMF XML Analysis Core Plug-in
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/core/Activator.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/core/Activator.java
index 5c8ae8d..dd9cc1d 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/core/Activator.java
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/internal/tmf/analysis/xml/core/Activator.java
@@ -13,8 +13,8 @@
package org.eclipse.linuxtools.internal.tmf.analysis.xml.core;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
@@ -22,7 +22,7 @@ import org.osgi.framework.BundleContext;
*
* @author Geneviève Bastien
*/
-public class Activator extends AbstractUIPlugin {
+public class Activator extends Plugin {
/** The plug-in ID */
public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.core"; //$NON-NLS-1$
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java
new file mode 100644
index 0000000..079910e
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/IXmlModuleMetadata.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/Messages.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/Messages.java
new file mode 100644
index 0000000..b8ac122
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/Messages.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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 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.core.module.messages"; //$NON-NLS-1$
+
+ /** Error copying XML file to workspace folder */
+ public static String XmlUtils_ErrorCopyingFile;
+ /** XML parse error */
+ public static String XmlUtils_XmlParseError;
+ /** Error occurred while validating XML */
+ public static String XmlUtils_XmlValidateError;
+ /** XML validation error */
+ public static String XmlUtils_XmlValidationError;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java
new file mode 100644
index 0000000..58d827e
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlHeadInfo.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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);
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlUtils.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlUtils.java
new file mode 100644
index 0000000..79294ea
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/XmlUtils.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * 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.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.channels.FileChannel;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.tmf.analysis.xml.core.Activator;
+import org.eclipse.osgi.util.NLS;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Class containing some utilities for the XML plug-in packages: for example, it
+ * manages the XML files and validates them
+ *
+ * @author Geneviève Bastien
+ */
+public class XmlUtils {
+
+ /** Sub-directory of the plug-in where XML files are stored */
+ private static final String XML_DIRECTORY = "xml_files"; //$NON-NLS-1$
+
+ /** Name of the XSD schema file */
+ private static final String XSD = "xmldefinition.xsd"; //$NON-NLS-1$
+
+ /** Make this class non-instantiable */
+ private XmlUtils() {
+
+ }
+
+ /**
+ * Get the path where the XML files are stored. Create it if it does not
+ * exist
+ *
+ * @return path to XML files
+ */
+ public static IPath getXmlFilesPath() {
+ IPath path = Activator.getDefault().getStateLocation();
+ path = path.addTrailingSeparator().append(XML_DIRECTORY);
+
+ /* Check if directory exists, otherwise create it */
+ File dir = path.toFile();
+ if (!dir.exists() || !dir.isDirectory()) {
+ dir.mkdirs();
+ }
+
+ return path;
+ }
+
+ /**
+ * Validate the XML file input with the XSD schema
+ *
+ * @param xmlFile
+ * XML file to validate
+ * @return True if the XML validates
+ */
+ public static IStatus xmlValidate(File xmlFile) {
+ URL url = XmlUtils.class.getResource(XSD);
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Source xmlSource = new StreamSource(xmlFile);
+ try {
+ Schema schema = schemaFactory.newSchema(url);
+ Validator validator = schema.newValidator();
+ validator.validate(xmlSource);
+ } catch (SAXParseException e) {
+ String error = NLS.bind(Messages.XmlUtils_XmlParseError, e.getLineNumber(), e.getLocalizedMessage());
+ Activator.logError(error);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+ } catch (SAXException e) {
+ String error = NLS.bind(Messages.XmlUtils_XmlValidationError, e.getLocalizedMessage());
+ Activator.logError(error);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+ } catch (IOException e) {
+ String error = Messages.XmlUtils_XmlValidateError;
+ Activator.logError("IO exception occurred", e); //$NON-NLS-1$
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Adds an XML file to the plugin's path. The XML file should have been
+ * validated using the {@link XmlUtils#xmlValidate(File)} method before
+ * calling this method.
+ *
+ * @param fromFile
+ * The XML file to add
+ * @return Whether the file was successfully added
+ */
+ public static IStatus addXmlFile(File fromFile) {
+
+ /* Copy file to path */
+ File toFile = getXmlFilesPath().addTrailingSeparator().append(fromFile.getName()).toFile();
+
+ try {
+ if (!toFile.exists()) {
+ toFile.createNewFile();
+ }
+ } catch (IOException e) {
+ String error = Messages.XmlUtils_ErrorCopyingFile;
+ Activator.logError(error, e);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+ }
+
+ try (FileInputStream fis = new FileInputStream(fromFile);
+ FileOutputStream fos = new FileOutputStream(toFile);
+ FileChannel source = fis.getChannel();
+ FileChannel destination = fos.getChannel();) {
+ destination.transferFrom(source, 0, source.size());
+ } catch (IOException e) {
+ String error = Messages.XmlUtils_ErrorCopyingFile;
+ Activator.logError(error, e);
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, error, e);
+ }
+ return Status.OK_STATUS;
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/messages.properties b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/messages.properties
new file mode 100644
index 0000000..7ec73d7
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/messages.properties
@@ -0,0 +1,4 @@
+XmlUtils_ErrorCopyingFile=An error occurred while copying the XML file to the TMF directory. The file was not imported.
+XmlUtils_XmlParseError=XML Parsing error at line {0}: {1}
+XmlUtils_XmlValidateError=An error occurred while validating the XML file.
+XmlUtils_XmlValidationError=Error validating XML file {0}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/xmldefinition.xsd b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/xmldefinition.xsd
new file mode 100644
index 0000000..281ec6d
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/module/xmldefinition.xsd
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- ***************************************************************************
+ * 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:
+ * Florian Wininger - Initial API and implementation
+ *************************************************************************** -->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ attributeFormDefault="unqualified" elementFormDefault="qualified">
+
+ <xs:element name="tmfxml">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="stateProvider" type="stateProvider" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name="stateProvider">
+ <xs:sequence maxOccurs="1" minOccurs="1">
+ <xs:element maxOccurs="1" minOccurs="0" name="head"
+ type="headProvider" />
+ </xs:sequence>
+ <xs:attribute name="analysisId" type="xs:string" use="required" />
+ <xs:attribute name="version" type="xs:integer" use="required" />
+ </xs:complexType>
+
+ <xs:complexType name="headProvider">
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0" name="traceType">
+ <xs:complexType>
+ <xs:attribute name="id" />
+ </xs:complexType>
+ </xs:element>
+ <xs:element maxOccurs="1" minOccurs="0" name="label">
+ <xs:complexType>
+ <xs:attribute name="value" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+
+</xs:schema>
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
new file mode 100644
index 0000000..ede1402
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/TmfXmlStrings.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ecole Polytechnique
+ *
+ * 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:
+ * Florian Wininger - Initial implementation
+ ******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider;
+
+/**
+ * This file defines all name in the XML Structure for the State Provider
+ *
+ * @author Florian Wininger
+ */
+@SuppressWarnings({ "javadoc", "nls" })
+public interface TmfXmlStrings {
+
+ /* XML Node Name */
+ static final String STATE_PROVIDER = "stateProvider";
+ static final String VALUE = "value";
+ static final String LABEL = "label";
+
+ /* XML Node Attribute */
+ static final String ANALYSIS_ID = "analysisId";
+ static final String NAME = "name";
+ static final String VERSION = "version";
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java
new file mode 100644
index 0000000..64340e4
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateProvider.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * 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:
+ * Florian Wininger - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider;
+
+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.core.Activator;
+import org.eclipse.linuxtools.tmf.analysis.xml.core.module.Messages;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.osgi.util.NLS;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * This is the state change input plug-in for TMF's state system which handles
+ * the XML Format
+ *
+ * @author Florian Wininger
+ */
+public class XmlStateProvider extends AbstractTmfStateProvider {
+
+ private final IPath fFilePath;
+ private final String fStateId;
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Instantiate a new state provider plug-in.
+ *
+ * @param trace
+ * The trace
+ * @param stateid
+ * The state system id, corresponding to the analysis_id
+ * attribute of the state provider element of the XML file
+ * @param file
+ * Path to the XML file containing the state provider definition
+ */
+ public XmlStateProvider(ITmfTrace trace, String stateid, IPath file) {
+ super(trace, ITmfEvent.class, stateid);
+ fStateId = stateid;
+ fFilePath = file;
+ }
+
+ /**
+ * Get the state id of the state provider
+ *
+ * @return The state id of the state provider
+ */
+ public String getStateId() {
+ return fStateId;
+ }
+
+ // ------------------------------------------------------------------------
+ // IStateChangeInput
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int getVersion() {
+ Node ssNode = loadXMLNode();
+ if (ssNode instanceof Element) {
+ Element element = (Element) ssNode;
+ return Integer.valueOf(element.getAttribute(TmfXmlStrings.VERSION));
+ }
+ /*
+ * The version attribute is mandatory and XML files that don't validate
+ * with the XSD are ignored, so this should never happen
+ */
+ throw new IllegalStateException("The state provider XML node should have a version attribute"); //$NON-NLS-1$
+ }
+
+ @Override
+ public XmlStateProvider getNewInstance() {
+ return new XmlStateProvider(this.getTrace(), getStateId(), fFilePath);
+ }
+
+ @Override
+ protected void eventHandle(ITmfEvent event) {
+ /* TODO: This method will be filled a few patches later */
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Loads the XML file and returns the element at the root of the current
+ * state provider.
+ *
+ * @return The XML node at the root of the state provider
+ */
+ protected Node loadXMLNode() {
+
+ try {
+ File XMLFile = fFilePath.toFile();
+ if (XMLFile == null || !XMLFile.exists() || !XMLFile.isFile()) {
+ return null;
+ }
+
+ /* Load the XML File */
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder;
+
+ dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(XMLFile);
+ doc.getDocumentElement().normalize();
+
+ /* get the state providers and find the corresponding one */
+ NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
+ Element stateproviderNode = null;
+
+ for (int i = 0; i < stateproviderNodes.getLength(); i++) {
+ Element node = (Element) stateproviderNodes.item(i);
+ String analysisid = node.getAttribute(TmfXmlStrings.ANALYSIS_ID);
+ if (analysisid.equals(fStateId)) {
+ stateproviderNode = node;
+ }
+ }
+
+ return stateproviderNode;
+ } catch (ParserConfigurationException | IOException e) {
+ Activator.logError("Error loading XML file", e); //$NON-NLS-1$
+ } catch (SAXException e) {
+ Activator.logError(NLS.bind(Messages.XmlUtils_XmlValidationError, e.getLocalizedMessage()), e);
+ }
+
+ return null;
+ }
+
+ /**
+ * Function to load the XML file structure
+ */
+ protected void loadXML() {
+ Element doc = (Element) loadXMLNode();
+ if (doc == null) {
+ return;
+ }
+
+ /* TODO: This method will be filled a few patches later */
+ }
+
+} \ No newline at end of file
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java
new file mode 100644
index 0000000..1e284e3
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.core/src/org/eclipse/linuxtools/tmf/analysis/xml/core/stateprovider/XmlStateSystemModule.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.stateprovider;
+
+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.core.statesystem.ITmfStateProvider;
+import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+
+/**
+ * Analysis module for the data-driven state systems, defined in XML.
+ *
+ * @author Geneviève Bastien
+ * @since 3.0
+ */
+public class XmlStateSystemModule extends TmfStateSystemAnalysisModule
+ implements IXmlModuleMetadata {
+
+ private IPath fXmlFile;
+ private XmlHeadInfo fHeadInfo = null;
+
+ @Override
+ protected StateSystemBackendType getBackendType() {
+ return StateSystemBackendType.FULL;
+ }
+
+ @Override
+ @NonNull
+ protected ITmfStateProvider createStateProvider() {
+ return new XmlStateProvider(getTrace(), getId(), fXmlFile);
+ }
+
+ @Override
+ public String getName() {
+ String name = fHeadInfo.getName();
+ if (name == null) {
+ name = getId();
+ }
+ return name;
+ }
+
+ /**
+ * Sets the file path of the XML file containing the state provider
+ *
+ * @param file
+ * The full path to the XML file
+ */
+ public void setXmlFile(IPath file) {
+ fXmlFile = file;
+ }
+
+ @Override
+ public void setHeadInfo(XmlHeadInfo headInfo) {
+ fHeadInfo = headInfo;
+ }
+
+ /**
+ * Get the path to the XML file containing this state provider definition.
+ *
+ * @return XML file path
+ */
+ public IPath getXmlFile() {
+ return fXmlFile;
+ }
+
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/Activator.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/Activator.java
index 2e03642..8d59881 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/Activator.java
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013, 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
@@ -23,7 +23,7 @@ public class Activator extends AbstractUIPlugin {
/**
* The plug-in ID
*/
- public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.tests"; //$NON-NLS-1$
+ public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.analysis.xml.ui.tests"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
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 5814469..2b0dd54 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013, 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
@@ -16,7 +16,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
/**
- * Master test suite for TMF Xml Analysis UI plug-in.
+ * Master test suite for TMF XML Analysis UI plug-in.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
diff --git a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/XmlAnalysisUiPluginTest.java b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/XmlAnalysisUiPluginTest.java
index a673bb9..4fdef05 100644
--- a/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/XmlAnalysisUiPluginTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui.tests/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/tests/XmlAnalysisUiPluginTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 École Polytechnique de Montréal
+ * Copyright (c) 2013, 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
@@ -18,7 +18,7 @@ import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator;
import org.junit.Test;
/**
- * Test the Xml Analysis UI plug-in activator
+ * Test the XML Analysis UI plug-in activator
*
* @author Geneviève Bastien
*/