コード例 #1
0
        /// <summary>
        /// Wases the assembly updated.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns>True if Assemly has been modified</returns>
        private bool WasAssemblyUpdated(VsProjectItem project)
        {
            if (this.projectBuildCache.ContainsKey(project.OutputPath))
            {
                var lastUpdateTime    = this.projectBuildCache[project.OutputPath];
                var currentUpdateTime = this.GetUpdateTimeFromAssembly(project.OutputPath);

                if (currentUpdateTime > lastUpdateTime)
                {
                    this.projectBuildCache.Remove(project.OutputPath);
                    this.projectBuildCache.Add(project.OutputPath, currentUpdateTime);
                    return(true);
                }
            }
            else
            {
                var currentUpdateTime = this.GetUpdateTimeFromAssembly(project.OutputPath);
                this.projectBuildCache.Add(project.OutputPath, currentUpdateTime);
                return(true);
            }

            this.notificationManager.ReportMessage(new VSSonarPlugins.Message {
                Id = "LocalViewModel", Data = "Project output is Updated"
            });
            return(false);
        }
コード例 #2
0
        /// <summary>The trigger a project analysis.</summary>
        /// <param name="project">The project.</param>
        public void TriggerAProjectAnalysis(VsProjectItem project)
        {
            if (this.FileAnalysisIsEnabled && this.WasAssemblyUpdated(project))
            {
                var isProjectAnalysisOn = true;

                try
                {
                    isProjectAnalysisOn = bool.Parse(
                        this.configurationHelper.ReadSetting(Context.AnalysisGeneral, OwnersId.AnalysisOwnerId, GlobalAnalysisIds.LocalAnalysisProjectAnalysisEnabledKey).Value);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                if (isProjectAnalysisOn)
                {
                    this.localAnalyserModule.RunProjectAnalysis(project, AuthtenticationHelper.AuthToken);
                }
                else
                {
                    this.notificationManager.ReportMessage(new VSSonarPlugins.Message {
                        Id = "LocalViewModel", Data = "Project Analysis Is Disabled, Enable in Options"
                    });
                }
            }
        }
コード例 #3
0
        /// <summary>The vs project item.</summary>
        /// <param name="filename">The filename.</param>
        /// <param name="associatedProject">The associated project.</param>
        /// <returns>The <see cref="VsProjectItem"/>.</returns>
        public VsProjectItem VsProjectItem(string filename, Resource associatedProject)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(null);
            }

            string driveLetter  = filename.Substring(0, 1);
            string projectName  = Path.GetFileNameWithoutExtension(filename);
            string projectPath  = driveLetter + this.GetProperFilePathCapitalization(filename).Substring(1);
            string solutionName = this.ActiveSolutionName();
            string solutionPath = driveLetter + this.ActiveSolutionPath().Substring(1);
            var    itemToReturn =
                new VsProjectItem
            {
                ProjectName     = projectName,
                ProjectFilePath = projectPath,
                Solution        =
                    new VsSolutionItem
                {
                    SolutionName = solutionName,
                    SolutionPath = solutionPath,
                    SonarProject = associatedProject
                }
            };

            return(itemToReturn);
        }
