From f5cc6ed1674964d61cbbbec7a934e318d5cae45d Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Wed, 29 Jun 2016 16:58:08 -0400 Subject: [PATCH] tmf: Bug 497038: Custom parser field names conflict with built-in tags A new Tag enum is added as part of the custom parser definition model. The 'tag' attribute is added to the XML definition. For backward compatibility if the 'tag' attribute is not present when loading a definition from XML, the Tag is determined from the 'name' attribute. In the internal payload data map of the custom event, the map's key is changed from a String to an Object that can either be the Tag, a String, or an enum constant, to ensure there is no conflict of keys. If the tag is OTHER, the wizards should ensure that the user-entered name does not conflict with one of the built-in tag labels. Change-Id: If9bf65fb32d646cda4f24f28bf41941f1f5c85f6 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/76257 Reviewed-by: Hudson CI --- .../testfiles/txt/testTxtDefinition.xml | 20 +-- .../testfiles/xml/testDefinition.xml | 16 +- .../tmf/core/parsers/custom/CustomEvent.java | 31 +++- .../parsers/custom/CustomTraceDefinition.java | 148 ++++++++++++++++-- .../core/parsers/custom/CustomTxtEvent.java | 39 ++--- .../custom/CustomTxtTraceDefinition.java | 33 +++- .../core/parsers/custom/CustomXmlEvent.java | 51 ++++-- .../custom/CustomXmlInputAttribute.java | 44 +++++- .../parsers/custom/CustomXmlInputElement.java | 61 +++++++- .../core/parsers/custom/CustomXmlTrace.java | 7 +- .../custom/CustomXmlTraceDefinition.java | 40 +++-- .../tmf/core/parsers/custom/Messages.java | 4 + .../core/parsers/custom/messages.properties | 2 + .../parsers/custom/TestCustomTxtWizard.java | 32 ++-- .../parsers/custom/TestCustomXmlWizard.java | 10 +- .../internal/tmf/ui/Messages.java | 2 + .../internal/tmf/ui/messages.properties | 2 + .../CustomTxtParserInputWizardPage.java | 115 ++++++++------ .../CustomTxtParserOutputWizardPage.java | 39 +++-- .../CustomXmlParserInputWizardPage.java | 117 ++++++++------ .../CustomXmlParserOutputWizardPage.java | 39 +++-- 21 files changed, 597 insertions(+), 255 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml b/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml index 25de005918..c21f6da13e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml +++ b/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml @@ -5,31 +5,31 @@ (\S*\s\S*) (.*\S) - - + + (.*\S) - + - - + + dd/MM/yyyy HH:mm:ss:SSS (\d*) (.*\S) - - + + (.*\S) - + - - + + diff --git a/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml b/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml index f2ac3a6e53..3eddce1677 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml +++ b/tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml @@ -4,26 +4,26 @@ HH:mm:ss:SSS - + - + - - + + HH:mm:ss:SSS - + - + - - + + diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java index e0e41ef6a2..ef57420953 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.java @@ -24,6 +24,7 @@ import org.eclipse.tracecompass.tmf.core.event.TmfEvent; import org.eclipse.tracecompass.tmf.core.event.TmfEventField; import org.eclipse.tracecompass.tmf.core.event.TmfEventType; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat; @@ -37,7 +38,16 @@ import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; */ public class CustomEvent extends TmfEvent { - /** Input format key */ + /** Payload data map key + * @since 2.1*/ + protected enum Key { + /** Timestamp input format */ + TIMESTAMP_INPUT_FORMAT + } + + /** Input format key + * @deprecated Use {@link Key#TIMESTAMP_INPUT_FORMAT} instead. */ + @Deprecated protected static final String TIMESTAMP_INPUT_FORMAT_KEY = "CE_TS_I_F"; //$NON-NLS-1$ /** Empty message */ @@ -55,8 +65,12 @@ public class CustomEvent extends TmfEvent { /** The trace to which this event belongs */ protected CustomTraceDefinition fDefinition; - /** The payload data of this event, */ - protected Map fData; + /** + * The payload data of this event, where the key is one of: the {@link Tag}, + * the field name string if the tag is {@link Tag#OTHER}, or + * {@link Key#TIMESTAMP_INPUT_FORMAT}. + */ + protected Map fData; private TmfEventField[] fColumnData; @@ -224,8 +238,8 @@ public class CustomEvent extends TmfEvent { } private void processData() { - String timestampString = fData.get(CustomTraceDefinition.TAG_TIMESTAMP); - String timestampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); + String timestampString = fData.get(Tag.TIMESTAMP); + String timestampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); ITmfTimestamp timestamp = null; if (timestampInputFormat != null && timestampString != null) { TmfTimestampFormat timestampFormat = new TmfTimestampFormat(timestampInputFormat); @@ -241,7 +255,7 @@ public class CustomEvent extends TmfEvent { } // Update the custom event type of this event if set - String eventName = fData.get(CustomTraceDefinition.TAG_EVENT_TYPE); + String eventName = fData.get(Tag.EVENT_TYPE); ITmfEventType type = getType(); if (eventName != null && type instanceof CustomEventType) { ((CustomEventType) type).setName(eventName); @@ -250,8 +264,9 @@ public class CustomEvent extends TmfEvent { int i = 0; fColumnData = new TmfEventField[fDefinition.outputs.size()]; for (OutputColumn outputColumn : fDefinition.outputs) { - String value = fData.get(outputColumn.name); - if (outputColumn.name.equals(CustomTraceDefinition.TAG_TIMESTAMP) && timestamp != null) { + Object key = (outputColumn.tag.equals(Tag.OTHER) ? outputColumn.name : outputColumn.tag); + String value = fData.get(key); + if (outputColumn.tag.equals(Tag.TIMESTAMP) && timestamp != null) { TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat); fColumnData[i++] = new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null); } else { diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTraceDefinition.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTraceDefinition.java index d2b9935b59..7146927770 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTraceDefinition.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTraceDefinition.java @@ -12,12 +12,18 @@ package org.eclipse.tracecompass.tmf.core.parsers.custom; +import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; + import java.io.ByteArrayInputStream; import java.text.SimpleDateFormat; +import java.util.AbstractMap.SimpleEntry; import java.util.List; +import java.util.Map.Entry; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; +import org.w3c.dom.Element; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; @@ -40,19 +46,82 @@ public abstract class CustomTraceDefinition { /** "append with separator" action */ public static final int ACTION_APPEND_WITH_SEPARATOR = 2; - /** Timestamp tag */ + /** + * Input tag + * + * @since 2.1 + */ + public enum Tag { + /** Ignore */ + IGNORE(Messages.CustomXmlTraceDefinition_ignoreTag), + /** Timestamp */ + TIMESTAMP(TmfBaseAspects.getTimestampAspect().getName()), + /** Event type */ + EVENT_TYPE(TmfBaseAspects.getEventTypeAspect().getName()), + /** Message */ + MESSAGE(Messages.CustomTraceDefinition_messageTag), + /** Other */ + OTHER(Messages.CustomTraceDefinition_otherTag); + + private final String fLabel; + + private Tag(String label) { + fLabel = label; + } + + @Override + public String toString() { + return fLabel; + } + + /** + * Get a tag from its label (toString). + * + * @param label + * the label + * @return the corresponding tag, or null + */ + public static Tag fromLabel(String label) { + for (Tag tag : Tag.values()) { + if (tag.toString().equals(label)) { + return tag; + } + } + return null; + } + + /** + * Get a tag from its name (identifier). + * + * @param name + * the name + * @return the corresponding tag, or null + */ + public static Tag fromName(String name) { + for (Tag tag : Tag.values()) { + if (tag.name().equals(name)) { + return tag; + } + } + return null; + } + } + + /** Timestamp tag + * @deprecated Use {@link Tag#TIMESTAMP} instead. */ + @Deprecated public static final String TAG_TIMESTAMP = Messages.CustomTraceDefinition_timestampTag; - /** Message tag */ + /** Message tag + * @deprecated Use {@link Tag#MESSAGE} instead. */ + @Deprecated public static final String TAG_MESSAGE = Messages.CustomTraceDefinition_messageTag; - /** "Other" tag */ + /** "Other" tag + * @deprecated Use {@link Tag#OTHER} instead. */ + @Deprecated public static final String TAG_OTHER = Messages.CustomTraceDefinition_otherTag; - /** Event type tag - * @since 2.1*/ - public static final String TAG_EVENT_TYPE = Messages.CustomTraceDefinition_eventTypeTag; - /** Category of this trace definition */ public String categoryName; @@ -70,22 +139,48 @@ public abstract class CustomTraceDefinition { */ public static class OutputColumn { + /** Tag of this input + * @since 2.1*/ + public @NonNull Tag tag; + /** Name of this column */ public @NonNull String name; /** * Default constructor (empty) + * @deprecated Use {@link OutputColumn#OutputColumn(Tag, String)} + * instead. */ + @Deprecated public OutputColumn() { - this(""); //$NON-NLS-1$ + this(Tag.IGNORE, ""); //$NON-NLS-1$ } /** * Constructor * - * @param name Name of this output column + * @param name + * Name of this output column + * @deprecated Use {@link OutputColumn#OutputColumn(Tag, String)} + * instead. */ + @Deprecated public OutputColumn(@NonNull String name) { + this.tag = Tag.OTHER; + this.name = name; + } + + /** + * Constructor + * + * @param tag + * Tag of this output column + * @param name + * Name of this output column + * @since 2.1 + */ + public OutputColumn(@NonNull Tag tag, @NonNull String name) { + this.tag = tag; this.name = name; } @@ -157,4 +252,39 @@ public abstract class CustomTraceDefinition { } }; } + + /** + * Extract the tag and name from an XML element + * + * @param element + * the XML element + * @param tagAttribute + * the tag attribute + * @param nameAttribute + * the name attribute + * @return an entry where the key is the tag and the value is the name + * @since 2.1 + */ + protected static Entry<@NonNull Tag, @NonNull String> extractTagAndName(Element element, String tagAttribute, String nameAttribute) { + Tag tag = Tag.fromName(element.getAttribute(tagAttribute)); + String name = element.getAttribute(nameAttribute); + if (tag == null) { + // Backward compatibility + if (name.equals(Messages.CustomTraceDefinition_timestampTag)) { + tag = Tag.TIMESTAMP; + name = checkNotNull(Tag.TIMESTAMP.toString()); + } else if (name.equals(Messages.CustomTraceDefinition_messageTag)) { + tag = Tag.MESSAGE; + name = checkNotNull(Tag.MESSAGE.toString()); + } else if (name.equals(Messages.CustomXmlTraceDefinition_ignoreTag)) { + tag = Tag.IGNORE; + name = checkNotNull(Tag.IGNORE.toString()); + } else { + tag = Tag.OTHER; + } + } else if (name.isEmpty()) { + name = checkNotNull(tag.toString()); + } + return new SimpleEntry<>(tag, name); + } } 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 d555f20288..4ea2fd5376 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 @@ -18,6 +18,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.event.TmfEvent; import org.eclipse.tracecompass.tmf.core.event.TmfEventType; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputLine; import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; @@ -84,7 +85,7 @@ public class CustomTxtEvent extends CustomEvent { */ public void processGroups(InputLine input, Matcher matcher) { if (input.eventType != null) { - fData.put(CustomTraceDefinition.TAG_EVENT_TYPE, input.eventType); + fData.put(Tag.EVENT_TYPE, input.eventType); } if (input.columns == null) { return; @@ -96,40 +97,40 @@ public class CustomTxtEvent extends CustomEvent { if (value.length() == 0) { continue; } - String name = column.name; + Object key = (column.tag.equals(Tag.OTHER) ? column.name : column.tag); if (column.action == CustomTraceDefinition.ACTION_SET) { - fData.put(name, value); - if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); + fData.put(key, value); + if (key.equals(Tag.TIMESTAMP)) { + fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format); } } else if (column.action == CustomTraceDefinition.ACTION_APPEND) { - String s = fData.get(name); + String s = fData.get(key); if (s != null) { - fData.put(name, s + value); + fData.put(key, s + value); } else { - fData.put(name, value); + fData.put(key, value); } - if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); + if (key.equals(Tag.TIMESTAMP)) { + String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); if (timeStampInputFormat != null) { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + column.format); + fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + column.format); } else { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); + fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format); } } } else if (column.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { - String s = fData.get(name); + String s = fData.get(key); if (s != null) { - fData.put(name, s + " | " + value); //$NON-NLS-1$ + fData.put(key, s + " | " + value); //$NON-NLS-1$ } else { - fData.put(name, value); + fData.put(key, value); } - if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); + if (key.equals(Tag.TIMESTAMP)) { + String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); if (timeStampInputFormat != null) { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$ + fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + column.format); //$NON-NLS-1$ } else { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, column.format); + fData.put(Key.TIMESTAMP_INPUT_FORMAT, column.format); } } } 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 f7e3df49fd..4364a23b3e 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 @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; import java.util.regex.Pattern; @@ -41,6 +42,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; import org.w3c.dom.Document; @@ -100,6 +102,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 TAG_ATTRIBUTE = Messages.CustomTxtTraceDefinition_tag; 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; @@ -365,7 +368,11 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { */ public static class InputData { - /** Name of this column */ + /** Tag of this input + * @since 2.1*/ + public Tag tag; + + /** Name of this input for "Other" tag */ public String name; /** Action id */ @@ -408,6 +415,20 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { this.name = name; this.action = action; } + + /** + * Constructor + * + * @param tag + * Tag + * @param action + * Action + * @since 2.1 + */ + public InputData(Tag tag, int action) { + this.tag = tag; + this.action = action; + } } /** @@ -532,6 +553,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { for (OutputColumn output : outputs) { Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT); definitionElement.appendChild(outputColumnElement); + outputColumnElement.setAttribute(TAG_ATTRIBUTE, output.tag.name()); outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name); } } @@ -578,6 +600,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { for (InputData inputData : inputLine.columns) { Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); inputLineElement.appendChild(inputDataElement); + inputDataElement.setAttribute(TAG_ATTRIBUTE, inputData.tag.name()); inputDataElement.setAttribute(NAME_ATTRIBUTE, inputData.name); inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputData.action)); if (inputData.format != null) { @@ -811,8 +834,8 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { } } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) { Element outputColumnElement = (Element) node; - OutputColumn outputColumn = new OutputColumn(); - outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE); + Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(outputColumnElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE); + OutputColumn outputColumn = new OutputColumn(entry.getKey(), entry.getValue()); def.outputs.add(outputColumn); } } @@ -843,7 +866,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { } else if (nodeName.equals(INPUT_DATA_ELEMENT)) { Element inputDataElement = (Element) node; InputData inputData = new InputData(); - inputData.name = inputDataElement.getAttribute(NAME_ATTRIBUTE); + Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE); + inputData.tag = checkNotNull(entry.getKey()); + inputData.name = checkNotNull(entry.getValue()); inputData.action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)); inputData.format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE); inputLine.addColumn(inputData); diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlEvent.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlEvent.java index ba862b5484..3322554f3e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlEvent.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlEvent.java @@ -16,6 +16,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.event.TmfEvent; import org.eclipse.tracecompass.tmf.core.event.TmfEventType; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; @@ -77,44 +78,60 @@ public class CustomXmlEvent extends CustomEvent { * @param name Name * @param inputAction Input action * @param inputFormat Input format + * @deprecated Use {@link #parseInput(String, Tag, String, int, String)} instead. */ + @Deprecated public void parseInput(String value, String name, int inputAction, String inputFormat) { + } + + /** + * Parse an entry. + * + * @param value Value + * @param inputTag Input tag + * @param inputName Input name + * @param inputAction Input action + * @param inputFormat Input format + * @since 2.1 + */ + public void parseInput(String value, Tag inputTag, String inputName, int inputAction, String inputFormat) { if (value.length() == 0) { return; } + Object key = (inputTag.equals(Tag.OTHER) ? inputName : inputTag); if (inputAction == CustomTraceDefinition.ACTION_SET) { - fData.put(name, value); - if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); + fData.put(key, value); + if (key.equals(Tag.TIMESTAMP)) { + fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); } } else if (inputAction == CustomTraceDefinition.ACTION_APPEND) { - String s = fData.get(name); + String s = fData.get(key); if (s != null) { - fData.put(name, s + value); + fData.put(key, s + value); } else { - fData.put(name, value); + fData.put(key, value); } - if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); + if (key.equals(Tag.TIMESTAMP)) { + String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); if (timeStampInputFormat != null) { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + inputFormat); + fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + inputFormat); } else { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); + fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); } } } else if (inputAction == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { - String s = fData.get(name); + String s = fData.get(key); if (s != null) { - fData.put(name, s + " | " + value); //$NON-NLS-1$ + fData.put(key, s + " | " + value); //$NON-NLS-1$ } else { - fData.put(name, value); + fData.put(key, value); } - if (name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { - String timeStampInputFormat = fData.get(TIMESTAMP_INPUT_FORMAT_KEY); + if (key.equals(Tag.TIMESTAMP)) { + String timeStampInputFormat = fData.get(Key.TIMESTAMP_INPUT_FORMAT); if (timeStampInputFormat != null) { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ + fData.put(Key.TIMESTAMP_INPUT_FORMAT, timeStampInputFormat + " | " + inputFormat); //$NON-NLS-1$ } else { - fData.put(TIMESTAMP_INPUT_FORMAT_KEY, inputFormat); + fData.put(Key.TIMESTAMP_INPUT_FORMAT, inputFormat); } } } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java index 5040c3df3b..5bbb8848a8 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.tracecompass.tmf.core.parsers.custom; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; + /** * Wrapper for XML element attributes */ @@ -20,6 +22,9 @@ public final class CustomXmlInputAttribute { /** Name of the XML attribute */ private final String fAttributeName; + /** Input tag */ + private final Tag fInputTag; + /** Input name */ private final String fInputName; @@ -40,10 +45,39 @@ public final class CustomXmlInputAttribute { * Input action * @param inputFormat * Input format + * @deprecated Use + * {@link #CustomXmlInputAttribute(String, Tag, String, int, String)} + * instead. */ + @Deprecated public CustomXmlInputAttribute(String attributeName, String inputName, int inputAction, String inputFormat) { fAttributeName = attributeName; + fInputTag = Tag.IGNORE; + fInputName = inputName; + fInputAction = inputAction; + fInputFormat = inputFormat; + } + + /** + * Constructor + * + * @param attributeName + * Name of the XML attribute + * @param inputTag + * Input tag + * @param inputName + * Input name + * @param inputAction + * Input action + * @param inputFormat + * Input format + * @since 2.1 + */ + public CustomXmlInputAttribute(String attributeName, Tag inputTag, + String inputName, int inputAction, String inputFormat) { + fAttributeName = attributeName; + fInputTag = inputTag; fInputName = inputName; fInputAction = inputAction; fInputFormat = inputFormat; @@ -56,6 +90,14 @@ public final class CustomXmlInputAttribute { return fAttributeName; } + /** + * @return the inputTag + * @since 2.1 + */ + public Tag getInputTag() { + return fInputTag; + } + /** * @return the inputName */ 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 75d4b82c7d..2092101338 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Ericsson + * Copyright (c) 2014, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -16,6 +16,8 @@ package org.eclipse.tracecompass.tmf.core.parsers.custom; import java.util.ArrayList; import java.util.List; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; + /** * Wrapper for input XML elements */ @@ -27,6 +29,9 @@ public final class CustomXmlInputElement { /** Indicates if this is a log entry */ private boolean fLogEntry; + /** Tag of the input element */ + private Tag fInputTag; + /** Name of the input element */ private String fInputName; @@ -65,14 +70,18 @@ public final class CustomXmlInputElement { * @param logEntry * If this element is a log entry * @param inputName - * Name of the the input + * Name of the input * @param inputAction * Input action * @param inputFormat * Input format * @param attributes * XML attributes of this element + * @deprecated Use + * {@link #CustomXmlInputElement(String, boolean, Tag, String, int, String, List)} + * instead. */ + @Deprecated public CustomXmlInputElement(String elementName, boolean logEntry, String inputName, int inputAction, String inputFormat, List attributes) { @@ -84,6 +93,37 @@ public final class CustomXmlInputElement { fAttributes = attributes; } + /** + * Constructor + * + * @param elementName + * Element name + * @param logEntry + * If this element is a log entry + * @param inputTag + * Tag of the input + * @param inputName + * Name of the input + * @param inputAction + * Input action + * @param inputFormat + * Input format + * @param attributes + * XML attributes of this element + * @since 2.1 + */ + public CustomXmlInputElement(String elementName, boolean logEntry, Tag inputTag, + String inputName, int inputAction, String inputFormat, + List attributes) { + fElementName = elementName; + fLogEntry = logEntry; + fInputTag = inputTag; + fInputName = inputName; + fInputAction = inputAction; + fInputFormat = inputFormat; + fAttributes = attributes; + } + /** * Add a XML attribute to the element * @@ -193,6 +233,23 @@ public final class CustomXmlInputElement { fLogEntry = logEntry; } + /** + * @return the inputTag + * @since 2.1 + */ + public Tag getInputTag() { + return fInputTag; + } + + /** + * @param inputTag + * the inputTag to set + * @since 2.1 + */ + public void setInputTag(Tag inputTag) { + fInputTag = inputTag; + } + /** * @return the inputName */ 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 cca70ea65a..e562fd880e 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 @@ -37,6 +37,7 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; import org.eclipse.tracecompass.tmf.core.signal.TmfTraceRangeUpdatedSignal; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; @@ -521,12 +522,12 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl 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()); + if (!inputElement.getInputTag().equals(Tag.IGNORE)) { + event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputTag(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat()); } if (inputElement.getAttributes() != null) { for (final CustomXmlInputAttribute attribute : inputElement.getAttributes()) { - event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat()); + event.parseInput(element.getAttribute(attribute.getAttributeName()), attribute.getInputTag(), attribute.getInputName(), attribute.getInputAction(), attribute.getInputFormat()); } } final NodeList childNodes = element.getChildNodes(); 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 2f3496f54a..6fc26120c8 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 @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; +import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; @@ -39,6 +40,7 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.internal.tmf.core.Activator; import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType; import org.w3c.dom.Document; @@ -58,7 +60,9 @@ import org.xml.sax.SAXParseException; */ public class CustomXmlTraceDefinition extends CustomTraceDefinition { - /** "ignore" tag */ + /** Ignore tag + * @deprecated Use {@link Tag#IGNORE} instead. */ + @Deprecated public static final String TAG_IGNORE = Messages.CustomXmlTraceDefinition_ignoreTag; /** @@ -104,6 +108,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { 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 TAG_ATTRIBUTE = Messages.CustomXmlTraceDefinition_tag; 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; @@ -202,6 +207,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { for (OutputColumn output : outputs) { Element outputColumnElement = doc.createElement(OUTPUT_COLUMN_ELEMENT); definitionElement.appendChild(outputColumnElement); + outputColumnElement.setAttribute(TAG_ATTRIBUTE, output.tag.name()); outputColumnElement.setAttribute(NAME_ATTRIBUTE, output.name); } } @@ -241,10 +247,12 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { if (inputElement.getParentElement() != null) { Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); inputElementElement.appendChild(inputDataElement); + inputDataElement.setAttribute(TAG_ATTRIBUTE, inputElement.getInputTag().name()); inputDataElement.setAttribute(NAME_ATTRIBUTE, inputElement.getInputName()); inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(inputElement.getInputAction())); - if (inputElement.getInputFormat() != null) { - inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputElement.getInputFormat()); + String inputFormat = inputElement.getInputFormat(); + if (inputFormat != null && !inputFormat.isEmpty()) { + inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputFormat); } } @@ -255,10 +263,12 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { inputAttributeElement.setAttribute(NAME_ATTRIBUTE, attribute.getAttributeName()); Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT); inputAttributeElement.appendChild(inputDataElement); + inputDataElement.setAttribute(TAG_ATTRIBUTE, attribute.getInputTag().name()); inputDataElement.setAttribute(NAME_ATTRIBUTE, attribute.getInputName()); inputDataElement.setAttribute(ACTION_ATTRIBUTE, Integer.toString(attribute.getInputAction())); - if (attribute.getInputFormat() != null) { - inputDataElement.setAttribute(FORMAT_ATTRIBUTE, attribute.getInputFormat()); + String inputFormat = attribute.getInputFormat(); + if (inputFormat != null && !inputFormat.isEmpty()) { + inputDataElement.setAttribute(FORMAT_ATTRIBUTE, inputFormat); } } } @@ -525,8 +535,8 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { } } else if (nodeName.equals(OUTPUT_COLUMN_ELEMENT)) { Element outputColumnElement = (Element) node; - OutputColumn outputColumn = new OutputColumn(); - outputColumn.name = outputColumnElement.getAttribute(NAME_ATTRIBUTE); + Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(outputColumnElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE); + OutputColumn outputColumn = new OutputColumn(entry.getKey(), entry.getValue()); def.outputs.add(outputColumn); } } @@ -545,28 +555,28 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { String nodeName = node.getNodeName(); if (nodeName.equals(INPUT_DATA_ELEMENT)) { Element inputDataElement = (Element) node; - inputElement.setInputName(inputDataElement.getAttribute(NAME_ATTRIBUTE)); + Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE); + inputElement.setInputTag(entry.getKey()); + inputElement.setInputName(entry.getValue()); inputElement.setInputAction(Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE))); inputElement.setInputFormat(inputDataElement.getAttribute(FORMAT_ATTRIBUTE)); } else if (nodeName.equals(ATTRIBUTE_ELEMENT)) { Element attributeElement = (Element) node; String attributeName = attributeElement.getAttribute(NAME_ATTRIBUTE); - String inputName = null; - int inputAction = 0; - String inputFormat = null; NodeList attributeNodeList = attributeElement.getChildNodes(); for (int j = 0; j < attributeNodeList.getLength(); j++) { Node attributeNode = attributeNodeList.item(j); String attributeNodeName = attributeNode.getNodeName(); if (attributeNodeName.equals(INPUT_DATA_ELEMENT)) { Element inputDataElement = (Element) attributeNode; - inputName = inputDataElement.getAttribute(NAME_ATTRIBUTE); - inputAction = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)); - inputFormat = inputDataElement.getAttribute(FORMAT_ATTRIBUTE); + Entry<@NonNull Tag, @NonNull String> entry = extractTagAndName(inputDataElement, TAG_ATTRIBUTE, NAME_ATTRIBUTE); + int action = Integer.parseInt(inputDataElement.getAttribute(ACTION_ATTRIBUTE)); + String format = inputDataElement.getAttribute(FORMAT_ATTRIBUTE); + inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, entry.getKey(), entry.getValue(), action, format)); + break; } } - inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat)); } else if (nodeName.equals(INPUT_ELEMENT_ELEMENT)) { Element childInputElementElement = (Element) node; CustomXmlInputElement childInputElement = extractInputElement(childInputElementElement); 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 ec9b0a3fac..494a952601 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 @@ -41,6 +41,8 @@ public class Messages extends NLS { public static String CustomTxtTraceDefinition_name; public static String CustomTxtTraceDefinition_outputColumn; public static String CustomTxtTraceDefinition_regEx; + /** @since 2.1 */ + public static String CustomTxtTraceDefinition_tag; public static String CustomTxtTraceDefinition_timestampOutputFormat; public static String CustomXmlTraceDefinition_action; public static String CustomXmlTraceDefinition_attribute; @@ -56,6 +58,8 @@ public class Messages extends NLS { public static String CustomXmlTraceDefinition_logEntry; public static String CustomXmlTraceDefinition_name; public static String CustomXmlTraceDefinition_outputColumn; + /** @since 2.1 */ + public static String CustomXmlTraceDefinition_tag; public static String CustomXmlTraceDefinition_timestampOutputFormat; static { 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 ca8da7d6bd..5820a30845 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 @@ -30,6 +30,7 @@ CustomTxtTraceDefinition_min=min CustomTxtTraceDefinition_name=name CustomTxtTraceDefinition_outputColumn=OutputColumn CustomTxtTraceDefinition_regEx=RegEx +CustomTxtTraceDefinition_tag=tag CustomTxtTraceDefinition_timestampOutputFormat=TimeStampOutputFormat CustomXmlTraceDefinition_action=action CustomXmlTraceDefinition_attribute=Attribute @@ -44,4 +45,5 @@ CustomXmlTraceDefinition_inputElement=InputElement CustomXmlTraceDefinition_logEntry=logentry CustomXmlTraceDefinition_name=name CustomXmlTraceDefinition_outputColumn=OutputColumn +CustomXmlTraceDefinition_tag=tag CustomXmlTraceDefinition_timestampOutputFormat=TimeStampOutputFormat diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomTxtWizard.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomTxtWizard.java index f524162df6..29741d6d0b 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomTxtWizard.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomTxtWizard.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 Ericsson + * Copyright (c) 2014, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -75,16 +75,16 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard { "\n" + "\n" + "\\s*(\\d\\d)\\s(.*\\S)\n" + - "\n" + - "\n" + + "\n" + + "\n" + "\n" + "\n" + "\n" + "([^0-9]*)\n" + - "\n" + + "\n" + "\n" + - "\n" + - "\n"; + "\n" + + "\n"; /** * Test to create a custom txt trace and compare the xml @@ -127,7 +127,7 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard { fBot.textWithLabel("Time Stamp format:").setText("ss"); // Fill Group 1 as time stamp - fBot.comboBox(1).setSelection("Time Stamp"); + fBot.comboBox(1).setSelection("Timestamp"); fBot.textWithLabel("format:").setText("ss"); // Click on the New group button fBot.button(8).click(); @@ -192,22 +192,22 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard { "\n" + "\n" + "\\s*(\\d*)\\s(.*)\n" + - "\n" + - "\n" + + "\n" + + "\n" + "\n" + - "\n" + - "\n" + + "\n" + + "\n" + "\n" + "\n" + "sssssss.ssssss\n" + "\n" + "\n" + "^[([0-9]*\\.[0.9]*)]\\s(.*)\n" + - "\n" + - "\n" + + "\n" + + "\n" + "\n" + - "\n" + - "\n" + + "\n" + + "\n" + "\n" + ""; fw.write(xmlContent); @@ -243,7 +243,7 @@ public class TestCustomTxtWizard extends AbstractCustomParserWizard { fBot.textWithLabel("Time Stamp format:").setText("ss"); // update time stamp format - fBot.comboBox(1).setSelection("Time Stamp"); + fBot.comboBox(1).setSelection("Timestamp"); fBot.textWithLabel("format:").setText("ss"); fBot.button(2).click(); SWTBotTreeItem[] treeItems = fBot.tree().getAllItems(); diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomXmlWizard.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomXmlWizard.java index a48a6a0414..a8f443cebf 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomXmlWizard.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/parsers/custom/TestCustomXmlWizard.java @@ -50,17 +50,17 @@ public class TestCustomXmlWizard extends AbstractCustomParserWizard { "ss\n" + "\n" + "\n" + - "\n" + + "\n" + "\n" + - "\n" + + "\n" + "\n" + "\n" + - "\n" + + "\n" + "\n" + "\n" + "\n" + - "\n" + - "\n"; + "\n" + + "\n"; /** * Test to create a custom XML trace and compare the XML generated 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 0244c82c2c..7aa2c6499b 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 @@ -239,11 +239,13 @@ public class Messages extends NLS { public static String CustomXmlParserInputWizardPage_elementMissingTimestampFmtError; public static String CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError; public static String CustomXmlParserInputWizardPage_elementDuplicateNameError; + public static String CustomXmlParserInputWizardPage_elementReservedInputNameError; public static String CustomXmlParserInputWizardPage_attributeMissingNameError; public static String CustomXmlParserInputWizardPage_attributeMissingInputNameError; public static String CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError; public static String CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError; public static String CustomXmlParserInputWizardPage_attributeDuplicateNameError; + public static String CustomXmlParserInputWizardPage_attributeReservedInputNameError; public static String CustomXmlParserInputWizardPage_addAttribute; public static String CustomXmlParserInputWizardPage_addChildElement; public static String CustomXmlParserInputWizardPage_addDocumentEleemnt; 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 96ccf2059d..736fdf19c2 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 @@ -239,11 +239,13 @@ CustomXmlParserInputWizardPage_elementMissingInputNameError=Enter a name for the CustomXmlParserInputWizardPage_elementMissingTimestampFmtError=Enter the input format for the Time Stamp (Element {0}). CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError=Enter a valid output format for the Time Stamp field (Element {0}). CustomXmlParserInputWizardPage_elementDuplicateNameError=Duplicate element names (Element {0}). +CustomXmlParserInputWizardPage_elementReservedInputNameError=Cannot use reserved name for the input (Element {0}). CustomXmlParserInputWizardPage_attributeMissingNameError=Enter a name for the attribute (Attribute {0}: ?). CustomXmlParserInputWizardPage_attributeMissingInputNameError=Enter a name for the input (Attribute {0}). CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError=Enter the input format for the Time Stamp (Attribute {0}). CustomXmlParserInputWizardPage_attributeInvalidTimestampFmtError=Enter a valid input format for the Time Stamp (Attribute {0}). CustomXmlParserInputWizardPage_attributeDuplicateNameError=Duplicate attribute names (Attribute {0}). +CustomXmlParserInputWizardPage_attributeReservedInputNameError=Cannot use reserved name for the input (Attribute {0}). CustomXmlParserInputWizardPage_addAttribute=Add attribute CustomXmlParserInputWizardPage_addChildElement=Add child element CustomXmlParserInputWizardPage_addDocumentEleemnt=Add document element 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 1d8284ceb8..3b646a44a9 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -19,12 +19,14 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.text.ParseException; +import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -82,6 +84,7 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.internal.tmf.ui.Messages; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.Cardinality; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData; @@ -394,7 +397,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage { if (definition == null) { definition = new CustomTxtTraceDefinition(); definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX, - Arrays.asList(new InputData(CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.ACTION_SET)))); + Arrays.asList(new InputData(Tag.MESSAGE, CustomTraceDefinition.ACTION_SET)))); } loadDefinition(definition); treeViewer.expandAll(); @@ -564,16 +567,16 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } /** - * Get the global list of input names. + * Get the global list of inputs. * - * @return The list of input names + * @return The list of inputs */ - public List getInputNames() { - List inputs = new ArrayList<>(); + public List> getInputs() { + List> inputs = new ArrayList<>(); for (InputLine inputLine : definition.inputs) { - for (String inputName : getInputNames(inputLine)) { - if (!inputs.contains(inputName)) { - inputs.add(inputName); + for (Entry input : getInputs(inputLine)) { + if (!inputs.contains(input)) { + inputs.add(input); } } } @@ -581,27 +584,27 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } /** - * Get the list of input names for the given input line. + * Get the list of inputs for the given input line, recursively. * * @param inputLine * The input line - * @return The list of input names + * @return The list of inputs */ - public List getInputNames(InputLine inputLine) { - List inputs = new ArrayList<>(); + private List> getInputs(InputLine inputLine) { + List> inputs = new ArrayList<>(); if (inputLine.columns != null) { for (InputData inputData : inputLine.columns) { - String inputName = inputData.name; - if (!inputs.contains(inputName)) { - inputs.add(inputName); + Entry input = new SimpleEntry<>(inputData.tag, inputData.name); + if (!inputs.contains(input)) { + inputs.add(input); } } } if (inputLine.childrenInputs != null) { for (InputLine childInputLine : inputLine.childrenInputs) { - for (String inputName : getInputNames(childInputLine)) { - if (!inputs.contains(inputName)) { - inputs.add(inputName); + for (Entry input : getInputs(childInputLine)) { + if (!inputs.contains(input)) { + inputs.add(input); } } } @@ -677,7 +680,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } } - Map data = new HashMap<>(); + Map data = new HashMap<>(); int rootLineMatches = 0; String firstEntryTimeStamp = null; String firstEntryTimeStampInputFormat = null; @@ -709,7 +712,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage { timeStampFormat = null; updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches); if (rootLineMatches == 1) { - firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP); + firstEntryTimeStamp = data.get(Tag.TIMESTAMP); firstEntryTimeStampInputFormat = timeStampFormat; } HashMap countMap = new HashMap<>(); @@ -848,14 +851,14 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } if (rootLineMatches == 1) { - firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP); + firstEntryTimeStamp = data.get(Tag.TIMESTAMP); firstEntryTimeStampInputFormat = timeStampFormat; } if (firstEntryTimeStamp == null) { timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup); if (selectedLine != null) { for (InputGroup group : selectedLine.inputs) { - if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (group.tagCombo.getText().equals(Tag.TIMESTAMP.toString())) { timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp); break; } @@ -877,7 +880,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } } - private void updatePreviewLine(InputLine line, Matcher matcher, Map data, int rawPos, int rootLineMatches) { + private void updatePreviewLine(InputLine line, Matcher matcher, Map data, int rawPos, int rootLineMatches) { for (int i = 0; i < line.columns.size(); i++) { InputData input = line.columns.get(i); if (i < matcher.groupCount() && matcher.group(i + 1) != null) { @@ -896,19 +899,20 @@ public class CustomTxtParserInputWizardPage extends WizardPage { if (value.length() == 0) { continue; } + Object key = (input.tag.equals(Tag.OTHER) ? input.name : input.tag); if (input.action == CustomTraceDefinition.ACTION_SET) { - data.put(input.name, value); - if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + data.put(key, value); + if (input.tag.equals(Tag.TIMESTAMP)) { timeStampFormat = input.format; } } else if (input.action == CustomTraceDefinition.ACTION_APPEND) { - String s = data.get(input.name); + String s = data.get(key); if (s != null) { - data.put(input.name, s + value); + data.put(key, s + value); } else { - data.put(input.name, value); + data.put(key, value); } - if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (input.tag.equals(Tag.TIMESTAMP)) { if (timeStampFormat != null) { timeStampFormat += input.format; } else { @@ -916,13 +920,13 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } } } else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) { - String s = data.get(input.name); + String s = data.get(key); if (s != null) { - data.put(input.name, s + " | " + value); //$NON-NLS-1$ + data.put(key, s + " | " + value); //$NON-NLS-1$ } else { - data.put(input.name, value); + data.put(key, value); } - if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (input.tag.equals(Tag.TIMESTAMP)) { if (timeStampFormat != null) { timeStampFormat += " | " + input.format; //$NON-NLS-1$ } else { @@ -1258,16 +1262,16 @@ public class CustomTxtParserInputWizardPage extends WizardPage { if (inputLine.columns != null) { for (InputData inputData : inputLine.columns) { InputGroup inputGroup = new InputGroup(group, this, inputs.size() + 1); - if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (inputData.tag.equals(Tag.TIMESTAMP)) { inputGroup.tagCombo.select(0); inputGroup.tagText.setText(inputData.format); inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format); inputGroup.tagLabel.setVisible(true); inputGroup.tagText.setVisible(true); inputGroup.tagText.addModifyListener(updateListener); - } else if (inputData.name.equals(CustomTraceDefinition.TAG_EVENT_TYPE)) { + } else if (inputData.tag.equals(Tag.EVENT_TYPE)) { inputGroup.tagCombo.select(1); - } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) { + } else if (inputData.tag.equals(Tag.MESSAGE)) { inputGroup.tagCombo.select(2); } else { inputGroup.tagCombo.select(3); @@ -1373,11 +1377,12 @@ public class CustomTxtParserInputWizardPage extends WizardPage { for (int i = 0; i < inputs.size(); i++) { InputGroup grp = inputs.get(i); InputData inputData = new InputData(); - if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { + inputData.tag = Tag.fromLabel(grp.tagCombo.getText()); + if (inputData.tag.equals(Tag.OTHER)) { inputData.name = grp.tagText.getText().trim(); } else { - inputData.name = grp.tagCombo.getText(); - if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + inputData.name = inputData.tag.toString(); + if (inputData.tag.equals(Tag.TIMESTAMP)) { inputData.format = grp.tagText.getText().trim(); } } @@ -1442,10 +1447,11 @@ public class CustomTxtParserInputWizardPage extends WizardPage { tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); - tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, - CustomTraceDefinition.TAG_EVENT_TYPE, - CustomTraceDefinition.TAG_MESSAGE, - CustomTraceDefinition.TAG_OTHER}); + tagCombo.setItems(new String[] { + Tag.TIMESTAMP.toString(), + Tag.EVENT_TYPE.toString(), + Tag.MESSAGE.toString(), + Tag.OTHER.toString()}); tagCombo.select(2); tagCombo.addSelectionListener(new SelectionListener() { @Override @@ -1672,7 +1678,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage { if (line != null) { group = line.inputs.get(i); } - if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (inputData.tag.equals(Tag.TIMESTAMP)) { timestampFound = true; if (inputData.format.length() == 0) { errors.append("Enter the input format for the Time Stamp (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -1692,10 +1698,21 @@ public class CustomTxtParserInputWizardPage extends WizardPage { } } } - } else if (inputData.name.length() == 0) { - errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (group != null) { - group.tagText.setBackground(COLOR_LIGHT_RED); + } else if (inputData.tag.equals(Tag.OTHER)) { + if (inputData.name.isEmpty()) { + errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (group != null) { + group.tagText.setBackground(COLOR_LIGHT_RED); + } + } else if (Tag.fromLabel(inputData.name) != null) { + errors.append("Cannot use reserved name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (group != null) { + group.tagText.setBackground(COLOR_LIGHT_RED); + } + } else { + if (group != null) { + group.tagText.setBackground(COLOR_TEXT_BACKGROUND); + } } } else { if (group != null) { diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserOutputWizardPage.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserOutputWizardPage.java index 2a637b9561..abfb20f09e 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserOutputWizardPage.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserOutputWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 Ericsson + * Copyright (c) 2010, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map.Entry; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -38,6 +39,7 @@ import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.internal.tmf.ui.Messages; import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; @@ -126,7 +128,7 @@ public class CustomTxtParserOutputWizardPage extends WizardPage { private void loadDefinition(final CustomTxtTraceDefinition def) { for (final OutputColumn outputColumn : def.outputs) { - final Output output = new Output(outputsContainer, outputColumn.name); + final Output output = new Output(outputsContainer, outputColumn.tag, outputColumn.name); outputs.add(output); } } @@ -135,15 +137,16 @@ public class CustomTxtParserOutputWizardPage extends WizardPage { public void setVisible(final boolean visible) { if (visible) { this.definition = wizard.inputPage.getDefinition(); - final List outputNames = wizard.inputPage.getInputNames(); + final List> inputs = wizard.inputPage.getInputs(); // dispose outputs that have been removed in the input page final Iterator iter = outputs.iterator(); while (iter.hasNext()) { final Output output = iter.next(); boolean found = false; - for (final String name : outputNames) { - if (output.name.equals(name)) { + for (final Entry input : inputs) { + if (output.tag.equals(input.getKey()) && + output.name.equals(input.getValue())) { found = true; break; } @@ -155,16 +158,17 @@ public class CustomTxtParserOutputWizardPage extends WizardPage { } // create outputs that have been added in the input page - for (final String name : outputNames) { + for (final Entry input : inputs) { boolean found = false; for (final Output output : outputs) { - if (output.name.equals(name)) { + if (output.tag.equals(input.getKey()) && + output.name.equals(input.getValue())) { found = true; break; } } if (!found) { - outputs.add(new Output(outputsContainer, name)); + outputs.add(new Output(outputsContainer, input.getKey(), input.getValue())); } } @@ -252,19 +256,10 @@ public class CustomTxtParserOutputWizardPage extends WizardPage { * @return The output columns */ public List extractOutputs() { - int numColumns = 0; - for (int i = 0; i < outputs.size(); i++) { - if (outputs.get(i).enabledButton.getSelection()) { - numColumns++; - } - } - final List outputColumns = new ArrayList<>(numColumns); - numColumns = 0; - for (int i = 0; i < outputs.size(); i++) { - final Output output = outputs.get(i); + final List outputColumns = new ArrayList<>(); + for (Output output : outputs) { if (output.enabledButton.getSelection()) { - final OutputColumn column = new OutputColumn(); - column.name = checkNotNull(output.nameLabel.getText()); + final OutputColumn column = new OutputColumn(checkNotNull(output.tag), checkNotNull(output.name)); outputColumns.add(column); } } @@ -272,13 +267,15 @@ public class CustomTxtParserOutputWizardPage extends WizardPage { } private class Output { + Tag tag; String name; Button enabledButton; Text nameLabel; Button upButton; Button downButton; - public Output(final Composite parent, final String name) { + public Output(final Composite parent, final Tag tag, final String name) { + this.tag = tag; this.name = name; enabledButton = new Button(parent, SWT.CHECK); 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 de8aac3c73..4f9cc2f623 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 Ericsson + * Copyright (c) 2010, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -19,8 +19,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.text.ParseException; +import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.List; +import java.util.Map.Entry; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -75,6 +77,7 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.tracecompass.internal.tmf.ui.Activator; import org.eclipse.tracecompass.internal.tmf.ui.Messages; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputAttribute; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlInputElement; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; @@ -380,7 +383,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { addChildButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ + CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ if (definition.rootInputElement == null) { definition.rootInputElement = inputElement; inputElement.setElementName(getChildNameSuggestion(null)); @@ -402,7 +405,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { addNextButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ + CustomXmlInputElement inputElement = new CustomXmlInputElement("", false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$ if (definition.rootInputElement == null) { definition.rootInputElement = inputElement; inputElement.setElementName(getChildNameSuggestion(null)); @@ -430,7 +433,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { CustomXmlInputElement inputElement = null; if (definition.rootInputElement == null) { if (getChildNameSuggestion(null).length() != 0) { - inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ + inputElement = new CustomXmlInputElement(getChildNameSuggestion(null), false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ definition.rootInputElement = inputElement; feelingLucky(inputElement); } else { @@ -495,7 +498,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (attributeName.length() == 0) { break; } - CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ + CustomXmlInputAttribute attribute = new CustomXmlInputAttribute(attributeName, Tag.OTHER, attributeName, 0, ""); //$NON-NLS-1$ inputElement.addAttribute(attribute); } while (true) { @@ -503,7 +506,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (childName.length() == 0) { break; } - CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, CustomXmlTraceDefinition.TAG_IGNORE, 0, "", null); //$NON-NLS-1$ + CustomXmlInputElement childElement = new CustomXmlInputElement(childName, false, Tag.IGNORE, Tag.IGNORE.toString(), 0, "", null); //$NON-NLS-1$ inputElement.addChild(childElement); feelingLucky(childElement); } @@ -648,42 +651,42 @@ public class CustomXmlParserInputWizardPage extends WizardPage { } /** - * Get the global list of input names. + * Get the global list of inputs. * - * @return The list of input names + * @return The list of inputs */ - public List getInputNames() { - return getInputNames(definition.rootInputElement); + public List> getInputs() { + return getInputs(definition.rootInputElement); } /** - * Get the list of input names for a given element. + * Get the list of inputs for a given element, recursively. * * @param inputElement * The element - * @return The input names for this element + * @return The list of inputs */ - public List getInputNames(CustomXmlInputElement inputElement) { - List inputs = new ArrayList<>(); - if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { - String inputName = inputElement.getInputName(); - if (!inputs.contains(inputName)) { - inputs.add(inputName); + public List> getInputs(CustomXmlInputElement inputElement) { + List> inputs = new ArrayList<>(); + if (inputElement.getInputTag() != null && !inputElement.getInputTag().equals(Tag.IGNORE)) { + Entry input = new SimpleEntry<>(inputElement.getInputTag(), inputElement.getInputName()); + if (!inputs.contains(input)) { + inputs.add(input); } } if (inputElement.getAttributes() != null) { for (CustomXmlInputAttribute attribute : inputElement.getAttributes()) { - String inputName = attribute.getInputName(); - if (!inputs.contains(inputName)) { - inputs.add(inputName); + Entry input = new SimpleEntry<>(attribute.getInputTag(), attribute.getInputName()); + if (!inputs.contains(input)) { + inputs.add(input); } } } if (inputElement.getChildElements() != null) { for (CustomXmlInputElement childInputElement : inputElement.getChildElements()) { - for (String inputName : getInputNames(childInputElement)) { - if (!inputs.contains(inputName)) { - inputs.add(inputName); + for (Entry input : getInputs(childInputElement)) { + if (!inputs.contains(input)) { + inputs.add(input); } } } @@ -943,8 +946,12 @@ public class CustomXmlParserInputWizardPage extends WizardPage { tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); - tagCombo.setItems(new String[] { CustomXmlTraceDefinition.TAG_IGNORE, CustomTraceDefinition.TAG_TIMESTAMP, - CustomTraceDefinition.TAG_EVENT_TYPE, CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER }); + tagCombo.setItems(new String[] { + Tag.IGNORE.toString(), + Tag.TIMESTAMP.toString(), + Tag.EVENT_TYPE.toString(), + Tag.MESSAGE.toString(), + Tag.OTHER.toString() }); tagCombo.setVisibleItemCount(tagCombo.getItemCount()); tagCombo.addSelectionListener(new SelectionListener() { @Override @@ -1010,21 +1017,21 @@ public class CustomXmlParserInputWizardPage extends WizardPage { actionCombo.select(inputElement.getInputAction()); actionCombo.addSelectionListener(updateListener); - if (inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) { + if (inputElement.getInputTag().equals(Tag.IGNORE)) { tagCombo.select(0); tagLabel.setVisible(false); tagText.setVisible(false); actionCombo.setVisible(false); - } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + } else if (inputElement.getInputTag().equals(Tag.TIMESTAMP)) { tagCombo.select(1); tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); tagText.setText(inputElement.getInputFormat()); tagText.addModifyListener(updateListener); - } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_EVENT_TYPE)) { + } else if (inputElement.getInputTag().equals(Tag.EVENT_TYPE)) { tagCombo.select(2); tagLabel.setVisible(false); tagText.setVisible(false); - } else if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) { + } else if (inputElement.getInputTag().equals(Tag.MESSAGE)) { tagCombo.select(3); tagLabel.setVisible(false); tagText.setVisible(false); @@ -1090,7 +1097,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { logEntryButton.setSelection(false); } } - if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) { + if (tagCombo.getText().equals(Tag.TIMESTAMP.toString()) && logEntriesCount <= 1) { String value = previewText.getText().trim(); if (value.length() != 0) { if (actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) { @@ -1122,7 +1129,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { String value = element.getAttribute(attribute.attributeNameText.getText().trim()); if (value.length() != 0) { attribute.previewText.setText(value); - if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP) && logEntriesCount <= 1) { + if (attribute.tagCombo.getText().equals(Tag.TIMESTAMP.toString()) && logEntriesCount <= 1) { if (attribute.actionCombo.getSelectionIndex() == CustomTraceDefinition.ACTION_SET) { timeStampValue = value; timeStampFormat = attribute.tagText.getText().trim(); @@ -1177,7 +1184,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { public void widgetSelected(SelectionEvent e) { removeAddButton(); String attributeName = getAttributeNameSuggestion(inputElement); - CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, attributeName, 0, ""); //$NON-NLS-1$ + CustomXmlInputAttribute inputAttribute = new CustomXmlInputAttribute(attributeName, Tag.OTHER, attributeName, 0, ""); //$NON-NLS-1$ attributes.add(new Attribute(group, ElementNode.this, inputAttribute, attributes.size() + 1)); createAddButton(); elementContainer.layout(); @@ -1222,11 +1229,13 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (inputElement.getParentElement() != null) { inputElement.setLogEntry(logEntryButton.getSelection()); inputElement.setEventType(eventTypeButton.getSelection() ? eventTypeText.getText().trim() : null); - if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { + Tag inputTag = Tag.fromLabel(tagCombo.getText()); + inputElement.setInputTag(inputTag); + if (inputTag.equals(Tag.OTHER)) { inputElement.setInputName(tagText.getText().trim()); } else { - inputElement.setInputName(tagCombo.getText()); - if (tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + inputElement.setInputName(inputTag.toString()); + if (inputTag.equals(Tag.TIMESTAMP)) { inputElement.setInputFormat(tagText.getText().trim()); } } @@ -1238,16 +1247,17 @@ public class CustomXmlParserInputWizardPage extends WizardPage { String inputFormat = null; Attribute attribute = attributes.get(i); String attributeName = attribute.attributeNameText.getText().trim(); - if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) { + Tag inputTag = Tag.fromLabel(attribute.tagCombo.getText()); + if (inputTag.equals(Tag.OTHER)) { inputName = attribute.tagText.getText().trim(); } else { - inputName = attribute.tagCombo.getText(); - if (attribute.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + inputName = inputTag.toString(); + if (inputTag.equals(Tag.TIMESTAMP)) { inputFormat = attribute.tagText.getText().trim(); } } int inputAction = attribute.actionCombo.getSelectionIndex(); - inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputName, inputAction, inputFormat)); + inputElement.addAttribute(new CustomXmlInputAttribute(attributeName, inputTag, inputName, inputAction, inputFormat)); } } } @@ -1338,8 +1348,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage { tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY); - tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP, CustomTraceDefinition.TAG_EVENT_TYPE, - CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.TAG_OTHER }); + tagCombo.setItems(new String[] { + Tag.TIMESTAMP.toString(), + Tag.EVENT_TYPE.toString(), + Tag.MESSAGE.toString(), + Tag.OTHER.toString() }); tagCombo.select(3); // Other tagCombo.addSelectionListener(new SelectionListener() { @Override @@ -1397,16 +1410,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage { actionCombo.select(inputAttribute.getInputAction()); actionCombo.addSelectionListener(updateListener); - if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (inputAttribute.getInputTag().equals(Tag.TIMESTAMP)) { tagCombo.select(0); tagLabel.setText(Messages.CustomXmlParserInputWizardPage_format); tagText.setText(inputAttribute.getInputFormat()); tagText.addModifyListener(updateListener); - } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_EVENT_TYPE)) { + } else if (inputAttribute.getInputTag().equals(Tag.EVENT_TYPE)) { tagCombo.select(1); tagLabel.setVisible(false); tagText.setVisible(false); - } else if (inputAttribute.getInputName().equals(CustomTraceDefinition.TAG_MESSAGE)) { + } else if (inputAttribute.getInputTag().equals(Tag.MESSAGE)) { tagCombo.select(2); tagLabel.setVisible(false); tagText.setVisible(false); @@ -1635,7 +1648,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (inputElement.isLogEntry()) { logEntryFound = true; } - if (inputElement.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (inputElement.getInputTag().equals(Tag.TIMESTAMP)) { timeStampFound = true; if (inputElement.getInputFormat().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementMissingTimestampFmtError, getName(inputElement))); @@ -1660,6 +1673,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (elementNode != null) { elementNode.tagText.setBackground(COLOR_LIGHT_RED); } + } else if (inputElement.getInputTag().equals(Tag.OTHER) && Tag.fromLabel(inputElement.getInputName()) != null) { + errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_elementReservedInputNameError, getName(inputElement))); + if (elementNode != null) { + elementNode.tagText.setBackground(COLOR_LIGHT_RED); + } } else { if (elementNode != null) { elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND); @@ -1705,7 +1723,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage { elementNode.attributes.get(i).attributeNameText.setBackground(COLOR_LIGHT_RED); } } - if (attribute.getInputName().equals(CustomTraceDefinition.TAG_TIMESTAMP)) { + if (attribute.getInputTag().equals(Tag.TIMESTAMP)) { timeStampFound = true; if (attribute.getInputFormat().length() == 0) { errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeMissingTimestampFmtError, getName(attribute, inputElement))); @@ -1730,6 +1748,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage { if (elementNode != null) { elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); } + } else if (attribute.getInputTag().equals(Tag.OTHER) && Tag.fromLabel(attribute.getInputName()) != null) { + errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_attributeReservedInputNameError, getName(attribute, inputElement))); + if (elementNode != null) { + elementNode.attributes.get(i).tagText.setBackground(COLOR_LIGHT_RED); + } } else { if (elementNode != null) { elementNode.attributes.get(i).tagText.setBackground(COLOR_TEXT_BACKGROUND); diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserOutputWizardPage.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserOutputWizardPage.java index bcf746899f..17766a7d68 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserOutputWizardPage.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserOutputWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 Ericsson + * Copyright (c) 2010, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Map.Entry; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; @@ -39,6 +40,7 @@ import org.eclipse.tracecompass.internal.tmf.ui.Messages; import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; +import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace; import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition; import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange; @@ -127,7 +129,7 @@ public class CustomXmlParserOutputWizardPage extends WizardPage { private void loadDefinition(final CustomTraceDefinition def) { for (final OutputColumn outputColumn : def.outputs) { - final Output output = new Output(outputsContainer, outputColumn.name); + final Output output = new Output(outputsContainer, outputColumn.tag, outputColumn.name); outputs.add(output); } } @@ -136,15 +138,16 @@ public class CustomXmlParserOutputWizardPage extends WizardPage { public void setVisible(final boolean visible) { if (visible) { this.definition = wizard.inputPage.getDefinition(); - final List outputNames = wizard.inputPage.getInputNames(); + final List> inputs = wizard.inputPage.getInputs(); // dispose outputs that have been removed in the input page final Iterator iter = outputs.iterator(); while (iter.hasNext()) { final Output output = iter.next(); boolean found = false; - for (final String name : outputNames) { - if (output.name.equals(name)) { + for (final Entry input : inputs) { + if (output.tag.equals(input.getKey()) && + output.name.equals(input.getValue())) { found = true; break; } @@ -156,16 +159,17 @@ public class CustomXmlParserOutputWizardPage extends WizardPage { } // create outputs that have been added in the input page - for (final String name : outputNames) { + for (final Entry input : inputs) { boolean found = false; for (final Output output : outputs) { - if (output.name.equals(name)) { + if (output.tag.equals(input.getKey()) && + output.name.equals(input.getValue())) { found = true; break; } } if (!found) { - outputs.add(new Output(outputsContainer, name)); + outputs.add(new Output(outputsContainer, input.getKey(), input.getValue())); } } @@ -253,19 +257,10 @@ public class CustomXmlParserOutputWizardPage extends WizardPage { * @return The list of output columns */ public List extractOutputs() { - int numColumns = 0; - for (int i = 0; i < outputs.size(); i++) { - if (outputs.get(i).enabledButton.getSelection()) { - numColumns++; - } - } - final List outputColumns = new ArrayList<>(numColumns); - numColumns = 0; - for (int i = 0; i < outputs.size(); i++) { - final Output output = outputs.get(i); + final List outputColumns = new ArrayList<>(); + for (Output output : outputs) { if (output.enabledButton.getSelection()) { - final OutputColumn column = new OutputColumn(); - column.name = checkNotNull(output.nameLabel.getText()); + final OutputColumn column = new OutputColumn(checkNotNull(output.tag), checkNotNull(output.name)); outputColumns.add(column); } } @@ -273,13 +268,15 @@ public class CustomXmlParserOutputWizardPage extends WizardPage { } private class Output { + Tag tag; String name; Button enabledButton; Text nameLabel; Button upButton; Button downButton; - public Output(final Composite parent, final String name) { + public Output(final Composite parent, final Tag tag, final String name) { + this.tag = tag; this.name = name; enabledButton = new Button(parent, SWT.CHECK); -- 2.34.1