예제 #1
0
        public void ReportUnusedPrivileges()
        {
            APICheckerWindowTaskProvider taskWindow = APICheckerWindowTaskProvider.CreateProvider(this.ServiceProvider);

            string[] lines = System.IO.File.ReadAllLines(manifestFile);
            foreach (KeyValuePair <string, bool> entry in privilegeMap)
            {
                if (entry.Value == false)
                {
                    string warnMsg   = string.Format("The privilege {0} is unused", entry.Key);
                    int    lineNum   = 0;
                    int    columnNum = 0;
                    foreach (string line in lines)
                    {
                        columnNum = line.IndexOf(entry.Key);
                        if (columnNum > -1)
                        {
                            break;
                        }

                        lineNum++;
                    }

                    taskWindow.ReportUnusedPrivileges(warnMsg, lineNum, columnNum, manifestFile);
                }
            }
        }
예제 #2
0
        public static APICheckerWindowTaskProvider CreateProvider(IServiceProvider parent)
        {
            if (taskProvider == null)
            {
                taskProvider = new APICheckerWindowTaskProvider(parent);
                taskProvider.ProviderName = "APIViolations";
            }

            return(taskProvider);
        }
예제 #3
0
        private void CheckPrivilegeViolations(string apiname, XmlNodeList nodes, string lineStr, string columnStr, string filename)
        {
            List <string> RequiredPrivileges = new List <string>();

            foreach (XmlNode node in nodes)
            {
                string privilege = node.InnerText;
                privilege = privilege.Trim();
                if (privilegeMap.ContainsKey(privilege) == false)
                {
                    RequiredPrivileges.Add(privilege);
                }
                else
                {
                    // Indicates the privilege is used.
                    privilegeMap[privilege] = true;
                }
            }

            int count = RequiredPrivileges.Count;

            if (count != 0)
            {
                int  line, column;
                bool isValidLine  = Int32.TryParse(lineStr, out line);
                bool isValidColum = Int32.TryParse(columnStr, out column);
                if (!isValidLine || !isValidColum)
                {
                    line = column = 0;
                }

                APICheckerWindowTaskProvider taskWindow = APICheckerWindowTaskProvider.CreateProvider(this.ServiceProvider);
                taskWindow.ReportMissingPrivileges(RequiredPrivileges, apiname, line, column, filename, manifestFile);
                //taskWindow.ReportViolations(errorMsg, line, column, filename);
            }
        }
예제 #4
0
        private void RunAPIChecker()
        {
            outpane.Clear();
            outpane.OutputString("===================Running API and Privilege Checker================ \n");

            APICheckerWindowTaskProvider taskWindow = APICheckerWindowTaskProvider.CreateProvider(this.ServiceProvider);

            taskWindow.ClearError();

            symbolMap = new Dictionary <ISymbol, string>();

            var componentModel = (IComponentModel)this.ServiceProvider.GetService(typeof(SComponentModel));
            var workspace      = componentModel?.GetService <Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>();
            var soln           = workspace.CurrentSolution;

            if (soln == null)
            {
                outpane.OutputString("Select a solution\n");
                return;
            }

            ProjectDependencyGraph projectGraph = soln.GetProjectDependencyGraph();

            foreach (ProjectId projectId in projectGraph.GetTopologicallySortedProjects())
            {
                Project       proj          = soln.GetProject(projectId);
                List <string> privilegeList = new List <string>();
                string        apiversion    = "";
                var           projFile      = proj.FilePath;
                var           projPath      = projFile.Substring(0, projFile.LastIndexOf("\\") + 1);
                var           manifestPath  = projPath + "tizen-manifest.xml";

                if (File.Exists(manifestPath))
                {
                    XmlDocument XDoc = new XmlDocument();
                    XDoc.Load(manifestPath);
                    XmlNodeList nodes = XDoc.GetElementsByTagName("privilege");
                    foreach (XmlNode node in nodes)
                    {
                        privilegeList.Add(node.InnerText);
                    }

                    nodes = XDoc.GetElementsByTagName("manifest");
                    if (nodes.Count > 0)
                    {
                        XmlAttributeCollection attribute = nodes[0].Attributes;
                        for (int ii = 0; ii < attribute.Count; ++ii)
                        {
                            string name = attribute[ii].Name;
                            if (name == "api-version")
                            {
                                apiversion = attribute[ii].Value;
                                break;
                            }
                        }
                    }
                }

                if (apiversion == "")
                {
                    continue;
                }

                //Create a new Analyzer for this project.
                analyzer = new Analyzer(apiversion, privilegeList, manifestPath, this.ServiceProvider);

                //Get Compilation
                Compilation projectCompilation = proj.GetCompilationAsync().Result;
                if (null == projectCompilation || string.IsNullOrEmpty(projectCompilation.AssemblyName))
                {
                    continue;
                }

                //Run Analysis on each file in this project
                foreach (var syntaxTree in projectCompilation.SyntaxTrees)
                {
                    SemanticModel model = projectCompilation.GetSemanticModel(syntaxTree);
                    RunAnalysis(model, syntaxTree, apiversion, privilegeList);
                }

                analyzer.ReportUnusedPrivileges();
            }

            outpane.OutputString("===================API and Privilege Completed================ \n");
        }