tmf: Don't open trace files with validation confidence 0 (Bug 436444)
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Tue, 10 Feb 2015 19:55:07 +0000 (14:55 -0500)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 11 Feb 2015 23:08:52 +0000 (18:08 -0500)
... and only one valid applicable trace type is available.

Change-Id: Id6494df2bf78d1be079ef12e729d6a869c81d260
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/41566
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
doc/org.eclipse.tracecompass.doc.dev/doc/Developer-Guide.mediawiki
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/project/model/TmfTraceTypeUIUtils.java

index f69ae8ed7fa1d58379f358ecd70a9d5cffc3303f..10850ae1c8e17ad1c801fb81937a02359fff6ec6 100644 (file)
@@ -83,14 +83,14 @@ org.eclipse.tracecompass.tracing.examples.core.trace.nexus.NexusTrace.java.
 In this example, the '''validate''' function first checks if the file
 exists, then makes sure that it is really a file, and not a directory. Then we
 attempt to read the file header, to make sure that it is really a Nexus Trace.
-If that check passes, we return a TmfValidationStatus with a confidence of 20.
+If that check passes, we return a TraceValidationStatus with a confidence of 20.
 
-Typically, TmfValidationStatus confidences should range from 1 to 100. 1 meaning
+Typically, TraceValidationStatus confidences should range from 1 to 100. 1 meaning
 "there is a very small chance that this trace is of this type", and 100 meaning
 "it is this type for sure, and cannot be anything else". At run-time, the
-auto-detection will pick the the type which returned the highest confidence. So
+auto-detection will pick the type which returned the highest confidence. So
 checks of the type "does the file exist?" should not return a too high
-confidence.
+confidence. If confidence 0 is returned the auto-detection won't pick this type.
 
 Here we used a confidence of 20, to leave "room" for more specific trace types
 in the Nexus format that could be defined in TMF.
index 3a4271d18b3757d54be3c6ee4d9826afba6c7d9b..ac5ce5a171c964b7aeb6a82c2e26a734f704f514 100644 (file)
@@ -9,10 +9,12 @@
  * Contributors:
  *   Alexandre Montplaisir - Initial API and implementation
  *   Patrick Tasse - Add support for folder elements
+ *   Bernd Hufmann - Update trace type auto-detection
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.ui.project.model;
 
+import java.io.File;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
@@ -212,9 +214,15 @@ public final class TmfTraceTypeUIUtils {
 
         TraceTypeHelper traceTypeToSet = null;
         if (validCandidates.isEmpty()) {
+            File traceFile = new File(path);
+            if (traceFile.isFile()) {
+                return null;
+            }
             final String errorMsg = NLS.bind(Messages.TmfOpenTraceHelper_NoTraceTypeMatch, path);
             throw new TmfTraceImportException(errorMsg);
-        } else if (validCandidates.size() != 1) {
+        }
+
+        if (validCandidates.size() != 1) {
             List<Pair<Integer, TraceTypeHelper>> candidates = new ArrayList<>(validCandidates);
             List<Pair<Integer, TraceTypeHelper>> reducedCandidates = reduce(candidates);
             for (Pair<Integer, TraceTypeHelper> candidatePair : reducedCandidates) {
@@ -228,7 +236,10 @@ public final class TmfTraceTypeUIUtils {
                 if (reducedCandidates.size() == 0) {
                     throw new TmfTraceImportException(Messages.TmfOpenTraceHelper_ReduceError);
                 } else if (reducedCandidates.size() == 1) {
-                    traceTypeToSet = reducedCandidates.get(0).getSecond();
+                    // Don't select the trace type if it has the lowest confidence
+                    if (reducedCandidates.get(0).getFirst() > 0) {
+                        traceTypeToSet = reducedCandidates.get(0).getSecond();
+                    }
                 } else if (shell == null) {
                     Pair<Integer, TraceTypeHelper> candidate = reducedCandidates.get(0);
                     // if the best match has lowest confidence, don't select it
@@ -240,7 +251,10 @@ public final class TmfTraceTypeUIUtils {
                 }
             }
         } else {
-            traceTypeToSet = validCandidates.first().getSecond();
+            // Don't select the trace type if it has the lowest confidence
+            if (validCandidates.first().getFirst() > 0) {
+                traceTypeToSet = validCandidates.first().getSecond();
+            }
         }
         return traceTypeToSet;
     }
This page took 0.030559 seconds and 5 git commands to generate.