Skip to content

Commit

Permalink
tmf: move implementation to instantiate ITmfEvent to common utility
Browse files Browse the repository at this point in the history
and call it from TmfTraceElement class

[Added] instantiate ITmfEvent API to TmfTraceType utility class

Change-Id: Ifdce097e1fa2ea28d138c8b4053e0cb43ce51895
Signed-off-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/202660
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
  • Loading branch information
bhufmann committed Jun 22, 2023
1 parent f05616f commit a0e1e12
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 47 deletions.
2 changes: 1 addition & 1 deletion tmf/org.eclipse.tracecompass.tmf.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 9.0.0.qualifier
Bundle-Version: 9.1.0.qualifier
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.tracecompass.tmf.core;singleton:=true
Bundle-Activator: org.eclipse.tracecompass.internal.tmf.core.Activator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.internal.tmf.core.project.model.Messages;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
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;
Expand Down Expand Up @@ -701,11 +704,45 @@ public static List<TraceTypeHelper> selectExperimentType(List<ITmfTrace> traces,
* if trace cannot be instantiated
* @since 9.0
*/
public static TmfExperiment instantiateExperiment(String typeID) throws CoreException {
public static @Nullable TmfExperiment instantiateExperiment(@NonNull String typeID) throws CoreException {
IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(typeID);
if (ce == null) {
return null;
}
return (TmfExperiment) ce.createExecutableExtension(TmfTraceType.EXPERIMENT_TYPE_ATTR);
}

/**
* Instantiate {@link ITmfEvent} from trace type ID.
*
* @param traceTypeId
* the trace type Id
* @return an instance of {@link ITmfEvent} or null
*
* @since 9.1
*/
public static @Nullable ITmfEvent instantiateEvent(@NonNull String traceTypeId) throws CoreException {
if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) {
for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName);
if (traceTypeId.equals(id)) {
return new CustomTxtEvent(def);
}
}
}
if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) {
for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName);
if (traceTypeId.equals(id)) {
return new CustomXmlEvent(def);
}
}
}
IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(traceTypeId);
if (ce == null) {
return null;
}
ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
return event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.io.ResourceUtil;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
import org.eclipse.tracecompass.tmf.core.project.model.ITmfPropertiesProvider;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
Expand Down Expand Up @@ -150,36 +146,18 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF

// The mapping of available trace type IDs to their corresponding
// configuration element
private static final Map<String, IConfigurationElement> TRACE_TYPE_ATTRIBUTES = new HashMap<>();
private static final Map<String, IConfigurationElement> TRACE_TYPE_UI_ATTRIBUTES = new HashMap<>();
private static final Map<String, IConfigurationElement> TRACE_CATEGORIES = new HashMap<>();

/**
* Initialize statically at startup by getting extensions from the platform
* extension registry.
*/
public static void init() {
/* Read the tmf.core "tracetype" extension point */
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceType.TMF_TRACE_TYPE_ID);
for (IConfigurationElement ce : config) {
switch (ce.getName()) {
case TmfTraceType.TYPE_ELEM:
String traceTypeId = ce.getAttribute(TmfTraceType.ID_ATTR);
TRACE_TYPE_ATTRIBUTES.put(traceTypeId, ce);
break;
case TmfTraceType.CATEGORY_ELEM:
String categoryId = ce.getAttribute(TmfTraceType.ID_ATTR);
TRACE_CATEGORIES.put(categoryId, ce);
break;
default:
}
}

/*
* Read the corresponding tmf.ui "tracetypeui" extension point for this
* trace type, if it exists.
*/
config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TmfTraceTypeUIUtils.TMF_TRACE_TYPE_UI_ID);
for (IConfigurationElement ce : config) {
String elemName = ce.getName();
if (TmfTraceTypeUIUtils.TYPE_ELEM.equals(elemName)) {
Expand Down Expand Up @@ -296,28 +274,7 @@ public ITmfEvent instantiateEvent() {
try {
String traceTypeId = getTraceType();
if (traceTypeId != null) {
if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) {
for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName);
if (traceTypeId.equals(id)) {
return new CustomTxtEvent(def);
}
}
}
if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) {
for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName);
if (traceTypeId.equals(id)) {
return new CustomXmlEvent(def);
}
}
}
IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(traceTypeId);
if (ce == null) {
return null;
}
ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
return event;
return TmfTraceType.instantiateEvent(traceTypeId);
}
} catch (CoreException e) {
Activator.getDefault().logError("Error instantiating ITmfEvent object for trace " + getName(), e); //$NON-NLS-1$
Expand Down

0 comments on commit a0e1e12

Please sign in to comment.