+ /**
+ * Clear the traces folder
+ *
+ * @param bot
+ * a given workbench bot
+ * @param projectName
+ * the name of the project (needs to exist)
+ */
+ public static void clearTracesFolder(SWTWorkbenchBot bot, String projectName) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
+ TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
+ try {
+ for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
+ traceElement.delete(null);
+ }
+
+ final IFolder resource = tracesFolder.getResource();
+ resource.accept(new IResourceVisitor() {
+ @Override
+ public boolean visit(IResource visitedResource) throws CoreException {
+ if (visitedResource != resource) {
+ visitedResource.delete(true, null);
+ }
+ return true;
+ }
+ }, IResource.DEPTH_ONE, 0);
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+
+ bot.waitUntil(new DefaultCondition() {
+ private int fTraceNb = 0;
+
+ @Override
+ public boolean test() throws Exception {
+ List<TmfTraceElement> traces = tracesFolder.getTraces();
+ fTraceNb = traces.size();
+ return fTraceNb == 0;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Traces Folder not empty (" + fTraceNb + ")";
+ }
+ });
+ }
+
+ /**
+ * Clear the trace folder (using the UI)
+ *
+ * @param bot
+ * a given workbench bot
+ * @param projectName
+ * the name of the project (needs to exist)
+ */
+ public static void clearTracesFolderUI(SWTWorkbenchBot bot, String projectName) {
+ SWTBotTreeItem tracesFolder = selectTracesFolder(bot, projectName);
+ tracesFolder.contextMenu().menu("Clear").click();
+ String CONFIRM_CLEAR_DIALOG_TITLE = "Confirm Clear";
+ bot.waitUntil(Conditions.shellIsActive(CONFIRM_CLEAR_DIALOG_TITLE));
+
+ SWTBotShell shell = bot.shell(CONFIRM_CLEAR_DIALOG_TITLE);
+ shell.bot().button("Yes").click();
+ bot.waitUntil(Conditions.shellCloses(shell));
+ bot.waitWhile(ConditionHelpers.treeItemHasChildren(tracesFolder));
+ }
+
+ /**
+ * Clear the experiment folder
+ *
+ * @param bot
+ * a given workbench bot
+ * @param projectName
+ * the name of the project (needs to exist)
+ */
+ public static void clearExperimentFolder(SWTWorkbenchBot bot, String projectName) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, false);
+ TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
+ expFolder.getExperiments().forEach(experiment -> {
+ IResource resource = experiment.getResource();
+ try {
+ // Close the experiment if open
+ experiment.closeEditors();
+
+ IPath path = resource.getLocation();
+ if (path != null) {
+ // Delete supplementary files
+ experiment.deleteSupplementaryFolder();
+ }
+ // Finally, delete the experiment
+ resource.delete(true, null);
+ } catch (CoreException e) {
+ fail(e.getMessage());
+ }
+ });
+
+ bot.waitUntil(new DefaultCondition() {
+ private int fExperimentNb = 0;
+
+ @Override
+ public boolean test() throws Exception {
+ List<TmfExperimentElement> experiments = expFolder.getExperiments();
+ fExperimentNb = experiments.size();
+ return fExperimentNb == 0;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Experiment Folder not empty (" + fExperimentNb + ")";
+ }
+ });
+ }
+