1212
1313import java .io .File ;
1414import java .io .FileReader ;
15+ import java .io .FileWriter ;
1516import java .io .IOException ;
1617import java .io .Reader ;
18+ import java .io .Writer ;
1719import java .nio .charset .Charset ;
1820import java .util .HashMap ;
1921import java .util .Map ;
2022import java .util .Objects ;
2123import java .util .UUID ;
2224
25+ import org .eclipse .core .runtime .IPath ;
2326import org .eclipse .jdt .annotation .Nullable ;
2427import org .eclipse .tracecompass .internal .tmf .core .Activator ;
2528import 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