コード例 #1
0
        private List <CoverageFile> BuildCoverageFiles(PathProcessor pathProcessor, bool useRelativePaths, List <FileCoverageData> coverageData)
        {
            // This needs attention, since this is optional if source is on public github
            var files = coverageData.Select(coverageFileData =>
            {
                var coverageBuilder = new CoverageFileBuilder(coverageFileData);

                var path = coverageFileData.FullPath;
                if (useRelativePaths)
                {
                    path = pathProcessor.ConvertPath(coverageFileData.FullPath);
                }

                path = PathProcessor.UnixifyPath(path);
                coverageBuilder.SetPath(path);

                if (!coverageBuilder.HasSource())
                {
                    var readAllText = _fileLoader.TryLoadFile(coverageFileData.FullPath);
                    if (readAllText.HasValue)
                    {
                        coverageBuilder.AddSource((string)readAllText);
                    }
                }

                var coverageFile = coverageBuilder.CreateFile();
                return(coverageFile);
            }).ToList();

            return(files);
        }
コード例 #2
0
        public List <CoverageFile> GenerateSourceFiles(XDocument document, bool useRelativePaths)
        {
            var sourceFiles = new List <CoverageFile> ();

            if (document.Root == null)
            {
                return(sourceFiles);
            }

            var filesUsed = document.Root.Elements("method").Where(m => !string.IsNullOrEmpty(m.Attribute("filename").Value)).Select(m => (m.Attribute("filename").Value));

            foreach (var fullpath in filesUsed)
            {
                var path = fullpath;
                if (useRelativePaths)
                {
                    path = _pathProcessor.ConvertPath(path);
                }
                path = _pathProcessor.UnixifyPath(path);

                var coverageBuilder = new CoverageFileBuilder(path);

                foreach (var method in document.Root.Elements("method").Where(m => (m.Attribute("filename").Value == fullpath)))
                {
                    foreach (var sequencePoint in method.Elements("statement"))
                    {
                        var line  = int.Parse(sequencePoint.Attribute("line").Value);
                        var count = int.Parse(sequencePoint.Attribute("counter").Value);

                        coverageBuilder.RecordCoverage(line, count);
                    }
                }

                var readAllText = _fileSystem.TryLoadFile(fullpath);
                if (readAllText != null)
                {
                    Console.WriteLine("{0}", readAllText);
                    coverageBuilder.AddSource(readAllText);
                }
                var coverageFile = coverageBuilder.CreateFile();
                sourceFiles.Add(coverageFile);
            }

            return(sourceFiles);
        }
コード例 #3
0
ファイル: MonoProfParser.cs プロジェクト: iainx/coveralls.net
		public List<CoverageFile> GenerateSourceFiles(XDocument document, bool useRelativePaths)
		{
			var sourceFiles = new List<CoverageFile> ();

			if (document.Root == null) {
				return sourceFiles;
			}

			var filesUsed = document.Root.Elements ("method").Where (m => !string.IsNullOrEmpty(m.Attribute("filename").Value)).Select (m => (m.Attribute ("filename").Value));
			foreach (var fullpath in filesUsed) {
				var path = fullpath;
				if (useRelativePaths)
				{
					path = _pathProcessor.ConvertPath(path);
				}
				path = _pathProcessor.UnixifyPath (path);

				var coverageBuilder = new CoverageFileBuilder (path);

				foreach (var method in document.Root.Elements ("method").Where (m => (m.Attribute ("filename").Value == fullpath))) {
					foreach (var sequencePoint in method.Elements ("statement")) {
						var line = int.Parse (sequencePoint.Attribute ("line").Value);
						var count = int.Parse (sequencePoint.Attribute ("counter").Value);

						coverageBuilder.RecordCoverage (line, count);
					}
				}

				var readAllText = _fileSystem.TryLoadFile(fullpath);
				if (readAllText != null)
				{
					Console.WriteLine ("{0}", readAllText);
					coverageBuilder.AddSource(readAllText);
				}
				var coverageFile = coverageBuilder.CreateFile();
				sourceFiles.Add (coverageFile);
			}

			return sourceFiles;
		}
