Skip to content

Commit 70d5719

Browse files
committed
tmf: extend api for configuration 5
Reviews round #1
1 parent 6f08bea commit 70d5719

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/AbstractTmfDataProviderConfigurator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**********************************************************************
2+
* Copyright (c) 2025 Ericsson
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License 2.0 which
6+
* accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
**********************************************************************/
111
package org.eclipse.tracecompass.tmf.core.config;
212

313
import java.io.File;
@@ -14,6 +24,7 @@
1424
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
1525
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
1626
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
27+
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
1728
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
1829
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
1930
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
@@ -28,8 +39,18 @@
2839
/**
2940
* This class meant to be extended by data provider factories that want to be
3041
* able to handle configurations.
42+
*
43+
* @since 9.6
3144
*/
3245
public abstract class AbstractTmfDataProviderConfigurator implements ITmfDataProviderConfigurator{
46+
47+
/**
48+
* Constructor
49+
*/
50+
protected AbstractTmfDataProviderConfigurator() {
51+
TmfSignalManager.register(this);
52+
}
53+
3354
/**
3455
* The json file extension
3556
* @since 9.5
@@ -239,4 +260,11 @@ protected static void writeConfiguration(ITmfConfiguration configuration, IPath
239260
@SuppressWarnings("null")
240261
protected @NonNull abstract IPath getConfigurationRootFolder(@NonNull ITmfTrace trace);
241262

263+
/**
264+
* Disposes the signal manager
265+
*/
266+
protected void dispose() {
267+
TmfSignalManager.dispose();
268+
}
269+
242270
}

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/config/TmfConfiguration.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212

1313
import java.io.File;
1414
import java.io.FileReader;
15+
import java.io.FileWriter;
1516
import java.io.IOException;
1617
import java.io.Reader;
18+
import java.io.Writer;
1719
import java.nio.charset.Charset;
1820
import java.util.HashMap;
1921
import java.util.Map;
2022
import java.util.Objects;
2123
import java.util.UUID;
2224

25+
import org.eclipse.core.runtime.IPath;
2326
import org.eclipse.jdt.annotation.Nullable;
2427
import org.eclipse.tracecompass.internal.tmf.core.Activator;
2528
import org.eclipse.tracecompass.tmf.core.exceptions.TmfConfigurationException;
@@ -43,6 +46,15 @@ public class TmfConfiguration implements ITmfConfiguration {
4346
*/
4447
public static final String UNKNOWN = "---unknown---"; //$NON-NLS-1$
4548

49+
/**
50+
* The json file extension
51+
*
52+
* @since 9.5
53+
* @deprecated use {@link AbstractTmfDataProviderConfigurator#JSON_EXTENSION} instead
54+
*/
55+
@Deprecated
56+
public static final String JSON_EXTENSION = "json"; //$NON-NLS-1$
57+
4658
@Expose
4759
@SerializedName(value = "id")
4860
@Nullable
@@ -307,4 +319,35 @@ public static ITmfConfiguration fromJsonFile(File jsonFile) throws TmfConfigurat
307319
}
308320
}
309321

322+
/**
323+
* Serialize {@link ITmfConfiguration} to JSON file with name configId.json
324+
*
325+
* @param configuration
326+
* the configuration to serialize
327+
* @param rootPath
328+
* the root path to store the configuration
329+
* @throws TmfConfigurationException
330+
* if an error occurs
331+
* @since 9.5
332+
* @deprecated use
333+
* {@link AbstractTmfDataProviderConfigurator#writeConfiguration(ITmfConfiguration, IPath)}
334+
* instead
335+
*/
336+
@Deprecated
337+
public static void writeConfiguration(ITmfConfiguration configuration, IPath rootPath) throws TmfConfigurationException {
338+
IPath supplPath = rootPath;
339+
File folder = supplPath.toFile();
340+
if (!folder.exists()) {
341+
folder.mkdir();
342+
}
343+
supplPath = supplPath.addTrailingSeparator().append(configuration.getId()).addFileExtension(JSON_EXTENSION);
344+
File file = supplPath.toFile();
345+
try (Writer writer = new FileWriter(file)) {
346+
writer.append(new Gson().toJson(configuration));
347+
} catch (IOException | JsonParseException e) {
348+
Activator.logError(e.getMessage(), e);
349+
throw new TmfConfigurationException("Error writing configuration.", e); //$NON-NLS-1$
350+
}
351+
}
352+
310353
}

0 commit comments

Comments
 (0)