tmf: allow for list of validation patterns for text trace
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Fri, 22 Aug 2014 15:03:04 +0000 (11:03 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Tue, 26 Aug 2014 11:24:05 +0000 (07:24 -0400)
Change-Id: I34846b45e6b7e64edd7f1c18958089b508405278
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/32166
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java

index 5c48b14cee937ed0eba364d720dff34f9c1fbfe9..64d411afda9868a67434b5fc77b4ab625cec5b01 100644 (file)
@@ -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<T extends TextTraceEvent> extends TmfTrace imple
     /**
      * {@inheritDoc}
      * <p>
-     * 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<T extends TextTraceEvent> extends TmfTrace imple
             int lineCount = 0;
             double matches = 0.0;
             String line = rafile.getNextLine();
+            List<Pattern> 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<T extends TextTraceEvent> 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<Pattern> getValidationPatterns() {
+        return Collections.singletonList(getFirstLinePattern());
+    }
+
     // ------------------------------------------------------------------------
     // Helper methods
     // ------------------------------------------------------------------------
This page took 0.026297 seconds and 5 git commands to generate.