コード例 #4
0
        public void ShouldRunDiagnosticsIfSyncIsFalse()
        {
            var notificaitonManager = new Mock <INotificationManager>();
            var confManager         = new Mock <IConfigurationHelper>();
            var helper          = new Mock <IVsEnvironmentHelper>();
            var rest            = new Mock <ISonarRestService>();
            var dictionaryprops = new Dictionary <string, string>();

            dictionaryprops.Add("sonar.roslyn.sync.type", "false");

            var dictionaryplugins = new Dictionary <string, string>();

            dictionaryplugins.Add("Roslyn", "1.0");

            rest.Setup(caller => caller.GetInstalledPlugins(It.IsAny <ISonarConfiguration>())).Returns(dictionaryplugins);
            rest.Setup(caller => caller.GetProperties(It.IsAny <ISonarConfiguration>(), It.IsAny <Resource>())).Returns(dictionaryprops);


            var             conf   = new ConnectionConfiguration("http://localhost:9000", "admin", "admin", 5.3);
            IAnalysisPlugin plugin = new AnalysisPlugin(notificaitonManager.Object, confManager.Object, rest.Object, helper.Object);

            var project = new Resource();

            project.Key          = "Tekla.Tools.RoslynRunner";
            project.SolutionRoot = Path.Combine(execpath, "TestData");
            project.SolutionName = "RoslynRunner.sln";

            var profiledata = new Dictionary <string, Profile>();
            var profile     = new Profile(null, null);

            profile.AddRule(new Rule {
                Repo = "roslyn-cs", Key = "SA140", IsParamsRetrivedFromServer = true, ConfigKey = "roslyn-cs:SA140"
            });
            profile.AddRule(new Rule {
                Repo = "roslyn-cs", Key = "SA1001", IsParamsRetrivedFromServer = true, ConfigKey = "roslyn-cs:SA1001"
            });
            profile.AddRule(new Rule {
                Repo = "roslyn-cs", Key = "SA1200", IsParamsRetrivedFromServer = true, ConfigKey = "roslyn-cs:SA1200"
            });
            profiledata.Add("cs", profile);

            plugin.AssociateProject(project, conf, profiledata, "14.0");

            var vsfile    = new VsFileItem();
            var vsproject = new VsProjectItem();

            vsproject.ProjectName     = "ClassLibrary1";
            vsproject.ProjectFilePath = Path.Combine(project.SolutionRoot, "ClassLibrary1", "ClassLibrary1.csproj");
            vsfile.Project            = vsproject;
            vsfile.FilePath           = Path.Combine(project.SolutionRoot, "ClassLibrary1", "Class1.cs");
            vsfile.FileName           = "Class1.cs";
            vsfile.SonarResource      = new Resource()
            {
                Key = "ProjectKey"
            };
            var issues = plugin.GetLocalAnalysisExtension(conf).ExecuteAnalysisOnFile(vsfile, project, conf, false);

            Assert.That(issues.Count, Is.EqualTo(5));
        }
コード例 #5
0
        /// <summary>
        /// Creates the vs project item.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns>return vs project it</returns>
        private static VsProjectItem CreateVsProjectItem(ProjectTypes.Project project)
        {
            var proToRet = new VsProjectItem();

            proToRet.ProjectName     = project.Name;
            proToRet.ProjectFilePath = project.Path;
            return(proToRet);
        }
コード例 #6
0
        /// <summary>
        /// Projects the has build.
        /// </summary>
        /// <param name="project">The project.</param>
        public void ProjectHasBuild(VsProjectItem project)
        {
            IAnalysisModelBase analyser = this.SelectedModel;

            if (analyser != null)
            {
                analyser.TriggerAProjectAnalysis(project);
            }
        }
コード例 #7
0
        public VsProjectItem GetProjectByNameInSolution(string projectName)
        {
            if (this.environment == null)
            {
                return(null);
            }

            foreach (Project project in this.environment.Solution.Projects)
            {
                if (project.Name.ToLower().Equals(projectName.ToLower()))
                {
                    var proToRet = new VsProjectItem();
                    proToRet.ProjectName     = project.Name;
                    proToRet.ProjectFilePath = project.FullName;
                    return(proToRet);
                }
            }

            return(null);
        }
コード例 #8
0
 /// <summary>
 /// The trigger a project analysis.
 /// </summary>
 /// <param name="project">The project.</param>
 public void TriggerAProjectAnalysis(VsProjectItem project)
 {
     // server analysis does not trigger project
 }
コード例 #9
0
 /// <summary>
 /// Projects the has build.
 /// </summary>
 /// <param name="project">The project.</param>
 public void ProjectHasBuild(VsProjectItem project)
 {
     IAnalysisModelBase analyser = this.SelectedModel;
     if (analyser != null)
     {
         analyser.TriggerAProjectAnalysis(project);
     }
 }
