Exemplo n.º 1
0
 private void AddSourceFileFullPathHierachy(string basePath, List <string> sourceFileFullPathList)
 {
     try
     {
         FileAttributes attr = File.GetAttributes(basePath);
         if (attr.HasFlag(FileAttributes.Directory)) // IsDirectory
         {
             foreach (string subFile in DexterUtil.GetAllFilesAndDirectoriesInDirectory(basePath))
             {
                 if (hasValidDirectoryName(subFile))
                 {
                     AddSourceFileFullPathHierachy(subFile, sourceFileFullPathList);
                 }
                 else
                 {
                     continue;
                 }
             }
         }
         else
         {
             if (DexterConfig.Instance.IsFileSupportedForAnalysis(basePath) == false)
             {
                 return;
             }
             sourceFileFullPathList.Add(DexterUtil.RefinePath(basePath));
         }
     }
     catch (Exception e)
     {
         CliLog.Error("There is no file :" + e.Message);
         Environment.Exit(0);
     }
 }
Exemplo n.º 2
0
        private void WriteJsonResult(AnalysisResult result, string resultFolderStr)
        {
            StringBuilder contents   = CreateJsonFormat(result);
            FileInfo      resultFile = GetResultFilePath(result, resultFolderStr);

            DexterUtil.WriteFilecontents(contents.ToString(), resultFile);
        }
Exemplo n.º 3
0
        public void CreateInitialFolderAndFiles()
        {
            if (string.IsNullOrEmpty(DexterHome))
            {
                return;
            }
            try
            {
                DexterUtil.CreateFolderIfDoesNotExist(DexterHome);

                string bin = DexterHome + "/bin";
                DexterUtil.CreateFolderIfDoesNotExist(bin);
                DexterUtil.CreateFolderIfDoesNotExist(bin + "/cppcheck");
                DexterUtil.CreateFolderIfDoesNotExist(bin + "/cppcheck/cfg");
                DexterUtil.CreateFolderIfDoesNotExist(bin + "/dexterCS");

                string plugin = DexterHome + "/" + PLUGIN_FOLDER_NAME;
                DexterUtil.CreateFolderIfDoesNotExist(plugin);

                string result = DexterHome + "/" + RESULT_FOLDER_NAME;
                DexterUtil.CreateFolderIfDoesNotExist(result);
                DexterUtil.CreateFolderIfDoesNotExist(result + "/" + OLD_FOLDER_NAME);

                DexterUtil.CreateFolderIfDoesNotExist(DexterHome + "/" + TEMP_FOLDER_NAME);
                DexterUtil.CreateFolderIfDoesNotExist(DexterHome + "/" + LOG_FOLDER_NAME);

                string filter = DexterHome + "/" + FILTER_FOLDER_NAME;
                DexterUtil.CreateFolderIfDoesNotExist(filter);
            }
            catch (IOException)
            {
                CliLog.Error("IOException in DexterConfig");
            }
        }
Exemplo n.º 4
0
        private FileInfo GetResultFilePath(AnalysisResult result, string resultFolderStr)
        {
            string path = resultFolderStr + "/" + GetResultFilePrefixName(result.ModulePath, result.FileName) +
                          "_" + DexterUtil.GetCurrentDateTimeMillis() + ResultFileConstant.RESULT_FILE_EXTENSION;
            FileInfo resultFile = DexterUtil.CreateEmptyFileIfDoesNotExist(path);

            return(resultFile);
        }
Exemplo n.º 5
0
 public static void AssertExclusiveOptions(object firstOption, object secondOption)
 {
     if (DexterUtil.HasOption(firstOption) &&
         DexterUtil.HasOption(secondOption))
     {
         throw new Exception("Cannot use option -" + firstOption + " with option -" + secondOption);
     }
 }
Exemplo n.º 6
0
        private void LoadProjectAnalysisConfiguration()
        {
            ProjectAnalysisConfigurationList = new List <ProjectAnalysisConfiguration>();

            string cfgFilePath = DexterConfig.Instance.DexterHome + CFG_PARM_JSON_FILE;

            DexterUtil.CreateEmptyFileIfNotExist(cfgFilePath);

            string content = DexterUtil.GetContentsFromFile(cfgFilePath);
        }
Exemplo n.º 7
0
 private string GetExistingModuleFullPathWithSourceDirList()
 {
     foreach (string srcDir in SourceDirList)
     {
         string moduleFullPath = DexterUtil.RefinePath(srcDir + "/" + ModulePath);
         if (File.Exists(moduleFullPath))
         {
             return(moduleFullPath);
         }
     }
     return("");
 }
Exemplo n.º 8
0
 public void WriteJsonResultFilePrefix(FileInfo file)
 {
     try
     {
         using (StreamWriter sw = file.AppendText())
         {
             sw.Write("[");
         }
     }
     catch (IOException)
     {
         throw new DexterRuntimeException("Exception in method " + DexterUtil.GetCurrentMethodName());
     }
 }
Exemplo n.º 9
0
 public void WriteXml2ResultFilePrefix(FileInfo file)
 {
     try
     {
         using (StreamWriter sw = file.AppendText())
         {
             sw.WriteLine("<dexter-result created=\"" + DexterUtil.currentDateTime() + "\">");
         }
     }
     catch (IOException)
     {
         throw new DexterRuntimeException("Exception in method " + DexterUtil.GetCurrentMethodName());
     }
 }
