public void RunsLocalAnalysisWithDummyFile()
        {
            var serviceStub = new Mock<IAnalysisPlugin>();
            var optionsStub = new Mock<IPluginsOptions>();
            var resource = new Resource() { Lang = "c++" };
            var configuration = new ConnectionConfiguration();
            serviceStub.Setup(control => control.GetPluginControlOptions(configuration)).Returns(optionsStub.Object);
            optionsStub.Setup(control => control.GetOptions()).Returns(this.options);

            var localextension = new CxxLocalExtension(serviceStub.Object, configuration);
            localextension.LocalAnalysisCompleted += this.AnalysisCompleted;
            var vsitem = new VsProjectItem(string.Empty, this.fileToAnalyse, string.Empty, string.Empty, string.Empty, string.Empty);
            var thread = localextension.GetFileAnalyserThread(vsitem, resource, new Profile(), string.Empty, false);
            thread.Start();
            thread.Join();
        }
 public bool IsSupported(VsProjectItem fileToAnalyse)
 {
     throw new System.NotImplementedException();
 }
 /// <summary>
 /// The get resource key.
 /// </summary>
 /// <param name="projectItem">
 /// The project item.
 /// </param>
 /// <param name="projectKey">
 /// The project key.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public string GetResourceKey(VsProjectItem projectItem, string projectKey)
 {
     return string.Empty;
 }
Beispiel #4
0
 /// <summary>
 /// The is supported.
 /// </summary>
 /// <param name="fileToAnalyse">
 /// The file to analyse.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool IsSupported(VsProjectItem fileToAnalyse)
 {
     return IsSupported(fileToAnalyse.FileName);
 }
Beispiel #5
0
        /// <summary>
        /// The get resource key.
        /// </summary>
        /// <param name="projectItem">
        /// The project item.
        /// </param>
        /// <param name="projectKey">
        /// The project key.
        /// </param>
        /// <param name="safeGeneration">
        /// The safe generation.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string GetResourceKey(VsProjectItem projectItem, string projectKey, bool safeGeneration)
        {
            if (safeGeneration && projectItem.ProjectName != null)
            {
                string filePath = projectItem.FilePath.Replace("\\", "/");
                string path = Directory.GetParent(projectItem.ProjectFilePath).ToString().Replace("\\", "/");
                string file = filePath.Replace(path + "/", string.Empty);
                return projectKey + ":" + projectItem.ProjectName + ":" + file;
            }

            string filerelativePath = projectItem.FilePath.Replace(projectItem.SolutionPath + "\\", string.Empty).Replace("\\", "/");
            var options = (CxxOptionsController)this.pluginOptions;
            if (string.IsNullOrEmpty(options.ProjectWorkingDir))
            {
                return projectKey + ":" + filerelativePath.Trim();
            }

            string toReplace = options.ProjectWorkingDir.Replace("\\", "/") + "/";
            return projectKey + ":" + filerelativePath.Replace(toReplace, string.Empty).Trim();
        }
 /// <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);
     }
 }
        /// <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);
                }
            }
        }
 /// <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;
 }
 /// <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);
 }
Beispiel #10
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;
        }