/*******************************************************************************
- * 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
*
* 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;
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;
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;
/**
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);
}
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) {
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) {
/*******************************************************************************
- * 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;
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(),
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<>();
*/
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();
}
/*******************************************************************************
- * 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
*
* 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;
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) {