tmf: Transition custom parsers to the new location
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 6 Feb 2014 21:10:36 +0000 (16:10 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 12 Feb 2014 18:11:45 +0000 (13:11 -0500)
If a user has some custom parsers defined in their workspace, and
they upgrade past 1b7d4a9, we can still look in the old location
so that they do not have to re-create the parsers manually.

Change-Id: Idd1c5f92f58d925be7494c75b8d1b668f487c119
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/21651
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
IP-Clean: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomXmlTraceDefinition.java

index 3402a47392a8d59016c1da59411bba5657bccfe4..f52e6272f4d0db4e28c81958237ca52f3b46fa11 100644 (file)
@@ -65,6 +65,13 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
     protected static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME =
         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 once we feel the transition phase is over. */
+    private static final String CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator()
+                    .append("org.eclipse.linuxtools.tmf.ui") //$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 NAME_ATTRIBUTE = Messages.CustomTxtTraceDefinition_name;
@@ -576,6 +583,21 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
      * @return The loaded trace definitions
      */
     public static CustomTxtTraceDefinition[] loadAll() {
+        File defaultFile = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
+        File legacyFile = new File(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME_LEGACY);
+
+        /*
+         * If there is no file at the expected location, check the legacy
+         * location 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();
+            }
+        }
+
         return loadAll(CUSTOM_TXT_TRACE_DEFINITIONS_PATH_NAME);
     }
 
index 80cb86cf5f628d22b5214daee4412b704a2717cb..6835667f38fbc6fe0ec1b0094ecb451751100590 100644 (file)
@@ -62,6 +62,13 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
     protected static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME =
         Activator.getDefault().getStateLocation().addTrailingSeparator().append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString();
 
+    /** Legacy path to the XML definitions file (in the UI plug-in)
+     * TODO Remove once we feel the transition phase is over. */
+    private static final String CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1).addTrailingSeparator()
+                    .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$
+                    .append(CUSTOM_XML_TRACE_DEFINITIONS_FILE_NAME).toString();
+
     private static final String CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT = Messages.CustomXmlTraceDefinition_definitionRootElement;
     private static final String DEFINITION_ELEMENT = Messages.CustomXmlTraceDefinition_definition;
     private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;
@@ -446,6 +453,21 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
      * @return The loaded trace definitions
      */
     public static CustomXmlTraceDefinition[] loadAll() {
+        File defaultFile = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
+        File legacyFile = new File(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY);
+
+        /*
+         * If there is no file at the expected location, check the legacy
+         * location instead.
+         */
+        if (!defaultFile.exists() && legacyFile.exists()) {
+            CustomXmlTraceDefinition[] oldDefs = loadAll(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME_LEGACY);
+            for (CustomXmlTraceDefinition def : oldDefs) {
+                /* Save in the new location */
+                def.save();
+            }
+        }
+
         return loadAll(CUSTOM_XML_TRACE_DEFINITIONS_PATH_NAME);
     }
 
This page took 0.029305 seconds and 5 git commands to generate.