Make Custom Parser trace type backwards compatible to Linux Tools
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / parsers / custom / CustomTxtTraceDefinition.java
index 1ee3ab17b0d90ae60d36226cb85b8d6cf97520b1..7b537fdb39036ce08de6a5fc8b24cff27267239f 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -59,6 +59,13 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
     /** Input lines */
     public List<InputLine> inputs;
 
+    /**
+     * Custom text label used internally and therefore should not be
+     * externalized
+     */
+    public static final String CUSTOM_TXT_CATEGORY = "Custom Text"; //$NON-NLS-1$
+
+
     /** File name of the default definition file */
     protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_DEFAULT_FILE_NAME = "custom_txt_default_parsers.xml"; //$NON-NLS-1$
     /** File name of the definition file */
@@ -73,14 +80,23 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
             Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString();
 
     /**
-     * Legacy path to the XML definitions file (in the UI plug-in) TODO Remove
+     * Legacy path to the XML definitions file (in the UI plug-in of linuxtools) TODO Remove
      * once we feel the transition phase is over.
      */
-    private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY =
+    private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI =
             Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator()
                     .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$
                     .append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString();
 
+    /**
+     * Legacy path to the XML definitions file (in the core plug-in of linuxtools) TODO Remove
+     * once we feel the transition phase is over.
+     */
+    private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE =
+            Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator()
+                    .append("org.eclipse.linuxtools.tmf.core") //$NON-NLS-1$
+                    .append(CUSTOM_TXT_TRACE_DEFINITIONS_FILE_NAME).toString();
+
     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;
@@ -100,7 +116,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
      * Default constructor.
      */
     public CustomTxtTraceDefinition() {
-        this(TmfTraceType.CUSTOM_TXT_CATEGORY, "", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
+        this(CUSTOM_TXT_CATEGORY, "", new ArrayList<InputLine>(0), new ArrayList<OutputColumn>(0), ""); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     /**
@@ -622,17 +638,18 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
      */
     public static CustomTxtTraceDefinition[] loadAll(boolean includeDefaults) {
         File defaultFile = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
-        File legacyFile = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY);
+        File legacyFileCore = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE);
+        File legacyFileUI = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI);
 
         /*
          * If there is no file at the expected location, check the legacy
-         * location instead.
+         * locations instead.
          */
-        if (!defaultFile.exists() && legacyFile.exists()) {
-            CustomTxtTraceDefinition[] oldDefs = loadAll(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY);
-            for (CustomTxtTraceDefinition def : oldDefs) {
-                /* Save in the new location */
-                def.save();
+        if (!defaultFile.exists()) {
+            if (legacyFileCore.exists()) {
+                transferDefinitions(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_CORE);
+            } else if (legacyFileUI.exists()) {
+                transferDefinitions(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY_UI);
             }
         }
 
@@ -654,6 +671,14 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
 
     }
 
+    private static void transferDefinitions(String defFile) {
+        CustomTxtTraceDefinition[] oldDefs = loadAll(defFile);
+        for (CustomTxtTraceDefinition def : oldDefs) {
+            /* Save in the new location */
+            def.save();
+        }
+    }
+
     /**
      * Load a specific text trace definition file.
      *
@@ -715,7 +740,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
      */
     @Deprecated
     public static CustomTxtTraceDefinition load(String definitionName) {
-        return load(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+        return load(CUSTOM_TXT_CATEGORY, definitionName);
     }
 
     /**
@@ -777,7 +802,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
                 Element element = (Element) node;
                 String categoryAttribute = element.getAttribute(CATEGORY_ATTRIBUTE);
                 if (categoryAttribute.isEmpty()) {
-                    categoryAttribute = TmfTraceType.CUSTOM_TXT_CATEGORY;
+                    categoryAttribute = CUSTOM_TXT_CATEGORY;
                 }
                 String nameAttribute = element.getAttribute(NAME_ATTRIBUTE);
                 if (categoryName.equals(categoryAttribute) &&
@@ -801,7 +826,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
 
         def.categoryName = definitionElement.getAttribute(CATEGORY_ATTRIBUTE);
         if (def.categoryName.isEmpty()) {
-            def.categoryName = TmfTraceType.CUSTOM_TXT_CATEGORY;
+            def.categoryName = CUSTOM_TXT_CATEGORY;
         }
         def.definitionName = definitionElement.getAttribute(NAME_ATTRIBUTE);
         if (def.definitionName.isEmpty()) {
@@ -875,7 +900,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
      */
     @Deprecated
     public static void delete(String definitionName) {
-        delete(TmfTraceType.CUSTOM_TXT_CATEGORY, definitionName);
+        delete(CUSTOM_TXT_CATEGORY, definitionName);
     }
 
     /**
This page took 0.026058 seconds and 5 git commands to generate.