/// <summary>
        /// The is rule enabled with repo.
        /// </summary>
        /// <param name="profile">
        /// The profile.
        /// </param>
        /// <param name="idWithRepository">
        /// The id with repository.
        /// </param>
        /// <returns>
        /// The <see cref="Rule"/>.
        /// </returns>
        public static Rule IsRuleEnabled(Profile profile, string idWithRepository)
        {
            if (profile == null)
            {
                return null;
            }

            return profile.Rules.FirstOrDefault(rule => (rule.Repo + "." + rule.Key).Equals(idWithRepository));
        }
 /// <summary>
 /// The reset profile.
 /// </summary>
 public void ResetProfile()
 {
     this.profile = null;
 }
Esempio n. 3
0
 /// <summary>
 /// The run sensor.
 /// </summary>
 /// <param name="output">
 /// The output.
 /// </param>
 /// <param name="file">
 /// The file.
 /// </param>
 /// <param name="sensor">
 /// The sensor.
 /// </param>
 /// <param name="projectIn">
 /// The project in.
 /// </param>
 /// <param name="profileIn">
 /// The profile in.
 /// </param>
 /// <param name="changedlines">
 /// The changedlines.
 /// </param>
 /// <param name="sourceRef">
 /// The source ref.
 /// </param>
 /// <param name="issuesToReturn">
 /// The issues to return.
 /// </param>
 private void RunSensor(
     EventHandler output,
     VsProjectItem file,
     KeyValuePair<string, ASensor> sensor,
     Resource projectIn,
     Profile profileIn,
     bool changedlines,
     string sourceRef,
     List<Issue> issuesToReturn)
 {
     ICommandExecutor exec = new CommandExecutor(null, 10);
     try
     {
         FSharpList<string> lines = sensor.Value.LaunchSensor(this, output, file.FilePath, exec);
         this.ProcessSensorsIssues(
             sensor.Key,
             lines,
             file,
             projectIn,
             profileIn,
             changedlines,
             sourceRef,
             issuesToReturn);
     }
     catch (Exception ex)
     {
         CxxPlugin.WriteLogMessage(
             this,
             this.StdOutEvent,
             sensor.Key + " : Exception on Analysis Plugin : " + this.filePathToAnalyse + " " + ex.StackTrace);
         CxxPlugin.WriteLogMessage(this, this.StdOutEvent, sensor.Key + " : StdError: " + exec.GetStdError);
         CxxPlugin.WriteLogMessage(this, this.StdOutEvent, sensor.Key + " : StdOut: " + exec.GetStdError);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// The process sensors issues.
        /// </summary>
        /// <param name="key">
        /// The key.
        /// </param>
        /// <param name="sensorReportedLines">
        /// The sensor reported lines.
        /// </param>
        /// <param name="itemInView">
        /// The item in view.
        /// </param>
        /// <param name="projectIn">
        /// The project in.
        /// </param>
        /// <param name="profileIn">
        /// The profile in.
        /// </param>
        /// <param name="modfiedLines">
        /// The modfied lines.
        /// </param>
        /// <param name="fileSourceRef">
        /// The file source ref.
        /// </param>
        /// <param name="issuesToReturn">
        /// The issues to return.
        /// </param>
        private void ProcessSensorsIssues(
            string key,
            FSharpList<string> sensorReportedLines,
            VsProjectItem itemInView,
            Resource projectIn,
            Profile profileIn,
            bool modfiedLines,
            string fileSourceRef,
            List<Issue> issuesToReturn)
        {
            var issuesPerTool = new List<Issue>();

            if (this.options.ContainsKey(projectIn.Key + ".IsDebugChecked")
                && this.options[projectIn.Key + ".IsDebugChecked"].Equals("true"))
            {
                foreach (string line in sensorReportedLines)
                {
                    CxxPlugin.WriteLogMessage(this, this.StdOutEvent, "[" + key + "] : " + line);
                }
            }

            try
            {
                List<Issue> issuesInTool = this.sensors[key].GetViolations(sensorReportedLines);
                foreach (Issue issue in issuesInTool)
                {
                    string path1 = Path.GetFullPath(itemInView.FilePath);
                    string path2 = issue.Component;
                    if (path1.Equals(path2))
                    {
                        issue.Component = this.commandPlugin.GetResourceKey(itemInView, projectIn.Key, false);
                        issue.ComponentSafe = this.commandPlugin.GetResourceKey(itemInView, projectIn.Key, true);
                        Rule ruleInProfile = Profile.IsRuleEnabled(profileIn, issue.Rule);
                        if (ruleInProfile != null)
                        {
                            issue.Severity = ruleInProfile.Severity;
                            issuesPerTool.Add(issue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CxxPlugin.WriteLogMessage(this, this.StdOutEvent, "Exception: " + key + " " + ex.StackTrace);
            }

            lock (this.lockThis)
            {
                try
                {
                    if (modfiedLines)
                    {
                        if (fileSourceRef != null)
                        {
                            ArrayList diffReport = VsSonarUtils.GetSourceDiffFromStrings(
                                itemInView.FilePath,
                                fileSourceRef);
                            issuesToReturn.AddRange(
                                VsSonarUtils.GetIssuesInModifiedLinesOnly(issuesPerTool, diffReport));
                        }
                        else
                        {
                            issuesToReturn.AddRange(issuesPerTool);
                        }
                    }
                    else
                    {
                        issuesToReturn.AddRange(issuesPerTool);
                    }
                }
                catch (Exception)
                {
                    issuesToReturn.AddRange(issuesPerTool);
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// The run sensor thread.
 /// </summary>
 /// <param name="output">
 /// The output.
 /// </param>
 /// <param name="file">
 /// The file.
 /// </param>
 /// <param name="sensor">
 /// The sensor.
 /// </param>
 /// <param name="projectIn">
 /// The project in.
 /// </param>
 /// <param name="profileIn">
 /// The profile in.
 /// </param>
 /// <param name="changedlines">
 /// The changedlines.
 /// </param>
 /// <param name="sourceRef">
 /// The source ref.
 /// </param>
 /// <param name="issuesToReturn">
 /// The issues to return.
 /// </param>
 /// <returns>
 /// The <see cref="Thread"/>.
 /// </returns>
 public Thread RunSensorThread(
     EventHandler output,
     VsProjectItem file,
     KeyValuePair<string, ASensor> sensor,
     Resource projectIn,
     Profile profileIn,
     bool changedlines,
     string sourceRef,
     List<Issue> issuesToReturn)
 {
     var t =
         new Thread(
             () =>
             this.RunSensor(output, file, sensor, projectIn, profileIn, changedlines, sourceRef, issuesToReturn));
     t.Start();
     return t;
 }
Esempio n. 6
0
 /// <summary>
 /// The launch local analysis.
 /// </summary>
 /// <param name="file">
 /// The file.
 /// </param>
 /// <param name="projectIn">
 /// The project In.
 /// </param>
 /// <param name="profileIn">
 /// The profileIn.
 /// </param>
 /// <param name="fileSourceInServer">
 /// The file Source In Server.
 /// </param>
 /// <param name="onModifiedLinesOnly">
 /// The on Modified Lines Only.
 /// </param>
 /// <returns>
 /// The <see cref="Thread"/>.
 /// </returns>
 public Thread GetFileAnalyserThread(
     VsProjectItem file,
     Resource projectIn,
     Profile profileIn,
     string fileSourceInServer,
     bool onModifiedLinesOnly)
 {
     this.sourceInServer = fileSourceInServer;
     this.modifiedLinesOnly = onModifiedLinesOnly;
     this.profile = profileIn;
     this.filePathToAnalyse = file.FilePath;
     this.projectItem = file;
     this.project = projectIn;
     return new Thread(this.LocalFileAnalyserExternalThread);
 }
Esempio n. 7
0
        /// <summary>
        /// The execute analysis on file.
        /// </summary>
        /// <param name="itemInView">
        /// The item In View.
        /// </param>
        /// <param name="externlProfile">
        /// The externl profile.
        /// </param>
        /// <param name="projectIn">
        /// The project.
        /// </param>
        /// <returns>
        /// The <see>
        ///         <cref>List</cref>
        ///     </see>
        ///     .
        /// </returns>
        public List<Issue> ExecuteAnalysisOnFile(VsProjectItem itemInView, Profile externlProfile, Resource projectIn)
        {
            var threads = new List<Thread>();
            var allIssues = new List<Issue>();
            this.options = this.pluginOptions.GetOptions();

            foreach (var sensor in this.sensors)
            {
                CxxPlugin.WriteLogMessage(
                    this,
                    this.StdOutEvent,
                    "Launching  Analysis on: " + sensor.Key + " " + itemInView.FilePath);
                threads.Add(
                    this.RunSensorThread(
                        this.StdOutEvent,
                        itemInView,
                        sensor,
                        projectIn,
                        externlProfile,
                        false,
                        string.Empty,
                        allIssues));
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }

            return allIssues;
        }