aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Rail2014-02-14 14:47:26 (EST)
committerMatthew Khouzam2014-04-15 22:55:52 (EDT)
commit3fc8d5fff5a84296812a46212239c7c5ea66323a (patch)
tree4c173770788720f6ce3c1edff63a388426b6ca77
parenta215944a89644ffa58c6b8985ce405d9a8cd73a8 (diff)
downloadorg.eclipse.linuxtools-3fc8d5fff5a84296812a46212239c7c5ea66323a.zip
org.eclipse.linuxtools-3fc8d5fff5a84296812a46212239c7c5ea66323a.tar.gz
org.eclipse.linuxtools-3fc8d5fff5a84296812a46212239c7c5ea66323a.tar.bz2
TMF: Add an API to query analyses to obtain their requirementsrefs/changes/89/22389/12
Change-Id: I764291e0ca5281550a16d61a9aa8dbf5ca05d390 Signed-off-by: Mathieu Rail <contact@mathieurail.com> Signed-off-by: Guilliano Molaire <guilliamo-jaime.molaire@polymtl.ca> Reviewed-on: https://git.eclipse.org/r/22389 Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.analysis.xml.ui/src/org/eclipse/linuxtools/tmf/analysis/xml/ui/module/TmfAnalysisModuleHelperXml.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java7
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementTest.java243
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/AnalysisModuleTestHelper.java12
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java3
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModuleHelper.java9
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisRequirementProvider.java32
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java5
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java13
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java233
10 files changed, 562 insertions, 7 deletions
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
index 157e4d2..8b6b3c3 100644
--- 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
@@ -13,6 +13,7 @@
package org.eclipse.linuxtools.tmf.analysis.xml.ui.module;
import java.io.File;
+import java.util.Collections;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.internal.tmf.analysis.xml.ui.Activator;
@@ -21,6 +22,7 @@ import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystem
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.analysis.TmfAnalysisRequirement;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.osgi.framework.Bundle;
@@ -115,6 +117,16 @@ public class TmfAnalysisModuleHelperXml implements IAnalysisModuleHelper {
}
@Override
+ public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override
+ public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override
public IAnalysisModule newModule(ITmfTrace trace) throws TmfAnalysisException {
String analysisid = getId();
IAnalysisModule module = null;
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java
index 878bf48..8dbb609 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AllTests.java
@@ -20,10 +20,11 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- AnalysisManagerTest.class,
- AnalysisModuleHelperTest.class,
AnalysisModuleTest.class,
- AnalysisParameterProviderTest.class
+ AnalysisModuleHelperTest.class,
+ AnalysisManagerTest.class,
+ AnalysisParameterProviderTest.class,
+ AnalysisRequirementTest.class
})
public class AllTests {
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementTest.java
new file mode 100644
index 0000000..502d270
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/analysis/AnalysisRequirementTest.java
@@ -0,0 +1,243 @@
+/*******************************************************************************
+ * 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:
+ * Guilliano Molaire - Initial API and implementation
+ * Mathieu Rail - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.tests.analysis;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+/**
+ * Test suite for the {@link TmfAnalysisRequirement} class.
+ *
+ * @author Guilliano Molaire
+ * @author Mathieu Rail
+ */
+public class AnalysisRequirementTest {
+
+ /* Requirements used in the tests */
+ private TmfAnalysisRequirement fRequirement;
+ private TmfAnalysisRequirement fSubRequirement;
+
+ /* Types of requirement type strings */
+ private static final String TYPE_A = "Test Type A";
+ private static final String TYPE_B = "Test Type B";
+
+ /* Requirement value name strings */
+ private static final String VALUE_A = "Test Value A";
+ private static final String VALUE_B = "Test Value B";
+ private static final String VALUE_C = "Test Value C";
+ private static final String VALUE_D = "Test Value D";
+ private static final String VALUE_E = "Test Value E";
+ private static final String VALUE_F = "Test Value F";
+
+ /* Requirement information strings */
+ private static final String INFO_A = "This is an information.";
+ private static final String INFO_B = "This is another information.";
+ private static final String INFO_C = "This is the last information.";
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#addInformation} and the
+ * {@link TmfAnalysisRequirement#getInformation} methods.
+ */
+ @Test
+ public void testAddAndGetInformation() {
+ fRequirement = new TmfAnalysisRequirement(TYPE_A);
+
+ fRequirement.addInformation(INFO_A);
+ fRequirement.addInformation(INFO_B);
+ fRequirement.addInformation(INFO_B);
+
+ Set<String> information = fRequirement.getInformation();
+
+ assertEquals(2, information.size());
+
+ assertTrue(information.contains(INFO_A));
+ assertTrue(information.contains(INFO_B));
+ }
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#addValues} and the
+ * {@link TmfAnalysisRequirement#addValue} methods.
+ */
+ @Test
+ public void testAddValuesToRequirement() {
+ fRequirement = new TmfAnalysisRequirement(TYPE_A);
+
+ assertEquals(0, fRequirement.getValues().size());
+
+ List<String> values = new ArrayList<>();
+ values.add(VALUE_A);
+ values.add(VALUE_B);
+ values.add(VALUE_C);
+ values.add(VALUE_C);
+
+ /*
+ * Add values to the requirement with the same level, Value C should
+ * only exist once
+ */
+ fRequirement.addValues(values, ValuePriorityLevel.MANDATORY);
+ assertEquals(3, fRequirement.getValues().size());
+
+ /*
+ * The new value should only exist once and its level should be
+ * mandatory
+ */
+ fRequirement.addValue(VALUE_D, ValuePriorityLevel.OPTIONAL);
+ fRequirement.addValue(VALUE_D, ValuePriorityLevel.MANDATORY);
+
+ assertEquals(4, fRequirement.getValues().size());
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_D));
+ }
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#getValueLevel} method.
+ */
+ @Test
+ public void testGetValueLevel() {
+ fRequirement = new TmfAnalysisRequirement(TYPE_A);
+ fRequirement.addValue(VALUE_A, ValuePriorityLevel.OPTIONAL);
+
+ /* Try to get the level of a value */
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_A));
+
+ /* Try to get the level of a value that doesn't exist */
+ assertNull(fRequirement.getValueLevel(VALUE_B));
+ }
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#merge} method with the
+ * parameter value MANDATORY.
+ */
+ @Test
+ public void testMergeMandatory() {
+ initMergeRequirements(TYPE_A, TYPE_A);
+
+ assertTrue(fRequirement.merge(fSubRequirement, ValuePriorityLevel.MANDATORY));
+
+ assertEquals(fRequirement.getValues().size(), 6);
+
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_A));
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_B));
+
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_C));
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_D));
+
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_E));
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_F));
+
+ Set<String> information = fRequirement.getInformation();
+
+ assertEquals(3, information.size());
+
+ assertTrue(information.contains(INFO_A));
+ assertTrue(information.contains(INFO_B));
+ assertTrue(information.contains(INFO_C));
+ }
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#merge} method with the
+ * parameter value OPTIONAL.
+ */
+ @Test
+ public void testMergeOptional() {
+ initMergeRequirements(TYPE_A, TYPE_A);
+
+ assertTrue(fRequirement.merge(fSubRequirement, ValuePriorityLevel.OPTIONAL));
+
+ assertEquals(6, fRequirement.getValues().size());
+
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_A));
+ assertEquals(ValuePriorityLevel.MANDATORY, fRequirement.getValueLevel(VALUE_B));
+
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_C));
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_D));
+
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_E));
+ assertEquals(ValuePriorityLevel.OPTIONAL, fRequirement.getValueLevel(VALUE_F));
+
+ Set<String> information = fRequirement.getInformation();
+
+ assertEquals(3, information.size());
+
+ assertTrue(information.contains(INFO_A));
+ assertTrue(information.contains(INFO_B));
+ assertTrue(information.contains(INFO_C));
+ }
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#merge} method with
+ * different requirement types.
+ */
+ @Test
+ public void testMergeDifferentTypes() {
+ initMergeRequirements(TYPE_A, TYPE_B);
+
+ assertFalse(fRequirement.merge(fSubRequirement, ValuePriorityLevel.OPTIONAL));
+ }
+
+ /**
+ * Test suite for the {@link TmfAnalysisRequirement#isSameType} method.
+ */
+ @Test
+ public void testIsSameRequirementType() {
+ fRequirement = new TmfAnalysisRequirement(TYPE_A);
+
+ assertTrue(fRequirement.isSameType(new TmfAnalysisRequirement(TYPE_A)));
+ assertFalse(fRequirement.isSameType(new TmfAnalysisRequirement(TYPE_B)));
+ }
+
+ /**
+ * Initialize the requirement and sub-requirement for the merge tests.
+ *
+ * @param typeA
+ * The type of the first requirement
+ * @param typeB
+ * The type of the second requirement
+ */
+ private void initMergeRequirements(String typeA, String typeB) {
+ fRequirement = new TmfAnalysisRequirement(typeA);
+ fRequirement.addValue(VALUE_A, ValuePriorityLevel.MANDATORY);
+ fRequirement.addValue(VALUE_B, ValuePriorityLevel.MANDATORY);
+
+ fRequirement.addValue(VALUE_C, ValuePriorityLevel.OPTIONAL);
+ fRequirement.addValue(VALUE_D, ValuePriorityLevel.OPTIONAL);
+
+ fRequirement.addInformation(INFO_A);
+ fRequirement.addInformation(INFO_B);
+
+ /* This sub-requirement will be merged into requirement */
+ fSubRequirement = new TmfAnalysisRequirement(typeB);
+ fSubRequirement.addValue(VALUE_A, ValuePriorityLevel.MANDATORY);
+ fSubRequirement.addValue(VALUE_B, ValuePriorityLevel.OPTIONAL);
+
+ fSubRequirement.addValue(VALUE_C, ValuePriorityLevel.MANDATORY);
+ fSubRequirement.addValue(VALUE_D, ValuePriorityLevel.OPTIONAL);
+
+ fSubRequirement.addValue(VALUE_E, ValuePriorityLevel.MANDATORY);
+ fSubRequirement.addValue(VALUE_F, ValuePriorityLevel.OPTIONAL);
+
+ fSubRequirement.addInformation(INFO_B);
+ fSubRequirement.addInformation(INFO_C);
+ }
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/AnalysisModuleTestHelper.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/AnalysisModuleTestHelper.java
index 35b7b76..dc8165b 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/AnalysisModuleTestHelper.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/stubs/org/eclipse/linuxtools/tmf/tests/stubs/analysis/AnalysisModuleTestHelper.java
@@ -12,9 +12,12 @@
package org.eclipse.linuxtools.tmf.tests.stubs.analysis;
+import java.util.Collections;
+
import org.eclipse.core.runtime.Platform;
import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.tests.stubs.trace.TmfTraceStub;
@@ -117,4 +120,13 @@ public class AnalysisModuleTestHelper implements IAnalysisModuleHelper {
return module;
}
+ @Override
+ public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override
+ public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+ return Collections.EMPTY_SET;
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java
index 05d1d84..98b6511 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModule.java
@@ -42,7 +42,7 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
* @author Geneviève Bastien
* @since 3.0
*/
-public interface IAnalysisModule extends ITmfComponent {
+public interface IAnalysisModule extends ITmfComponent, IAnalysisRequirementProvider {
// --------------------------------------------------------
// Getters and setters
@@ -239,5 +239,4 @@ public interface IAnalysisModule extends ITmfComponent {
* The of the parameter that changed
*/
void notifyParameterChanged(String name);
-
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModuleHelper.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModuleHelper.java
index 91134ee..2529825 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModuleHelper.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisModuleHelper.java
@@ -23,7 +23,7 @@ import org.osgi.framework.Bundle;
* @author Geneviève Bastien
* @since 3.0
*/
-public interface IAnalysisModuleHelper {
+public interface IAnalysisModuleHelper extends IAnalysisRequirementProvider {
// ------------------------------------
// Getters
@@ -90,6 +90,13 @@ public interface IAnalysisModuleHelper {
*/
boolean appliesToTraceType(Class<? extends ITmfTrace> traceclass);
+ /**
+ * Gets the list of valid trace types that the analysis can operate on.
+ *
+ * @return List of the trace type
+ */
+ Iterable<Class<? extends ITmfTrace>> getValidTraceTypes();
+
// ---------------------------------------
// Functionalities
// ---------------------------------------
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisRequirementProvider.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisRequirementProvider.java
new file mode 100644
index 0000000..f1744ba
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/IAnalysisRequirementProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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:
+ * Guilliano Molaire - Initial API and implementation
+ * Mathieu Rail - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.analysis;
+
+/**
+ * Interface that provides the necessary methods for an analysis to define its
+ * requirements.
+ *
+ * @author Guilliano Molaire
+ * @author Mathieu Rail
+ * @since 3.0
+ */
+public interface IAnalysisRequirementProvider {
+
+ /**
+ * Gets the requirements associated with this analysis.
+ *
+ * @return List of requirement
+ */
+ Iterable<TmfAnalysisRequirement> getAnalysisRequirements();
+}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java
index 89ce13e..83632f8 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAbstractAnalysisModule.java
@@ -13,6 +13,7 @@
package org.eclipse.linuxtools.tmf.core.analysis;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -416,4 +417,8 @@ public abstract class TmfAbstractAnalysisModule extends TmfComponent implements
return text;
}
+ @Override
+ public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+ return Collections.EMPTY_SET;
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java
index 4f01fcd..8558cfb 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisModuleHelperConfigElement.java
@@ -12,6 +12,8 @@
package org.eclipse.linuxtools.tmf.core.analysis;
+import java.util.Collections;
+
import org.eclipse.core.runtime.ContributorFactoryOSGi;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -111,6 +113,16 @@ public class TmfAnalysisModuleHelperConfigElement implements IAnalysisModuleHelp
return applies;
}
+ @Override
+ public Iterable<Class<? extends ITmfTrace>> getValidTraceTypes() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override
+ public Iterable<TmfAnalysisRequirement> getAnalysisRequirements() {
+ return Collections.EMPTY_SET;
+ }
+
// ---------------------------------------
// Functionalities
// ---------------------------------------
@@ -147,5 +159,4 @@ public class TmfAnalysisModuleHelperConfigElement implements IAnalysisModuleHelp
return module;
}
-
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java
new file mode 100644
index 0000000..0809b51
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/analysis/TmfAnalysisRequirement.java
@@ -0,0 +1,233 @@
+/*******************************************************************************
+ * 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:
+ * Mathieu Rail - Initial API and implementation
+ * Guilliano Molaire - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.analysis;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+
+/**
+ * Class that contains all the values associated with a type needed by an
+ * analysis in order to execute. Each value is peered with a level that
+ * determines the importance of that specific value for the requirement.
+ *
+ * The type gives an indication about the kind of value the requirement
+ * contains. The value should depend on the type. For instance, a requirement
+ * type could be "event" and all the values that would be added in the
+ * requirement object could indicate the possible events handled by the
+ * analysis.
+ *
+ * For these values, a level will be assigned indicating how important the value
+ * is based on two possibilities: Mandatory or optional.
+ *
+ * Moreover, useful information that can not be leveled with a priority but are
+ * important for the proper execution of an analysis can be added.
+ *
+ * @author Guilliano Molaire
+ * @author Mathieu Rail
+ * @since 3.0
+ */
+public class TmfAnalysisRequirement {
+
+ private final String fType;
+ private final Map<String, ValuePriorityLevel> fValues = new HashMap<>();
+ private final Set<String> fInformation = new HashSet<>();
+
+ /**
+ * The possible level for each value. They must be listed in ascending order
+ * of priority.
+ */
+ public enum ValuePriorityLevel {
+ /** The value could be absent and the analysis would still work */
+ OPTIONAL,
+ /** The value must be present at runtime (for the analysis) */
+ MANDATORY
+ }
+
+ /**
+ * Constructor
+ *
+ * @param type
+ * The type of the requirement
+ */
+ public TmfAnalysisRequirement(String type) {
+ fType = type;
+ }
+
+ /**
+ * Constructor. Instantiate a requirement object with a list of values of
+ * the same level
+ *
+ * @param type
+ * The type of the requirement
+ * @param values
+ * All the values associated with that type
+ * @param level
+ * A level associated with all the values
+ */
+ public TmfAnalysisRequirement(String type, Iterable<String> values, ValuePriorityLevel level) {
+ fType = type;
+ addValues(values, level);
+ }
+
+ /**
+ * Merges the values of the specified requirement with those of this
+ * requirement. All new values will retain their priority value level. If a
+ * value was already inside the current requirement, the current priority
+ * level will be overridden if the new priority level is higher.
+ *
+ * @param subRequirement
+ * The requirement to be merged into the current one
+ * @param maxSubRequirementValueLevel
+ * The level associated with all the new values or currently
+ * lower priority ones
+ * @return True if the merge was successful
+ */
+ public Boolean merge(TmfAnalysisRequirement subRequirement, ValuePriorityLevel maxSubRequirementValueLevel) {
+ /* Two requirements can't be merged if their types are different */
+ if (!isSameType(subRequirement)) {
+ return false;
+ }
+
+ Set<String> values = subRequirement.getValues();
+ for (String value : values) {
+ /*
+ * Sub-requirement value levels are limited to
+ * maxSubRequirementValueLevel, so the level associated with the
+ * values in the merge is the minimum value between
+ * maxSubRequirementValueLevel and its true level.
+ */
+ int minLevel = Math.min(subRequirement.getValueLevel(value).ordinal(), maxSubRequirementValueLevel.ordinal());
+ ValuePriorityLevel subRequirementValueLevel = ValuePriorityLevel.values()[minLevel];
+
+ if (fValues.containsKey(value)) {
+ /*
+ * If a value is already in a requirement, we update the level
+ * by the highest value between the current level in the
+ * requirement and the level of the value in the
+ * sub-requirement.
+ */
+ ValuePriorityLevel requirementValueLevel = getValueLevel(value);
+
+ int newValueLevel = Math.max(requirementValueLevel.ordinal(), subRequirementValueLevel.ordinal());
+ ValuePriorityLevel highestLevel = ValuePriorityLevel.values()[newValueLevel];
+ addValue(value, highestLevel);
+ }
+ else {
+ addValue(value, subRequirementValueLevel);
+ }
+ }
+
+ /* Merge the information */
+ fInformation.addAll(subRequirement.getInformation());
+
+ return true;
+ }
+
+ /**
+ * Adds a list of value inside the requirement with the same level.
+ *
+ * @param values
+ * A list of value
+ * @param level
+ * The level associated with all the values
+ */
+ public void addValues(Iterable<String> values, ValuePriorityLevel level) {
+ for (String value : values) {
+ addValue(value, level);
+ }
+ }
+
+ /**
+ * Adds a value with his associated level into the requirement. If the value
+ * is already contained in the requirement the method modifies its existing
+ * value level.
+ *
+ * @param value
+ * The value
+ * @param level
+ * The level
+ */
+ public void addValue(String value, ValuePriorityLevel level) {
+ synchronized (fValues) {
+ fValues.put(value, level);
+ }
+ }
+
+ /**
+ * Adds an information about the requirement.
+ *
+ * @param information
+ * The information to be added
+ */
+ public void addInformation(String information) {
+ fInformation.add(information);
+ }
+
+ /**
+ * Determines if the analysis requirement has the same type of another
+ * requirement.
+ *
+ * @param requirement
+ * Requirement whose type is to be compared to this requirement's
+ * type.
+ * @return True if the two requirements have the same type; otherwise false
+ */
+ public Boolean isSameType(TmfAnalysisRequirement requirement) {
+ return fType.equals(requirement.getType());
+ }
+
+ /**
+ * Gets the requirement type. The type is read only.
+ *
+ * @return The type of this requirement
+ */
+ public String getType() {
+ return fType;
+ }
+
+ /**
+ * Gets all the values associated with the requirement.
+ *
+ * @return Set containing the values
+ */
+ public Set<String> getValues() {
+ synchronized (fValues) {
+ return fValues.keySet();
+ }
+ }
+
+ /**
+ * Gets information about the requirement.
+ *
+ * @return The set of all the information
+ */
+ public Set<String> getInformation() {
+ return fInformation;
+ }
+
+ /**
+ * Gets the level associated with a particular type
+ *
+ * @param value
+ * The value
+ * @return The level or null if the value does not exist
+ */
+ public ValuePriorityLevel getValueLevel(String value) {
+ synchronized (fValues) {
+ return fValues.get(value);
+ }
+ }
+}