tmf: Fix workspace backwards compatibility of filters, colors and XML
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Fri, 6 Feb 2015 02:27:53 +0000 (21:27 -0500)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Mon, 9 Feb 2015 20:20:58 +0000 (15:20 -0500)
analysis

Change-Id: Ifa81c71e3858008d091ee7e1ead5a60f6daac09b
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/41236
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java
org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterContentHandler.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterManager.java

index 2dc72b231b8eb14cdb04bd23b1349aaa16d64129..ffbbdc4fa6904df9a1d11232f695a5a09d07752d 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2015 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal and others
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,14 +8,18 @@
  *
  * Contributors:
  *   Geneviève Bastien - Initial API and implementation
+ *   Bernd Hufmann - Ensure backwards compatibility to Linux Tools
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.analysis.xml.ui.module;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -30,6 +34,7 @@ import org.eclipse.core.runtime.ISafeRunnable;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.SafeRunner;
 import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.module.Messages;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
 import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.TmfAnalysisModuleHelperXml.XmlAnalysisModuleType;
@@ -57,6 +62,15 @@ public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
 
     private static final String XML_FILE_ATTRIB = "file"; //$NON-NLS-1$
 
+    /*
+     * Legacy (Linux Tools) XML directory.
+     * TODO Remove once we feel the transition phase is over.
+     */
+    private static final IPath XML_DIRECTORY_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1)
+            .append("org.eclipse.linuxtools.tmf.analysis.xml.core") //$NON-NLS-1$
+            .append("xml_files"); //$NON-NLS-1$
+
     private static List<IAnalysisModuleHelper> fModules = null;
 
     /**
@@ -144,6 +158,28 @@ public class XmlAnalysisModuleSource implements IAnalysisModuleSource {
         if (!(fFolder.isDirectory() && fFolder.exists())) {
             return;
         }
+
+        /*
+         * Transfer files from Linux Tools directory.
+         */
+        File fOldFolder = XML_DIRECTORY_LEGACY.toFile();
+        if ((fOldFolder.isDirectory() && fOldFolder.exists())) {
+            for (File fromFile : fOldFolder.listFiles()) {
+                File toFile = pathToFiles.append(fromFile.getName()).toFile();
+                if (!toFile.exists() && !fromFile.isDirectory()) {
+                    try (FileInputStream fis = new FileInputStream(fromFile);
+                            FileOutputStream fos = new FileOutputStream(toFile);
+                            FileChannel source = fis.getChannel();
+                            FileChannel destination = fos.getChannel();) {
+                        destination.transferFrom(source, 0, source.size());
+                    } catch (IOException e) {
+                        String error = Messages.XmlUtils_ErrorCopyingFile;
+                        Activator.logError(error, e);
+                    }
+                }
+            }
+        }
+
         for (File xmlFile : fFolder.listFiles()) {
             processFile(xmlFile);
         }
