lttng ui: Fix minor sonar warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / service / LTTngControlService.java
index 294124e9cab5c78d503881807e22cd7ab516599e..d660dcfdbbff742c2168f9c317bed84cbf8a9840 100644 (file)
@@ -44,7 +44,6 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences.ControlPreferences;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandResult;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell;
-import org.osgi.framework.Version;
 
 /**
  * <p>
@@ -61,12 +60,12 @@ public class LTTngControlService implements ILttngControlService {
     /**
      * The command shell implementation
      */
-    protected ICommandShell fCommandShell = null;
+    private final ICommandShell fCommandShell;
 
     /**
      * The version string.
      */
-    protected Version fVersion = null;
+    private LttngVersion fVersion = null;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -85,10 +84,7 @@ public class LTTngControlService implements ILttngControlService {
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getVersion()
-     */
+
     @Override
     public String getVersion() {
         if (fVersion == null) {
@@ -102,30 +98,28 @@ public class LTTngControlService implements ILttngControlService {
      * @param version - a version to set
      */
     public void setVersion(String version) {
-        fVersion = new Version(version);
+        fVersion = new LttngVersion(version);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#isVersionSupported(java.lang.String)
-     */
     @Override
     public boolean isVersionSupported(String version) {
-        Version tmp = new Version(version);
+        LttngVersion tmp = new LttngVersion(version);
         return (fVersion != null && fVersion.compareTo(tmp) >= 0) ? true : false;
     }
 
+    /**
+     * Returns the command shell implementation.
+     *
+     * @return the command shell implementation
+     */
+    protected ICommandShell getCommandShell() {
+        return fCommandShell;
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
-     * #getSessionNames(org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST);
@@ -152,13 +146,6 @@ public class LTTngControlService implements ILttngControlService {
         return retArray.toArray(new String[retArray.size()]);
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
-     * #getSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName);
@@ -244,13 +231,6 @@ public class LTTngControlService implements ILttngControlService {
         return sessionInfo;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
-     * #getKernelProvider(org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_KERNEL);
@@ -287,25 +267,11 @@ public class LTTngControlService implements ILttngControlService {
         return events;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
-     * #getUstProvider()
-     */
     @Override
     public List<IUstProviderInfo> getUstProvider() throws ExecutionException {
         return getUstProvider(new NullProgressMonitor());
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService
-     * #getUstProvider(org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_UST);
@@ -314,7 +280,36 @@ public class LTTngControlService implements ILttngControlService {
             command.append(LTTngControlServiceConstants.OPTION_FIELDS);
         }
 
-        ICommandResult result = executeCommand(command.toString(), monitor);
+        ICommandResult result = executeCommand(command.toString(), monitor, false);
+        List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
+
+        // Workaround for versions 2.0.x which causes a segmentation fault for this command
+        // if LTTng Tools is compiled without UST support.
+        if (!isVersionSupported("2.1.0") && (result.getResult() != 0)) { //$NON-NLS-1$
+            return allProviders;
+        }
+
+        if (result.getOutput() != null) {
+            // Ignore the following 2 cases:
+            // Spawning a session daemon
+            // Error: Unable to list UST events: Listing UST events failed
+            // or:
+            // Error: Unable to list UST events: Listing UST events failed
+            //
+            int index = 0;
+            while (index < result.getOutput().length) {
+                String line = result.getOutput()[index];
+                Matcher matcher = LTTngControlServiceConstants.LIST_UST_NO_UST_PROVIDER_PATTERN.matcher(line);
+                if (matcher.matches()) {
+                    return allProviders;
+                }
+                index++;
+            }
+        }
+
+        if (isError(result)) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command.toString() + "\n" + formatOutput(result)); //$NON-NLS-1$ //$NON-NLS-2$
+        }
 
         // Note that field print-outs exists for version >= 2.1.0
         //
@@ -339,7 +334,6 @@ public class LTTngControlService implements ILttngControlService {
         //    field: floatfield (float)
         //    field: stringfield (string)
 
-        List<IUstProviderInfo> allProviders = new ArrayList<IUstProviderInfo>();
         IUstProviderInfo provider = null;
 
         int index = 0;
@@ -356,15 +350,10 @@ public class LTTngControlService implements ILttngControlService {
             } else {
                 index++;
             }
-
         }
         return allProviders;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public ISessionInfo createSession(String sessionName, String sessionPath, IProgressMonitor monitor) throws ExecutionException {
 
@@ -423,10 +412,6 @@ public class LTTngControlService implements ILttngControlService {
 
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#createSession(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public ISessionInfo createSession(String sessionName, String networkUrl, String controlUrl, String dataUrl, IProgressMonitor monitor) throws ExecutionException {
 
@@ -530,10 +515,6 @@ public class LTTngControlService implements ILttngControlService {
         //Session <sessionName> destroyed
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#startSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
 
@@ -546,10 +527,6 @@ public class LTTngControlService implements ILttngControlService {
         //Session <sessionName> started
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#stopSession(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
         String newSessionName = formatParameter(sessionName);
@@ -561,10 +538,6 @@ public class LTTngControlService implements ILttngControlService {
 
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableChannel(java.lang.String, java.util.List, boolean, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
 
@@ -623,10 +596,6 @@ public class LTTngControlService implements ILttngControlService {
 
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableChannel(java.lang.String, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
 
@@ -658,10 +627,6 @@ public class LTTngControlService implements ILttngControlService {
         executeCommand(command.toString(), monitor);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableEvents(java.lang.String, java.lang.String, java.util.List, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
 
@@ -711,10 +676,6 @@ public class LTTngControlService implements ILttngControlService {
 
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableSyscalls(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException {
 
@@ -738,10 +699,6 @@ public class LTTngControlService implements ILttngControlService {
         executeCommand(command.toString(), monitor);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableProbe(java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT);
@@ -768,10 +725,6 @@ public class LTTngControlService implements ILttngControlService {
         executeCommand(command.toString(), monitor);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#enableLogLevel(java.lang.String, java.lang.String, java.lang.String, org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ENABLE_EVENT);
@@ -801,12 +754,6 @@ public class LTTngControlService implements ILttngControlService {
         executeCommand(command.toString(), monitor);
     }
 
-
-
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#disableEvent(java.lang.String, java.lang.String, java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_DISABLE_EVENT);
@@ -848,10 +795,6 @@ public class LTTngControlService implements ILttngControlService {
         executeCommand(command.toString(), monitor);
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
 
@@ -886,10 +829,6 @@ public class LTTngControlService implements ILttngControlService {
         return contexts;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_ADD_CONTEXT);
@@ -924,17 +863,9 @@ public class LTTngControlService implements ILttngControlService {
 
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#calibrate(boolean, org.eclipse.core.runtime.IProgressMonitor)
-     */
     @Override
     public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
-//        String newSessionName = formatParameter(sessionName);
         StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_CALIBRATE);
-//
-//        command.append(OPTION_SESSION);
-//        command.append(newSessionName);
 
         if (isKernel) {
             command.append(LTTngControlServiceConstants.OPTION_KERNEL);
@@ -950,6 +881,7 @@ public class LTTngControlService implements ILttngControlService {
     // ------------------------------------------------------------------------
     // Helper methods
     // ------------------------------------------------------------------------
+
     /**
      * Checks if command result is an error result.
      *
@@ -1210,10 +1142,6 @@ public class LTTngControlService implements ILttngControlService {
             } else {
                 index++;
             }
-//            else if (line.matches(EVENT_NONE_PATTERN)) {
-                // do nothing
-//            } else
-
         }
 
         return index;
This page took 0.027808 seconds and 5 git commands to generate.