コード例 #4
0
ファイル: Program.cs プロジェクト: llenroc/coveralls.net
        public static void Main(string[] argv)
        {
            var    args = new MainArgs(argv, exit: true, version: (string)GetDisplayVersion());
            string repoToken;

            if (args.IsProvided("--repoToken"))
            {
                repoToken = args.OptRepotoken;
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoToken is required.");
                }
            }
            else
            {
                var variable = args.OptRepotokenvariable;
                if (variable.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoTokenVariable is required.");
                }

                repoToken = Environment.GetEnvironmentVariable(variable);
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("No token found in Environment Variable '{0}'.".FormatWith(variable));
                }
            }
            var outputFile = args.IsProvided("--output") ? args.OptOutput : string.Empty;

            if (!string.IsNullOrWhiteSpace(outputFile) && File.Exists(outputFile))
            {
                Console.WriteLine("output file '{0}' already exists and will be overwritten.", outputFile);
            }

            var pathProcessor = new PathProcessor(args.IsProvided("--basePath") ? args.OptBasepath : null);

            List <CoverageFile> files;

            if (args.IsProvided("--monocov") && args.OptMonocov)
            {
                var fileName = args.OptInput;
                if (!Directory.Exists(fileName))
                {
                    ExitWithError("Input file '" + fileName + "' cannot be found");
                }
                Dictionary <string, XDocument> documents =
                    new DirectoryInfo(fileName).GetFiles()
                    .Where(f => f.Name.EndsWith(".xml"))
                    .ToDictionary(f => f.Name, f => XDocument.Load(f.FullName));

                files = new MonoCoverParser(pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
            }
            else
            {
                List <FileCoverageData> coverageData;
                if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new DynamicCodeCoverageParser().GenerateSourceFiles(document);
                }
                else if (args.IsProvided("--exportcodecoverage") && args.OptExportcodecoverage)
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new ExportCodeCoverageParser().GenerateSourceFiles(document);
                }
                else
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new OpenCoverParser().GenerateSourceFiles(document);
                }

                files = coverageData.Select(coverageFileData =>
                {
                    var coverageBuilder = new CoverageFileBuilder(coverageFileData);

                    var path = coverageFileData.FullPath;
                    if (args.OptUserelativepaths)
                    {
                        path = pathProcessor.ConvertPath(coverageFileData.FullPath);
                    }
                    path = pathProcessor.UnixifyPath(path);
                    coverageBuilder.SetPath(path);

                    var readAllText = new FileSystem().TryLoadFile(coverageFileData.FullPath);
                    if (readAllText.HasValue)
                    {
                        coverageBuilder.AddSource((string)readAllText);
                    }

                    var coverageFile = coverageBuilder.CreateFile();
                    return(coverageFile);
                }).ToList();
            }

            var gitData = ResolveGitData(args);

            var serviceJobId  = ResolveServiceJobId(args);
            var pullRequestId = ResolvePullRequestId(args);

            string serviceName = args.IsProvided("--serviceName") ? args.OptServicename : "coveralls.net";
            var    data        = new CoverallData
            {
                RepoToken     = repoToken,
                ServiceJobId  = serviceJobId.ValueOr("0"),
                ServiceName   = serviceName,
                PullRequestId = pullRequestId.ValueOr(null),
                SourceFiles   = files.ToArray(),
                Git           = gitData.ValueOrDefault()
            };

            var fileData = JsonConvert.SerializeObject(data);

            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploadResult = new CoverallsService().Upload(fileData);
                if (!uploadResult.Successful)
                {
                    var message = string.Format("Failed to upload to coveralls\n{0}", uploadResult.Error);
                    if (args.OptTreatuploaderrorsaswarnings)
                    {
                        Console.WriteLine(message);
                    }
                    else
                    {
                        ExitWithError(message);
                    }
                }
                else
                {
                    Console.WriteLine("Coverage data uploaded to coveralls.");
                }
            }
        }