コード例 #10
0
        /// <summary>The vs project item.</summary>
        /// <param name="filename">The filename.</param>
        /// <param name="associatedProject">The associated project.</param>
        /// <returns>The <see cref="VsProjectItem"/>.</returns>
        public VsProjectItem VsProjectItem(string filename, Resource associatedProject)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return null;
            }

            string driveLetter = filename.Substring(0, 1);
            string projectName = Path.GetFileNameWithoutExtension(filename);
            string projectPath = driveLetter + this.GetProperFilePathCapitalization(filename).Substring(1);
            string solutionName = this.ActiveSolutionName();
            string solutionPath = driveLetter + this.ActiveSolutionPath().Substring(1);
            var itemToReturn =
                new VsProjectItem
                {
                    ProjectName = projectName,
                    ProjectFilePath = projectPath,
                    Solution =
                        new VsSolutionItem
                        {
                            SolutionName = solutionName,
                            SolutionPath = solutionPath,
                            SonarProject = associatedProject
                        }
                };

            return itemToReturn;
        }
コード例 #11
0
 private static VsProjectItem CreateVsProjectItem(Project project)
 {
     var proToRet = new VsProjectItem();
     proToRet.ProjectName = project.Name;
     proToRet.ProjectFilePath = project.FullName;
     return proToRet;
 }
コード例 #12
0
 /// <summary>
 /// The trigger a project analysis.
 /// </summary>
 /// <param name="project">The project.</param>
 public void TriggerAProjectAnalysis(VsProjectItem project)
 {
     // server analysis does not trigger project
 }
コード例 #13
0
        /// <summary>The trigger a project analysis.</summary>
        /// <param name="project">The project.</param>
        public void TriggerAProjectAnalysis(VsProjectItem project)
        {
            if (this.FileAnalysisIsEnabled && this.WasAssemblyUpdated(project))
            {
                var isProjectAnalysisOn = true;

                try
                {
                    isProjectAnalysisOn = bool.Parse(
                        this.configurationHelper.ReadSetting(Context.AnalysisGeneral, OwnersId.AnalysisOwnerId, GlobalAnalysisIds.LocalAnalysisProjectAnalysisEnabledKey).Value);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                if (isProjectAnalysisOn)
                {
                    this.localAnalyserModule.RunProjectAnalysis(project, AuthtenticationHelper.AuthToken);
                }
                else
                {
                    this.notificationManager.ReportMessage(new VSSonarPlugins.Message { Id = "LocalViewModel", Data = "Project Analysis Is Disabled, Enable in Options" });
                }
            }
        }
コード例 #14
0
        /// <summary>
        /// Wases the assembly updated.
        /// </summary>
        /// <param name="project">The project.</param>
        /// <returns>True if Assemly has been modified</returns>
        private bool WasAssemblyUpdated(VsProjectItem project)
        {
            if (this.projectBuildCache.ContainsKey(project.OutputPath))
            {
                var lastUpdateTime = this.projectBuildCache[project.OutputPath];
                var currentUpdateTime = this.GetUpdateTimeFromAssembly(project.OutputPath);

                if (currentUpdateTime > lastUpdateTime)
                {
                    this.projectBuildCache.Remove(project.OutputPath);
                    this.projectBuildCache.Add(project.OutputPath, currentUpdateTime);
                    return true;
                }
            }
            else
            {
                var currentUpdateTime = this.GetUpdateTimeFromAssembly(project.OutputPath);
                this.projectBuildCache.Add(project.OutputPath, currentUpdateTime);
                return true;
            }

            this.notificationManager.ReportMessage(new VSSonarPlugins.Message { Id = "LocalViewModel", Data = "Project output is Updated" });
            return false;
        }
コード例 #15
0
        public VsProjectItem GetProjectByNameInSolution(string projectName)
        {
            if (this.environment == null) { return null; }

            foreach (Project project in this.environment.Solution.Projects)
            {
                if (project.Name.ToLower().Equals(projectName.ToLower()))
                {
                    var proToRet = new VsProjectItem();
                    proToRet.ProjectName = project.Name;
                    proToRet.ProjectFilePath = project.FullName;
                    return proToRet;
                }
            }

            return null;
        }
 /// <summary>The trigger a project analysis.</summary>
 /// <param name="project">The project.</param>
 public void TriggerAProjectAnalysis(VsProjectItem project)
 {
     // is not a analyser
 }
コード例 #17
0
 /// <summary>The trigger a project analysis.</summary>
 /// <param name="project">The project.</param>
 public void TriggerAProjectAnalysis(VsProjectItem project)
 {
     // is not a analyser
 }