import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jdt.annotation.NonNull;
import org.osgi.framework.BundleContext;
/**
* The path relative to the plugin's root directory
* @return The path corresponding to the relative path in parameter
*/
- public static IPath getAbsoluteFilePath(String relativePath) {
+ public static @NonNull IPath getAbsoluteFilePath(String relativePath) {
Activator plugin = Activator.getDefault();
if (plugin == null) {
/*
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.List;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection;
import org.eclipse.tracecompass.analysis.graph.core.tests.Activator;
import org.eclipse.tracecompass.analysis.graph.core.tests.stubs.TestGraphWorker;
import org.eclipse.tracecompass.analysis.graph.core.tests.stubs.module.GraphBuilderModuleStub;
-import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
* @return
*/
private TmfGraphBuilderModule getModule() {
- ITmfTrace trace = new TmfXmlTraceStub();
- IPath filePath = Activator.getAbsoluteFilePath(STUB_TRACE_FILE);
- IStatus status = trace.validate(null, filePath.toOSString());
- if (!status.isOK()) {
- fail(status.getException().getMessage());
- }
- try {
- trace.initTrace(null, filePath.toOSString(), TmfEvent.class);
- } catch (TmfTraceException e) {
- fail(e.getMessage());
- }
+ ITmfTrace trace = TmfXmlTraceStub.setupTrace(Activator.getAbsoluteFilePath(STUB_TRACE_FILE));
((TmfTrace) trace).traceOpened(new TmfTraceOpenedSignal(this, trace, null));
GraphBuilderModuleStub module = null;
for (GraphBuilderModuleStub mod : TmfTraceUtils.getAnalysisModulesOfClass(trace, GraphBuilderModuleStub.class)) {
package org.eclipse.tracecompass.tmf.core.tests;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.internal.tmf.core.TmfCoreTracer;
import org.osgi.framework.BundleContext;
super.stop(context);
}
+ /**
+ * Return a path to a file relative to this plugin's base directory
+ *
+ * @param relativePath
+ * The path relative to the plugin's root directory
+ * @return The path corresponding to the relative path in parameter
+ */
+ public static @NonNull IPath getAbsoluteFilePath(String relativePath) {
+ Plugin plugin = TmfCoreTestPlugin.getDefault();
+ if (plugin == null) {
+ /*
+ * Shouldn't happen but at least throw something to get the test to
+ * fail early
+ */
+ throw new IllegalStateException();
+ }
+ URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
+ try {
+ return new Path(FileLocator.toFileURL(location).getPath());
+ } catch (IOException e) {
+ throw new IllegalStateException();
+ }
+ }
+
}
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
-import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest;
import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
*/
public class XmlStubTraceTest {
- private static final Path VALID_FILE = new Path("testfiles/stub_xml_traces/valid/test.xml");
- private static final Path VALID_PATH = new Path("testfiles/stub_xml_traces/valid");
- private static final Path INVALID_PATH = new Path("testfiles/stub_xml_traces/invalid");
+ private static final String VALID_FILE = "testfiles/stub_xml_traces/valid/test.xml";
+ private static final String VALID_PATH = "testfiles/stub_xml_traces/valid";
+ private static final String INVALID_PATH = "testfiles/stub_xml_traces/invalid";
private static final String EVENT_A = "A";
private static final String EVENT_B = "B";
private static final String FIELD_A = "b";
private static final String FIELD_B = "f";
- private static IPath getAbsolutePath(Path relativePath) {
- Plugin plugin = TmfCoreTestPlugin.getDefault();
- if (plugin == null) {
- /*
- * Shouldn't happen but at least throw something to get the test to
- * fail early
- */
- throw new IllegalStateException();
- }
- URL location = FileLocator.find(plugin.getBundle(), relativePath, null);
- try {
- IPath path = new Path(FileLocator.toFileURL(location).getPath());
- return path;
- } catch (IOException e) {
- throw new IllegalStateException();
- }
- }
-
/**
* Test the
* {@link TmfXmlTraceStub#validate(org.eclipse.core.resources.IProject, String)}
@Test
public void testValidate() {
TmfXmlTraceStub trace = new TmfXmlTraceStub();
- File[] invalidFiles = getAbsolutePath(INVALID_PATH).toFile().listFiles();
+ File[] invalidFiles = TmfCoreTestPlugin.getAbsoluteFilePath(INVALID_PATH).toFile().listFiles();
assertTrue(invalidFiles.length > 0);
for (File f : invalidFiles) {
assertTrue(!trace.validate(null, f.getAbsolutePath()).isOK());
}
- File[] validFiles = getAbsolutePath(VALID_PATH).toFile().listFiles();
+ File[] validFiles = TmfCoreTestPlugin.getAbsoluteFilePath(VALID_PATH).toFile().listFiles();
assertTrue(validFiles.length > 0);
for (File f : validFiles) {
assertTrue(trace.validate(null, f.getAbsolutePath()).isOK());
*/
@Test
public void testDevelopmentTrace() {
- TmfXmlTraceStub trace = new TmfXmlTraceStub();
- IStatus status = trace.validate(null, getAbsolutePath(VALID_FILE).toOSString());
- if (!status.isOK()) {
- fail(status.getException().getMessage());
- }
-
- try {
- trace.initTrace(null, getAbsolutePath(VALID_FILE).toOSString(), TmfEvent.class);
- } catch (TmfTraceException e1) {
- fail(e1.getMessage());
- }
+ TmfXmlTraceStub trace = TmfXmlTraceStub.setupTrace(TmfCoreTestPlugin.getAbsoluteFilePath(VALID_FILE));
CustomEventRequest req = new CustomEventRequest(trace);
trace.sendRequest(req);
*/
@Test
public void testAspects() {
- TmfXmlTraceStub trace = new TmfXmlTraceStub();
- IStatus status = trace.validate(null, getAbsolutePath(VALID_FILE).toOSString());
- if (!status.isOK()) {
- fail(status.getException().getMessage());
- }
-
- try {
- trace.initTrace(null, getAbsolutePath(VALID_FILE).toOSString(), TmfEvent.class);
- } catch (TmfTraceException e1) {
- fail(e1.getMessage());
- }
+ TmfXmlTraceStub trace = TmfXmlTraceStub.setupTrace(TmfCoreTestPlugin.getAbsoluteFilePath(VALID_FILE));
ITmfEventAspect<?> cpuAspect = null;
ITmfEventAspect<?> testAspect = null;
package org.eclipse.tracecompass.tmf.tests.stubs.trace.xml;
import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.Nullable;
private Collection<ITmfEventAspect<?>> fAspects = TmfTrace.BASE_ASPECTS;
private final Collection<ITmfEventAspect<?>> fAdditionalAspects = new HashSet<>();
+ /**
+ * Validate and initialize a {@link TmfXmlTraceStub} object
+ *
+ * @param absolutePath
+ * The absolute file path of the trace file
+ * @return The trace
+ */
+ public static TmfXmlTraceStub setupTrace(IPath absolutePath) {
+ TmfXmlTraceStub trace = new TmfXmlTraceStub();
+ IStatus status = trace.validate(null, absolutePath.toOSString());
+ if (!status.isOK()) {
+ fail(status.getException().getMessage());
+ }
+ try {
+ trace.initTrace(null, absolutePath.toOSString(), TmfEvent.class);
+ } catch (TmfTraceException e) {
+ fail(e.getMessage());
+ }
+ return trace;
+ }
+
/**
* Constructor. Constructs the custom XML trace with the appropriate
* definition.