ctf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.gdbtrace.core / src / org / eclipse / linuxtools / internal / gdbtrace / core / trace / GdbTrace.java
index d3dd7f9e64800af3dfcc3e6ef1a6b8248e571619..097f49e4cff67eacf5cbc071cefe18f48b581ac7 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011, 2013 Ericsson
+ * Copyright (c) 2011, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
 
 package org.eclipse.linuxtools.internal.gdbtrace.core.trace;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Arrays;
 
 import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
 import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
@@ -32,14 +36,15 @@ import org.eclipse.linuxtools.internal.gdbtrace.core.GdbTraceCorePlugin;
 import org.eclipse.linuxtools.internal.gdbtrace.core.event.GdbTraceEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 import org.eclipse.linuxtools.tmf.core.trace.location.TmfLongLocation;
+import org.eclipse.osgi.util.NLS;
 
 /**
  * GDB Tracepoint extension of TmfTrace. This class implements the necessary
@@ -60,6 +65,8 @@ public class GdbTrace extends TmfTrace implements ITmfEventParser {
 
     private static final int CACHE_SIZE = 20;
 
+    private static final byte[] HEADER = new byte[] {0x7f, 'T', 'R', 'A', 'C', 'E'};
+
     /** The qualified name for the 'executable' persistent property */
     public static final QualifiedName EXEC_KEY = new QualifiedName(GdbTraceCorePlugin.PLUGIN_ID, "executable"); //$NON-NLS-1$
 
@@ -87,15 +94,27 @@ public class GdbTrace extends TmfTrace implements ITmfEventParser {
 
     @Override
     public IStatus validate(IProject project, String path) {
-        if (fileExists(path)) {
-            if ((new File(path)).isFile()) {
-                return Status.OK_STATUS;
+        File file = new File(path);
+        if (!file.exists()) {
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                    NLS.bind(Messages.GdbTrace_FileNotFound, path));
+        }
+        if (!file.isFile()) {
+            return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                    NLS.bind(Messages.GdbTrace_GdbTracesMustBeAFile, path));
+        }
+        try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file))) {
+            byte[] buffer = new byte[HEADER.length];
+            int read = stream.read(buffer);
+            if (read != HEADER.length || !Arrays.equals(buffer, HEADER)) {
+                return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+                        NLS.bind(Messages.GdbTrace_NotGdbTraceFile, path));
             }
+        } catch (IOException e) {
             return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
-                    Messages.GdbTrace_GdbTracesMustBeAFile + ": " + //$NON-NLS-1$
-                            path + " " + Messages.GdbTrace_IsNotAFile); //$NON-NLS-1$
+                    NLS.bind(Messages.GdbTrace_IOException, path), e);
         }
-        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.GdbTrace_FileNotFound + ": " + path); //$NON-NLS-1$
+        return new TraceValidationStatus(100, GdbTraceCorePlugin.PLUGIN_ID);
     }
 
     @Override
This page took 0.024543 seconds and 5 git commands to generate.