From: Patrick Tasse Date: Thu, 23 Jun 2016 22:32:55 +0000 (-0400) Subject: tmf: Add support for custom event type by text line or XML element X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=eddf2682b03b38114cf882d6dff9bfb96e47e9ee;p=deliverable%2Ftracecompass.git tmf: Add support for custom event type by text line or XML element The text line or XML element can have an associated event type that will override the definition name as the default event type. If a custom event field or attribute is defined to set the event type, it will override that default. Change-Id: I9e38a0cdb5dc1b4442ca8028bbbbee220dc6001c Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/75892 Reviewed-by: Hudson CI --- diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtEvent.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtEvent.java index 02f3954c3d..d555f20288 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtEvent.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtEvent.java @@ -83,6 +83,9 @@ public class CustomTxtEvent extends CustomEvent { * The regex matcher to use */ public void processGroups(InputLine input, Matcher matcher) { + if (input.eventType != null) { + fData.put(CustomTraceDefinition.TAG_EVENT_TYPE, input.eventType); + } if (input.columns == null) { return; } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java index 2de73280a8..f7e3df49fd 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java @@ -107,6 +107,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { private static final String MIN_ATTRIBUTE = Messages.CustomTxtTraceDefinition_min; private static final String MAX_ATTRIBUTE = Messages.CustomTxtTraceDefinition_max; private static final String REGEX_ELEMENT = Messages.CustomTxtTraceDefinition_regEx; + private static final String EVENT_TYPE_ELEMENT = Messages.CustomTxtTraceDefinition_eventType; private static final String INPUT_DATA_ELEMENT = Messages.CustomTxtTraceDefinition_inputData; private static final String ACTION_ATTRIBUTE = Messages.CustomTxtTraceDefinition_action; private static final String FORMAT_ATTRIBUTE = Messages.CustomTxtTraceDefinition_format; @@ -165,6 +166,10 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { /** Children of this line (if one "event" spans many lines) */ public List childrenInputs; + /** Event type associated with this line + * @since 2.1*/ + public String eventType; + private String regex; private Pattern pattern; @@ -563,6 +568,12 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { inputLineElement.appendChild(regexElement); regexElement.appendChild(doc.createTextNode(inputLine.regex)); + if (inputLine.eventType != null) { + Element eventTypeElement = doc.createElement(EVENT_TYPE_ELEMENT); + inputLineElement.appendChild(eventTypeElement); + eventTypeElement.appendChild(doc.createTextNode(inputLine.eventType)); + } + if (inputLine.columns != null) { for (InputData inputData : inputLine.columns) { Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); @@ -826,6 +837,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { } else if (nodeName.equals(REGEX_ELEMENT)) { Element regexElement = (Element) node; inputLine.regex = regexElement.getTextContent(); + } else if (nodeName.equals(EVENT_TYPE_ELEMENT)) { + Element eventTypeElement = (Element) node; + inputLine.eventType = eventTypeElement.getTextContent(); } else if (nodeName.equals(INPUT_DATA_ELEMENT)) { Element inputDataElement = (Element) node; InputData inputData = new InputData(); diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java index 79fbf333ea..75d4b82c7d 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java @@ -48,6 +48,9 @@ public final class CustomXmlInputElement { /** Child elements */ private List fChildElements; + /** Event type associated with this input element */ + private String fEventType; + /** * Default (empty) constructor */ @@ -205,6 +208,23 @@ public final class CustomXmlInputElement { fInputName = inputName; } + /** + * @return the eventType, or null + * @since 2.1 + */ + public String getEventType() { + return fEventType; + } + + /** + * @param eventType + * the eventType to set, or null + * @since 2.1 + */ + public void setEventType(String eventType) { + fEventType = eventType; + } + /** * @return the inputAction */ diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java index 1ac4a245cf..cca70ea65a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java @@ -517,6 +517,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl } private void parseElement(final Element element, final CustomXmlEvent event, final CustomXmlInputElement inputElement) { + String eventType = inputElement.getEventType(); + if (eventType != null && event.getType() instanceof CustomEventType) { + ((CustomEventType) event.getType()).setName(eventType); + } if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat()); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java index d95783237a..2f3496f54a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java @@ -106,6 +106,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { 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 EVENT_TYPE_ATTRIBUTE = Messages.CustomXmlTraceDefinition_eventType; private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomXmlTraceDefinition_timestampOutputFormat; private static final String INPUT_ELEMENT_ELEMENT = Messages.CustomXmlTraceDefinition_inputElement; private static final String ATTRIBUTE_ELEMENT = Messages.CustomXmlTraceDefinition_attribute; @@ -233,6 +234,10 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { inputElementElement.setAttribute(LOG_ENTRY_ATTRIBUTE, Boolean.toString(inputElement.isLogEntry())); } + if (inputElement.getEventType() != null) { + inputElementElement.setAttribute(EVENT_TYPE_ATTRIBUTE, inputElement.getEventType()); + } + if (inputElement.getParentElement() != null) { Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); inputElementElement.appendChild(inputDataElement); @@ -532,6 +537,8 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { CustomXmlInputElement inputElement = new CustomXmlInputElement(); inputElement.setElementName(inputElementElement.getAttribute(NAME_ATTRIBUTE)); inputElement.setLogEntry((Boolean.toString(true).equals(inputElementElement.getAttribute(LOG_ENTRY_ATTRIBUTE))) ? true : false); + String eventType = inputElementElement.getAttribute(EVENT_TYPE_ATTRIBUTE); + inputElement.setEventType(eventType.isEmpty() ? null : eventType); NodeList nodeList = inputElementElement.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/Messages.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/Messages.java index 282862bfe7..ec9b0a3fac 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/Messages.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/Messages.java @@ -31,6 +31,8 @@ public class Messages extends NLS { public static String CustomTxtTraceDefinition_category; public static String CustomTxtTraceDefinition_definition; public static String CustomTxtTraceDefinition_definitionRootElement; + /** @since 2.1 */ + public static String CustomTxtTraceDefinition_eventType; public static String CustomTxtTraceDefinition_format; public static String CustomTxtTraceDefinition_inputData; public static String CustomTxtTraceDefinition_inputLine; @@ -45,6 +47,8 @@ public class Messages extends NLS { public static String CustomXmlTraceDefinition_category; public static String CustomXmlTraceDefinition_definition; public static String CustomXmlTraceDefinition_definitionRootElement; + /** @since 2.1 */ + public static String CustomXmlTraceDefinition_eventType; public static String CustomXmlTraceDefinition_format; public static String CustomXmlTraceDefinition_ignoreTag; public static String CustomXmlTraceDefinition_inputData; diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/messages.properties b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/messages.properties index 996150ebdb..ca8da7d6bd 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/messages.properties +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/messages.properties @@ -21,6 +21,7 @@ CustomTxtTraceDefinition_cardinality=Cardinality CustomTxtTraceDefinition_category=category CustomTxtTraceDefinition_definition=Definition CustomTxtTraceDefinition_definitionRootElement=CustomTxtTraceDefinitionList +CustomTxtTraceDefinition_eventType=EventType CustomTxtTraceDefinition_format=format CustomTxtTraceDefinition_inputData=InputData CustomTxtTraceDefinition_inputLine=InputLine @@ -35,6 +36,7 @@ CustomXmlTraceDefinition_attribute=Attribute CustomXmlTraceDefinition_category=category CustomXmlTraceDefinition_definition=Definition CustomXmlTraceDefinition_definitionRootElement=CustomXMLTraceDefinitionList +CustomXmlTraceDefinition_eventType=eventtype CustomXmlTraceDefinition_format=format CustomXmlTraceDefinition_ignoreTag=Ignore CustomXmlTraceDefinition_inputData=InputData diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java index ee43e12fb2..7bae0aa043 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java @@ -184,6 +184,7 @@ public class Messages extends NLS { public static String CustomTxtParserInputWizardPage_category; public static String CustomTxtParserInputWizardPage_desccriptionEdit; public static String CustomTxtParserInputWizardPage_descriptionNew; + public static String CustomTxtParserInputWizardPage_eventType; public static String CustomTxtParserInputWizardPage_format; public static String CustomTxtParserInputWizardPage_group; public static String CustomTxtParserInputWizardPage_highlightAll; @@ -223,6 +224,7 @@ public class Messages extends NLS { public static String CustomTxtParserOutputWizardPage_moveBefore; public static String CustomTxtParserOutputWizardPage_visible; public static String CustomXmlParserInputWizardPage_emptyCategoryError; + public static String CustomXmlParserInputWizardPage_emptyEventTypeError; public static String CustomXmlParserInputWizardPage_emptyLogTypeError; public static String CustomXmlParserInputWizardPage_invalidCategoryError; public static String CustomXmlParserInputWizardPage_invalidLogTypeError; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties index acd5432b20..1b784a930b 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2013, 2015 Ericsson +# Copyright (c) 2013, 2016 Ericsson # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 @@ -184,6 +184,7 @@ CustomTxtParserInputWizardPage_cardinality=Cardinality: CustomTxtParserInputWizardPage_category=Category: CustomTxtParserInputWizardPage_desccriptionEdit=Edit an existing custom parser for text trace files CustomTxtParserInputWizardPage_descriptionNew=Create a new custom parser for text trace files +CustomTxtParserInputWizardPage_eventType=Event type: CustomTxtParserInputWizardPage_format=format: CustomTxtParserInputWizardPage_group=Group {0}: CustomTxtParserInputWizardPage_highlightAll=Highlight All @@ -223,6 +224,7 @@ CustomTxtParserOutputWizardPage_moveAfter=Move After CustomTxtParserOutputWizardPage_moveBefore=Move Before CustomTxtParserOutputWizardPage_visible=Visible CustomXmlParserInputWizardPage_emptyCategoryError=Enter a category for the new trace type. +CustomXmlParserInputWizardPage_emptyEventTypeError=Enter the event type for the element (Element {0}). CustomXmlParserInputWizardPage_emptyLogTypeError=Enter a name for the new trace type. CustomXmlParserInputWizardPage_invalidCategoryError=Invalid character ':' in category. CustomXmlParserInputWizardPage_invalidLogTypeError=Invalid character ':' in trace type. diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java index 44b3b2914f..1d8284ceb8 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java @@ -1051,6 +1051,8 @@ public class CustomTxtParserInputWizardPage extends WizardPage { private Label cardinalityMaxLabel; private Text cardinalityMaxText; private Button infiniteButton; + private Button eventTypeButton; + private Text eventTypeText; private List inputs = new ArrayList<>(); private Button addGroupButton; private Label addGroupLabel; @@ -1224,6 +1226,35 @@ public class CustomTxtParserInputWizardPage extends WizardPage { cardinalityMinText.addVerifyListener(digitsListener); cardinalityMaxText.addVerifyListener(digitsListener); + eventTypeButton = new Button(group, SWT.CHECK); + eventTypeButton.setText(Messages.CustomTxtParserInputWizardPage_eventType); + eventTypeButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + eventTypeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (eventTypeButton.getSelection()) { + eventTypeText.setEnabled(true); + } else { + eventTypeText.setEnabled(false); + } + } + }); + eventTypeButton.addSelectionListener(updateListener); + + eventTypeText = new Text(group, SWT.BORDER | SWT.SINGLE); + gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd.widthHint = 0; + eventTypeText.setLayoutData(gd); + if (inputLine.eventType != null) { + eventTypeText.setText(inputLine.eventType); + eventTypeButton.setSelection(true); + } else { + eventTypeText.setEnabled(false); + eventTypeButton.setSelection(false); + } + eventTypeText.addModifyListener(updateListener); + + if (inputLine.columns != null) { for (InputData inputData : inputLine.columns) { InputGroup inputGroup = new InputGroup(group, this, inputs.size() + 1); @@ -1301,6 +1332,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage { private void extractInputs() { inputLine.setRegex(selectedLine.regexText.getText()); + inputLine.eventType = selectedLine.eventTypeButton.getSelection() ? selectedLine.eventTypeText.getText().trim() : null; switch (cardinalityCombo.getSelectionIndex()) { case 0: inputLine.cardinality = Cardinality.ZERO_OR_MORE; @@ -1624,6 +1656,16 @@ public class CustomTxtParserInputWizardPage extends WizardPage { line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND); } } + if (inputLine.eventType != null && inputLine.eventType.trim().isEmpty()) { + errors.append("Enter the event type (Line " + name + "). "); //$NON-NLS-1$ //$NON-NLS-2$ + if (line != null) { + line.eventTypeText.setBackground(COLOR_LIGHT_RED); + } + } else { + if (line != null) { + line.eventTypeText.setBackground(COLOR_TEXT_BACKGROUND); + } + } for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) { InputData inputData = inputLine.columns.get(i); InputGroup group = null; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java index bd6ff9c02d..d430d865f8 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java @@ -872,6 +872,8 @@ public class CustomXmlParserInputWizardPage extends WizardPage { private Label previewLabel; private Text previewText; private Button logEntryButton; + private Button eventTypeButton; + private Text eventTypeText; private Label fillerLabel; private Composite addAttributeComposite; private Button addAttributeButton; @@ -1032,6 +1034,34 @@ public class CustomXmlParserInputWizardPage extends WizardPage { tagText.setText(inputElement.getInputName()); tagText.addModifyListener(updateListener); } + + eventTypeButton = new Button(group, SWT.CHECK); + eventTypeButton.setText(Messages.CustomTxtParserInputWizardPage_eventType); + eventTypeButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + eventTypeButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if (eventTypeButton.getSelection()) { + eventTypeText.setEnabled(true); + } else { + eventTypeText.setEnabled(false); + } + } + }); + eventTypeButton.addSelectionListener(updateListener); + + eventTypeText = new Text(group, SWT.BORDER | SWT.SINGLE); + gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd.widthHint = 0; + eventTypeText.setLayoutData(gd); + if (inputElement.getEventType() != null) { + eventTypeText.setText(inputElement.getEventType()); + eventTypeButton.setSelection(true); + } else { + eventTypeText.setEnabled(false); + eventTypeButton.setSelection(false); + } + eventTypeText.addModifyListener(updateListener); } if (inputElement.getAttributes() != null) { @@ -1191,6 +1221,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { inputElement.setElementName(elementNameText.getText().trim()); if (inputElement.getParentElement() != null) { inputElement.setLogEntry(logEntryButton.getSelection()); + inputElement.setEventType(eventTypeButton.getSelection() ? eventTypeText.getText().trim() : null); if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { inputElement.setInputName(tagText.getText().trim()); } else { @@ -1634,6 +1665,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage { elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); } } + if (inputElement.getEventType() != null && inputElement.getEventType().trim().isEmpty()) { + errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_emptyEventTypeError, getName(inputElement))); + if (elementNode != null) { + elementNode.eventTypeText.setBackground(COLOR_LIGHT_RED); + } + } else { + if (elementNode != null) { + elementNode.eventTypeText.setBackground(COLOR_TEXT_BACKGROUND); + } + } } if (inputElement.getAttributes() != null) { if (elementNode != null) {