package org.eclipse.linuxtools.ctf.core.tests;
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.linuxtools.internal.ctf.core.Activator;
import org.osgi.framework.BundleContext;
/**
*/
public class CtfCoreTestPlugin extends Plugin {
+ private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
super.stop(context);
}
+ /**
+ * Get the temporary directory path. If there is an instance of Eclipse
+ * running, the temporary directory will reside under the workspace.
+ *
+ * @return the temporary directory path suitable to be passed to the
+ * java.io.File constructor without a trailing separator
+ */
+ public static String getTemporaryDirPath() {
+ String property = System.getProperty("osgi.instance.area"); //$NON-NLS-1$
+ if (property != null) {
+ try {
+ File dir = new File(new URI(property));
+ dir = new File(dir.getAbsolutePath() + File.separator + TEMP_DIR_NAME);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ return dir.getAbsolutePath();
+ } catch (URISyntaxException e) {
+ Activator.logError(e.getLocalizedMessage(), e);
+ }
+ }
+ return System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
+ }
}
*/
public static void main(String[] args) {
// not using createTempFile as this is a directory
- String path = System.getProperty("java.io.tmpdir") + File.separator + TRACE_NAME;
+ String path = CtfCoreTestPlugin.getTemporaryDirPath() + File.separator + TRACE_NAME;
generateLttngKernelTrace(new File(path));
}
import java.util.List;
import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
+import org.eclipse.linuxtools.ctf.core.tests.CtfCoreTestPlugin;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
private static final String allDressedTSDL = metadataDecs + environmentMD + clockMD
+ ctfStart + ctfHeaders + ctfBody + enumMd + callsiteMD;
- static final String tempTraceDir = System.getProperty("java.io.tmpdir")
+ static final String tempTraceDir = CtfCoreTestPlugin.getTemporaryDirPath()
+ File.separator + "tempTrace";
private static final int DATA_SIZE = 4096;
package org.eclipse.linuxtools.tmf.core.trace;
import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
/** The currently-selected trace. Should always be part of the trace map */
private ITmfTrace fCurrentTrace = null;
+ private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$
+
// ------------------------------------------------------------------------
// Constructor
// ------------------------------------------------------------------------
return new TmfTimeRange(start, end);
}
+ /**
+ * Get the temporary directory path. If there is an instance of Eclipse
+ * running, the temporary directory will reside under the workspace.
+ *
+ * @return the temporary directory path suitable to be passed to the
+ * java.io.File constructor without a trailing separator
+ * @since 3.1
+ */
+ public static String getTemporaryDirPath() {
+ // Get the workspace path from the properties
+ String property = System.getProperty("osgi.instance.area"); //$NON-NLS-1$
+ if (property != null) {
+ try {
+ File dir = new File(new URI(property));
+ dir = new File(dir.getAbsolutePath() + File.separator + TEMP_DIR_NAME);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ return dir.getAbsolutePath();
+ } catch (URISyntaxException e) {
+ Activator.logError(e.getLocalizedMessage(), e);
+ }
+ }
+ return System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
+ }
+
/**
* Get a temporary directory based on a trace's name. We will create the
* directory if it doesn't exist, so that it's ready to be used.
*/
private static String getTemporaryDir(ITmfTrace trace) {
- String pathName = System.getProperty("java.io.tmpdir") + //$NON-NLS-1$
+ String pathName = getTemporaryDirPath() +
File.separator +
trace.getName() +
File.separator;
public void testSupplementaryFileDir() {
String name1 = trace1.getName();
String name2 = trace2.getName();
- String basePath = System.getProperty("java.io.tmpdir") + File.separator;
+ String basePath = TmfTraceManager.getTemporaryDirPath() + File.separator;
String expected1 = basePath + name1 + File.separator;
String expected2 = basePath + name2 + File.separator;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTraceDefinition;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
/**
*/
public class CustomTxtIndexTest extends AbstractCustomTraceIndexTest {
- private static final String TRACE_DIRECTORY = System.getProperty("java.io.tmpdir") + File.separator + "dummyTxtTrace";
+ private static final String TRACE_DIRECTORY = TmfTraceManager.getTemporaryDirPath() + File.separator + "dummyTxtTrace";
private static final String TRACE_PATH = TRACE_DIRECTORY + File.separator + "test.txt";
private static final String DEFINITION_PATH = "tracesets" + File.separator + "txt" + File.separator + "testTxtDefinition.xml";
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace;
import org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTraceDefinition;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
/**
*/
public class CustomXmlIndexTest extends AbstractCustomTraceIndexTest {
- private static final String TRACE_DIRECTORY = System.getProperty("java.io.tmpdir") + File.separator + "dummyXmlTrace";
+ private static final String TRACE_DIRECTORY = TmfTraceManager.getTemporaryDirPath() + File.separator + "dummyXmlTrace";
private static final String TRACE_PATH = TRACE_DIRECTORY + File.separator + "test.xml";
private static final String DEFINITION_PATH = "tracesets" + File.separator + "xml" + File.separator + "testDefinition.xml";