From 2aebf5f32e5ecdd3e4c0c51dfc9caefc3502f027 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Thu, 5 Feb 2015 21:27:53 -0500 Subject: [PATCH] tmf: Fix workspace backwards compatibility of filters, colors and XML analysis Change-Id: Ifa81c71e3858008d091ee7e1ead5a60f6daac09b Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/41236 Reviewed-by: Hudson CI Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse Reviewed-by: Bernd Hufmann --- .../ui/module/XmlAnalysisModuleSource.java | 38 ++++++++++++++++++- .../filter/xml/TmfFilterContentHandler.java | 2 + .../ui/views/colors/ColorSettingsManager.java | 37 ++++++++++++++++-- .../tmf/ui/views/filter/FilterManager.java | 38 ++++++++++++++++++- 4 files changed, 110 insertions(+), 5 deletions(-) diff --git a/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java b/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java index 2dc72b231b..ffbbdc4fa6 100644 --- a/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java +++ b/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/module/XmlAnalysisModuleSource.java @@ -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 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); } diff --git a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterContentHandler.java b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterContentHandler.java index 1addc396ac..dc159844fc 100644 --- a/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterContentHandler.java +++ b/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/filter/xml/TmfFilterContentHandler.java @@ -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) { diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java index a271b0bfa9..cf83e11fa2 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/colors/ColorSettingsManager.java @@ -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 @@ -13,10 +13,12 @@ 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 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(); } diff --git a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterManager.java b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterManager.java index de0cf88c47..7efcf62539 100644 --- a/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterManager.java +++ b/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/filter/FilterManager.java @@ -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) { -- 2.34.1