index 1addc396acc6730d29ce8a7dffc65ea17bd7633b..dc159844fc3a3a79698a030329c5e6dd58246d7f 100644 (file)
@@ -93,6 +93,7 @@ public class TmfFilterContentHandler extends DefaultHandler {
 
             node = new TmfFilterTraceTypeNode(null);
             String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
+            traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
             ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
             TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
             if (helper != null) {
@@ -228,6 +229,7 @@ public class TmfFilterContentHandler extends DefaultHandler {
 
     private static void createEventAspect(TmfFilterAspectNode node, Attributes atts) {
         String traceTypeId = atts.getValue(TmfFilterAspectNode.TRACE_TYPE_ID_ATTR);
+        traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
         String name = atts.getValue(TmfFilterAspectNode.EVENT_ASPECT_ATTR);
         if (TmfFilterAspectNode.BASE_ASPECT_ID.equals(traceTypeId)) {
             for (ITmfEventAspect eventAspect : ITmfEventAspect.BASE_ASPECTS) {
index a271b0bfa99e50b0b27f380f62247f898f70ba1b..cf83e11fa2612522775e458653d5875845af1852 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
 
 package org.eclipse.tracecompass.tmf.ui.views.colors;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
@@ -38,6 +40,15 @@ public class ColorSettingsManager {
     private static final String COLOR_SETTINGS_PATH_NAME =
         Activator.getDefault().getStateLocation().addTrailingSeparator().append(COLOR_SETTINGS_FILE_NAME).toString();
 
+    /*
+     * Legacy path to the XML definitions file (in Linux Tools)
+     *  TODO Remove once we feel the transition phase is over.
+     */
+    private static final IPath COLOR_SETTINGS_PATH_NAME_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1)
+                    .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$
+                    .append(COLOR_SETTINGS_FILE_NAME);
+
     // The default color setting
     private static final ColorSetting DEFAULT_COLOR_SETTING = new ColorSetting(
             Display.getDefault().getSystemColor(SWT.COLOR_LIST_FOREGROUND).getRGB(),
@@ -51,7 +62,25 @@ public class ColorSettingsManager {
     public static final int PRIORITY_NONE = Integer.MAX_VALUE;
 
     // The stored color settings
-    private static ColorSetting[] fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);
+    private static ColorSetting[] fColorSettings;
+
+    static {
+        File defaultFile = new File(COLOR_SETTINGS_PATH_NAME);
+        /*
+         * If there is no file at the expected location, check the legacy
+         * location instead.
+         */
+        if (!defaultFile.exists()) {
+            File legacyFileCore = COLOR_SETTINGS_PATH_NAME_LEGACY.toFile();
+            if (legacyFileCore.exists()) {
+                ColorSetting[] colorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME_LEGACY.toString());
+                if (colorSettings != null) {
+                    ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, colorSettings);
+                }
+            }
+        }
+        fColorSettings = ColorSettingsXML.load(COLOR_SETTINGS_PATH_NAME);
+    }
 
     // The listener list
     private static List<IColorSettingsListener> fListeners = new ArrayList<>();
@@ -72,7 +101,9 @@ public class ColorSettingsManager {
      */
     public static void setColorSettings(ColorSetting[] colorSettings) {
         fColorSettings = (colorSettings != null) ? Arrays.copyOf(colorSettings, colorSettings.length) : null;
-        ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);
+        if (fColorSettings != null) {
+            ColorSettingsXML.save(COLOR_SETTINGS_PATH_NAME, fColorSettings);
+        }
         fireColorSettingsChanged();
     }
 
index de0cf88c470e80d758596819b64fe5a2e7f37ccf..7efcf62539c90017fcca3995fe15e660f61b03fc 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
@@ -8,15 +8,18 @@
  *
  * Contributors:
  *   Patrick Tasse - Initial API and implementation
+ *   Bernd Hufmann - Ensure backwards compatibility to Linux Tools
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.ui.views.filter;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.tracecompass.internal.tmf.ui.Activator;
 import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode;
 import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode;
@@ -36,9 +39,42 @@ public class FilterManager {
     private static final String SAVED_FILTERS_PATH_NAME =
         Activator.getDefault().getStateLocation().addTrailingSeparator().append(SAVED_FILTERS_FILE_NAME).toString();
 
+    /*
+     * Legacy path to the XML definitions file (in Linux Tools)
+     *  TODO Remove once we feel the transition phase is over.
+     */
+    private static final IPath SAVED_FILTERS_FILE_NAME_LEGACY =
+            Activator.getDefault().getStateLocation().removeLastSegments(1)
+                    .append("org.eclipse.linuxtools.tmf.ui") //$NON-NLS-1$
+                    .append(SAVED_FILTERS_FILE_NAME);
+
+
     private static ITmfFilterTreeNode fRoot = new TmfFilterRootNode();
     static {
+
+        File defaultFile = new File(SAVED_FILTERS_PATH_NAME);
+
+        try {
+            /*
+             * If there is no file at the expected location, check the legacy
+             * location instead.
+             */
+            if (!defaultFile.exists()) {
+                File legacyFileCore = SAVED_FILTERS_FILE_NAME_LEGACY.toFile();
+                if (legacyFileCore.exists()) {
+                    ITmfFilterTreeNode root = new TmfFilterXMLParser(SAVED_FILTERS_FILE_NAME_LEGACY.toString()).getTree();
+                    setSavedFilters(root.getChildren());
+                }
+            }
+        } catch (FileNotFoundException e) {
+        } catch (SAXException e) {
+            Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_FILE_NAME_LEGACY, e); //$NON-NLS-1$
+        } catch (IOException e) {
+            Activator.getDefault().logError("Error parsing saved filter xml file: " + SAVED_FILTERS_FILE_NAME_LEGACY, e); //$NON-NLS-1$
+        }
+
         try {
+            // Now load the filters from the current location
             fRoot = new TmfFilterXMLParser(SAVED_FILTERS_PATH_NAME).getTree();
         } catch (FileNotFoundException e) {
         } catch (SAXException e) {
This page took 0.03068 seconds and 5 git commands to generate.