Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Tasse2014-08-22 20:02:24 +0000
committerPatrick Tasse2014-09-08 18:09:35 +0000
commitc1309907623a4fc6e3b87464f7c21c162adcfab8 (patch)
treec7640d104f001525f2e38cf05ba974d736d8ae24 /lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf
parent11cab7a5b40f3f7104d22bc2f98ff332126d0477 (diff)
downloadorg.eclipse.linuxtools-c1309907623a4fc6e3b87464f7c21c162adcfab8.tar.gz
org.eclipse.linuxtools-c1309907623a4fc6e3b87464f7c21c162adcfab8.tar.xz
org.eclipse.linuxtools-c1309907623a4fc6e3b87464f7c21c162adcfab8.zip
tmf: Add category to custom parser definition
Change-Id: I882676278acca7398e4adee5c4f485bb20cda083 Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-on: https://git.eclipse.org/r/32278 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Diffstat (limited to 'lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf')
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTraceDefinition.java4
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java130
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java137
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/Messages.java5
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/messages.properties2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java4
6 files changed, 215 insertions, 67 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTraceDefinition.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTraceDefinition.java
index d483de788c..bbaa81da25 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTraceDefinition.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTraceDefinition.java
@@ -49,6 +49,10 @@ public abstract class CustomTraceDefinition {
/** "Other" tag */
public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag;
+ /** Category of this trace definition
+ * @since 3.1*/
+ public String categoryName;
+
/** Name of this trace definition */
public String definitionName;
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
index fe1db39d4b..b1406da073 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
@@ -83,6 +83,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
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;
private static final String NAME_ATTRIBUTE = Messages.CustomTxtTraceDefinition_name;
private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomTxtTraceDefinition_timestampOutputFormat;
private static final String INPUT_LINE_ELEMENT = Messages.CustomTxtTraceDefinition_inputLine;
@@ -99,13 +100,13 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
* Default constructor.
*/
public CustomTxtTraceDefinition() {
- this("", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ this(TmfTraceType.CUSTOM_TXT_CATEGORY, "", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Full constructor.
*
- * @param logtype
+ * @param traceType
* Name of the trace type
* @param inputs
* List of inputs
@@ -113,10 +114,36 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
* List of output columns
* @param timeStampOutputFormat
* The timestamp format to use
+ * @deprecated Use {@link #CustomTxtTraceDefinition(String, String, List, List, String)}
*/
- public CustomTxtTraceDefinition(String logtype, List<InputLine> inputs,
+ @Deprecated
+ public CustomTxtTraceDefinition(String traceType, List<InputLine> inputs,
List<OutputColumn> outputs, String timeStampOutputFormat) {
- this.definitionName = logtype;
+ this.definitionName = traceType;
+ this.inputs = inputs;
+ this.outputs = outputs;
+ this.timeStampOutputFormat = timeStampOutputFormat;
+ }
+
+ /**
+ * Full constructor.
+ *
+ * @param category
+ * Category of the trace type
+ * @param traceType
+ * Name of the trace type
+ * @param inputs
+ * List of inputs
+ * @param outputs
+ * List of output columns
+ * @param timeStampOutputFormat
+ * The timestamp format to use
+ * @since 3.1
+ */
+ public CustomTxtTraceDefinition(String category, String traceType, List<InputLine> inputs,
+ List<OutputColumn> outputs, String timeStampOutputFormat) {
+ this.categoryName = category;
+ this.definitionName = traceType;
this.inputs = inputs;
this.outputs = outputs;
this.timeStampOutputFormat = timeStampOutputFormat;
@@ -483,17 +510,13 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
Element root = doc.getDocumentElement();
- NodeList nodeList = root.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node instanceof Element &&
- node.getNodeName().equals(DEFINITION_ELEMENT) &&
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
- root.removeChild(node);
- }
+ Element oldDefinitionElement = findDefinitionElement(root, categoryName, definitionName);
+ if (oldDefinitionElement != null) {
+ root.removeChild(oldDefinitionElement);
}
Element definitionElement = doc.createElement(DEFINITION_ELEMENT);
root.appendChild(definitionElement);
+ definitionElement.setAttribute(CATEGORY_ATTRIBUTE, categoryName);
definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);
Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
@@ -527,7 +550,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
writer.write(xmlString);
}
- TmfTraceType.addCustomTraceType(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ TmfTraceType.addCustomTraceType(categoryName, definitionName);
} catch (ParserConfigurationException e) {
Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$
@@ -667,8 +690,24 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
* @param definitionName
* Name of the definition to load
* @return The loaded trace definition
+ * @deprecated Use {@link #load(String, String)}
*/
+ @Deprecated
public static CustomTxtTraceDefinition load(String definitionName) {
+ return load(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ }
+
+ /**
+ * Load a single definition.
+ *
+ * @param categoryName
+ * Category of the definition to load
+ * @param definitionName
+ * Name of the definition to load
+ * @return The loaded trace definition
+ * @since 3.1
+ */
+ public static CustomTxtTraceDefinition load(String categoryName, String definitionName) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
@@ -679,9 +718,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
// The following catches xml parsing exceptions
db.setErrorHandler(createErrorHandler());
- CustomTxtTraceDefinition value = lookupDefinition(definitionName, db, CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
+ CustomTxtTraceDefinition value = lookupDefinition(categoryName, definitionName, db, CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
if (value == null) {
- return lookupDefinition(definitionName, db, CUSTOM_TXT_TRACE_DEFINITIONS_DEFAULT_PATH_NAME);
+ return lookupDefinition(categoryName, definitionName, db, CUSTOM_TXT_TRACE_DEFINITIONS_DEFAULT_PATH_NAME);
}
return value;
} catch (ParserConfigurationException | SAXException | IOException e) {
@@ -690,7 +729,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
return null;
}
- private static CustomTxtTraceDefinition lookupDefinition(String definitionName, DocumentBuilder db, String source) throws SAXException, IOException {
+ private static CustomTxtTraceDefinition lookupDefinition(String categoryName, String definitionName, DocumentBuilder db, String source) throws SAXException, IOException {
File file = new File(source);
if (!file.exists()) {
return null;
@@ -702,13 +741,28 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
return null;
}
+ Element definitionElement = findDefinitionElement(root, categoryName, definitionName);
+ if (definitionElement != null) {
+ return extractDefinition(definitionElement);
+ }
+ return null;
+ }
+
+ private static Element findDefinitionElement(Element root, String categoryName, String definitionName) {
NodeList nodeList = root.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
- if (node instanceof Element &&
- node.getNodeName().equals(DEFINITION_ELEMENT) &&
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
- return extractDefinition((Element) node);
+ if (node instanceof Element && node.getNodeName().equals(DEFINITION_ELEMENT)) {
+ Element element = (Element) node;
+ String categoryAttribute = element.getAttribute(CATEGORY_ATTRIBUTE);
+ if (categoryAttribute.isEmpty()) {
+ categoryAttribute = TmfTraceType.CUSTOM_TXT_CATEGORY;
+ }
+ String nameAttribute = element.getAttribute(NAME_ATTRIBUTE);
+ if (categoryName.equals(categoryAttribute) &&
+ definitionName.equals(nameAttribute)) {
+ return element;
+ }
}
}
return null;
@@ -724,8 +778,12 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
public static CustomTxtTraceDefinition extractDefinition(Element definitionElement) {
CustomTxtTraceDefinition def = new CustomTxtTraceDefinition();
+ def.categoryName = definitionElement.getAttribute(CATEGORY_ATTRIBUTE);
+ if (def.categoryName.isEmpty()) {
+ def.categoryName = TmfTraceType.CUSTOM_TXT_CATEGORY;
+ }
def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);
- if (def.definitionName == null) {
+ if (def.definitionName.isEmpty()) {
return null;
}
@@ -792,8 +850,23 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
*
* @param definitionName
* The name of the definition to delete
+ * @deprecated Use {@link #delete(String, String)}
*/
+ @Deprecated
public static void delete(String definitionName) {
+ delete(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ }
+
+ /**
+ * Delete a definition from the currently loaded ones.
+ *
+ * @param categoryName
+ * The category of the definition to delete
+ * @param definitionName
+ * The name of the definition to delete
+ * @since 3.1
+ */
+ public static void delete(String categoryName, String definitionName) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
@@ -812,14 +885,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
return;
}
- NodeList nodeList = root.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node instanceof Element &&
- node.getNodeName().equals(DEFINITION_ELEMENT) &&
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
- root.removeChild(node);
- }
+ Element definitionElement = findDefinitionElement(root, categoryName, definitionName);
+ if (definitionElement != null) {
+ root.removeChild(definitionElement);
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -835,9 +903,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
writer.write(xmlString);
}
- TmfTraceType.removeCustomTraceType(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ TmfTraceType.removeCustomTraceType(categoryName, definitionName);
// Check if default definition needs to be reloaded
- TmfTraceType.addCustomTraceType(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+ TmfTraceType.addCustomTraceType(categoryName, definitionName);
} catch (ParserConfigurationException | SAXException | IOException | TransformerFactoryConfigurationError | TransformerException e) {
Activator.logError("Error deleting CustomTxtTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java
index a8124f5f2b..0568f36131 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java
@@ -84,8 +84,10 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
.append("org.eclipse.linuxtools.tmf.ui") //$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;
+ private static final String CATEGORY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_category;
private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;
private static final String LOG_ENTRY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_logEntry;
private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomXmlTraceDefinition_timestampOutputFormat;
@@ -103,24 +105,50 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
* Default constructor
*/
public CustomXmlTraceDefinition() {
- this("", null, new ArrayList<OutputColumn>(), ""); //$NON-NLS-1$ //$NON-NLS-2$
+ this(TmfTraceType.CUSTOM_XML_CATEGORY, "", null, new ArrayList<OutputColumn>(), ""); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* Full constructor
*
- * @param logtype
- * Type of trace type
+ * @param traceType
+ * Name of the trace type
* @param rootElement
* The top-level XML element
* @param outputs
* The list of output columns
* @param timeStampOutputFormat
* The timestamp format to use
+ * @deprecated Use {@link #CustomXmlTraceDefinition(String, String, InputElement, List, String)}
*/
- public CustomXmlTraceDefinition(String logtype, InputElement rootElement,
+ @Deprecated
+ public CustomXmlTraceDefinition(String traceType, InputElement rootElement,
List<OutputColumn> outputs, String timeStampOutputFormat) {
- this.definitionName = logtype;
+ this.definitionName = traceType;
+ this.rootInputElement = rootElement;
+ this.outputs = outputs;
+ this.timeStampOutputFormat = timeStampOutputFormat;
+ }
+
+ /**
+ * Full constructor
+ *
+ * @param category
+ * Category of the trace type
+ * @param traceType
+ * Name of the trace type
+ * @param rootElement
+ * The top-level XML element
+ * @param outputs
+ * The list of output columns
+ * @param timeStampOutputFormat
+ * The timestamp format to use
+ * @since 3.1
+ */
+ public CustomXmlTraceDefinition(String category, String traceType, InputElement rootElement,
+ List<OutputColumn> outputs, String timeStampOutputFormat) {
+ this.categoryName = category;
+ this.definitionName = traceType;
this.rootInputElement = rootElement;
this.outputs = outputs;
this.timeStampOutputFormat = timeStampOutputFormat;
@@ -344,17 +372,13 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
Element root = doc.getDocumentElement();
- NodeList nodeList = root.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node instanceof Element &&
- node.getNodeName().equals(DEFINITION_ELEMENT) &&
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
- root.removeChild(node);
- }
+ Element oldDefinitionElement = findDefinitionElement(root, categoryName, definitionName);
+ if (oldDefinitionElement != null) {
+ root.removeChild(oldDefinitionElement);
}
Element definitionElement = doc.createElement(DEFINITION_ELEMENT);
root.appendChild(definitionElement);
+ definitionElement.setAttribute(CATEGORY_ATTRIBUTE, categoryName);
definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);
Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
@@ -386,7 +410,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
writer.write(xmlString);
}
- TmfTraceType.addCustomTraceType(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ TmfTraceType.addCustomTraceType(categoryName, definitionName);
} catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException | IOException | SAXException e) {
Activator.logError("Error saving CustomXmlTraceDefinition: path=" + path, e); //$NON-NLS-1$
@@ -521,8 +545,24 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
* @param definitionName
* Name of the XML trace definition to load
* @return The loaded trace definition
+ * @deprecated Use {@link #load(String, String)}
*/
+ @Deprecated
public static CustomXmlTraceDefinition load(String definitionName) {
+ return load(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ }
+
+ /**
+ * Load the given trace definition.
+ *
+ * @param categoryName
+ * Category of the definition to load
+ * @param definitionName
+ * Name of the XML trace definition to load
+ * @return The loaded trace definition
+ * @since 3.1
+ */
+ public static CustomXmlTraceDefinition load(String categoryName, String definitionName) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
@@ -554,9 +594,9 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
}
});
- CustomXmlTraceDefinition value = lookupXmlDefinition(definitionName, db, CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
+ CustomXmlTraceDefinition value = lookupXmlDefinition(categoryName, definitionName, db, CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
if (value == null) {
- value = lookupXmlDefinition(definitionName, db, CUSTOM_XML_TRACE_DEFINITIONS_DEFAULT_PATH_NAME);
+ value = lookupXmlDefinition(categoryName, definitionName, db, CUSTOM_XML_TRACE_DEFINITIONS_DEFAULT_PATH_NAME);
}
return value;
} catch (ParserConfigurationException | SAXException | IOException e) {
@@ -565,7 +605,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
return null;
}
- private static CustomXmlTraceDefinition lookupXmlDefinition(String definitionName, DocumentBuilder db, String source) throws SAXException, IOException {
+ private static CustomXmlTraceDefinition lookupXmlDefinition(String categoryName, String definitionName, DocumentBuilder db, String source) throws SAXException, IOException {
File file = new File(source);
if (!file.exists()) {
return null;
@@ -578,13 +618,28 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
return null;
}
+ Element definitionElement = findDefinitionElement(root, categoryName, definitionName);
+ if (definitionElement != null) {
+ return extractDefinition(definitionElement);
+ }
+ return null;
+ }
+
+ private static Element findDefinitionElement(Element root, String categoryName, String definitionName) {
NodeList nodeList = root.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
- if (node instanceof Element &&
- node.getNodeName().equals(DEFINITION_ELEMENT) &&
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
- return extractDefinition((Element) node);
+ if (node instanceof Element && node.getNodeName().equals(DEFINITION_ELEMENT)) {
+ Element element = (Element) node;
+ String categoryAttribute = element.getAttribute(CATEGORY_ATTRIBUTE);
+ if (categoryAttribute.isEmpty()) {
+ categoryAttribute = TmfTraceType.CUSTOM_XML_CATEGORY;
+ }
+ String nameAttribute = element.getAttribute(NAME_ATTRIBUTE);
+ if (categoryName.equals(categoryAttribute) &&
+ definitionName.equals(nameAttribute)) {
+ return element;
+ }
}
}
return null;
@@ -600,8 +655,12 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
public static CustomXmlTraceDefinition extractDefinition(Element definitionElement) {
CustomXmlTraceDefinition def = new CustomXmlTraceDefinition();
+ def.categoryName = definitionElement.getAttribute(CATEGORY_ATTRIBUTE);
+ if (def.categoryName.isEmpty()) {
+ def.categoryName = TmfTraceType.CUSTOM_XML_CATEGORY;
+ }
def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);
- if (def.definitionName == null) {
+ if (def.definitionName.isEmpty()) {
return null;
}
@@ -672,12 +731,27 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
}
/**
- * Delete the given trace definition from the list of currently loaded ones.
+ * Delete a definition from the currently loaded ones.
*
* @param definitionName
- * Name of the trace definition to delete
+ * The name of the definition to delete
+ * @deprecated Use {@link #delete(String, String)}
*/
+ @Deprecated
public static void delete(String definitionName) {
+ delete(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ }
+
+ /**
+ * Delete a definition from the currently loaded ones.
+ *
+ * @param categoryName
+ * The category of the definition to delete
+ * @param definitionName
+ * The name of the definition to delete
+ * @since 3.1
+ */
+ public static void delete(String categoryName, String definitionName) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
@@ -717,14 +791,9 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
return;
}
- NodeList nodeList = root.getChildNodes();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node instanceof Element &&
- node.getNodeName().equals(DEFINITION_ELEMENT) &&
- definitionName.equals(((Element) node).getAttribute(NAME_ATTRIBUTE))) {
- root.removeChild(node);
- }
+ Element definitionElement = findDefinitionElement(root, categoryName, definitionName);
+ if (definitionElement != null) {
+ root.removeChild(definitionElement);
}
Transformer transformer = TransformerFactory.newInstance().newTransformer();
@@ -740,9 +809,9 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
writer.write(xmlString);
}
- TmfTraceType.removeCustomTraceType(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ TmfTraceType.removeCustomTraceType(categoryName, definitionName);
// Check if default definition needs to be reloaded
- TmfTraceType.addCustomTraceType(TmfTraceType.CUSTOM_XML_CATEGORY, definitionName);
+ TmfTraceType.addCustomTraceType(categoryName, definitionName);
} catch (ParserConfigurationException | SAXException | IOException | TransformerFactoryConfigurationError | TransformerException e) {
Activator.logError("Error deleteing CustomXmlTraceDefinition: definitionName=" + definitionName, e); //$NON-NLS-1$
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/Messages.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/Messages.java
index 885da4396a..3081a35f6f 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/Messages.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/Messages.java
@@ -23,11 +23,14 @@ public class Messages extends NLS {
public static String CustomTrace_FileNotFound;
+ // TODO: These strings should not be externalized
public static String CustomTraceDefinition_messageTag;
public static String CustomTraceDefinition_otherTag;
public static String CustomTraceDefinition_timestampTag;
public static String CustomTxtTraceDefinition_action;
public static String CustomTxtTraceDefinition_cardinality;
+ /** @since 3.1 */
+ public static String CustomTxtTraceDefinition_category;
public static String CustomTxtTraceDefinition_definition;
public static String CustomTxtTraceDefinition_definitionRootElement;
public static String CustomTxtTraceDefinition_format;
@@ -41,6 +44,8 @@ public class Messages extends NLS {
public static String CustomTxtTraceDefinition_timestampOutputFormat;
public static String CustomXmlTraceDefinition_action;
public static String CustomXmlTraceDefinition_attribute;
+ /** @since 3.1 */
+ public static String CustomXmlTraceDefinition_category;
public static String CustomXmlTraceDefinition_definition;
public static String CustomXmlTraceDefinition_definitionRootElement;
public static String CustomXmlTraceDefinition_format;
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/messages.properties b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/messages.properties
index f7fde094e2..5f12afdde8 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/messages.properties
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/messages.properties
@@ -17,6 +17,7 @@ CustomTraceDefinition_otherTag=Other
CustomTraceDefinition_timestampTag=Time Stamp
CustomTxtTraceDefinition_action=action
CustomTxtTraceDefinition_cardinality=Cardinality
+CustomTxtTraceDefinition_category=category
CustomTxtTraceDefinition_definition=Definition
CustomTxtTraceDefinition_definitionRootElement=CustomTxtTraceDefinitionList
CustomTxtTraceDefinition_format=format
@@ -30,6 +31,7 @@ CustomTxtTraceDefinition_regEx=RegEx
CustomTxtTraceDefinition_timestampOutputFormat=TimeStampOutputFormat
CustomXmlTraceDefinition_action=action
CustomXmlTraceDefinition_attribute=Attribute
+CustomXmlTraceDefinition_category=category
CustomXmlTraceDefinition_definition=Definition
CustomXmlTraceDefinition_definitionRootElement=CustomXMLTraceDefinitionList
CustomXmlTraceDefinition_format=format
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java
index 8593be945f..c47140af29 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceType.java
@@ -318,13 +318,13 @@ public final class TmfTraceType {
if (category.equals(CUSTOM_TXT_CATEGORY)) {
traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + definitionName;
- CustomTxtTraceDefinition def = CustomTxtTraceDefinition.load(definitionName);
+ CustomTxtTraceDefinition def = CustomTxtTraceDefinition.load(category, definitionName);
if (def != null) {
trace = new CustomTxtTrace(def);
}
} else if (category.equals(CUSTOM_XML_CATEGORY)) {
traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + definitionName;
- CustomXmlTraceDefinition def = CustomXmlTraceDefinition.load(definitionName);
+ CustomXmlTraceDefinition def = CustomXmlTraceDefinition.load(category, definitionName);
if (def != null) {
trace = new CustomXmlTrace(def);
}

Back to the top