Change-Id: Ib7581d4d2b8cb2807882afc62ba0071e7d123f82
Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Reviewed-on: https://git.eclipse.org/r/81721
Reviewed-by: Hudson CI
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.ControlFlowView;
import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.controlflow.ControlFlowView;
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.ui.swtbot.tests.shared.SWTBotUtils;
import org.junit.Before;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.junit.Before;
assertEquals(0, allItems[i].getNodes().size());
}
assertEquals(0, allItems[i].getNodes().size());
}
- SWTBotTreeItem item = treeCfv.getTreeItem(TmfTraceManager.getInstance().getActiveTrace().getName());
+ ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(trace);
+ SWTBotTreeItem item = treeCfv.getTreeItem(trace.getName());
assertNotNull(item);
item = item.getNode("systemd");
assertNotNull(item);
assertNotNull(item);
item = item.getNode("systemd");
assertNotNull(item);
* @return The newly created context
* @since 2.0
*/
* @return The newly created context
* @since 2.0
*/
- default TmfTraceContext createTraceContext(@NonNull TmfTimeRange selection, @NonNull TmfTimeRange windowRange, @Nullable IFile editorFile, @Nullable ITmfFilter filter) {
+ default @NonNull TmfTraceContext createTraceContext(@NonNull TmfTimeRange selection, @NonNull TmfTimeRange windowRange, @Nullable IFile editorFile, @Nullable ITmfFilter filter) {
return new TmfTraceContext(selection, windowRange, editorFile, filter);
}
}
return new TmfTraceContext(selection, windowRange, editorFile, filter);
}
}
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
*
* @author Alexandre Montplaisir
*/
*
* @author Alexandre Montplaisir
*/
public final class TmfTraceManager {
// ------------------------------------------------------------------------
public final class TmfTraceManager {
// ------------------------------------------------------------------------
private final Map<ITmfTrace, TmfTraceContext> fTraces;
/** The currently-selected trace. Should always be part of the trace map */
private final Map<ITmfTrace, TmfTraceContext> fTraces;
/** The currently-selected trace. Should always be part of the trace map */
- private ITmfTrace fCurrentTrace = null;
+ private @Nullable ITmfTrace fCurrentTrace = null;
private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$
private static final String TEMP_DIR_NAME = ".temp"; //$NON-NLS-1$
}
/** Singleton instance */
}
/** Singleton instance */
- private static TmfTraceManager tm = null;
+ private static @Nullable TmfTraceManager tm = null;
/**
* Get an instance of the trace manager.
/**
* Get an instance of the trace manager.
* @return The trace manager
*/
public static synchronized TmfTraceManager getInstance() {
* @return The trace manager
*/
public static synchronized TmfTraceManager getInstance() {
- if (tm == null) {
- tm = new TmfTraceManager();
+ TmfTraceManager mgr = tm;
+ if (mgr == null) {
+ mgr = new TmfTraceManager();
+ tm = mgr;
}
// ------------------------------------------------------------------------
}
// ------------------------------------------------------------------------
/**
* Get the currently selected trace (normally, the focused editor).
*
/**
* Get the currently selected trace (normally, the focused editor).
*
- * @return The active trace
+ * @return The active trace, or <code>null</code> if there is no active
+ * trace
- public synchronized ITmfTrace getActiveTrace() {
+ public synchronized @Nullable ITmfTrace getActiveTrace() {
return fCurrentTrace;
}
/**
* Get the trace set of the currently active trace.
*
return fCurrentTrace;
}
/**
* Get the trace set of the currently active trace.
*
- * @return The active trace set
+ * @return The active trace set. Empty (but non-null) if there is no
+ * currently active trace.
* @see #getTraceSet(ITmfTrace)
*/
* @see #getTraceSet(ITmfTrace)
*/
- public synchronized @NonNull Collection<ITmfTrace> getActiveTraceSet() {
+ public synchronized Collection<ITmfTrace> getActiveTraceSet() {
final ITmfTrace trace = fCurrentTrace;
return getTraceSet(trace);
}
final ITmfTrace trace = fCurrentTrace;
return getTraceSet(trace);
}
* the trace
* @return the editor file or null if the trace is not opened
*/
* the trace
* @return the editor file or null if the trace is not opened
*/
- public synchronized IFile getTraceEditorFile(ITmfTrace trace) {
+ public synchronized @Nullable IFile getTraceEditorFile(ITmfTrace trace) {
TmfTraceContext ctx = fTraces.get(trace);
if (ctx != null) {
return ctx.getEditorFile();
TmfTraceContext ctx = fTraces.get(trace);
if (ctx != null) {
return ctx.getEditorFile();
* all the traces contained in this experiment.
*
* @param trace
* all the traces contained in this experiment.
*
* @param trace
- * The trace or experiment
+ * The trace or experiment. If it is null, an empty collection
+ * will be returned.
* @return The corresponding trace set.
*/
* @return The corresponding trace set.
*/
- public static @NonNull Collection<@NonNull ITmfTrace> getTraceSet(ITmfTrace trace) {
+ public static Collection<ITmfTrace> getTraceSet(@Nullable ITmfTrace trace) {
if (trace == null) {
return ImmutableSet.of();
}
if (trace == null) {
return ImmutableSet.of();
}
* this experiment, along with the experiment.
*
* @param trace
* this experiment, along with the experiment.
*
* @param trace
- * The trace or experiment
+ * The trace or experiment. If it is null, an empty collection
+ * will be returned.
* @return The corresponding trace set, including the experiment.
*/
* @return The corresponding trace set, including the experiment.
*/
- public static @NonNull Collection<ITmfTrace> getTraceSetWithExperiment(ITmfTrace trace) {
+ public static Collection<ITmfTrace> getTraceSetWithExperiment(@Nullable ITmfTrace trace) {
if (trace == null) {
return ImmutableSet.of();
}
if (trace == null) {
return ImmutableSet.of();
}
- * @param signal any signal
+ *
+ * @param signal
+ * any signal
* @since 2.0
*/
@TmfSignalHandler
* @since 2.0
*/
@TmfSignalHandler
- public synchronized void signalReceived(final @NonNull TmfTraceModelSignal signal) {
+ public synchronized void signalReceived(final TmfTraceModelSignal signal) {
fTraces.forEach((t, u) -> u.receive(signal));
}
fTraces.forEach((t, u) -> u.receive(signal));
}
package org.eclipse.tracecompass.tmf.ui.swtbot.tests.perf.views;
package org.eclipse.tracecompass.tmf.ui.swtbot.tests.perf.views;
+import static org.junit.Assert.assertNotNull;
+
import java.io.File;
import java.util.Collection;
import java.io.File;
import java.util.Collection;
// Set the time range to the full trace range
ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
// Set the time range to the full trace range
ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(activeTrace);
TmfTimeRange fullRange = new TmfTimeRange(activeTrace.getStartTime(), activeTrace.getEndTime());
TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, fullRange));
waitViewReady(part, selectionRange, fullRange.getEndTime());
TmfTimeRange fullRange = new TmfTimeRange(activeTrace.getStartTime(), activeTrace.getEndTime());
TmfSignalManager.dispatchSignal(new TmfWindowRangeUpdatedSignal(this, fullRange));
waitViewReady(part, selectionRange, fullRange.getEndTime());
package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
+import static org.junit.Assert.assertNotNull;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@Test
public void testRefresh() throws IOException {
ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
@Test
public void testRefresh() throws IOException {
ITmfTrace activeTrace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(activeTrace);
fBot.waitUntil(new NumberOfEventsCondition(activeTrace, INITIAL_NB_EVENTS));
fBot.waitUntil(new NumberOfEventsCondition(activeTrace, INITIAL_NB_EVENTS));
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
SWTBotUtils.createProject(PROJECT_NAME);
SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
WaitUtils.waitForJobs();
SWTBotUtils.createProject(PROJECT_NAME);
SWTBotUtils.openTrace(PROJECT_NAME, f.getAbsolutePath(), XMLSTUB_ID);
WaitUtils.waitForJobs();
- assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(TmfTraceManager.getInstance().getActiveTrace().getPath())).getAbsolutePath());
+ ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(trace);
+ assertEquals("Incorrect opened trace!", f.getAbsolutePath(), (new File(trace.getPath())).getAbsolutePath());
SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
projectExplorerBot.show();
SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
assertNotNull("Cannot find " + PROJECT_EXPLORER, projectExplorerBot);
projectExplorerBot.show();
fBot.waitUntil(Conditions.shellCloses(shell));
fBot = new SWTWorkbenchBot();
SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
fBot.waitUntil(Conditions.shellCloses(shell));
fBot = new SWTWorkbenchBot();
SWTBotUtils.openEditor(fBot, PROJECT_NAME, new Path(f.getName()));
- assertEquals("Test if import matches", f.getName(), TmfTraceManager.getInstance().getActiveTrace().getName());
- assertFalse("Test if import files don't match", f.getAbsolutePath().equals(TmfTraceManager.getInstance().getActiveTrace().getPath()));
+ trace = TmfTraceManager.getInstance().getActiveTrace();
+ assertNotNull(trace);
+ assertEquals("Test if import matches", f.getName(), trace.getName());
+ assertFalse("Test if import files don't match", f.getAbsolutePath().equals(trace.getPath()));
SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
WaitUtils.waitForJobs();
}
SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
WaitUtils.waitForJobs();
}
TmfTreeViewerEntry rootEntry = new TmfTreeViewerEntry("root"); //$NON-NLS-1$
for (final ITmfTrace trace : TmfTraceManager.getTraceSetWithExperiment(getTrace())) {
TmfTreeViewerEntry rootEntry = new TmfTreeViewerEntry("root"); //$NON-NLS-1$
for (final ITmfTrace trace : TmfTraceManager.getTraceSetWithExperiment(getTrace())) {
- if (trace != null) {
- rootEntry.addChild(createTraceEntry(trace));
- }
+ rootEntry.addChild(createTraceEntry(trace));