X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tmf%2Forg.eclipse.tracecompass.tmf.core.tests%2Fstubs%2Forg%2Feclipse%2Ftracecompass%2Ftmf%2Ftests%2Fstubs%2Ftrace%2Fxml%2FTmfXmlTraceStub.java;h=af595419c838e1d081581a434b89a8b072cea2d3;hb=b405ad64068a9ff24bf6e6947c3a7b477deb8a3b;hp=1477160a08dd9043ae6c7015262390950fca0ddf;hpb=c0d85d59aaa926c9b3eb6fa3ade2216cb433b881;p=deliverable%2Ftracecompass.git diff --git a/tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlTraceStub.java b/tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlTraceStub.java index 1477160a08..af595419c8 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlTraceStub.java +++ b/tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlTraceStub.java @@ -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; @@ -52,7 +61,7 @@ import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; 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; @@ -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. @@ -99,8 +109,30 @@ public class TmfXmlTraceStub extends TmfTrace { private final CustomXmlTraceDefinition fDefinition; private CustomXmlTrace fTrace; - private Collection fAspects = TmfTrace.BASE_ASPECTS; - private final Collection fAdditionalAspects = new HashSet<>(); + private Collection> fAspects = TmfTrace.BASE_ASPECTS; + private final Collection> fAdditionalAspects = new HashSet<>(); + private final Collection 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 type) throws TmfTraceException { super.initTrace(resource, path, type); ITmfContext ctx; @@ -315,23 +348,23 @@ public class TmfXmlTraceStub extends TmfTrace { * 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 builder = new ImmutableList.Builder<>(); + ImmutableList.Builder> 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 @@ -349,14 +382,14 @@ 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(); } @Override - public Iterable getEventAspects() { + public Iterable> getEventAspects() { return fAspects; } @@ -371,8 +404,30 @@ public class TmfXmlTraceStub extends TmfTrace { * @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 modules = super.getAnalysisModules(); + return checkNotNull(Iterables.concat(modules, fAdditionalModules)); + } + + @Override + public @Nullable IAnalysisModule getAnalysisModule(@Nullable String analysisId) { + Iterable<@NonNull IAnalysisModule> modules = getAnalysisModules(); + Optional opt = StreamSupport.stream(modules.spliterator(), false).filter(analysis -> analysis.getId().equals(analysisId)).findFirst(); + return opt.isPresent() ? opt.get() : null; + } }