scripting: Allow scripts to define more than one data provider
Previously, the data provider name was the analysis name, which meant
only one data provider per analysis was possible. We add a dpName
parameter to all the data provider creation methods to specify a name
for the data provider, which allows analyses to define as many data
providers as they want.
[Added] Possibility to specify the data provider name in creation methods, to allow analyses to have more than one data provider
Change-Id: I330af099782709ab633e212c11ec9987727d5183
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/158613
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
diff --git a/scripting/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/data/provider/ScriptedDataProviderTest.java b/scripting/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/data/provider/ScriptedDataProviderTest.java
index b28afb3..09e2584 100644
--- a/scripting/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/data/provider/ScriptedDataProviderTest.java
+++ b/scripting/org.eclipse.tracecompass.incubator.scripting.core.tests/src/org/eclipse/tracecompass/incubator/scripting/core/tests/data/provider/ScriptedDataProviderTest.java
@@ -120,7 +120,7 @@
DataProviderScriptingModule scriptingModule = new DataProviderScriptingModule();
// Create a data provider that returns a flat hierarchy of objects
- ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> dp = scriptingModule.createTimeGraphProvider(fixture, ImmutableMap.of(DataProviderScriptingModule.ENTRY_PATH, "*/*"));
+ ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> dp = scriptingModule.createTimeGraphProvider(fixture, ImmutableMap.of(DataProviderScriptingModule.ENTRY_PATH, "*/*"), "test");
assertNotNull(dp);
/*
diff --git a/scripting/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/data/provider/DataProviderScriptingModule.java b/scripting/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/data/provider/DataProviderScriptingModule.java
index 75af64b..7199abd 100644
--- a/scripting/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/data/provider/DataProviderScriptingModule.java
+++ b/scripting/org.eclipse.tracecompass.incubator.scripting.core/src/org/eclipse/tracecompass/incubator/scripting/core/data/provider/DataProviderScriptingModule.java
@@ -17,6 +17,7 @@
import java.util.Map;
import java.util.function.Function;
+import org.eclipse.ease.modules.ScriptParameter;
import org.eclipse.ease.modules.WrapToScript;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.incubator.internal.scripting.core.data.provider.ScriptedEntryDataModel;
@@ -129,10 +130,14 @@
* The analysis for which to create a time graph provider
* @param data
* The time graph provider data
+ * @param dpName
+ * The unique name of this data provider. If not set, the
+ * analysis name will be used. Output of this data provider will
+ * use this name as the title
* @return The time graph data provider
*/
@WrapToScript
- public @Nullable ITimeGraphDataProvider<TimeGraphEntryModel> createTimeGraphProvider(IAnalysisModule analysis, Map<String, Object> data) {
+ public @Nullable ITimeGraphDataProvider<TimeGraphEntryModel> createTimeGraphProvider(IAnalysisModule analysis, Map<String, Object> data, @ScriptParameter(defaultValue = "") String dpName) {
ITmfTrace trace = null;
if (analysis instanceof TmfAbstractAnalysisModule) {
TmfAbstractAnalysisModule newAnalysis = (TmfAbstractAnalysisModule) analysis;
@@ -148,7 +153,8 @@
if (stateSystems.isEmpty() || trace == null) {
return null;
}
- return createTimeGraphProvider(trace, stateSystems, String.valueOf(analysis.getName()), data);
+ String dataProviderName = dpName.isEmpty() ? String.valueOf(analysis.getName()) : dpName;
+ return createTimeGraphProvider(trace, stateSystems, dataProviderName, data);
}
/**
@@ -184,15 +190,20 @@
* The analysis for which to create a time graph provider
* @param data
* The time graph provider data
+ * @param dpName
+ * The unique name of this data provider. If not set, the
+ * analysis name will be used. Output of this data provider will
+ * use this name as the title
* @return The time graph data provider
*/
@WrapToScript
- public @Nullable ITimeGraphDataProvider<TimeGraphEntryModel> createTimeGraphProvider(ScriptedAnalysis analysis, Map<String, Object> data) {
+ public @Nullable ITimeGraphDataProvider<TimeGraphEntryModel> createTimeGraphProvider(ScriptedAnalysis analysis, Map<String, Object> data, @ScriptParameter(defaultValue = "") String dpName) {
ITmfStateSystemBuilder stateSystem = analysis.getStateSystem(true);
if (stateSystem == null) {
return null;
}
- return createTimeGraphProvider(analysis.getTrace(), Collections.singletonList(stateSystem), analysis.getName(), data);
+ String dataProviderName = dpName.isEmpty() ? String.valueOf(analysis.getName()) : dpName;
+ return createTimeGraphProvider(analysis.getTrace(), Collections.singletonList(stateSystem), dataProviderName, data);
}
private static @Nullable ITimeGraphDataProvider<TimeGraphEntryModel> createTimeGraphProvider(ITmfTrace trace,
@@ -254,10 +265,14 @@
* The analysis for which to create a time graph provider
* @param data
* The XY chart data
+ * @param dpName
+ * The unique name of this data provider. If not set, the
+ * analysis name will be used. Output of this data provider will
+ * use this name as the title
* @return The XY data provider
*/
@WrapToScript
- public @Nullable ITmfTreeXYDataProvider<ITmfTreeDataModel> createXYProvider(IAnalysisModule analysis, Map<String, Object> data) {
+ public @Nullable ITmfTreeXYDataProvider<ITmfTreeDataModel> createXYProvider(IAnalysisModule analysis, Map<String, Object> data, @ScriptParameter(defaultValue = "") String dpName) {
ITmfTrace trace = null;
if (analysis instanceof TmfAbstractAnalysisModule) {
TmfAbstractAnalysisModule newAnalysis = (TmfAbstractAnalysisModule) analysis;
@@ -273,7 +288,8 @@
if (stateSystems.isEmpty() || trace == null) {
return null;
}
- return createXYProvider(trace, stateSystems, String.valueOf(analysis.getName()), data);
+ String dataProviderName = dpName.isEmpty() ? String.valueOf(analysis.getName()) : dpName;
+ return createXYProvider(trace, stateSystems, dataProviderName, data);
}
/**
@@ -307,16 +323,21 @@
* The scripted analysis for which to create a time graph
* provider
* @param data
- * The XY chart data
+ * The XY chart options
+ * @param dpName
+ * The unique name of this data provider. If not set, the
+ * analysis name will be used. Output of this data provider will
+ * use this name as the title
* @return The XY data provider
*/
@WrapToScript
- public @Nullable ITmfTreeXYDataProvider<ITmfTreeDataModel> createXYProvider(ScriptedAnalysis analysis, Map<String, Object> data) {
+ public @Nullable ITmfTreeXYDataProvider<ITmfTreeDataModel> createXYProvider(ScriptedAnalysis analysis, Map<String, Object> data, @ScriptParameter(defaultValue = "") String dpName) {
ITmfStateSystemBuilder stateSystem = analysis.getStateSystem(true);
if (stateSystem == null) {
return null;
}
- return createXYProvider(analysis.getTrace(), Collections.singletonList(stateSystem), String.valueOf(analysis.getName()), data);
+ String dataProviderName = dpName.isEmpty() ? String.valueOf(analysis.getName()) : dpName;
+ return createXYProvider(analysis.getTrace(), Collections.singletonList(stateSystem), dataProviderName, data);
}
private static @Nullable ITmfTreeXYDataProvider<ITmfTreeDataModel> createXYProvider(ITmfTrace trace,
@@ -406,7 +427,7 @@
* Create a data provider from scripted functions. The script itself is
* responsible for generating the entries, optionally row data and arrows.
* For a simple state system, the
- * {@link #createTimeGraphProvider(ScriptedAnalysis, Map)} may be used
+ * {@link #createTimeGraphProvider(ScriptedAnalysis, Map, String)} may be used
* instead
*
* @param analysis