Exemplo n.º 10
0
        internal void WriteJson(List <AnalysisResult> resultList)
        {
            if (resultList.Count == 0)
            {
                return;
            }

            string resultFolderStr = DexterConfig.Instance.DexterHome + "/" + DexterConfig.RESULT_FOLDER_NAME;

            DexterUtil.CreateFolderIfNotExist(resultFolderStr);

            IAnalysisEntityFactory factory    = new AnalysisEntityFactory();
            AnalysisResult         baseResult = factory.CreateAnalysisResultList(resultList);

            RemoveOldResultFile(baseResult, resultFolderStr);
            WriteJsonResult(baseResult, resultFolderStr);
        }
Exemplo n.º 11
0
        private List <string> GenerateSourceFileFullPathListAsFolderType()
        {
            string moduleFullPath = GetExistingModuleFullPathWithSourceDirList();

            if (string.IsNullOrEmpty(moduleFullPath))
            {
                return(new List <string>(0));
            }
            List <string> sourceFileFullPathList = new List <String>(10);

            foreach (string filePath in (DexterUtil.getSubFileNames(moduleFullPath)))
            {
                sourceFileFullPathList.Add(filePath);
            }

            return(sourceFileFullPathList);
        }
Exemplo n.º 12
0
 public void AddHeaderAndSourceConfiguration(List <ProjectAnalysisConfiguration> projectAnalysisConfigurationList)
 {
     foreach (var param in projectAnalysisConfigurationList)
     {
         if (param.ProjectName.Equals(ProjectName) &&
             DexterUtil.RefinePath(param.ProjectFullPath).Equals(ProjectFullPath))
         {
             foreach (string dir in param.SourceDirs)
             {
                 AddSourceBaseDirList(dir);
             }
             foreach (string dir in param.HeaderDirs)
             {
                 AddHeaderBaseDirList(dir);
             }
         }
     }
 }
Exemplo n.º 13
0
        public void WriteXmlResultFileBody(FileInfo xmlResultFile, List <Defect> allDefectList, string sourceFileFullPath)
        {
            int           size = allDefectList.Count * 1024;
            StringBuilder m;

            if (size < Int32.MaxValue)
            {
                m = new StringBuilder(size);
            }
            else
            {
                m = new StringBuilder(Int32.MaxValue);
            }

            m.Append("\t<error filename=\"").Append(sourceFileFullPath).Append("\">\n");

            foreach (Defect defect in allDefectList)
            {
                m.Append("\t\t<defect checker=\"").Append(defect.CheckerCode).Append("\">\n");
                foreach (Occurence o in defect.Occurences)
                {
                    m.Append("\t\t\t<occurence startLine=\"").Append(o.StartLine).Append("\" ")
                    .Append("endLine=\"").Append(o.EndLine).Append("\" ")
                    .Append(" message=\"").Append(o.Message.Replace("\"", "&quot;")).Append("\" />\n");
                }
                m.Append("\t\t</defect>\n");
            }

            m.Append("\t</error>\n");

            try
            {
                using (StreamWriter sw = xmlResultFile.AppendText())
                {
                    sw.Write(m.ToString());
                }
            }
            catch (IOException)
            {
                throw new DexterRuntimeException("Exception in method " + DexterUtil.GetCurrentMethodName());
            }
        }
Exemplo n.º 14
0
        public void SetFieldsByCommandLine(DexterCLIOptionSet options)
        {
            String ResultFileName = "." + DexterUtil.FILE_SEPARATOR + "dexter-result";

            SetHostAndPort(options.ServerIp, options.ServerPort);
            this.ServerHostIp = options.ServerIp;
            this.ServerPort   = options.ServerPort;
            this.UserId       = options.UserId;
            this.UserPassword = options.UserPassword;

            if (DexterUtil.HasOption(options.SpecifiedDexterConfigFile))
            {
                this.ConfigFilePath = options.SpecifiedDexterConfigFile;
            }
            else
            {
                this.ConfigFilePath = "./" + DexterConfig.DEXTER_CFG_FILENAME;
            }

            DexterUtil.LogErrorAndExitIfFileDoesNotExist(ConfigFilePath);

            if (DexterUtil.HasOption(options.ResultFormat))
            {
                switch (options.ResultFormat)
                {
                case "xml":
                    this.IsXmlResultFile = true;
                    CreateXmlResultFile(ResultFileName);
                    break;

                case "xml2":
                    this.IsXml2ResultFile = true;
                    break;

                case "json":
                    this.IsJsonResultFile = true;
                    CreateJsonResultFile(ResultFileName);
                    break;
                }
            }
        }
Exemplo n.º 15
0
 private void CheckFolderExistence(dynamic configMetadata)
 {
     DexterUtil.CheckFolderExistence(configMetadata.projectFullPath);
 }
Exemplo n.º 16
0
 public void ChangeDexterHome(string homePath)
 {
     HomePath   = DexterUtil.RefinePath(homePath);
     dexterHome = HomePath;
 }