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 {
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));
+++ /dev/null
-/*******************************************************************************
- * 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<? extends ITmfTrace> traceClass, String category, String definitionName) {
- return traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
- }
-
- @Override
- public String getTraceTypeId() {
- return fTraceTypeId;
- }
-}
/*******************************************************************************
- * 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
*
* Contributors:
* Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Add trace type id handling
*******************************************************************************/
package org.eclipse.tracecompass.tmf.core.parsers.custom;
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;
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;
* @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;
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.
* 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);
}
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 <code>true</code> if it's a custom text trace type ID else <code>false</code>
+ */
+ 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;
+ }
}
/*******************************************************************************
- * 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
/** Input lines */
public List<InputLine> 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 */
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;
* Default constructor.
*/
public CustomTxtTraceDefinition() {
- this(TmfTraceType.CUSTOM_TXT_CATEGORY, "", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ this(CUSTOM_TXT_CATEGORY, "", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
*/
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);
}
}
}
+ 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.
*
*/
@Deprecated
public static CustomTxtTraceDefinition load(String definitionName) {
- return load(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ return load(CUSTOM_TXT_CATEGORY, definitionName);
}
/**
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) &&
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()) {
*/
@Deprecated
public static void delete(String definitionName) {
- delete(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ delete(CUSTOM_TXT_CATEGORY, definitionName);
}
/**
/*******************************************************************************
- * 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
*
* Contributors:
* Patrick Tasse - Initial API and implementation
+ * Bernd Hufmann - Add trace type id handling
*******************************************************************************/
package org.eclipse.tracecompass.tmf.core.parsers.custom;
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;
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;
* @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;
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
* 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);
}
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 <code>true</code> if it's a custom text trace type ID else <code>false</code>
+ */
+ 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;
+ }
}
/*******************************************************************************
- * 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
/** "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$
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;
* Default constructor
*/
public CustomXmlTraceDefinition() {
- this(TmfTraceType.CUSTOM_XML_CATEGORY, "", null, new ArrayList<OutputColumn>(), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ this(CUSTOM_XML_CATEGORY, "", null, new ArrayList<OutputColumn>(), ""); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
*/
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);
}
}
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.
*
*/
@Deprecated
public static CustomXmlTraceDefinition load(String definitionName) {
- return load(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ return load(CUSTOM_XML_CATEGORY, definitionName);
}
/**
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) &&
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()) {
*/
@Deprecated
public static void delete(String definitionName) {
- delete(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ delete(CUSTOM_XML_CATEGORY, definitionName);
}
/**
* 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;
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;
/** 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$
*/
public static List<String> getCustomTraceTypes(String type) {
List<String> 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);
*/
@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);
}
}
*/
public static void addCustomTraceType(Class<? extends ITmfTrace> 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);
*/
@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);
}
}
* The custom parser definition name to add or replace
*/
public static void removeCustomTraceType(Class<? extends ITmfTrace> 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();
+ }
}
}
*/
public static boolean validateTraceFiles(String traceTypeName, List<File> 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;
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;
}
+
}
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;
/**
*/
@Before
public void init() {
- cxtd = new CustomXmlTraceDefinition(TmfTraceType.CUSTOM_XML_CATEGORY, "test", new CustomXmlInputElement(), new ArrayList<OutputColumn>(), "s");
+ cxtd = new CustomXmlTraceDefinition(CustomXmlTraceDefinition.CUSTOM_XML_CATEGORY, "test", new CustomXmlInputElement(), new ArrayList<OutputColumn>(), "s");
t = new CustomXmlTrace(cxtd);
}
*/
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);
}
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);
// 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;
}
*/
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;
}
@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 */