From d1b0903fe92fabef842f26e50cf12062d398c28c Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Tue, 31 May 2016 13:58:10 -0400 Subject: [PATCH] tmf: Bug 495054: Importing or exporting custom parsers fails silently When importing custom parsers from a file that does not contain any custom parser definition, a message dialog is shown to the user. When exporting a custom parser to an existing file that is not a valid custom parser definition file, a message is logged to the Error Log. Change-Id: I2f0bb781d9d43d8bbaf05da2b7ec06c2a65d47d3 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/74094 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- .../parsers/custom/CustomTxtTraceDefinition.java | 16 +++------------- .../parsers/custom/CustomXmlTraceDefinition.java | 3 ++- .../tracecompass/internal/tmf/ui/Messages.java | 4 +++- .../ui/dialogs/ManageCustomParsersDialog.java | 4 ++++ .../internal/tmf/ui/messages.properties | 2 ++ 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java index 087c5bd20c..2de73280a8 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 Ericsson + * Copyright (c) 2010, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -34,7 +34,6 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactoryConfigurationError; @@ -494,6 +493,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { if (file.canRead()) { doc = db.parse(file); if (!doc.getDocumentElement().getNodeName().equals(CUSTOM_TXT_TRACE_DEFINITION_ROOT_ELEMENT)) { + Activator.logError(String.format("Error saving CustomTxtTraceDefinition: path=%s is not a valid custom parser file", path)); //$NON-NLS-1$ return; } } else { @@ -546,17 +546,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition { TmfTraceType.addCustomTraceType(CustomTxtTrace.class, categoryName, definitionName); - } catch (ParserConfigurationException e) { - Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ - } catch (TransformerConfigurationException e) { - Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ - } catch (TransformerFactoryConfigurationError e) { - Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ - } catch (TransformerException e) { - Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ - } catch (IOException e) { - Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ - } catch (SAXException e) { + } catch (ParserConfigurationException | TransformerFactoryConfigurationError | TransformerException | IOException | SAXException e) { Activator.logError("Error saving CustomTxtTraceDefinition: path=" + path, e); //$NON-NLS-1$ } } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java index 19263f4ffd..d95783237a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 Ericsson + * Copyright (c) 2010, 2016 Ericsson * * All rights reserved. This program and the accompanying materials are * made available under the terms of the Eclipse Public License v1.0 which @@ -169,6 +169,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition { if (file.canRead()) { doc = db.parse(file); if (!doc.getDocumentElement().getNodeName().equals(CUSTOM_XML_TRACE_DEFINITION_ROOT_ELEMENT)) { + Activator.logError(String.format("Error saving CustomXmlTraceDefinition: path=%s is not a valid custom parser file", path)); //$NON-NLS-1$ return; } } else { diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java index 62bda33b17..1151ab56ae 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2015 Ericsson + * Copyright (c) 2012, 2016 Ericsson * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,6 +35,8 @@ public class Messages extends NLS { public static String ManageCustomParsersDialog_ExportParserSelection; public static String ManageCustomParsersDialog_ImportButtonLabel; public static String ManageCustomParsersDialog_ImportParserSelection; + public static String ManageCustomParsersDialog_ImportFailureTitle; + public static String ManageCustomParsersDialog_ImportFailureMessage; public static String ManageCustomParsersDialog_NewButtonLabel; public static String ManageCustomParsersDialog_TextButtonLabel; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java index a69b77ff82..d7c38d44f6 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/dialogs/ManageCustomParsersDialog.java @@ -262,6 +262,10 @@ public class ManageCustomParsersDialog extends Dialog { } } fillParserList(); + } else { + MessageDialog.openInformation(Display.getCurrent().getActiveShell(), + Messages.ManageCustomParsersDialog_ImportFailureTitle, + Messages.ManageCustomParsersDialog_ImportFailureMessage); } } } diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties index e07a4779ba..6fd59177cf 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties @@ -27,6 +27,8 @@ ManageCustomParsersDialog_ExportButtonLabel=Export... ManageCustomParsersDialog_ExportParserSelection=Select file to export {0} ManageCustomParsersDialog_ImportButtonLabel=Import... ManageCustomParsersDialog_ImportParserSelection=Select custom parser file to import +ManageCustomParsersDialog_ImportFailureTitle=Import failure +ManageCustomParsersDialog_ImportFailureMessage=Selected file did not contain any valid custom parser. ManageCustomParsersDialog_NewButtonLabel=New... ManageCustomParsersDialog_TextButtonLabel=Text -- 2.34.1