Fix some null warnings
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core.tests / shared / org / eclipse / tracecompass / lttng2 / lttng / kernel / core / tests / shared / vm / VmTraces.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.lttng2.lttng.kernel.core.tests.shared.vm;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.net.URL;
18
19 import org.eclipse.core.runtime.FileLocator;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.jdt.annotation.NonNull;
24 import org.eclipse.jdt.annotation.Nullable;
25 import org.eclipse.tracecompass.lttng2.kernel.core.tests.Activator;
26 import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
27 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
28 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
29 import org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub;
30
31 /**
32 * List the available virtual machine host and guest traces
33 *
34 * @author Geneviève Bastien
35 */
36 public enum VmTraces {
37
38 /** Host from simple QEMU/KVM experiment */
39 HOST_ONE_QEMUKVM("vm/OneQemuKvm/host.xml"),
40 /** Guest from simple QEMU/KVM experiment */
41 GUEST_ONE_QEMUKVM("vm/OneQemuKvm/guest.xml");
42
43 private static final @NonNull String filePath = "testfiles";
44
45 private final IPath fPath;
46
47 VmTraces(String path) {
48 IPath relativePath = new Path(filePath + File.separator + path);
49 Activator plugin = Activator.getDefault();
50 if (plugin == null) {
51 /*
52 * Shouldn't happen but at least throw something to get the test to
53 * fail early
54 */
55 throw new IllegalStateException();
56 }
57 URL location = FileLocator.find(plugin.getBundle(), relativePath, null);
58 try {
59 fPath = new Path(FileLocator.toFileURL(location).getPath());
60 } catch (IOException e) {
61 throw new IllegalStateException();
62 }
63 }
64
65 /**
66 * Return a TmfXmlTraceStub object of this test trace. It will be already
67 * initTrace()'ed.
68 *
69 * Make sure you call {@link #exists()} before calling this!
70 *
71 * @return A TmfXmlTraceStub reference to this trace
72 */
73 public @Nullable ITmfTrace getTrace() {
74 ITmfTrace trace = new TmfXmlTraceStub();
75 IStatus status = trace.validate(null, fPath.toOSString());
76 if (!status.isOK()) {
77 return null;
78 }
79 try {
80 trace.initTrace(null, fPath.toOSString(), TmfEvent.class);
81 } catch (TmfTraceException e) {
82 return null;
83 }
84 return trace;
85 }
86
87 /**
88 * Check if the trace actually exists on disk or not.
89 *
90 * @return If the trace is present
91 */
92 public boolean exists() {
93 return fPath.toFile().exists();
94 }
95 }
This page took 0.035519 seconds and 5 git commands to generate.