lttng: Make schema validation optional
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Fri, 8 Apr 2016 03:21:29 +0000 (23:21 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 21 Apr 2016 17:00:33 +0000 (13:00 -0400)
With this change, the schema validation is disabled by default except
for tests. The validation can be enabled easily as a Tracing option
in the launch configuration. To be able to enable this by default for
tests, it is also exposed in a system variable which could also be
used on the command-line.

Change-Id: I492f2877a7e066e14176a209159da17cea83c3f1
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/70199
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
lttng/org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/control/ui/swtbot/tests/Activator.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/META-INF/MANIFEST.MF
lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/Activator.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.control.ui/.options [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.control.ui/META-INF/MANIFEST.MF
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java

diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/control/ui/swtbot/tests/Activator.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/control/ui/swtbot/tests/Activator.java
new file mode 100644 (file)
index 0000000..4931ce9
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlServiceMI;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     *  The plug-in ID
+     */
+    public static final String PLUGIN_ID = "org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests";
+
+    // The shared instance
+    private static Activator fPlugin;
+
+    /**
+     * The constructor
+     */
+    public Activator() {
+        setDefault(this);
+    }
+
+    /**
+     * @return the shared instance
+     */
+    public static Activator getDefault() {
+        return fPlugin;
+    }
+
+    /**
+     * @param plugin the shared instance
+     */
+    private static void setDefault(Activator plugin) {
+        fPlugin = plugin;
+    }
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        super.start(context);
+        setDefault(this);
+        String systemProperty = System.getProperty(LTTngControlServiceMI.MI_SCHEMA_VALIDATION_KEY);
+        if (systemProperty == null) {
+            System.setProperty(LTTngControlServiceMI.MI_SCHEMA_VALIDATION_KEY, Boolean.TRUE.toString());
+        }
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        setDefault(null);
+        super.stop(context);
+    }
+
+}
index 97d310c24530b2ccbdc845a9fd30b2c22a9e35cf..ac48bc5d9b2e9ceb820e5fcbea808fb7e01b2e52 100644 (file)
@@ -26,3 +26,4 @@ Export-Package: org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs;x
  org.eclipse.tracecompass.lttng2.control.ui.tests;x-friends:="org.eclipse.tracecompass.alltests",
  org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;x-internal:=true,
  org.eclipse.tracecompass.lttng2.control.ui.tests.service;x-internal:=true
+Bundle-Activator: org.eclipse.tracecompass.lttng2.control.ui.tests.Activator
diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/Activator.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui.tests/src/org/eclipse/tracecompass/lttng2/control/ui/tests/Activator.java
new file mode 100644 (file)
index 0000000..6695e34
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.control.ui.tests;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlServiceMI;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     *  The plug-in ID
+     */
+    public static final String PLUGIN_ID = "org.eclipse.tracecompass.lttng2.control.ui.tests";
+
+    // The shared instance
+    private static Activator fPlugin;
+
+    /**
+     * The constructor
+     */
+    public Activator() {
+        setDefault(this);
+    }
+
+    /**
+     * @return the shared instance
+     */
+    public static Activator getDefault() {
+        return fPlugin;
+    }
+
+    /**
+     * @param plugin the shared instance
+     */
+    private static void setDefault(Activator plugin) {
+        fPlugin = plugin;
+    }
+
+    @Override
+    public void start(BundleContext context) throws Exception {
+        super.start(context);
+        setDefault(this);
+        String systemProperty = System.getProperty(LTTngControlServiceMI.MI_SCHEMA_VALIDATION_KEY);
+        if (systemProperty == null) {
+            System.setProperty(LTTngControlServiceMI.MI_SCHEMA_VALIDATION_KEY, Boolean.TRUE.toString());
+        }
+    }
+
+    @Override
+    public void stop(BundleContext context) throws Exception {
+        setDefault(null);
+        super.stop(context);
+    }
+
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/.options b/lttng/org.eclipse.tracecompass.lttng2.control.ui/.options
new file mode 100644 (file)
index 0000000..a0e9e21
--- /dev/null
@@ -0,0 +1 @@
+org.eclipse.tracecompass.lttng2.control.ui/mi/schema-validation=false
index a83dd4f6c16da1c8903113f820d5023f8c5ac346..7381bf8a1459957f5614c1b2818d8dfa38e4e3d9 100644 (file)
@@ -41,5 +41,5 @@ Export-Package: org.eclipse.tracecompass.internal.lttng2.control.ui;x-friends:="
  org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl;x-friends:="org.eclipse.tracecompass.lttng2.control.ui.tests,org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests",
  org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences;x-friends:="org.eclipse.tracecompass.lttng2.control.ui.tests",
  org.eclipse.tracecompass.internal.lttng2.control.ui.views.property;x-friends:="org.eclipse.tracecompass.lttng2.control.ui.tests",
