Esempio n. 1
0
        public static void Main(string[] argv)
        {
            var args = new MainArgs(argv, exit: true, version: Assembly.GetEntryAssembly().GetName().Version);
            var repoToken = args.OptRepotoken;
            if (string.IsNullOrWhiteSpace(repoToken))
            {
                Console.Error.WriteLine("parameter repoToken is required.");
                Console.WriteLine(MainArgs.Usage);
                Environment.Exit(1);
            }

            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))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
                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 if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new DynamicCodeCoverageParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }
            else if (args.IsProvided("--mprof") && args.OptMprof)
            {
                var fileName = args.OptInput;
                files = null;

                if (File.Exists(fileName)) 
                {
                    var document = XDocument.Load (fileName);

                    files = new MonoProfParser (new FileSystem (), pathProcessor).GenerateSourceFiles (document, args.OptUserelativepaths);
                }
                else if (Directory.Exists(fileName))
                {
                    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 MonoProfParser(new FileSystem(), pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
                }
                else
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
            }
            else
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new OpenCoverParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }

            GitData gitData = null;
            var commitId = args.IsProvided("--commitId") ? args.OptCommitid : string.Empty;
            if (commitId.IsNotNullOrWhitespace())
            {
                var committerName = args.OptCommitauthor ?? string.Empty;
                var comitterEmail = args.OptCommitemail ?? string.Empty;
                var commitMessage = args.OptCommitmessage ?? string.Empty;
                gitData = new GitData
                {
                    Head = new GitHead
                    {
                        Id = commitId,
                        AuthorName = committerName,
                        AuthorEmail = comitterEmail,
                        CommitterName = committerName,
                        ComitterEmail = comitterEmail,
                        Message = commitMessage
                    },
                    Branch = args.OptCommitbranch ?? string.Empty
                };
            }

            var serviceJobId = args.IsProvided("--jobId") ? args.OptJobid : "0";

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

            var fileData = JsonConvert.SerializeObject(data);
            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploaded = Upload(@"https://coveralls.io/api/v1/jobs", fileData);
                if (!uploaded)
                {
                    Console.Error.WriteLine("Failed to upload to coveralls");
                    Environment.Exit(1);
                }
            }
        }
Esempio n. 2
0
        public static void Main(string[] argv)
        {
            var args      = new MainArgs(argv, exit: true, version: Assembly.GetEntryAssembly().GetName().Version);
            var repoToken = args.OptRepotoken;

            if (string.IsNullOrWhiteSpace(repoToken))
            {
                Console.Error.WriteLine("parameter repoToken is required.");
                Console.WriteLine(MainArgs.Usage);
                Environment.Exit(1);
            }

            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))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
                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 if (args.IsProvided("--dynamiccodecoverage") && args.OptDynamiccodecoverage)
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new DynamicCodeCoverageParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }
            else if (args.IsProvided("--mprof") && args.OptMprof)
            {
                var fileName = args.OptInput;
                files = null;

                if (File.Exists(fileName))
                {
                    var document = XDocument.Load(fileName);

                    files = new MonoProfParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
                }
                else if (Directory.Exists(fileName))
                {
                    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 MonoProfParser(new FileSystem(), pathProcessor).GenerateSourceFiles(documents, args.OptUserelativepaths);
                }
                else
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }
            }
            else
            {
                var fileName = args.OptInput;
                if (!File.Exists(fileName))
                {
                    Console.Error.WriteLine("Input file '" + fileName + "' cannot be found");
                    Environment.Exit(1);
                }

                var document = XDocument.Load(fileName);

                files = new OpenCoverParser(new FileSystem(), pathProcessor).GenerateSourceFiles(document, args.OptUserelativepaths);
            }

            GitData gitData  = null;
            var     commitId = args.IsProvided("--commitId") ? args.OptCommitid : string.Empty;

            if (commitId.IsNotNullOrWhitespace())
            {
                var committerName = args.OptCommitauthor ?? string.Empty;
                var comitterEmail = args.OptCommitemail ?? string.Empty;
                var commitMessage = args.OptCommitmessage ?? string.Empty;
                gitData = new GitData
                {
                    Head = new GitHead
                    {
                        Id            = commitId,
                        AuthorName    = committerName,
                        AuthorEmail   = comitterEmail,
                        CommitterName = committerName,
                        ComitterEmail = comitterEmail,
                        Message       = commitMessage
                    },
                    Branch = args.OptCommitbranch ?? string.Empty
                };
            }

            var serviceJobId = args.IsProvided("--jobId") ? args.OptJobid : "0";

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

            var fileData = JsonConvert.SerializeObject(data);

            if (!string.IsNullOrWhiteSpace(outputFile))
            {
                WriteFileData(fileData, outputFile);
            }
            if (!args.OptDryrun)
            {
                var uploaded = Upload(@"https://coveralls.io/api/v1/jobs", fileData);
                if (!uploaded)
                {
                    Console.Error.WriteLine("Failed to upload to coveralls");
                    Environment.Exit(1);
                }
            }
        }