Skip to content

Commit

Permalink
server: Create bookmarks file for experiments
Browse files Browse the repository at this point in the history
The bookmarks file can be used to store and retrieve markers associated
with an experiment using platform APIs.

It can later be obtained for an opened experiment with:
TmfTraceManager.getInstance().getTraceEditorFile(experiment)

Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
  • Loading branch information
PatrickTasse committed Nov 14, 2024
1 parent 8a218dd commit 81b6a38
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -103,6 +104,8 @@ public class ExperimentManagerService {
private static final String EXPERIMENTS_FOLDER = "Experiments"; //$NON-NLS-1$
private static final String TRACES_FOLDER = "Traces"; //$NON-NLS-1$
private static final String SUFFIX = "_exp"; //$NON-NLS-1$
private static final String BOOKMARKS_HIDDEN_FILE = ".bookmarks"; //$NON-NLS-1$
private static final String EXPERIMENT_EDITOR_INPUT_TYPE = "editorInputType.experiment"; //$NON-NLS-1$

/**
* Getter for the list of experiments from the trace manager
Expand Down Expand Up @@ -374,7 +377,7 @@ public Response postExperiment(@RequestBody(content = {
experiment.getNext(ctx);
ctx.dispose();

TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(ExperimentManagerService.class, experiment, null));
TmfSignalManager.dispatchSignal(new TmfTraceOpenedSignal(ExperimentManagerService.class, experiment, createBookmarksFile(resource)));

EXPERIMENTS.put(expUUID, experiment);
TRACE_INSTANCES.put(expUUID, uuidToTraceInstances);
Expand Down Expand Up @@ -495,6 +498,24 @@ private static void createSupplementaryFolder(IResource experimentResource) {
}
}

private static IFile createBookmarksFile(IResource resource) {
IFile file = ((IFolder) resource).getFile(resource.getName() + '_');
try {
if (!file.exists()) {
final IFile bookmarksFile = ((IFolder) resource.getParent()).getFile(BOOKMARKS_HIDDEN_FILE);
if (!bookmarksFile.exists()) {
final InputStream source = new ByteArrayInputStream(new byte[0]);
bookmarksFile.create(source, IResource.FORCE | IResource.HIDDEN, new NullProgressMonitor());
}
file.createLink(bookmarksFile.getLocation(), IResource.REPLACE | IResource.HIDDEN, new NullProgressMonitor());
}
file.setPersistentProperty(TmfCommonConstants.TRACETYPE, EXPERIMENT_EDITOR_INPUT_TYPE);
} catch (CoreException e) {
Activator.getInstance().logWarning("Error creating bookmarks file", e); //$NON-NLS-1$
}
return file;
}

private static void createFolder(IFolder folder) throws CoreException {
if (!folder.exists()) {
if (folder.getParent() instanceof IFolder) {
Expand Down

0 comments on commit 81b6a38

Please sign in to comment.