- org.eclipse.tracecompass.internal.lttng2.control.ui.views.service;x-friends:="org.eclipse.tracecompass.lttng2.control.ui.tests"
+ org.eclipse.tracecompass.internal.lttng2.control.ui.views.service;x-friends:="org.eclipse.tracecompass.lttng2.control.ui.tests,org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests"
 Import-Package: com.google.common.collect
index e78920e24cd4c2e2b5b720340f3b5ce20d24c8cf..928c3516bd7cd2ae94fc7530c27a3ed4763397d6 100644 (file)
@@ -31,6 +31,7 @@ import javax.xml.validation.SchemaFactory;
 
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.osgi.util.NLS;
@@ -59,6 +60,7 @@ import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.ProbeEve
 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.SessionInfo;
 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.SnapshotInfo;
 import org.eclipse.tracecompass.internal.lttng2.control.core.model.impl.UstProviderInfo;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers.XmlMiValidationErrorHandler;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
 import org.eclipse.tracecompass.tmf.remote.core.shell.ICommandInput;
@@ -78,6 +80,11 @@ import org.xml.sax.SAXException;
  */
 public class LTTngControlServiceMI extends LTTngControlService {
 
+    /**
+     * The tracing key (.options) and System property to control whether or not schema validation should be used.
+     */
+    public static final String MI_SCHEMA_VALIDATION_KEY = Activator.PLUGIN_ID + "/mi/schema-validation"; //$NON-NLS-1$
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -105,13 +112,15 @@ public class LTTngControlServiceMI extends LTTngControlService {
         DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
         docBuilderFactory.setValidating(false);
 
-        // Validate XSD schema
-        if (xsdUrl != null) {
-            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            try {
-                docBuilderFactory.setSchema(schemaFactory.newSchema(xsdUrl));
-            } catch (SAXException e) {
-                throw new ExecutionException(Messages.TraceControl_InvalidSchemaError, e);
+        if (isSchemaValidationEnabled()) {
+            // Validate XSD schema
+            if (xsdUrl != null) {
+                SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+                try {
+                    docBuilderFactory.setSchema(schemaFactory.newSchema(xsdUrl));
+                } catch (SAXException e) {
+                    throw new ExecutionException(Messages.TraceControl_InvalidSchemaError, e);
+                }
             }
         }
 
@@ -125,6 +134,12 @@ public class LTTngControlServiceMI extends LTTngControlService {
 
     }
 
+    private static boolean isSchemaValidationEnabled() {
+        String schemaValidationKey = Platform.getDebugOption(MI_SCHEMA_VALIDATION_KEY);
+        String systemProperty = System.getProperty(MI_SCHEMA_VALIDATION_KEY);
+        return schemaValidationKey != null && Boolean.parseBoolean(schemaValidationKey) || systemProperty != null && Boolean.parseBoolean(systemProperty);
+    }
+
     /**
      * Generate a Document object from an list of Strings.
      *
This page took 0.029858 seconds and 5 git commands to generate.