import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
-import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
assertEquals(expected, actual);
}
- /**
- * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
- */
- @Test
- public void testSupplementaryFileDir() {
- final ITmfTrace localTrace1 = trace1;
- final ITmfTrace localTrace2 = trace2;
- assertNotNull(localTrace1);
- assertNotNull(localTrace2);
- String name1 = localTrace1.getName();
- String name2 = localTrace2.getName();
- String basePath = TmfTraceManager.getTemporaryDirPath() + File.separator;
-
- String expected1 = basePath + name1 + File.separator;
- String expected2 = basePath + name2 + File.separator;
-
- assertEquals(expected1, TmfTraceManager.getSupplementaryFileDir(localTrace1));
- assertEquals(expected2, TmfTraceManager.getSupplementaryFileDir(localTrace2));
- }
-
// ------------------------------------------------------------------------
// Test a single trace
// ------------------------------------------------------------------------
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.ctf.core.tests.temp.tracemanager;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for the utility methods in {@link TmfTraceManager}.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class TmfTraceManagerUtilityTest {
+
+ private ITmfTrace fTrace;
+
+ /**
+ * Test initialization
+ */
+ @Before
+ public void setup() {
+ fTrace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.TRACE2);
+ fTrace.indexTrace(true);
+ }
+
+ /**
+ * Test clean-up
+ */
+ @AfterClass
+ public static void teardown() {
+ CtfTmfTestTraceUtils.dispose(CtfTestTrace.TRACE2);
+ }
+
+ /**
+ * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
+ */
+ @Test
+ public void testSupplementaryFileDir() {
+ final ITmfTrace trace = fTrace;
+ assertNotNull(trace);
+ String name1 = trace.getName();
+ String basePath = TmfTraceManager.getTemporaryDirPath() + File.separator;
+
+ String expected = basePath + name1 + File.separator;
+ assertEquals(expected, TmfTraceManager.getSupplementaryFileDir(trace));
+ }
+
+ /**
+ * Test the {@link TmfTraceManager#deleteSupplementaryFiles} method.
+ */
+ @Test
+ public void testDeleteSupplementaryFiles() {
+ ITmfTrace trace = fTrace;
+ assertNotNull(trace);
+
+ String suppFilesPath = TmfTraceManager.getSupplementaryFileDir(trace);
+ try {
+ /*
+ * Initializing/indexing the trace should have produced some
+ * supplementary files already.
+ */
+ assertFalse(isDirectoryEmpty(suppFilesPath));
+
+ TmfTraceManager.deleteSupplementaryFiles(trace);
+ assertTrue(isDirectoryEmpty(suppFilesPath));
+
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ private static boolean isDirectoryEmpty(String dirPath) throws IOException {
+ Path path = Paths.get(dirPath);
+ try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
+ return !stream.iterator().hasNext();
+ }
+ }
+}
import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
import java.io.File;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
}
}
+ /**
+ * Delete the supplementary files of a given trace.
+ *
+ * @param trace
+ * The trace for which the supplementary files are to be deleted
+ * @since 2.2
+ */
+ public static void deleteSupplementaryFiles(ITmfTrace trace) {
+ try {
+ FileUtils.cleanDirectory(new File(TmfTraceManager.getSupplementaryFileDir(trace)));
+ } catch (IOException e) {
+ Activator.logError("Error deleting supplementary files for trace " + trace.getName(), e); //$NON-NLS-1$
+ }
+ refreshSupplementaryFiles(trace);
+ }
+
// ------------------------------------------------------------------------
// Signal handlers
// ------------------------------------------------------------------------