From c9b31f606321336dcbba0804aef2ab84547781cf Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Tue, 3 Feb 2015 09:19:35 -0500 Subject: [PATCH] Make Custom Parser trace type backwards compatible to Linux Tools To achieve this it was necessary to update how the trace type ids are build for custom parsers Change-Id: I09dbfd83c1296f00473bfdd15ae36cdb105d52a9 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/41013 Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann --- .../filter/TmfFilterTraceTypeNodeTest.java | 8 +- .../tmf/core/parsers/custom/CustomTrace.java | 59 -------------- .../core/parsers/custom/CustomTxtTrace.java | 80 ++++++++++++++++++- .../custom/CustomTxtTraceDefinition.java | 55 +++++++++---- .../core/parsers/custom/CustomXmlTrace.java | 80 ++++++++++++++++++- .../custom/CustomXmlTraceDefinition.java | 55 +++++++++---- .../tmf/core/project/model/TmfTraceType.java | 58 ++++++-------- .../ui/tests/trace/CustomXmlTraceTest.java | 7 +- .../SelectElementTypeContributionItem.java | 4 +- .../tmf/ui/project/model/TmfTraceElement.java | 39 +++++---- 10 files changed, 291 insertions(+), 154 deletions(-) delete mode 100644 org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java diff --git a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java index d6e65b0383..7ff09423a0 100644 --- a/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java +++ b/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/filter/TmfFilterTraceTypeNodeTest.java @@ -63,6 +63,8 @@ public class TmfFilterTraceTypeNodeTest extends TmfFilterTreeNodeTest { private static final String DEFINITION_NAME_TXT = "name txt"; private static final String DEFINITION_NAME_XML = "name xml"; private static final String SEP = ":"; + private static final String CUSTOM_TXT_TRACE_TYPE_PREFIX = "custom.txt.trace" + SEP; + private static final String CUSTOM_XML_TRACE_TYPE_PREFIX = "custom.xml.trace" + SEP; private static CustomTxtTraceDefinition fCustomTxtDefinition = new CustomTxtTraceDefinition(); private static CustomXmlTraceDefinition fCustomXmlDefinition = new CustomXmlTraceDefinition(); static { @@ -106,19 +108,19 @@ public class TmfFilterTraceTypeNodeTest extends TmfFilterTreeNodeTest { assertFalse(fFilter.matches(fEvent3)); fFilter.setTraceClass(CustomTxtTrace.class); - fFilter.setTraceTypeId(CustomTxtTrace.class.getCanonicalName() + SEP + CATEGORY_TXT + SEP + DEFINITION_NAME_TXT); + fFilter.setTraceTypeId(CUSTOM_TXT_TRACE_TYPE_PREFIX + CATEGORY_TXT + SEP + DEFINITION_NAME_TXT); assertFalse(fFilter.matches(fEvent1)); assertTrue(fFilter.matches(fEvent2)); assertFalse(fFilter.matches(fEvent3)); fFilter.setTraceClass(CustomXmlTrace.class); - fFilter.setTraceTypeId(CustomXmlTrace.class.getCanonicalName() + SEP + CATEGORY_XML + SEP + DEFINITION_NAME_XML); + fFilter.setTraceTypeId(CUSTOM_XML_TRACE_TYPE_PREFIX + CATEGORY_XML + SEP + DEFINITION_NAME_XML); assertFalse(fFilter.matches(fEvent1)); assertFalse(fFilter.matches(fEvent2)); assertTrue(fFilter.matches(fEvent3)); fFilter.setTraceClass(CustomTxtTrace.class); - fFilter.setTraceTypeId(CustomTxtTrace.class.getCanonicalName() + SEP + CATEGORY_XML + SEP + DEFINITION_NAME_XML); + fFilter.setTraceTypeId(CUSTOM_TXT_TRACE_TYPE_PREFIX + CATEGORY_XML + SEP + DEFINITION_NAME_XML); assertFalse(fFilter.matches(fEvent1)); assertFalse(fFilter.matches(fEvent2)); assertFalse(fFilter.matches(fEvent3)); diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java deleted file mode 100644 index 1d0df02013..0000000000 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTrace.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Patrick Tasse - Initial API and implementation - *******************************************************************************/ - -package org.eclipse.tracecompass.tmf.core.parsers.custom; - -import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; -import org.eclipse.tracecompass.tmf.core.trace.TmfTrace; - -/** - * Base class for custom traces. - * - * @author Patrick Tasse - */ -public abstract class CustomTrace extends TmfTrace { - - private static final char SEPARATOR = ':'; - - private final String fTraceTypeId; - - /** - * Basic constructor. - * - * @param definition - * Custom trace definition - */ - public CustomTrace(CustomTraceDefinition definition) { - fTraceTypeId = buildTraceTypeId(getClass(), definition.categoryName, definition.definitionName); - } - - /** - * Build the trace type id for a custom trace - * - * @param traceClass - * the trace class - * @param category - * the category - * @param definitionName - * the definition name - * @return the trace type id - */ - public static @NonNull String buildTraceTypeId(Class traceClass, String category, String definitionName) { - return traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName; - } - - @Override - public String getTraceTypeId() { - return fTraceTypeId; - } -} diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java index 452b99e5dc..854ea78c72 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTrace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Patrick Tasse - Initial API and implementation + * Bernd Hufmann - Add trace type id handling *******************************************************************************/ package org.eclipse.tracecompass.tmf.core.parsers.custom; @@ -26,6 +27,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.internal.tmf.core.parsers.custom.CustomEventAspects; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; @@ -36,6 +38,7 @@ import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition 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.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable; import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer; @@ -51,7 +54,7 @@ import org.eclipse.tracecompass.tmf.core.trace.location.TmfLongLocation; * @author Patrick Tassé * @since 3.0 */ -public class CustomTxtTrace extends CustomTrace implements ITmfPersistentlyIndexable { +public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexable { private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L); private static final int DEFAULT_CACHE_SIZE = 100; @@ -61,6 +64,12 @@ public class CustomTxtTrace extends CustomTrace implements ITmfPersistentlyIndex private final CustomTxtTraceDefinition fDefinition; private final CustomTxtEventType fEventType; private BufferedRandomAccessFile fFile; + private final String fTraceTypeId; + + private static final char SEPARATOR = ':'; + private static final String CUSTOM_TXT_TRACE_TYPE_PREFIX = "custom.txt.trace" + SEPARATOR; //$NON-NLS-1$ + private static final String LINUX_TOOLS_CUSTOM_TXT_TRACE_TYPE_PREFIX = "org.eclipse.linuxtools.tmf.core.parsers.custom.CustomTxtTrace" + SEPARATOR; //$NON-NLS-1$ + private static final String EARLY_TRACE_COMPASS_CUSTOM_TXT_TRACE_TYPE_PREFIX = "org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace" + SEPARATOR; //$NON-NLS-1$ /** * Basic constructor. @@ -69,9 +78,9 @@ public class CustomTxtTrace extends CustomTrace implements ITmfPersistentlyIndex * Text trace definition */ public CustomTxtTrace(final CustomTxtTraceDefinition definition) { - super(definition); fDefinition = definition; fEventType = new CustomTxtEventType(fDefinition); + fTraceTypeId = buildTraceTypeId(definition.categoryName, definition.definitionName); setCacheSize(DEFAULT_CACHE_SIZE); } @@ -466,4 +475,69 @@ public class CustomTxtTrace extends CustomTrace implements ITmfPersistentlyIndex protected ITmfTraceIndexer createIndexer(int interval) { return new TmfBTreeTraceIndexer(this, interval); } + + @Override + public String getTraceTypeId() { + return fTraceTypeId; + } + + /** + * Build the trace type id for a custom text trace + * + * @param category + * the category + * @param definitionName + * the definition name + * @return the trace type id + */ + public static @NonNull String buildTraceTypeId(String category, String definitionName) { + return CUSTOM_TXT_TRACE_TYPE_PREFIX + category + SEPARATOR + definitionName; + } + + /** + * Checks whether the given trace type ID is a custom text trace type ID + * + * @param traceTypeId + * the trace type ID to check + * @return true if it's a custom text trace type ID else false + */ + public static boolean isCustomTraceTypeId(@NonNull String traceTypeId) { + return traceTypeId.startsWith(CUSTOM_TXT_TRACE_TYPE_PREFIX); + } + + /** + * This methods builds a trace type ID from a given ID taking into + * consideration any format changes that were done for the IDs of custom + * text traces. For example, such format change took place when moving to + * Trace Compass. Trace type IDs that are part of the plug-in extension for + * trace types won't be changed. + * + * This method is useful for IDs that were persisted in the workspace before + * the format changes (e.g. in the persistent properties of a trace + * resource). + * + * It ensures backwards compatibility of the workspace for custom text + * traces. + * + * @param traceTypeId + * the legacy trace type ID + * @return the trace type id in Trace Compass format + */ + public static @NonNull String buildCompatibilityTraceTypeId(@NonNull String traceTypeId) { + // Handle early Trace Compass custom text trace type IDs + if (traceTypeId.startsWith(EARLY_TRACE_COMPASS_CUSTOM_TXT_TRACE_TYPE_PREFIX)) { + return CUSTOM_TXT_TRACE_TYPE_PREFIX + traceTypeId.substring(EARLY_TRACE_COMPASS_CUSTOM_TXT_TRACE_TYPE_PREFIX.length()); + } + + // Handle Linux Tools custom text trace type IDs (with and without category) + int index = traceTypeId.lastIndexOf(SEPARATOR); + if ((index != -1) && (traceTypeId.startsWith(LINUX_TOOLS_CUSTOM_TXT_TRACE_TYPE_PREFIX))) { + String definitionName = index < traceTypeId.length() ? traceTypeId.substring(index + 1) : ""; //$NON-NLS-1$ + if (traceTypeId.contains(CustomTxtTrace.class.getSimpleName() + SEPARATOR) && traceTypeId.indexOf(SEPARATOR) == index) { + return buildTraceTypeId(CustomTxtTraceDefinition.CUSTOM_TXT_CATEGORY, definitionName); + } + return CUSTOM_TXT_TRACE_TYPE_PREFIX + traceTypeId.substring(LINUX_TOOLS_CUSTOM_TXT_TRACE_TYPE_PREFIX.length()); + } + return traceTypeId; + } } diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java index 1ee3ab17b0..7b537fdb39 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -59,6 +59,13 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { /** Input lines */ public List inputs; + /** + * Custom text label used internally and therefore should not be + * externalized + */ + public static final String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$ + + /** File name of the default definition file */ protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_DEFAULT_FILE_NAME = "custom_txt_default_parsers.xml"; //$NON-NLS-1$ /** File name of the definition file */ @@ -73,14 +80,23 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString(); /** - * Legacy path to the XML definitions file (in the UI plug-in) TODO Remove + * Legacy path to the XML definitions file (in the UI plug-in of linuxtools) TODO Remove * once we feel the transition phase is over. */ - private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY = + private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI = Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator() .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$ .append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString(); + /** + * Legacy path to the XML definitions file (in the core plug-in of linuxtools) TODO Remove + * once we feel the transition phase is over. + */ + private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE = + Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator() + .append("org.eclipse.linuxtools.tmf.core") //$NON-NLS-1$ + .append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString(); + private static final String CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomTxtTraceDefinition_definitionRootElement; private static final String DEFINITION_ELEMENT = Messages.CustomTxtTraceDefinition_definition; private static final String CATEGORY_ATTRIBUTE = Messages.CustomTxtTraceDefinition_category; @@ -100,7 +116,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { * Default constructor. */ public CustomTxtTraceDefinition() { - this(TmfTraceType.CUSTOM_TXT_CATEGORY, "", new ArrayList(0), new ArrayList(0), ""); //$NON-NLS-1$ //$NON-NLS-2$ + this(CUSTOM_TXT_CATEGORY, "", new ArrayList(0), new ArrayList(0), ""); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -622,17 +638,18 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { */ public static CustomTxtTraceDefinition[] loadAll(boolean includeDefaults) { File defaultFile = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME); - File legacyFile = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY); + File legacyFileCore = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE); + File legacyFileUI = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI); /* * If there is no file at the expected location, check the legacy - * location instead. + * locations instead. */ - if (!defaultFile.exists() && legacyFile.exists()) { - CustomTxtTraceDefinition[] oldDefs = loadAll(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY); - for (CustomTxtTraceDefinition def : oldDefs) { - /* Save in the new location */ - def.save(); + if (!defaultFile.exists()) { + if (legacyFileCore.exists()) { + transferDefinitions(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE); + } else if (legacyFileUI.exists()) { + transferDefinitions(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI); } } @@ -654,6 +671,14 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { } + private static void transferDefinitions(String defFile) { + CustomTxtTraceDefinition[] oldDefs = loadAll(defFile); + for (CustomTxtTraceDefinition def : oldDefs) { + /* Save in the new location */ + def.save(); + } + } + /** * Load a specific text trace definition file. * @@ -715,7 +740,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { */ @Deprecated public static CustomTxtTraceDefinition load(String definitionName) { - return load(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName); + return load(CUSTOM_TXT_CATEGORY, definitionName); } /** @@ -777,7 +802,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { Element element = (Element) node; String categoryAttribute = element.getAttribute(CATEGORY_ATTRIBUTE); if (categoryAttribute.isEmpty()) { - categoryAttribute = TmfTraceType.CUSTOM_TXT_CATEGORY; + categoryAttribute = CUSTOM_TXT_CATEGORY; } String nameAttribute = element.getAttribute(NAME_ATTRIBUTE); if (categoryName.equals(categoryAttribute) && @@ -801,7 +826,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { def.categoryName = definitionElement.getAttribute(CATEGORY_ATTRIBUTE); if (def.categoryName.isEmpty()) { - def.categoryName = TmfTraceType.CUSTOM_TXT_CATEGORY; + def.categoryName = CUSTOM_TXT_CATEGORY; } def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE); if (def.definitionName.isEmpty()) { @@ -875,7 +900,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { */ @Deprecated public static void delete(String definitionName) { - delete(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName); + delete(CUSTOM_TXT_CATEGORY, definitionName); } /** diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java index aa38c7093f..5c91bcb381 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -8,6 +8,7 @@ * * Contributors: * Patrick Tasse - Initial API and implementation + * Bernd Hufmann - Add trace type id handling *******************************************************************************/ package org.eclipse.tracecompass.tmf.core.parsers.custom; @@ -26,6 +27,7 @@ import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.internal.tmf.core.parsers.custom.CustomEventAspects; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; @@ -35,6 +37,7 @@ import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile; 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.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus; import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable; import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer; @@ -59,7 +62,7 @@ import org.xml.sax.SAXParseException; * @author Patrick Tassé * @since 3.0 */ -public class CustomXmlTrace extends CustomTrace implements ITmfPersistentlyIndexable { +public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexable { private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L); private static final int DEFAULT_CACHE_SIZE = 100; @@ -70,6 +73,12 @@ public class CustomXmlTrace extends CustomTrace implements ITmfPersistentlyIndex private final CustomXmlEventType fEventType; private final CustomXmlInputElement fRecordInputElement; private BufferedRandomAccessFile fFile; + private final String fTraceTypeId; + + private static final char SEPARATOR = ':'; + private static final String CUSTOM_XML_TRACE_TYPE_PREFIX = "custom.xml.trace" + SEPARATOR; //$NON-NLS-1$ + private static final String LINUX_TOOLS_CUSTOM_XML_TRACE_TYPE_PREFIX = "org.eclipse.linuxtools.tmf.core.parsers.custom.CustomXmlTrace" + SEPARATOR; //$NON-NLS-1$ + private static final String EARLY_TRACE_COMPASS_CUSTOM_XML_TRACE_TYPE_PREFIX = "org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace" + SEPARATOR; //$NON-NLS-1$ /** * Basic constructor @@ -78,10 +87,10 @@ public class CustomXmlTrace extends CustomTrace implements ITmfPersistentlyIndex * Trace definition */ public CustomXmlTrace(final CustomXmlTraceDefinition definition) { - super(definition); fDefinition = definition; fEventType = new CustomXmlEventType(fDefinition); fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement); + fTraceTypeId = buildTraceTypeId(definition.categoryName, definition.definitionName); setCacheSize(DEFAULT_CACHE_SIZE); } @@ -588,4 +597,69 @@ public class CustomXmlTrace extends CustomTrace implements ITmfPersistentlyIndex protected ITmfTraceIndexer createIndexer(int interval) { return new TmfBTreeTraceIndexer(this, interval); } + + @Override + public String getTraceTypeId() { + return fTraceTypeId; + } + + /** + * Build the trace type id for a custom XML trace + * + * @param category + * the category + * @param definitionName + * the definition name + * @return the trace type id + */ + public static @NonNull String buildTraceTypeId(String category, String definitionName) { + return CUSTOM_XML_TRACE_TYPE_PREFIX + category + SEPARATOR + definitionName; + } + + /** + * Checks whether the given trace type ID is a custom XML trace type ID + * + * @param traceTypeId + * the trace type ID to check + * @return true if it's a custom text trace type ID else false + */ + public static boolean isCustomTraceTypeId(@NonNull String traceTypeId) { + return traceTypeId.startsWith(CUSTOM_XML_TRACE_TYPE_PREFIX); + } + + /** + * This methods builds a trace type ID from a given ID taking into + * consideration any format changes that were done for the IDs of custom + * XML traces. For example, such format change took place when moving to + * Trace Compass. Trace type IDs that are part of the plug-in extension for + * trace types won't be changed. + * + * This method is useful for IDs that were persisted in the workspace before + * the format changes (e.g. in the persistent properties of a trace + * resource). + * + * It ensures backwards compatibility of the workspace for custom XML + * traces. + * + * @param traceTypeId + * the legacy trace type ID + * @return the trace type id in Trace Compass format + */ + public static @NonNull String buildCompatibilityTraceTypeId(@NonNull String traceTypeId) { + // Handle early Trace Compass custom XML trace type IDs + if (traceTypeId.startsWith(EARLY_TRACE_COMPASS_CUSTOM_XML_TRACE_TYPE_PREFIX)) { + return CUSTOM_XML_TRACE_TYPE_PREFIX + traceTypeId.substring(EARLY_TRACE_COMPASS_CUSTOM_XML_TRACE_TYPE_PREFIX.length()); + } + + // Handle Linux Tools custom XML trace type IDs (with and without category) + int index = traceTypeId.lastIndexOf(SEPARATOR); + if ((index != -1) && (traceTypeId.startsWith(LINUX_TOOLS_CUSTOM_XML_TRACE_TYPE_PREFIX))) { + String definitionName = index < traceTypeId.length() ? traceTypeId.substring(index + 1) : ""; //$NON-NLS-1$ + if (traceTypeId.contains(CustomXmlTrace.class.getSimpleName() + SEPARATOR) && traceTypeId.indexOf(SEPARATOR) == index) { + return buildTraceTypeId(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY, definitionName); + } + return CUSTOM_XML_TRACE_TYPE_PREFIX + traceTypeId.substring(LINUX_TOOLS_CUSTOM_XML_TRACE_TYPE_PREFIX.length()); + } + return traceTypeId; + } } diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java index 556458bdea..9ee123eded 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2015 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -62,6 +62,12 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { /** "ignore" tag */ public static final String TAG_IGNORE = Messages.CustomXmlTraceDefinition_ignoreTag; + /** + * Custom XML label used internally and therefore should not be externalized + */ + public static final String CUSTOM_XML_CATEGORY = "Custom XML"; //$NON-NLS-1$ + + /** Name of the default XML definitions file */ protected static final String CUSTOM_XML_TRACE_DEFINITIONS_DEFAULT_FILE_NAME = "custom_xml_default_parsers.xml"; //$NON-NLS-1$ @@ -78,14 +84,23 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString(); /** - * Legacy path to the XML definitions file (in the UI plug-in) TODO Remove + * Legacy path to the XML definitions file (in the UI plug-in of linux tools) TODO Remove * once we feel the transition phase is over. */ - private static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY = + private static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI = Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator() .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$ .append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString(); + /** + * Legacy path to the XML definitions file (in the core plug-in of linux tools) TODO Remove + * once we feel the transition phase is over. + */ + private static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE = + Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator() + .append("org.eclipse.linuxtools.tmf.core") //$NON-NLS-1$ + .append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString(); + // TODO: These strings should not be externalized private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomXmlTraceDefinition_definitionRootElement; private static final String DEFINITION_ELEMENT = Messages.CustomXmlTraceDefinition_definition; @@ -107,7 +122,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { * Default constructor */ public CustomXmlTraceDefinition() { - this(TmfTraceType.CUSTOM_XML_CATEGORY, "", null, new ArrayList(), ""); //$NON-NLS-1$ //$NON-NLS-2$ + this(CUSTOM_XML_CATEGORY, "", null, new ArrayList(), ""); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -298,17 +313,18 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { */ public static CustomXmlTraceDefinition[] loadAll(boolean includeDefaults) { File defaultFile = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME); - File legacyFile = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY); + File legacyFileUI = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI); + File legacyFileCore = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE); /* * If there is no file at the expected location, check the legacy - * location instead. + * locations instead. */ - if (!defaultFile.exists() && legacyFile.exists()) { - CustomXmlTraceDefinition[] oldDefs = loadAll(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY); - for (CustomXmlTraceDefinition def : oldDefs) { - /* Save in the new location */ - def.save(); + if (!defaultFile.exists()) { + if (legacyFileCore.exists()) { + transferDefinitions(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE); + } else if (legacyFileUI.exists()) { + transferDefinitions(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI); } } @@ -329,6 +345,15 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { return defs.toArray(new CustomXmlTraceDefinition[0]); } + private static void transferDefinitions(String defFile) { + CustomXmlTraceDefinition[] oldDefs = loadAll(defFile); + for (CustomXmlTraceDefinition def : oldDefs) { + /* Save in the new location */ + def.save(); + } + } + + /** * Load all the XML trace definitions in the given definitions file. * @@ -402,7 +427,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { */ @Deprecated public static CustomXmlTraceDefinition load(String definitionName) { - return load(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName); + return load(CUSTOM_XML_CATEGORY, definitionName); } /** @@ -486,7 +511,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { Element element = (Element) node; String categoryAttribute = element.getAttribute(CATEGORY_ATTRIBUTE); if (categoryAttribute.isEmpty()) { - categoryAttribute = TmfTraceType.CUSTOM_XML_CATEGORY; + categoryAttribute = CUSTOM_XML_CATEGORY; } String nameAttribute = element.getAttribute(NAME_ATTRIBUTE); if (categoryName.equals(categoryAttribute) && @@ -510,7 +535,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { def.categoryName = definitionElement.getAttribute(CATEGORY_ATTRIBUTE); if (def.categoryName.isEmpty()) { - def.categoryName = TmfTraceType.CUSTOM_XML_CATEGORY; + def.categoryName = CUSTOM_XML_CATEGORY; } def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE); if (def.definitionName.isEmpty()) { @@ -595,7 +620,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { */ @Deprecated public static void delete(String definitionName) { - delete(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName); + delete(CUSTOM_XML_CATEGORY, definitionName); } /** diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TmfTraceType.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TmfTraceType.java index 3dc44a1a17..ee632b7880 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TmfTraceType.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/project/model/TmfTraceType.java @@ -10,6 +10,7 @@ * Patrick Tasse - Initial API and implementation * Matthew Khouzam - Added import functionalities * Geneviève Bastien - Added support for experiment types + * Bernd Hufmann - Updated custom trace type ID handling *******************************************************************************/ package org.eclipse.tracecompass.tmf.core.project.model; @@ -30,7 +31,6 @@ import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.Platform; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTrace; 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.CustomXmlTrace; @@ -86,17 +86,6 @@ public final class TmfTraceType { /** Extension point attribute 'isDirectory' */ public static final String IS_DIR_ATTR = "isDirectory"; //$NON-NLS-1$ - /** - * Custom text label used internally and therefore should not be - * externalized - */ - public static final String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$ - - /** - * Custom XML label used internally and therefore should not be externalized - */ - public static final String CUSTOM_XML_CATEGORY = "Custom XML"; //$NON-NLS-1$ - /** Default experiment type */ public static final String DEFAULT_EXPERIMENT_TYPE = "org.eclipse.linuxtools.tmf.core.experiment.generic"; //$NON-NLS-1$ @@ -240,13 +229,13 @@ public final class TmfTraceType { */ public static List getCustomTraceTypes(String type) { List traceTypes = new ArrayList<>(); - if (type.equals(CUSTOM_TXT_CATEGORY)) { + if (type.equals(CustomTxtTraceDefinition.CUSTOM_TXT_CATEGORY)) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { String traceTypeName = def.definitionName; traceTypes.add(traceTypeName); } } - if (type.equals(CUSTOM_XML_CATEGORY)) { + if (type.equals(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY)) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { String traceTypeName = def.definitionName; traceTypes.add(traceTypeName); @@ -305,9 +294,9 @@ public final class TmfTraceType { */ @Deprecated public static void addCustomTraceType(String category, String definitionName) { - if (category.equals(CUSTOM_TXT_CATEGORY)) { + if (category.equals(CustomTxtTraceDefinition.CUSTOM_TXT_CATEGORY)) { addCustomTraceType(CustomTxtTrace.class, category, definitionName); - } else if (category.equals(CUSTOM_XML_CATEGORY)) { + } else if (category.equals(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY)) { addCustomTraceType(CustomXmlTrace.class, category, definitionName); } } @@ -325,7 +314,7 @@ public final class TmfTraceType { */ public static void addCustomTraceType(Class traceClass, String category, String definitionName) { String traceTypeId = null; - CustomTrace trace = null; + ITmfTrace trace = null; if (traceClass.equals(CustomTxtTrace.class)) { CustomTxtTraceDefinition def = CustomTxtTraceDefinition.load(category, definitionName); @@ -364,9 +353,9 @@ public final class TmfTraceType { */ @Deprecated public static void removeCustomTraceType(String category, String definitionName) { - if (category.equals(CUSTOM_TXT_CATEGORY)) { + if (category.equals(CustomTxtTraceDefinition.CUSTOM_TXT_CATEGORY)) { removeCustomTraceType(CustomTxtTrace.class, category, definitionName); - } else if (category.equals(CUSTOM_XML_CATEGORY)) { + } else if (category.equals(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY)) { removeCustomTraceType(CustomXmlTrace.class, category, definitionName); } } @@ -383,10 +372,17 @@ public final class TmfTraceType { * The custom parser definition name to add or replace */ public static void removeCustomTraceType(Class traceClass, String category, String definitionName) { - String traceTypeId = CustomTrace.buildTraceTypeId(traceClass, category, definitionName); - TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId); - if (helper != null) { - helper.getTrace().dispose(); + String traceTypeId = null; + if (traceClass.equals(CustomTxtTrace.class)) { + traceTypeId = CustomTxtTrace.buildTraceTypeId(category, definitionName); + } else if (traceClass.equals(CustomXmlTrace.class)) { + traceTypeId = CustomXmlTrace.buildTraceTypeId(category, definitionName); + } + if (traceTypeId != null) { + TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId); + if (helper != null) { + helper.getTrace().dispose(); + } } } @@ -541,7 +537,7 @@ public final class TmfTraceType { */ public static boolean validateTraceFiles(String traceTypeName, List traces) { if (traceTypeName != null && !"".equals(traceTypeName) && //$NON-NLS-1$ - !traceTypeName.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY) && !traceTypeName.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY)) { + !traceTypeName.startsWith(CustomTxtTraceDefinition.CUSTOM_TXT_CATEGORY) && !traceTypeName.startsWith(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY)) { for (File trace : traces) { if (!validate(traceTypeName, trace.getAbsolutePath())) { return false; @@ -625,17 +621,13 @@ public final class TmfTraceType { String traceTypeId = resource.getPersistentProperties().get(TmfCommonConstants.TRACETYPE); // Fix custom trace type id with old class name or without category name for backward compatibility if (traceTypeId != null) { - int index = traceTypeId.lastIndexOf(':'); - if (index != -1) { - if (traceTypeId.contains(CustomTxtTrace.class.getSimpleName() + ':') && traceTypeId.indexOf(':') == index) { - traceTypeId = CustomTxtTrace.class.getCanonicalName() + ':' + - TmfTraceType.CUSTOM_TXT_CATEGORY + traceTypeId.substring(index); - } else if (traceTypeId.contains(CustomXmlTrace.class.getSimpleName() + ':') && traceTypeId.indexOf(':') == index) { - traceTypeId = CustomXmlTrace.class.getCanonicalName() + ':' + - TmfTraceType.CUSTOM_XML_CATEGORY + traceTypeId.substring(index); - } + String newTraceType = CustomTxtTrace.buildCompatibilityTraceTypeId(traceTypeId); + if (newTraceType.equals(traceTypeId)) { + newTraceType = CustomXmlTrace.buildCompatibilityTraceTypeId(traceTypeId); } + return newTraceType; } return traceTypeId; } + } diff --git a/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java b/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java index 826b989a02..4dac2dc296 100644 --- a/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java +++ b/org.eclipse.tracecompass.tmf.ui.tests/src/org/eclipse/tracecompass/tmf/ui/tests/trace/CustomXmlTraceTest.java @@ -14,11 +14,10 @@ package org.eclipse.tracecompass.tmf.ui.tests.trace; import java.util.ArrayList; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; -import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement; -import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.junit.Before; /** @@ -44,7 +43,7 @@ public abstract class CustomXmlTraceTest { */ @Before public void init() { - cxtd = new CustomXmlTraceDefinition(TmfTraceType.CUSTOM_XML_CATEGORY, "test", new CustomXmlInputElement(), new ArrayList(), "s"); + cxtd = new CustomXmlTraceDefinition(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY, "test", new CustomXmlInputElement(), new ArrayList(), "s"); t = new CustomXmlTrace(cxtd); } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java index 06959fa6fd..2c09e8d3d5 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/project/handlers/SelectElementTypeContributionItem.java @@ -176,7 +176,7 @@ public class SelectElementTypeContributionItem extends CompoundContributionItem */ for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { String traceBundle = Activator.getDefault().getBundle().getSymbolicName(); - String traceTypeId = CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName; + String traceTypeId = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName); String traceIcon = DEFAULT_TRACE_ICON_PATH; String label = def.definitionName; boolean selected = selectedTraceTypes.contains(traceTypeId); @@ -186,7 +186,7 @@ public class SelectElementTypeContributionItem extends CompoundContributionItem } for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { String traceBundle = Activator.getDefault().getBundle().getSymbolicName(); - String traceTypeId = CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName; + String traceTypeId = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName); String traceIcon = DEFAULT_TRACE_ICON_PATH; String label = def.definitionName; boolean selected = selectedTraceTypes.contains(traceTypeId); diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceElement.java index 8daf7095ed..a4187a4480 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceElement.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceElement.java @@ -241,22 +241,25 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF // make sure that supplementary folder exists refreshSupplementaryFolder(); - if (getTraceType() != null) { - if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { + String traceTypeId = getTraceType(); + if (traceTypeId != null) { + if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { + String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName); + if (traceTypeId.equals(id)) { return new CustomTxtTrace(def); } } } - if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { + if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { + String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName); + if (traceTypeId.equals(id)) { return new CustomXmlTrace(def); } } } - IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType()); + IConfigurationElement ce = sfTraceTypeAttributes.get(traceTypeId); if (ce == null) { return null; } @@ -277,22 +280,25 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF */ public ITmfEvent instantiateEvent() { try { - if (getTraceType() != null) { - if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { + String traceTypeId = getTraceType(); + if (traceTypeId != null) { + if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) { for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomTxtTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { + String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName); + if (traceTypeId.equals(id)) { return new CustomTxtEvent(def); } } } - if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { + if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) { for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { - if (getTraceType().equals(CustomXmlTrace.class.getCanonicalName() + ':' + def.categoryName+ ':' + def.definitionName)) { + String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName); + if (traceTypeId.equals(id)) { return new CustomXmlEvent(def); } } } - IConfigurationElement ce = sfTraceTypeAttributes.get(getTraceType()); + IConfigurationElement ce = sfTraceTypeAttributes.get(traceTypeId); if (ce == null) { return null; } @@ -307,13 +313,12 @@ public class TmfTraceElement extends TmfCommonProjectElement implements IActionF @Override public String getEditorId() { - if (getTraceType() != null) { - if (getTraceType().startsWith(CustomTxtTrace.class.getCanonicalName())) { - return TmfEventsEditor.ID; - } - if (getTraceType().startsWith(CustomXmlTrace.class.getCanonicalName())) { + String traceTypeId = getTraceType(); + if (traceTypeId != null) { + if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId) || CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) { return TmfEventsEditor.ID; } + IConfigurationElement ce = sfTraceTypeUIAttributes.get(getTraceType()); if (ce == null) { /* This trace type does not define UI attributes */ -- 2.34.1