コード例 #5
0
        public List<CoverageFile> GenerateSourceFiles(XDocument document, bool useRelativePaths)
        {
            var files = new List<CoverageFile>();
            if (document.Root != null)
            {
                var xElement = document.Root.Element("modules");
                if (xElement != null)
                    foreach (var module in xElement.Elements("module"))
                    {
                        var filesElement = module.Element("source_files");
                        if (filesElement != null)
                        {
                            foreach (var file in filesElement.Elements("source_file"))
                            {
                                var fileid = file.Attribute("id").Value;
                                var fullPath = file.Attribute("path").Value;
                                var path = fullPath;
                                if (useRelativePaths)
                                {
                                    path = _pathProcessor.ConvertPath(fullPath);
                                }
                                path = _pathProcessor.UnixifyPath(path);
                                var coverageBuilder = new CoverageFileBuilder(path);

                                var classesElement = module.Element("functions");
                                if (classesElement != null)
                                {
                                    foreach (var @class in classesElement.Elements("function"))
                                    {
                                        var ranges = @class.Element("ranges");
                                        if (ranges != null)
                                        {
                                            foreach (var range in ranges.Elements("range"))
                                            {
                                                var rangeFileId = range.Attribute("source_id").Value;
                                                if (fileid == rangeFileId)
                                                {
                                                    var sourceStartLine = int.Parse(range.Attribute("start_line").Value);
                                                    var sourceEndLine = int.Parse(range.Attribute("end_line").Value);
                                                    var covered = range.Attribute("covered").Value == "yes";

                                                    foreach (
                                                        var lineNumber in
                                                            Enumerable.Range(sourceStartLine,
                                                                sourceEndLine - sourceStartLine + 1))
                                                    {
                                                        coverageBuilder.RecordCoverage(lineNumber, covered ? 1 : 0);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                var readAllText = _fileSystem.TryLoadFile(fullPath);
                                if (readAllText != null)
                                {
                                    coverageBuilder.AddSource(readAllText);
                                }
                                var coverageFile = coverageBuilder.CreateFile();
                                files.Add(coverageFile);
                            }
                        }
                    }
            }
            return files;
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: AndersAbel/coveralls.net
        public static void Main(string[] argv)
        {
            var args = new MainArgs(argv, exit: true, version: (string)GetDisplayVersion());
            string repoToken;
            if (args.IsProvided("--repoToken"))
            {
                repoToken = args.OptRepotoken;
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoToken is required.");
                }
            }
            else
            {
                var variable = args.OptRepotokenvariable;
                if (variable.IsNullOrWhitespace())
                {
                    ExitWithError("parameter repoTokenVariable is required.");
                }

                repoToken = Environment.GetEnvironmentVariable(variable);
                if (repoToken.IsNullOrWhitespace())
                {
                    ExitWithError("No token found in Environment Variable '{0}'.".FormatWith(variable));
                }

            }
            var outputFile = args.IsProvided("--output") ? args.OptOutput : string.Empty;
            if (!string.IsNullOrWhiteSpace(outputFile) && File.Exists(outputFile))
            {
                Console.WriteLine("output file '{0}' already exists and will be overwritten.", outputFile);
            }

            var pathProcessor = new PathProcessor(args.IsProvided("--basePath") ? args.OptBasepath : null);

            List<CoverageFile> files;
            if (args.IsProvided("--monocov") && args.OptMonocov)
            {
                var fileName = args.OptInput;
                if (!Directory.Exists(fileName))
                {
                    ExitWithError("Input file '" + fileName + "' cannot be found");
                }
                Dictionary<string, XDocument> documents =
                    new DirectoryInfo(fileName).GetFiles()
                        .Where(f => f.Name.EndsWith(".xml"))
                        .ToDictionary(f => f.Name, f => XDocument.Load(f.FullName));

                files = new MonoCoverParser(pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
            }
            else
            {
                List<FileCoverageData> coverageData;
                if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new DynamicCodeCoverageParser().GenerateSourceFiles(document);
                }
                else
                {
                    var fileName = args.OptInput;
                    if (!File.Exists(fileName))
                    {
                        ExitWithError("Input file '" + fileName + "' cannot be found");
                    }

                    var document = XDocument.Load(fileName);

                    coverageData = new OpenCoverParser().GenerateSourceFiles(document);
                }

                files = coverageData.Select(coverageFileData =>
                {
                    var coverageBuilder = new CoverageFileBuilder(coverageFileData);

                    var path = coverageFileData.FullPath;
                    if (args.OptUserelativepaths)
                    {
                        path = pathProcessor.ConvertPath(coverageFileData.FullPath);
                    }
                    path = pathProcessor.UnixifyPath(path);
                    coverageBuilder.SetPath(path);

                    var readAllText = new FileSystem().TryLoadFile(coverageFileData.FullPath);
                    if (readAllText.HasValue)
                    {
                        coverageBuilder.AddSource((string)readAllText);
                    }

                    var coverageFile = coverageBuilder.CreateFile();
                    return coverageFile;
                }).ToList();
            }

            var gitData = ResolveGitData(args);

            var serviceJobId = ResolveServiceJobId(args);

            string serviceName = args.IsProvided("--serviceName") ? args.OptServicename : "coveralls.net";
            var data = new CoverallData
            {
                RepoToken = repoToken,
                ServiceJobId = serviceJobId.ValueOr("0"),
                ServiceName = serviceName,
                SourceFiles = files.ToArray(),
                Git = gitData.ValueOrDefault()
            };

            var fileData = JsonConvert.SerializeObject(data);
            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploadResult = new CoverallsService().Upload(fileData);
                if (!uploadResult.Successful)
                {
                    var message = string.Format("Failed to upload to coveralls\n{0}", uploadResult.Error);
                    if (args.OptTreatuploaderrorsaswarnings)
                    {
                        Console.WriteLine(message);
                    }
                    else
                    {
                        ExitWithError(message);
                    }
                }
            }
        }
コード例 #7
0
        public List <CoverageFile> GenerateSourceFiles(XDocument document, bool useRelativePaths)
        {
            var files = new List <CoverageFile>();

            if (document.Root != null)
            {
                var xElement = document.Root.Element("modules");
                if (xElement != null)
                {
                    foreach (var module in xElement.Elements("module"))
                    {
                        var filesElement = module.Element("source_files");
                        if (filesElement != null)
                        {
                            foreach (var file in filesElement.Elements("source_file"))
                            {
                                var fileid   = file.Attribute("id").Value;
                                var fullPath = file.Attribute("path").Value;
                                var path     = fullPath;
                                if (useRelativePaths)
                                {
                                    path = _pathProcessor.ConvertPath(fullPath);
                                }
                                path = _pathProcessor.UnixifyPath(path);
                                var coverageBuilder = new CoverageFileBuilder(path);

                                var classesElement = module.Element("functions");
                                if (classesElement != null)
                                {
                                    foreach (var @class in classesElement.Elements("function"))
                                    {
                                        var ranges = @class.Element("ranges");
                                        if (ranges != null)
                                        {
                                            foreach (var range in ranges.Elements("range"))
                                            {
                                                var rangeFileId = range.Attribute("source_id").Value;
                                                if (fileid == rangeFileId)
                                                {
                                                    var sourceStartLine = int.Parse(range.Attribute("start_line").Value);
                                                    var sourceEndLine   = int.Parse(range.Attribute("end_line").Value);
                                                    var covered         = range.Attribute("covered").Value == "yes";

                                                    foreach (
                                                        var lineNumber in
                                                        Enumerable.Range(sourceStartLine,
                                                                         sourceEndLine - sourceStartLine + 1))
                                                    {
                                                        coverageBuilder.RecordCoverage(lineNumber, covered ? 1 : 0);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                var readAllText = _fileSystem.TryLoadFile(fullPath);
                                if (readAllText != null)
                                {
                                    coverageBuilder.AddSource(readAllText);
                                }
                                var coverageFile = coverageBuilder.CreateFile();
                                files.Add(coverageFile);
                            }
                        }
                    }
                }
            }
            return(files);
        }
コード例 #8
0
        public List <CoverageFile> GenerateSourceFiles(XDocument document)
        {
            var files = new List <CoverageFile>();

            if (document.Root != null)
            {
                var xElement = document.Root.Element("Modules");
                if (xElement != null)
                {
                    foreach (var module in xElement.Elements("Module"))
                    {
                        var attribute = module.Attribute("skippedDueTo");
                        if (attribute == null || string.IsNullOrEmpty(attribute.Value))
                        {
                            var filesElement = module.Element("Files");
                            if (filesElement != null)
                            {
                                foreach (var file in filesElement.Elements("File"))
                                {
                                    var fileid             = file.Attribute("uid").Value;
                                    var fullPath           = file.Attribute("fullPath").Value;
                                    var compatibleFilePath = UnixifyPath(fullPath);
                                    var coverageBuilder    = new CoverageFileBuilder(compatibleFilePath);

                                    var classesElement = module.Element("Classes");
                                    if (classesElement != null)
                                    {
                                        foreach (var @class in classesElement.Elements("Class"))
                                        {
                                            var methods = @class.Element("Methods");
                                            if (methods != null)
                                            {
                                                foreach (var method in methods.Elements("Method"))
                                                {
                                                    var sequencePointsElement = method.Element("SequencePoints");
                                                    if (sequencePointsElement != null)
                                                    {
                                                        foreach (var sequencePoint in sequencePointsElement.Elements("SequencePoint"))
                                                        {
                                                            var sequenceFileid = sequencePoint.Attribute("fileid").Value;
                                                            if (fileid == sequenceFileid)
                                                            {
                                                                var sourceLine = int.Parse(sequencePoint.Attribute("sl").Value);
                                                                var visitCount = int.Parse(sequencePoint.Attribute("vc").Value);

                                                                coverageBuilder.RecordCoverage(sourceLine, visitCount);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    var readAllText = _fileSystem.TryLoadFile(fullPath);
                                    if (readAllText != null)
                                    {
                                        coverageBuilder.AddSource(readAllText);
                                    }
                                    var coverageFile = coverageBuilder.CreateFile();
                                    files.Add(coverageFile);
                                }
                            }
                        }
                    }
                }
            }
            return(files);
        }
コード例 #9
0
        public List<CoverageFile> GenerateSourceFiles(XDocument document, bool useRelativePaths)
        {
            var files = new List<CoverageFile>();
            if (document.Root != null)
            {
                var xElement = document.Root.Element("Modules");
                if (xElement != null)
                    foreach (var module in xElement.Elements("Module"))
                    {
                        var attribute = module.Attribute("skippedDueTo");
                        if (attribute == null || string.IsNullOrEmpty(attribute.Value))
                        {
                            var filesElement = module.Element("Files");
                            if (filesElement != null)
                            {
                                foreach (var file in filesElement.Elements("File"))
                                {
                                    var fileid = file.Attribute("uid").Value;
                                    var fullPath = file.Attribute("fullPath").Value;
                                    var path = fullPath;
                                    if (useRelativePaths)
                                    {
                                        path = _pathProcessor.ConvertPath(fullPath);
                                    }
                                    path = _pathProcessor.UnixifyPath(path);
                                    var coverageBuilder = new CoverageFileBuilder(path);

                                    var classesElement = module.Element("Classes");
                                    if (classesElement != null)
                                    {
                                        foreach (var @class in classesElement.Elements("Class"))
                                        {
                                            var methods = @class.Element("Methods");
                                            if (methods != null)
                                                foreach (var method in methods.Elements("Method"))
                                                {
                                                    var sequencePointsElement = method.Element("SequencePoints");
                                                    if (sequencePointsElement != null)
                                                        foreach (var sequencePoint in sequencePointsElement.Elements("SequencePoint"))
                                                        {
                                                            var sequenceFileid = sequencePoint.Attribute("fileid").Value;
                                                            if (fileid == sequenceFileid)
                                                            {
                                                                var sourceLine = int.Parse(sequencePoint.Attribute("sl").Value);
                                                                var visitCount = int.Parse(sequencePoint.Attribute("vc").Value);

                                                                coverageBuilder.RecordCoverage(sourceLine, visitCount);
                                                            }

                                                        }
                                                }
                                        }
                                    }

                                    var readAllText = _fileSystem.TryLoadFile(fullPath);
                                    if (readAllText != null)
                                    {
                                        coverageBuilder.AddSource(readAllText);
                                    }
                                    var coverageFile = coverageBuilder.CreateFile();
                                    files.Add(coverageFile);
                                }
                            }
                        }
                    }
            }
            return files;
        }