From 543e2b1e3d90a355cbe80ec078e6fb93bea28968 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Fri, 22 Aug 2014 11:03:04 -0400 Subject: [PATCH] tmf: allow for list of validation patterns for text trace Change-Id: I34846b45e6b7e64edd7f1c18958089b508405278 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/32166 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- .../tmf/core/trace/text/TextTrace.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java index 5c48b14cee..64d411afda 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java @@ -16,6 +16,8 @@ package org.eclipse.linuxtools.tmf.core.trace.text; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -72,9 +74,11 @@ public abstract class TextTrace extends TmfTrace imple /** * {@inheritDoc} *

- * The default implementation computes the confidence as the percentage of - * lines in the first 100 lines of the file which match the first line - * pattern. + * The default implementation computes the confidence as the sum of weighted + * values of the first 100 lines of the file which match any of the provided + * validation patterns. For each matching line a weighted value between 1.5 + * and 2.0 is assigned based on the group count of the matching patterns. + * The higher the group count, the closer the weighted value will be to 2.0. */ @Override public IStatus validate(IProject project, String path) { @@ -90,11 +94,14 @@ public abstract class TextTrace extends TmfTrace imple int lineCount = 0; double matches = 0.0; String line = rafile.getNextLine(); + List validationPatterns = getValidationPatterns(); while ((line != null) && (lineCount++ < MAX_LINES)) { - Matcher matcher = getFirstLinePattern().matcher(line); - if (matcher.matches()) { - int groupCount = matcher.groupCount(); - matches += (1.0 + groupCount / ((double) groupCount + 1)); + for(Pattern pattern : validationPatterns) { + Matcher matcher = pattern.matcher(line); + if (matcher.matches()) { + int groupCount = matcher.groupCount(); + matches += (1.0 + groupCount / ((double) groupCount + 1)); + } } confidence = (int) (MAX_CONFIDENCE * matches / lineCount); line = rafile.getNextLine(); @@ -305,6 +312,18 @@ public abstract class TextTrace extends TmfTrace imple */ protected abstract void parseNextLine(T event, String line); + /** + * Returns a ordered list of validation patterns that will be used in + * the default {@link #validate(IProject, String)} method to match + * the first 100 to compute the confidence level + * + * @return collection of patterns to validate against + * @since 3.1 + */ + protected List getValidationPatterns() { + return Collections.singletonList(getFirstLinePattern()); + } + // ------------------------------------------------------------------------ // Helper methods // ------------------------------------------------------------------------ -- 2.34.1