From bcf083a63e17cf0d1b4d1c5803435178ef732f43 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 27 Feb 2025 17:07:30 +0100 Subject: [PATCH 1/9] tmf: extend api for configuration --- .../tmf/core/config/TmfConfiguration.java | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java index b7b9e8232d..83d22baf67 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java @@ -17,15 +17,24 @@ import java.io.Reader; import java.io.Writer; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.internal.tmf.core.Activator; +import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; +import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; +import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; +import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; import com.google.gson.Gson; import com.google.gson.JsonParseException; @@ -343,4 +352,109 @@ public static void writeConfiguration(ITmfConfiguration configuration, IPath roo throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$ } } + + @SuppressWarnings("null") + private static @NonNull IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder) { + String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); + IPath supplPath = new Path(supplFolder); + supplPath = supplPath.addTrailingSeparator().append(subFolder); + return supplPath; + } + + /** + * Reads the configurations for a given trace + * + * @param trace + * the trace to read configurations from + * @return list of configurations if any + * @throws TmfConfigurationException + * if an error occurs + */ + public static @NonNull List readConfigurations(@NonNull ITmfTrace trace, String subfolder) throws TmfConfigurationException { + IPath rootPath = getConfigurationRootFolder(trace, subfolder); + File folder = rootPath.toFile(); + List list = new ArrayList<>(); + if (folder.exists()) { + File[] listOfFiles = folder.listFiles(); + for (File file : listOfFiles) { + IPath path = new Path(file.getName()); + if (path.getFileExtension().equals(TmfConfiguration.JSON_EXTENSION)) { + ITmfConfiguration config = TmfConfiguration.fromJsonFile(file); + list.add(config); + } + } + } + return list; + } + + /** + * Removes configuration from trace: + * - delete configuration file + * - remove analysis module from trace object + * + * @param config + * the configuration to remove + * @param trace + * the + * @throws TmfConfigurationException if an error occurs + */ + public static void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { + IPath traceConfig = getConfigurationRootFolder(trace, config.getSourceTypeId()); + traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(TmfConfiguration.JSON_EXTENSION); + File configFile = traceConfig.toFile(); + if ((!configFile.exists()) || !configFile.delete()) { + throw new TmfConfigurationException("Configuration file can't be deleted from trace: configId=" + config.getId()); //$NON-NLS-1$ + } + + // Remove and clear persistent data + try { + IAnalysisModule module = trace.removeAnalysisModule(baseAnalysisId + config.getId()); + if (module != null) { + module.dispose(); + module.clearPersistentData(); + } + } catch (TmfTraceException e) { + throw new TmfConfigurationException("Error removing analysis module from trace: analysis ID=" + baseAnalysisId + config.getId(), e); //$NON-NLS-1$ + } + } + + /** + * Create the InAndOutAnalysisModule for a given configuration and trace + * + * @param config + * the input {@link ITmfConfiguration} + * @param trace + * the trace to apply it to + * @param writeConfig + * write the config (do only once) + * @return InAndOutAnalysisModule + * @throws TmfConfigurationException + * if an error occurs + */ + public static void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException { + /* + * Apply configuration to each trace (no need to check trace type here) + */ + module.setConfiguration(config); + if (writeConfig) { + IPath traceConfigPath = TmfConfiguration.getConfigurationRootFolder(trace, config.getSourceTypeId()); + TmfConfiguration.writeConfiguration(config, traceConfigPath); + } + try { + if (module.setTrace(trace)) { + IAnalysisModule oldModule = trace.addAnalysisModule(module); + if (oldModule != null) { + oldModule.dispose(); + oldModule.clearPersistentData(); + } + } else { + module.dispose(); + throw new TmfConfigurationException("InAndOut analysis module can't be created"); //$NON-NLS-1$ + } + } catch (TmfAnalysisException | TmfTraceException e) { + module.dispose(); + throw new TmfConfigurationException("Exception when setting trace", e); //$NON-NLS-1$ + } + } + } From 384fa9234aab9533480da647d55c48ff7a1bcbfe Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Fri, 28 Feb 2025 13:53:27 +0100 Subject: [PATCH 2/9] tmf: extend api for configuration 2 --- .../AbstractTmfDataProviderConfigurator.java | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java new file mode 100644 index 0000000000..35aaa408de --- /dev/null +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -0,0 +1,150 @@ +package org.eclipse.tracecompass.tmf.core.config; + +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; +import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; +import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; +import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; +import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; +import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; +import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + +/** + * + */ +public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{ + + private static final Table fTmfConfigurationTable = HashBasedTable.create(); + + @Override + public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException { + + if (configuration.getName().equals(TmfConfiguration.UNKNOWN)) { + throw new TmfConfigurationException("Missing configuration name of InAndOut analysis"); //$NON-NLS-1$ + } + + if (configuration.getSourceTypeId().equals(TmfConfiguration.UNKNOWN)) { + throw new TmfConfigurationException("Missing configuration type for InAndOut analysis"); //$NON-NLS-1$ + } + + String description = configuration.getDescription(); + if (configuration.getDescription().equals(TmfConfiguration.UNKNOWN)) { + description = "InAndOut Analysis defined by configuration " + configuration.getName(); //$NON-NLS-1$ + } + + TmfConfiguration.Builder builder = new TmfConfiguration.Builder(); + builder.setId(configuration.getId()) + .setSourceTypeId(configuration.getSourceTypeId()) + .setName(configuration.getName()) + .setDescription(description) + .setParameters(configuration.getParameters()) + .build(); + + ITmfConfiguration config = builder.build(); + + applyConfiguration(trace, config, true); + if (fTmfConfigurationTable.contains(config.getId(), trace)) { + throw new TmfConfigurationException("Configuration already existis with label: " + config.getName()); //$NON-NLS-1$ + } + fTmfConfigurationTable.put(config.getId(), trace, config); + return getDescriptorFromConfig(config); + } + + /** + * @param config + * @return A data provider descriptor based on the configuration parameter + */ + protected abstract IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration config); + + /** + * This is the method that handles what happens when a configuration is applied + * @param trace + * @param config + * @param writeConfig + */ + protected abstract void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig); + + // efrooo: the below move to open source + @Override + public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescriptor descriptor) throws TmfConfigurationException { + ITmfConfiguration creationConfiguration = descriptor.getConfiguration(); + if (creationConfiguration == null) { + throw new TmfConfigurationException("Data provider was not created by a configuration"); //$NON-NLS-1$ + } + + String configId = creationConfiguration.getId(); + ITmfConfiguration config = fTmfConfigurationTable.get(configId, trace); + if (config == null) { + return; + } + config = fTmfConfigurationTable.remove(configId, trace); + removeConfiguration(trace, config); + } + + /** + * This is the method that handles what happens when a configuration is removed (e.g. remove analysis, dp etc) + * @param trace + * @param config + */ + protected abstract void removeConfiguration(@NonNull ITmfTrace trace, @NonNull ITmfConfiguration config); + + // efroroo: to open source + /** + * Signal handler for opened trace signal. Will populate trace + * configurations + * + * @param signal + * the signal to handle + */ + @TmfSignalHandler + public void traceOpened(TmfTraceOpenedSignal signal, String subfolder) { + ITmfTrace trace = signal.getTrace(); + if (trace == null) { + return; + } + try { + if (trace instanceof TmfExperiment) { + for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { + // Read configurations from sub-trace + List configs = TmfConfiguration.readConfigurations(tr, subfolder); + readAndApplyConfiguration(trace, configs); + } + } else { + // Read configurations trace + List configs = TmfConfiguration.readConfigurations(trace, subfolder); + readAndApplyConfiguration(trace, configs); + } + } catch (TmfConfigurationException e) { + // FIXME: use proper logging + // Activator.logError("Error applying configurations for trace " + trace.getName(), e); //$NON-NLS-1$ + } + } + + /** + * Handles trace closed signal + * + * @param signal + * the close signal to handle + */ + @TmfSignalHandler + public void traceClosed(TmfTraceClosedSignal signal) { + ITmfTrace trace = signal.getTrace(); + fTmfConfigurationTable.column(trace).clear(); + } + + private void readAndApplyConfiguration(ITmfTrace trace, List configs) throws TmfConfigurationException { + for (ITmfConfiguration config : configs) { + if (!fTmfConfigurationTable.contains(config.getId(), trace)) { + fTmfConfigurationTable.put(config.getId(), trace, config); + applyConfiguration(trace, config, false); + } + } + } + +} From 7b47e78210ca45eb4d5acaa3132043bca3ac5311 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Wed, 5 Mar 2025 13:41:27 +0100 Subject: [PATCH 3/9] tmf: extend api for configuration 3 --- .../AbstractTmfDataProviderConfigurator.java | 90 ++++++++++- .../tmf/core/config/TmfConfiguration.java | 150 ------------------ 2 files changed, 88 insertions(+), 152 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index 35aaa408de..cf8b54a165 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -1,8 +1,16 @@ package org.eclipse.tracecompass.tmf.core.config; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; import java.util.List; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; @@ -14,14 +22,28 @@ import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; +import com.google.gson.Gson; +import com.google.gson.JsonParseException; /** * */ public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{ + /** + * The json file extension + * @since 9.5 + */ + public static final String JSON_EXTENSION = "json"; //$NON-NLS-1$ private static final Table fTmfConfigurationTable = HashBasedTable.create(); + /** + * @return a table mapping configuration id and trace (exp) to its configuration + */ + protected Table getConfigurationTable(){ + return fTmfConfigurationTable; + } + @Override public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException { @@ -112,12 +134,12 @@ public void traceOpened(TmfTraceOpenedSignal signal, String subfolder) { if (trace instanceof TmfExperiment) { for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { // Read configurations from sub-trace - List configs = TmfConfiguration.readConfigurations(tr, subfolder); + List configs = readConfigurations(tr, subfolder); readAndApplyConfiguration(trace, configs); } } else { // Read configurations trace - List configs = TmfConfiguration.readConfigurations(trace, subfolder); + List configs = readConfigurations(trace, subfolder); readAndApplyConfiguration(trace, configs); } } catch (TmfConfigurationException e) { @@ -147,4 +169,68 @@ private void readAndApplyConfiguration(ITmfTrace trace, List } } + /** + * Reads the configurations for a given trace + * + * @param trace + * the trace to read configurations from + * @return list of configurations if any + * @throws TmfConfigurationException + * if an error occurs + */ + private @NonNull List readConfigurations(@NonNull ITmfTrace trace, String subfolder) throws TmfConfigurationException { + IPath rootPath = getConfigurationRootFolder(trace, subfolder); + File folder = rootPath.toFile(); + List list = new ArrayList<>(); + if (folder.exists()) { + File[] listOfFiles = folder.listFiles(); + for (File file : listOfFiles) { + IPath path = new Path(file.getName()); + if (path.getFileExtension().equals(JSON_EXTENSION)) { + ITmfConfiguration config = TmfConfiguration.fromJsonFile(file); + list.add(config); + } + } + } + return list; + } + + /** + * Serialize {@link ITmfConfiguration} to JSON file with name configId.json + * + * @param configuration + * the configuration to serialize + * @param rootPath + * the root path to store the configuration + * @throws TmfConfigurationException + * if an error occurs + * @since 9.5 + */ + protected static void writeConfiguration(ITmfConfiguration configuration, IPath rootPath) throws TmfConfigurationException { + IPath supplPath = rootPath; + File folder = supplPath.toFile(); + if (!folder.exists()) { + folder.mkdir(); + } + supplPath = supplPath.addTrailingSeparator().append(configuration.getId()).addFileExtension(JSON_EXTENSION); + File file = supplPath.toFile(); + try (Writer writer = new FileWriter(file)) { + writer.append(new Gson().toJson(configuration)); + } catch (IOException | JsonParseException e) { + Activator.logError(e.getMessage(), e); + throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$ + } + } + +// @SuppressWarnings("null") +// protected static @NonNull IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder) { +// String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); +// IPath supplPath = new Path(supplFolder); +// supplPath = supplPath.addTrailingSeparator().append(subFolder); +// return supplPath; +// } + + @SuppressWarnings("null") + protected @NonNull abstract IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder); + } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java index 83d22baf67..addb956928 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java @@ -12,30 +12,17 @@ import java.io.File; import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.Reader; -import java.io.Writer; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.UUID; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.internal.tmf.core.Activator; -import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; -import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; -import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager; - import com.google.gson.Gson; import com.google.gson.JsonParseException; import com.google.gson.annotations.Expose; @@ -56,12 +43,6 @@ public class TmfConfiguration implements ITmfConfiguration { */ public static final String UNKNOWN = "---unknown---"; //$NON-NLS-1$ - /** - * The json file extension - * @since 9.5 - */ - public static final String JSON_EXTENSION = "json"; //$NON-NLS-1$ - @Expose @SerializedName(value = "id") @Nullable @@ -326,135 +307,4 @@ public static ITmfConfiguration fromJsonFile(File jsonFile) throws TmfConfigurat } } - /** - * Serialize {@link ITmfConfiguration} to JSON file with name configId.json - * - * @param configuration - * the configuration to serialize - * @param rootPath - * the root path to store the configuration - * @throws TmfConfigurationException - * if an error occurs - * @since 9.5 - */ - public static void writeConfiguration(ITmfConfiguration configuration, IPath rootPath) throws TmfConfigurationException { - IPath supplPath = rootPath; - File folder = supplPath.toFile(); - if (!folder.exists()) { - folder.mkdir(); - } - supplPath = supplPath.addTrailingSeparator().append(configuration.getId()).addFileExtension(JSON_EXTENSION); - File file = supplPath.toFile(); - try (Writer writer = new FileWriter(file)) { - writer.append(new Gson().toJson(configuration)); - } catch (IOException | JsonParseException e) { - Activator.logError(e.getMessage(), e); - throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$ - } - } - - @SuppressWarnings("null") - private static @NonNull IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder) { - String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); - IPath supplPath = new Path(supplFolder); - supplPath = supplPath.addTrailingSeparator().append(subFolder); - return supplPath; - } - - /** - * Reads the configurations for a given trace - * - * @param trace - * the trace to read configurations from - * @return list of configurations if any - * @throws TmfConfigurationException - * if an error occurs - */ - public static @NonNull List readConfigurations(@NonNull ITmfTrace trace, String subfolder) throws TmfConfigurationException { - IPath rootPath = getConfigurationRootFolder(trace, subfolder); - File folder = rootPath.toFile(); - List list = new ArrayList<>(); - if (folder.exists()) { - File[] listOfFiles = folder.listFiles(); - for (File file : listOfFiles) { - IPath path = new Path(file.getName()); - if (path.getFileExtension().equals(TmfConfiguration.JSON_EXTENSION)) { - ITmfConfiguration config = TmfConfiguration.fromJsonFile(file); - list.add(config); - } - } - } - return list; - } - - /** - * Removes configuration from trace: - * - delete configuration file - * - remove analysis module from trace object - * - * @param config - * the configuration to remove - * @param trace - * the - * @throws TmfConfigurationException if an error occurs - */ - public static void remove(ITmfConfiguration config, @NonNull ITmfTrace trace, String baseAnalysisId) throws TmfConfigurationException { - IPath traceConfig = getConfigurationRootFolder(trace, config.getSourceTypeId()); - traceConfig = traceConfig.append(File.separator).append(config.getId()).addFileExtension(TmfConfiguration.JSON_EXTENSION); - File configFile = traceConfig.toFile(); - if ((!configFile.exists()) || !configFile.delete()) { - throw new TmfConfigurationException("Configuration file can't be deleted from trace: configId=" + config.getId()); //$NON-NLS-1$ - } - - // Remove and clear persistent data - try { - IAnalysisModule module = trace.removeAnalysisModule(baseAnalysisId + config.getId()); - if (module != null) { - module.dispose(); - module.clearPersistentData(); - } - } catch (TmfTraceException e) { - throw new TmfConfigurationException("Error removing analysis module from trace: analysis ID=" + baseAnalysisId + config.getId(), e); //$NON-NLS-1$ - } - } - - /** - * Create the InAndOutAnalysisModule for a given configuration and trace - * - * @param config - * the input {@link ITmfConfiguration} - * @param trace - * the trace to apply it to - * @param writeConfig - * write the config (do only once) - * @return InAndOutAnalysisModule - * @throws TmfConfigurationException - * if an error occurs - */ - public static void create(@NonNull ITmfConfiguration config, @NonNull ITmfTrace trace, boolean writeConfig, IAnalysisModule module) throws TmfConfigurationException { - /* - * Apply configuration to each trace (no need to check trace type here) - */ - module.setConfiguration(config); - if (writeConfig) { - IPath traceConfigPath = TmfConfiguration.getConfigurationRootFolder(trace, config.getSourceTypeId()); - TmfConfiguration.writeConfiguration(config, traceConfigPath); - } - try { - if (module.setTrace(trace)) { - IAnalysisModule oldModule = trace.addAnalysisModule(module); - if (oldModule != null) { - oldModule.dispose(); - oldModule.clearPersistentData(); - } - } else { - module.dispose(); - throw new TmfConfigurationException("InAndOut analysis module can't be created"); //$NON-NLS-1$ - } - } catch (TmfAnalysisException | TmfTraceException e) { - module.dispose(); - throw new TmfConfigurationException("Exception when setting trace", e); //$NON-NLS-1$ - } - } - } From e218b9e5389855eb507535095db9562511769eb3 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 6 Mar 2025 13:43:24 +0100 Subject: [PATCH 4/9] tmf: extend api for configuration 4 --- .../AbstractTmfDataProviderConfigurator.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index cf8b54a165..7014217d49 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -92,7 +92,6 @@ protected Table getConfigurationTable(){ */ protected abstract void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig); - // efrooo: the below move to open source @Override public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescriptor descriptor) throws TmfConfigurationException { ITmfConfiguration creationConfiguration = descriptor.getConfiguration(); @@ -116,7 +115,6 @@ public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescripto */ protected abstract void removeConfiguration(@NonNull ITmfTrace trace, @NonNull ITmfConfiguration config); - // efroroo: to open source /** * Signal handler for opened trace signal. Will populate trace * configurations @@ -125,7 +123,7 @@ public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescripto * the signal to handle */ @TmfSignalHandler - public void traceOpened(TmfTraceOpenedSignal signal, String subfolder) { + public void traceOpened(TmfTraceOpenedSignal signal) { ITmfTrace trace = signal.getTrace(); if (trace == null) { return; @@ -134,12 +132,12 @@ public void traceOpened(TmfTraceOpenedSignal signal, String subfolder) { if (trace instanceof TmfExperiment) { for (ITmfTrace tr : TmfTraceManager.getTraceSet(trace)) { // Read configurations from sub-trace - List configs = readConfigurations(tr, subfolder); + List configs = readConfigurations(tr); readAndApplyConfiguration(trace, configs); } } else { // Read configurations trace - List configs = readConfigurations(trace, subfolder); + List configs = readConfigurations(trace); readAndApplyConfiguration(trace, configs); } } catch (TmfConfigurationException e) { @@ -178,8 +176,8 @@ private void readAndApplyConfiguration(ITmfTrace trace, List * @throws TmfConfigurationException * if an error occurs */ - private @NonNull List readConfigurations(@NonNull ITmfTrace trace, String subfolder) throws TmfConfigurationException { - IPath rootPath = getConfigurationRootFolder(trace, subfolder); + private @NonNull List readConfigurations(@NonNull ITmfTrace trace) throws TmfConfigurationException { + IPath rootPath = getConfigurationRootFolder(trace); File folder = rootPath.toFile(); List list = new ArrayList<>(); if (folder.exists()) { @@ -222,15 +220,7 @@ protected static void writeConfiguration(ITmfConfiguration configuration, IPath } } -// @SuppressWarnings("null") -// protected static @NonNull IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder) { -// String supplFolder = TmfTraceManager.getSupplementaryFileDir(trace); -// IPath supplPath = new Path(supplFolder); -// supplPath = supplPath.addTrailingSeparator().append(subFolder); -// return supplPath; -// } - @SuppressWarnings("null") - protected @NonNull abstract IPath getConfigurationRootFolder(@NonNull ITmfTrace trace, String subFolder); + protected @NonNull abstract IPath getConfigurationRootFolder(@NonNull ITmfTrace trace); } From 3455a21a06f779f9a9f7d4e78a73ec2b90e8eb91 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 6 Mar 2025 21:02:21 +0100 Subject: [PATCH 5/9] tmf: extend api for configuration 4 --- .../tmf/core/config/AbstractTmfDataProviderConfigurator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index 7014217d49..2c4b12270e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -35,7 +35,7 @@ public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataPro */ public static final String JSON_EXTENSION = "json"; //$NON-NLS-1$ - private static final Table fTmfConfigurationTable = HashBasedTable.create(); + private Table fTmfConfigurationTable = HashBasedTable.create(); /** * @return a table mapping configuration id and trace (exp) to its configuration From 6f08bea016e69e65ee73e3ae333cb53d32b01b7f Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Wed, 12 Mar 2025 11:48:34 +0100 Subject: [PATCH 6/9] tmf: extend api for configuration 5 --- .../AbstractTmfDataProviderConfigurator.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index 2c4b12270e..52d7a924cc 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -26,7 +26,8 @@ import com.google.gson.JsonParseException; /** - * + * This class meant to be extended by data provider factories that want to be + * able to handle configurations. */ public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{ /** @@ -48,16 +49,16 @@ protected Table getConfigurationTable(){ public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException { if (configuration.getName().equals(TmfConfiguration.UNKNOWN)) { - throw new TmfConfigurationException("Missing configuration name of InAndOut analysis"); //$NON-NLS-1$ + throw new TmfConfigurationException("Missing configuration name"); //$NON-NLS-1$ } if (configuration.getSourceTypeId().equals(TmfConfiguration.UNKNOWN)) { - throw new TmfConfigurationException("Missing configuration type for InAndOut analysis"); //$NON-NLS-1$ + throw new TmfConfigurationException("Missing configuration type"); //$NON-NLS-1$ } String description = configuration.getDescription(); if (configuration.getDescription().equals(TmfConfiguration.UNKNOWN)) { - description = "InAndOut Analysis defined by configuration " + configuration.getName(); //$NON-NLS-1$ + description = "Data provider defined by configuration " + configuration.getName(); //$NON-NLS-1$ } TmfConfiguration.Builder builder = new TmfConfiguration.Builder(); @@ -80,15 +81,22 @@ protected Table getConfigurationTable(){ /** * @param config + * a configuration * @return A data provider descriptor based on the configuration parameter */ protected abstract IDataProviderDescriptor getDescriptorFromConfig(ITmfConfiguration config); /** - * This is the method that handles what happens when a configuration is applied + * This is the method that handles what happens when a configuration is + * applied + * * @param trace + * trace to which the configuration should be applied * @param config + * the configuration to be applied * @param writeConfig + * true if the configuration should be written to disk, false + * otherwise */ protected abstract void applyConfiguration(ITmfTrace trace, ITmfConfiguration config, boolean writeConfig); @@ -109,9 +117,13 @@ public void removeDataProviderDescriptor(ITmfTrace trace, IDataProviderDescripto } /** - * This is the method that handles what happens when a configuration is removed (e.g. remove analysis, dp etc) + * This is the method that handles what happens when a configuration is + * removed (e.g. remove analysis, dp etc) + * * @param trace + * trace to which the configuration should be applied * @param config + * the configuration to be applied */ protected abstract void removeConfiguration(@NonNull ITmfTrace trace, @NonNull ITmfConfiguration config); @@ -141,8 +153,7 @@ public void traceOpened(TmfTraceOpenedSignal signal) { readAndApplyConfiguration(trace, configs); } } catch (TmfConfigurationException e) { - // FIXME: use proper logging - // Activator.logError("Error applying configurations for trace " + trace.getName(), e); //$NON-NLS-1$ + Activator.logError("Error applying configurations for trace " + trace.getName(), e); //$NON-NLS-1$ } } @@ -220,6 +231,11 @@ protected static void writeConfiguration(ITmfConfiguration configuration, IPath } } + /** + * @param trace + * the trace to which the configuration should be applied to + * @return the path where the configuration should be stored + */ @SuppressWarnings("null") protected @NonNull abstract IPath getConfigurationRootFolder(@NonNull ITmfTrace trace); From 70d5719603da337b717beeaca6dcc1920ac306a3 Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 3 Apr 2025 14:34:59 +0200 Subject: [PATCH 7/9] tmf: extend api for configuration 5 Reviews round #1 --- .../AbstractTmfDataProviderConfigurator.java | 28 ++++++++++++ .../tmf/core/config/TmfConfiguration.java | 43 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index 52d7a924cc..edbdb26703 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -1,3 +1,13 @@ +/********************************************************************** + * Copyright (c) 2025 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ package org.eclipse.tracecompass.tmf.core.config; import java.io.File; @@ -14,6 +24,7 @@ import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; +import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal; import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; @@ -28,8 +39,18 @@ /** * This class meant to be extended by data provider factories that want to be * able to handle configurations. + * + * @since 9.6 */ public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{ + + /** + * Constructor + */ + protected AbstractTmfDataProviderConfigurator() { + TmfSignalManager.register(this); + } + /** * The json file extension * @since 9.5 @@ -239,4 +260,11 @@ protected static void writeConfiguration(ITmfConfiguration configuration, IPath @SuppressWarnings("null") protected @NonNull abstract IPath getConfigurationRootFolder(@NonNull ITmfTrace trace); + /** + * Disposes the signal manager + */ + protected void dispose() { + TmfSignalManager.dispose(); + } + } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java index addb956928..337c28c68c 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java @@ -12,14 +12,17 @@ import java.io.File; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.Reader; +import java.io.Writer; import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.UUID; +import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException; @@ -43,6 +46,15 @@ public class TmfConfiguration implements ITmfConfiguration { */ public static final String UNKNOWN = "---unknown---"; //$NON-NLS-1$ + /** + * The json file extension + * + * @since 9.5 + * @deprecated use {@link AbstractTmfDataProviderConfigurator#JSON_EXTENSION} instead + */ + @Deprecated + public static final String JSON_EXTENSION = "json"; //$NON-NLS-1$ + @Expose @SerializedName(value = "id") @Nullable @@ -307,4 +319,35 @@ public static ITmfConfiguration fromJsonFile(File jsonFile) throws TmfConfigurat } } + /** + * Serialize {@link ITmfConfiguration} to JSON file with name configId.json + * + * @param configuration + * the configuration to serialize + * @param rootPath + * the root path to store the configuration + * @throws TmfConfigurationException + * if an error occurs + * @since 9.5 + * @deprecated use + * {@link AbstractTmfDataProviderConfigurator#writeConfiguration(ITmfConfiguration, IPath)} + * instead + */ + @Deprecated + public static void writeConfiguration(ITmfConfiguration configuration, IPath rootPath) throws TmfConfigurationException { + IPath supplPath = rootPath; + File folder = supplPath.toFile(); + if (!folder.exists()) { + folder.mkdir(); + } + supplPath = supplPath.addTrailingSeparator().append(configuration.getId()).addFileExtension(JSON_EXTENSION); + File file = supplPath.toFile(); + try (Writer writer = new FileWriter(file)) { + writer.append(new Gson().toJson(configuration)); + } catch (IOException | JsonParseException e) { + Activator.logError(e.getMessage(), e); + throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$ + } + } + } From eeb672c649230a6f1856db7d375847c4ade506ca Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 3 Apr 2025 15:48:32 +0200 Subject: [PATCH 8/9] tmf: extend api for configuration 5 Review round #1 - siw --- .../AbstractTmfDataProviderConfigurator.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index edbdb26703..3d82bd3afb 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -66,17 +66,17 @@ protected Table getConfigurationTable(){ return fTmfConfigurationTable; } - @Override - public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException { - - if (configuration.getName().equals(TmfConfiguration.UNKNOWN)) { - throw new TmfConfigurationException("Missing configuration name"); //$NON-NLS-1$ - } - - if (configuration.getSourceTypeId().equals(TmfConfiguration.UNKNOWN)) { - throw new TmfConfigurationException("Missing configuration type"); //$NON-NLS-1$ - } - + /** + * Create instances implementing {@link ITmfConfiguration}. Override this + * method if the data provider configurator needs another configuration + * instead of the default {@link TmfConfiguration} + * + * @param configuration + * a object implementing implementing {@link ITmfConfiguration}. + * @return the instance of the class implementing {@link ITmfConfiguration}. + * Default is {@link TmfConfiguration}. + */ + protected ITmfConfiguration createConfiguration(ITmfConfiguration configuration) { String description = configuration.getDescription(); if (configuration.getDescription().equals(TmfConfiguration.UNKNOWN)) { description = "Data provider defined by configuration " + configuration.getName(); //$NON-NLS-1$ @@ -89,8 +89,21 @@ protected Table getConfigurationTable(){ .setDescription(description) .setParameters(configuration.getParameters()) .build(); + return builder.build(); + } + + @Override + public @NonNull IDataProviderDescriptor createDataProviderDescriptors(ITmfTrace trace, ITmfConfiguration configuration) throws TmfConfigurationException { + + if (configuration.getName().equals(TmfConfiguration.UNKNOWN)) { + throw new TmfConfigurationException("Missing configuration name"); //$NON-NLS-1$ + } + + if (configuration.getSourceTypeId().equals(TmfConfiguration.UNKNOWN)) { + throw new TmfConfigurationException("Missing configuration type"); //$NON-NLS-1$ + } - ITmfConfiguration config = builder.build(); + ITmfConfiguration config = createConfiguration(configuration); applyConfiguration(trace, config, true); if (fTmfConfigurationTable.contains(config.getId(), trace)) { @@ -168,11 +181,10 @@ public void traceOpened(TmfTraceOpenedSignal signal) { List configs = readConfigurations(tr); readAndApplyConfiguration(trace, configs); } - } else { - // Read configurations trace - List configs = readConfigurations(trace); - readAndApplyConfiguration(trace, configs); } + // Read configurations from trace or top level experiment + List configs = readConfigurations(trace); + readAndApplyConfiguration(trace, configs); } catch (TmfConfigurationException e) { Activator.logError("Error applying configurations for trace " + trace.getName(), e); //$NON-NLS-1$ } From c11317c6e1eefcc5db990175662d06f1cb89b36a Mon Sep 17 00:00:00 2001 From: Francesco Robino Date: Thu, 10 Apr 2025 10:06:06 +0200 Subject: [PATCH 9/9] tmf: extend api for configuration 5 Review round #1 - bernd --- .../core/config/AbstractTmfDataProviderConfigurator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java index 3d82bd3afb..a235909072 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java @@ -60,9 +60,11 @@ protected AbstractTmfDataProviderConfigurator() { private Table fTmfConfigurationTable = HashBasedTable.create(); /** + * Return the configuration table + * * @return a table mapping configuration id and trace (exp) to its configuration */ - protected Table getConfigurationTable(){ + public Table getConfigurationTable(){ return fTmfConfigurationTable; } @@ -114,6 +116,8 @@ protected ITmfConfiguration createConfiguration(ITmfConfiguration configuration) } /** + * Return a data provider descriptor based on the configuration parameter + * * @param config * a configuration * @return A data provider descriptor based on the configuration parameter @@ -265,6 +269,8 @@ protected static void writeConfiguration(ITmfConfiguration configuration, IPath } /** + * Return the path where the configuration for a trace is stored + * * @param trace * the trace to which the configuration should be applied to * @return the path where the configuration should be stored