timing.core: Add local statistics to the latency statistics
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / stubs / org / eclipse / tracecompass / tmf / tests / stubs / trace / xml / TmfXmlTraceStub.java
index b2bb7a3fbd82e24ef230c51d7b1e2b5464f521a3..af595419c838e1d081581a434b89a8b072cea2d3 100644 (file)
@@ -14,6 +14,7 @@
 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;
@@ -21,6 +22,8 @@ import java.io.InputStream;
 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;
@@ -31,11 +34,16 @@ import javax.xml.validation.Validator;
 
 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;
@@ -43,6 +51,7 @@ import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
 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;
@@ -62,6 +71,7 @@ import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
 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.
@@ -101,6 +111,28 @@ public class TmfXmlTraceStub extends TmfTrace {
 
     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
@@ -131,6 +163,7 @@ public class TmfXmlTraceStub extends TmfTrace {
     }
 
     @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;
@@ -325,8 +358,8 @@ public class TmfXmlTraceStub extends TmfTrace {
         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) {
@@ -349,7 +382,7 @@ public class TmfXmlTraceStub extends TmfTrace {
         }
 
         /* Add the big content aspect */
-        builder.add(ITmfEventAspect.BaseAspects.CONTENTS);
+        builder.add(TmfBaseAspects.getContentsAspect());
         /* Add the additional aspects */
         builder.addAll(fAdditionalAspects);
         fAspects = builder.build();
@@ -375,4 +408,26 @@ public class TmfXmlTraceStub extends TmfTrace {
         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;
+    }
 }
This page took 0.025616 seconds and 5 git commands to generate.