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 java.net.URL;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Optional;
+import java.util.stream.StreamSupport;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
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.DefaultLocation;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
+import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
import org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect;
import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
import org.xml.sax.SAXException;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
/**
* An XML development trace using a custom XML trace definition and schema.
private final CustomXmlTraceDefinition fDefinition;
private CustomXmlTrace fTrace;
- private Collection<ITmfEventAspect> fAspects = TmfTrace.BASE_ASPECTS;
- private final Collection<ITmfEventAspect> fAdditionalAspects = new HashSet<>();
+ private Collection<ITmfEventAspect<?>> fAspects = TmfTrace.BASE_ASPECTS;
+ private final Collection<ITmfEventAspect<?>> fAdditionalAspects = new HashSet<>();
+ private final Collection<IAnalysisModule> fAdditionalModules = 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
}
@Override
+ @NonNullByDefault({DefaultLocation.TYPE_ARGUMENT})
public void initTrace(@Nullable IResource resource, @Nullable String path, @Nullable Class<? extends ITmfEvent> type) throws TmfTraceException {
super.initTrace(resource, path, type);
ITmfContext ctx;
* original is in second and we need to convert it. We should do that at
* the source when it is supported
*/
- ITmfTimestamp timestamp = new TmfNanoTimestamp(event.getTimestamp().getValue() / SECONDS_TO_NS);
+ ITmfTimestamp timestamp = TmfTimestamp.fromNanos(event.getTimestamp().getValue() / SECONDS_TO_NS);
TmfEvent newEvent = new TmfEvent(this, ITmfContext.UNKNOWN_RANK, timestamp, eventType, eventFields);
updateAttributes(savedContext, event);
return newEvent;
}
private void generateAspects(ITmfEventField[] fieldsArray) {
- ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>();
+ ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
/* Initialize the first default trace aspects */
- builder.add(ITmfEventAspect.BaseAspects.TIMESTAMP);
- builder.add(ITmfEventAspect.BaseAspects.EVENT_TYPE);
+ builder.add(TmfBaseAspects.getTimestampAspect());
+ builder.add(TmfBaseAspects.getEventTypeAspect());
/* Add custom aspects in between */
for (ITmfEventField field : fieldsArray) {
String name = field.getName();
- final ITmfEventAspect aspect = new TmfContentFieldAspect(name, name);
+ final ITmfEventAspect<?> aspect = new TmfContentFieldAspect(name, name);
if (name.equals(ASPECT_CPU)) {
builder.add(new TmfCpuAspect() {
@Override
}
/* Add the big content aspect */
- builder.add(ITmfEventAspect.BaseAspects.CONTENTS);
+ builder.add(TmfBaseAspects.getContentsAspect());
/* Add the additional aspects */
builder.addAll(fAdditionalAspects);
fAspects = builder.build();
}
@Override
- public Iterable<ITmfEventAspect> getEventAspects() {
+ public Iterable<ITmfEventAspect<?>> getEventAspects() {
return fAspects;
}
* @param aspect
* The aspect to have
*/
- public void addEventAspect(ITmfEventAspect aspect) {
+ public void addEventAspect(ITmfEventAspect<?> aspect) {
fAdditionalAspects.add(aspect);
}
+ /**
+ * Add an additional new module
+ *
+ * @param module
+ * The new module
+ */
+ public void addAnalysisModule(IAnalysisModule module) {
+ fAdditionalModules.add(module);
+ }
+
+ @Override
+ public Iterable<@NonNull IAnalysisModule> getAnalysisModules() {
+ @NonNull Iterable<IAnalysisModule> modules = super.getAnalysisModules();
+ return checkNotNull(Iterables.concat(modules, fAdditionalModules));
+ }
+
+ @Override
+ public @Nullable IAnalysisModule getAnalysisModule(@Nullable String analysisId) {
+ Iterable<@NonNull IAnalysisModule> modules = getAnalysisModules();
+ Optional<IAnalysisModule> opt = StreamSupport.stream(modules.spliterator(), false).filter(analysis -> analysis.getId().equals(analysisId)).findFirst();
+ return opt.isPresent() ? opt.get() : null;
+ }
}